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