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.annotations.*;
25 import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
26 import org.openecomp.sdc.be.components.upgrade.UpgradeRequest;
27 import org.openecomp.sdc.be.components.upgrade.UpgradeStatus;
28 import org.openecomp.sdc.be.dao.api.ActionStatus;
29 import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
30 import org.openecomp.sdc.be.model.Resource;
31 import org.openecomp.sdc.common.api.Constants;
32 import org.openecomp.sdc.common.log.wrappers.Logger;
33 import org.springframework.stereotype.Controller;
35 import javax.servlet.http.HttpServletRequest;
37 import javax.ws.rs.core.Context;
38 import javax.ws.rs.core.MediaType;
39 import javax.ws.rs.core.Response;
40 import java.util.List;
42 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
44 @Api(value = "policy types resource")
46 @Consumes(MediaType.APPLICATION_JSON)
47 @Produces(MediaType.APPLICATION_JSON)
48 public class AutomatedUpgradeEndpoint extends BeGenericServlet {
49 private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
51 private final UpgradeBusinessLogic businessLogic;
53 public AutomatedUpgradeEndpoint(UpgradeBusinessLogic businessLogic) {
54 this.businessLogic = businessLogic;
59 @Path("/{componentType}/{componentId}/automatedupgrade")
60 @Consumes(MediaType.APPLICATION_JSON)
61 @Produces(MediaType.APPLICATION_JSON)
62 @ApiOperation(value = "Autometed upgrade", httpMethod = "POST", notes = "....", response = Resource.class)
63 @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
64 public Response autometedUpgrade(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
65 @ApiParam(value = "json describes upgrade request", required = true) String data) {
68 String url = request.getMethod() + " " + request.getRequestURI();
69 log.debug("(POST) Start handle request of {}", url);
73 List<UpgradeRequest> inputsToUpdate = JsonParserUtils.toList(data, UpgradeRequest.class);
75 if (log.isDebugEnabled()) {
76 log.debug("Received upgrade requests size is {}", inputsToUpdate == null ? 0 : inputsToUpdate.size());
78 UpgradeStatus actionResponse = businessLogic.automatedUpgrade(componentId, inputsToUpdate, userId);
80 return actionResponse.getStatus() == ActionStatus.OK ? buildOkResponse(actionResponse) : buildErrorResponse(actionResponse.getError());
82 } catch (Exception e) {
83 log.error("#autometedUpgrade - Exception occurred during autometed Upgrade", e);
84 return buildGeneralErrorResponse();
89 @Path("/{componentType}/{componentId}/dependencies")
90 @Consumes(MediaType.APPLICATION_JSON)
91 @Produces(MediaType.APPLICATION_JSON)
92 @ApiOperation(value = "Autometed upgrade", httpMethod = "POST", notes = "....", response = Resource.class)
93 @ApiResponses(value = { @ApiResponse(code = 200, message = "Component found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Component not found") })
94 public Response getComponentDependencies(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request, @PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
95 @ApiParam(value = "Consumer Object to be created", required = true) List<String> data) {
96 String url = request.getMethod() + " " + request.getRequestURI();
97 log.debug("(GET) Start handle request of {}", url);
100 return businessLogic.getComponentDependencies(componentId, userId)
101 .either(this::buildOkResponse, this::buildErrorResponse);
102 } catch (Exception e) {
103 log.error("#getServicesForComponent - Exception occurred during autometed Upgrade", e);
104 return buildGeneralErrorResponse();