bf10fcc183cd71bed75c6500af205b866159d581
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra.infra.rest;
22
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.Action;
36 import org.onap.so.apihandlerinfra.infra.rest.handler.ServiceInstanceRestHandler;
37 import org.onap.so.db.catalog.beans.Recipe;
38 import org.onap.so.db.request.beans.InfraActiveRequests;
39 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
40 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.slf4j.MDC;
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;
48
49 @Component
50 @Path("/onap/so/infra/serviceInstantiation")
51 public class ServiceInstance {
52
53     private static Logger logger = LoggerFactory.getLogger(ServiceInstance.class);
54
55     @Autowired
56     private ServiceInstanceRestHandler requestHandler;
57
58     @Autowired
59     private BpmnRequestBuilder requestBuilder;
60
61     @DELETE
62     @ResponseUpdater
63     @Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}")
64     @Consumes(MediaType.APPLICATION_JSON)
65     @Produces(MediaType.APPLICATION_JSON)
66     @ApiOperation(value = "Delete a Service instance", response = ServiceInstancesResponse.class)
67     @Transactional
68     public Response deleteServiceInstance(@PathParam("version") String version,
69             @PathParam("serviceInstanceId") String serviceInstanceId, @Context ContainerRequestContext requestContext)
70             throws Exception {
71         InfraActiveRequests currentRequest = null;
72         String requestId = requestHandler.getRequestId(requestContext);
73         String requestorId = "Unknown";
74         String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
75         String requestURI = requestContext.getUriInfo().getAbsolutePath().toString();
76         currentRequest = requestHandler.createInfraActiveRequestForDelete(requestId, serviceInstanceId, requestorId,
77                 source, requestURI);
78         ServiceInstancesRequest request = requestBuilder.buildServiceDeleteRequest(serviceInstanceId);
79         requestHandler.saveInstanceName(request, currentRequest);
80         requestHandler.checkDuplicateRequest(serviceInstanceId,
81                 request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
82         Recipe recipe = requestHandler.findServiceRecipe(request.getRequestDetails().getModelInfo().getModelUuid(),
83                 Action.deleteInstance.toString());
84         requestHandler.callWorkflowEngine(requestHandler.buildRequestParams(request,
85                 requestHandler.getRequestUri(requestContext), requestId, serviceInstanceId),
86                 recipe.getOrchestrationUri());
87         ServiceInstancesResponse response = requestHandler.createResponse(serviceInstanceId, requestId, requestContext);
88         return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();
89
90     }
91 }