2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications Copyright (C) 2019 IBM.
10 * ================================================================================
11 * Modifications Copyright (C) 2019 Ericsson
12 * =============================================================================
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
17 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 * ============LICENSE_END=========================================================
28 package org.onap.appc.aai.client.node;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import org.apache.commons.lang3.StringUtils;
33 import org.onap.appc.aai.client.AppcAaiClientConstant;
34 import org.onap.appc.aai.client.aai.AaiService;
35 import org.onap.appc.aai.client.aai.AaiServiceInternalException;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
41 import java.util.Map.Entry;
43 public class AAIResourceNode implements SvcLogicJavaPlugin {
45 private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
47 private static final String STR_VSERVER_ID = "].vserver-id";
48 private static final String STR_TENANT_ID = "].tenant-id";
49 private static final String STR_CLOUD_OWNER = "].cloud-owner";
50 private static final String STR_CLOUD_REGION_ID = "].cloud-region-id";
51 private static final String STR_VSERVER_SELFLINK ="].vserver-selflink";
52 private static final String STR_TMP_VNF_INFO = "tmp.vnfInfo.vm[";
54 private static final String PARAM_VSERVER_ID = "vserverId";
55 private static final String PARAM_TENANT_ID = "tenantId";
56 private static final String PARAM_CLOUD_OWNER = "cloudOwner";
57 private static final String PARAM_CLOUD_REGION_ID = "cloudRegionId";
58 private static final String PARAM_VSERVER_NAME = "vserver-name";
59 private static final String PARAM_VSERVER_SELFLINK = "vserver-selflink";
60 private static final String PARAM_VNFC_NAME = "vnfcName";
62 private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
64 public AaiService getAaiService() {
65 return new AaiService();
68 /* Gets VNF Info and All VServers associated with Vnf */
69 public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
71 log.info("Received getVnfInfo call with params : " + inParams);
73 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
77 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
78 AaiService aai = getAaiService();
79 aai.getGenericVnfInfo(inParams, ctx);
81 String cloudOwnerValue = ctx.getAttribute(responsePrefix + "vm[0].cloud-owner");
82 String cloudRegionValue = ctx.getAttribute(responsePrefix + "vm[0].cloud-region-id");
84 log.debug("Cloud Owner" + cloudOwnerValue);
85 log.debug("CloudRegionId" + cloudOwnerValue);
86 Map<String, String> paramsCloud = new HashMap<>();
87 paramsCloud.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
88 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
90 if(StringUtils.isNotBlank(cloudOwnerValue) && StringUtils.isNotBlank(cloudRegionValue)) {
92 paramsCloud.put(PARAM_CLOUD_OWNER, cloudOwnerValue);
93 paramsCloud.put(PARAM_CLOUD_REGION_ID, cloudRegionValue);
95 aai.getIdentityUrl(paramsCloud, ctx);
98 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
99 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
100 log.info("getVnfInfo Successful ");
101 } catch (Exception e) {
102 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
103 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
104 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
105 log.error("Failed in getVnfInfo", e);
107 throw new SvcLogicException(e.getMessage());
112 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
114 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
116 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
119 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
120 AaiService aai = getAaiService();
122 ArrayList<Map<String, String>> vservers = new ArrayList<>();
124 int vmWithNoVnfcsCount = 0;
125 int vmsWithNoVnfcsForVfModule = 0;
126 int vmCountForVfModule = 0;
127 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
128 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
129 log.info("getAllVServersVnfcsInfo()::: vfMOdule=" + vfModuleFromRequest);
131 if (vmCountStr == null) {
132 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
135 int vmCount = Integer.parseInt(vmCountStr);
136 for (int i = 0; i < vmCount; i++) {
138 SvcLogicContext vmServerCtx = new SvcLogicContext();
140 Map<String, String> paramsVm = new HashMap<>();
141 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
142 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
143 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
144 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
145 paramsVm.put(PARAM_VSERVER_SELFLINK, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_SELFLINK));
146 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
147 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
149 aai.getVMInfo(paramsVm, vmServerCtx);
151 HashMap<String, String> vserverMap = new HashMap<>();
152 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
153 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
154 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
155 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
157 // Parameters returned by getVMInfo
158 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
159 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
160 vserverMap.put(PARAM_VSERVER_SELFLINK, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
162 log.info("VSERVER-LINK VALUE:" + vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
164 // as Per 17.07 requirements we are supporting only one VNFC per VM.
166 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
167 vserverMap.put("vnfc-name", vnfcName);
169 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
170 if (vnfcCount == null) {
174 vserverMap.put("vnfc-count", vnfcCount);
175 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
177 if (vnfcName != null) {
178 Map<String, String> paramsVnfc = new HashMap<>();
179 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
181 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
182 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
184 SvcLogicContext vnfcCtx = new SvcLogicContext();
186 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
188 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
190 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
191 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
192 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
193 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
196 vmWithNoVnfcsCount++;
198 log.info("getAllVServersVnfcsInfo()::Vf Modules: " + vfModuleForVserver+", " + vfModuleFromRequest);
199 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
200 vmsWithNoVnfcsForVfModule++;
204 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
205 vmCountForVfModule++;
207 vservers.add(vserverMap);
211 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
213 log.info("SORTED VSERVERS " + vservers.toString());
215 populateContext(vservers, ctx, responsePrefix);
217 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
218 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
219 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
220 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
221 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
222 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
223 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
224 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
227 } catch (Exception e) {
228 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
229 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
230 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
231 log.error("Failed in getAllVServersVnfcsInfo", e);
233 throw new SvcLogicException(e.getMessage());
237 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
239 log.info("Populating Final Context");
242 for (Map<String, String> input : vservers) {
243 for (Entry<String, String> entry : input.entrySet()) {
245 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
246 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
251 String firstVServerName = null;
252 for (int i = 0; i < counter; i++) {
253 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
254 log.info("VNFCNAME " + i + vnfcName);
255 if (vnfcName == null && firstVServerName == null) {
256 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
257 ctx.setAttribute("vm-name", firstVServerName);
258 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
264 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
266 log.info("Received addVnfcs call with params : " + inParams);
268 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
272 int vmWithNoVnfcCount = 0;
276 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
277 AaiService aai = getAaiService();
279 //no:of vnfcs from the vnfc_reference table
280 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
282 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
284 //Vms without vnfc from A&AI
285 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
288 if (vmWithNoVnfcCountStr == null) {
289 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
291 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
294 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
296 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
298 if (vmCountStr == null) {
299 throw new ResourceNodeInternalException("VM data from A&AI is missing");
301 vmCount = Integer.parseInt(vmCountStr);
303 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
304 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
305 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
309 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
310 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
313 log.info("VMCOUNT " + vmCount);
314 log.info("VNFCREFLEN " + vnfcRefLen);
317 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
318 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
321 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
323 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
324 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
326 log.info("addVnfcs Successful ");
327 } catch (Exception e) {
328 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
329 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
330 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
331 log.error("Failed in addVnfcs", e);
333 throw new SvcLogicException(e.getMessage());
337 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
338 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
340 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
341 int vmsWithoutVnfcsForVfModule = 0;
342 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
343 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
344 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule=" + vfModuleIdFromRequest);
347 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
349 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: " + vmsWithoutVnfcsForVfModule);
350 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-count-for-vf-module");
351 int vmsForVfModule = 0;
352 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
353 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
355 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
356 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request=" + vfModuleIdFromRequest);
358 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
362 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
364 if (vnfcRefLenStr == null) {
365 log.info("Vnfc Reference data is missing");
366 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
369 return Integer.parseInt(vnfcRefLenStr);
374 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
376 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
378 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
384 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
385 AaiService aai = getAaiService();
387 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
389 if (vmCountStr == null) {
390 throw new ResourceNodeInternalException("VM data from A&AI is missing");
392 vmCount = Integer.parseInt(vmCountStr);
395 log.info("VMCOUNT " + vmCount);
397 aai.updateVnfStatus(inParams, ctx);
398 aai.updateVServerStatus(inParams, ctx, vmCount);
400 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
401 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
403 log.info("updateVnfAndVServerStatus Successful ");
404 } catch (Exception e) {
405 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
406 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
407 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
408 log.error("Failed in updateVnfAndVServerStatus", e);
410 throw new SvcLogicException(e.getMessage());
414 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
415 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
416 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
418 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
419 AaiService aaiService = getAaiService();
420 String vServerId = inParams.get(PARAM_VSERVER_ID);
421 Map<String, String> params = setVmParams(ctx, vServerId);
422 Map<String, String> vnfcParams = new HashMap<>();
423 if (null == params) {
424 log.error("getVserverInfo()::No Vm Info found!!");
425 throw new SvcLogicException("No Vm Info in Context");
427 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
428 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
429 SvcLogicContext newVmCtx = new SvcLogicContext();
430 aaiService.getVMInfo(params, newVmCtx);
432 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
433 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
434 SvcLogicContext newVnfcCtx = new SvcLogicContext();
435 if (StringUtils.isNotBlank(vnfcName)) {
436 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
438 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
441 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
442 } catch (Exception e) {
443 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
444 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
445 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
446 log.error("Failed in getVserverInfo", e);
450 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
451 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix) throws AaiServiceInternalException, SvcLogicException {
452 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
453 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
454 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
456 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
458 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
459 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
460 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
461 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
463 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
464 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
465 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
467 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
468 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
469 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
470 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
471 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
472 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
473 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
476 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
477 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
478 Map<String, String> params = new HashMap<>();
481 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
482 if (StringUtils.isNotBlank(vmCountStr)) {
483 vmCount = Integer.parseInt(vmCountStr);
485 for (int cnt = 0; cnt < vmCount; cnt++) {
486 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
487 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
488 if (StringUtils.equals(vServerId, vsId)) {
492 if (arrayIndex < 0) {
493 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
496 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
497 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
498 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
499 String vserverSelflink = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_VSERVER_SELFLINK);
500 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
502 params.put(PARAM_VSERVER_ID, vServerId);
503 params.put(PARAM_TENANT_ID, tenantId);
504 params.put(PARAM_CLOUD_OWNER, cloudOwner);
505 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
506 params.put(PARAM_VSERVER_SELFLINK, vserverSelflink);
507 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
511 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
512 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
513 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
515 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
516 AaiService aaiService = getAaiService();
517 processForVfModuleModelInfo(aaiService, inParams, ctx);
518 } catch (Exception e) {
519 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
520 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
521 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
522 log.error("Failed in vfModuleInfo", e);
526 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
527 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
528 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
530 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
531 Map<String, String> params = new HashMap<>();
532 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
533 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
534 params.put("vnfId", inParams.get("vnf-id"));
535 params.put("vfModuleId", inParams.get("vf-module-id"));
536 SvcLogicContext vfModuleCtx = new SvcLogicContext();
537 aaiService.getVfModuleInfo(params, vfModuleCtx);
539 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
540 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
541 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
543 Map<String, String> modelParams = new HashMap<>();
544 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
545 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
546 SvcLogicContext modelCtx = new SvcLogicContext();
547 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
548 modelParams.put("model-invariant-id", modelInvariantId);
549 modelParams.put("model-version-id", modelVersionId);
552 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
555 aaiService.getModelVersionInfo(modelParams, modelCtx);
556 String modelName = modelCtx.getAttribute(responsePrefix + "vfModule.model-name");
557 log.info("processForVfModuleModelInfo()::modelName for vfModule:::" + modelName);
558 log.info("Setting context template-model-id as :::" + modelName);
559 ctx.setAttribute("template-model-id", modelName);
560 log.info("processForVfModuleModelInfo() ::: End");
562 catch (Exception e) {
563 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
564 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
565 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
566 log.error("Failed in vfModuleInfo", e);
571 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
572 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
573 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
575 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
576 String inputValue = inParams.get("inputParameter");
577 if (StringUtils.isBlank(inputValue)) {
580 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
581 outputValue = StringUtils.replace(outputValue, " ", "");//remove space
582 ctx.setAttribute("template-model-id", outputValue);
583 } catch (Exception e) {
584 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
585 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
586 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
587 log.error("Failed in getFormattedValue", e);