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.NetworkRestHandler;
43 import org.onap.so.db.catalog.beans.Recipe;
44 import org.onap.so.db.request.beans.InfraActiveRequests;
45 import org.onap.so.logger.HttpHeadersConstants;
46 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
47 import org.onap.so.serviceinstancebeans.ServiceInstancesResponse;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.http.HttpStatus;
51 import org.springframework.stereotype.Component;
52 import com.fasterxml.jackson.core.JsonProcessingException;
53 import io.swagger.v3.oas.annotations.Operation;
54 import io.swagger.v3.oas.annotations.media.ArraySchema;
55 import io.swagger.v3.oas.annotations.media.Content;
56 import io.swagger.v3.oas.annotations.media.Schema;
57 import io.swagger.v3.oas.annotations.responses.ApiResponse;
60 @Path("/onap/so/infra/serviceInstantiation")
61 public class Network {
64 private NetworkRestHandler networkRestHandler;
67 private BpmnRequestBuilder requestBuilder;
71 @Path("/{version:[vV][8]}/serviceInstances/{serviceInstanceId}/networks/{networkInstanceId}")
72 @Consumes(MediaType.APPLICATION_JSON)
73 @Produces(MediaType.APPLICATION_JSON)
74 @Operation(description = "Delete provided Network instance", responses = @ApiResponse(
75 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
77 public Response deleteNetworkInstance(@PathParam("version") String version,
78 @PathParam("serviceInstanceId") String serviceInstanceId,
79 @PathParam("networkInstanceId") String networkInstanceId, @Context ContainerRequestContext requestContext)
80 throws AAIEntityNotFound, NoRecipeException, JsonProcessingException, WorkflowEngineConnectionException,
83 String requestId = networkRestHandler.getRequestId(requestContext);
84 String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID);
85 String source = MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME);
86 String requestURI = requestContext.getUriInfo().getAbsolutePath().toString();
87 InfraActiveRequests currentRequest = networkRestHandler.createInfraActiveRequestForDelete(requestId,
88 serviceInstanceId, networkInstanceId, requestorId, source, requestURI);
89 ServiceInstancesRequest request = requestBuilder.buildNetworkDeleteRequest(networkInstanceId);
90 networkRestHandler.saveInstanceName(request, currentRequest);
91 networkRestHandler.checkDuplicateRequest(serviceInstanceId, networkInstanceId,
92 request.getRequestDetails().getRequestInfo().getInstanceName(), currentRequest.getRequestId());
93 Recipe recipe = networkRestHandler.findNetworkRecipe(Action.deleteInstance.toString());
94 networkRestHandler.callWorkflowEngine(networkRestHandler.buildRequestParams(request,
95 networkRestHandler.getRequestUri(requestContext), requestId, serviceInstanceId, networkInstanceId),
96 recipe.getOrchestrationUri());
97 ServiceInstancesResponse response =
98 networkRestHandler.createResponse(networkInstanceId, requestId, requestContext);
99 return Response.status(HttpStatus.ACCEPTED.value()).entity(response).build();