2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.interfaces.service.executorImpl;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
31 import org.onap.appc.aai.client.aai.AaiService;
32 import org.onap.appc.interfaces.service.data.Request;
33 import org.onap.appc.interfaces.service.data.ScopeOverlap;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
39 import com.fasterxml.jackson.databind.ObjectMapper;
40 import com.google.common.base.Strings;
42 public class ServiceExecutorImpl {
44 private static final EELFLogger log = EELFManager.getInstance().getLogger(ServiceExecutorImpl.class);
45 private AAIClient aaiClient;
46 public String isRequestOverLap(String requestData) throws Exception {
47 String response = "\"requestOverlap\" : ";
48 log.info("Response from ServiceExecutorImpl");
49 ScopeOverlap scopeOverlap = new ScopeOverlap();
50 ObjectMapper mapper = new ObjectMapper();
51 scopeOverlap = mapper.readValue(requestData, ScopeOverlap.class);
52 // return response + String.valueOf(checkForOverLap(scopeOverlap));
53 boolean isOverlap = checkForOverLap(scopeOverlap);
54 scopeOverlap.setOverlap(String.valueOf(isOverlap));
55 if (scopeOverlap.getOverlap() != null && scopeOverlap.getOverlap().equalsIgnoreCase("false")){
56 log.info(response + "false");
57 return response + "false";
60 log.info(response + "true");
61 return response + "true";
65 private boolean checkForOverLap(ScopeOverlap scopeOverlap) throws Exception {
66 log.info("Checking for isScopeOverlap");
67 if (scopeOverlap.getInProgressRequest() == null) {
69 }else if ( scopeOverlap.getInProgressRequest().isEmpty()){
72 else if (scopeOverlap.getInProgressRequest().size() == 0) {
75 if (scopeOverlap.getCurrentRequest().getActionIdentifiers().getVnfId() != null) {
77 } else if (scopeOverlap.getCurrentRequest().getActionIdentifiers().getVfModuleId() != null) {
79 } else if (scopeOverlap.getCurrentRequest().getActionIdentifiers().getvServerId() != null) {
80 return isVserverOrVnfcIdOverLap(scopeOverlap);
81 } else if (scopeOverlap.getCurrentRequest().getActionIdentifiers().getVnfcName() != null) {
82 return isVserverOrVnfcIdOverLap(scopeOverlap);
84 throw new Exception(" Action Identifier doesn't have VnfId, VfModuleId, VServerId, VnfcName ");
88 private boolean isVnfcNameOverLap(ScopeOverlap scopeOverlap) throws Exception {
90 AaiService aaiService =new AaiService(aaiClient);
91 SvcLogicContext ctx = new SvcLogicContext();
92 Map<String, String> params = new HashMap<String, String>();
93 List<String> inProgressVServerIds = new ArrayList<String>();
94 String currentVnfcVserverId = new String();
95 String currentRequestVnfcName = scopeOverlap.getCurrentRequest().getActionIdentifiers().getVnfcName();
96 String currentRequestVServerId = scopeOverlap.getCurrentRequest().getActionIdentifiers().getvServerId();
97 List<Request> inProgressRequests = scopeOverlap.getInProgressRequest();
98 params.put("vnfId", scopeOverlap.getVnfId());
100 aaiService.getGenericVnfInfo(params, ctx);
101 int vm_count = Integer.parseInt(ctx.getAttribute("vm-count"));
102 for(Request inprogressRequest:inProgressRequests){
103 if(inprogressRequest.getActionIdentifiers().getVnfcName() != null){
104 for (int i = 0; i < vm_count; i++){
105 if (ctx.getAttribute("vm[" + i + "].vnfc-name") != null && ctx.getAttribute("vm[" + i + "].vnfc-name")
106 .equals(inprogressRequest.getActionIdentifiers().getVnfcName()))
107 inProgressVServerIds.add(ctx.getAttribute("vm[" + i + "].vserver-id"));
108 log.debug("Received vserver-id from AAI: "+ inProgressVServerIds);
112 for(Request inProgVserverIds:inProgressRequests)
113 if(inProgVserverIds.getActionIdentifiers().getvServerId()!=null)
114 inProgressVServerIds.add(inProgVserverIds.getActionIdentifiers().getvServerId());
115 if(currentRequestVnfcName != null){
116 for (int i = 0; i < vm_count; i++)
117 if (ctx.getAttribute("vm[" + i + "].vnfc-name") != null && ctx.getAttribute("vm[" + i + "].vnfc-name")
118 .equals(currentRequestVnfcName))
119 currentVnfcVserverId = ctx.getAttribute("vm[" + i + "].vserver-id");
120 log.debug("Received vserver-id from AAI: "+ currentVnfcVserverId);
121 return inProgressVServerIds.contains(currentVnfcVserverId);
123 for (Request request : inProgressRequests) {
124 if(!Strings.isNullOrEmpty(currentRequestVServerId) && currentRequestVServerId.equalsIgnoreCase(request.getActionIdentifiers().getvServerId()))
127 if(currentRequestVServerId != null) {
128 return inProgressVServerIds.contains(currentRequestVServerId);
130 return Boolean.FALSE;
131 } catch (Exception e) {
133 log.debug(e.getMessage());
138 private boolean isVserverOrVnfcIdOverLap(ScopeOverlap scopeOverlap) throws Exception {
139 List<Request> inProgressRequests = scopeOverlap.getInProgressRequest();
140 for (Request request : inProgressRequests) {
141 if(request.getActionIdentifiers().getVnfId()!= null)
142 return Boolean.TRUE ;
144 for (Request request : inProgressRequests) {
145 if(request.getActionIdentifiers().getVfModuleId()!= null)
146 return Boolean.TRUE ;
148 String currentVserverID = scopeOverlap.getCurrentRequest().getActionIdentifiers().getvServerId();
149 for (Request request : inProgressRequests) {
150 if(currentVserverID != null && currentVserverID.equalsIgnoreCase(request.getActionIdentifiers().getvServerId()))
151 return Boolean.TRUE ;
153 return isVnfcNameOverLap(scopeOverlap);