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.create;
26 import static org.onap.usecaseui.server.util.RestfulServices.extractBody;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.List;
33 import jakarta.annotation.Resource;
34 import jakarta.servlet.http.HttpServletRequest;
35 import lombok.RequiredArgsConstructor;
36 import lombok.extern.slf4j.Slf4j;
38 import org.onap.usecaseui.server.bean.ServiceBean;
39 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
40 import org.onap.usecaseui.server.constant.CommonConstant;
41 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
42 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
43 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
44 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
45 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
46 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
47 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
48 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
49 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
50 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
51 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
52 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.springframework.context.annotation.EnableAspectJAutoProxy;
56 import org.springframework.stereotype.Service;
58 import com.alibaba.fastjson.JSON;
59 import com.alibaba.fastjson.JSONObject;
61 import okhttp3.RequestBody;
62 import okhttp3.ResponseBody;
63 import retrofit2.Response;
66 @RequiredArgsConstructor
67 @Service("PackageDistributionService")
68 public class DefaultPackageDistributionService implements PackageDistributionService {
70 private final SDCCatalogService sdcCatalogService;
71 private final VfcService vfcService;
72 private final ServiceLcmService serviceLcmService;
75 public VfNsPackageInfo retrievePackageInfo() {
76 List<SDCServiceTemplate> nsTemplate = sdcNsPackageInfo();
77 List<Vnf> vnf = sdcVfPackageInfo();
78 return new VfNsPackageInfo(nsTemplate, vnf);
82 public List<Vnf> sdcVfPackageInfo() {
84 Response<List<Vnf>> response = sdcCatalogService.listResources(RESOURCETYPE_VF).execute();
85 if (response.isSuccessful()) {
86 return response.body();
88 log.info(String.format("Can not get VF resources[code=%s, message=%s]", response.code(), response.message()));
89 return Collections.emptyList();
91 } catch (IOException e) {
92 log.error("sdcVfPackageInfo occur exception.Details:"+e.getMessage());
98 public List<SDCServiceTemplate> sdcNsPackageInfo() {
100 Response<List<SDCServiceTemplate>> response = sdcCatalogService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED).execute();
101 if (response.isSuccessful()) {
102 return response.body();
104 log.info(String.format("Can not get NS services[code=%s, message=%s]", response.code(), response.message()));
105 return Collections.emptyList();
107 } catch (IOException e) {
108 log.error("sdcNsPackageInfo occur exception.Details:"+e.getMessage());
114 public DistributionResult postNsPackage(Csar csar) {
116 Response<DistributionResult> response = vfcService.distributeNsPackage(csar).execute();
117 if (response.isSuccessful()) {
118 return response.body();
120 log.info(String.format("Can not post NS packages[code=%s, message=%s]", response.code(), response.message()));
121 throw new VfcException("VFC service is not available!");
123 } catch (IOException e) {
124 throw new VfcException("VFC service is not available!", e);
129 public Job postVfPackage(Csar csar) {
131 Response<Job> response = vfcService.distributeVnfPackage(csar).execute();
132 if (response.isSuccessful()) {
133 return response.body();
135 log.info(String.format("Can not get VF packages[code=%s, message=%s]", response.code(), response.message()));
136 throw new VfcException("VFC service is not available!");
138 } catch (IOException e) {
139 throw new VfcException("VFC service is not available!", e);
144 public JobStatus getJobStatus(String jobId, String responseId) {
146 Response<JobStatus> response = vfcService.getJobStatus(jobId, responseId).execute();
147 if (response.isSuccessful()) {
148 return response.body();
150 log.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
151 throw new VfcException("VFC service is not available!");
153 } catch (IOException e) {
154 throw new VfcException("VFC service is not available!", e);
159 public JobStatus getNsLcmJobStatus(String serviceInstanceId,String jobId, String responseId,String operationType) { try {
160 Response<JobStatus> response = vfcService.getNsLcmJobStatus(jobId, responseId).execute();
161 if (response.isSuccessful()) {
162 return response.body();
164 log.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
165 throw new VfcException("VFC service getNsLcmJobStatus is not available!");
167 } catch (IOException e) {
168 throw new VfcException("VFC service getNsLcmJobStatus is not available!", e);
172 public DistributionResult deleteNsPackage(String csarId) {
174 Response<DistributionResult> response = vfcService.deleteNsPackage(csarId).execute();
175 if (response.isSuccessful()) {
176 return response.body();
178 log.info(String.format("Can not delete NS packages[code=%s, message=%s]", response.code(), response.message()));
179 throw new VfcException("VFC service is not available!");
181 } catch (IOException e) {
182 throw new VfcException("VFC service is not available!", e);
187 public Job deleteVfPackage(String csarId) {
189 Response<Job> response = vfcService.deleteVnfPackage(csarId).execute();
190 if (response.isSuccessful()) {
191 return response.body();
193 log.info(String.format("Can not delete VF packages[code=%s, message=%s]", response.code(), response.message()));
194 throw new VfcException("VFC service is not available!");
196 } catch (IOException e) {
197 throw new VfcException("VFC service is not available!", e);
202 public String getVnfPackages() {
205 log.info("vfc getVnfPackages is starting!");
206 Response<ResponseBody> response = this.vfcService.getVnfPackages().execute();
207 log.info("vfc getVnfPackages has finished!");
208 if (response.isSuccessful()) {
209 result=new String(response.body().bytes());
211 log.info(String.format("Can not get getVnfPackages[code=%s, message=%s]", response.code(), response.message()));
212 result= CommonConstant.CONSTANT_FAILED;;
214 } catch (IOException e) {
215 log.error("getVnfPackages occur exception:"+e);
216 result= CommonConstant.CONSTANT_FAILED;;
222 public String getNetworkServicePackages() {
226 log.info("vfc getNetworkServicePackages is starting!");
227 Response<ResponseBody> response = this.vfcService.getNetworkServicePackages().execute();
228 log.info("vfc getNetworkServicePackages has finished!");
229 if (response.isSuccessful()) {
230 result=new String(response.body().bytes());
232 log.info(String.format("Can not get getNetworkServicePackages[code=%s, message=%s]", response.code(), response.message()));
233 result= CommonConstant.CONSTANT_FAILED;;
235 } catch (IOException e) {
236 log.error("getNetworkServicePackages occur exception:"+e);
237 result= CommonConstant.CONSTANT_FAILED;;
244 public String getPnfPackages() {
248 log.info("vfc getPnfPackages is starting!");
249 Response<ResponseBody> response = this.vfcService.getPnfPackages().execute();
250 log.info("vfc getPnfPackages has finished!");
251 if (response.isSuccessful()) {
252 result=new String(response.body().bytes());
254 log.info(String.format("Can not get getPnfPackages[code=%s, message=%s]", response.code(), response.message()));
255 result= CommonConstant.CONSTANT_FAILED;;
257 } catch (IOException e) {
258 log.error("getPnfPackages occur exception:"+e);
259 result= CommonConstant.CONSTANT_FAILED;;
266 public String downLoadNsPackage(String nsdInfoId) {
270 log.info("vfc downLoadNsPackage is starting!");
271 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(nsdInfoId).execute();
272 log.info("vfc downLoadNsPackage has finished!");
273 if (response.isSuccessful()) {
274 result= CommonConstant.CONSTANT_SUCCESS;
276 log.info(String.format("Can not get downLoadNsPackage[code=%s, message=%s]", response.code(), response.message()));
277 result= CommonConstant.CONSTANT_FAILED;;
279 } catch (IOException e) {
280 log.error("downLoadNsPackage occur exception:"+e);
281 result= CommonConstant.CONSTANT_FAILED;;
288 public String downLoadPnfPackage(String pnfdInfoId) {
292 log.info("vfc downLoadPnfPackage is starting!");
293 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(pnfdInfoId).execute();
294 log.info("vfc downLoadPnfPackage has finished!");
295 if (response.isSuccessful()) {
296 result= CommonConstant.CONSTANT_SUCCESS;
298 log.info(String.format("Can not get downLoadPnfPackage[code=%s, message=%s]", response.code(), response.message()));
299 result= CommonConstant.CONSTANT_FAILED;;
301 } catch (IOException e) {
302 log.error("downLoadPnfPackage occur exception:"+e);
303 result= CommonConstant.CONSTANT_FAILED;;
310 public String downLoadVnfPackage(String vnfPkgId) {
314 log.info("vfc downLoadVnfPackage is starting!");
315 Response<ResponseBody> response = this.vfcService.downLoadNsPackage(vnfPkgId).execute();
316 log.info("vfc downLoadVnfPackage has finished!");
317 if (response.isSuccessful()) {
318 result= CommonConstant.CONSTANT_SUCCESS;
320 log.info(String.format("Can not get downLoadVnfPackage[code=%s, message=%s]", response.code(), response.message()));
321 result= CommonConstant.CONSTANT_FAILED;;
323 } catch (IOException e) {
324 log.error("downLoadVnfPackage occur exception:"+e);
325 result= CommonConstant.CONSTANT_FAILED;;
332 public String deleteNsdPackage(String nsdInfoId) {
333 Response<ResponseBody> response=null;
336 log.info("vfc deleteNsdPackage is starting!");
337 response = this.vfcService.deleteNsdPackage(nsdInfoId).execute();
338 log.info("vfc deleteNsdPackage has finished!");
339 if (response.isSuccessful()) {
340 result= CommonConstant.CONSTANT_SUCCESS;
342 log.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
343 result= CommonConstant.CONSTANT_FAILED;;
345 } catch (IOException e) {
346 if(e.getMessage().contains("204")){
347 return CommonConstant.CONSTANT_SUCCESS;
349 log.error("deleteNsdPackage occur exception:"+e);
350 result= CommonConstant.CONSTANT_FAILED;;
357 public String deleteVnfPackage(String vnfPkgId) {
358 Response<ResponseBody> response=null;
361 log.info("vfc deleteVnfPackage is starting!");
362 response = this.vfcService.deleteVnfdPackage(vnfPkgId).execute();
363 log.info("vfc deleteVnfPackage has finished!");
364 if (response.isSuccessful()) {
365 result= CommonConstant.CONSTANT_SUCCESS;
367 log.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
368 result= CommonConstant.CONSTANT_FAILED;;
370 } catch (IOException e) {
371 if(e.getMessage().contains("204")){
372 return CommonConstant.CONSTANT_SUCCESS;
374 log.error("deleteVnfPackage occur exception:"+e);
375 result= CommonConstant.CONSTANT_FAILED;;
382 public String deletePnfPackage(String pnfdInfoId) {
383 Response<ResponseBody> response=null;
386 log.info("vfc deletePnfPackage is starting!");
387 response = this.vfcService.deletePnfdPackage(pnfdInfoId).execute();
388 log.info("vfc deletePnfPackage has finished!");
389 if (response.isSuccessful()) {
390 result= CommonConstant.CONSTANT_SUCCESS;
392 log.info(String.format("Can not get deletePnfPackage[code=%s, message=%s]", response.code(), response.message()));
393 result= CommonConstant.CONSTANT_FAILED;;
395 } catch (IOException e) {
396 if(e.getMessage().contains("204")){
397 return CommonConstant.CONSTANT_SUCCESS;
399 log.error("deletePnfPackage occur exception:"+e);
400 result= CommonConstant.CONSTANT_FAILED;;
407 public List<String> getNetworkServiceInfo() {
408 List<String> result = new ArrayList<>();
410 log.info("vfc getNetworkServiceInfo is starting!");
411 Response<nsServiceRsp> response = this.vfcService.getNetworkServiceInfo().execute();
412 log.info("vfc getNetworkServiceInfo has finished!");
413 if (response.isSuccessful()) {
414 List<String> nsServices = response.body().nsServices;
415 if(nsServices.size()>0){
416 for(String nsService:nsServices){
417 JSONObject object = JSON.parseObject(nsService);
418 String serviceInstanceId=object.get("nsInstanceId").toString();
419 ServiceBean serviceBean = serviceLcmService.getServiceBeanByServiceInStanceId(serviceInstanceId);
420 object.put("serviceDomain",serviceBean.getServiceDomain());
421 object.put("childServiceInstances","[]");
422 result.add(object.toString());
427 log.info(String.format("Can not get getNetworkServiceInfo[code=%s, message=%s]", response.code(), response.message()));
428 return Collections.emptyList();
430 } catch (IOException e) {
431 log.error("getNetworkServiceInfo occur exception:"+e);
432 return Collections.emptyList();
438 public String createNetworkServiceInstance(HttpServletRequest request) {
441 log.info("aai createNetworkServiceInstance is starting");
442 RequestBody requestBody = extractBody(request);
443 Response<ResponseBody> response = vfcService.createNetworkServiceInstance(requestBody).execute();
444 log.info("aai createNetworkServiceInstance has finished");
445 if (response.isSuccessful()) {
446 result=new String(response.body().bytes());
448 result= CommonConstant.CONSTANT_FAILED;
449 log.error(String.format("Can not createNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
451 } catch (Exception e) {
452 result= CommonConstant.CONSTANT_FAILED;
453 log.error("createNetworkServiceInstance occur exception:"+e);
459 public String deleteNetworkServiceInstance(String nsInstanceId) {
460 Response response = null;
463 log.info("vfc deleteNetworkServiceInstance is starting!");
464 response = this.vfcService.deleteNetworkServiceInstance(nsInstanceId).execute();
465 log.info("vfc deleteNetworkServiceInstance has finished!");
466 if (response.isSuccessful()) {
467 result= CommonConstant.CONSTANT_SUCCESS;
469 log.info(String.format("Can not get deleteNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
470 result= CommonConstant.CONSTANT_FAILED;;
472 } catch (IOException e) {
473 if(e.getMessage().contains("204")){
474 return CommonConstant.CONSTANT_SUCCESS;
476 log.error("deleteNetworkServiceInstance occur exception:"+e);
477 result= CommonConstant.CONSTANT_FAILED;
484 public String terminateNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
487 log.info("aai terminateNetworkServiceInstance is starting");
488 RequestBody requestBody = extractBody(request);
489 Response<ResponseBody> response = vfcService.terminateNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
490 log.info("aai terminateNetworkServiceInstance has finished");
491 if (response.isSuccessful()) {
492 result=new String(response.body().bytes());
494 result= CommonConstant.CONSTANT_FAILED;
495 log.error(String.format("Can not terminateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
497 } catch (Exception e) {
498 result= CommonConstant.CONSTANT_FAILED;
499 log.error("terminateNetworkServiceInstance occur exception:"+e);
505 public String healNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
508 log.info("aai healNetworkServiceInstance is starting");
509 RequestBody requestBody = extractBody(request);
510 Response<ResponseBody> response = vfcService.healNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
511 log.info("aai healNetworkServiceInstance has finished");
512 if (response.isSuccessful()) {
513 result=new String(response.body().bytes());
515 result= CommonConstant.CONSTANT_FAILED;
516 log.error(String.format("Can not healNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
518 } catch (Exception e) {
519 result= CommonConstant.CONSTANT_FAILED;
520 log.error("healNetworkServiceInstance occur exception:"+e);
526 public String scaleNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
529 log.info("aai scaleNetworkServiceInstance is starting");
530 RequestBody requestBody = extractBody(request);
531 Response<ResponseBody> response = vfcService.scaleNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
532 log.info("aai scaleNetworkServiceInstance has finished");
533 if (response.isSuccessful()) {
534 result=new String(response.body().bytes());
536 result= CommonConstant.CONSTANT_FAILED;
537 log.error(String.format("Can not scaleNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
539 } catch (Exception e) {
540 result= CommonConstant.CONSTANT_FAILED;
541 log.error("scaleNetworkServiceInstance occur exception:"+e);
547 public String createNetworkServiceData(HttpServletRequest request) {
550 log.info("aai createNetworkServiceData is starting");
551 RequestBody requestBody = extractBody(request);
552 Response<ResponseBody> response = vfcService.createNetworkServiceData(requestBody).execute();
553 log.info("aai createNetworkServiceData has finished");
554 if (response.isSuccessful()) {
555 result=new String(response.body().bytes());
557 result= CommonConstant.CONSTANT_FAILED;
558 log.error(String.format("Can not createNetworkServiceData[code=%s, message=%s]", response.code(), response.message()));
560 } catch (Exception e) {
561 result= CommonConstant.CONSTANT_FAILED;
562 log.error("createNetworkServiceData occur exception:"+e);
568 public String createVnfData(HttpServletRequest request) {
571 log.info("aai createVnfData is starting");
572 RequestBody requestBody = extractBody(request);
573 Response<ResponseBody> response = vfcService.createVnfData(requestBody).execute();
574 log.info("aai createVnfData has finished");
575 if (response.isSuccessful()) {
576 result=new String(response.body().bytes());
578 result= CommonConstant.CONSTANT_FAILED;
579 log.error(String.format("Can not createVnfData[code=%s, message=%s]", response.code(), response.message()));
581 } catch (Exception e) {
582 result= CommonConstant.CONSTANT_FAILED;
583 log.error("createVnfData occur exception:"+e);
589 public String createPnfData(HttpServletRequest request) {
592 log.info("aai createPnfData is starting");
593 RequestBody requestBody = extractBody(request);
594 Response<ResponseBody> response = vfcService.createPnfData(requestBody).execute();
595 log.info("aai createPnfData has finished");
596 if (response.isSuccessful()) {
597 result=new String(response.body().bytes());
599 result= CommonConstant.CONSTANT_FAILED;
600 log.error(String.format("Can not createPnfData[code=%s, message=%s]", response.code(), response.message()));
602 } catch (Exception e) {
603 result= CommonConstant.CONSTANT_FAILED;
604 log.error("createPnfData occur exception:"+e);
610 public String getNsdInfo(String nsdInfoId) {
614 log.info("vfc getNsdInfo is starting!");
615 Response<ResponseBody> response = this.vfcService.getNsdInfo(nsdInfoId).execute();
616 log.info("vfc getNsdInfo has finished!");
617 if (response.isSuccessful()) {
618 result= CommonConstant.CONSTANT_SUCCESS;
620 log.info(String.format("Can not get getNsdInfo[code=%s, message=%s]", response.code(), response.message()));
621 result= CommonConstant.CONSTANT_FAILED;;
623 } catch (IOException e) {
624 log.error("getNsdInfo occur exception:"+e);
625 result= CommonConstant.CONSTANT_FAILED;;
632 public String getVnfInfo(String vnfPkgId) {
636 log.info("vfc getVnfInfo is starting!");
637 Response<ResponseBody> response = this.vfcService.getVnfInfo(vnfPkgId).execute();
638 log.info("vfc getVnfInfo has finished!");
639 if (response.isSuccessful()) {
640 result= CommonConstant.CONSTANT_SUCCESS;
642 log.info(String.format("Can not get getVnfInfo[code=%s, message=%s]", response.code(), response.message()));
643 result= CommonConstant.CONSTANT_FAILED;;
645 } catch (IOException e) {
646 log.error("getVnfInfo occur exception:"+e);
647 result= CommonConstant.CONSTANT_FAILED;;
654 public String getPnfInfo(String pnfdInfoId) {
658 log.info("vfc getPnfInfo is starting!");
659 Response<ResponseBody> response = this.vfcService.getPnfInfo(pnfdInfoId).execute();
660 log.info("vfc getPnfInfo has finished!");
661 if (response.isSuccessful()) {
662 result= CommonConstant.CONSTANT_SUCCESS;
664 log.info(String.format("Can not get getPnfInfo[code=%s, message=%s]", response.code(), response.message()));
665 result= CommonConstant.CONSTANT_FAILED;;
667 } catch (IOException e) {
668 log.error("getPnfInfo occur exception:"+e);
669 result= CommonConstant.CONSTANT_FAILED;;
676 public String listNsTemplates() {
680 log.info("vfc listNsTemplates is starting!");
681 Response<ResponseBody> response = this.vfcService.listNsTemplates().execute();
682 log.info("vfc listNsTemplates has finished!");
683 if (response.isSuccessful()) {
684 result=new String(response.body().bytes());
686 log.info(String.format("Can not get listNsTemplates[code=%s, message=%s]", response.code(), response.message()));
687 result= CommonConstant.CONSTANT_FAILED;;
689 } catch (IOException e) {
690 log.error("listNsTemplates occur exception:"+e);
691 result= CommonConstant.CONSTANT_FAILED;;
698 public String fetchNsTemplateData(HttpServletRequest request) {
701 log.info("aai fetchNsTemplateData is starting");
702 RequestBody requestBody = extractBody(request);
703 Response<ResponseBody> response = vfcService.fetchNsTemplateData(requestBody).execute();
704 log.info("aai fetchNsTemplateData has finished");
705 if (response.isSuccessful()) {
706 result=new String(response.body().bytes());
708 result= CommonConstant.CONSTANT_FAILED;
709 log.error(String.format("Can not fetchNsTemplateData[code=%s, message=%s]", response.code(), response.message()));
711 } catch (Exception e) {
712 result= CommonConstant.CONSTANT_FAILED;
713 log.error("fetchNsTemplateData occur exception:"+e);
719 public JSONObject fetchCCVPNTemplateData(HttpServletRequest request, String csarId) {
720 JSONObject result = new JSONObject();
722 RequestBody requestBody = extractBody(request);
723 // search template from vfc catalog
724 Response<ResponseBody> getResponse = this.vfcService.servicePackages(csarId).execute();
726 if (getResponse.isSuccessful()) {
727 // call vfc template parser
728 log.info("calling ccvpn template file parser is starting");
729 Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
730 log.info("calling ccvpn template file parser has finished");
731 if (response.isSuccessful()) {
732 result.put("status", CommonConstant.CONSTANT_SUCCESS);
733 result.put("result", JSONObject.parseObject(new String(response.body().bytes())));
735 result.put("status", CommonConstant.CONSTANT_FAILED);
736 result.put("error", String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
737 log.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
740 // distribute template files to vfc catalog
741 Response<ResponseBody> postResponse = this.vfcService.servicePackages(requestBody).execute();
742 if (postResponse.isSuccessful()) {
743 // call vfc template parser
744 log.info("calling ccvpn template file parser is starting");
745 Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
746 log.info("calling ccvpn template file parser has finished");
747 if (response.isSuccessful()) {
748 result.put("status", CommonConstant.CONSTANT_SUCCESS);
749 result.put("result",JSONObject.parseObject(new String(response.body().bytes())));
751 result.put("status", CommonConstant.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 log.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
756 result.put("status", CommonConstant.CONSTANT_FAILED);
757 result.put("error",String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
758 log.error(String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
761 } catch (Exception e) {
762 result.put("status", CommonConstant.CONSTANT_FAILED);
763 result.put("errorMessage", "calling ccvpn template parser happened exception:"+e);
769 public String instantiateNetworkServiceInstance(HttpServletRequest request, String serviceInstanceId) {
772 log.info("aai instantiateNetworkServiceInstance is starting");
773 RequestBody requestBody = extractBody(request);
774 Response<ResponseBody> response = vfcService.instantiateNetworkServiceInstance(requestBody,serviceInstanceId).execute();
775 log.info("aai instantiateNetworkServiceInstance has finished");
776 if (response.isSuccessful()) {
777 result=new String(response.body().bytes());
779 result= CommonConstant.CONSTANT_FAILED;
780 log.error(String.format("Can not instantiateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
782 } catch (Exception e) {
783 result= CommonConstant.CONSTANT_FAILED;
784 log.error("instantiateNetworkServiceInstance occur exception:"+e);
790 public String getVnfInfoById(String vnfinstid) {
794 log.info("vfc getVnfInfoById is starting!");
795 Response<ResponseBody> response = this.vfcService.getVnfInfoById(vnfinstid).execute();
796 log.info("vfc getVnfInfoById has finished!");
797 if (response.isSuccessful()) {
798 result=new String(response.body().bytes());
800 log.info(String.format("Can not get getVnfInfoById[code=%s, message=%s]", response.code(), response.message()));
801 result= CommonConstant.CONSTANT_FAILED;;
803 } catch (IOException e) {
804 log.error("getVnfInfoById occur exception:"+e);
805 result= CommonConstant.CONSTANT_FAILED;;