752a538b163a23c89a70ed3094b0a215cda43870
[music.git] / jar / src / main / java / org / onap / music / rest / RestMusicHealthCheckAPI.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
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
10  * 
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22 package org.onap.music.rest;
23
24 import java.util.HashMap;
25 /**
26  * @author inam
27  *
28  */
29 import java.util.Map;
30
31 import javax.servlet.http.HttpServletResponse;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.Path;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.core.Context;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.Consumes;
38 import javax.ws.rs.core.Response;
39 import javax.ws.rs.core.Response.ResponseBuilder;
40 import javax.ws.rs.core.Response.Status;
41
42
43 import org.onap.music.response.jsonobjects.JsonResponse;
44 import org.onap.music.eelf.healthcheck.MusicHealthCheck;
45 import org.onap.music.eelf.logging.EELFLoggerDelegate;
46 import org.onap.music.main.MusicUtil;
47 import org.onap.music.main.ResultType;
48
49 import com.att.eelf.configuration.EELFLogger;
50 import com.att.eelf.configuration.EELFManager;
51
52 import io.swagger.annotations.Api;
53 import io.swagger.annotations.ApiOperation;
54
55
56
57
58 @Path("/v{version: [0-9]+}/service")
59 @Api(value="Healthcheck Api")
60 public class RestMusicHealthCheckAPI {
61         
62         
63         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
64         
65         
66         @GET
67         @Path("/cs")
68         @ApiOperation(value = "Get Health Status", response = Map.class)
69         @Produces(MediaType.APPLICATION_JSON)
70         public Response cassandraStatus(@Context HttpServletResponse response) {
71                 logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for MUSIC Health Check status for Cassandra");
72                 
73                 Map<String, Object> resultMap = new HashMap<>();
74                 
75                 MusicHealthCheck cassHealthCheck = new MusicHealthCheck();
76                 String status = cassHealthCheck.getCassandraStatus();
77                 if(status.equals("ACTIVE")) {
78                         resultMap.put("ACTIVE", "Cassandra Running and Listening to requests");
79                         return Response.status(Status.OK).entity(resultMap).build();
80                 }else {
81                         resultMap.put("INACTIVE", "Cassandra Service is not responding");
82                         return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
83                 }
84                 
85                 
86                 
87         }
88         
89         @GET
90         @Path("/zk")
91         @ApiOperation(value = "Get Health Status", response = Map.class)
92         @Produces(MediaType.APPLICATION_JSON)
93         public Response ZKStatus(@Context HttpServletResponse response) {
94                 logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for MUSIC Health Check status for Zookeeper");
95                 Map<String, Object> resultMap = new HashMap<>();
96                 MusicHealthCheck ZKHealthCheck = new MusicHealthCheck();
97                 String status = ZKHealthCheck.getZookeeperStatus();
98                 if(status.equals("ACTIVE")) {
99                         resultMap.put("ACTIVE", "Zookeeper is Active and Running");
100                         return Response.status(Status.OK).entity(resultMap).build();
101                 }else {
102                         resultMap.put("INACTIVE", "Zookeeper is not responding");
103                         return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
104                 }
105         }
106         
107         
108         
109         
110         
111         
112
113 }