a8ccdeecaca8b1dc3a788adeb860686a3fb64f53
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.apihandlerinfra.infra.rest;
24
25 import javax.transaction.Transactional;
26 import javax.ws.rs.Consumes;
27 import javax.ws.rs.DELETE;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.PathParam;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.container.ContainerRequestContext;
32 import javax.ws.rs.core.Context;
33 import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.Response;
35 import org.onap.logging.ref.slf4j.ONAPLogConstants;
36 import org.onap.so.apihandler.filters.ResponseUpdater;
37 import org.onap.so.apihandlerinfra.infra.rest.handler.VnfRestHandler;
38 import org.onap.so.db.catalog.beans.Recipe;
39 import org.onap.so.db.request.beans.InfraActiveRequests;
40 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
41 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
42 import org.slf4j.MDC;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.http.HttpStatus;
45 import org.springframework.stereotype.Component;
46 import io.swagger.annotations.ApiOperation;
47
48 @Component
49 @Path("/onap/so/infra/serviceInstantiation")
50 public class Vnf {
51
52     @Autowired
53     private BpmnRequestBuilder requestBuilder;
54
55     @Autowired
56     private VnfRestHandler vnfRestHandler;
57
58     @DELETE
59     @ResponseUpdater
60     @Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}")
61     @Consumes(MediaType.APPLICATION_JSON)
62     @Produces(MediaType.APPLICATION_JSON)
63     @ApiOperation(value = "Delete a Vnf instance", response = ServiceInstancesResponse.class)
64     @Transactional
65     public Response deleteVnfInstance(@PathParam("version") String version,
66             @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId,
67             @Context ContainerRequestContext requestContext) throws Exception {
68         InfraActiveRequests currentRequest = null;
69         String requestId = vnfRestHandler.getRequestId(requestContext);
70         String requestorId = "Unknown";
71         String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
72         String requestURL = requestContext.getUriInfo().getAbsolutePath().toString();
73         currentRequest = vnfRestHandler.createInfraActiveRequestForDelete(requestId, serviceInstanceId, vnfInstanceId,
74                 requestorId, source, requestURL);
75         ServiceInstancesRequest request = requestBuilder.buildVnfDeleteRequest(vnfInstanceId);
76         vnfRestHandler.saveInstanceName(request, currentRequest);
77         vnfRestHandler.checkDuplicateRequest(serviceInstanceId, vnfInstanceId,
78                 request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
79         Recipe recipe = vnfRestHandler.findVnfModuleRecipe(
80                 request.getRequestDetails().getModelInfo().getModelCustomizationId(), "vnf", "deleteInstance");
81         vnfRestHandler.callWorkflowEngine(vnfRestHandler.buildRequestParams(request,
82                 vnfRestHandler.getRequestUri(requestContext), requestId, serviceInstanceId, vnfInstanceId),
83                 recipe.getOrchestrationUri());
84         ServiceInstancesResponse response = vnfRestHandler.createResponse(vnfInstanceId, requestId, requestContext);
85         return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();
86     }
87 }