AAI Client Updates
[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 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 java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.Arrays;
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
36 import org.apache.commons.lang3.StringUtils;
37
38 import org.onap.appc.aai.client.AppcAaiClientConstant;
39 import org.onap.appc.aai.client.aai.AaiService;
40
41
42 import com.att.eelf.configuration.EELFLogger;
43 import com.att.eelf.configuration.EELFManager;
44
45 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
46 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
47 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
48
49 //import com.fasterxml.jackson.databind.ObjectMapper;
50
51
52 public class AAIResourceNode implements SvcLogicJavaPlugin {
53
54     private static final EELFLogger log = EELFManager.getInstance().getLogger(AAIResourceNode.class);
55
56
57     public AaiService getAaiService() {
58         return new AaiService();
59     }
60     /* Gets VNF Info and All VServers associated with Vnf */
61     public void getVnfInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
62
63         log.info("Received getVnfInfo call with params : " + inParams);
64
65         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
66
67         try {
68
69             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
70             AaiService aai = getAaiService();
71             aai.getGenericVnfInfo(inParams,ctx);
72
73             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
74                     AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
75             log.info("getVnfInfo Successful ");
76         } catch (Exception e) {
77             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
78                     AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
79             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
80             log.error("Failed in getVnfInfo " + e.getMessage());
81
82             throw new SvcLogicException(e.getMessage());
83         }
84     }
85
86
87     public void getAllVServersVnfcsInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
88
89         log.info("Received getAllVServersVnfcsInfo call with params : " + inParams);
90
91         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
92
93         try {
94             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
95             AaiService aai = getAaiService();
96
97
98
99             ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>();
100
101             int vmWithNoVnfcsCount = 0;
102             String  vmCountStr = ctx.getAttribute(responsePrefix + "vm-count");
103
104             if ( vmCountStr == null )
105                 throw new Exception("Unable to get VServers for the VNF");
106
107             int vmCount = Integer.parseInt(vmCountStr);
108             for ( int i = 0; i < vmCount; i++ ) {
109
110                 SvcLogicContext vmServerCtx = new SvcLogicContext();
111
112                 Map<String, String> paramsVm = new HashMap<String, String>();
113                 paramsVm.put("vserverId", ctx.getAttribute(responsePrefix + "vm[" + i + "].vserver-id"));
114                 paramsVm.put("tenantId", ctx.getAttribute(responsePrefix +"vm[" + i + "].tenant-id"));
115                 paramsVm.put("cloudOwner", ctx.getAttribute(responsePrefix +"vm[" + i + "].cloud-owner"));
116                 paramsVm.put("cloudRegionId", ctx.getAttribute(responsePrefix +"vm[" + i + "].cloud-region-id"));
117                 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
118
119
120
121                 aai.getVMInfo(paramsVm, vmServerCtx);
122
123                 HashMap<String, String> vserverMap = new HashMap<String, String>();
124                 vserverMap.put("vserver-id", ctx.getAttribute(responsePrefix + "vm[" + i + "].vserver-id"));
125                 vserverMap.put("tenant-id", ctx.getAttribute(responsePrefix +"vm[" + i + "].tenant-id"));
126                 vserverMap.put("cloud-owner", ctx.getAttribute(responsePrefix +"vm[" + i + "].cloud-owner"));
127                 vserverMap.put("cloud-region-id", ctx.getAttribute(responsePrefix +"vm[" + i + "].cloud-region-id"));
128
129                 // Parameters returned by getVMInfo
130                 vserverMap.put("vserver-name", vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
131                 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
132
133
134                 // as Per 17.07 requirements we are supporting only one VNFC per VM.
135
136                 String vnfcName = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
137                 vserverMap.put("vnfc-name", vnfcName);
138
139
140                 String vnfcCount = vmServerCtx.getAttribute(responsePrefix + "vm.vnfc-count");
141                 if ( vnfcCount == null )
142                     vnfcCount = "0";
143
144                 vserverMap.put("vnfc-count", vnfcCount);
145
146                 if ( vnfcName != null  ) {
147                     Map<String, String> paramsVnfc = new HashMap<String, String>();
148                     paramsVnfc.put("vnfcName", vnfcName);
149
150                     paramsVnfc.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
151
152                     SvcLogicContext vnfcCtx = new SvcLogicContext();
153
154                     aai.getVnfcInfo(paramsVnfc, vnfcCtx);
155
156                     vserverMap.put("vnfc-type", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type"));
157                     vserverMap.put("vnfc-function-code", vnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code"));
158                     vserverMap.put("group-notation", vnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation"));
159                     vserverMap.put("vnfc-ipaddress-v4-oam-vip", vnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip"));
160
161                 }
162                 else
163                     vmWithNoVnfcsCount++;
164                 vservers.add(vserverMap);
165
166             } // vmCount
167
168             Collections.sort(vservers, new Comparator<Map<String, String>>() {
169                 @Override
170                 public int compare(Map<String, String> o1, Map<String, String> o2) {
171                     return o1.get("vserver-name").compareTo(o2.get("vserver-name"));
172                 }
173             });
174
175             log.info("SORTED VSERVERS " + vservers.toString());
176
177             populateContext(vservers, ctx, responsePrefix);
178
179             log.info("VMCOUNT IN GETALLVSERVERS " + vmCount);
180             log.info("VMSWITHNOVNFCSCOUNT IN GETALLVSERVERS " + vmWithNoVnfcsCount);
181             ctx.setAttribute(responsePrefix+"vnf.vm-count", String.valueOf(vmCount));
182             ctx.setAttribute(responsePrefix+"vnf.vm-with-no-vnfcs-count", String.valueOf(vmWithNoVnfcsCount));
183
184
185         } catch (Exception e) {
186             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
187                     AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
188             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
189             log.error("Failed in getAllVServersVnfcsInfo " + e.getMessage());
190
191             throw new SvcLogicException(e.getMessage());
192         }
193     }
194
195     public void populateContext(ArrayList<Map<String, String>> vservers, SvcLogicContext ctx, String prefix) {
196
197
198         log.info("Populating Final Context");
199         int ctr = 0;
200
201         for (Map<String, String> entry : vservers) {
202             for (String key : entry.keySet()) {
203                 String value = entry.get(key);
204
205                    ctx.setAttribute(prefix+ "vm[" + ctr + "]."+ key, value);
206                 log.info("Populating Context Key = " + prefix+ "vm[" + ctr + "]."+ key + " Value = " + value);
207
208             }
209             ctr++;
210         }
211
212         String firstVServerName = null;
213         for  ( int i =0; i < ctr; i++ ) {
214             String vnfcName = ctx.getAttribute(prefix + "vm[" + i + "].vnfc-name");
215             log.info("VNFCNAME " + i + vnfcName);
216             if (  vnfcName == null && firstVServerName == null ) {
217                    firstVServerName = ctx.getAttribute(prefix + "vm[" + i + "].vserver-name");
218                    ctx.setAttribute("vm-name" , firstVServerName);
219                    log.info("Populating Context Key = " +  "vm-name" + " Value = " + firstVServerName);
220             }
221         }
222     }
223
224
225
226     public void addVnfcs(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
227
228         log.info("Received addVnfcs call with params : " + inParams);
229
230         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
231
232         int vnfcRefLen =0 ;
233         int vmCount = 0;
234         int vmWithNoVnfcCount = 0;
235
236         try {
237
238             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
239             AaiService aai = getAaiService();
240
241             String vnfcRefLenStr = ctx.getAttribute("vnfcReference_length");
242
243             if ( vnfcRefLenStr == null) {
244                 log.info("Vnfc Reference data is missing");
245                 throw new Exception("Vnfc Reference data is missing");
246
247             }
248             else
249                 vnfcRefLen = Integer.parseInt(vnfcRefLenStr);
250
251             String vmWithNoVnfcCountStr = ctx.getAttribute(responsePrefix+"vnf.vm-with-no-vnfcs-count");
252
253       //Commented  for backward compatibility
254
255             /*if ( vmWithNoVnfcCountStr == null) {
256             throw new Exception("VNFCs to be added data from A&AI is missing");
257             //log.info("VNFCs to be added data from A&AI is missing");
258              }
259             else
260                 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
261
262             if ( vmWithNoVnfcCount!= vnfcRefLen )
263                 throw new Exception("Unable to Add Vnfcs to A&AI. Reference data mismatch.");
264
265             String vmCountStr = ctx.getAttribute(responsePrefix+"vnf.vm-count");
266
267             if ( vmCountStr == null)
268                 throw new Exception("VM data from A&AI is missing");
269             else
270                 vmCount = Integer.parseInt(vmCountStr);
271
272
273             log.info("VMCOUNT " + vmCount);
274             log.info("VNFCREFLEN " + vnfcRefLen);
275             aai.insertVnfcs(inParams,ctx, vnfcRefLen, vmCount);
276
277          */
278
279
280         // Modified for 1710
281
282             if ( vmWithNoVnfcCountStr == null) {
283                 log.info("Parameter VM without VNFCs(vmWithNoVnfcCountStr) from A&AI is Null");
284             }
285             else
286                 vmWithNoVnfcCount = Integer.parseInt(vmWithNoVnfcCountStr);
287
288             log.info("No of VM without VNFCs(vmWithNoVnfcCount) from A&AI is " +vmWithNoVnfcCount);
289
290             String vmCountStr = ctx.getAttribute(responsePrefix+"vnf.vm-count");
291
292             if ( vmCountStr == null)
293                 throw new Exception("VM data from A&AI is missing");
294             else
295                 vmCount = Integer.parseInt(vmCountStr);
296     if(vmCount<vnfcRefLen)
297                 throw new Exception("Vnfc and VM count mismatch");
298
299
300             log.info("VMCOUNT " + vmCount);
301             log.info("VNFCREFLEN " + vnfcRefLen);
302             if(StringUtils.isBlank(ctx.getAttribute("vnfc-type"))){
303                 aai.updateVnfStatusWithOAMAddress(inParams, ctx);
304             }
305
306             if ( vmWithNoVnfcCount!= vnfcRefLen ) {
307                 //throw new Exception("Unable to Add Vnfcs to A&AI. Reference data mismatch.");
308                 log.info("vmWithNoVnfcCount and vnfcRefLen data from table are not same ");
309                 aai.checkAndUpdateVnfc(inParams,ctx, vnfcRefLen, vmCount);
310             }
311
312             else {
313
314                 aai.insertVnfcs(inParams,ctx, vnfcRefLen, vmCount);
315             }
316
317                    //// Modified 1710
318
319             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
320                     AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
321
322             log.info("addVnfcs Successful ");
323         } catch (Exception e) {
324             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
325                     AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
326             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
327             log.error("Failed in addVnfcs " + e.getMessage());
328
329             throw new SvcLogicException(e.getMessage());
330         }
331     }
332
333
334     public void updateVnfAndVServerStatus(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
335
336         log.info("Received updateVnfAndVServerStatus call with params : " + inParams);
337
338         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
339
340
341         int vmCount = 0;
342
343
344         try {
345
346             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
347             AaiService aai = getAaiService();
348
349
350
351             String vmCountStr = ctx.getAttribute(responsePrefix+"vnf.vm-count");
352
353             if ( vmCountStr == null)
354                 throw new Exception("VM data from A&AI is missing");
355             else
356                 vmCount = Integer.parseInt(vmCountStr);
357
358
359             log.info("VMCOUNT " + vmCount);
360
361
362             aai.updateVnfStatus(inParams, ctx);
363             aai.updateVServerStatus(inParams,ctx, vmCount);
364
365             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
366                     AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS);
367
368             log.info("updateVnfAndVServerStatus Successful ");
369         } catch (Exception e) {
370             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
371                     AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
372             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
373             log.error("Failed in updateVnfAndVServerStatus " + e.getMessage());
374
375             throw new SvcLogicException(e.getMessage());
376         }
377     }
378
379     /*public void getDummyValues(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
380
381         log.info("Received getDummyValues call with params : " + inParams);
382
383         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
384
385         try {
386
387                 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
388                 String instarKeys = inParams.get("instarKeys");
389                 ObjectMapper mapper = new ObjectMapper();
390                 if ( instarKeys != null ) {
391
392                     List<String> keyList = mapper.readValue(instarKeys, ArrayList.class);
393
394                     Map<String, String> instarParams  =new HashMap<String, String>();
395                     if(keyList != null){
396                         //System.out.println(keyList.toString());
397
398
399                         for(int i=0;i<keyList.size();i++)
400                         {
401                             log.info(" -->"+keyList.get(i));
402
403                             //ctx.setAttribute(keyList.get(i), "test" + i);
404
405                             instarParams.put( keyList.get(i), "test" + i);
406                         }
407
408                     }
409                     log.info("INSTARPARAMMAP " + instarParams);
410                     String jsonString = mapper.writeValueAsString(instarParams);
411                     log.info(jsonString);
412                     ctx.setAttribute(responsePrefix + "configuration-parameters", jsonString);
413
414                 }
415
416                 log.info("getDummyValues Successful ");
417             } catch (Exception e) {
418                 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
419                         AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
420                 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
421                 log.error("Failed in getDummyValues " + e.getMessage());
422
423                 throw new SvcLogicException(e.getMessage());
424             }
425
426     }
427
428     */
429     /*public void getRequestKeys(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
430
431         log.info("Received getRequestKeys call with params : " + inParams);
432
433         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
434
435         try {
436
437                 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix+".") : "";
438                 String instarKeys = inParams.get("instarKeys");
439
440                 ObjectMapper mapper = new ObjectMapper();
441                 if ( instarKeys != null ) {
442
443                     List<String> keyList = mapper.readValue(instarKeys, ArrayList.class);
444
445                     //Map<String, String> instarParams  =new HashMap<String, String>();
446                     if(keyList != null){
447
448
449                         for(int i=0;i<keyList.size();i++)
450                         {
451                             log.info("INSTARKEY -->"+keyList.get(i));
452
453
454                             String instarParameter = ctx.getAttribute("INSTAR." + keyList.get(i));
455                             log.info("INSTARPARAMETER " + instarParameter);
456                             Parameter param = parseParameterContent(instarParameter);
457
458                             log.info("PARAMETER KEY SIZE " + param.getRequestKeys().size());
459                             log.info("RULE TYPE " + param.getClassType());
460
461                             for ( int j =0 ; j < param.getRequestKeys().size() ; j++ ) {
462
463                                 log.info(" PARAM KEY NAME " + param.getRequestKeys().get(j).getKeyName());
464                                 log.info(" PARAM KEY VALUE " + param.getRequestKeys().get(j).getKeyValue());
465                             }
466
467                            // instarParams.put( keyList.get(i), "test" + i);
468                         }
469
470                     }
471                     //log.info("INSTARPARAMMAP " + instarParams);
472                     //String jsonString = mapper.writeValueAsString(instarParams);
473                     //log.info(jsonString);
474                     //ctx.setAttribute(responsePrefix + "configuration-parameters", jsonString);
475
476                 }
477
478                 log.info("getRequestKeys Successful ");
479             } catch (Exception e) {
480                 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
481                         AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
482                 ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
483                 log.error("Failed in getRequestKeys " + e.getMessage());
484
485                 throw new SvcLogicException(e.getMessage());
486             }
487
488     }
489
490
491     public Parameter parseParameterContent(String parameter) throws JsonParseException, JsonMappingException, IOException{
492         Parameter parameterDefinition = null;
493         if(StringUtils.isNotBlank(parameter)){
494             ObjectMapper mapper = new ObjectMapper();
495             parameterDefinition = mapper.readValue(parameter, Parameter.class);
496         }
497         return parameterDefinition;
498     }*/
499 public void getVserverInfo(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
500         log.debug("getVserverInfo()::Retrieving vm and vnfc information for vserver:" + inParams.toString());
501         String responsePrefix = inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
502         try {
503             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
504             AaiService aaiService = getAaiService();
505             String vServerId = inParams.get("vserverId");
506             Map<String, String> params = setVmParams(ctx, vServerId);
507             Map<String, String> vnfcParams = new HashMap<String, String>();
508             if (null == params) {
509                 log.error("getVserverInfo()::No Vm Info found!!");
510                 throw new SvcLogicException("No Vm Info in Context");
511             }
512             params.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
513                     inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
514             SvcLogicContext newVmCtx = new SvcLogicContext();
515             aaiService.getVMInfo(params, newVmCtx);
516
517             String vnfcName = newVmCtx.getAttribute(responsePrefix + "vm.vnfc[0].vnfc-name");
518             log.debug("getVnfcFunctionCodeForVserver()::vnfcName=" + vnfcName);
519             SvcLogicContext newVnfcCtx = new SvcLogicContext();
520             if (StringUtils.isNotBlank(vnfcName)) {
521                 vnfcParams.put("vnfcName", vnfcName);
522             } else {
523                 log.info("getVserverInfo()::vnfc Name is blank, not setting vnfc info !!!!");
524                 return;
525             }
526             getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aaiService, responsePrefix);
527         } catch (Exception e) {
528             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_STATUS,
529                     AppcAaiClientConstant.OUTPUT_STATUS_FAILURE);
530             ctx.setAttribute(responsePrefix + AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
531             log.error("Failed in getVserverInfo " + e.getMessage());
532         }
533     }
534
535     public void getVnfcInformationForVserver(Map<String, String> vnfcParams, SvcLogicContext newVnfcCtx,
536             Map<String, String> inParams, SvcLogicContext ctx, AaiService aaiService, String responsePrefix)
537             throws Exception {
538         log.debug("getVnfcInformationForVserver()::vnfcParams:" + vnfcParams.toString());
539         vnfcParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
540                 inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
541
542         aaiService.getVnfcInfo(vnfcParams, newVnfcCtx);
543
544         String vnfcType = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-type");
545         String vnfcFunctionCode = newVnfcCtx.getAttribute(responsePrefix + "vnfc.vnfc-function-code");
546         String vnfcGroupNotation = newVnfcCtx.getAttribute(responsePrefix + "vnfc.group-notation");
547         String vnfcV4OamIp = newVnfcCtx.getAttribute(responsePrefix + "vnfc.ipaddress-v4-oam-vip");
548
549         if (StringUtils.isBlank(vnfcType) || StringUtils.isBlank(vnfcFunctionCode)
550                 || StringUtils.isBlank(vnfcGroupNotation) || StringUtils.isBlank(vnfcV4OamIp)) {
551             log.info("getVnfcInformationForVserver()::Some vnfc parameters are blank!!!!");
552         }
553         log.debug("getVnfcInformationForVserver()::vnfcType=" + vnfcType + ",vnfcFunctionCode=" + vnfcFunctionCode,
554                 ", vnfc-ipaddress-v4-oam-vip=" + vnfcV4OamIp);
555         ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-name", vnfcParams.get("vnfcName"));
556         ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-type", vnfcType);
557         ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-function-code", vnfcFunctionCode);
558         ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-group-notation", vnfcGroupNotation);
559         ctx.setAttribute(responsePrefix + "vm.vnfc.vnfc-ipaddress-v4-oam-vip", vnfcV4OamIp);
560
561     }
562
563     public Map<String, String> setVmParams(SvcLogicContext ctx, String vServerId) {
564         log.debug("setVmParams()::setVmParamsVM level action:" + vServerId);
565         Map<String, String> params = new HashMap<String, String>();
566         int vmCount = 0, arrayIndex = -1;
567         String vmCountStr = ctx.getAttribute("tmp.vnfInfo.vm-count");
568         if (StringUtils.isNotBlank(vmCountStr))
569             vmCount = Integer.parseInt(vmCountStr);
570         for (int cnt = 0; cnt < vmCount; cnt++) {
571             String vsId = ctx.getAttribute("tmp.vnfInfo.vm[" + cnt + "].vserver-id");
572             log.debug("setVmParams():::vserver details::" + cnt + ":" + vsId);
573             if (StringUtils.equals(vServerId, vsId)) {
574                 arrayIndex = cnt;
575             }
576         }
577         if (arrayIndex < 0) {
578             log.info("setVmParams()::VserverId not found in context!! Returning null for params!!");
579             return null;
580         }
581         String tenantId = ctx.getAttribute("tmp.vnfInfo.vm[" + arrayIndex + "].tenant-id");
582         String cloudOwner = ctx.getAttribute("tmp.vnfInfo.vm[" + arrayIndex + "].cloud-region-id");
583         String cloudRegionId = ctx.getAttribute("tmp.vnfInfo.vm[" + arrayIndex + "].cloud-owner");
584         log.debug("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
585                 + cloudRegionId);
586         params.put("vserverId", vServerId);
587         params.put("tenantId", tenantId);
588         params.put("cloudOwner", cloudOwner);
589         params.put("cloudRegionId", cloudRegionId);
590         log.debug("setVmParams()::setVmParamsVM level action:" + params.toString());
591         return params;
592
593     }
594 }