aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionService.java
blob: e3b758e467c0d44e490eebe78423ad3c1bd27e24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
/**
 * Copyright 2016-2017 ZTE Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onap.usecaseui.server.service.lcm.impl;

import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.CATEGORY_NS;
import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.DISTRIBUTION_STATUS_DISTRIBUTED;
import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.RESOURCETYPE_VF;

import static org.onap.usecaseui.server.util.RestfulServices.create;
import static org.onap.usecaseui.server.util.RestfulServices.extractBody;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.onap.usecaseui.server.bean.ServiceBean;
import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
import org.onap.usecaseui.server.constant.CommonConstant;
import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Response;

@Service("PackageDistributionService")
@org.springframework.context.annotation.Configuration
@EnableAspectJAutoProxy
public class DefaultPackageDistributionService implements PackageDistributionService {

    private static final Logger logger = LoggerFactory.getLogger(DefaultPackageDistributionService.class);

    private SDCCatalogService sdcCatalogService;

    private VfcService vfcService;
    
    @Resource(name="ServiceLcmService")
    private ServiceLcmService serviceLcmService;

    public DefaultPackageDistributionService() {
        this(create(SDCCatalogService.class), create(VfcService.class));
    }

    public DefaultPackageDistributionService(SDCCatalogService sdcCatalogService, VfcService vfcService) {
        this.sdcCatalogService = sdcCatalogService;
        this.vfcService = vfcService;
    }

    public void setServiceLcmService(ServiceLcmService serviceLcmService) {
        this.serviceLcmService = serviceLcmService;
    }
    
    @Override
    public VfNsPackageInfo retrievePackageInfo() {
            List<SDCServiceTemplate> nsTemplate = sdcNsPackageInfo();
            List<Vnf> vnf = sdcVfPackageInfo();
            return new VfNsPackageInfo(nsTemplate, vnf);
    }
    
    @Override
    public List<Vnf> sdcVfPackageInfo() {
        try {
            Response<List<Vnf>> response = sdcCatalogService.listResources(RESOURCETYPE_VF).execute();
            if (response.isSuccessful()) {
                return response.body();
            } else {
                logger.info(String.format("Can not get VF resources[code=%s, message=%s]", response.code(), response.message()));
                return Collections.emptyList();
            }
        } catch (IOException e) {
            logger.error("sdcVfPackageInfo occur exception.Details:"+e.getMessage());
        }
        return null;
    }
    
    @Override
    public List<SDCServiceTemplate> sdcNsPackageInfo() {
        try {
            Response<List<SDCServiceTemplate>> response = sdcCatalogService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED).execute();
            if (response.isSuccessful()) {
                return response.body();
            } else {
                logger.info(String.format("Can not get NS services[code=%s, message=%s]", response.code(), response.message()));
                return Collections.emptyList();
            }
        } catch (IOException e) {
            logger.error("sdcNsPackageInfo occur exception.Details:"+e.getMessage());
        }
        return null;
    }
    
    @Override
    public DistributionResult postNsPackage(Csar csar) {
        try {
            Response<DistributionResult> response = vfcService.distributeNsPackage(csar).execute();
            if (response.isSuccessful()) {
                return response.body();
            } else {
                logger.info(String.format("Can not post NS packages[code=%s, message=%s]", response.code(), response.message()));
                throw new VfcException("VFC service is not available!");
            }
        } catch (IOException e) {
            throw new VfcException("VFC service is not available!", e);
        }
    }

    @Override
    public Job postVfPackage(Csar csar) {
        try {
            Response<Job> response = vfcService.distributeVnfPackage(csar).execute();
            if (response.isSuccessful()) {
                return response.body();
            } else {
                logger.info(String.format("Can not get VF packages[code=%s, message=%s]", response.code(), response.message()));
                throw new VfcException("VFC service is not available!");
            }
        } catch (IOException e) {
            throw new VfcException("VFC service is not available!", e);
        }
    }

    @Override
    public JobStatus getJobStatus(String jobId, String responseId) {
        try {
            Response<JobStatus> response = vfcService.getJobStatus(jobId, responseId).execute();
            if (response.isSuccessful()) {
                return response.body();
            } else {
                logger.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
                throw new VfcException("VFC service is not available!");
            }
        } catch (IOException e) {
            throw new VfcException("VFC service is not available!", e);
        }
    }
    
    @Override
    public JobStatus getNsLcmJobStatus(String serviceInstanceId,String jobId, String responseId,String operationType) {        try {
        Response<JobStatus> response = vfcService.getNsLcmJobStatus(jobId, responseId).execute();
        if (response.isSuccessful()) {
            return response.body();
        } else {
            logger.info(String.format("Can not get Job status[code=%s, message=%s]", response.code(), response.message()));
            throw new VfcException("VFC service getNsLcmJobStatus is not available!");
        }
    } catch (IOException e) {
        throw new VfcException("VFC service getNsLcmJobStatus is not available!", e);
    }}
    
    @Override
    public DistributionResult deleteNsPackage(String csarId) {
        try {
            Response<DistributionResult> response = vfcService.deleteNsPackage(csarId).execute();
            if (response.isSuccessful()) {
                return response.body();
            } else {
                logger.info(String.format("Can not delete NS packages[code=%s, message=%s]", response.code(), response.message()));
                throw new VfcException("VFC service is not available!");
            }
        } catch (IOException e) {
            throw new VfcException("VFC service is not available!", e);
        }
    }

    @Override
    public Job deleteVfPackage(String csarId) {
        try {
            Response<Job> response = vfcService.deleteVnfPackage(csarId).execute();
            if (response.isSuccessful()) {
                return response.body();
            } else {
                logger.info(String.format("Can not delete VF packages[code=%s, message=%s]", response.code(), response.message()));
                throw new VfcException("VFC service is not available!");
            }
        } catch (IOException e) {
            throw new VfcException("VFC service is not available!", e);
        }
    }

    @Override
    public String getVnfPackages() {
        String result="";
        try {
            logger.info("vfc getVnfPackages is starting!");
            Response<ResponseBody> response = this.vfcService.getVnfPackages().execute();
            logger.info("vfc getVnfPackages has finished!");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                logger.info(String.format("Can not get getVnfPackages[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("getVnfPackages occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    }

    @Override
    public String getNetworkServicePackages() {

        String result="";
        try {
            logger.info("vfc getNetworkServicePackages is starting!");
            Response<ResponseBody> response = this.vfcService.getNetworkServicePackages().execute();
            logger.info("vfc getNetworkServicePackages has finished!");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                logger.info(String.format("Can not get getNetworkServicePackages[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("getNetworkServicePackages occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String getPnfPackages() {

        String result="";
        try {
            logger.info("vfc getPnfPackages is starting!");
            Response<ResponseBody> response = this.vfcService.getPnfPackages().execute();
            logger.info("vfc getPnfPackages has finished!");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                logger.info(String.format("Can not get getPnfPackages[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("getPnfPackages occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String downLoadNsPackage(String nsdInfoId) {

        String result="";
        try {
            logger.info("vfc downLoadNsPackage is starting!");
            Response<ResponseBody> response = this.vfcService.downLoadNsPackage(nsdInfoId).execute();
            logger.info("vfc downLoadNsPackage has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get downLoadNsPackage[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("downLoadNsPackage occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String downLoadPnfPackage(String pnfdInfoId) {

        String result="";
        try {
            logger.info("vfc downLoadPnfPackage is starting!");
            Response<ResponseBody> response = this.vfcService.downLoadNsPackage(pnfdInfoId).execute();
            logger.info("vfc downLoadPnfPackage has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get downLoadPnfPackage[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("downLoadPnfPackage occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String downLoadVnfPackage(String vnfPkgId) {

        String result="";
        try {
            logger.info("vfc downLoadVnfPackage is starting!");
            Response<ResponseBody> response = this.vfcService.downLoadNsPackage(vnfPkgId).execute();
            logger.info("vfc downLoadVnfPackage has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get downLoadVnfPackage[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("downLoadVnfPackage occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String deleteNsdPackage(String nsdInfoId) {
        Response<ResponseBody> response=null;
        String result="";
        try {
            logger.info("vfc deleteNsdPackage is starting!");
            response = this.vfcService.deleteNsdPackage(nsdInfoId).execute();
            logger.info("vfc deleteNsdPackage has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            if(e.getMessage().contains("204")){
                return CommonConstant.CONSTANT_SUCCESS;
            }
            logger.error("deleteNsdPackage occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String deleteVnfPackage(String vnfPkgId) {
        Response<ResponseBody> response=null;
        String result="";
        try {
            logger.info("vfc deleteVnfPackage is starting!");
            response = this.vfcService.deleteVnfdPackage(vnfPkgId).execute();
            logger.info("vfc deleteVnfPackage has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get deleteNsdPackage[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            if(e.getMessage().contains("204")){
                return CommonConstant.CONSTANT_SUCCESS;
            }
            logger.error("deleteVnfPackage occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String deletePnfPackage(String pnfdInfoId) {
        Response<ResponseBody> response=null;
        String result="";
        try {
            logger.info("vfc deletePnfPackage is starting!");
            response = this.vfcService.deletePnfdPackage(pnfdInfoId).execute();
            logger.info("vfc deletePnfPackage has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get deletePnfPackage[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            if(e.getMessage().contains("204")){
                return CommonConstant.CONSTANT_SUCCESS;
            }
            logger.error("deletePnfPackage occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public List<String> getNetworkServiceInfo() {
        List<String> result = new ArrayList<>();
        try {
            logger.info("vfc getNetworkServiceInfo is starting!");
            Response<nsServiceRsp> response = this.vfcService.getNetworkServiceInfo().execute();
            logger.info("vfc getNetworkServiceInfo has finished!");
            if (response.isSuccessful()) {
                List<String> nsServices = response.body().nsServices;
                if(nsServices.size()>0){
                    for(String nsService:nsServices){
                        JSONObject object =  JSON.parseObject(nsService);
                        String serviceInstanceId=object.get("nsInstanceId").toString();
                        ServiceBean serviceBean = serviceLcmService.getServiceBeanByServiceInStanceId(serviceInstanceId);
                        object.put("serviceDomain",serviceBean.getServiceDomain());
                        object.put("childServiceInstances","[]");
                        result.add(object.toString());
                    }
                }
                return result;
            } else {
                logger.info(String.format("Can not get getNetworkServiceInfo[code=%s, message=%s]", response.code(), response.message()));
                return Collections.emptyList();
            }
        } catch (IOException e) {
            logger.error("getNetworkServiceInfo occur exception:"+e);
            return Collections.emptyList();
        }
    
    }

    @Override
    public String createNetworkServiceInstance(HttpServletRequest request) {
        String result = "";
        try {
            logger.info("aai createNetworkServiceInstance is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.createNetworkServiceInstance(requestBody).execute();
            logger.info("aai createNetworkServiceInstance has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not createNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("createNetworkServiceInstance occur exception:"+e);
        }
        return result;
    }

    @Override
    public String deleteNetworkServiceInstance(String nsInstanceId) {
        Response response = null;
        String result="";
        try {
            logger.info("vfc deleteNetworkServiceInstance is starting!");
            response = this.vfcService.deleteNetworkServiceInstance(nsInstanceId).execute();
            logger.info("vfc deleteNetworkServiceInstance has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get deleteNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            if(e.getMessage().contains("204")){
                return CommonConstant.CONSTANT_SUCCESS;
            }
            logger.error("deleteNetworkServiceInstance occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;
        }
        return result;
    
    }

    @Override
    public String terminateNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
        String result = "";
        try {
            logger.info("aai terminateNetworkServiceInstance is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.terminateNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
            logger.info("aai terminateNetworkServiceInstance has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not terminateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("terminateNetworkServiceInstance occur exception:"+e);
        }
        return result;
    }

    @Override
    public String healNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
        String result = "";
        try {
            logger.info("aai healNetworkServiceInstance is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.healNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
            logger.info("aai healNetworkServiceInstance has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not healNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("healNetworkServiceInstance occur exception:"+e);
        }
        return result;
    }

    @Override
    public String scaleNetworkServiceInstance(HttpServletRequest request,String networkServiceInstanceId) {
        String result = "";
        try {
            logger.info("aai scaleNetworkServiceInstance is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.scaleNetworkServiceInstance(networkServiceInstanceId,requestBody).execute();
            logger.info("aai scaleNetworkServiceInstance has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not scaleNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("scaleNetworkServiceInstance occur exception:"+e);
        }
        return result;
    }

    @Override
    public String createNetworkServiceData(HttpServletRequest request) {
        String result = "";
        try {
            logger.info("aai createNetworkServiceData is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.createNetworkServiceData(requestBody).execute();
            logger.info("aai createNetworkServiceData has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not createNetworkServiceData[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("createNetworkServiceData occur exception:"+e);
        }
        return result;
    }

    @Override
    public String createVnfData(HttpServletRequest request) {
        String result = "";
        try {
            logger.info("aai createVnfData is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.createVnfData(requestBody).execute();
            logger.info("aai createVnfData has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not createVnfData[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("createVnfData occur exception:"+e);
        }
        return result;
    }

    @Override
    public String createPnfData(HttpServletRequest request) {
        String result = "";
        try {
            logger.info("aai createPnfData is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.createPnfData(requestBody).execute();
            logger.info("aai createPnfData has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not createPnfData[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("createPnfData occur exception:"+e);
        }
        return result;
    }

    @Override
    public String getNsdInfo(String nsdInfoId) {

        String result="";
        try {
            logger.info("vfc getNsdInfo is starting!");
            Response<ResponseBody> response = this.vfcService.getNsdInfo(nsdInfoId).execute();
            logger.info("vfc getNsdInfo has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get getNsdInfo[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("getNsdInfo occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String getVnfInfo(String vnfPkgId) {

        String result="";
        try {
            logger.info("vfc getVnfInfo is starting!");
            Response<ResponseBody> response = this.vfcService.getVnfInfo(vnfPkgId).execute();
            logger.info("vfc getVnfInfo has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get getVnfInfo[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("getVnfInfo occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String getPnfInfo(String pnfdInfoId) {

        String result="";
        try {
            logger.info("vfc getPnfInfo is starting!");
            Response<ResponseBody> response = this.vfcService.getPnfInfo(pnfdInfoId).execute();
            logger.info("vfc getPnfInfo has finished!");
            if (response.isSuccessful()) {
                result= CommonConstant.CONSTANT_SUCCESS;
            } else {
                logger.info(String.format("Can not get getPnfInfo[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("getPnfInfo occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String listNsTemplates() {

        String result="";
        try {
            logger.info("vfc listNsTemplates is starting!");
            Response<ResponseBody> response = this.vfcService.listNsTemplates().execute();
            logger.info("vfc listNsTemplates has finished!");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                logger.info(String.format("Can not get listNsTemplates[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("listNsTemplates occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }

    @Override
    public String fetchNsTemplateData(HttpServletRequest request) {
        String result = "";
        try {
            logger.info("aai fetchNsTemplateData is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.fetchNsTemplateData(requestBody).execute();
            logger.info("aai fetchNsTemplateData has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not fetchNsTemplateData[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("fetchNsTemplateData occur exception:"+e);
        }
        return result;
    }
    
    @Override
    public JSONObject fetchCCVPNTemplateData(HttpServletRequest request, String csarId) {
        JSONObject result = new JSONObject();
        try {
            RequestBody requestBody = extractBody(request);
            // search template from vfc catalog
            Response<ResponseBody> getResponse = this.vfcService.servicePackages(csarId).execute();

            if (getResponse.isSuccessful()) {
                // call vfc template parser
                logger.info("calling ccvpn template file parser is starting");
                Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
                logger.info("calling ccvpn template file parser has finished");
                if (response.isSuccessful()) {
                    result.put("status", CommonConstant.CONSTANT_SUCCESS);
                    result.put("result", JSONObject.parseObject(new String(response.body().bytes())));
                } else {
                    result.put("status", CommonConstant.CONSTANT_FAILED);
                    result.put("error", String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
                    logger.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
               }
            } else {
                // distribute template files to vfc catalog
                Response<ResponseBody> postResponse = this.vfcService.servicePackages(requestBody).execute();
                if (postResponse.isSuccessful()) {
                    // call vfc template parser
                    logger.info("calling ccvpn template file parser is starting");
                    Response<ResponseBody> response = vfcService.fetchTemplateInfo(requestBody).execute();
                    logger.info("calling ccvpn template file parser has finished");
                    if (response.isSuccessful()) {
                        result.put("status", CommonConstant.CONSTANT_SUCCESS);
                        result.put("result",JSONObject.parseObject(new String(response.body().bytes())));
                    } else {
                        result.put("status", CommonConstant.CONSTANT_FAILED);
                        result.put("error",String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
                        logger.error(String.format("Can not parse ccvpn template file. Detail Info [code=%s, message=%s]", response.code(), response.message()));
                    }
                } else {
                    result.put("status", CommonConstant.CONSTANT_FAILED);
                    result.put("error",String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
                    logger.error(String.format("Can not distribute ccvpn template file. Detail Info [code=%s, message=%s]", postResponse.code(), postResponse.message()));
               }
            }
        } catch (Exception e) {
            result.put("status", CommonConstant.CONSTANT_FAILED);
            result.put("errorMessage", "calling ccvpn template parser happened exception:"+e);
        }
        return result;
    }
    
    @Override
    public String instantiateNetworkServiceInstance(HttpServletRequest request, String serviceInstanceId) {
        String result = "";
        try {
            logger.info("aai instantiateNetworkServiceInstance is starting");
            RequestBody requestBody = extractBody(request);
            Response<ResponseBody> response = vfcService.instantiateNetworkServiceInstance(requestBody,serviceInstanceId).execute();
            logger.info("aai instantiateNetworkServiceInstance has finished");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                result= CommonConstant.CONSTANT_FAILED;
                logger.error(String.format("Can not instantiateNetworkServiceInstance[code=%s, message=%s]", response.code(), response.message()));
            }
        } catch (Exception e) {
            result= CommonConstant.CONSTANT_FAILED;
            logger.error("instantiateNetworkServiceInstance occur exception:"+e);
        }
        return result;
    }

    @Override
    public String getVnfInfoById(String vnfinstid) {

        String result="";
        try {
            logger.info("vfc getVnfInfoById is starting!");
            Response<ResponseBody> response = this.vfcService.getVnfInfoById(vnfinstid).execute();
            logger.info("vfc getVnfInfoById has finished!");
            if (response.isSuccessful()) {
                result=new String(response.body().bytes());
            } else {
                logger.info(String.format("Can not get getVnfInfoById[code=%s, message=%s]", response.code(), response.message()));
                result= CommonConstant.CONSTANT_FAILED;;
            }
        } catch (IOException e) {
            logger.error("getVnfInfoById occur exception:"+e);
            result= CommonConstant.CONSTANT_FAILED;;
        }
        return result;
    
    }
}