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