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 String cloudOwnerValue=ctx.getAttribute(responsePrefix + "vm[0].cloud-owner");
83 String cloudRegionValue=ctx.getAttribute(responsePrefix + "vm[0].cloud-region-id");
85 log.debug("Cloud Owner" + cloudOwnerValue);
86 log.debug("CloudRegionId" + cloudOwnerValue);
87 SvcLogicContext cloudCtx = new SvcLogicContext();
88 Map<String, String> paramsCloud = new HashMap<String, String>();
89 paramsCloud.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
90 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
92 if(StringUtils.isNotBlank(cloudOwnerValue)&&StringUtils.isNotBlank(cloudRegionValue)) {
94 paramsCloud.put("cloudOwner", cloudOwnerValue);
95 paramsCloud.put("cloudRegionId", cloudRegionValue);
97 aai.getIdentityUrl(paramsCloud, ctx);
100 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
101 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
102 log.info("getVnfInfo Successful ");
103 } catch (Exception e) {
104 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
105 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
106 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
107 log.error("Failed in getVnfInfo", e);
109 throw new SvcLogicException(e.getMessage());
114 public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
116 log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
118 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
121 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
122 AaiService aai = getAaiService();
124 ArrayList<Map<String, String>> vservers = new ArrayList<>();
126 int vmWithNoVnfcsCount = 0;
127 int vmsWithNoVnfcsForVfModule = 0;
128 int vmCountForVfModule = 0;
129 String vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
130 String vfModuleFromRequest = ctx.getAttribute("req-vf-module-id");
131 log.info("getAllVServersVnfcsInfo()::: vfMOdule="+vfModuleFromRequest);
133 if (vmCountStr == null) {
134 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
137 int vmCount = Integer.parseInt(vmCountStr);
138 for (int i = 0; i < vmCount; i++) {
140 SvcLogicContext vmServerCtx = new SvcLogicContext();
142 Map<String, String> paramsVm = new HashMap<>();
143 paramsVm.put(PARAM_VSERVER_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
144 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
145 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
146 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
147 paramsVm.put(PARAM_VSERVER_SELFLINK, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_SELFLINK));
148 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
149 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
151 aai.getVMInfo(paramsVm, vmServerCtx);
153 HashMap<String, String> vserverMap = new HashMap<>();
154 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_ID));
155 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
156 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
157 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
159 // Parameters returned by getVMInfo
160 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
161 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
162 vserverMap.put(PARAM_VSERVER_SELFLINK, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
164 log.info("VSERVER-LINK VALUE:" + vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
166 // as Per 17.07 requirements we are supporting only one VNFC per VM.
168 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
169 vserverMap.put("vnfc-name", vnfcName);
171 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
172 if (vnfcCount == null) {
176 vserverMap.put("vnfc-count", vnfcCount);
177 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
179 if (vnfcName != null) {
180 Map<String, String> paramsVnfc = new HashMap<String, String>();
181 paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
183 paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
184 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
186 SvcLogicContext vnfcCtx = new SvcLogicContext();
188 aai.getVnfcInfo(paramsVnfc, vnfcCtx);
190 vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
192 .put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
193 vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
194 vserverMap.put("vnfc-ipaddress-v4-oam-vip",
195 vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
198 vmWithNoVnfcsCount++;
200 log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
201 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
202 vmsWithNoVnfcsForVfModule++;
206 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
207 vmCountForVfModule++;
209 vservers.add(vserverMap);
213 Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
215 log.info("SORTED VSERVERS " + vservers.toString());
217 populateContext(vservers, ctx, responsePrefix);
219 log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
220 log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
221 log.info("VMSWITHNOVNFCSCOUNTFOR VFMODULE IN GETALLVSERVERS " + vmsWithNoVnfcsForVfModule);
222 log.info("VMCOUNT FOR VFMODULE IN GETALLVSERVERS " + vmCountForVfModule);
223 ctx.setAttribute(responsePrefix + ATTR_VNF_VM_COUNT, String.valueOf(vmCount));
224 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
225 ctx.setAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module", String.valueOf(vmsWithNoVnfcsForVfModule));
226 ctx.setAttribute(responsePrefix + "vnf.vm-count-for-vf-module", String.valueOf(vmCountForVfModule));
229 } catch (Exception e) {
230 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
231 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
232 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
233 log.error("Failed in getAllVServersVnfcsInfo", e);
235 throw new SvcLogicException(e.getMessage());
239 public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
241 log.info("Populating Final Context");
244 for (Map<String, String> input : vservers) {
245 for (Entry<String, String> entry : input.entrySet()) {
247 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
248 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
253 String firstVServerName = null;
254 for (int i = 0; i < counter; i++) {
255 String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
256 log.info("VNFCNAME " + i + vnfcName);
257 if (vnfcName == null && firstVServerName == null) {
258 firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
259 ctx.setAttribute("vm-name", firstVServerName);
260 log.info("Populating Context Key = " + "vm-name" + " Value = " + firstVServerName);
266 public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
268 log.info("Received addVnfcs call with params : " + inParams);
270 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
274 int vmWithNoVnfcCount = 0;
278 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
279 AaiService aai = getAaiService();
281 //no:of vnfcs from the vnfc_reference table
282 String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
284 vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
286 //Vms without vnfc from A&AI
287 String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
290 if (vmWithNoVnfcCountStr == null) {
291 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
293 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
296 log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
298 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
300 if (vmCountStr == null) {
301 throw new ResourceNodeInternalException("VM data from A&AI is missing");
303 vmCount = Integer.parseInt(vmCountStr);
305 String vfModuleIdFromRequest = ctx.getAttribute("req-vf-module-id");
306 if ((vmCount < vnfcRefLen) && StringUtils.isBlank(vfModuleIdFromRequest)) {
307 throw new ResourceNodeInternalException("Vnfc and VM count mismatch");
311 if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
312 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
315 log.info("VMCOUNT " + vmCount);
316 log.info("VNFCREFLEN " + vnfcRefLen);
319 if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
320 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
323 aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
325 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
326 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
328 log.info("addVnfcs Successful ");
329 } catch (Exception e) {
330 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
331 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
332 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
333 log.error("Failed in addVnfcs", e);
335 throw new SvcLogicException(e.getMessage());
339 public void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
340 String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
342 log.info("processCheckForVfModule()::vfModuleId From Request"+vfModuleIdFromRequest+"-"+vnfcRefLen);
343 int vmsWithoutVnfcsForVfModule = 0;
344 String vmsWithoutVnfcsForVfModuleStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count-vf-module");
345 if (StringUtils.isBlank(vmsWithoutVnfcsForVfModuleStr) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
346 log.info("addVnfcs()::No vmsWithoutVnfcsForVfModule (is null) for vfmodule="+vfModuleIdFromRequest);
349 vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
351 log.info("addVnfcs():::Number of VMs without vnfcs for vfmodule: "+vmsWithoutVnfcsForVfModule);
352 String vmsForVfModuleStr = ctx.getAttribute(responsePrefix +"vnf.vm-count-for-vf-module");
353 int vmsForVfModule = 0;
354 if (StringUtils.isNotBlank(vmsForVfModuleStr)) {
355 vmsForVfModule = Integer.parseInt(vmsForVfModuleStr);
357 if ((vmsForVfModule != vnfcRefLen ) && StringUtils.isNotBlank(vfModuleIdFromRequest)) {
358 throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
360 log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
364 private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
366 if (vnfcRefLenStr == null) {
367 log.info("Vnfc Reference data is missing");
368 throw new ResourceNodeInternalException("Vnfc Reference data is missing");
371 return Integer.parseInt(vnfcRefLenStr);
376 public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
378 log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
380 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
386 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
387 AaiService aai = getAaiService();
389 String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
391 if (vmCountStr == null) {
392 throw new ResourceNodeInternalException("VM data from A&AI is missing");
394 vmCount = Integer.parseInt(vmCountStr);
397 log.info("VMCOUNT " + vmCount);
399 aai.updateVnfStatus(inParams, ctx);
400 aai.updateVServerStatus(inParams, ctx, vmCount);
402 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
403 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
405 log.info("updateVnfAndVServerStatus Successful ");
406 } catch (Exception e) {
407 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
408 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
409 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
410 log.error("Failed in updateVnfAndVServerStatus", e);
412 throw new SvcLogicException(e.getMessage());
416 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
417 log.info("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
418 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
420 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
421 AaiService aaiService = getAaiService();
422 String vServerId = inParams.get(PARAM_VSERVER_ID);
423 Map<String, String> params = setVmParams(ctx, vServerId);
424 Map<String, String> vnfcParams = new HashMap<>();
425 if (null == params) {
426 log.error("getVserverInfo()::No Vm Info found!!");
427 throw new SvcLogicException("No Vm Info in Context");
429 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
430 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
431 SvcLogicContext newVmCtx = new SvcLogicContext();
432 aaiService.getVMInfo(params, newVmCtx);
434 String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
435 log.info("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
436 SvcLogicContext newVnfcCtx = new SvcLogicContext();
437 if (StringUtils.isNotBlank(vnfcName)) {
438 vnfcParams.put(PARAM_VNFC_NAME, vnfcName);
440 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
443 getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
444 } catch (Exception e) {
445 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
446 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
447 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
448 log.error("Failed in getVserverInfo", e);
452 public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
453 Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
455 log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
456 vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
457 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
459 aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
461 String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
462 String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
463 String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
464 String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
466 if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
467 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
468 log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
470 log.info("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
471 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
472 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get(PARAM_VNFC_NAME));
473 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
474 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
475 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
476 ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
479 public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
480 log.info("setVmParams()::setVmParamsVM level action:" + vServerId);
481 Map<String, String> params = new HashMap<>();
484 String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
485 if (StringUtils.isNotBlank(vmCountStr)) {
486 vmCount = Integer.parseInt(vmCountStr);
488 for (int cnt = 0; cnt < vmCount; cnt++) {
489 String vsId = ctx.getAttribute(STR_TMP_VNF_INFO + cnt + STR_VSERVER_ID);
490 log.info("setVmParams():::vserver details::" + cnt + ":" + vsId);
491 if (StringUtils.equals(vServerId, vsId)) {
495 if (arrayIndex < 0) {
496 log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
499 String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
500 String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
501 String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
502 String vserverSelflink = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_VSERVER_SELFLINK);
503 log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
505 params.put(PARAM_VSERVER_ID, vServerId);
506 params.put(PARAM_TENANT_ID, tenantId);
507 params.put(PARAM_CLOUD_OWNER, cloudOwner);
508 params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
509 params.put(PARAM_VSERVER_SELFLINK, vserverSelflink);
510 log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
514 public void getVfModuleModelInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
515 log.info("vfModuleInfo()::Retrieving vf-module information :" + inParams.toString());
516 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
518 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
519 AaiService aaiService = getAaiService();
520 processForVfModuleModelInfo(aaiService,inParams,ctx);
521 } catch (Exception e) {
522 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
523 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
524 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
525 log.error("Failed in vfModuleInfo", e);
529 public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
530 log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams);
531 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
533 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
534 Map<String, String> params = new HashMap<>();
535 params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
536 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
537 params.put("vnfId", inParams.get("vnf-id"));
538 params.put("vfModuleId", inParams.get("vf-module-id"));
539 SvcLogicContext vfModuleCtx = new SvcLogicContext();
540 aaiService.getVfModuleInfo(params, vfModuleCtx);
542 String modelInvariantId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-invariant-id");
543 String modelVersionId = vfModuleCtx.getAttribute(responsePrefix + "vfModule.model-version-id");
544 log.info("processForVfModuleModelInfo()::modelInvariantId=" + modelInvariantId+",modelVersionId="+modelVersionId);
546 Map<String, String> modelParams = new HashMap<>();
547 modelParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
548 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
549 SvcLogicContext modelCtx = new SvcLogicContext();
550 if (StringUtils.isNotBlank(modelInvariantId) && StringUtils.isNotBlank(modelVersionId)) {
551 modelParams.put("model-invariant-id", modelInvariantId);
552 modelParams.put("model-version-id", modelVersionId);
555 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
558 aaiService.getModelVersionInfo(modelParams,modelCtx);
559 String modelName = modelCtx.getAttribute(responsePrefix+"vfModule.model-name");
560 log.info("processForVfModuleModelInfo()::modelName for vfModule:::"+modelName);
561 log.info("Setting context template-model-id as :::"+modelName);
562 ctx.setAttribute("template-model-id", modelName);
563 log.info("processForVfModuleModelInfo() ::: End");
565 catch (Exception e) {
566 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
567 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
568 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
569 log.error("Failed in vfModuleInfo", e);
574 public void getFormattedValue(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
575 log.info("getFormattedValue()::Formatting values :" + inParams.toString());
576 String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
578 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
579 String inputValue = inParams.get("inputParameter");
580 if (StringUtils.isBlank(inputValue)) {
583 String outputValue = StringUtils.replace(inputValue, "/", "_");//change / to _
584 outputValue = StringUtils.replace(outputValue," ","");//remove space
585 ctx.setAttribute("template-model-id", outputValue);
586 } catch (Exception e) {
587 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
588 AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
589 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
590 log.error("Failed in getFormattedValue", e);