2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 fj.data.Either;
25 import io.swagger.annotations.Api;
26 import io.swagger.annotations.ApiOperation;
27 import io.swagger.annotations.ApiResponse;
28 import io.swagger.annotations.ApiResponses;
29 import javax.inject.Inject;
30 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
31 import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic;
32 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
33 import org.openecomp.sdc.be.config.BeEcompErrorManager;
34 import org.openecomp.sdc.be.dao.api.ActionStatus;
35 import org.openecomp.sdc.be.impl.ComponentsUtils;
36 import org.openecomp.sdc.be.info.DistributionStatusListResponse;
37 import org.openecomp.sdc.be.info.DistributionStatusOfServiceListResponce;
38 import org.openecomp.sdc.be.user.UserBusinessLogic;
39 import org.openecomp.sdc.common.api.Constants;
40 import org.openecomp.sdc.common.log.wrappers.Logger;
41 import org.openecomp.sdc.exception.ResponseFormat;
43 import javax.inject.Singleton;
44 import javax.servlet.http.HttpServletRequest;
46 import javax.ws.rs.core.Context;
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
51 * Root resource (exposed at "/" path)
53 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
55 @Api(value = "Distribution Service Servlet", description = "Distribution Service Servlet")
57 public class DistributionServiceServlet extends BeGenericServlet {
58 private static final Logger log = Logger.getLogger(DistributionServiceServlet.class);
61 public DistributionServiceServlet(UserBusinessLogic userBusinessLogic,
62 ComponentsUtils componentsUtils,
63 DistributionMonitoringBusinessLogic distributionMonitoringLogic) {
64 super(userBusinessLogic, componentsUtils);
65 this.distributionMonitoringLogic = distributionMonitoringLogic;
68 private DistributionMonitoringBusinessLogic distributionMonitoringLogic;
71 @Path("/services/{serviceUUID}/distribution")
72 @Consumes(MediaType.APPLICATION_JSON)
73 @Produces(MediaType.APPLICATION_JSON)
74 @ApiOperation(value = "Retrieve Distributions", httpMethod = "GET", notes = "Returns list bases on the information extracted from Auditing Records according to service uuid", response = DistributionStatusListResponse.class)
75 @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Service not found") })
76 public Response getServiceById(@PathParam("serviceUUID") final String serviceUUID, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
78 String url = request.getMethod() + " " + request.getRequestURI();
79 log.debug("Start handle request of {}", url);
80 Response response = null;
81 ResponseFormat responseFormat = null;
84 Either<DistributionStatusOfServiceListResponce, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionServiceStatus(serviceUUID, userId);
86 if (actionResponse.isRight()) {
88 responseFormat = actionResponse.right().value();
89 response = buildErrorResponse(responseFormat);
91 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
92 response = buildOkResponse(responseFormat, actionResponse.left().value());
98 } catch (Exception e) {
99 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution list for Service");
100 log.debug("failed to get service distribution statuses", e);
101 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
103 response = buildErrorResponse(responseFormat);
110 @Path("/services/distribution/{did}")
111 @Consumes(MediaType.APPLICATION_JSON)
112 @Produces(MediaType.APPLICATION_JSON)
113 @ApiOperation(value = "Retrieve Distributions", httpMethod = "GET", notes = "Return the list of distribution status objects", response = DistributionStatusListResponse.class)
114 @ApiResponses(value = { @ApiResponse(code = 200, message = "Service found"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 404, message = "Status not found") })
115 public Response getListOfDistributionStatuses(@PathParam("did") final String did, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
117 String url = request.getMethod() + " " + request.getRequestURI();
118 log.debug("Start handle request of {}", url);
119 Response response = null;
120 ResponseFormat responseFormat = null;
123 Either<DistributionStatusListResponse, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionStatus(did, userId);
125 if (actionResponse.isRight()) {
127 responseFormat = actionResponse.right().value();
128 log.debug("failed to fount statuses for did {} {}", did, responseFormat);
129 response = buildErrorResponse(responseFormat);
132 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
133 log.debug("success to fount statuses for did {} {}", did, actionResponse.left().value());
134 response = buildOkResponse(responseFormat, actionResponse.left().value());
140 } catch (Exception e) {
141 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution Status");
142 log.debug("failed to get distribution status ", e);
143 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
145 response = buildErrorResponse(responseFormat);