2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
22 package org.onap.music.rest;
24 import java.util.HashMap;
31 import javax.servlet.http.HttpServletResponse;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.Path;
34 import javax.ws.rs.PathParam;
35 import javax.ws.rs.Produces;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MediaType;
38 import javax.ws.rs.Consumes;
39 import javax.ws.rs.core.Response;
40 import javax.ws.rs.core.Response.ResponseBuilder;
41 import javax.ws.rs.core.Response.Status;
44 import org.onap.music.response.jsonobjects.JsonResponse;
45 import org.onap.music.eelf.healthcheck.MusicHealthCheck;
46 import org.onap.music.eelf.logging.EELFLoggerDelegate;
47 import org.onap.music.main.MusicUtil;
48 import org.onap.music.main.ResultType;
50 import com.att.eelf.configuration.EELFLogger;
51 import com.att.eelf.configuration.EELFManager;
52 import com.datastax.driver.core.ConsistencyLevel;
54 import io.swagger.annotations.Api;
55 import io.swagger.annotations.ApiOperation;
56 import io.swagger.annotations.ApiParam;
61 @Path("/v{version: [0-9]+}/service")
62 @Api(value="Healthcheck Api")
63 public class RestMusicHealthCheckAPI {
66 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
70 @Path("/pingCassandra/{consistency}")
71 @ApiOperation(value = "Get Health Status", response = Map.class)
72 @Produces(MediaType.APPLICATION_JSON)
73 public Response cassandraStatus(@Context HttpServletResponse response, @ApiParam(value = "Consistency level",
74 required = true) @PathParam("consistency") String consistency) {
75 logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for MUSIC Health Check status for Cassandra");
77 Map<String, Object> resultMap = new HashMap<>();
78 if(ConsistencyLevel.valueOf(consistency) == null) {
79 resultMap.put("INVALID", "Consistency level is invalid...");
80 return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
82 MusicHealthCheck cassHealthCheck = new MusicHealthCheck();
83 String status = cassHealthCheck.getCassandraStatus(consistency);
84 if(status.equals("ACTIVE")) {
85 resultMap.put("ACTIVE", "Cassandra Running and Listening to requests");
86 return Response.status(Status.OK).entity(resultMap).build();
88 resultMap.put("INACTIVE", "One or more nodes in the Cluster is/are down or not responding.");
89 return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
97 @Path("/pingZookeeper")
98 @ApiOperation(value = "Get Health Status", response = Map.class)
99 @Produces(MediaType.APPLICATION_JSON)
100 public Response ZKStatus(@Context HttpServletResponse response) {
101 logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for MUSIC Health Check status for Zookeeper");
102 Map<String, Object> resultMap = new HashMap<>();
103 MusicHealthCheck ZKHealthCheck = new MusicHealthCheck();
104 String status = ZKHealthCheck.getZookeeperStatus();
105 if(status.equals("ACTIVE")) {
106 resultMap.put("ACTIVE", "Zookeeper is Active and Running");
107 return Response.status(Status.OK).entity(resultMap).build();
109 resultMap.put("INACTIVE", "Zookeeper is not responding");
110 return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
115 @Path("/musicHealthCheck")
116 @ApiOperation(value = "Get Health Status", response = Map.class)
117 @Produces(MediaType.APPLICATION_JSON)
118 public Response musicHealthCheck() {
119 logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for Health Check status for MUSIC");
120 Map<String, Object> resultMap = new HashMap<>();
121 MusicHealthCheck healthCheck = new MusicHealthCheck();
122 String status = healthCheck.getZookeeperStatus();
123 if(status.equals("ACTIVE")) {
124 resultMap.put("ZooKeeper", "Active");
126 resultMap.put("ZooKeeper", "Inactive");
128 status = healthCheck.getCassandraStatus(ConsistencyLevel.ANY.toString());
129 if(status.equals("ACTIVE")) {
130 resultMap.put("Cassandra", "Active");
132 resultMap.put("Cassandra", "Inactive");
134 resultMap.put("MUSIC", "Active");
135 return Response.status(Status.OK).entity(resultMap).build();