f1331a31855f4c6e2ea6218b8be33e715ce52ef3
[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.exceptions.ValidateException;
38 import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound;
39 import org.onap.so.apihandlerinfra.infra.rest.exception.WorkflowEngineConnectionException;
40 import org.onap.so.apihandlerinfra.infra.rest.handler.VnfRestHandler;
41 import org.onap.so.db.catalog.beans.Recipe;
42 import org.onap.so.db.request.beans.InfraActiveRequests;
43 import org.onap.so.logger.HttpHeadersConstants;
44 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
45 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
46 import org.slf4j.MDC;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.http.HttpStatus;
49 import org.springframework.stereotype.Component;
50 import com.fasterxml.jackson.core.JsonProcessingException;
51 import io.swagger.v3.oas.annotations.Operation;
52 import io.swagger.v3.oas.annotations.media.ArraySchema;
53 import io.swagger.v3.oas.annotations.media.Content;
54 import io.swagger.v3.oas.annotations.media.Schema;
55 import io.swagger.v3.oas.annotations.responses.ApiResponse;
56
57 @Component
58 @Path("/onap/so/infra/serviceInstantiation")
59 public class Vnf {
60
61     @Autowired
62     private BpmnRequestBuilder requestBuilder;
63
64     @Autowired
65     private VnfRestHandler vnfRestHandler;
66
67     @DELETE
68     @ResponseUpdater
69     @Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}")
70     @Consumes(MediaType.APPLICATION_JSON)
71     @Produces(MediaType.APPLICATION_JSON)
72     @Operation(description = "Delete a Vnf instance", responses = @ApiResponse(content = @Content(
73             array = @ArraySchema(schema = @Schema(implementation = ServiceInstancesResponse.class)))))
74     @Transactional
75     public Response deleteVnfInstance(@PathParam("version") String version,
76             @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId,
77             @Context ContainerRequestContext requestContext)
78             throws AAIEntityNotFound, JsonProcessingException, WorkflowEngineConnectionException, ValidateException {
79
80         String requestId = vnfRestHandler.getRequestId(requestContext);
81         String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID);
82         String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
83         String requestURL = requestContext.getUriInfo().getAbsolutePath().toString();
84         InfraActiveRequests currentRequest = vnfRestHandler.createInfraActiveRequestForDelete(requestId,
85                 serviceInstanceId, vnfInstanceId, requestorId, source, requestURL);
86         ServiceInstancesRequest request = requestBuilder.buildVnfDeleteRequest(vnfInstanceId);
87         vnfRestHandler.saveInstanceName(request, currentRequest);
88         vnfRestHandler.checkDuplicateRequest(serviceInstanceId, vnfInstanceId,
89                 request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
90         Recipe recipe = vnfRestHandler.findVnfModuleRecipe(
91                 request.getRequestDetails().getModelInfo().getModelCustomizationId(), "vnf", "deleteInstance");
92         vnfRestHandler.callWorkflowEngine(vnfRestHandler.buildRequestParams(request,
93                 vnfRestHandler.getRequestUri(requestContext), requestId, serviceInstanceId, vnfInstanceId),
94                 recipe.getOrchestrationUri());
95         ServiceInstancesResponse response = vnfRestHandler.createResponse(vnfInstanceId, requestId, requestContext);
96         return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();
97     }
98 }