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.aai.client.node;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.Comparator;
31 import java.util.HashMap;
32 import java.util.List;
34 import java.util.Map.Entry;
35 import org.apache.commons.lang3.StringUtils;
36 import org.onap.appc.aai.client.AppcAaiClientConstant;
37 import org.onap.appc.aai.client.aai.AaiService;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
42 public class AAIResourceNode implements SvcLogicJavaPlugin {
44 private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
46 private static final String STR_VSERVER_ID = "].vserver-id";
47 private static final String STR_TENANT_ID = "].tenant-id";
48 private static final String STR_CLOUD_OWNER = "].cloud-owner";
49 private static final String STR_CLOUD_REGION_ID = "].cloud-region-id";
50 private static final String STR_VSERVER_SELFLINK ="].vserver-selflink";
51 private static final String STR_TMP_VNF_INFO = "tmp.vnfInfo.vm[";
53 private static final String PARAM_VSERVER_ID = "vserverId";
54 private static final String PARAM_TENANT_ID = "tenantId";
55 private static final String PARAM_CLOUD_OWNER = "cloudOwner";
56 private static final String PARAM_CLOUD_REGION_ID = "cloudRegionId";
57 private static final String PARAM_VSERVER_NAME = "vserver-name";
58 private static final String PARAM_VSERVER_SELFLINK = "vserver-selflink";
59 private static final String PARAM_VNFC_NAME = "vnfcName";
61 private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
63 public AaiService getAaiService() {
64 return new AaiService();
67 /* Gets VNF Info and All VServers associated with Vnf */
68 public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
70 log.info("Received getVnfInfo call with params : " + inParams);
72 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
76 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
77 AaiService aai = getAaiService();
78 aai.getGenericVnfInfo(inParams, ctx);
80 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
81 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
82 log.info("getVnfInfo Successful ");
83 } catch (Exception e) {
84 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
85 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
86 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
87 log.error("Failed in getVnfInfo", e);
89 throw new SvcLogicException(e.getMessage());
94 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
96 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
98 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
101 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
102 AaiService aai = getAaiService();
104 ArrayList<Map<String, String>> vservers = new ArrayList<>();
106 int vmWithNoVnfcsCount = 0;
107 int vmsWithNoVnfcsForVfModule = 0;
108 int vmCountForVfModule = 0;
109 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
110 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
111 log.info("getAllVServersVnfcsInfo()::: vfMOdule="+vfModuleFromRequest);
113 if (vmCountStr == null) {
114 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
117 int vmCount = Integer.parseInt(vmCountStr);
118 for (int i = 0; i < vmCount; i++) {
120 SvcLogicContext vmServerCtx = new SvcLogicContext();
122 Map<String, String> paramsVm = new HashMap<String, String>();
123 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
124 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
125 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
126 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
127 paramsVm.put(PARAM_VSERVER_SELFLINK, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_SELFLINK));
128 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
129 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
131 aai.getVMInfo(paramsVm, vmServerCtx);
133 HashMap<String, String> vserverMap = new HashMap<String, String>();
134 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
135 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
136 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
137 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
139 // Parameters returned by getVMInfo
140 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
141 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
142 vserverMap.put("vserver-selflink", vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
144 log.info("VSERVER-LINK VALUE:" + vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
146 // as Per 17.07 requirements we are supporting only one VNFC per VM.
148 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
149 vserverMap.put("vnfc-name", vnfcName);
151 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
152 if (vnfcCount == null) {
156 vserverMap.put("vnfc-count", vnfcCount);
157 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
159 if (vnfcName != null) {
160 Map<String, String> paramsVnfc = new HashMap<String, String>();
161 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
163 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
164 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
166 SvcLogicContext vnfcCtx = new SvcLogicContext();
168 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
170 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
172 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
173 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
174 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
175 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
178 vmWithNoVnfcsCount++;
180 log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
181 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
182 vmsWithNoVnfcsForVfModule++;
186 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
187 vmCountForVfModule++;
189 vservers.add(vserverMap);
193 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
195 log.info("SORTED VSERVERS " + vservers.toString());
197 populateContext(vservers, ctx, responsePrefix);
199 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
200 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
201 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
202 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
203 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
204 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
205 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
206 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
209 } catch (Exception e) {
210 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
211 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
212 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
213 log.error("Failed in getAllVServersVnfcsInfo", e);
215 throw new SvcLogicException(e.getMessage());
219 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
221 log.info("Populating Final Context");
224 for (Map<String, String> input : vservers) {
225 for (Entry<String, String> entry : input.entrySet()) {
227 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
228 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
233 String firstVServerName = null;
234 for (int i = 0; i < counter; i++) {
235 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
236 log.info("VNFCNAME " + i + vnfcName);
237 if (vnfcName == null && firstVServerName == null) {
238 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
239 ctx.setAttribute("vm-name", firstVServerName);
240 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
246 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
248 log.info("Received addVnfcs call with params : " + inParams);
250 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
254 int vmWithNoVnfcCount = 0;
258 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
259 AaiService aai = getAaiService();
261 //no:of vnfcs from the vnfc_reference table
262 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
264 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
266 //Vms without vnfc from A&AI
267 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
270 if (vmWithNoVnfcCountStr == null) {
271 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
273 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
276 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
278 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
280 if (vmCountStr == null) {
281 throw new ResourceNodeInternalException("VM data from A&AI is missing");
283 vmCount = Integer.parseInt(vmCountStr);
285 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
286 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
287 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
291 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
292 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
295 log.info("VMCOUNT " + vmCount);
296 log.info("VNFCREFLEN " + vnfcRefLen);
299 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
300 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
303 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
305 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
306 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
308 log.info("addVnfcs Successful ");
309 } catch (Exception e) {
310 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
311 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
312 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
313 log.error("Failed in addVnfcs", e);
315 throw new SvcLogicException(e.getMessage());
319 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
320 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
322 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
323 int vmsWithoutVnfcsForVfModule = 0;
324 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
325 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
326 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule="+vfModuleIdFromRequest);
329 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
331 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: "+vmsWithoutVnfcsForVfModule);
332 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix +"vnf.vm-count-for-vf-module");
333 int vmsForVfModule = 0;
334 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
335 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
337 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
338 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
340 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
344 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
346 if (vnfcRefLenStr == null) {
347 log.info("Vnfc Reference data is missing");
348 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
351 return Integer.parseInt(vnfcRefLenStr);
356 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
358 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
360 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
366 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
367 AaiService aai = getAaiService();
369 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
371 if (vmCountStr == null) {
372 throw new ResourceNodeInternalException("VM data from A&AI is missing");
374 vmCount = Integer.parseInt(vmCountStr);
377 log.info("VMCOUNT " + vmCount);
379 aai.updateVnfStatus(inParams, ctx);
380 aai.updateVServerStatus(inParams, ctx, vmCount);
382 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
383 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
385 log.info("updateVnfAndVServerStatus Successful ");
386 } catch (Exception e) {
387 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
388 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
389 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
390 log.error("Failed in updateVnfAndVServerStatus", e);
392 throw new SvcLogicException(e.getMessage());
396 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
397 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
398 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
400 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
401 AaiService aaiService = getAaiService();
402 String vServerId = inParams.get(PARAM_VSERVER_ID);
403 Map<String, String> params = setVmParams(ctx, vServerId);
404 Map<String, String> vnfcParams = new HashMap<>();
405 if (null == params) {
406 log.error("getVserverInfo()::No Vm Info found!!");
407 throw new SvcLogicException("No Vm Info in Context");
409 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
410 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
411 SvcLogicContext newVmCtx = new SvcLogicContext();
412 aaiService.getVMInfo(params, newVmCtx);
414 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
415 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
416 SvcLogicContext newVnfcCtx = new SvcLogicContext();
417 if (StringUtils.isNotBlank(vnfcName)) {
418 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
420 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
423 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
424 } catch (Exception e) {
425 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
426 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
427 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
428 log.error("Failed in getVserverInfo", e);
432 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
433 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
435 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
436 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
437 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
439 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
441 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
442 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
443 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
444 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
446 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
447 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
448 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
450 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
451 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
452 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
453 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
454 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
455 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
456 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
459 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
460 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
461 Map<String, String> params = new HashMap<>();
464 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
465 if (StringUtils.isNotBlank(vmCountStr)) {
466 vmCount = Integer.parseInt(vmCountStr);
468 for (int cnt = 0; cnt < vmCount; cnt++) {
469 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
470 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
471 if (StringUtils.equals(vServerId, vsId)) {
475 if (arrayIndex < 0) {
476 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
479 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
480 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
481 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
482 String vserverSelflink = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_VSERVER_SELFLINK);
483 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
485 params.put(PARAM_VSERVER_ID, vServerId);
486 params.put(PARAM_TENANT_ID, tenantId);
487 params.put(PARAM_CLOUD_OWNER, cloudOwner);
488 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
489 params.put(PARAM_VSERVER_SELFLINK, vserverSelflink);
490 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
494 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
495 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
496 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
498 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
499 AaiService aaiService = getAaiService();
500 processForVfModuleModelInfo(aaiService,inParams,ctx);
501 } catch (Exception e) {
502 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
503 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
504 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
505 log.error("Failed in vfModuleInfo", e);
509 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
510 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
511 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
513 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
514 Map<String, String> params = new HashMap<>();
515 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
516 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
517 params.put("vnfId", inParams.get("vnf-id"));
518 params.put("vfModuleId", inParams.get("vf-module-id"));
519 SvcLogicContext vfModuleCtx = new SvcLogicContext();
520 aaiService.getVfModuleInfo(params, vfModuleCtx);
522 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
523 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
524 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
526 Map<String, String> modelParams = new HashMap<>();
527 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
528 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
529 SvcLogicContext modelCtx = new SvcLogicContext();
530 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
531 modelParams.put("model-invariant-id", modelInvariantId);
532 modelParams.put("model-version-id", modelVersionId);
535 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
538 aaiService.getModelVersionInfo(modelParams,modelCtx);
539 String modelName = modelCtx.getAttribute(responsePrefix+"vfModule.model-name");
540 log.info("processForVfModuleModelInfo()::modelName for vfModule:::"+modelName);
541 log.info("Setting context template-model-id as :::"+modelName);
542 ctx.setAttribute("template-model-id", modelName);
543 log.info("processForVfModuleModelInfo() ::: End");
545 catch (Exception e) {
546 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
547 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
548 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
549 log.error("Failed in vfModuleInfo", e);
554 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
555 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
556 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
558 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
559 String inputValue = inParams.get("inputParameter");
560 if (StringUtils.isBlank(inputValue)) {
563 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
564 outputValue = StringUtils.replace(outputValue," ","");//remove space
565 ctx.setAttribute("template-model-id", outputValue);
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 getFormattedValue", e);