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.svnfm.simulator.controller;
23 import java.util.UUID;
24 import javax.ws.rs.core.MediaType;
25 import org.onap.svnfm.simulator.repository.VnfmCacheRepository;
26 import org.onap.svnfm.simulator.services.SvnfmService;
27 import org.onap.vnfm.v1.model.CreateVnfRequest;
28 import org.onap.vnfm.v1.model.InlineResponse201;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.http.HttpHeaders;
33 import org.springframework.http.HttpStatus;
34 import org.springframework.http.ResponseEntity;
35 import org.springframework.web.bind.annotation.PathVariable;
36 import org.springframework.web.bind.annotation.RequestBody;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.bind.annotation.RequestMethod;
39 import org.springframework.web.bind.annotation.ResponseStatus;
40 import org.springframework.web.bind.annotation.RestController;
44 * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
45 * @author Ronan Kenny (ronan.kenny@est.tech)
48 @RequestMapping("/svnfm")
49 public class SvnfmController {
52 private SvnfmService svnfmService;
55 private VnfmCacheRepository vnfmCacheRepository;
57 private static final Logger LOGGER = LoggerFactory.getLogger(SvnfmController.class);
61 * @param createVNFRequest
64 @RequestMapping(method = RequestMethod.POST, value = "/vnf_instances")
65 public ResponseEntity<InlineResponse201> createVnf(@RequestBody final CreateVnfRequest createVNFRequest) {
66 LOGGER.info("Start createVnf------");
67 final HttpHeaders headers = new HttpHeaders();
68 headers.add("Content-Type", MediaType.APPLICATION_JSON);
69 return new ResponseEntity<>(vnfmCacheRepository.createVnf(createVNFRequest), headers, HttpStatus.CREATED);
75 * @return vnfm cache repository
77 @RequestMapping(method = RequestMethod.GET, value = "/vnf_instances/{vnfInstanceId}",
78 produces = MediaType.APPLICATION_JSON)
79 @ResponseStatus(code = HttpStatus.OK)
80 public InlineResponse201 getVnf(@PathVariable("vnfInstanceId") final String vnfId) {
81 LOGGER.info("Start getVnf------");
82 return vnfmCacheRepository.getVnf(vnfId);
88 * @return response entity
89 * @throws InterruptedException
91 @RequestMapping(method = RequestMethod.POST, value = "/vnf_instances/{vnfInstanceId}/instantiate")
92 public ResponseEntity<Object> instantiateVnf(@PathVariable("vnfInstanceId") final String vnfId)
93 throws InterruptedException {
94 LOGGER.info("Start instantiateVNFRequest");
95 final String instantiateJobId = UUID.randomUUID().toString();
96 final HttpHeaders headers = new HttpHeaders();
97 headers.add("Content-Type", MediaType.APPLICATION_JSON);
98 headers.add("Location", instantiateJobId);
99 return new ResponseEntity<>(svnfmService.instatiateVnf(vnfId, instantiateJobId), headers, HttpStatus.ACCEPTED);
105 * @return response entity
106 * @throws InterruptedException
108 public ResponseEntity<Object> getJobStatus(@PathVariable("jobId") final String jobId) throws InterruptedException {
109 LOGGER.info("Start getJobStatus");
110 final HttpHeaders headers = new HttpHeaders();
111 headers.add("Content-Type", MediaType.APPLICATION_JSON);
112 return new ResponseEntity<>(svnfmService.getJobStatus(jobId), headers, HttpStatus.ACCEPTED);
120 @RequestMapping(method = RequestMethod.DELETE, value = "/vnf_instances/{vnfInstanceId}",
121 produces = MediaType.APPLICATION_JSON)
122 @ResponseStatus(code = HttpStatus.OK)
123 public InlineResponse201 deleteVnf(@PathVariable("vnfInstanceId") final String vnfId) {
124 LOGGER.info("Start deleting Vnf------");
125 return vnfmCacheRepository.deleteVnf(vnfId);
131 * @return response entity
132 * @throws InterruptedException
134 @RequestMapping(method = RequestMethod.POST, value = "/vnf_instances/{vnfInstanceId}/terminate")
135 public ResponseEntity<Object> terminateVnf(@PathVariable("vnfInstanceId") final String vnfId)
136 throws InterruptedException {
137 LOGGER.info("Start terminateVNFRequest");
138 final HttpHeaders headers = new HttpHeaders();
139 headers.add("Content-Type", MediaType.APPLICATION_JSON);
140 return new ResponseEntity<>(svnfmService.terminateVnf(vnfId), headers, HttpStatus.ACCEPTED);