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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.aai.client.node;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.Comparator;
32 import java.util.HashMap;
33 import java.util.List;
35 import java.util.Map.Entry;
36 import org.apache.commons.lang3.StringUtils;
37 import org.onap.appc.aai.client.AppcAaiClientConstant;
38 import org.onap.appc.aai.client.aai.AaiService;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
43 public class AAIResourceNode implements SvcLogicJavaPlugin {
45 private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
47 private static final String STR_VSERVER_ID = "].vserver-id";
48 private static final String STR_TENANT_ID = "].tenant-id";
49 private static final String STR_CLOUD_OWNER = "].cloud-owner";
50 private static final String STR_CLOUD_REGION_ID = "].cloud-region-id";
51 private static final String STR_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_VNFC_NAME = "vnfcName";
60 private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
62 public AaiService getAaiService() {
63 return new AaiService();
66 /* Gets VNF Info and All VServers associated with Vnf */
67 public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
69 log.info("Received getVnfInfo call with params : " + inParams);
71 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
75 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
76 AaiService aai = getAaiService();
77 aai.getGenericVnfInfo(inParams, ctx);
79 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
80 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
81 log.info("getVnfInfo Successful ");
82 } catch (Exception e) {
83 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
84 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
85 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
86 log.error("Failed in getVnfInfo", e);
88 throw new SvcLogicException(e.getMessage());
93 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
95 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
97 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
100 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
101 AaiService aai = getAaiService();
103 ArrayList<Map<String, String>> vservers = new ArrayList<>();
105 int vmWithNoVnfcsCount = 0;
106 int vmsWithNoVnfcsForVfModule = 0;
107 int vmCountForVfModule = 0;
108 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
109 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
110 log.info("getAllVServersVnfcsInfo()::: vfMOdule="+vfModuleFromRequest);
112 if (vmCountStr == null) {
113 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
116 int vmCount = Integer.parseInt(vmCountStr);
117 for (int i = 0; i < vmCount; i++) {
119 SvcLogicContext vmServerCtx = new SvcLogicContext();
121 Map<String, String> paramsVm = new HashMap<String, String>();
122 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
123 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
124 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
125 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
126 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
127 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
129 aai.getVMInfo(paramsVm, vmServerCtx);
131 HashMap<String, String> vserverMap = new HashMap<String, String>();
132 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
133 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
134 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
135 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
137 // Parameters returned by getVMInfo
138 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
139 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
141 // as Per 17.07 requirements we are supporting only one VNFC per VM.
143 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
144 vserverMap.put("vnfc-name", vnfcName);
146 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
147 if (vnfcCount == null) {
151 vserverMap.put("vnfc-count", vnfcCount);
152 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
154 if (vnfcName != null) {
155 Map<String, String> paramsVnfc = new HashMap<String, String>();
156 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
158 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
159 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
161 SvcLogicContext vnfcCtx = new SvcLogicContext();
163 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
165 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
167 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
168 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
169 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
170 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
173 vmWithNoVnfcsCount++;
175 log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
176 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
177 vmsWithNoVnfcsForVfModule++;
181 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
182 vmCountForVfModule++;
184 vservers.add(vserverMap);
188 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
190 log.info("SORTED VSERVERS " + vservers.toString());
192 populateContext(vservers, ctx, responsePrefix);
194 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
195 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
196 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
197 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
198 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
199 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
200 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
201 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
204 } catch (Exception e) {
205 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
206 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
207 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
208 log.error("Failed in getAllVServersVnfcsInfo", e);
210 throw new SvcLogicException(e.getMessage());
214 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
216 log.info("Populating Final Context");
219 for (Map<String, String> input : vservers) {
220 for (Entry<String, String> entry : input.entrySet()) {
222 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
223 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
228 String firstVServerName = null;
229 for (int i = 0; i < counter; i++) {
230 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
231 log.info("VNFCNAME " + i + vnfcName);
232 if (vnfcName == null && firstVServerName == null) {
233 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
234 ctx.setAttribute("vm-name", firstVServerName);
235 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
241 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
243 log.info("Received addVnfcs call with params : " + inParams);
245 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
249 int vmWithNoVnfcCount = 0;
253 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
254 AaiService aai = getAaiService();
256 //no:of vnfcs from the vnfc_reference table
257 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
259 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
261 //Vms without vnfc from A&AI
262 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
265 if (vmWithNoVnfcCountStr == null) {
266 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
268 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
271 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
273 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
275 if (vmCountStr == null) {
276 throw new ResourceNodeInternalException("VM data from A&AI is missing");
278 vmCount = Integer.parseInt(vmCountStr);
280 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
281 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
282 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
286 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
287 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
290 log.info("VMCOUNT " + vmCount);
291 log.info("VNFCREFLEN " + vnfcRefLen);
294 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
295 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
298 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
300 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
301 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
303 log.info("addVnfcs Successful ");
304 } catch (Exception e) {
305 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
306 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
307 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
308 log.error("Failed in addVnfcs", e);
310 throw new SvcLogicException(e.getMessage());
314 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
315 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
317 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
318 int vmsWithoutVnfcsForVfModule = 0;
319 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
320 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
321 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule="+vfModuleIdFromRequest);
324 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
326 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: "+vmsWithoutVnfcsForVfModule);
327 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix +"vnf.vm-count-for-vf-module");
328 int vmsForVfModule = 0;
329 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
330 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
332 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
333 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
335 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
339 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
341 if (vnfcRefLenStr == null) {
342 log.info("Vnfc Reference data is missing");
343 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
346 return Integer.parseInt(vnfcRefLenStr);
351 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
353 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
355 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
361 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
362 AaiService aai = getAaiService();
364 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
366 if (vmCountStr == null) {
367 throw new ResourceNodeInternalException("VM data from A&AI is missing");
369 vmCount = Integer.parseInt(vmCountStr);
372 log.info("VMCOUNT " + vmCount);
374 aai.updateVnfStatus(inParams, ctx);
375 aai.updateVServerStatus(inParams, ctx, vmCount);
377 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
378 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
380 log.info("updateVnfAndVServerStatus Successful ");
381 } catch (Exception e) {
382 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
383 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
384 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
385 log.error("Failed in updateVnfAndVServerStatus", e);
387 throw new SvcLogicException(e.getMessage());
391 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
392 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
393 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
395 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
396 AaiService aaiService = getAaiService();
397 String vServerId = inParams.get(PARAM_VSERVER_ID);
398 Map<String, String> params = setVmParams(ctx, vServerId);
399 Map<String, String> vnfcParams = new HashMap<>();
400 if (null == params) {
401 log.error("getVserverInfo()::No Vm Info found!!");
402 throw new SvcLogicException("No Vm Info in Context");
404 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
405 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
406 SvcLogicContext newVmCtx = new SvcLogicContext();
407 aaiService.getVMInfo(params, newVmCtx);
409 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
410 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
411 SvcLogicContext newVnfcCtx = new SvcLogicContext();
412 if (StringUtils.isNotBlank(vnfcName)) {
413 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
415 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
418 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
419 } catch (Exception e) {
420 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
421 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
422 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
423 log.error("Failed in getVserverInfo", e);
427 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
428 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
430 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
431 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
432 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
434 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
436 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
437 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
438 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
439 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
441 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
442 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
443 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
445 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
446 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
447 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
448 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
449 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
450 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
451 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
454 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
455 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
456 Map<String, String> params = new HashMap<>();
459 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
460 if (StringUtils.isNotBlank(vmCountStr)) {
461 vmCount = Integer.parseInt(vmCountStr);
463 for (int cnt = 0; cnt < vmCount; cnt++) {
464 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
465 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
466 if (StringUtils.equals(vServerId, vsId)) {
470 if (arrayIndex < 0) {
471 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
474 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
475 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
476 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
477 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
479 params.put(PARAM_VSERVER_ID, vServerId);
480 params.put(PARAM_TENANT_ID, tenantId);
481 params.put(PARAM_CLOUD_OWNER, cloudOwner);
482 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
483 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
487 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
488 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
489 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
491 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
492 AaiService aaiService = getAaiService();
493 processForVfModuleModelInfo(aaiService,inParams,ctx);
494 } catch (Exception e) {
495 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
496 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
497 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
498 log.error("Failed in vfModuleInfo", e);
502 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
503 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
504 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
506 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
507 Map<String, String> params = new HashMap<>();
508 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
509 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
510 params.put("vnfId", inParams.get("vnf-id"));
511 params.put("vfModuleId", inParams.get("vf-module-id"));
512 SvcLogicContext vfModuleCtx = new SvcLogicContext();
513 aaiService.getVfModuleInfo(params, vfModuleCtx);
515 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
516 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
517 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
519 Map<String, String> modelParams = new HashMap<>();
520 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
521 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
522 SvcLogicContext modelCtx = new SvcLogicContext();
523 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
524 modelParams.put("model-invariant-id", modelInvariantId);
525 modelParams.put("model-version-id", modelVersionId);
528 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
531 aaiService.getModelVersionInfo(modelParams,modelCtx);
532 String modelName = modelCtx.getAttribute(responsePrefix+"vfModule.model-name");
533 log.info("processForVfModuleModelInfo()::modelName for vfModule:::"+modelName);
534 log.info("Setting context template-model-id as :::"+modelName);
535 ctx.setAttribute("template-model-id", modelName);
536 log.info("processForVfModuleModelInfo() ::: End");
538 catch (Exception e) {
539 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
540 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
541 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
542 log.error("Failed in vfModuleInfo", e);
547 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
548 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
549 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
551 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
552 String inputValue = inParams.get("inputParameter");
553 if (StringUtils.isBlank(inputValue)) {
556 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
557 outputValue = StringUtils.replace(outputValue," ","");//remove space
558 ctx.setAttribute("template-model-id", outputValue);
559 } catch (Exception e) {
560 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
561 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
562 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
563 log.error("Failed in getFormattedValue", e);