2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.servlets;
23 import com.jcabi.aspects.Loggable;
24 import io.swagger.v3.oas.annotations.Operation;
25 import io.swagger.v3.oas.annotations.Parameter;
26 import io.swagger.v3.oas.annotations.media.ArraySchema;
27 import io.swagger.v3.oas.annotations.media.Content;
28 import io.swagger.v3.oas.annotations.media.Schema;
29 import io.swagger.v3.oas.annotations.responses.ApiResponse;
30 import io.swagger.v3.oas.annotations.servers.Server;
31 import io.swagger.v3.oas.annotations.servers.Servers;
32 import io.swagger.v3.oas.annotations.tags.Tag;
33 import io.swagger.v3.oas.annotations.tags.Tags;
34 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
35 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
36 import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
37 import org.openecomp.sdc.be.components.upgrade.UpgradeRequest;
38 import org.openecomp.sdc.be.components.upgrade.UpgradeStatus;
39 import org.openecomp.sdc.be.dao.api.ActionStatus;
40 import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
41 import org.openecomp.sdc.be.impl.ComponentsUtils;
42 import org.openecomp.sdc.be.user.UserBusinessLogic;
43 import org.openecomp.sdc.common.api.Constants;
44 import org.openecomp.sdc.common.log.wrappers.Logger;
45 import org.springframework.stereotype.Controller;
47 import javax.inject.Inject;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.ws.rs.Consumes;
50 import javax.ws.rs.GET;
51 import javax.ws.rs.HeaderParam;
52 import javax.ws.rs.POST;
53 import javax.ws.rs.Path;
54 import javax.ws.rs.PathParam;
55 import javax.ws.rs.Produces;
56 import javax.ws.rs.core.Context;
57 import javax.ws.rs.core.MediaType;
58 import javax.ws.rs.core.Response;
59 import java.util.List;
61 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
63 @Tags({@Tag(name = "SDCE-2 APIs")})
64 @Servers({@Server(url = "/sdc2/rest")})
66 @Consumes(MediaType.APPLICATION_JSON)
67 @Produces(MediaType.APPLICATION_JSON)
68 public class AutomatedUpgradeEndpoint extends BeGenericServlet {
69 private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
71 private final UpgradeBusinessLogic businessLogic;
74 public AutomatedUpgradeEndpoint(UserBusinessLogic userBusinessLogic,
75 ComponentsUtils componentsUtils,
76 UpgradeBusinessLogic businessLogic) {
77 super(userBusinessLogic, componentsUtils);
78 this.businessLogic = businessLogic;
82 @Path("/{componentType}/{componentId}/automatedupgrade")
83 @Consumes(MediaType.APPLICATION_JSON)
84 @Produces(MediaType.APPLICATION_JSON)
85 @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = {
86 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
87 @ApiResponse(responseCode = "200", description = "Component found"),
88 @ApiResponse(responseCode = "403", description = "Restricted operation"),
89 @ApiResponse(responseCode = "404", description = "Component not found")})
90 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
91 public Response autometedUpgrade(@PathParam("componentType") final String componentType,
92 @Context final HttpServletRequest request, @PathParam("componentId") final String componentId,
93 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
94 @Parameter(description = "json describes upgrade request", required = true) String data) {
97 String url = request.getMethod() + " " + request.getRequestURI();
98 log.debug("(POST) Start handle request of {}", url);
102 List<UpgradeRequest> inputsToUpdate = JsonParserUtils.toList(data, UpgradeRequest.class);
104 if (log.isDebugEnabled()) {
105 log.debug("Received upgrade requests size is {}", inputsToUpdate == null ? 0 : inputsToUpdate.size());
107 UpgradeStatus actionResponse = businessLogic.automatedUpgrade(componentId, inputsToUpdate, userId);
109 return actionResponse.getStatus() == ActionStatus.OK ? buildOkResponse(actionResponse) : buildErrorResponse(actionResponse.getError());
111 } catch (Exception e) {
112 log.error("#autometedUpgrade - Exception occurred during autometed Upgrade", e);
118 @Path("/{componentType}/{componentId}/dependencies")
119 @Consumes(MediaType.APPLICATION_JSON)
120 @Produces(MediaType.APPLICATION_JSON)
121 @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = {
122 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
123 @ApiResponse(responseCode = "200", description = "Component found"),
124 @ApiResponse(responseCode = "403", description = "Restricted operation"),
125 @ApiResponse(responseCode = "404", description = "Component not found")})
126 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
127 public Response getComponentDependencies(@PathParam("componentType") final String componentType,
128 @Context final HttpServletRequest request, @PathParam("componentId") final String componentId,
129 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
130 @Parameter(description = "Consumer Object to be created", required = true) List<String> data) {
131 String url = request.getMethod() + " " + request.getRequestURI();
132 log.debug("(GET) Start handle request of {}", url);
135 return businessLogic.getComponentDependencies(componentId, userId)
136 .either(this::buildOkResponse, this::buildErrorResponse);
137 } catch (Exception e) {
138 log.error("#getServicesForComponent - Exception occurred during autometed Upgrade", e);