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