2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.cnf.rest;
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;
69 public class CnfAdapterRest {
71 private static final Logger logger = LoggerFactory.getLogger(CnfAdapterRest.class);
72 private final CloseableHttpClient httpClient = HttpClients.createDefault();
75 private CnfAdapterService cnfAdapterService;
78 @RequestMapping(value = {"/api/cnf-adapter/v1/healthcheck"}, method = RequestMethod.GET,
79 produces = "application/json")
80 public ResponseEntity<String> healthCheck() throws Exception {
82 logger.info("healthCheck called.");
83 return cnfAdapterService.healthCheck();
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 {
93 logger.info("createInstance called.");
94 return cnfAdapterService.createInstance(bpmnInstanceRequest);
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 {
103 logger.info("getInstanceByInstanceId called.");
105 return cnfAdapterService.getInstanceByInstanceId(instanceId);
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 {
115 logger.info("getInstanceStatusByInstanceId called.");
117 return cnfAdapterService.getInstanceStatusByInstanceId(instanceId);
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 {
128 logger.info("getInstanceByRBNameOrRBVersionOrProfileName called.");
129 return cnfAdapterService.getInstanceByRBNameOrRBVersionOrProfileName(rbName, rbVersion, profileName);
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 {
139 logger.info("deleteInstanceByInstanceId called.");
140 return cnfAdapterService.deleteInstanceByInstanceId(instanceID);
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 {
149 logger.info("ResourceBundleEntity:" + rB.toString());
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);
160 try (CloseableHttpClient httpClient = HttpClients.createDefault();
161 CloseableHttpResponse response = httpClient.execute(post)) {
162 logger.info("response:" + response.getEntity());
163 return EntityUtils.toString(response.getEntity());
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)
173 logger.info("get RB called.");
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());
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)
190 logger.info("delete RB called.");
193 // Below URL should be changed as appropriate multicloud URL.
194 HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion);
196 try (CloseableHttpResponse response = httpClient.execute(req)) {
197 logger.info("response:" + response.getEntity());
198 return EntityUtils.toString(response.getEntity());
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 {
208 logger.info("getListOfRB called.");
211 // Below URL should be changed as appropriate multicloud URL.
212 HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName);
214 try (CloseableHttpResponse response = httpClient.execute(req)) {
215 logger.info("response:" + response.getEntity());
216 return EntityUtils.toString(response.getEntity());
222 @RequestMapping(value = {"/api/cnf-adapter/v1/rb/definition"}, method = RequestMethod.GET,
223 produces = "application/json")
224 public String getListOfRBWithoutUsingRBName() throws Exception {
226 logger.info("getListOfRBWithoutUsingRBName called.");
229 // Below URL should be changed as appropriate multicloud URL.
230 HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/rb/definition");
232 try (CloseableHttpResponse response = httpClient.execute(req)) {
233 logger.info("response:" + response.getEntity());
234 return EntityUtils.toString(response.getEntity());
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 {
245 logger.info("Upload Artifact For RB called.");
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();
256 // Below URL should be changed as appropriate multicloud URL.
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);
263 try (CloseableHttpClient httpClient = HttpClients.createDefault();
264 CloseableHttpResponse response = httpClient.execute(post)) {
265 logger.info("response:" + response.getEntity());
266 return EntityUtils.toString(response.getEntity());
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 {
276 logger.info("create Profile called.");
279 // Below URL should be changed as appropriate multicloud URL.
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);
287 try (CloseableHttpClient httpClient = HttpClients.createDefault();
288 CloseableHttpResponse response = httpClient.execute(post)) {
289 logger.info("response:" + response.getEntity());
290 return EntityUtils.toString(response.getEntity());
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 {
300 logger.info("get Profile called.");
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);
307 try (CloseableHttpResponse response = httpClient.execute(req)) {
308 logger.info("response:" + response.getEntity());
309 return EntityUtils.toString(response.getEntity());
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)
319 logger.info("getListOfProfile called.");
322 // Below URL should be changed as appropriate multicloud URL.
324 new HttpGet("http://multicloud-k8s:9015/v1/rb/definition/" + rbName + "/" + rbVersion + "/profile");
326 try (CloseableHttpResponse response = httpClient.execute(req)) {
327 logger.info("response:" + response.getEntity());
328 return EntityUtils.toString(response.getEntity());
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 {
338 logger.info("delete Profile called.");
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);
345 try (CloseableHttpResponse response = httpClient.execute(req)) {
346 logger.info("response:" + response.getEntity());
347 return EntityUtils.toString(response.getEntity());
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 {
359 logger.info("Upload Artifact For Profile called.");
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();
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");
375 logger.info(String.valueOf(post));
376 post.setEntity(entity);
378 try (CloseableHttpClient httpClient = HttpClients.createDefault();
379 CloseableHttpResponse response = httpClient.execute(post)) {
380 logger.info("response:" + response.getEntity());
381 return EntityUtils.toString(response.getEntity());
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)
392 logger.info("create Configuration called.");
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);
403 try (CloseableHttpClient httpClient = HttpClients.createDefault();
404 CloseableHttpResponse response = httpClient.execute(post)) {
405 logger.info("response:" + response.getEntity());
406 return EntityUtils.toString(response.getEntity());
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 {
417 logger.info("get Configuration called.");
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);
424 try (CloseableHttpResponse response = httpClient.execute(req)) {
425 logger.info("response:" + response.getEntity());
426 return EntityUtils.toString(response.getEntity());
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 {
438 logger.info("delete Configuration called.");
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);
445 try (CloseableHttpResponse response = httpClient.execute(req)) {
446 logger.info("response:" + response.getEntity());
447 return EntityUtils.toString(response.getEntity());
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 {
460 logger.info("update Configuration called.");
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);
471 try (CloseableHttpClient httpClient = HttpClients.createDefault();
472 CloseableHttpResponse response = httpClient.execute(post)) {
473 logger.info("response:" + response.getEntity());
474 return EntityUtils.toString(response.getEntity());
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.");
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");
490 ObjectMapper objectMapper = new ObjectMapper();
491 String requestBody = objectMapper.writeValueAsString(tag);
492 StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
493 post.setEntity(requestEntity);
495 try (CloseableHttpClient httpClient = HttpClients.createDefault();
496 CloseableHttpResponse response = httpClient.execute(post)) {
497 logger.info("response:" + response.getEntity());
498 return EntityUtils.toString(response.getEntity());
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 {
507 logger.info("create ConnectivityInfo called.");
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);
517 try (CloseableHttpClient httpClient = HttpClients.createDefault();
518 CloseableHttpResponse response = httpClient.execute(post)) {
519 logger.info("response:" + response.getEntity());
520 return EntityUtils.toString(response.getEntity());
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 {
529 logger.info("get Connectivity Info called.");
532 // Below URL should be changed as appropriate multicloud URL.
533 HttpGet req = new HttpGet("http://multicloud-k8s:9015/v1/connectivity-info/" + connName);
535 try (CloseableHttpResponse response = httpClient.execute(req)) {
536 logger.info("response:" + response.getEntity());
537 return EntityUtils.toString(response.getEntity());
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 {
546 logger.info("delete Connectivity Info called.");
549 // Below URL should be changed as appropriate multicloud URL.
550 HttpDelete req = new HttpDelete("http://multicloud-k8s:9015/v1/connectivity-info/" + connName);
552 try (CloseableHttpResponse response = httpClient.execute(req)) {
553 logger.info("response:" + response.getEntity());
554 return EntityUtils.toString(response.getEntity());
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 {
565 logger.info("createConfigTemplate called.");
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);
576 try (CloseableHttpClient httpClient = HttpClients.createDefault();
577 CloseableHttpResponse response = httpClient.execute(post)) {
578 logger.info("response:" + response.getEntity());
579 return EntityUtils.toString(response.getEntity());
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 {
589 logger.info("getConfigTemplate called.");
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);
596 try (CloseableHttpResponse response = httpClient.execute(req)) {
597 logger.info("response:" + response.getEntity());
598 return EntityUtils.toString(response.getEntity());
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 {
608 logger.info("deleteTemplate called.");
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);
615 try (CloseableHttpResponse response = httpClient.execute(req)) {
616 logger.info("response:" + response.getEntity());
617 return EntityUtils.toString(response.getEntity());
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 {
630 logger.info("uploadTarFileForTemplate called.");
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();
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");
646 logger.info(String.valueOf(post));
647 post.setEntity(entity);
649 try (CloseableHttpClient httpClient = HttpClients.createDefault();
650 CloseableHttpResponse response = httpClient.execute(post)) {
651 logger.info("response:" + response.getEntity());
652 return EntityUtils.toString(response.getEntity());
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.");
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");
669 ObjectMapper objectMapper = new ObjectMapper();
670 String requestBody = objectMapper.writeValueAsString(rE);
671 StringEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON);
672 post.setEntity(requestEntity);
674 try (CloseableHttpClient httpClient = HttpClients.createDefault();
675 CloseableHttpResponse response = httpClient.execute(post)) {
676 logger.info("response:" + response.getEntity());
677 return EntityUtils.toString(response.getEntity());