2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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=========================================================
20 package org.onap.so.etsi.nfvo.ns.lcm.rest;
22 import static org.onap.so.etsi.nfvo.ns.lcm.Constants.HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME;
23 import static org.onap.so.etsi.nfvo.ns.lcm.Constants.HTTP_SERVICETYPE_HEADER_DEFAULT_VALUE;
24 import static org.onap.so.etsi.nfvo.ns.lcm.Constants.HTTP_SERVICETYPE_HEADER_PARM_NAME;
25 import static org.onap.so.etsi.nfvo.ns.lcm.Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL;
26 import static org.slf4j.LoggerFactory.getLogger;
28 import javax.ws.rs.core.MediaType;
29 import org.apache.commons.lang3.tuple.ImmutablePair;
30 import org.onap.so.etsi.nfvo.ns.lcm.lifecycle.NsLifeCycleManager;
31 import org.onap.so.etsi.nfvo.ns.lcm.model.Body;
32 import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest;
33 import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest;
34 import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance;
35 import org.onap.so.etsi.nfvo.ns.lcm.model.TerminateNsRequest;
36 import org.slf4j.Logger;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.stereotype.Controller;
41 import org.springframework.web.bind.annotation.DeleteMapping;
42 import org.springframework.web.bind.annotation.PathVariable;
43 import org.springframework.web.bind.annotation.PostMapping;
44 import org.springframework.web.bind.annotation.RequestBody;
45 import org.springframework.web.bind.annotation.RequestHeader;
46 import org.springframework.web.bind.annotation.RequestMapping;
49 * Controller for handling the NS Lifecycle Management. For further information please read:
50 * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/005/02.07.01_60/gs_NFV-SOL005v020701p.pdf Use the section number
51 * above each endpoint to find the corresponding section in the above document.
53 * @author Waqas Ikram (waqas.ikram@est.tech)
57 @RequestMapping(value = NS_LIFE_CYCLE_MANAGEMENT_BASE_URL)
58 public class NsLifecycleManagementController {
59 private static final Logger logger = getLogger(NsLifecycleManagementController.class);
61 private final NsLifeCycleManager nsLifeCycleManager;
64 public NsLifecycleManagementController(final NsLifeCycleManager nsLifeCycleManager) {
65 this.nsLifeCycleManager = nsLifeCycleManager;
69 * The POST method creates new {@link Body new NS instance resource} request. See Section Number: 6.3.1 for more
72 * @param globalCustomerId The global customer ID
73 * @param serviceType The service type
74 * @param createNsRequest create network service request (see clause 6.5.2.9)
75 * @return "201 Created" response containing a representation of the NS instance resource
76 * {@link NsInstancesNsInstance} just created by the NFVO, and provides the URI of the newly-created
77 * resource in the "Location:" HTTP header
79 @PostMapping(value = "/ns_instances", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
80 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
81 public ResponseEntity<?> createNs(
82 @RequestHeader(value = HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME,
83 required = true) final String globalCustomerId,
84 @RequestHeader(value = HTTP_SERVICETYPE_HEADER_PARM_NAME, required = false,
85 defaultValue = HTTP_SERVICETYPE_HEADER_DEFAULT_VALUE) final String serviceType,
86 @RequestBody final CreateNsRequest createNsRequest) {
87 logger.info("Received Create NS Request: {}\n with globalCustomerId: {}\n serviceType: {}\n", createNsRequest,
88 globalCustomerId, serviceType);
90 final ImmutablePair<URI, NsInstancesNsInstance> nsInstance =
91 nsLifeCycleManager.createNs(createNsRequest, globalCustomerId, serviceType);
93 final URI resourceUri = nsInstance.getLeft();
94 final NsInstancesNsInstance createdNsresponse = nsInstance.getRight();
96 logger.info("NS resource created successfully. Resource location: {}, response: {}", resourceUri,
99 return ResponseEntity.created(resourceUri).body(createdNsresponse);
103 * The DELETE method delete NS instance
105 * @param nsInstanceId Identifier of the NS instance to be deleted.
106 * @return "202 Accepted" response with an empty entity body
108 @DeleteMapping(value = "/ns_instances/{nsInstanceId}",
109 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
110 public ResponseEntity<?> deleteNs(@PathVariable("nsInstanceId") final String nsInstanceId) {
111 logger.debug("Received delete NS request for nsInstanceId: {}", nsInstanceId);
112 return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet");
116 * The POST method instantiate NS instance
118 * @param nsInstanceId Identifier of the NS instance to be instantiated.
119 * @param instantiateNsRequest Instantiate network service request (see clause 6.5.2.11)
120 * @return "202 Accepted" response with an empty entity body and a "Location" HTTP header that points to the new "NS
121 * Lifecycle Operation Occurrence" resource
123 @PostMapping(value = "/ns_instances/{nsInstanceId}/instantiate",
124 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
125 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
126 public ResponseEntity<?> instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId,
127 @RequestBody final InstantiateNsRequest instantiateNsRequest) {
128 logger.debug("Received instantiate NS request: {}\n with nsInstanceId: {}", instantiateNsRequest, nsInstanceId);
129 final URI resourceUri = nsLifeCycleManager.instantiateNs(nsInstanceId, instantiateNsRequest);
130 logger.info("{} Ns Instantiation started successfully. Resource Operation Occurrence uri: {}", nsInstanceId,
132 return ResponseEntity.accepted().location(resourceUri).build();
136 * The POST method terminate NS instance
138 * @param nsInstanceId Identifier of the NS instance to be terminated.
139 * @param terminateNsRequest The terminate NS request parameters (see clause 6.5.2.15)
140 * @return "202 Accepted" response with an empty entity body and a "Location" HTTP header that points to the new "NS
141 * Lifecycle Operation Occurrence" resource
143 @PostMapping(value = "/ns_instances/{nsInstanceId}/terminate",
144 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
145 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
146 public ResponseEntity<?> terminateNs(@PathVariable("nsInstanceId") final String nsInstanceId,
147 @RequestBody final TerminateNsRequest terminateNsRequest) {
148 logger.debug("Received terminate NS request: {}\n with nsInstanceId: {}", terminateNsRequest, nsInstanceId);
149 final URI resourceUri = nsLifeCycleManager.terminateNs(nsInstanceId, terminateNsRequest);
150 logger.info("{} Ns Terminate started successfully. Resource Operation Occurrence uri: {}", nsInstanceId,
152 return ResponseEntity.accepted().location(resourceUri).build();