073ca12f4293b5b402bea7739d12f80a5e6294a1
[appc.git] / appc-outbound / appc-aai-client / provider / src / main / java / org / onap / appc / aai / client / node / AAIResourceNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.aai.client.node;
26
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;
34 import java.util.Map;
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;
42
43 public class AAIResourceNode implements SvcLogicJavaPlugin {
44
45     private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
46
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[";
52
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";
59
60     private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
61
62     public AaiService getAaiService() {
63         return new AaiService();
64     }
65
66     /* Gets VNF Info and All VServers associated with Vnf */
67     public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
68
69         log.info("Received getVnfInfo call with params : " + inParams);
70
71         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
72
73         try {
74
75             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
76             AaiService aai = getAaiService();
77             aai.getGenericVnfInfo(inParams, ctx);
78
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);
87
88             throw new SvcLogicException(e.getMessage());
89         }
90     }
91
92
93     public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
94
95         log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
96
97         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
98
99         try {
100             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
101             AaiService aai = getAaiService();
102
103             ArrayList<Map<String, String>> vservers = new ArrayList<>();
104
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);
111
112             if (vmCountStr == null) {
113                 throw new ResourceNodeInternalException("Unable to get VServers for the VNF");
114             }
115
116             int vmCount = Integer.parseInt(vmCountStr);
117             for (int i = 0; i < vmCount; i++) {
118
119                 SvcLogicContext vmServerCtx = new SvcLogicContext();
120
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));
128
129                 aai.getVMInfo(paramsVm, vmServerCtx);
130
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));
136
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"));
140
141                 // as Per 17.07 requirements we are supporting only one VNFC per VM.
142
143                 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
144                 vserverMap.put("vnfc-name", vnfcName);
145
146                 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
147                 if (vnfcCount == null) {
148                     vnfcCount = "0";
149                 }
150
151                 vserverMap.put("vnfc-count", vnfcCount);
152                 String vfModuleForVserver = vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id");
153
154                 if (vnfcName != null) {
155                     Map<String, String> paramsVnfc = new HashMap<String, String>();
156                     paramsVnfc.put(PARAM_VNFC_NAME, vnfcName);
157
158                     paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
159                         inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
160
161                     SvcLogicContext vnfcCtx = new SvcLogicContext();
162
163                     aai.getVnfcInfo(paramsVnfc, vnfcCtx);
164
165                     vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
166                     vserverMap
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"));
171
172                 } else {
173                     vmWithNoVnfcsCount++;
174                     //ConfigScaleOut
175                     log.info("getAllVServersVnfcsInfo()::Vf Modules: "+vfModuleForVserver+", "+vfModuleFromRequest);
176                     if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)) {
177                         vmsWithNoVnfcsForVfModule++;
178                     }
179                 }
180
181                 if (StringUtils.isNotBlank(vfModuleFromRequest) && StringUtils.isNotBlank(vfModuleForVserver) && StringUtils.equalsIgnoreCase(vfModuleForVserver,vfModuleFromRequest)){
182                     vmCountForVfModule++;
183                 }
184                 vservers.add(vserverMap);
185
186             } // vmCount
187
188             Collections.sort(vservers, Comparator.comparing(o -> o.get(PARAM_VSERVER_NAME)));
189
190             log.info("SORTED VSERVERS " + vservers.toString());
191
192             populateContext(vservers, ctx, responsePrefix);
193
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));
202
203
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);
209
210             throw new SvcLogicException(e.getMessage());
211         }
212     }
213
214     public void populateContext(List<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
215
216         log.info("Populating Final Context");
217         int counter = 0;
218
219         for (Map<String, String> input : vservers) {
220             for (Entry<String, String> entry : input.entrySet()) {
221
222                 ctx.setAttribute(prefix + "vm[" + counter + "]." + entry.getKey(), entry.getValue());
223                 log.info("Populating Context Key = " + prefix + "vm[" + counter + "]." + entry.getKey() + " Value = " + entry.getValue());
224             }
225             counter++;
226         }
227
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);
236             }
237         }
238     }
239
240
241     public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
242
243         log.info("Received addVnfcs call with params : " + inParams);
244
245         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
246
247         int vnfcRefLen;
248         int vmCount;
249         int vmWithNoVnfcCount = 0;
250
251         try {
252
253             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
254             AaiService aai = getAaiService();
255
256             //no:of vnfcs from the vnfc_reference table
257             String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
258
259             vnfcRefLen = trySetVnfcRefLen(vnfcRefLenStr);
260
261             //Vms without vnfc from A&AI
262             String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix + "vnf.vm-with-no-vnfcs-count");
263
264             // Modified for 1710
265             if (vmWithNoVnfcCountStr == null) {
266                 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
267             } else {
268                 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
269             }
270
271             log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " + vmWithNoVnfcCount);
272
273             String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
274
275             if (vmCountStr == null) {
276                 throw new ResourceNodeInternalException("VM data from A&AI is missing");
277             } else {
278                 vmCount = Integer.parseInt(vmCountStr);
279             }
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");
283             }
284
285             //ConfigScaleOut
286             if (StringUtils.isNotBlank(vfModuleIdFromRequest)) {
287                 processCheckForVfModule(vfModuleIdFromRequest, ctx, responsePrefix,vnfcRefLen);
288             }
289
290             log.info("VMCOUNT " + vmCount);
291             log.info("VNFCREFLEN " + vnfcRefLen);
292
293
294             if (StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
295                 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
296             }
297
298             aai.insertVnfcs(inParams, ctx, vnfcRefLen, vmCount,vfModuleIdFromRequest);
299
300             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
301                 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
302
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);
309
310             throw new SvcLogicException(e.getMessage());
311         }
312     }
313
314     private void processCheckForVfModule(String vfModuleIdFromRequest, SvcLogicContext ctx,
315     String responsePrefix, int vnfcRefLen) throws ResourceNodeInternalException {
316
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);
322         }
323         else {
324             vmsWithoutVnfcsForVfModule = Integer.parseInt(vmsWithoutVnfcsForVfModuleStr);
325         }
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);
331         }
332         if ((vmsForVfModule != vnfcRefLen ) &&  StringUtils.isNotBlank(vfModuleIdFromRequest)) {
333             throw new ResourceNodeInternalException("Vnfc and VM count mismatch for vfModule in request="+vfModuleIdFromRequest);
334         }
335         log.info("processCheckForVfModule()::vmsForVfModule " + vmsForVfModule);
336
337     }
338
339     private int trySetVnfcRefLen(String vnfcRefLenStr) throws ResourceNodeInternalException {
340
341         if (vnfcRefLenStr == null) {
342             log.info("Vnfc Reference data is missing");
343             throw new ResourceNodeInternalException("Vnfc Reference data is missing");
344
345         } else {
346             return Integer.parseInt(vnfcRefLenStr);
347         }
348     }
349
350
351     public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
352
353         log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
354
355         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
356
357         int vmCount;
358
359         try {
360
361             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
362             AaiService aai = getAaiService();
363
364             String vmCountStr = ctx.getAttribute(responsePrefix + ATTR_VNF_VM_COUNT);
365
366             if (vmCountStr == null) {
367                 throw new ResourceNodeInternalException("VM data from A&AI is missing");
368             } else {
369                 vmCount = Integer.parseInt(vmCountStr);
370             }
371
372             log.info("VMCOUNT " + vmCount);
373
374             aai.updateVnfStatus(inParams, ctx);
375             aai.updateVServerStatus(inParams, ctx, vmCount);
376
377             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
378                 AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
379
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);
386
387             throw new SvcLogicException(e.getMessage());
388         }
389     }
390
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);
394         try {
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");
403             }
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);
408
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);
414             } else {
415                 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
416                 return;
417             }
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);
424         }
425     }
426
427     public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
428         Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
429         throws Exception {
430         log.info("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
431         vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
432             inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
433
434         aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
435
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");
440
441         if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
442             || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
443             log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
444         }
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);
452     }
453
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<>();
457         int vmCount = 0;
458         int arrayIndex = -1;
459         String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
460         if (StringUtils.isNotBlank(vmCountStr)) {
461             vmCount = Integer.parseInt(vmCountStr);
462         }
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)) {
467                 arrayIndex = cnt;
468             }
469         }
470         if (arrayIndex < 0) {
471             log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
472             return null;
473         }
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= "
478             + cloudRegionId);
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());
484         return params;
485     }
486
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);
490         try {
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);
499         }
500     }
501
502     public void processForVfModuleModelInfo(AaiService aaiService, Map<String, String> inParams, SvcLogicContext ctx) {
503         log.info("processForVfModuleModelInfo()::Retrieving vf-module information :" + inParams.toString());
504         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
505         try {
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);
514
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);
518
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);
526
527             } else {
528                 log.info("processForVfModuleModelInfo()::model-invariant-id or model-version-id is blank, not getting model info !!!!");
529                 return;
530             }
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");
537             }
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);
543             }
544
545 }
546 }