2 * Copyright 2016-2017 ZTE Corporation.
4 * ================================================================================
5 * Modifications Copyright (C) 2025 Deutsche Telekom.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org.onap.usecaseui.server.service.lcm.impl;
21 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.CATEGORY_NS;
22 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.DISTRIBUTION_STATUS_DISTRIBUTED;
23 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.RESOURCETYPE_VF;
25 import static org.onap.usecaseui.server.util.RestfulServices.extractBody;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.List;
32 import jakarta.annotation.Resource;
33 import jakarta.servlet.http.HttpServletRequest;
34 import lombok.RequiredArgsConstructor;
35 import lombok.extern.slf4j.Slf4j;
37 import org.onap.usecaseui.server.bean.ServiceBean;
38 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
39 import org.onap.usecaseui.server.constant.CommonConstant;
40 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
41 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
42 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
43 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
44 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
45 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
46 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
47 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
48 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
49 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
50 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
51 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.springframework.context.annotation.EnableAspectJAutoProxy;
55 import org.springframework.stereotype.Service;
57 import com.alibaba.fastjson.JSON;
58 import com.alibaba.fastjson.JSONObject;
60 import okhttp3.RequestBody;
61 import okhttp3.ResponseBody;
62 import retrofit2.Response;
65 @RequiredArgsConstructor
66 @Service("PackageDistributionService")
67 public class DefaultPackageDistributionService implements PackageDistributionService {
69 private final SDCCatalogService sdcCatalogService;
70 private final VfcService vfcService;
71 private final ServiceLcmService serviceLcmService;
74 public VfNsPackageInfo retrievePackageInfo() {
75 List<SDCServiceTemplate> nsTemplate = sdcNsPackageInfo();
76 List<Vnf> vnf = sdcVfPackageInfo();
77 return new VfNsPackageInfo(nsTemplate, vnf);
81 public List<Vnf> sdcVfPackageInfo() {
83 Response<List<Vnf>> response = sdcCatalogService.listResources(RESOURCETYPE_VF).execute();
84 if (response.isSuccessful()) {
85 return response.body();
87 log.info(String.format("Can not get VF resources[code=%s, message=%s]", response.code(), response.message()));
88 return Collections.emptyList();
90 } catch (IOException e) {
91 log.error("sdcVfPackageInfo occur exception.Details:"+e.getMessage());
97 public List<SDCServiceTemplate> sdcNsPackageInfo() {
99 Response<List<SDCServiceTemplate>> response = sdcCatalogService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED).execute();
100 if (response.isSuccessful()) {
101 return response.body();
103 log.info(String.format("Can not get NS services[code=%s, message=%s]", response.code(), response.message()));
104 return Collections.emptyList();
106 } catch (IOException e) {
107 log.error("sdcNsPackageInfo occur exception.Details:"+e.getMessage());
113 public DistributionResult postNsPackage(Csar csar) {
115 Response<DistributionResult> response = vfcService.distributeNsPackage(csar).execute();
116 if (response.isSuccessful()) {
117 return response.body();
119 log.info(String.format("Can not post NS packages[code=%s, message=%s]", response.code(), response.message()));
120 throw new VfcException("VFC service is not available!");
122 } catch (IOException e) {
123 throw new VfcException("VFC service is not available!", e);
128 public Job postVfPackage(Csar csar) {
130 Response<Job> response = vfcService.distributeVnfPackage(csar).execute();
131 if (response.isSuccessful()) {
132 return response.body();
134 log.info(String.format("Can not get VF packages[code=%s, message=%s]", response.code(), response.message()));
135 throw new VfcException("VFC service is not available!");
137 } catch (IOException e) {
138 throw new VfcException("VFC service is not available!", e);
143 public JobStatus getJobStatus(String jobId, String responseId) {
145 Response<JobStatus> response = vfcService.getJobStatus(jobId, responseId).execute();
146 if (response.isSuccessful()) {
147 return response.body();
149 log.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
150 throw new VfcException("VFC service is not available!");
152 } catch (IOException e) {
153 throw new VfcException("VFC service is not available!", e);
158 public JobStatus getNsLcmJobStatus(String serviceInstanceId,String jobId, String responseId,String operationType) { try {
159 Response<JobStatus> response = vfcService.getNsLcmJobStatus(jobId, responseId).execute();
160 if (response.isSuccessful()) {
161 return response.body();
163 log.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
164 throw new VfcException("VFC service getNsLcmJobStatus is not available!");
166 } catch (IOException e) {
167 throw new VfcException("VFC service getNsLcmJobStatus is not available!", e);
171 public DistributionResult deleteNsPackage(String csarId) {
173 Response<DistributionResult> response = vfcService.deleteNsPackage(csarId).execute();
174 if (response.isSuccessful()) {
175 return response.body();
177 log.info(String.format("Can not delete NS packages[code=%s, message=%s]", response.code(), response.message()));
178 throw new VfcException("VFC service is not available!");
180 } catch (IOException e) {
181 throw new VfcException("VFC service is not available!", e);
186 public Job deleteVfPackage(String csarId) {
188 Response<Job> response = vfcService.deleteVnfPackage(csarId).execute();
189 if (response.isSuccessful()) {
190 return response.body();
192 log.info(String.format("Can not delete VF packages[code=%s, message=%s]", response.code(), response.message()));
193 throw new VfcException("VFC service is not available!");
195 } catch (IOException e) {
196 throw new VfcException("VFC service is not available!", e);
201 public String getVnfPackages() {
204 log.info("vfc getVnfPackages is starting!");
205 Response<ResponseBody> response = this.vfcService.getVnfPackages().execute();
206 log.info("vfc getVnfPackages has finished!");
207 if (response.isSuccessful()) {
208 result=new String(response.body().bytes());
210 log.info(String.format("Can not get getVnfPackages[code=%s, message=%s]", response.code(), response.message()));
211 result= CommonConstant.CONSTANT_FAILED;;
213 } catch (IOException e) {
214 log.error("getVnfPackages occur exception:"+e);
215 result= CommonConstant.CONSTANT_FAILED;;
221 public String getNetworkServicePackages() {
225 log.info("vfc getNetworkServicePackages is starting!");
226 Response<ResponseBody> response = this.vfcService.getNetworkServicePackages().execute();
227 log.info("vfc getNetworkServicePackages has finished!");
228 if (response.isSuccessful()) {
229 result=new String(response.body().bytes());
231 log.info(String.format("Can not get getNetworkServicePackages[code=%s, message=%s]", response.code(), response.message()));
232 result= CommonConstant.CONSTANT_FAILED;;
234 } catch (IOException e) {
235 log.error("getNetworkServicePackages occur exception:"+e);
236 result= CommonConstant.CONSTANT_FAILED;;
243 public String getPnfPackages() {
247 log.info("vfc getPnfPackages is starting!");
248 Response<ResponseBody> response = this.vfcService.getPnfPackages().execute();
249 log.info("vfc getPnfPackages has finished!");
250 if (response.isSuccessful()) {
251 result=new String(response.body().bytes());
253 log.info(String.format("Can not get getPnfPackages[code=%s, message=%s]", response.code(), response.message()));
254 result= CommonConstant.CONSTANT_FAILED;;
256 } catch (IOException e) {
257 log.error("getPnfPackages occur exception:"+e);
258 result= CommonConstant.CONSTANT_FAILED;;
265 public String downLoadNsPackage(String nsdInfoId) {
269 log.info("vfc downLoadNsPackage is starting!");
270 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(nsdInfoId).execute();
271 log.info("vfc downLoadNsPackage has finished!");
272 if (response.isSuccessful()) {
273 result= CommonConstant.CONSTANT_SUCCESS;
275 log.info(String.format("Can not get downLoadNsPackage[code=%s, message=%s]", response.code(), response.message()));
276 result= CommonConstant.CONSTANT_FAILED;;
278 } catch (IOException e) {
279 log.error("downLoadNsPackage occur exception:"+e);
280 result= CommonConstant.CONSTANT_FAILED;;
287 public String downLoadPnfPackage(String pnfdInfoId) {
291 log.info("vfc downLoadPnfPackage is starting!");
292 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(pnfdInfoId).execute();
293 log.info("vfc downLoadPnfPackage has finished!");
294 if (response.isSuccessful()) {
295 result= CommonConstant.CONSTANT_SUCCESS;
297 log.info(String.format("Can not get downLoadPnfPackage[code=%s, message=%s]", response.code(), response.message()));
298 result= CommonConstant.CONSTANT_FAILED;;
300 } catch (IOException e) {
301 log.error("downLoadPnfPackage occur exception:"+e);
302 result= CommonConstant.CONSTANT_FAILED;;
309 public String downLoadVnfPackage(String vnfPkgId) {
313 log.info("vfc downLoadVnfPackage is starting!");
314 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(vnfPkgId).execute();
315 log.info("vfc downLoadVnfPackage has finished!");
316 if (response.isSuccessful()) {
317 result= CommonConstant.CONSTANT_SUCCESS;
319 log.info(String.format("Can not get downLoadVnfPackage[code=%s, message=%s]", response.code(), response.message()));
320 result= CommonConstant.CONSTANT_FAILED;;
322 } catch (IOException e) {
323 log.error("downLoadVnfPackage occur exception:"+e);
324 result= CommonConstant.CONSTANT_FAILED;;
331 public String deleteNsdPackage(String nsdInfoId) {
332 Response<ResponseBody> response=null;
335 log.info("vfc deleteNsdPackage is starting!");
336 response = this.vfcService.deleteNsdPackage(nsdInfoId).execute();
337 log.info("vfc deleteNsdPackage has finished!");
338 if (response.isSuccessful()) {
339 result= CommonConstant.CONSTANT_SUCCESS;
341 log.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
342 result= CommonConstant.CONSTANT_FAILED;;
344 } catch (IOException e) {
345 if(e.getMessage().contains("204")){
346 return CommonConstant.CONSTANT_SUCCESS;
348 log.error("deleteNsdPackage occur exception:"+e);
349 result= CommonConstant.CONSTANT_FAILED;;
356 public String deleteVnfPackage(String vnfPkgId) {
357 Response<ResponseBody> response=null;
360 log.info("vfc deleteVnfPackage is starting!");
361 response = this.vfcService.deleteVnfdPackage(vnfPkgId).execute();
362 log.info("vfc deleteVnfPackage has finished!");
363 if (response.isSuccessful()) {
364 result= CommonConstant.CONSTANT_SUCCESS;
366 log.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
367 result= CommonConstant.CONSTANT_FAILED;;
369 } catch (IOException e) {
370 if(e.getMessage().contains("204")){
371 return CommonConstant.CONSTANT_SUCCESS;
373 log.error("deleteVnfPackage occur exception:"+e);
374 result= CommonConstant.CONSTANT_FAILED;;
381 public String deletePnfPackage(String pnfdInfoId) {
382 Response<ResponseBody> response=null;
385 log.info("vfc deletePnfPackage is starting!");
386 response = this.vfcService.deletePnfdPackage(pnfdInfoId).execute();
387 log.info("vfc deletePnfPackage has finished!");
388 if (response.isSuccessful()) {
389 result= CommonConstant.CONSTANT_SUCCESS;
391 log.info(String.format("Can not get deletePnfPackage[code=%s, message=%s]", response.code(), response.message()));
392 result= CommonConstant.CONSTANT_FAILED;;
394 } catch (IOException e) {
395 if(e.getMessage().contains("204")){
396 return CommonConstant.CONSTANT_SUCCESS;
398 log.error("deletePnfPackage occur exception:"+e);
399 result= CommonConstant.CONSTANT_FAILED;;
406 public List<String> getNetworkServiceInfo() {
407 List<String> result = new ArrayList<>();
409 log.info("vfc getNetworkServiceInfo is starting!");
410 Response<nsServiceRsp> response = this.vfcService.getNetworkServiceInfo().execute();
411 log.info("vfc getNetworkServiceInfo has finished!");
412 if (response.isSuccessful()) {
413 List<String> nsServices = response.body().nsServices;
414 if(nsServices.size()>0){
415 for(String nsService:nsServices){
416 JSONObject object = JSON.parseObject(nsService);
417 String serviceInstanceId=object.get("nsInstanceId").toString();
418 ServiceBean serviceBean = serviceLcmService.getServiceBeanByServiceInStanceId(serviceInstanceId);
419 object.put("serviceDomain",serviceBean.getServiceDomain());
420 object.put("childServiceInstances","[]");
421 result.add(object.toString());
426 log.info(String.format("Can not get getNetworkServiceInfo[code=%s, message=%s]", response.code(), response.message()));
427 return Collections.emptyList();
429 } catch (IOException e) {
430 log.error("getNetworkServiceInfo occur exception:"+e);
431 return Collections.emptyList();
437 public String createNetworkServiceInstance(HttpServletRequest request) {
440 log.info("aai createNetworkServiceInstance is starting");
441 RequestBody requestBody = extractBody(request);
442 Response<ResponseBody> response = vfcService.createNetworkServiceInstance(requestBody).execute();
443 log.info("aai createNetworkServiceInstance has finished");
444 if (response.isSuccessful()) {
445 result=new String(response.body().bytes());
447 result= CommonConstant.CONSTANT_FAILED;
448 log.error(String.format("Can not createNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
450 } catch (Exception e) {
451 result= CommonConstant.CONSTANT_FAILED;
452 log.error("createNetworkServiceInstance occur exception:"+e);
458 public String deleteNetworkServiceInstance(String nsInstanceId) {
459 Response response = null;
462 log.info("vfc deleteNetworkServiceInstance is starting!");
463 response = this.vfcService.deleteNetworkServiceInstance(nsInstanceId).execute();
464 log.info("vfc deleteNetworkServiceInstance has finished!");
465 if (response.isSuccessful()) {
466 result= CommonConstant.CONSTANT_SUCCESS;
468 log.info(String.format("Can not get deleteNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
469 result= CommonConstant.CONSTANT_FAILED;;
471 } catch (IOException e) {
472 if(e.getMessage().contains("204")){
473 return CommonConstant.CONSTANT_SUCCESS;
475 log.error("deleteNetworkServiceInstance occur exception:"+e);
476 result= CommonConstant.CONSTANT_FAILED;
483 public String terminateNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
486 log.info("aai terminateNetworkServiceInstance is starting");
487 RequestBody requestBody = extractBody(request);
488 Response<ResponseBody> response = vfcService.terminateNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
489 log.info("aai terminateNetworkServiceInstance has finished");
490 if (response.isSuccessful()) {
491 result=new String(response.body().bytes());
493 result= CommonConstant.CONSTANT_FAILED;
494 log.error(String.format("Can not terminateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
496 } catch (Exception e) {
497 result= CommonConstant.CONSTANT_FAILED;
498 log.error("terminateNetworkServiceInstance occur exception:"+e);
504 public String healNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
507 log.info("aai healNetworkServiceInstance is starting");
508 RequestBody requestBody = extractBody(request);
509 Response<ResponseBody> response = vfcService.healNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
510 log.info("aai healNetworkServiceInstance has finished");
511 if (response.isSuccessful()) {
512 result=new String(response.body().bytes());
514 result= CommonConstant.CONSTANT_FAILED;
515 log.error(String.format("Can not healNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
517 } catch (Exception e) {
518 result= CommonConstant.CONSTANT_FAILED;
519 log.error("healNetworkServiceInstance occur exception:"+e);
525 public String scaleNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
528 log.info("aai scaleNetworkServiceInstance is starting");
529 RequestBody requestBody = extractBody(request);
530 Response<ResponseBody> response = vfcService.scaleNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
531 log.info("aai scaleNetworkServiceInstance has finished");
532 if (response.isSuccessful()) {
533 result=new String(response.body().bytes());
535 result= CommonConstant.CONSTANT_FAILED;
536 log.error(String.format("Can not scaleNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
538 } catch (Exception e) {
539 result= CommonConstant.CONSTANT_FAILED;
540 log.error("scaleNetworkServiceInstance occur exception:"+e);
546 public String createNetworkServiceData(HttpServletRequest request) {
549 log.info("aai createNetworkServiceData is starting");
550 RequestBody requestBody = extractBody(request);
551 Response<ResponseBody> response = vfcService.createNetworkServiceData(requestBody).execute();
552 log.info("aai createNetworkServiceData has finished");
553 if (response.isSuccessful()) {
554 result=new String(response.body().bytes());
556 result= CommonConstant.CONSTANT_FAILED;
557 log.error(String.format("Can not createNetworkServiceData[code=%s, message=%s]", response.code(), response.message()));
559 } catch (Exception e) {
560 result= CommonConstant.CONSTANT_FAILED;
561 log.error("createNetworkServiceData occur exception:"+e);
567 public String createVnfData(HttpServletRequest request) {
570 log.info("aai createVnfData is starting");
571 RequestBody requestBody = extractBody(request);
572 Response<ResponseBody> response = vfcService.createVnfData(requestBody).execute();
573 log.info("aai createVnfData has finished");
574 if (response.isSuccessful()) {
575 result=new String(response.body().bytes());
577 result= CommonConstant.CONSTANT_FAILED;
578 log.error(String.format("Can not createVnfData[code=%s, message=%s]", response.code(), response.message()));
580 } catch (Exception e) {
581 result= CommonConstant.CONSTANT_FAILED;
582 log.error("createVnfData occur exception:"+e);
588 public String createPnfData(HttpServletRequest request) {
591 log.info("aai createPnfData is starting");
592 RequestBody requestBody = extractBody(request);
593 Response<ResponseBody> response = vfcService.createPnfData(requestBody).execute();
594 log.info("aai createPnfData has finished");
595 if (response.isSuccessful()) {
596 result=new String(response.body().bytes());
598 result= CommonConstant.CONSTANT_FAILED;
599 log.error(String.format("Can not createPnfData[code=%s, message=%s]", response.code(), response.message()));
601 } catch (Exception e) {
602 result= CommonConstant.CONSTANT_FAILED;
603 log.error("createPnfData occur exception:"+e);
609 public String getNsdInfo(String nsdInfoId) {
613 log.info("vfc getNsdInfo is starting!");
614 Response<ResponseBody> response = this.vfcService.getNsdInfo(nsdInfoId).execute();
615 log.info("vfc getNsdInfo has finished!");
616 if (response.isSuccessful()) {
617 result= CommonConstant.CONSTANT_SUCCESS;
619 log.info(String.format("Can not get getNsdInfo[code=%s, message=%s]", response.code(), response.message()));
620 result= CommonConstant.CONSTANT_FAILED;;
622 } catch (IOException e) {
623 log.error("getNsdInfo occur exception:"+e);
624 result= CommonConstant.CONSTANT_FAILED;;
631 public String getVnfInfo(String vnfPkgId) {
635 log.info("vfc getVnfInfo is starting!");
636 Response<ResponseBody> response = this.vfcService.getVnfInfo(vnfPkgId).execute();
637 log.info("vfc getVnfInfo has finished!");
638 if (response.isSuccessful()) {
639 result= CommonConstant.CONSTANT_SUCCESS;
641 log.info(String.format("Can not get getVnfInfo[code=%s, message=%s]", response.code(), response.message()));
642 result= CommonConstant.CONSTANT_FAILED;;
644 } catch (IOException e) {
645 log.error("getVnfInfo occur exception:"+e);
646 result= CommonConstant.CONSTANT_FAILED;;
653 public String getPnfInfo(String pnfdInfoId) {
657 log.info("vfc getPnfInfo is starting!");
658 Response<ResponseBody> response = this.vfcService.getPnfInfo(pnfdInfoId).execute();
659 log.info("vfc getPnfInfo has finished!");
660 if (response.isSuccessful()) {
661 result= CommonConstant.CONSTANT_SUCCESS;
663 log.info(String.format("Can not get getPnfInfo[code=%s, message=%s]", response.code(), response.message()));
664 result= CommonConstant.CONSTANT_FAILED;;
666 } catch (IOException e) {
667 log.error("getPnfInfo occur exception:"+e);
668 result= CommonConstant.CONSTANT_FAILED;;
675 public String listNsTemplates() {
679 log.info("vfc listNsTemplates is starting!");
680 Response<ResponseBody> response = this.vfcService.listNsTemplates().execute();
681 log.info("vfc listNsTemplates has finished!");
682 if (response.isSuccessful()) {
683 result=new String(response.body().bytes());
685 log.info(String.format("Can not get listNsTemplates[code=%s, message=%s]", response.code(), response.message()));
686 result= CommonConstant.CONSTANT_FAILED;;
688 } catch (IOException e) {
689 log.error("listNsTemplates occur exception:"+e);
690 result= CommonConstant.CONSTANT_FAILED;;
697 public String fetchNsTemplateData(HttpServletRequest request) {
700 log.info("aai fetchNsTemplateData is starting");
701 RequestBody requestBody = extractBody(request);
702 Response<ResponseBody> response = vfcService.fetchNsTemplateData(requestBody).execute();
703 log.info("aai fetchNsTemplateData has finished");
704 if (response.isSuccessful()) {
705 result=new String(response.body().bytes());
707 result= CommonConstant.CONSTANT_FAILED;
708 log.error(String.format("Can not fetchNsTemplateData[code=%s, message=%s]", response.code(), response.message()));
710 } catch (Exception e) {
711 result= CommonConstant.CONSTANT_FAILED;
712 log.error("fetchNsTemplateData occur exception:"+e);
718 public JSONObject fetchCCVPNTemplateData(HttpServletRequest request, String csarId) {
719 JSONObject result = new JSONObject();
721 RequestBody requestBody = extractBody(request);
722 // search template from vfc catalog
723 Response<ResponseBody> getResponse = this.vfcService.servicePackages(csarId).execute();
725 if (getResponse.isSuccessful()) {
726 // call vfc template parser
727 log.info("calling ccvpn template file parser is starting");
728 Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
729 log.info("calling ccvpn template file parser has finished");
730 if (response.isSuccessful()) {
731 result.put("status", CommonConstant.CONSTANT_SUCCESS);
732 result.put("result", JSONObject.parseObject(new String(response.body().bytes())));
734 result.put("status", CommonConstant.CONSTANT_FAILED);
735 result.put("error", String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
736 log.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
739 // distribute template files to vfc catalog
740 Response<ResponseBody> postResponse = this.vfcService.servicePackages(requestBody).execute();
741 if (postResponse.isSuccessful()) {
742 // call vfc template parser
743 log.info("calling ccvpn template file parser is starting");
744 Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
745 log.info("calling ccvpn template file parser has finished");
746 if (response.isSuccessful()) {
747 result.put("status", CommonConstant.CONSTANT_SUCCESS);
748 result.put("result",JSONObject.parseObject(new String(response.body().bytes())));
750 result.put("status", CommonConstant.CONSTANT_FAILED);
751 result.put("error",String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
752 log.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
755 result.put("status", CommonConstant.CONSTANT_FAILED);
756 result.put("error",String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
757 log.error(String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
760 } catch (Exception e) {
761 result.put("status", CommonConstant.CONSTANT_FAILED);
762 result.put("errorMessage", "calling ccvpn template parser happened exception:"+e);
768 public String instantiateNetworkServiceInstance(HttpServletRequest request, String serviceInstanceId) {
771 log.info("aai instantiateNetworkServiceInstance is starting");
772 RequestBody requestBody = extractBody(request);
773 Response<ResponseBody> response = vfcService.instantiateNetworkServiceInstance(requestBody,serviceInstanceId).execute();
774 log.info("aai instantiateNetworkServiceInstance has finished");
775 if (response.isSuccessful()) {
776 result=new String(response.body().bytes());
778 result= CommonConstant.CONSTANT_FAILED;
779 log.error(String.format("Can not instantiateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
781 } catch (Exception e) {
782 result= CommonConstant.CONSTANT_FAILED;
783 log.error("instantiateNetworkServiceInstance occur exception:"+e);
789 public String getVnfInfoById(String vnfinstid) {
793 log.info("vfc getVnfInfoById is starting!");
794 Response<ResponseBody> response = this.vfcService.getVnfInfoById(vnfinstid).execute();
795 log.info("vfc getVnfInfoById has finished!");
796 if (response.isSuccessful()) {
797 result=new String(response.body().bytes());
799 log.info(String.format("Can not get getVnfInfoById[code=%s, message=%s]", response.code(), response.message()));
800 result= CommonConstant.CONSTANT_FAILED;;
802 } catch (IOException e) {
803 log.error("getVnfInfoById occur exception:"+e);
804 result= CommonConstant.CONSTANT_FAILED;;