2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.aai.client.node;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Comparator;
33 import java.util.HashMap;
34 import java.util.List;
36 import java.util.Map.Entry;
37 import org.apache.commons.lang3.StringUtils;
38 import org.onap.appc.aai.client.AppcAaiClientConstant;
39 import org.onap.appc.aai.client.aai.AaiService;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
44 public class AAIResourceNode implements SvcLogicJavaPlugin {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
48 private static final String STR_VSERVER_ID = "].vserver-id";
49 private static final String STR_TENANT_ID = "].tenant-id";
50 private static final String STR_CLOUD_OWNER = "].cloud-owner";
51 private static final String STR_CLOUD_REGION_ID = "].cloud-region-id";
52 private static final String STR_VSERVER_SELFLINK ="].vserver-selflink";
53 private static final String STR_TMP_VNF_INFO = "tmp.vnfInfo.vm[";
55 private static final String PARAM_VSERVER_ID = "vserverId";
56 private static final String PARAM_TENANT_ID = "tenantId";
57 private static final String PARAM_CLOUD_OWNER = "cloudOwner";
58 private static final String PARAM_CLOUD_REGION_ID = "cloudRegionId";
59 private static final String PARAM_VSERVER_NAME = "vserver-name";
60 private static final String PARAM_VSERVER_SELFLINK = "vserver-selflink";
61 private static final String PARAM_VNFC_NAME = "vnfcName";
63 private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
65 public AaiService getAaiService() {
66 return new AaiService();
69 /* Gets VNF Info and All VServers associated with Vnf */
70 public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
72 log.info("Received getVnfInfo call with params : " + inParams);
74 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
78 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
79 AaiService aai = getAaiService();
80 aai.getGenericVnfInfo(inParams, ctx);
82 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
83 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
84 log.info("getVnfInfo Successful ");
85 } catch (Exception e) {
86 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
87 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
88 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
89 log.error("Failed in getVnfInfo", e);
91 throw new SvcLogicException(e.getMessage());
96 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
98 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
100 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
103 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
104 AaiService aai = getAaiService();
106 ArrayList<Map<String, String>> vservers = new ArrayList<>();
108 int vmWithNoVnfcsCount = 0;
109 int vmsWithNoVnfcsForVfModule = 0;
110 int vmCountForVfModule = 0;
111 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
112 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
113 log.info("getAllVServersVnfcsInfo()::: vfMOdule="+vfModuleFromRequest);
115 if (vmCountStr == null) {
116 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
119 int vmCount = Integer.parseInt(vmCountStr);
120 for (int i = 0; i < vmCount; i++) {
122 SvcLogicContext vmServerCtx = new SvcLogicContext();
124 Map<String, String> paramsVm = new HashMap<>();
125 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
126 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
127 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
128 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
129 paramsVm.put(PARAM_VSERVER_SELFLINK, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_SELFLINK));
130 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
131 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
133 aai.getVMInfo(paramsVm, vmServerCtx);
135 HashMap<String, String> vserverMap = new HashMap<>();
136 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
137 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
138 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
139 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
141 // Parameters returned by getVMInfo
142 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
143 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
144 vserverMap.put(PARAM_VSERVER_SELFLINK, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
146 log.info("VSERVER-LINK VALUE:" + vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
148 // as Per 17.07 requirements we are supporting only one VNFC per VM.
150 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
151 vserverMap.put("vnfc-name", vnfcName);
153 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
154 if (vnfcCount == null) {
158 vserverMap.put("vnfc-count", vnfcCount);
159 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
161 if (vnfcName != null) {
162 Map<String, String> paramsVnfc = new HashMap<String, String>();
163 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
165 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
166 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
168 SvcLogicContext vnfcCtx = new SvcLogicContext();
170 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
172 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
174 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
175 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
176 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
177 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
180 vmWithNoVnfcsCount++;
182 log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
183 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
184 vmsWithNoVnfcsForVfModule++;
188 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
189 vmCountForVfModule++;
191 vservers.add(vserverMap);
195 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
197 log.info("SORTED VSERVERS " + vservers.toString());
199 populateContext(vservers, ctx, responsePrefix);
201 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
202 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
203 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
204 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
205 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
206 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
207 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
208 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
211 } catch (Exception e) {
212 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
213 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
214 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
215 log.error("Failed in getAllVServersVnfcsInfo", e);
217 throw new SvcLogicException(e.getMessage());
221 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
223 log.info("Populating Final Context");
226 for (Map<String, String> input : vservers) {
227 for (Entry<String, String> entry : input.entrySet()) {
229 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
230 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
235 String firstVServerName = null;
236 for (int i = 0; i < counter; i++) {
237 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
238 log.info("VNFCNAME " + i + vnfcName);
239 if (vnfcName == null && firstVServerName == null) {
240 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
241 ctx.setAttribute("vm-name", firstVServerName);
242 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
248 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
250 log.info("Received addVnfcs call with params : " + inParams);
252 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
256 int vmWithNoVnfcCount = 0;
260 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
261 AaiService aai = getAaiService();
263 //no:of vnfcs from the vnfc_reference table
264 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
266 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
268 //Vms without vnfc from A&AI
269 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
272 if (vmWithNoVnfcCountStr == null) {
273 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
275 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
278 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
280 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
282 if (vmCountStr == null) {
283 throw new ResourceNodeInternalException("VM data from A&AI is missing");
285 vmCount = Integer.parseInt(vmCountStr);
287 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
288 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
289 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
293 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
294 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
297 log.info("VMCOUNT " + vmCount);
298 log.info("VNFCREFLEN " + vnfcRefLen);
301 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
302 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
305 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
307 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
308 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
310 log.info("addVnfcs Successful ");
311 } catch (Exception e) {
312 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
313 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
314 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
315 log.error("Failed in addVnfcs", e);
317 throw new SvcLogicException(e.getMessage());
321 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
322 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
324 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
325 int vmsWithoutVnfcsForVfModule = 0;
326 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
327 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
328 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule="+vfModuleIdFromRequest);
331 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
333 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: "+vmsWithoutVnfcsForVfModule);
334 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix +"vnf.vm-count-for-vf-module");
335 int vmsForVfModule = 0;
336 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
337 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
339 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
340 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
342 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
346 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
348 if (vnfcRefLenStr == null) {
349 log.info("Vnfc Reference data is missing");
350 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
353 return Integer.parseInt(vnfcRefLenStr);
358 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
360 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
362 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
368 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
369 AaiService aai = getAaiService();
371 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
373 if (vmCountStr == null) {
374 throw new ResourceNodeInternalException("VM data from A&AI is missing");
376 vmCount = Integer.parseInt(vmCountStr);
379 log.info("VMCOUNT " + vmCount);
381 aai.updateVnfStatus(inParams, ctx);
382 aai.updateVServerStatus(inParams, ctx, vmCount);
384 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
385 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
387 log.info("updateVnfAndVServerStatus Successful ");
388 } catch (Exception e) {
389 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
390 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
391 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
392 log.error("Failed in updateVnfAndVServerStatus", e);
394 throw new SvcLogicException(e.getMessage());
398 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
399 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
400 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
402 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
403 AaiService aaiService = getAaiService();
404 String vServerId = inParams.get(PARAM_VSERVER_ID);
405 Map<String, String> params = setVmParams(ctx, vServerId);
406 Map<String, String> vnfcParams = new HashMap<>();
407 if (null == params) {
408 log.error("getVserverInfo()::No Vm Info found!!");
409 throw new SvcLogicException("No Vm Info in Context");
411 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
412 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
413 SvcLogicContext newVmCtx = new SvcLogicContext();
414 aaiService.getVMInfo(params, newVmCtx);
416 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
417 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
418 SvcLogicContext newVnfcCtx = new SvcLogicContext();
419 if (StringUtils.isNotBlank(vnfcName)) {
420 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
422 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
425 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
426 } catch (Exception e) {
427 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
428 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
429 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
430 log.error("Failed in getVserverInfo", e);
434 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
435 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
437 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
438 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
439 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
441 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
443 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
444 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
445 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
446 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
448 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
449 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
450 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
452 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
453 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
454 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
455 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
456 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
457 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
458 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
461 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
462 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
463 Map<String, String> params = new HashMap<>();
466 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
467 if (StringUtils.isNotBlank(vmCountStr)) {
468 vmCount = Integer.parseInt(vmCountStr);
470 for (int cnt = 0; cnt < vmCount; cnt++) {
471 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
472 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
473 if (StringUtils.equals(vServerId, vsId)) {
477 if (arrayIndex < 0) {
478 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
481 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
482 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
483 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
484 String vserverSelflink = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_VSERVER_SELFLINK);
485 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
487 params.put(PARAM_VSERVER_ID, vServerId);
488 params.put(PARAM_TENANT_ID, tenantId);
489 params.put(PARAM_CLOUD_OWNER, cloudOwner);
490 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
491 params.put(PARAM_VSERVER_SELFLINK, vserverSelflink);
492 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
496 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
497 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
498 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
500 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
501 AaiService aaiService = getAaiService();
502 processForVfModuleModelInfo(aaiService,inParams,ctx);
503 } catch (Exception e) {
504 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
505 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
506 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
507 log.error("Failed in vfModuleInfo", e);
511 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
512 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
513 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
515 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
516 Map<String, String> params = new HashMap<>();
517 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
518 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
519 params.put("vnfId", inParams.get("vnf-id"));
520 params.put("vfModuleId", inParams.get("vf-module-id"));
521 SvcLogicContext vfModuleCtx = new SvcLogicContext();
522 aaiService.getVfModuleInfo(params, vfModuleCtx);
524 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
525 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
526 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
528 Map<String, String> modelParams = new HashMap<>();
529 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
530 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
531 SvcLogicContext modelCtx = new SvcLogicContext();
532 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
533 modelParams.put("model-invariant-id", modelInvariantId);
534 modelParams.put("model-version-id", modelVersionId);
537 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
540 aaiService.getModelVersionInfo(modelParams,modelCtx);
541 String modelName = modelCtx.getAttribute(responsePrefix+"vfModule.model-name");
542 log.info("processForVfModuleModelInfo()::modelName for vfModule:::"+modelName);
543 log.info("Setting context template-model-id as :::"+modelName);
544 ctx.setAttribute("template-model-id", modelName);
545 log.info("processForVfModuleModelInfo() ::: End");
547 catch (Exception e) {
548 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
549 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
550 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
551 log.error("Failed in vfModuleInfo", e);
556 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
557 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
558 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
560 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
561 String inputValue = inParams.get("inputParameter");
562 if (StringUtils.isBlank(inputValue)) {
565 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
566 outputValue = StringUtils.replace(outputValue," ","");//remove space
567 ctx.setAttribute("template-model-id", outputValue);
568 } catch (Exception e) {
569 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
570 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
571 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
572 log.error("Failed in getFormattedValue", e);