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 * 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 java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.Comparator;
35 import java.util.HashMap;
36 import java.util.List;
38 import java.util.Map.Entry;
39 import org.apache.commons.lang3.StringUtils;
40 import org.onap.appc.aai.client.AppcAaiClientConstant;
41 import org.onap.appc.aai.client.aai.AaiService;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
46 public class AAIResourceNode implements SvcLogicJavaPlugin {
48 private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
50 private static final String STR_VSERVER_ID = "].vserver-id";
51 private static final String STR_TENANT_ID = "].tenant-id";
52 private static final String STR_CLOUD_OWNER = "].cloud-owner";
53 private static final String STR_CLOUD_REGION_ID = "].cloud-region-id";
54 private static final String STR_VSERVER_SELFLINK ="].vserver-selflink";
55 private static final String STR_TMP_VNF_INFO = "tmp.vnfInfo.vm[";
57 private static final String PARAM_VSERVER_ID = "vserverId";
58 private static final String PARAM_TENANT_ID = "tenantId";
59 private static final String PARAM_CLOUD_OWNER = "cloudOwner";
60 private static final String PARAM_CLOUD_REGION_ID = "cloudRegionId";
61 private static final String PARAM_VSERVER_NAME = "vserver-name";
62 private static final String PARAM_VSERVER_SELFLINK = "vserver-selflink";
63 private static final String PARAM_VNFC_NAME = "vnfcName";
65 private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
67 public AaiService getAaiService() {
68 return new AaiService();
71 /* Gets VNF Info and All VServers associated with Vnf */
72 public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
74 log.info("Received getVnfInfo call with params : " + inParams);
76 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
80 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
81 AaiService aai = getAaiService();
82 aai.getGenericVnfInfo(inParams, ctx);
84 String cloudOwnerValue = ctx.getAttribute(responsePrefix + "vm[0].cloud-owner");
85 String cloudRegionValue = ctx.getAttribute(responsePrefix + "vm[0].cloud-region-id");
87 log.debug("Cloud Owner" + cloudOwnerValue);
88 log.debug("CloudRegionId" + cloudOwnerValue);
89 Map<String, String> paramsCloud = new HashMap<>();
90 paramsCloud.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
91 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
93 if(StringUtils.isNotBlank(cloudOwnerValue) && StringUtils.isNotBlank(cloudRegionValue)) {
95 paramsCloud.put(PARAM_CLOUD_OWNER, cloudOwnerValue);
96 paramsCloud.put(PARAM_CLOUD_REGION_ID, cloudRegionValue);
98 aai.getIdentityUrl(paramsCloud, ctx);
101 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
102 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
103 log.info("getVnfInfo Successful ");
104 } catch (Exception e) {
105 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
106 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
107 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
108 log.error("Failed in getVnfInfo", e);
110 throw new SvcLogicException(e.getMessage());
115 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
117 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
119 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
122 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
123 AaiService aai = getAaiService();
125 ArrayList<Map<String, String>> vservers = new ArrayList<>();
127 int vmWithNoVnfcsCount = 0;
128 int vmsWithNoVnfcsForVfModule = 0;
129 int vmCountForVfModule = 0;
130 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
131 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
132 log.info("getAllVServersVnfcsInfo()::: vfMOdule=" + vfModuleFromRequest);
134 if (vmCountStr == null) {
135 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
138 int vmCount = Integer.parseInt(vmCountStr);
139 for (int i = 0; i < vmCount; i++) {
141 SvcLogicContext vmServerCtx = new SvcLogicContext();
143 Map<String, String> paramsVm = new HashMap<>();
144 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
145 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
146 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
147 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
148 paramsVm.put(PARAM_VSERVER_SELFLINK, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_SELFLINK));
149 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
150 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
152 aai.getVMInfo(paramsVm, vmServerCtx);
154 HashMap<String, String> vserverMap = new HashMap<>();
155 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
156 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
157 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
158 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
160 // Parameters returned by getVMInfo
161 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
162 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
163 vserverMap.put(PARAM_VSERVER_SELFLINK, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
165 log.info("VSERVER-LINK VALUE:" + vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
167 // as Per 17.07 requirements we are supporting only one VNFC per VM.
169 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
170 vserverMap.put("vnfc-name", vnfcName);
172 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
173 if (vnfcCount == null) {
177 vserverMap.put("vnfc-count", vnfcCount);
178 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
180 if (vnfcName != null) {
181 Map<String, String> paramsVnfc = new HashMap<>();
182 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
184 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
185 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
187 SvcLogicContext vnfcCtx = new SvcLogicContext();
189 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
191 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
193 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
194 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
195 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
196 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
199 vmWithNoVnfcsCount++;
201 log.info("getAllVServersVnfcsInfo()::Vf Modules: " + vfModuleForVserver+", " + vfModuleFromRequest);
202 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
203 vmsWithNoVnfcsForVfModule++;
207 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
208 vmCountForVfModule++;
210 vservers.add(vserverMap);
214 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
216 log.info("SORTED VSERVERS " + vservers.toString());
218 populateContext(vservers, ctx, responsePrefix);
220 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
221 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
222 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
223 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
224 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
225 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
226 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
227 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
230 } catch (Exception e) {
231 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
232 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
233 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
234 log.error("Failed in getAllVServersVnfcsInfo", e);
236 throw new SvcLogicException(e.getMessage());
240 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
242 log.info("Populating Final Context");
245 for (Map<String, String> input : vservers) {
246 for (Entry<String, String> entry : input.entrySet()) {
248 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
249 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
254 String firstVServerName = null;
255 for (int i = 0; i < counter; i++) {
256 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
257 log.info("VNFCNAME " + i + vnfcName);
258 if (vnfcName == null && firstVServerName == null) {
259 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
260 ctx.setAttribute("vm-name", firstVServerName);
261 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
267 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
269 log.info("Received addVnfcs call with params : " + inParams);
271 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
275 int vmWithNoVnfcCount = 0;
279 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
280 AaiService aai = getAaiService();
282 //no:of vnfcs from the vnfc_reference table
283 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
285 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
287 //Vms without vnfc from A&AI
288 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
291 if (vmWithNoVnfcCountStr == null) {
292 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
294 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
297 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
299 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
301 if (vmCountStr == null) {
302 throw new ResourceNodeInternalException("VM data from A&AI is missing");
304 vmCount = Integer.parseInt(vmCountStr);
306 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
307 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
308 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
312 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
313 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
316 log.info("VMCOUNT " + vmCount);
317 log.info("VNFCREFLEN " + vnfcRefLen);
320 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
321 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
324 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
326 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
327 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
329 log.info("addVnfcs Successful ");
330 } catch (Exception e) {
331 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
332 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
333 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
334 log.error("Failed in addVnfcs", e);
336 throw new SvcLogicException(e.getMessage());
340 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
341 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
343 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
344 int vmsWithoutVnfcsForVfModule = 0;
345 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
346 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
347 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule=" + vfModuleIdFromRequest);
350 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
352 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: " + vmsWithoutVnfcsForVfModule);
353 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-count-for-vf-module");
354 int vmsForVfModule = 0;
355 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
356 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
358 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
359 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request=" + vfModuleIdFromRequest);
361 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
365 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
367 if (vnfcRefLenStr == null) {
368 log.info("Vnfc Reference data is missing");
369 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
372 return Integer.parseInt(vnfcRefLenStr);
377 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
379 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
381 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
387 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
388 AaiService aai = getAaiService();
390 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
392 if (vmCountStr == null) {
393 throw new ResourceNodeInternalException("VM data from A&AI is missing");
395 vmCount = Integer.parseInt(vmCountStr);
398 log.info("VMCOUNT " + vmCount);
400 aai.updateVnfStatus(inParams, ctx);
401 aai.updateVServerStatus(inParams, ctx, vmCount);
403 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
404 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
406 log.info("updateVnfAndVServerStatus Successful ");
407 } catch (Exception e) {
408 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
409 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
410 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
411 log.error("Failed in updateVnfAndVServerStatus", e);
413 throw new SvcLogicException(e.getMessage());
417 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
418 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
419 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
421 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
422 AaiService aaiService = getAaiService();
423 String vServerId = inParams.get(PARAM_VSERVER_ID);
424 Map<String, String> params = setVmParams(ctx, vServerId);
425 Map<String, String> vnfcParams = new HashMap<>();
426 if (null == params) {
427 log.error("getVserverInfo()::No Vm Info found!!");
428 throw new SvcLogicException("No Vm Info in Context");
430 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
431 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
432 SvcLogicContext newVmCtx = new SvcLogicContext();
433 aaiService.getVMInfo(params, newVmCtx);
435 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
436 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
437 SvcLogicContext newVnfcCtx = new SvcLogicContext();
438 if (StringUtils.isNotBlank(vnfcName)) {
439 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
441 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
444 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
445 } catch (Exception e) {
446 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
447 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
448 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
449 log.error("Failed in getVserverInfo", e);
453 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
454 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
456 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
457 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
458 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
460 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
462 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
463 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
464 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
465 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
467 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
468 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
469 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
471 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
472 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
473 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
474 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
475 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
476 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
477 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
480 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
481 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
482 Map<String, String> params = new HashMap<>();
485 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
486 if (StringUtils.isNotBlank(vmCountStr)) {
487 vmCount = Integer.parseInt(vmCountStr);
489 for (int cnt = 0; cnt < vmCount; cnt++) {
490 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
491 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
492 if (StringUtils.equals(vServerId, vsId)) {
496 if (arrayIndex < 0) {
497 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
500 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
501 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
502 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
503 String vserverSelflink = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_VSERVER_SELFLINK);
504 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
506 params.put(PARAM_VSERVER_ID, vServerId);
507 params.put(PARAM_TENANT_ID, tenantId);
508 params.put(PARAM_CLOUD_OWNER, cloudOwner);
509 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
510 params.put(PARAM_VSERVER_SELFLINK, vserverSelflink);
511 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
515 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) {
516 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
517 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
519 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
520 AaiService aaiService = getAaiService();
521 processForVfModuleModelInfo(aaiService, inParams, ctx);
522 } catch (Exception e) {
523 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
524 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
525 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
526 log.error("Failed in vfModuleInfo", e);
530 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
531 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
532 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
534 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
535 Map<String, String> params = new HashMap<>();
536 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
537 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
538 params.put("vnfId", inParams.get("vnf-id"));
539 params.put("vfModuleId", inParams.get("vf-module-id"));
540 SvcLogicContext vfModuleCtx = new SvcLogicContext();
541 aaiService.getVfModuleInfo(params, vfModuleCtx);
543 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
544 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
545 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
547 Map<String, String> modelParams = new HashMap<>();
548 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
549 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
550 SvcLogicContext modelCtx = new SvcLogicContext();
551 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
552 modelParams.put("model-invariant-id", modelInvariantId);
553 modelParams.put("model-version-id", modelVersionId);
556 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
559 aaiService.getModelVersionInfo(modelParams, modelCtx);
560 String modelName = modelCtx.getAttribute(responsePrefix + "vfModule.model-name");
561 log.info("processForVfModuleModelInfo()::modelName for vfModule:::" + modelName);
562 log.info("Setting context template-model-id as :::" + modelName);
563 ctx.setAttribute("template-model-id", modelName);
564 log.info("processForVfModuleModelInfo() ::: End");
566 catch (Exception e) {
567 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
568 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
569 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
570 log.error("Failed in vfModuleInfo", e);
575 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) {
576 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
577 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
579 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
580 String inputValue = inParams.get("inputParameter");
581 if (StringUtils.isBlank(inputValue)) {
584 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
585 outputValue = StringUtils.replace(outputValue, " ", "");//remove space
586 ctx.setAttribute("template-model-id", outputValue);
587 } catch (Exception e) {
588 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
589 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
590 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
591 log.error("Failed in getFormattedValue", e);