1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.service;
24 import java.io.IOException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.core.Context;
34 import org.apache.http.HttpStatus;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.beans.factory.annotation.Qualifier;
39 import org.springframework.stereotype.Component;
41 import org.onap.dmaap.dmf.mr.CambriaApiException;
42 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
43 import org.onap.dmaap.dmf.mr.exception.DMaaPResponseCode;
44 import org.onap.dmaap.dmf.mr.exception.ErrorResponse;
45 import org.onap.dmaap.dmf.mr.service.MetricsService;
46 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
49 * This class is a CXF REST service which acts
50 * as gateway for MR Metrics Service.
51 * @author rajashree.khare
56 public class MetricsRestService {
62 private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigurationReader.class);
64 * HttpServletRequest obj
67 private HttpServletRequest request;
70 * HttpServletResponse obj
73 private HttpServletResponse response;
79 @Qualifier("configurationReader")
80 private ConfigurationReader configReader;
86 private MetricsService metricsService;
90 * @throws CambriaApiException ex
93 @Produces("text/plain")
94 public void getMetrics() throws CambriaApiException {
96 log.info("MetricsRestService: getMetrics : START");
97 metricsService.get(getDmaapContext());
98 log.info("MetricsRestService: getMetrics : Completed");
99 } catch (IOException e) {
100 log.error("Error while fetching metrics data : ", e);
101 ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_FORBIDDEN,
102 DMaaPResponseCode.GET_METRICS_ERROR.getResponseCode(),
103 "Error while fetching metrics data"+ e.getMessage());
104 log.info(errRes.toString());
105 throw new CambriaApiException(errRes);
110 * This method is for get the metrics details by the metrics name
113 * @throws CambriaApiException
116 @Path("/{metricName}")
117 @Produces("text/plain")
118 public void getMetricsByName(@PathParam("metricName") String metricName)
119 throws CambriaApiException {
122 log.info("MetricsProducer: getMetricsByName : START");
123 metricsService.getMetricByName(getDmaapContext(), metricName);
124 log.info("MetricsRestService: getMetricsByName : Completed");
125 } catch (IOException | CambriaApiException e) {
126 log.error("Error while fetching metrics data : ", e);
127 ErrorResponse errRes = new ErrorResponse(HttpStatus.SC_NOT_FOUND,
128 DMaaPResponseCode.GET_METRICS_ERROR.getResponseCode(),
129 "Error while fetching metrics data"+ e.getMessage());
130 log.info(errRes.toString());
131 throw new CambriaApiException(errRes);
136 * This method is used for taking Configuration Object,HttpServletRequest
137 * Object,HttpServletRequest HttpServletResponse Object,HttpServletSession
140 * @return DMaaPContext object from where user can get Configuration
141 * Object,HttpServlet Object
144 private DMaaPContext getDmaapContext() {
145 DMaaPContext dmaapContext = new DMaaPContext();
146 dmaapContext.setConfigReader(configReader);
147 dmaapContext.setRequest(request);
148 dmaapContext.setResponse(response);