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 org.onap.logging.ref.slf4j.ONAPLogConstants;
36 import org.onap.so.apihandler.filters.ResponseUpdater;
37 import org.onap.so.apihandlerinfra.Action;
38 import org.onap.so.apihandlerinfra.infra.rest.handler.ServiceInstanceRestHandler;
39 import org.onap.so.db.catalog.beans.Recipe;
40 import org.onap.so.db.request.beans.InfraActiveRequests;
41 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
42 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.http.HttpStatus;
46 import org.springframework.stereotype.Component;
47 import io.swagger.annotations.ApiOperation;
50 @Path("/onap/so/infra/serviceInstantiation")
51 public class ServiceInstance {
54 private ServiceInstanceRestHandler requestHandler;
57 private BpmnRequestBuilder requestBuilder;
61 @Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}")
62 @Consumes(MediaType.APPLICATION_JSON)
63 @Produces(MediaType.APPLICATION_JSON)
64 @ApiOperation(value = "Delete a Service instance", response = ServiceInstancesResponse.class)
66 public Response deleteServiceInstance(@PathParam("version") String version,
67 @PathParam("serviceInstanceId") String serviceInstanceId, @Context ContainerRequestContext requestContext)
69 InfraActiveRequests currentRequest = null;
70 String requestId = requestHandler.getRequestId(requestContext);
71 String requestorId = "Unknown";
72 String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
73 String requestURI = requestContext.getUriInfo().getAbsolutePath().toString();
74 currentRequest = requestHandler.createInfraActiveRequestForDelete(requestId, serviceInstanceId, requestorId,
76 ServiceInstancesRequest request = requestBuilder.buildServiceDeleteRequest(serviceInstanceId);
77 requestHandler.saveInstanceName(request, currentRequest);
78 requestHandler.checkDuplicateRequest(serviceInstanceId,
79 request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
80 Recipe recipe = requestHandler.findServiceRecipe(request.getRequestDetails().getModelInfo().getModelUuid(),
81 Action.deleteInstance.toString());
82 requestHandler.callWorkflowEngine(requestHandler.buildRequestParams(request,
83 requestHandler.getRequestUri(requestContext), requestId, serviceInstanceId),
84 recipe.getOrchestrationUri());
85 ServiceInstancesResponse response = requestHandler.createResponse(serviceInstanceId, requestId, requestContext);
86 return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();