2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.svnfm.simulator.controller;
23 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.*;
24 import org.onap.so.svnfm.simulator.constants.Constant;
25 import org.onap.so.svnfm.simulator.repository.VnfmCacheRepository;
26 import org.onap.so.svnfm.simulator.services.SvnfmService;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.http.HttpHeaders;
31 import org.springframework.http.HttpStatus;
32 import org.springframework.http.ResponseEntity;
33 import org.springframework.web.bind.annotation.*;
34 import javax.ws.rs.core.MediaType;
35 import java.util.UUID;
38 * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
39 * @author Ronan Kenny (ronan.kenny@est.tech)
42 @RequestMapping(path = Constant.BASE_URL, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
43 public class SvnfmController {
45 private static final Logger LOGGER = LoggerFactory.getLogger(SvnfmController.class);
47 private SvnfmService svnfmService;
49 private VnfmCacheRepository vnfmCacheRepository;
52 * To create the Vnf and stores the response in cache
54 * @param createVNFRequest
55 * @return InlineResponse201
57 @PostMapping(value = "/vnf_instances")
58 public ResponseEntity<InlineResponse201> createVnf(@RequestBody final CreateVnfRequest createVNFRequest) {
59 LOGGER.info("Start createVnf {}", createVNFRequest);
60 final String id = UUID.randomUUID().toString();
61 final HttpHeaders headers = new HttpHeaders();
62 headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
63 final ResponseEntity<InlineResponse201> responseEntity =
64 new ResponseEntity<>(vnfmCacheRepository.createVnf(createVNFRequest, id), headers, HttpStatus.CREATED);
65 LOGGER.info("Finished create {}", responseEntity);
66 return responseEntity;
70 * Get the vnf by id from cache
73 * @return InlineResponse201
75 @GetMapping(value = "/vnf_instances/{vnfInstanceId}")
76 @ResponseStatus(code = HttpStatus.OK)
77 public InlineResponse201 getVnf(@PathVariable("vnfInstanceId") final String vnfId) {
78 LOGGER.info("Start getVnf------");
79 return vnfmCacheRepository.getVnf(vnfId);
83 * To instantiate the vnf and returns the operation id
86 * @throws InterruptedException
88 @PostMapping(value = "/vnf_instances/{vnfInstanceId}/instantiate")
89 public ResponseEntity<Void> instantiateVnf(@PathVariable("vnfInstanceId") final String vnfId) {
90 LOGGER.info("Start instantiateVNFRequest for vnf id {} ", vnfId);
92 final HttpHeaders headers = new HttpHeaders();
93 headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
94 headers.add(HttpHeaders.LOCATION, svnfmService.instantiateVnf(vnfId));
95 return new ResponseEntity<>(headers, HttpStatus.ACCEPTED);
99 * To delete the vnf by id
102 * @return InlineResponse201
104 @DeleteMapping(value = "/vnf_instances/{vnfInstanceId}")
105 @ResponseStatus(code = HttpStatus.OK)
106 public ResponseEntity<Void> deleteVnf(@PathVariable("vnfInstanceId") final String vnfId) {
107 LOGGER.info("Start deleting Vnf------");
108 vnfmCacheRepository.deleteVnf(vnfId);
109 final HttpHeaders headers = new HttpHeaders();
110 headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
111 return new ResponseEntity<>(headers, HttpStatus.NO_CONTENT);
115 * To terminate the vnf by id
118 * @throws InterruptedException
120 @PostMapping(value = "/vnf_instances/{vnfInstanceId}/terminate")
121 public ResponseEntity<Object> terminateVnf(@PathVariable("vnfInstanceId") final String vnfId) {
122 LOGGER.info("Start terminateVNFRequest {}", vnfId);
123 final HttpHeaders headers = new HttpHeaders();
124 headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
125 headers.add(HttpHeaders.LOCATION, svnfmService.terminateVnf(vnfId));
126 return new ResponseEntity<>(headers, HttpStatus.ACCEPTED);
131 * To get the status of the operation by id
134 * @return response entity
135 * @throws InterruptedException
137 @GetMapping(value = "/vnf_lcm_op_occs/{vnfLcmOpOccId}")
138 public ResponseEntity<InlineResponse200> getOperationStatus(
139 @PathVariable("vnfLcmOpOccId") final String operationId) {
140 LOGGER.info("Start getOperationStatus");
141 final HttpHeaders headers = new HttpHeaders();
142 headers.add("Content-Type", MediaType.APPLICATION_JSON);
143 return new ResponseEntity<>(svnfmService.getOperationStatus(operationId), headers, HttpStatus.OK);
146 @PostMapping(value = "/subscriptions")
147 public ResponseEntity<InlineResponse2001> subscribeForNotifications(
148 @RequestBody final LccnSubscriptionRequest lccnSubscriptionRequest) {
149 LOGGER.info("Subscription request received: {}", lccnSubscriptionRequest);
150 svnfmService.registerSubscription(lccnSubscriptionRequest);
151 final InlineResponse2001 response = new InlineResponse2001();
152 response.setId(UUID.randomUUID().toString());
153 final HttpHeaders headers = new HttpHeaders();
154 headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
155 return new ResponseEntity<>(response, headers, HttpStatus.CREATED);
158 @GetMapping(value = "/subscriptions/{id}")
159 public ResponseEntity<InlineResponse2001> getSubscribeId(@PathVariable("id") final String id) {
160 LOGGER.info("Subscription/id request received with id: {}", id);
161 final InlineResponse2001 response = new InlineResponse2001();
163 final HttpHeaders headers = new HttpHeaders();
164 headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
165 return new ResponseEntity<>(response, headers, HttpStatus.OK);