1a2688f0b3961903c7fa0d0d01f289d9bb983719
[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.VFModuleRestHandler;
37 import org.onap.so.db.catalog.beans.Recipe;
38 import org.onap.so.db.request.beans.InfraActiveRequests;
39 import org.onap.so.serviceinstancebeans.ModelType;
40 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
41 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import org.slf4j.MDC;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.http.HttpStatus;
47 import org.springframework.stereotype.Component;
48 import io.swagger.annotations.ApiOperation;
49
50 @Component
51 @Path("/onap/so/infra/serviceInstantiation")
52 public class VfModules {
53
54     private static Logger logger = LoggerFactory.getLogger(VfModules.class);
55
56     @Autowired
57     private VFModuleRestHandler restHandler;
58
59     @Autowired
60     private BpmnRequestBuilder requestBuilder;
61
62     @DELETE
63     @ResponseUpdater
64     @Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfmoduleInstanceId}")
65     @Consumes(MediaType.APPLICATION_JSON)
66     @Produces(MediaType.APPLICATION_JSON)
67     @ApiOperation(value = "Delete a VfModule instance", response = ServiceInstancesResponse.class)
68     @Transactional
69     public Response deleteVfModuleInstance(@PathParam("version") String version,
70             @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId,
71             @PathParam("vfmoduleInstanceId") String vfmoduleInstanceId, @Context ContainerRequestContext requestContext)
72             throws Exception {
73         InfraActiveRequests currentRequest = null;
74
75         String requestId = restHandler.getRequestId(requestContext);
76         String requestorId = "Unknown";
77         String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
78         String requestURL = requestContext.getUriInfo().getAbsolutePath().toString();
79         currentRequest = restHandler.createInfraActiveRequestForDelete(requestId, vfmoduleInstanceId, serviceInstanceId,
80                 vnfInstanceId, requestorId, source, requestURL);
81         ServiceInstancesRequest request =
82                 requestBuilder.buildVFModuleDeleteRequest(vnfInstanceId, vfmoduleInstanceId, ModelType.vfModule);
83         restHandler.saveInstanceName(request, currentRequest);
84         restHandler.checkDuplicateRequest(serviceInstanceId, vnfInstanceId, vfmoduleInstanceId,
85                 request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
86         Recipe recipe =
87                 restHandler.findVfModuleRecipe(request.getRequestDetails().getModelInfo().getModelCustomizationId(),
88                         ModelType.vfModule.toString(), Action.deleteInstance.toString());
89         restHandler
90                 .callWorkflowEngine(restHandler.buildRequestParams(request, restHandler.getRequestUri(requestContext),
91                         requestId, serviceInstanceId, vnfInstanceId, vfmoduleInstanceId), recipe.getOrchestrationUri());
92         ServiceInstancesResponse response = restHandler.createResponse(vfmoduleInstanceId, requestId, requestContext);
93         return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();
94
95     }
96 }