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 {@link NsInstance} just
 
  76      *         created by the NFVO, and provides the URI of the newly-created resource in the "Location:" HTTP header
 
  78     @PostMapping(value = "/ns_instances", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
 
  79             consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
 
  80     public ResponseEntity<?> createNs(
 
  81             @RequestHeader(value = HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME,
 
  82                     required = true) final String globalCustomerId,
 
  83             @RequestHeader(value = HTTP_SERVICETYPE_HEADER_PARM_NAME, required = false,
 
  84                     defaultValue = HTTP_SERVICETYPE_HEADER_DEFAULT_VALUE) final String serviceType,
 
  85             @RequestBody final CreateNsRequest createNsRequest) {
 
  86         logger.info("Received Create NS Request: {}\n with globalCustomerId: {}\n serviceType: {}\n", createNsRequest,
 
  87                 globalCustomerId, serviceType);
 
  89         final ImmutablePair<URI, NsInstancesNsInstance> nsInstance =
 
  90                 nsLifeCycleManager.createNs(createNsRequest, globalCustomerId, serviceType);
 
  92         final URI resourceUri = nsInstance.getLeft();
 
  93         final NsInstancesNsInstance createdNsresponse = nsInstance.getRight();
 
  95         logger.info("NS resource created successfully. Resource location: {}, response: {}", resourceUri,
 
  98         return ResponseEntity.created(resourceUri).body(createdNsresponse);
 
 102      * The DELETE method delete NS instance
 
 104      * @param nsInstanceId Identifier of the NS instance to be deleted.
 
 105      * @return "202 Accepted" response with an empty entity body
 
 107     @DeleteMapping(value = "/ns_instances/{nsInstanceId}",
 
 108             produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
 
 109     public ResponseEntity<?> deleteNs(@PathVariable("nsInstanceId") final String nsInstanceId) {
 
 110         logger.debug("Received delete NS request for nsInstanceId: {}", nsInstanceId);
 
 111         return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet");
 
 115      * The POST method instantiate NS instance
 
 117      * @param nsInstanceId Identifier of the NS instance to be instantiated.
 
 118      * @param instantiateNsRequest Instantiate network service request (see clause 6.5.2.11)
 
 119      * @return "202 Accepted" response with an empty entity body and a "Location" HTTP header that points to the new "NS
 
 120      *         Lifecycle Operation Occurrence" resource
 
 122     @PostMapping(value = "/ns_instances/{nsInstanceId}/instantiate",
 
 123             produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
 
 124             consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
 
 125     public ResponseEntity<?> instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId,
 
 126             @RequestBody final InstantiateNsRequest instantiateNsRequest) {
 
 127         logger.debug("Received instantiate NS request: {}\n with nsInstanceId: {}", instantiateNsRequest, nsInstanceId);
 
 128         return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet");
 
 132      * The POST method terminate NS instance
 
 134      * @param nsInstanceId Identifier of the NS instance to be terminated.
 
 135      * @param terminateNsRequest The terminate NS request parameters (see clause 6.5.2.15)
 
 136      * @return "202 Accepted" response with an empty entity body and a "Location" HTTP header that points to the new "NS
 
 137      *         Lifecycle Operation Occurrence" resource
 
 139     @PostMapping(value = "/ns_instances/{nsInstanceId}/terminate",
 
 140             produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
 
 141             consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
 
 142     public ResponseEntity<?> terminateNs(@PathVariable("nsInstanceId") final String nsInstanceId,
 
 143             @RequestBody final TerminateNsRequest terminateNsRequest) {
 
 144         logger.debug("Received terminate NS request: {}\n with nsInstanceId: {}", terminateNsRequest, nsInstanceId);
 
 145         return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet");