2 * Copyright 2016-2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.usecaseui.server.service.lcm.impl;
18 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.CATEGORY_NS;
19 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.DISTRIBUTION_STATUS_DISTRIBUTED;
20 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.RESOURCETYPE_VF;
22 import static org.onap.usecaseui.server.util.RestfulServices.create;
23 import static org.onap.usecaseui.server.util.RestfulServices.extractBody;
25 import java.io.BufferedReader;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
32 import javax.annotation.Resource;
33 import javax.servlet.http.HttpServletRequest;
35 import org.onap.usecaseui.server.bean.ServiceBean;
36 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
37 import org.onap.usecaseui.server.constant.Constant;
38 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
39 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
40 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
41 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
42 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
43 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
44 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
45 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
46 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
47 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
48 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
49 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
50 import org.onap.usecaseui.server.util.RestfulServices;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 import org.springframework.context.annotation.EnableAspectJAutoProxy;
54 import org.springframework.stereotype.Service;
56 import com.alibaba.fastjson.JSON;
57 import com.alibaba.fastjson.JSONObject;
59 import okhttp3.RequestBody;
60 import okhttp3.ResponseBody;
61 import retrofit2.Response;
63 @Service("PackageDistributionService")
64 @org.springframework.context.annotation.Configuration
65 @EnableAspectJAutoProxy
66 public class DefaultPackageDistributionService implements PackageDistributionService {
68 private static final Logger logger = LoggerFactory.getLogger(DefaultPackageDistributionService.class);
70 private SDCCatalogService sdcCatalogService;
72 private VfcService vfcService;
74 @Resource(name="ServiceLcmService")
75 private ServiceLcmService serviceLcmService;
77 public DefaultPackageDistributionService() {
78 this(create(SDCCatalogService.class), create(VfcService.class));
81 public DefaultPackageDistributionService(SDCCatalogService sdcCatalogService, VfcService vfcService) {
82 this.sdcCatalogService = sdcCatalogService;
83 this.vfcService = vfcService;
86 public void setServiceLcmService(ServiceLcmService serviceLcmService) {
87 this.serviceLcmService = serviceLcmService;
91 public VfNsPackageInfo retrievePackageInfo() {
92 List<SDCServiceTemplate> nsTemplate = sdcNsPackageInfo();
93 List<Vnf> vnf = sdcVfPackageInfo();
94 return new VfNsPackageInfo(nsTemplate, vnf);
98 public List<Vnf> sdcVfPackageInfo() {
100 Response<List<Vnf>> response = sdcCatalogService.listResources(RESOURCETYPE_VF).execute();
101 if (response.isSuccessful()) {
102 return response.body();
104 logger.info(String.format("Can not get VF resources[code=%s, message=%s]", response.code(), response.message()));
105 return Collections.emptyList();
107 } catch (IOException e) {
108 logger.error("sdcVfPackageInfo occur exception.Details:"+e.getMessage());
114 public List<SDCServiceTemplate> sdcNsPackageInfo() {
116 Response<List<SDCServiceTemplate>> response = sdcCatalogService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED).execute();
117 if (response.isSuccessful()) {
118 return response.body();
120 logger.info(String.format("Can not get NS services[code=%s, message=%s]", response.code(), response.message()));
121 return Collections.emptyList();
123 } catch (IOException e) {
124 logger.error("sdcNsPackageInfo occur exception.Details:"+e.getMessage());
130 public DistributionResult postNsPackage(Csar csar) {
132 Response<DistributionResult> response = vfcService.distributeNsPackage(csar).execute();
133 if (response.isSuccessful()) {
134 return response.body();
136 logger.info(String.format("Can not post NS packages[code=%s, message=%s]", response.code(), response.message()));
137 throw new VfcException("VFC service is not available!");
139 } catch (IOException e) {
140 throw new VfcException("VFC service is not available!", e);
145 public Job postVfPackage(Csar csar) {
147 Response<Job> response = vfcService.distributeVnfPackage(csar).execute();
148 if (response.isSuccessful()) {
149 return response.body();
151 logger.info(String.format("Can not get VF packages[code=%s, message=%s]", response.code(), response.message()));
152 throw new VfcException("VFC service is not available!");
154 } catch (IOException e) {
155 throw new VfcException("VFC service is not available!", e);
160 public JobStatus getJobStatus(String jobId, String responseId) {
162 Response<JobStatus> response = vfcService.getJobStatus(jobId, responseId).execute();
163 if (response.isSuccessful()) {
164 return response.body();
166 logger.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
167 throw new VfcException("VFC service is not available!");
169 } catch (IOException e) {
170 throw new VfcException("VFC service is not available!", e);
175 public JobStatus getNsLcmJobStatus(String serviceInstanceId,String jobId, String responseId,String operationType) { try {
176 Response<JobStatus> response = vfcService.getNsLcmJobStatus(jobId, responseId).execute();
177 if (response.isSuccessful()) {
178 return response.body();
180 logger.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
181 throw new VfcException("VFC service getNsLcmJobStatus is not available!");
183 } catch (IOException e) {
184 throw new VfcException("VFC service getNsLcmJobStatus is not available!", e);
188 public DistributionResult deleteNsPackage(String csarId) {
190 Response<DistributionResult> response = vfcService.deleteNsPackage(csarId).execute();
191 if (response.isSuccessful()) {
192 return response.body();
194 logger.info(String.format("Can not delete NS packages[code=%s, message=%s]", response.code(), response.message()));
195 throw new VfcException("VFC service is not available!");
197 } catch (IOException e) {
198 throw new VfcException("VFC service is not available!", e);
203 public Job deleteVfPackage(String csarId) {
205 Response<Job> response = vfcService.deleteVnfPackage(csarId).execute();
206 if (response.isSuccessful()) {
207 return response.body();
209 logger.info(String.format("Can not delete VF packages[code=%s, message=%s]", response.code(), response.message()));
210 throw new VfcException("VFC service is not available!");
212 } catch (IOException e) {
213 throw new VfcException("VFC service is not available!", e);
218 public String getVnfPackages() {
221 logger.info("vfc getVnfPackages is starting!");
222 Response<ResponseBody> response = this.vfcService.getVnfPackages().execute();
223 logger.info("vfc getVnfPackages has finished!");
224 if (response.isSuccessful()) {
225 result=new String(response.body().bytes());
227 logger.info(String.format("Can not get getVnfPackages[code=%s, message=%s]", response.code(), response.message()));
228 result=Constant.CONSTANT_FAILED;;
230 } catch (IOException e) {
231 logger.error("getVnfPackages occur exception:"+e);
232 result=Constant.CONSTANT_FAILED;;
238 public String getNetworkServicePackages() {
242 logger.info("vfc getNetworkServicePackages is starting!");
243 Response<ResponseBody> response = this.vfcService.getNetworkServicePackages().execute();
244 logger.info("vfc getNetworkServicePackages has finished!");
245 if (response.isSuccessful()) {
246 result=new String(response.body().bytes());
248 logger.info(String.format("Can not get getNetworkServicePackages[code=%s, message=%s]", response.code(), response.message()));
249 result=Constant.CONSTANT_FAILED;;
251 } catch (IOException e) {
252 logger.error("getNetworkServicePackages occur exception:"+e);
253 result=Constant.CONSTANT_FAILED;;
260 public String getPnfPackages() {
264 logger.info("vfc getPnfPackages is starting!");
265 Response<ResponseBody> response = this.vfcService.getPnfPackages().execute();
266 logger.info("vfc getPnfPackages has finished!");
267 if (response.isSuccessful()) {
268 result=new String(response.body().bytes());
270 logger.info(String.format("Can not get getPnfPackages[code=%s, message=%s]", response.code(), response.message()));
271 result=Constant.CONSTANT_FAILED;;
273 } catch (IOException e) {
274 logger.error("getPnfPackages occur exception:"+e);
275 result=Constant.CONSTANT_FAILED;;
282 public String downLoadNsPackage(String nsdInfoId) {
286 logger.info("vfc downLoadNsPackage is starting!");
287 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(nsdInfoId).execute();
288 logger.info("vfc downLoadNsPackage has finished!");
289 if (response.isSuccessful()) {
290 result=Constant.CONSTANT_SUCCESS;
292 logger.info(String.format("Can not get downLoadNsPackage[code=%s, message=%s]", response.code(), response.message()));
293 result=Constant.CONSTANT_FAILED;;
295 } catch (IOException e) {
296 logger.error("downLoadNsPackage occur exception:"+e);
297 result=Constant.CONSTANT_FAILED;;
304 public String downLoadPnfPackage(String pnfdInfoId) {
308 logger.info("vfc downLoadPnfPackage is starting!");
309 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(pnfdInfoId).execute();
310 logger.info("vfc downLoadPnfPackage has finished!");
311 if (response.isSuccessful()) {
312 result=Constant.CONSTANT_SUCCESS;
314 logger.info(String.format("Can not get downLoadPnfPackage[code=%s, message=%s]", response.code(), response.message()));
315 result=Constant.CONSTANT_FAILED;;
317 } catch (IOException e) {
318 logger.error("downLoadPnfPackage occur exception:"+e);
319 result=Constant.CONSTANT_FAILED;;
326 public String downLoadVnfPackage(String vnfPkgId) {
330 logger.info("vfc downLoadVnfPackage is starting!");
331 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(vnfPkgId).execute();
332 logger.info("vfc downLoadVnfPackage has finished!");
333 if (response.isSuccessful()) {
334 result=Constant.CONSTANT_SUCCESS;
336 logger.info(String.format("Can not get downLoadVnfPackage[code=%s, message=%s]", response.code(), response.message()));
337 result=Constant.CONSTANT_FAILED;;
339 } catch (IOException e) {
340 logger.error("downLoadVnfPackage occur exception:"+e);
341 result=Constant.CONSTANT_FAILED;;
348 public String deleteNsdPackage(String nsdInfoId) {
349 Response<ResponseBody> response=null;
352 logger.info("vfc deleteNsdPackage is starting!");
353 response = this.vfcService.deleteNsdPackage(nsdInfoId).execute();
354 logger.info("vfc deleteNsdPackage has finished!");
355 if (response.isSuccessful()) {
356 result=Constant.CONSTANT_SUCCESS;
358 logger.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
359 result=Constant.CONSTANT_FAILED;;
361 } catch (IOException e) {
362 if(e.getMessage().contains("204")){
363 return Constant.CONSTANT_SUCCESS;
365 logger.error("deleteNsdPackage occur exception:"+e);
366 result=Constant.CONSTANT_FAILED;;
373 public String deleteVnfPackage(String vnfPkgId) {
374 Response<ResponseBody> response=null;
377 logger.info("vfc deleteVnfPackage is starting!");
378 response = this.vfcService.deleteVnfdPackage(vnfPkgId).execute();
379 logger.info("vfc deleteVnfPackage has finished!");
380 if (response.isSuccessful()) {
381 result=Constant.CONSTANT_SUCCESS;
383 logger.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
384 result=Constant.CONSTANT_FAILED;;
386 } catch (IOException e) {
387 if(e.getMessage().contains("204")){
388 return Constant.CONSTANT_SUCCESS;
390 logger.error("deleteVnfPackage occur exception:"+e);
391 result=Constant.CONSTANT_FAILED;;
398 public String deletePnfPackage(String pnfdInfoId) {
399 Response<ResponseBody> response=null;
402 logger.info("vfc deletePnfPackage is starting!");
403 response = this.vfcService.deletePnfdPackage(pnfdInfoId).execute();
404 logger.info("vfc deletePnfPackage has finished!");
405 if (response.isSuccessful()) {
406 result=Constant.CONSTANT_SUCCESS;
408 logger.info(String.format("Can not get deletePnfPackage[code=%s, message=%s]", response.code(), response.message()));
409 result=Constant.CONSTANT_FAILED;;
411 } catch (IOException e) {
412 if(e.getMessage().contains("204")){
413 return Constant.CONSTANT_SUCCESS;
415 logger.error("deletePnfPackage occur exception:"+e);
416 result=Constant.CONSTANT_FAILED;;
423 public List<String> getNetworkServiceInfo() {
424 List<String> result = new ArrayList<>();
426 logger.info("vfc getNetworkServiceInfo is starting!");
427 Response<nsServiceRsp> response = this.vfcService.getNetworkServiceInfo().execute();
428 logger.info("vfc getNetworkServiceInfo has finished!");
429 if (response.isSuccessful()) {
430 List<String> nsServices = response.body().nsServices;
431 if(nsServices.size()>0){
432 for(String nsService:nsServices){
433 JSONObject object = JSON.parseObject(nsService);
434 String serviceInstanceId=object.get("nsInstanceId").toString();
435 ServiceBean serviceBean = serviceLcmService.getServiceBeanByServiceInStanceId(serviceInstanceId);
436 object.put("serviceDomain",serviceBean.getServiceDomain());
437 object.put("childServiceInstances","[]");
438 result.add(object.toString());
443 logger.info(String.format("Can not get getNetworkServiceInfo[code=%s, message=%s]", response.code(), response.message()));
444 return Collections.emptyList();
446 } catch (IOException e) {
447 logger.error("getNetworkServiceInfo occur exception:"+e);
448 return Collections.emptyList();
454 public String createNetworkServiceInstance(HttpServletRequest request) {
457 logger.info("aai createNetworkServiceInstance is starting");
458 RequestBody requestBody = extractBody(request);
459 Response<ResponseBody> response = vfcService.createNetworkServiceInstance(requestBody).execute();
460 logger.info("aai createNetworkServiceInstance has finished");
461 if (response.isSuccessful()) {
462 result=new String(response.body().bytes());
464 result=Constant.CONSTANT_FAILED;
465 logger.error(String.format("Can not createNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
467 } catch (Exception e) {
468 result=Constant.CONSTANT_FAILED;
469 logger.error("createNetworkServiceInstance occur exception:"+e);
475 public String deleteNetworkServiceInstance(String nsInstanceId) {
476 Response response = null;
479 logger.info("vfc deleteNetworkServiceInstance is starting!");
480 response = this.vfcService.deleteNetworkServiceInstance(nsInstanceId).execute();
481 logger.info("vfc deleteNetworkServiceInstance has finished!");
482 if (response.isSuccessful()) {
483 result=Constant.CONSTANT_SUCCESS;
485 logger.info(String.format("Can not get deleteNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
486 result=Constant.CONSTANT_FAILED;;
488 } catch (IOException e) {
489 if(e.getMessage().contains("204")){
490 return Constant.CONSTANT_SUCCESS;
492 logger.error("deleteNetworkServiceInstance occur exception:"+e);
493 result=Constant.CONSTANT_FAILED;
500 public String terminateNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
503 logger.info("aai terminateNetworkServiceInstance is starting");
504 RequestBody requestBody = extractBody(request);
505 Response<ResponseBody> response = vfcService.terminateNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
506 logger.info("aai terminateNetworkServiceInstance has finished");
507 if (response.isSuccessful()) {
508 result=new String(response.body().bytes());
510 result=Constant.CONSTANT_FAILED;
511 logger.error(String.format("Can not terminateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
513 } catch (Exception e) {
514 result=Constant.CONSTANT_FAILED;
515 logger.error("terminateNetworkServiceInstance occur exception:"+e);
521 public String healNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
524 logger.info("aai healNetworkServiceInstance is starting");
525 RequestBody requestBody = extractBody(request);
526 Response<ResponseBody> response = vfcService.healNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
527 logger.info("aai healNetworkServiceInstance has finished");
528 if (response.isSuccessful()) {
529 result=new String(response.body().bytes());
531 result=Constant.CONSTANT_FAILED;
532 logger.error(String.format("Can not healNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
534 } catch (Exception e) {
535 result=Constant.CONSTANT_FAILED;
536 logger.error("healNetworkServiceInstance occur exception:"+e);
542 public String scaleNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
545 logger.info("aai scaleNetworkServiceInstance is starting");
546 RequestBody requestBody = extractBody(request);
547 Response<ResponseBody> response = vfcService.scaleNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
548 logger.info("aai scaleNetworkServiceInstance has finished");
549 if (response.isSuccessful()) {
550 result=new String(response.body().bytes());
552 result=Constant.CONSTANT_FAILED;
553 logger.error(String.format("Can not scaleNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
555 } catch (Exception e) {
556 result=Constant.CONSTANT_FAILED;
557 logger.error("scaleNetworkServiceInstance occur exception:"+e);
563 public String createNetworkServiceData(HttpServletRequest request) {
566 logger.info("aai createNetworkServiceData is starting");
567 RequestBody requestBody = extractBody(request);
568 Response<ResponseBody> response = vfcService.createNetworkServiceData(requestBody).execute();
569 logger.info("aai createNetworkServiceData has finished");
570 if (response.isSuccessful()) {
571 result=new String(response.body().bytes());
573 result=Constant.CONSTANT_FAILED;
574 logger.error(String.format("Can not createNetworkServiceData[code=%s, message=%s]", response.code(), response.message()));
576 } catch (Exception e) {
577 result=Constant.CONSTANT_FAILED;
578 logger.error("createNetworkServiceData occur exception:"+e);
584 public String createVnfData(HttpServletRequest request) {
587 logger.info("aai createVnfData is starting");
588 RequestBody requestBody = extractBody(request);
589 Response<ResponseBody> response = vfcService.createVnfData(requestBody).execute();
590 logger.info("aai createVnfData has finished");
591 if (response.isSuccessful()) {
592 result=new String(response.body().bytes());
594 result=Constant.CONSTANT_FAILED;
595 logger.error(String.format("Can not createVnfData[code=%s, message=%s]", response.code(), response.message()));
597 } catch (Exception e) {
598 result=Constant.CONSTANT_FAILED;
599 logger.error("createVnfData occur exception:"+e);
605 public String createPnfData(HttpServletRequest request) {
608 logger.info("aai createPnfData is starting");
609 RequestBody requestBody = extractBody(request);
610 Response<ResponseBody> response = vfcService.createPnfData(requestBody).execute();
611 logger.info("aai createPnfData has finished");
612 if (response.isSuccessful()) {
613 result=new String(response.body().bytes());
615 result=Constant.CONSTANT_FAILED;
616 logger.error(String.format("Can not createPnfData[code=%s, message=%s]", response.code(), response.message()));
618 } catch (Exception e) {
619 result=Constant.CONSTANT_FAILED;
620 logger.error("createPnfData occur exception:"+e);
626 public String getNsdInfo(String nsdInfoId) {
630 logger.info("vfc getNsdInfo is starting!");
631 Response<ResponseBody> response = this.vfcService.getNsdInfo(nsdInfoId).execute();
632 logger.info("vfc getNsdInfo has finished!");
633 if (response.isSuccessful()) {
634 result=Constant.CONSTANT_SUCCESS;
636 logger.info(String.format("Can not get getNsdInfo[code=%s, message=%s]", response.code(), response.message()));
637 result=Constant.CONSTANT_FAILED;;
639 } catch (IOException e) {
640 logger.error("getNsdInfo occur exception:"+e);
641 result=Constant.CONSTANT_FAILED;;
648 public String getVnfInfo(String vnfPkgId) {
652 logger.info("vfc getVnfInfo is starting!");
653 Response<ResponseBody> response = this.vfcService.getVnfInfo(vnfPkgId).execute();
654 logger.info("vfc getVnfInfo has finished!");
655 if (response.isSuccessful()) {
656 result=Constant.CONSTANT_SUCCESS;
658 logger.info(String.format("Can not get getVnfInfo[code=%s, message=%s]", response.code(), response.message()));
659 result=Constant.CONSTANT_FAILED;;
661 } catch (IOException e) {
662 logger.error("getVnfInfo occur exception:"+e);
663 result=Constant.CONSTANT_FAILED;;
670 public String getPnfInfo(String pnfdInfoId) {
674 logger.info("vfc getPnfInfo is starting!");
675 Response<ResponseBody> response = this.vfcService.getPnfInfo(pnfdInfoId).execute();
676 logger.info("vfc getPnfInfo has finished!");
677 if (response.isSuccessful()) {
678 result=Constant.CONSTANT_SUCCESS;
680 logger.info(String.format("Can not get getPnfInfo[code=%s, message=%s]", response.code(), response.message()));
681 result=Constant.CONSTANT_FAILED;;
683 } catch (IOException e) {
684 logger.error("getPnfInfo occur exception:"+e);
685 result=Constant.CONSTANT_FAILED;;
692 public String listNsTemplates() {
696 logger.info("vfc listNsTemplates is starting!");
697 Response<ResponseBody> response = this.vfcService.listNsTemplates().execute();
698 logger.info("vfc listNsTemplates has finished!");
699 if (response.isSuccessful()) {
700 result=new String(response.body().bytes());
702 logger.info(String.format("Can not get listNsTemplates[code=%s, message=%s]", response.code(), response.message()));
703 result=Constant.CONSTANT_FAILED;;
705 } catch (IOException e) {
706 logger.error("listNsTemplates occur exception:"+e);
707 result=Constant.CONSTANT_FAILED;;
714 public String fetchNsTemplateData(HttpServletRequest request) {
717 logger.info("aai fetchNsTemplateData is starting");
718 RequestBody requestBody = extractBody(request);
719 Response<ResponseBody> response = vfcService.fetchNsTemplateData(requestBody).execute();
720 logger.info("aai fetchNsTemplateData has finished");
721 if (response.isSuccessful()) {
722 result=new String(response.body().bytes());
724 result=Constant.CONSTANT_FAILED;
725 logger.error(String.format("Can not fetchNsTemplateData[code=%s, message=%s]", response.code(), response.message()));
727 } catch (Exception e) {
728 result=Constant.CONSTANT_FAILED;
729 logger.error("fetchNsTemplateData occur exception:"+e);
735 public JSONObject fetchCCVPNTemplateData(HttpServletRequest request, String csarId) {
736 JSONObject result = new JSONObject();
738 RequestBody requestBody = extractBody(request);
739 // search template from vfc catalog
740 Response<ResponseBody> getResponse = this.vfcService.servicePackages(csarId).execute();
742 if (getResponse.isSuccessful()) {
743 // call vfc template parser
744 logger.info("calling ccvpn template file parser is starting");
745 Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
746 logger.info("calling ccvpn template file parser has finished");
747 if (response.isSuccessful()) {
748 result.put("status", Constant.CONSTANT_SUCCESS);
749 result.put("result", JSONObject.parseObject(new String(response.body().bytes())));
751 result.put("status", Constant.CONSTANT_FAILED);
752 result.put("error", String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
753 logger.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
756 // distribute template files to vfc catalog
757 Response<ResponseBody> postResponse = this.vfcService.servicePackages(requestBody).execute();
758 if (postResponse.isSuccessful()) {
759 // call vfc template parser
760 logger.info("calling ccvpn template file parser is starting");
761 Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
762 logger.info("calling ccvpn template file parser has finished");
763 if (response.isSuccessful()) {
764 result.put("status", Constant.CONSTANT_SUCCESS);
765 result.put("result",JSONObject.parseObject(new String(response.body().bytes())));
767 result.put("status", Constant.CONSTANT_FAILED);
768 result.put("error",String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
769 logger.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
772 result.put("status", Constant.CONSTANT_FAILED);
773 result.put("error",String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
774 logger.error(String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
777 } catch (Exception e) {
778 result.put("status", Constant.CONSTANT_FAILED);
779 result.put("errorMessage", "calling ccvpn template parser happened exception:"+e);
785 public String instantiateNetworkServiceInstance(HttpServletRequest request, String serviceInstanceId) {
788 logger.info("aai instantiateNetworkServiceInstance is starting");
789 RequestBody requestBody = extractBody(request);
790 Response<ResponseBody> response = vfcService.instantiateNetworkServiceInstance(requestBody,serviceInstanceId).execute();
791 logger.info("aai instantiateNetworkServiceInstance has finished");
792 if (response.isSuccessful()) {
793 result=new String(response.body().bytes());
795 result=Constant.CONSTANT_FAILED;
796 logger.error(String.format("Can not instantiateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
798 } catch (Exception e) {
799 result=Constant.CONSTANT_FAILED;
800 logger.error("instantiateNetworkServiceInstance occur exception:"+e);
806 public String getVnfInfoById(String vnfinstid) {
810 logger.info("vfc getVnfInfoById is starting!");
811 Response<ResponseBody> response = this.vfcService.getVnfInfoById(vnfinstid).execute();
812 logger.info("vfc getVnfInfoById has finished!");
813 if (response.isSuccessful()) {
814 result=new String(response.body().bytes());
816 logger.info(String.format("Can not get getVnfInfoById[code=%s, message=%s]", response.code(), response.message()));
817 result=Constant.CONSTANT_FAILED;;
819 } catch (IOException e) {
820 logger.error("getVnfInfoById occur exception:"+e);
821 result=Constant.CONSTANT_FAILED;;