Push variuos changes
[music.git] / jar / src / main / java / org / onap / music / eelf / healthcheck / MusicHealthCheck.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.eelf.healthcheck;
24
25 import java.io.BufferedReader;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.util.Iterator;
29
30
31 import java.util.HashMap;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.UUID;
36
37 import org.mindrot.jbcrypt.BCrypt;
38 import org.onap.music.datastore.PreparedQueryObject;
39 import org.onap.music.datastore.jsonobjects.JsonOnboard;
40 import org.onap.music.eelf.logging.EELFLoggerDelegate;
41 import org.onap.music.eelf.logging.format.AppMessages;
42 import org.onap.music.eelf.logging.format.ErrorSeverity;
43 import org.onap.music.eelf.logging.format.ErrorTypes;
44 import org.onap.music.exceptions.MusicLockingException;
45 import org.onap.music.lockingservice.MusicLockingService;
46 import org.onap.music.main.CachingUtil;
47 import org.onap.music.main.MusicCore;
48 import org.onap.music.main.MusicUtil;
49 import org.onap.music.main.ResultType;
50 import com.datastax.driver.core.DataType;
51 import com.datastax.driver.core.ResultSet;
52
53
54
55
56 /**
57  * @author inam
58  *
59  */
60 public class MusicHealthCheck {
61     
62     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
63     
64     private String cassandrHost;
65     private String zookeeperHost;
66     
67     
68     
69     
70     
71     
72     
73     
74     public String getCassandraStatus() {
75         logger.info(EELFLoggerDelegate.applicationLogger,"Getting Status for Cassandra");
76         if(this.getAdminKeySpace()) {
77             return "ACTIVE";
78         }else {
79             logger.info(EELFLoggerDelegate.applicationLogger,"Cassandra Service is not responding");
80             return "INACTIVE";
81         }
82    }
83     
84     
85     private Boolean getAdminKeySpace() {
86         
87         String appName = "";
88         
89         PreparedQueryObject pQuery = new PreparedQueryObject();
90         pQuery.appendQueryString(
91                         "select * from admin.keyspace_master");
92         //pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
93         try {
94             ResultSet rs = MusicCore.get(pQuery);
95         
96             if(rs != null) {
97                 return Boolean.TRUE;
98             }else {
99                 return Boolean.FALSE;
100             }
101         } catch (Exception e) {
102             logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(),AppMessages.CASSANDRACONNECTIVITY, ErrorTypes.CONNECTIONERROR, ErrorSeverity.CRITICAL);
103         }
104         
105         return Boolean.FALSE;
106         
107        
108     }
109     
110     public String getZookeeperStatus() {
111         
112         
113         String host = MusicUtil.getMyZkHost();
114         logger.info(EELFLoggerDelegate.applicationLogger,"Getting Status for Zookeeper Host: "+host);
115         try {
116             MusicLockingService lockingService = MusicCore.getLockingServiceHandle();
117             //additionally need to call the ZK to create,aquire and delete lock
118         } catch (MusicLockingException e) {
119             logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(),AppMessages.LOCKINGERROR, ErrorTypes.CONNECTIONERROR, ErrorSeverity.CRITICAL);
120             return "INACTIVE";
121         }
122     
123         logger.info(EELFLoggerDelegate.applicationLogger,"Zookeeper is Active and Running");
124         return "ACTIVE";
125         
126             //return "Zookeeper is not responding";
127         
128     }
129
130
131
132
133     public String getCassandrHost() {
134         return cassandrHost;
135     }
136
137
138
139
140     public void setCassandrHost(String cassandrHost) {
141         this.cassandrHost = cassandrHost;
142     }
143
144
145
146
147     public String getZookeeperHost() {
148         return zookeeperHost;
149     }
150
151
152
153
154     public void setZookeeperHost(String zookeeperHost) {
155         this.zookeeperHost = zookeeperHost;
156     }
157     
158     
159     
160     
161     
162     
163     
164     
165     
166     
167     
168     
169     
170     
171     
172     
173     
174     
175
176 }