Further changes for cnf-adpter in bpmn infra
[so.git] / adapters / mso-cnf-adapter / src / main / java / org / onap / so / adapters / cnf / rest / CnfAdapterRest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.cnf.rest;
22
23 import java.io.File;
24 import java.io.IOException;
25 import org.apache.http.HttpEntity;
26 import org.apache.http.client.methods.CloseableHttpResponse;
27 import org.apache.http.client.methods.HttpDelete;
28 import org.apache.http.client.methods.HttpGet;
29 import org.apache.http.client.methods.HttpPost;
30 import org.apache.http.client.methods.HttpPut;
31 import org.apache.http.entity.ContentType;
32 import org.apache.http.entity.StringEntity;
33 import org.apache.http.entity.mime.HttpMultipartMode;
34 import org.apache.http.entity.mime.MultipartEntityBuilder;
35 import org.apache.http.entity.mime.content.FileBody;
36 import org.apache.http.impl.client.CloseableHttpClient;
37 import org.apache.http.impl.client.HttpClients;
38 import org.apache.http.util.EntityUtils;
39 import org.onap.so.adapters.cnf.model.BpmnInstanceRequest;
40 import org.onap.so.adapters.cnf.model.ConfigTemplateEntity;
41 import org.onap.so.adapters.cnf.model.ConfigurationEntity;
42 import org.onap.so.adapters.cnf.model.ConfigurationRollbackEntity;
43 import org.onap.so.adapters.cnf.model.ConnectivityInfo;
44 import org.onap.so.adapters.cnf.model.InstanceMiniResponseList;
45 import org.onap.so.adapters.cnf.model.InstanceResponse;
46 import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
47 import org.onap.so.adapters.cnf.model.ProfileEntity;
48 import org.onap.so.adapters.cnf.model.ResourceBundleEntity;
49 import org.onap.so.adapters.cnf.model.Tag;
50 import org.onap.so.adapters.cnf.service.CnfAdapterService;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 import org.springframework.beans.factory.annotation.Autowired;
54 import org.springframework.http.ResponseEntity;
55 import org.springframework.web.bind.annotation.PathVariable;
56 import org.springframework.web.bind.annotation.RequestBody;
57 import org.springframework.web.bind.annotation.RequestMapping;
58 import org.springframework.web.bind.annotation.RequestMethod;
59 import org.springframework.web.bind.annotation.RequestParam;
60 import org.springframework.web.bind.annotation.ResponseBody;
61 import org.springframework.web.bind.annotation.RestController;
62 import org.springframework.web.multipart.MultipartFile;
63 import com.fasterxml.jackson.core.JsonParseException;
64 import com.fasterxml.jackson.databind.JsonMappingException;
65 import com.fasterxml.jackson.databind.ObjectMapper;
66 import com.fasterxml.jackson.databind.SerializationFeature;
67
68 @RestController
69 public class CnfAdapterRest {
70
71     private static final Logger logger = LoggerFactory.getLogger(CnfAdapterRest.class);
72     private final CloseableHttpClient httpClient = HttpClients.createDefault();
73
74     @Autowired
75     private CnfAdapterService cnfAdapterService;
76
77     @ResponseBody
78     @RequestMapping(value = {"/api/cnf-adapter/v1/healthcheck"}, method = RequestMethod.GET,
79             produces = "application/json")
80     public ResponseEntity<String> healthCheck() throws Exception {
81
82         logger.info("healthCheck called.");
83         return cnfAdapterService.healthCheck();
84
85     }
86
87     @ResponseBody
88     @RequestMapping(value = {"/api/cnf-adapter/v1/instance"}, method = RequestMethod.POST,
89             produces = "application/json", consumes = "application/json")
90     public String createInstance(@RequestBody BpmnInstanceRequest bpmnInstanceRequest)
91             throws JsonParseException, JsonMappingException, IOException {
92
93         logger.info("createInstance called.");
94         return cnfAdapterService.createInstance(bpmnInstanceRequest);
95     }
96
97     @ResponseBody
98     @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instID}"}, method = RequestMethod.GET,
99             produces = "application/json")
100     public ResponseEntity<InstanceResponse> getInstanceByInstanceId(@PathVariable("instID") String instanceId)
101             throws JsonParseException, JsonMappingException, IOException {
102
103         logger.info("getInstanceByInstanceId called.");
104
105         return cnfAdapterService.getInstanceByInstanceId(instanceId);
106
107     }
108
109     @ResponseBody
110     @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instID}/status"}, method = RequestMethod.GET,
111             produces = "application/json")
112     public ResponseEntity<InstanceStatusResponse> getInstanceStatusByInstanceId(
113             @PathVariable("instID") String instanceId) throws JsonParseException, JsonMappingException, IOException {
114
115         logger.info("getInstanceStatusByInstanceId called.");
116
117         return cnfAdapterService.getInstanceStatusByInstanceId(instanceId);
118
119     }
120
121     @RequestMapping(value = {"/api/cnf-adapter/v1/instance"}, method = RequestMethod.GET, produces = "application/json")
122     public ResponseEntity<InstanceMiniResponseList> getInstanceByRBNameOrRBVersionOrProfileName(
123             @RequestParam(value = "rb-name", required = false) String rbName,
124             @RequestParam(value = "rb-version", required = false) String rbVersion,
125             @RequestParam(value = "profile-name", required = false) String profileName)
126             throws JsonParseException, JsonMappingException, IOException {
127
128         logger.info("getInstanceByRBNameOrRBVersionOrProfileName called.");
129         return cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName);
130
131     }
132
133     @ResponseBody
134     @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instID}"}, method = RequestMethod.DELETE,
135             produces = "application/json")
136     public ResponseEntity<String> deleteInstanceByInstanceId(@PathVariable("instID") String instanceID)
137             throws JsonParseException, JsonMappingException, IOException {
138
139         logger.info("deleteInstanceByInstanceId called.");
140         return cnfAdapterService.deleteInstanceByInstanceId(instanceID);
141
142     }
143
144     @ResponseBody
145     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition"}, method = RequestMethod.POST,
146             produces = "application/json")
147     public String createRB(@RequestBody ResourceBundleEntity rB) throws Exception {
148
149         logger.info("ResourceBundleEntity:" + rB.toString());
150
151         // TODO
152         // Below URL should be changed as appropriate multicloud URL.
153         HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/rb/definition");
154         ObjectMapper objectMapper = new ObjectMapper();
155         objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
156         String requestBody = objectMapper.writeValueAsString(rB);
157         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
158         post.setEntity(requestEntity);
159
160         try (CloseableHttpClient httpClient = HttpClients.createDefault();
161                 CloseableHttpResponse response = httpClient.execute(post)) {
162             logger.info("response:" + response.getEntity());
163             return EntityUtils.toString(response.getEntity());
164         }
165     }
166
167     @ResponseBody
168     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}"}, method = RequestMethod.GET,
169             produces = "application/json")
170     public String getRB(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
171             throws Exception {
172
173         logger.info("get RB called.");
174
175         // TODO
176         // Below URL should be changed as appropriate multicloud URL.
177         HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion);
178         try (CloseableHttpResponse response = httpClient.execute(req)) {
179             logger.info("response:" + response.getEntity());
180             return EntityUtils.toString(response.getEntity());
181         }
182     }
183
184     @ResponseBody
185     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}"}, method = RequestMethod.DELETE,
186             produces = "application/json")
187     public String deleteRB(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
188             throws Exception {
189
190         logger.info("delete RB called.");
191
192         // TODO
193         // Below URL should be changed as appropriate multicloud URL.
194         HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion);
195
196         try (CloseableHttpResponse response = httpClient.execute(req)) {
197             logger.info("response:" + response.getEntity());
198             return EntityUtils.toString(response.getEntity());
199         }
200
201     }
202
203     @ResponseBody
204     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}"}, method = RequestMethod.GET,
205             produces = "application/json")
206     public String getListOfRB(@PathVariable("rb-name") String rbName) throws Exception {
207
208         logger.info("getListOfRB called.");
209
210         // TODO
211         // Below URL should be changed as appropriate multicloud URL.
212         HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName);
213
214         try (CloseableHttpResponse response = httpClient.execute(req)) {
215             logger.info("response:" + response.getEntity());
216             return EntityUtils.toString(response.getEntity());
217         }
218
219     }
220
221     @ResponseBody
222     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition"}, method = RequestMethod.GET,
223             produces = "application/json")
224     public String getListOfRBWithoutUsingRBName() throws Exception {
225
226         logger.info("getListOfRBWithoutUsingRBName called.");
227
228         // TODO
229         // Below URL should be changed as appropriate multicloud URL.
230         HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition");
231
232         try (CloseableHttpResponse response = httpClient.execute(req)) {
233             logger.info("response:" + response.getEntity());
234             return EntityUtils.toString(response.getEntity());
235         }
236
237     }
238
239     @ResponseBody
240     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/content"},
241             method = RequestMethod.POST, produces = "multipart/form-data")
242     public String uploadArtifactForRB(@RequestParam("file") MultipartFile file, @PathVariable("rb-name") String rbName,
243             @PathVariable("rb-version") String rbVersion) throws Exception {
244
245         logger.info("Upload  Artifact For RB called.");
246
247         File convFile = new File(file.getOriginalFilename());
248         file.transferTo(convFile);
249         FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
250         MultipartEntityBuilder builder = MultipartEntityBuilder.create();
251         builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
252         builder.addPart("file", fileBody);
253         HttpEntity entity = builder.build();
254
255         // TODO
256         // Below URL should be changed as appropriate multicloud URL.
257         HttpPost post =
258                 new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/content");
259         post.setHeader("Content-Type", "multipart/form-data");
260         logger.info(String.valueOf(post));
261         post.setEntity(entity);
262
263         try (CloseableHttpClient httpClient = HttpClients.createDefault();
264                 CloseableHttpResponse response = httpClient.execute(post)) {
265             logger.info("response:" + response.getEntity());
266             return EntityUtils.toString(response.getEntity());
267         }
268     }
269
270     @ResponseBody
271     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile"},
272             method = RequestMethod.POST, produces = "application/json")
273     public String createProfile(@RequestBody ProfileEntity fE, @PathVariable("rb-name") String rbName,
274             @PathVariable("rb-version") String rbVersion) throws Exception {
275
276         logger.info("create Profile called.");
277
278         // TODO
279         // Below URL should be changed as appropriate multicloud URL.
280         HttpPost post =
281                 new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
282         ObjectMapper objectMapper = new ObjectMapper();
283         String requestBody = objectMapper.writeValueAsString(fE);
284         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
285         post.setEntity(requestEntity);
286
287         try (CloseableHttpClient httpClient = HttpClients.createDefault();
288                 CloseableHttpResponse response = httpClient.execute(post)) {
289             logger.info("response:" + response.getEntity());
290             return EntityUtils.toString(response.getEntity());
291         }
292     }
293
294     @ResponseBody
295     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
296             method = RequestMethod.GET, produces = "application/json")
297     public String getProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
298             @PathVariable("pr-name") String prName) throws Exception {
299
300         logger.info("get Profile called.");
301
302         // TODO
303         // Below URL should be changed as appropriate multicloud URL.
304         HttpGet req = new HttpGet(
305                 "http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
306
307         try (CloseableHttpResponse response = httpClient.execute(req)) {
308             logger.info("response:" + response.getEntity());
309             return EntityUtils.toString(response.getEntity());
310         }
311     }
312
313     @ResponseBody
314     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile"},
315             method = RequestMethod.GET, produces = "application/json")
316     public String getListOfProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion)
317             throws Exception {
318
319         logger.info("getListOfProfile called.");
320
321         // TODO
322         // Below URL should be changed as appropriate multicloud URL.
323         HttpGet req =
324                 new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
325
326         try (CloseableHttpResponse response = httpClient.execute(req)) {
327             logger.info("response:" + response.getEntity());
328             return EntityUtils.toString(response.getEntity());
329         }
330     }
331
332     @ResponseBody
333     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}"},
334             method = RequestMethod.DELETE, produces = "application/json")
335     public String deleteProfile(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
336             @PathVariable("pr-name") String prName) throws Exception {
337
338         logger.info("delete Profile called.");
339
340         // TODO
341         // Below URL should be changed as appropriate multicloud URL.
342         HttpDelete req = new HttpDelete(
343                 "http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile/" + prName);
344
345         try (CloseableHttpResponse response = httpClient.execute(req)) {
346             logger.info("response:" + response.getEntity());
347             return EntityUtils.toString(response.getEntity());
348         }
349
350     }
351
352     @ResponseBody
353     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/profile/{pr-name}/content"},
354             method = RequestMethod.POST, produces = "multipart/form-data")
355     public String uploadArtifactForProfile(@RequestParam("file") MultipartFile file,
356             @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
357             @PathVariable("pr-name") String prName) throws Exception {
358
359         logger.info("Upload  Artifact For Profile called.");
360
361         File convFile = new File(file.getOriginalFilename());
362         file.transferTo(convFile);
363         FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
364         MultipartEntityBuilder builder = MultipartEntityBuilder.create();
365         builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
366         builder.addPart("file", fileBody);
367         HttpEntity entity = builder.build();
368
369         // TODO
370         // Below URL should be changed as appropriate multicloud URL.
371         HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion
372                 + "/profile/" + prName + "/content");
373         post.setHeader("Content-Type", "multipart/form-data");
374
375         logger.info(String.valueOf(post));
376         post.setEntity(entity);
377
378         try (CloseableHttpClient httpClient = HttpClients.createDefault();
379                 CloseableHttpResponse response = httpClient.execute(post)) {
380             logger.info("response:" + response.getEntity());
381             return EntityUtils.toString(response.getEntity());
382         }
383     }
384
385     @ResponseBody
386     @RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config"},
387             method = RequestMethod.POST, produces = "application/json")
388     public String createConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
389             @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName)
390             throws Exception {
391
392         logger.info("create Configuration called.");
393
394         // TODO
395         // Below URL should be changed as appropriate multicloud URL.
396         HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion
397                 + "/profile/" + prName + "/config");
398         ObjectMapper objectMapper = new ObjectMapper();
399         String requestBody = objectMapper.writeValueAsString(cE);
400         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
401         post.setEntity(requestEntity);
402
403         try (CloseableHttpClient httpClient = HttpClients.createDefault();
404                 CloseableHttpResponse response = httpClient.execute(post)) {
405             logger.info("response:" + response.getEntity());
406             return EntityUtils.toString(response.getEntity());
407         }
408     }
409
410     @ResponseBody
411     @RequestMapping(
412             value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
413             method = RequestMethod.GET, produces = "application/json")
414     public String getConfiguration(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
415             @PathVariable("profile-name") String prName, @PathVariable("cfg-name") String cfgName) throws Exception {
416
417         logger.info("get Configuration called.");
418
419         // TODO
420         // Below URL should be changed as appropriate multicloud URL.
421         HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
422                 + prName + "/config/" + cfgName);
423
424         try (CloseableHttpResponse response = httpClient.execute(req)) {
425             logger.info("response:" + response.getEntity());
426             return EntityUtils.toString(response.getEntity());
427         }
428     }
429
430     @ResponseBody
431     @RequestMapping(
432             value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
433             method = RequestMethod.DELETE, produces = "application/json")
434     public String deleteConfiguration(@PathVariable("rb-name") String rbName,
435             @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
436             @PathVariable("cfg-name") String cfgName) throws Exception {
437
438         logger.info("delete Configuration called.");
439
440         // TODO
441         // Below URL should be changed as appropriate multicloud URL.
442         HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion
443                 + "/profile/" + prName + "/config/" + cfgName);
444
445         try (CloseableHttpResponse response = httpClient.execute(req)) {
446             logger.info("response:" + response.getEntity());
447             return EntityUtils.toString(response.getEntity());
448         }
449
450     }
451
452     @ResponseBody
453     @RequestMapping(
454             value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/config/{cfg-name}"},
455             method = RequestMethod.PUT, produces = "application/json")
456     public String updateConfiguration(@RequestBody ConfigurationEntity cE, @PathVariable("rb-name") String rbName,
457             @PathVariable("rb-version") String rbVersion, @PathVariable("profile-name") String prName,
458             @PathVariable("cfg-name") String cfgName) throws Exception {
459
460         logger.info("update Configuration called.");
461
462         // TODO
463         // Below URL should be changed as appropriate multicloud URL.
464         HttpPut post = new HttpPut("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion + "/profile/"
465                 + prName + "/config/" + cfgName);
466         ObjectMapper objectMapper = new ObjectMapper();
467         String requestBody = objectMapper.writeValueAsString(cE);
468         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
469         post.setEntity(requestEntity);
470
471         try (CloseableHttpClient httpClient = HttpClients.createDefault();
472                 CloseableHttpResponse response = httpClient.execute(post)) {
473             logger.info("response:" + response.getEntity());
474             return EntityUtils.toString(response.getEntity());
475         }
476     }
477
478     @ResponseBody
479     @RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rb-name}/{rb-version}/profile/{profile-name}/tagit"},
480             method = RequestMethod.POST, produces = "application/json")
481     public String tagConfigurationValue(@RequestBody Tag tag, @PathVariable("rb-name") String rbName,
482             @PathVariable("rb-version") String rbVersion, @PathVariable("pr-name") String prName) throws Exception {
483         logger.info("Tag Configuration called.");
484
485         // TODO
486         // Below URL should be changed as appropriate multicloud URL.
487         HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion
488                 + "/profile/" + prName + "/config/tagit");
489
490         ObjectMapper objectMapper = new ObjectMapper();
491         String requestBody = objectMapper.writeValueAsString(tag);
492         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
493         post.setEntity(requestEntity);
494
495         try (CloseableHttpClient httpClient = HttpClients.createDefault();
496                 CloseableHttpResponse response = httpClient.execute(post)) {
497             logger.info("response:" + response.getEntity());
498             return EntityUtils.toString(response.getEntity());
499         }
500     }
501
502     @ResponseBody
503     @RequestMapping(value = {"/api/cnf-adapter/v1/connectivity-info"}, method = RequestMethod.POST,
504             produces = "application/json")
505     public String createConnectivityInfo(@RequestBody ConnectivityInfo cIE) throws Exception {
506
507         logger.info("create ConnectivityInfo called.");
508
509         // TODO
510         // Below URL should be changed as appropriate multicloud URL.
511         HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/connectivity-info");
512         ObjectMapper objectMapper = new ObjectMapper();
513         String requestBody = objectMapper.writeValueAsString(cIE);
514         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
515         post.setEntity(requestEntity);
516
517         try (CloseableHttpClient httpClient = HttpClients.createDefault();
518                 CloseableHttpResponse response = httpClient.execute(post)) {
519             logger.info("response:" + response.getEntity());
520             return EntityUtils.toString(response.getEntity());
521         }
522     }
523
524     @ResponseBody
525     @RequestMapping(value = {"/api/cnf-adapter/v1/connectivity-info/{connname}"}, method = RequestMethod.GET,
526             produces = "application/json")
527     public String getConnectivityInfo(@PathVariable("connname") String connName) throws Exception {
528
529         logger.info("get Connectivity Info called.");
530
531         // TODO
532         // Below URL should be changed as appropriate multicloud URL.
533         HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/connectivity-info/" + connName);
534
535         try (CloseableHttpResponse response = httpClient.execute(req)) {
536             logger.info("response:" + response.getEntity());
537             return EntityUtils.toString(response.getEntity());
538         }
539     }
540
541     @ResponseBody
542     @RequestMapping(value = {"/api/cnf-adapter/v1/connectivity-info/{connname}"}, method = RequestMethod.DELETE,
543             produces = "application/json")
544     public String deleteConnectivityInfo(@PathVariable("connname") String connName) throws Exception {
545
546         logger.info("delete Connectivity Info called.");
547
548         // TODO
549         // Below URL should be changed as appropriate multicloud URL.
550         HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/connectivity-info/" + connName);
551
552         try (CloseableHttpResponse response = httpClient.execute(req)) {
553             logger.info("response:" + response.getEntity());
554             return EntityUtils.toString(response.getEntity());
555         }
556
557     }
558
559     @ResponseBody
560     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template"},
561             method = RequestMethod.POST, produces = "application/json")
562     public String createConfigTemplate(@RequestBody ConfigTemplateEntity tE, @PathVariable("rb-name") String rbName,
563             @PathVariable("rb-version") String rbVersion) throws Exception {
564
565         logger.info("createConfigTemplate called.");
566
567         // TODO
568         // Below URL should be changed as appropriate multicloud URL.
569         HttpPost post = new HttpPost(
570                 "http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/config-template");
571         ObjectMapper objectMapper = new ObjectMapper();
572         String requestBody = objectMapper.writeValueAsString(tE);
573         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
574         post.setEntity(requestEntity);
575
576         try (CloseableHttpClient httpClient = HttpClients.createDefault();
577                 CloseableHttpResponse response = httpClient.execute(post)) {
578             logger.info("response:" + response.getEntity());
579             return EntityUtils.toString(response.getEntity());
580         }
581     }
582
583     @ResponseBody
584     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
585             method = RequestMethod.GET, produces = "application/json")
586     public String getConfigTemplate(@PathVariable("rb-name") String rbName,
587             @PathVariable("rb-version") String rbVersion, @PathVariable("tname") String tName) throws Exception {
588
589         logger.info("getConfigTemplate called.");
590
591         // TODO
592         // Below URL should be changed as appropriate multicloud URL.
593         HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion
594                 + "/config-template/" + tName);
595
596         try (CloseableHttpResponse response = httpClient.execute(req)) {
597             logger.info("response:" + response.getEntity());
598             return EntityUtils.toString(response.getEntity());
599         }
600     }
601
602     @ResponseBody
603     @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}"},
604             method = RequestMethod.DELETE, produces = "application/json")
605     public String deleteTemplate(@PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
606             @PathVariable("tname") String tName) throws Exception {
607
608         logger.info("deleteTemplate called.");
609
610         // TODO
611         // Below URL should be changed as appropriate multicloud URL.
612         HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion
613                 + "/config-template/" + tName);
614
615         try (CloseableHttpResponse response = httpClient.execute(req)) {
616             logger.info("response:" + response.getEntity());
617             return EntityUtils.toString(response.getEntity());
618         }
619
620     }
621
622     @ResponseBody
623     @RequestMapping(
624             value = {"/api/cnf-adapter/v1/rb/definition/{rb-name}/{rb-version}/config-template/{tname}/content"},
625             method = RequestMethod.POST, produces = "multipart/form-data")
626     public String uploadTarFileForTemplate(@RequestParam("file") MultipartFile file,
627             @PathVariable("rb-name") String rbName, @PathVariable("rb-version") String rbVersion,
628             @PathVariable("tname") String tName) throws Exception {
629
630         logger.info("uploadTarFileForTemplate called.");
631
632         File convFile = new File(file.getOriginalFilename());
633         file.transferTo(convFile);
634         FileBody fileBody = new FileBody(convFile, ContentType.DEFAULT_BINARY);
635         MultipartEntityBuilder builder = MultipartEntityBuilder.create();
636         builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
637         builder.addPart("file", fileBody);
638         HttpEntity entity = builder.build();
639
640         // TODO
641         // Below URL should be changed as appropriate multicloud URL.
642         HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion
643                 + "/config-template/" + tName + "/content");
644         post.setHeader("Content-Type", "multipart/form-data");
645
646         logger.info(String.valueOf(post));
647         post.setEntity(entity);
648
649         try (CloseableHttpClient httpClient = HttpClients.createDefault();
650                 CloseableHttpResponse response = httpClient.execute(post)) {
651             logger.info("response:" + response.getEntity());
652             return EntityUtils.toString(response.getEntity());
653         }
654     }
655
656     @ResponseBody
657     @RequestMapping(value = {"/api/cnf-adapter/v1/definition/{rbName}/{rbVersion}/profile/{prName}/config/rollback"},
658             method = RequestMethod.DELETE, produces = "application/json")
659     public String rollbackConfiguration(@RequestBody ConfigurationRollbackEntity rE,
660             @PathVariable("rbName") String rbName, @PathVariable("rbVersion") String rbVersion,
661             @PathVariable("prName") String prName) throws Exception {
662         logger.info("rollbackConfiguration called.");
663
664         // TODO
665         // Below URL should be changed as appropriate multicloud URL.
666         HttpPost post = new HttpPost("http://multicloud-k8s:9015/v1/definition/" + rbName + "/" + rbVersion
667                 + "/profile/" + prName + "/config/rollback");
668
669         ObjectMapper objectMapper = new ObjectMapper();
670         String requestBody = objectMapper.writeValueAsString(rE);
671         StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
672         post.setEntity(requestEntity);
673
674         try (CloseableHttpClient httpClient = HttpClients.createDefault();
675                 CloseableHttpResponse response = httpClient.execute(post)) {
676             logger.info("response:" + response.getEntity());
677             return EntityUtils.toString(response.getEntity());
678         }
679     }
680
681 }