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