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) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.aai.client.node;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Comparator;
33 import java.util.HashMap;
34 import java.util.List;
36 import java.util.Map.Entry;
37 import org.apache.commons.lang3.StringUtils;
38 import org.onap.appc.aai.client.AppcAaiClientConstant;
39 import org.onap.appc.aai.client.aai.AaiService;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
44 public class AAIResourceNode implements SvcLogicJavaPlugin {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
48 private static final String STR_VSERVER_ID = "].vserver-id";
49 private static final String STR_TENANT_ID = "].tenant-id";
50 private static final String STR_CLOUD_OWNER = "].cloud-owner";
51 private static final String STR_CLOUD_REGION_ID = "].cloud-region-id";
52 private static final String STR_VSERVER_SELFLINK ="].vserver-selflink";
53 private static final String STR_TMP_VNF_INFO = "tmp.vnfInfo.vm[";
55 private static final String PARAM_VSERVER_ID = "vserverId";
56 private static final String PARAM_TENANT_ID = "tenantId";
57 private static final String PARAM_CLOUD_OWNER = "cloudOwner";
58 private static final String PARAM_CLOUD_REGION_ID = "cloudRegionId";
59 private static final String PARAM_VSERVER_NAME = "vserver-name";
60 private static final String PARAM_VSERVER_SELFLINK = "vserver-selflink";
61 private static final String PARAM_VNFC_NAME = "vnfcName";
63 private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
65 public AaiService getAaiService() {
66 return new AaiService();
69 /* Gets VNF Info and All VServers associated with Vnf */
70 public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
72 log.info("Received getVnfInfo call with params : " + inParams);
74 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
78 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
79 AaiService aai = getAaiService();
80 aai.getGenericVnfInfo(inParams, ctx);
82 String cloudOwnerValue=ctx.getAttribute(responsePrefix + "vm[0].cloud-owner");
83 String cloudRegionValue=ctx.getAttribute(responsePrefix + "vm[0].cloud-region-id");
85 log.debug("Cloud Owner" + cloudOwnerValue);
86 log.debug("CloudRegionId" + cloudOwnerValue);
87 Map<String, String> paramsCloud = new HashMap<String, String>();
88 paramsCloud.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
89 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
91 if(StringUtils.isNotBlank(cloudOwnerValue)&&StringUtils.isNotBlank(cloudRegionValue)) {
93 paramsCloud.put(PARAM_CLOUD_OWNER, cloudOwnerValue);
94 paramsCloud.put(PARAM_CLOUD_REGION_ID, cloudRegionValue);
96 aai.getIdentityUrl(paramsCloud, ctx);
99 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
100 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
101 log.info("getVnfInfo Successful ");
102 } catch (Exception e) {
103 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
104 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
105 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
106 log.error("Failed in getVnfInfo", e);
108 throw new SvcLogicException(e.getMessage());
113 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
115 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
117 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
120 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
121 AaiService aai = getAaiService();
123 ArrayList<Map<String, String>> vservers = new ArrayList<>();
125 int vmWithNoVnfcsCount = 0;
126 int vmsWithNoVnfcsForVfModule = 0;
127 int vmCountForVfModule = 0;
128 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
129 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
130 log.info("getAllVServersVnfcsInfo()::: vfMOdule="+vfModuleFromRequest);
132 if (vmCountStr == null) {
133 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
136 int vmCount = Integer.parseInt(vmCountStr);
137 for (int i = 0; i < vmCount; i++) {
139 SvcLogicContext vmServerCtx = new SvcLogicContext();
141 Map<String, String> paramsVm = new HashMap<>();
142 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
143 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
144 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
145 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
146 paramsVm.put(PARAM_VSERVER_SELFLINK, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_SELFLINK));
147 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
148 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
150 aai.getVMInfo(paramsVm, vmServerCtx);
152 HashMap<String, String> vserverMap = new HashMap<>();
153 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
154 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
155 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
156 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
158 // Parameters returned by getVMInfo
159 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
160 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
161 vserverMap.put(PARAM_VSERVER_SELFLINK, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
163 log.info("VSERVER-LINK VALUE:" + vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
165 // as Per 17.07 requirements we are supporting only one VNFC per VM.
167 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
168 vserverMap.put("vnfc-name", vnfcName);
170 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
171 if (vnfcCount == null) {
175 vserverMap.put("vnfc-count", vnfcCount);
176 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
178 if (vnfcName != null) {
179 Map<String, String> paramsVnfc = new HashMap<String, String>();
180 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
182 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
183 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
185 SvcLogicContext vnfcCtx = new SvcLogicContext();
187 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
189 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
191 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
192 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
193 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
194 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
197 vmWithNoVnfcsCount++;
199 log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
200 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
201 vmsWithNoVnfcsForVfModule++;
205 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
206 vmCountForVfModule++;
208 vservers.add(vserverMap);
212 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
214 log.info("SORTED VSERVERS " + vservers.toString());
216 populateContext(vservers, ctx, responsePrefix);
218 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
219 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
220 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
221 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
222 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
223 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
224 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
225 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
228 } catch (Exception e) {
229 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
230 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
231 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
232 log.error("Failed in getAllVServersVnfcsInfo", e);
234 throw new SvcLogicException(e.getMessage());
238 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
240 log.info("Populating Final Context");
243 for (Map<String, String> input : vservers) {
244 for (Entry<String, String> entry : input.entrySet()) {
246 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
247 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
252 String firstVServerName = null;
253 for (int i = 0; i < counter; i++) {
254 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
255 log.info("VNFCNAME " + i + vnfcName);
256 if (vnfcName == null && firstVServerName == null) {
257 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
258 ctx.setAttribute("vm-name", firstVServerName);
259 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
265 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
267 log.info("Received addVnfcs call with params : " + inParams);
269 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
273 int vmWithNoVnfcCount = 0;
277 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
278 AaiService aai = getAaiService();
280 //no:of vnfcs from the vnfc_reference table
281 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
283 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
285 //Vms without vnfc from A&AI
286 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
289 if (vmWithNoVnfcCountStr == null) {
290 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
292 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
295 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
297 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
299 if (vmCountStr == null) {
300 throw new ResourceNodeInternalException("VM data from A&AI is missing");
302 vmCount = Integer.parseInt(vmCountStr);
304 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
305 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
306 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
310 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
311 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
314 log.info("VMCOUNT " + vmCount);
315 log.info("VNFCREFLEN " + vnfcRefLen);
318 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
319 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
322 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
324 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
325 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
327 log.info("addVnfcs Successful ");
328 } catch (Exception e) {
329 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
330 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
331 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
332 log.error("Failed in addVnfcs", e);
334 throw new SvcLogicException(e.getMessage());
338 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
339 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
341 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
342 int vmsWithoutVnfcsForVfModule = 0;
343 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
344 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
345 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule="+vfModuleIdFromRequest);
348 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
350 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: "+vmsWithoutVnfcsForVfModule);
351 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix +"vnf.vm-count-for-vf-module");
352 int vmsForVfModule = 0;
353 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
354 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
356 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
357 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
359 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
363 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
365 if (vnfcRefLenStr == null) {
366 log.info("Vnfc Reference data is missing");
367 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
370 return Integer.parseInt(vnfcRefLenStr);
375 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
377 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
379 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
385 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
386 AaiService aai = getAaiService();
388 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
390 if (vmCountStr == null) {
391 throw new ResourceNodeInternalException("VM data from A&AI is missing");
393 vmCount = Integer.parseInt(vmCountStr);
396 log.info("VMCOUNT " + vmCount);
398 aai.updateVnfStatus(inParams, ctx);
399 aai.updateVServerStatus(inParams, ctx, vmCount);
401 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
402 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
404 log.info("updateVnfAndVServerStatus Successful ");
405 } catch (Exception e) {
406 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
407 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
408 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
409 log.error("Failed in updateVnfAndVServerStatus", e);
411 throw new SvcLogicException(e.getMessage());
415 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
416 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
417 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
419 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
420 AaiService aaiService = getAaiService();
421 String vServerId = inParams.get(PARAM_VSERVER_ID);
422 Map<String, String> params = setVmParams(ctx, vServerId);
423 Map<String, String> vnfcParams = new HashMap<>();
424 if (null == params) {
425 log.error("getVserverInfo()::No Vm Info found!!");
426 throw new SvcLogicException("No Vm Info in Context");
428 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
429 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
430 SvcLogicContext newVmCtx = new SvcLogicContext();
431 aaiService.getVMInfo(params, newVmCtx);
433 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
434 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
435 SvcLogicContext newVnfcCtx = new SvcLogicContext();
436 if (StringUtils.isNotBlank(vnfcName)) {
437 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
439 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
442 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
443 } catch (Exception e) {
444 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
445 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
446 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
447 log.error("Failed in getVserverInfo", e);
451 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
452 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
454 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
455 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
456 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
458 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
460 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
461 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
462 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
463 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
465 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
466 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
467 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
469 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
470 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
471 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
472 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
473 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
474 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
475 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
478 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
479 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
480 Map<String, String> params = new HashMap<>();
483 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
484 if (StringUtils.isNotBlank(vmCountStr)) {
485 vmCount = Integer.parseInt(vmCountStr);
487 for (int cnt = 0; cnt < vmCount; cnt++) {
488 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
489 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
490 if (StringUtils.equals(vServerId, vsId)) {
494 if (arrayIndex < 0) {
495 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
498 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
499 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
500 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
501 String vserverSelflink = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_VSERVER_SELFLINK);
502 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
504 params.put(PARAM_VSERVER_ID, vServerId);
505 params.put(PARAM_TENANT_ID, tenantId);
506 params.put(PARAM_CLOUD_OWNER, cloudOwner);
507 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
508 params.put(PARAM_VSERVER_SELFLINK, vserverSelflink);
509 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
513 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) {
514 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
515 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
517 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
518 AaiService aaiService = getAaiService();
519 processForVfModuleModelInfo(aaiService,inParams,ctx);
520 } catch (Exception e) {
521 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
522 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
523 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
524 log.error("Failed in vfModuleInfo", e);
528 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
529 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
530 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
532 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
533 Map<String, String> params = new HashMap<>();
534 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
535 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
536 params.put("vnfId", inParams.get("vnf-id"));
537 params.put("vfModuleId", inParams.get("vf-module-id"));
538 SvcLogicContext vfModuleCtx = new SvcLogicContext();
539 aaiService.getVfModuleInfo(params, vfModuleCtx);
541 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
542 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
543 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
545 Map<String, String> modelParams = new HashMap<>();
546 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
547 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
548 SvcLogicContext modelCtx = new SvcLogicContext();
549 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
550 modelParams.put("model-invariant-id", modelInvariantId);
551 modelParams.put("model-version-id", modelVersionId);
554 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
557 aaiService.getModelVersionInfo(modelParams,modelCtx);
558 String modelName = modelCtx.getAttribute(responsePrefix+"vfModule.model-name");
559 log.info("processForVfModuleModelInfo()::modelName for vfModule:::"+modelName);
560 log.info("Setting context template-model-id as :::"+modelName);
561 ctx.setAttribute("template-model-id", modelName);
562 log.info("processForVfModuleModelInfo() ::: End");
564 catch (Exception e) {
565 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
566 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
567 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
568 log.error("Failed in vfModuleInfo", e);
573 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) {
574 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
575 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
577 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
578 String inputValue = inParams.get("inputParameter");
579 if (StringUtils.isBlank(inputValue)) {
582 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
583 outputValue = StringUtils.replace(outputValue," ","");//remove space
584 ctx.setAttribute("template-model-id", outputValue);
585 } catch (Exception e) {
586 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
587 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
588 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
589 log.error("Failed in getFormattedValue", e);