summaryrefslogtreecommitdiffstats
path: root/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java
blob: afce77562d0b6e8bbe258cad82a64d36b065509f (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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
 * Modifications Copyright (C) 2021 Samsung Technologies Co.
 * Modifications Copyright (C) 2021 Orange.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */
package org.onap.so.adapters.cnf.rest;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.onap.so.adapters.cnf.MulticloudConfiguration;
import org.onap.so.adapters.cnf.client.SoCallbackClient;
import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
import org.onap.so.adapters.cnf.model.CheckInstanceRequest;
import org.onap.so.adapters.cnf.model.ConfigTemplateEntity;
import org.onap.so.adapters.cnf.model.ConfigurationEntity;
import org.onap.so.adapters.cnf.model.ConfigurationRollbackEntity;
import org.onap.so.adapters.cnf.model.ConnectivityInfo;
import org.onap.so.adapters.cnf.model.ProfileEntity;
import org.onap.so.adapters.cnf.model.ResourceBundleEntity;
import org.onap.so.adapters.cnf.model.Tag;
import org.onap.so.adapters.cnf.model.aai.AaiCallbackResponse;
import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse;
import org.onap.so.adapters.cnf.model.aai.AaiRequest;
import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse;
import org.onap.so.adapters.cnf.model.upgrade.InstanceUpgradeRequest;
import org.onap.so.adapters.cnf.service.CnfAdapterService;
import org.onap.so.adapters.cnf.service.aai.AaiService;
import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService;
import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService;
import org.onap.so.adapters.cnf.service.synchrornization.SynchronizationService;
import org.onap.so.adapters.cnf.service.upgrade.InstanceUpgradeService;
import org.onap.so.client.exception.BadResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class CnfAdapterRest {

    private static final Logger logger = LoggerFactory.getLogger(CnfAdapterRest.class);
    private final CloseableHttpClient httpClient = HttpClients.createDefault();
    private final SimpleStatusCheckService simpleStatusCheckService;
    private final HealthCheckService healthCheckService;
    private final InstanceUpgradeService instanceUpgradeService;
    private final CnfAdapterService cnfAdapterService;
    private final SoCallbackClient callbackClient;
    private final AaiService aaiService;
    private final SynchronizationService synchronizationService;
    private final String uri;

    @Autowired
    public CnfAdapterRest(SimpleStatusCheckService simpleStatusCheckService,
                          HealthCheckService healthCheckService,
                          InstanceUpgradeService instanceUpgradeService,
                          CnfAdapterService cnfAdapterService,
                          SoCallbackClient callbackClient,
                          AaiService aaiService,
                          SynchronizationService synchronizationService,
                          MulticloudConfiguration multicloudConfiguration) {
        this.simpleStatusCheckService = simpleStatusCheckService;
        this.healthCheckService = healthCheckService;
        this.instanceUpgradeService = instanceUpgradeService;
        this.cnfAdapterService = cnfAdapterService;
        this.aaiService = aaiService;
        this.callbackClient = callbackClient;
        this.synchronizationService = synchronizationService;
        this.uri = multicloudConfiguration.getMulticloudUrl();
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instanceID}/upgrade"}, method = RequestMethod.POST,
            produces = "application/json", consumes = "application/json")
    public String upgrade(@PathVariable("instanceID") String instanceId,
                          @RequestBody InstanceUpgradeRequest upgradeRequest) throws BadResponseException {
        logger.info("upgrade called for instance {}.", instanceId);
        return instanceUpgradeService.upgradeInstance(instanceId, upgradeRequest);
    }


    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/healthcheck"}, method = RequestMethod.POST,
            produces = "application/json")
    public DeferredResult<ResponseEntity> healthCheck(@RequestBody CheckInstanceRequest healthCheckRequest) {
        logger.info("healthCheck called.");
        DeferredResult<ResponseEntity> response = new DeferredResult<>();

        new Thread(() -> {
            logger.info("Processing health check request");

            HealthCheckResponse healthCheckResponse = null;
            try {
                healthCheckResponse = healthCheckService.healthCheck(healthCheckRequest);
            } catch (Exception e) {
                logger.error("END - Health check process failed", e);
                healthCheckResponse = healthCheckService.healthCheckError(healthCheckRequest, e);
            }
            callbackClient.sendPostCallback(healthCheckRequest.getCallbackUrl(), healthCheckResponse);
        }).start();

        response.setResult(ResponseEntity.accepted().build());
        return response;
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/aai-update/"}, method = RequestMethod.POST,
            produces = "application/json")
    public DeferredResult<ResponseEntity> aaiUpdate(@RequestBody AaiRequest aaiRequest) {
        logger.info("aai-update called.");
        DeferredResult<ResponseEntity> response = new DeferredResult<>();

        new Thread(() -> {
            logger.info("Processing aai update");
            AaiCallbackResponse callbackResponse = new AaiCallbackResponse();
            try {
                aaiService.aaiUpdate(aaiRequest);
                synchronizationService.createSubscriptionIfNotExists(aaiRequest);
                callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
            } catch (Exception e) {
                logger.warn("Failed to create resource in AAI", e);
                callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.FAILED);
                callbackResponse.setMessage(e.getMessage());
            }
            callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), callbackResponse);
        }).start();

        response.setResult(ResponseEntity.accepted().build());
        return response;
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/aai-delete/"}, method = RequestMethod.POST,
            produces = "application/json")
    public DeferredResult<ResponseEntity> aaiDelete(@RequestBody AaiRequest aaiRequest) {
        logger.info("aai-delete called.");
        DeferredResult<ResponseEntity> response = new DeferredResult<>();

        new Thread(() -> {
            logger.info("Processing aai delete");
            AaiCallbackResponse callbackResponse = new AaiCallbackResponse();
            try {
                synchronizationService.deleteSubscriptionIfExists(aaiRequest.getInstanceId());
                aaiService.aaiDelete(aaiRequest);
                callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.COMPLETED);
            } catch (Exception e) {
                logger.warn("Failed to delete resource from AAI", e);
                callbackResponse.setCompletionStatus(AaiCallbackResponse.CompletionStatus.FAILED);
                callbackResponse.setMessage(e.getMessage());
            }
            callbackClient.sendPostCallback(aaiRequest.getCallbackUrl(), callbackResponse);
        }).start();

        response.setResult(ResponseEntity.accepted().build());
        return response;
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/statuscheck"}, method = RequestMethod.POST,
            produces = "application/json")
    public DeferredResult<ResponseEntity> statusCheck(@RequestBody CheckInstanceRequest statusCheckRequest) {
        logger.info("statusCheck called.");
        DeferredResult<ResponseEntity> response = new DeferredResult<>();

        new Thread(() -> {
            logger.info("Processing status check request");
            StatusCheckResponse statusCheckResponse = null;
            try {
                statusCheckResponse = simpleStatusCheckService.statusCheck(statusCheckRequest);
            } catch (Exception e) {
                logger.error("END - Status check process failed", e);
                statusCheckResponse = simpleStatusCheckService.statusCheckError(statusCheckRequest, e);
            }
            callbackClient.sendPostCallback(statusCheckRequest.getCallbackUrl(), statusCheckResponse);
        }).start();

        response.setResult(ResponseEntity.accepted().build());
        return response;
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/instance"}, method = RequestMethod.POST,
            produces = "application/json", consumes = "application/json")
    public String createInstance(@RequestBody BpmnInstanceRequest bpmnInstanceRequest) throws BadResponseException {
        logger.info("createInstance called.");
        return cnfAdapterService.createInstance(bpmnInstanceRequest);
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instID}"}, method = RequestMethod.GET,
            produces = "application/json")
    public String getInstanceByInstanceId(@PathVariable("instID") String instanceId)
            throws JsonParseException, JsonMappingException, IOException {

        logger.info("getInstanceByInstanceId called.");

        return cnfAdapterService.getInstanceByInstanceId(instanceId);

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instID}/status"}, method = RequestMethod.GET,
            produces = "application/json")
    public String getInstanceStatusByInstanceId(@PathVariable("instID") String instanceId)
            throws JsonParseException, JsonMappingException, IOException {

        logger.info("getInstanceStatusByInstanceId called.");

        return cnfAdapterService.getInstanceStatusByInstanceId(instanceId);

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instanceId}/query"}, method = RequestMethod.GET,
            produces = "application/json")
    public String queryInstanceResources(
            @PathVariable("instanceId") String instanceId,
            @RequestParam(value = "Kind") String kind,
            @RequestParam(value = "ApiVersion") String apiVersion,
            @RequestParam(value = "Labels", required = false) String labels,
            @RequestParam(value = "Namespace", required = false) String namespace,
            @RequestParam(value = "Name", required = false) String name) {
        logger.info("queryInstanceResources called.");

        return cnfAdapterService.queryInstanceResources(instanceId, kind, apiVersion, name, labels, namespace);
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/query"}, method = RequestMethod.GET,
            produces = "application/json")
    public String queryResources(
            @RequestParam(value = "Kind") String kind,
            @RequestParam(value = "ApiVersion") String apiVersion,
            @RequestParam(value = "Labels", required = false) String labels,
            @RequestParam(value = "Namespace", required = false) String namespace,
            @RequestParam(value = "Name", required = false) String name,
            @RequestParam(value = "CloudRegion") String cloudRegion) {
        logger.info("queryResources called.");

        return cnfAdapterService.queryResources(kind, apiVersion, name, labels, namespace, cloudRegion);
    }

    @RequestMapping(value = {"/api/cnf-adapter/v1/instance"}, method = RequestMethod.GET, produces = "application/json")
    public String getInstanceByRBNameOrRBVersionOrProfileName(
            @RequestParam(value = "rb-name", required = false) String rbName,
            @RequestParam(value = "rb-version", required = false) String rbVersion,
            @RequestParam(value = "profile-name", required = false) String profileName)
            throws JsonParseException, JsonMappingException, IOException {

        logger.info("getInstanceByRBNameOrRBVersionOrProfileName called.");
        return cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName);

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instID}"}, method = RequestMethod.DELETE,
            produces = "application/json")
    public String deleteInstanceByInstanceId(@PathVariable("instID") String instanceID) throws BadResponseException {

        logger.info("deleteInstanceByInstanceId called.");
        if (instanceID == null || instanceID.isEmpty() || instanceID.equals("null")) {
            //we skip deletion of instance that was not created properly and instance id was not stored in AAI
            logger.warn("Undefined instance ID delete attempt. Skipping delete");
            return "";
        }
        synchronizationService.deleteSubscriptionIfExists(instanceID);
        return cnfAdapterService.deleteInstanceByInstanceId(instanceID);

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition"}, method = RequestMethod.POST,
            produces = "application/json")
    public String createRB(@RequestBody ResourceBundleEntity rB) throws Exception {

        logger.info("ResourceBundleEntity:" + rB.toString());

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(uri + "/v1/rb/definition");
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        String requestBody = objectMapper.writeValueAsString(rB);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}"}, method = RequestMethod.GET,
            produces = "application/json")
    public String getRB(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
            throws Exception {

        logger.info("get RB called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req = new HttpGet(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion);
        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}"}, method = RequestMethod.DELETE,
            produces = "application/json")
    public String deleteRB(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
            throws Exception {

        logger.info("delete RB called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpDelete req = new HttpDelete(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}"}, method = RequestMethod.GET,
            produces = "application/json")
    public String getListOfRB(@PathVariable("rb-name") String rbName) throws Exception {

        logger.info("getListOfRB called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req = new HttpGet(uri + "/v1/rb/definition/" + rbName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition"}, method = RequestMethod.GET,
            produces = "application/json")
    public String getListOfRBWithoutUsingRBName() throws Exception {

        logger.info("getListOfRBWithoutUsingRBName called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req = new HttpGet(uri + "/v1/rb/definition");

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/content"},
            method = RequestMethod.POST, produces = "multipart/form-data")
    public String uploadArtifactForRB(@RequestParam("file") MultipartFile file, @PathVariable("rb-name") String rbName,
                                      @PathVariable("rb-version") String rbVersion) throws Exception {

        logger.info("Upload  Artifact For RB called.");

        File convFile = new File(file.getOriginalFilename());
        file.transferTo(convFile);
        FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addPart("file", fileBody);
        HttpEntity entity = builder.build();

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post =
                new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/content");
        post.setHeader("Content-Type", "multipart/form-data");
        logger.info(String.valueOf(post));
        post.setEntity(entity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile"},
            method = RequestMethod.POST, produces = "application/json")
    public String createProfile(@RequestBody ProfileEntity fE, @PathVariable("rb-name") String rbName,
                                @PathVariable("rb-version") String rbVersion) throws Exception {

        logger.info("create Profile called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post =
                new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
        ObjectMapper objectMapper = new ObjectMapper();
        String requestBody = objectMapper.writeValueAsString(fE);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
            method = RequestMethod.GET, produces = "application/json")
    public String getProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
                             @PathVariable("pr-name") String prName) throws Exception {

        logger.info("get Profile called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req = new HttpGet(
                uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile"},
            method = RequestMethod.GET, produces = "application/json")
    public String getListOfProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
            throws Exception {

        logger.info("getListOfProfile called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req =
                new HttpGet(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
            method = RequestMethod.DELETE, produces = "application/json")
    public String deleteProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
                                @PathVariable("pr-name") String prName) throws Exception {

        logger.info("delete Profile called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpDelete req = new HttpDelete(
                uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}/content"},
            method = RequestMethod.POST, produces = "multipart/form-data")
    public String uploadArtifactForProfile(@RequestParam("file") MultipartFile file,
                                           @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
                                           @PathVariable("pr-name") String prName) throws Exception {

        logger.info("Upload  Artifact For Profile called.");

        File convFile = new File(file.getOriginalFilename());
        file.transferTo(convFile);
        FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addPart("file", fileBody);
        HttpEntity entity = builder.build();

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
                + "/profile/" + prName + "/content");
        post.setHeader("Content-Type", "multipart/form-data");

        logger.info(String.valueOf(post));
        post.setEntity(entity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config"},
            method = RequestMethod.POST, produces = "application/json")
    public String createConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
                                      @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName)
            throws Exception {

        logger.info("create Configuration called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(uri + "/v1/definition/" + rbName + "/" + rbVersion
                + "/profile/" + prName + "/config");
        ObjectMapper objectMapper = new ObjectMapper();
        String requestBody = objectMapper.writeValueAsString(cE);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(
            value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
            method = RequestMethod.GET, produces = "application/json")
    public String getConfiguration(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
                                   @PathVariable("profile-name") String prName, @PathVariable("cfg-name") String cfgName) throws Exception {

        logger.info("get Configuration called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req = new HttpGet(uri + "/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
                + prName + "/config/" + cfgName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(
            value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
            method = RequestMethod.DELETE, produces = "application/json")
    public String deleteConfiguration(@PathVariable("rb-name") String rbName,
                                      @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
                                      @PathVariable("cfg-name") String cfgName) throws Exception {

        logger.info("delete Configuration called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpDelete req = new HttpDelete(uri + "/v1/definition/" + rbName + "/" + rbVersion
                + "/profile/" + prName + "/config/" + cfgName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }

    }

    @ResponseBody
    @RequestMapping(
            value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
            method = RequestMethod.PUT, produces = "application/json")
    public String updateConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
                                      @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
                                      @PathVariable("cfg-name") String cfgName) throws Exception {

        logger.info("update Configuration called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPut post = new HttpPut(uri + "/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
                + prName + "/config/" + cfgName);
        ObjectMapper objectMapper = new ObjectMapper();
        String requestBody = objectMapper.writeValueAsString(cE);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/tagit"},
            method = RequestMethod.POST, produces = "application/json")
    public String tagConfigurationValue(@RequestBody Tag tag, @PathVariable("rb-name") String rbName,
                                        @PathVariable("rb-version") String rbVersion, @PathVariable("pr-name") String prName) throws Exception {
        logger.info("Tag Configuration called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(uri + "/v1/definition/" + rbName + "/" + rbVersion
                + "/profile/" + prName + "/config/tagit");

        ObjectMapper objectMapper = new ObjectMapper();
        String requestBody = objectMapper.writeValueAsString(tag);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/connectivity-info"}, method = RequestMethod.POST,
            produces = "application/json")
    public String createConnectivityInfo(@RequestBody ConnectivityInfo cIE) throws Exception {

        logger.info("create ConnectivityInfo called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(uri + "/v1/connectivity-info");
        ObjectMapper objectMapper = new ObjectMapper();
        String requestBody = objectMapper.writeValueAsString(cIE);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/connectivity-info/{connname}"}, method = RequestMethod.GET,
            produces = "application/json")
    public String getConnectivityInfo(@PathVariable("connname") String connName) throws Exception {

        logger.info("get Connectivity Info called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req = new HttpGet(uri + "/v1/connectivity-info/" + connName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/connectivity-info/{connname}"}, method = RequestMethod.DELETE,
            produces = "application/json")
    public String deleteConnectivityInfo(@PathVariable("connname") String connName) throws Exception {

        logger.info("delete Connectivity Info called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpDelete req = new HttpDelete(uri + "/v1/connectivity-info/" + connName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }

    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template"},
            method = RequestMethod.POST, produces = "application/json")
    public String createConfigTemplate(@RequestBody ConfigTemplateEntity tE, @PathVariable("rb-name") String rbName,
                                       @PathVariable("rb-version") String rbVersion) throws Exception {

        logger.info("createConfigTemplate called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(
                uri + "/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template");
        ObjectMapper objectMapper = new ObjectMapper();
        String requestBody = objectMapper.writeValueAsString(tE);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
            method = RequestMethod.GET, produces = "application/json")
    public String getConfigTemplate(@PathVariable("rb-name") String rbName,
                                    @PathVariable("rb-version") String rbVersion, @PathVariable("tname") String tName) throws Exception {

        logger.info("getConfigTemplate called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpGet req = new HttpGet(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
                + "/config-template/" + tName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
            method = RequestMethod.DELETE, produces = "application/json")
    public String deleteTemplate(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
                                 @PathVariable("tname") String tName) throws Exception {

        logger.info("deleteTemplate called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpDelete req = new HttpDelete(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
                + "/config-template/" + tName);

        try (CloseableHttpResponse response = httpClient.execute(req)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }

    }

    @ResponseBody
    @RequestMapping(
            value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}/content"},
            method = RequestMethod.POST, produces = "multipart/form-data")
    public String uploadTarFileForTemplate(@RequestParam("file") MultipartFile file,
                                           @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
                                           @PathVariable("tname") String tName) throws Exception {

        logger.info("uploadTarFileForTemplate called.");

        File convFile = new File(file.getOriginalFilename());
        file.transferTo(convFile);
        FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addPart("file", fileBody);
        HttpEntity entity = builder.build();

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(uri + "/v1/rb/definition/" + rbName + "/" + rbVersion
                + "/config-template/" + tName + "/content");
        post.setHeader("Content-Type", "multipart/form-data");

        logger.info(String.valueOf(post));
        post.setEntity(entity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

    @ResponseBody
    @RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rbName}/{rbVersion}/profile/{prName}/config/rollback"},
            method = RequestMethod.DELETE, produces = "application/json")
    public String rollbackConfiguration(@RequestBody ConfigurationRollbackEntity rE,
                                        @PathVariable("rbName") String rbName, @PathVariable("rbVersion") String rbVersion,
                                        @PathVariable("prName") String prName) throws Exception {
        logger.info("rollbackConfiguration called.");

        // TODO
        // Below URL should be changed as appropriate multicloud URL.
        HttpPost post = new HttpPost(uri + "/v1/definition/" + rbName + "/" + rbVersion
                + "/profile/" + prName + "/config/rollback");

        ObjectMapper objectMapper = new ObjectMapper();
        String requestBody = objectMapper.writeValueAsString(rE);
        StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
        post.setEntity(requestEntity);

        try (CloseableHttpClient httpClient = HttpClients.createDefault();
             CloseableHttpResponse response = httpClient.execute(post)) {
            logger.info("response:" + response.getEntity());
            return EntityUtils.toString(response.getEntity());
        }
    }

}