Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / AutomatedUpgradeEndpoint.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 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 package org.openecomp.sdc.be.servlets;
21
22 import com.jcabi.aspects.Loggable;
23 import io.swagger.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.Parameter;
25 import io.swagger.v3.oas.annotations.media.ArraySchema;
26 import io.swagger.v3.oas.annotations.media.Content;
27 import io.swagger.v3.oas.annotations.media.Schema;
28 import io.swagger.v3.oas.annotations.responses.ApiResponse;
29 import io.swagger.v3.oas.annotations.servers.Server;
30 import io.swagger.v3.oas.annotations.servers.Servers;
31 import io.swagger.v3.oas.annotations.tags.Tag;
32 import io.swagger.v3.oas.annotations.tags.Tags;
33 import java.util.List;
34 import javax.inject.Inject;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.ws.rs.Consumes;
37 import javax.ws.rs.GET;
38 import javax.ws.rs.HeaderParam;
39 import javax.ws.rs.POST;
40 import javax.ws.rs.Path;
41 import javax.ws.rs.PathParam;
42 import javax.ws.rs.Produces;
43 import javax.ws.rs.core.Context;
44 import javax.ws.rs.core.MediaType;
45 import javax.ws.rs.core.Response;
46 import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
47 import org.openecomp.sdc.be.components.upgrade.UpgradeRequest;
48 import org.openecomp.sdc.be.components.upgrade.UpgradeStatus;
49 import org.openecomp.sdc.be.dao.api.ActionStatus;
50 import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
51 import org.openecomp.sdc.be.impl.ComponentsUtils;
52 import org.openecomp.sdc.common.api.Constants;
53 import org.openecomp.sdc.common.log.wrappers.Logger;
54 import org.springframework.stereotype.Controller;
55
56 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
57 @Path("/v1/catalog")
58 @Tags({@Tag(name = "SDCE-2 APIs")})
59 @Servers({@Server(url = "/sdc2/rest")})
60 @Controller
61 @Consumes(MediaType.APPLICATION_JSON)
62 @Produces(MediaType.APPLICATION_JSON)
63 public class AutomatedUpgradeEndpoint extends BeGenericServlet {
64
65     private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
66     private final UpgradeBusinessLogic businessLogic;
67
68     @Inject
69     public AutomatedUpgradeEndpoint(ComponentsUtils componentsUtils, UpgradeBusinessLogic businessLogic) {
70         super(componentsUtils);
71         this.businessLogic = businessLogic;
72     }
73
74     @POST
75     @Path("/{componentType}/{componentId}/automatedupgrade")
76     @Consumes(MediaType.APPLICATION_JSON)
77     @Produces(MediaType.APPLICATION_JSON)
78     @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = {
79         @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
80         @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
81         @ApiResponse(responseCode = "404", description = "Component not found")})
82     public Response autometedUpgrade(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
83                                      @PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
84                                      @Parameter(description = "json describes upgrade request", required = true) String data) {
85         String url = request.getMethod() + " " + request.getRequestURI();
86         log.debug("(POST) Start handle request of {}", url);
87         try {
88             List<UpgradeRequest> inputsToUpdate = JsonParserUtils.toList(data, UpgradeRequest.class);
89             if (log.isDebugEnabled()) {
90                 log.debug("Received upgrade requests size is {}", inputsToUpdate == null ? 0 : inputsToUpdate.size());
91             }
92             UpgradeStatus actionResponse = businessLogic.automatedUpgrade(componentId, inputsToUpdate, userId);
93             return actionResponse.getStatus() == ActionStatus.OK ? buildOkResponse(actionResponse) : buildErrorResponse(actionResponse.getError());
94         } catch (Exception e) {
95             log.error("#autometedUpgrade - Exception occurred during autometed Upgrade", e);
96             throw e;
97         }
98     }
99
100     @GET
101     @Path("/{componentType}/{componentId}/dependencies")
102     @Consumes(MediaType.APPLICATION_JSON)
103     @Produces(MediaType.APPLICATION_JSON)
104     @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = {
105         @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
106         @ApiResponse(responseCode = "200", description = "Component found"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
107         @ApiResponse(responseCode = "404", description = "Component not found")})
108     public Response getComponentDependencies(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
109                                              @PathParam("componentId") final String componentId,
110                                              @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
111                                              @Parameter(description = "Consumer Object to be created", required = true) List<String> data) {
112         String url = request.getMethod() + " " + request.getRequestURI();
113         log.debug("(GET) Start handle request of {}", url);
114         try {
115             return businessLogic.getComponentDependencies(componentId, userId).either(this::buildOkResponse, this::buildErrorResponse);
116         } catch (Exception e) {
117             log.error("#getServicesForComponent - Exception occurred during autometed Upgrade", e);
118             throw e;
119         }
120     }
121 }