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_TMP_VNF_INFO = "tmp.vnfInfo.vm[";
52 private static final String PARAM_VSERVER_ID = "vserverId";
53 private static final String PARAM_TENANT_ID = "tenantId";
54 private static final String PARAM_CLOUD_OWNER = "cloudOwner";
55 private static final String PARAM_CLOUD_REGION_ID = "cloudRegionId";
56 private static final String PARAM_VSERVER_NAME = "vserver-name";
57 private static final String PARAM_VNFC_NAME = "vnfcName";
59 private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
61 public AaiService getAaiService() {
62 return new AaiService();
65 /* Gets VNF Info and All VServers associated with Vnf */
66 public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
68 log.info("Received getVnfInfo call with params : " + inParams);
70 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
74 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
75 AaiService aai = getAaiService();
76 aai.getGenericVnfInfo(inParams, ctx);
78 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
79 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
80 log.info("getVnfInfo Successful ");
81 } catch (Exception e) {
82 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
83 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
84 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
85 log.error("Failed in getVnfInfo", e);
87 throw new SvcLogicException(e.getMessage());
92 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
94 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
96 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
99 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
100 AaiService aai = getAaiService();
102 ArrayList<Map<String, String>> vservers = new ArrayList<>();
104 int vmWithNoVnfcsCount = 0;
105 int vmsWithNoVnfcsForVfModule = 0;
106 int vmCountForVfModule = 0;
107 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
108 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
109 log.info("getAllVServersVnfcsInfo()::: vfMOdule="+vfModuleFromRequest);
111 if (vmCountStr == null) {
112 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
115 int vmCount = Integer.parseInt(vmCountStr);
116 for (int i = 0; i < vmCount; i++) {
118 SvcLogicContext vmServerCtx = new SvcLogicContext();
120 Map<String, String> paramsVm = new HashMap<String, String>();
121 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
122 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
123 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
124 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
125 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
126 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
128 aai.getVMInfo(paramsVm, vmServerCtx);
130 HashMap<String, String> vserverMap = new HashMap<String, String>();
131 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
132 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
133 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
134 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
136 // Parameters returned by getVMInfo
137 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
138 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
140 // as Per 17.07 requirements we are supporting only one VNFC per VM.
142 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
143 vserverMap.put("vnfc-name", vnfcName);
145 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
146 if (vnfcCount == null) {
150 vserverMap.put("vnfc-count", vnfcCount);
151 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
153 if (vnfcName != null) {
154 Map<String, String> paramsVnfc = new HashMap<String, String>();
155 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
157 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
158 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
160 SvcLogicContext vnfcCtx = new SvcLogicContext();
162 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
164 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
166 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
167 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
168 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
169 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
172 vmWithNoVnfcsCount++;
174 log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
175 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
176 vmsWithNoVnfcsForVfModule++;
180 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
181 vmCountForVfModule++;
183 vservers.add(vserverMap);
187 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
189 log.info("SORTED VSERVERS " + vservers.toString());
191 populateContext(vservers, ctx, responsePrefix);
193 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
194 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
195 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
196 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
197 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
198 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
199 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
200 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
203 } catch (Exception e) {
204 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
205 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
206 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
207 log.error("Failed in getAllVServersVnfcsInfo", e);
209 throw new SvcLogicException(e.getMessage());
213 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
215 log.info("Populating Final Context");
218 for (Map<String, String> input : vservers) {
219 for (Entry<String, String> entry : input.entrySet()) {
221 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
222 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
227 String firstVServerName = null;
228 for (int i = 0; i < counter; i++) {
229 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
230 log.info("VNFCNAME " + i + vnfcName);
231 if (vnfcName == null && firstVServerName == null) {
232 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
233 ctx.setAttribute("vm-name", firstVServerName);
234 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
240 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
242 log.info("Received addVnfcs call with params : " + inParams);
244 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
248 int vmWithNoVnfcCount = 0;
252 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
253 AaiService aai = getAaiService();
255 //no:of vnfcs from the vnfc_reference table
256 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
258 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
260 //Vms without vnfc from A&AI
261 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
264 if (vmWithNoVnfcCountStr == null) {
265 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
267 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
270 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
272 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
274 if (vmCountStr == null) {
275 throw new ResourceNodeInternalException("VM data from A&AI is missing");
277 vmCount = Integer.parseInt(vmCountStr);
279 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
280 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
281 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
285 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
286 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
289 log.info("VMCOUNT " + vmCount);
290 log.info("VNFCREFLEN " + vnfcRefLen);
293 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
294 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
297 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
299 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
300 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
302 log.info("addVnfcs Successful ");
303 } catch (Exception e) {
304 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
305 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
306 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
307 log.error("Failed in addVnfcs", e);
309 throw new SvcLogicException(e.getMessage());
313 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
314 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
316 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
317 int vmsWithoutVnfcsForVfModule = 0;
318 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
319 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
320 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule="+vfModuleIdFromRequest);
323 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
325 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: "+vmsWithoutVnfcsForVfModule);
326 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix +"vnf.vm-count-for-vf-module");
327 int vmsForVfModule = 0;
328 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
329 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
331 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
332 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
334 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
338 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
340 if (vnfcRefLenStr == null) {
341 log.info("Vnfc Reference data is missing");
342 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
345 return Integer.parseInt(vnfcRefLenStr);
350 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
352 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
354 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
360 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
361 AaiService aai = getAaiService();
363 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
365 if (vmCountStr == null) {
366 throw new ResourceNodeInternalException("VM data from A&AI is missing");
368 vmCount = Integer.parseInt(vmCountStr);
371 log.info("VMCOUNT " + vmCount);
373 aai.updateVnfStatus(inParams, ctx);
374 aai.updateVServerStatus(inParams, ctx, vmCount);
376 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
377 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
379 log.info("updateVnfAndVServerStatus Successful ");
380 } catch (Exception e) {
381 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
382 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
383 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
384 log.error("Failed in updateVnfAndVServerStatus", e);
386 throw new SvcLogicException(e.getMessage());
390 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
391 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
392 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
394 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
395 AaiService aaiService = getAaiService();
396 String vServerId = inParams.get(PARAM_VSERVER_ID);
397 Map<String, String> params = setVmParams(ctx, vServerId);
398 Map<String, String> vnfcParams = new HashMap<>();
399 if (null == params) {
400 log.error("getVserverInfo()::No Vm Info found!!");
401 throw new SvcLogicException("No Vm Info in Context");
403 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
404 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
405 SvcLogicContext newVmCtx = new SvcLogicContext();
406 aaiService.getVMInfo(params, newVmCtx);
408 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
409 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
410 SvcLogicContext newVnfcCtx = new SvcLogicContext();
411 if (StringUtils.isNotBlank(vnfcName)) {
412 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
414 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
417 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
418 } catch (Exception e) {
419 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
420 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
421 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
422 log.error("Failed in getVserverInfo", e);
426 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
427 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
429 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
430 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
431 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
433 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
435 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
436 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
437 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
438 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
440 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
441 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
442 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
444 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
445 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
446 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
447 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
448 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
449 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
450 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
453 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
454 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
455 Map<String, String> params = new HashMap<>();
458 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
459 if (StringUtils.isNotBlank(vmCountStr)) {
460 vmCount = Integer.parseInt(vmCountStr);
462 for (int cnt = 0; cnt < vmCount; cnt++) {
463 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
464 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
465 if (StringUtils.equals(vServerId, vsId)) {
469 if (arrayIndex < 0) {
470 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
473 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
474 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
475 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
476 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
478 params.put(PARAM_VSERVER_ID, vServerId);
479 params.put(PARAM_TENANT_ID, tenantId);
480 params.put(PARAM_CLOUD_OWNER, cloudOwner);
481 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
482 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
486 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
487 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
488 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
490 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
491 AaiService aaiService = getAaiService();
492 processForVfModuleModelInfo(aaiService,inParams,ctx);
493 } catch (Exception e) {
494 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
495 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
496 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
497 log.error("Failed in vfModuleInfo", e);
501 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
502 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
503 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
505 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
506 Map<String, String> params = new HashMap<>();
507 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
508 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
509 params.put("vnfId", inParams.get("vnf-id"));
510 params.put("vfModuleId", inParams.get("vf-module-id"));
511 SvcLogicContext vfModuleCtx = new SvcLogicContext();
512 aaiService.getVfModuleInfo(params, vfModuleCtx);
514 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
515 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
516 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
518 Map<String, String> modelParams = new HashMap<>();
519 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
520 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
521 SvcLogicContext modelCtx = new SvcLogicContext();
522 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
523 modelParams.put("model-invariant-id", modelInvariantId);
524 modelParams.put("model-version-id", modelVersionId);
527 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
530 aaiService.getModelVersionInfo(modelParams,modelCtx);
531 String modelName = modelCtx.getAttribute(responsePrefix+"vfModule.model-name");
532 log.info("processForVfModuleModelInfo()::modelName for vfModule:::"+modelName);
533 log.info("Setting context template-model-id as :::"+modelName);
534 ctx.setAttribute("template-model-id", modelName);
535 log.info("processForVfModuleModelInfo() ::: End");
537 catch (Exception e) {
538 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
539 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
540 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
541 log.error("Failed in vfModuleInfo", e);
546 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
547 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
548 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
550 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
551 String inputValue = inParams.get("inputParameter");
552 if (StringUtils.isBlank(inputValue)) {
555 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
556 outputValue = StringUtils.replace(outputValue," ","");//remove space
557 ctx.setAttribute("template-model-id", outputValue);
558 } catch (Exception e) {
559 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
560 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
561 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
562 log.error("Failed in getFormattedValue", e);