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.exceptions.ValidateException;
39 import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound;
40 import org.onap.so.apihandlerinfra.infra.rest.exception.NoRecipeException;
41 import org.onap.so.apihandlerinfra.infra.rest.exception.WorkflowEngineConnectionException;
42 import org.onap.so.apihandlerinfra.infra.rest.handler.VFModuleRestHandler;
43 import org.onap.so.apihandlerinfra.infra.rest.handler.VolumeRestHandler;
44 import org.onap.so.db.catalog.beans.Recipe;
45 import org.onap.so.db.request.beans.InfraActiveRequests;
46 import org.onap.so.logger.HttpHeadersConstants;
47 import org.onap.so.serviceinstancebeans.ModelType;
48 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
49 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
51 import org.springframework.beans.factory.annotation.Autowired;
52 import org.springframework.http.HttpStatus;
53 import org.springframework.stereotype.Component;
54 import com.fasterxml.jackson.core.JsonProcessingException;
55 import io.swagger.v3.oas.annotations.Operation;
56 import io.swagger.v3.oas.annotations.media.ArraySchema;
57 import io.swagger.v3.oas.annotations.media.Content;
58 import io.swagger.v3.oas.annotations.media.Schema;
59 import io.swagger.v3.oas.annotations.responses.ApiResponse;
61 @Component("VolumesV8")
62 @Path("/onap/so/infra/serviceInstantiation")
63 public class Volumes {
66 private BpmnRequestBuilder requestBuilder;
69 private VFModuleRestHandler vfModuleRestHandler;
72 private VolumeRestHandler volumeRestHandler;
76 @Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupInstanceId}")
77 @Consumes(MediaType.APPLICATION_JSON)
78 @Produces(MediaType.APPLICATION_JSON)
79 @Operation(description = "Delete a VfModule instance", responses = @ApiResponse(content = @Content(
80 array = @ArraySchema(schema = @Schema(implementation = ServiceInstancesResponse.class)))))
82 public Response deleteVfModuleInstance(@PathParam("version") String version,
83 @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId,
84 @PathParam("volumeGroupInstanceId") String volumeGroupId, @Context ContainerRequestContext requestContext)
85 throws AAIEntityNotFound, NoRecipeException, JsonProcessingException, WorkflowEngineConnectionException,
88 String requestId = volumeRestHandler.getRequestId(requestContext);
89 String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID);
90 String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
91 String requestURL = requestContext.getUriInfo().getAbsolutePath().toString();
92 InfraActiveRequests currentRequest = volumeRestHandler.createInfraActiveRequestForDelete(requestId,
93 volumeGroupId, serviceInstanceId, vnfInstanceId, requestorId, source, requestURL);
94 ServiceInstancesRequest request = requestBuilder.buildVolumeGroupDeleteRequest(vnfInstanceId, volumeGroupId);
95 volumeRestHandler.saveInstanceName(request, currentRequest);
96 volumeRestHandler.checkDuplicateRequest(serviceInstanceId, vnfInstanceId, volumeGroupId,
97 request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
98 Recipe recipe = vfModuleRestHandler.findVfModuleRecipe(
99 request.getRequestDetails().getModelInfo().getModelCustomizationId(), ModelType.volumeGroup.toString(),
100 Action.deleteInstance.toString());
103 volumeRestHandler.buildRequestParams(request, volumeRestHandler.getRequestUri(requestContext),
104 requestId, serviceInstanceId, vnfInstanceId, volumeGroupId),
105 recipe.getOrchestrationUri());
106 ServiceInstancesResponse response = volumeRestHandler.createResponse(volumeGroupId, requestId, requestContext);
107 return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();