68ed255e96c286165bcc77f4e3049e9899eba6be
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.common.database.responses;
23
24 import java.io.IOException;
25 import org.elasticsearch.client.Response;
26 import org.json.JSONException;
27 import org.json.JSONObject;
28
29 @Deprecated
30 public class ClusterHealthResponse extends BaseResponse {
31
32     public static final String HEALTHSTATUS_GREEN = "green";
33     public static final String HEALTHSTATUS_YELLOW = "yellow";
34     public static final String HEALTSTATUS_RED = "red";
35
36     private String status;
37     private boolean timedOut;
38
39     /*
40      * "cluster_name": "docker-cluster", "status": "yellow", "timed_out": false,
41      * "number_of_nodes": 1, "number_of_data_nodes": 1, "active_primary_shards": 5,
42      * "active_shards": 5, "relocating_shards": 0, "initializing_shards": 0,
43      * "unassigned_shards": 5, "delayed_unassigned_shards": 0,
44      * "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0,
45      * "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 50
46      */
47     public ClusterHealthResponse(Response response) throws UnsupportedOperationException, IOException, JSONException {
48         super(response);
49
50         JSONObject o = this.getJson(response);
51         if (o != null) {
52             this.status = o.getString("status");
53             this.timedOut = o.getBoolean("timed_out");
54         }
55     }
56
57     public boolean isTimedOut() {
58         return this.timedOut;
59     }
60
61     @SuppressWarnings("hiding")
62     public boolean isStatusMinimal(String status) {
63         if (status == null) {
64             return true;
65         }
66         if (this.status.equals(HEALTHSTATUS_GREEN)) {
67             return true;
68         }
69         if (this.status.equals(HEALTHSTATUS_YELLOW) && !status.equals(HEALTHSTATUS_GREEN)) {
70             return true;
71         }
72         if (this.status.equals(status)) {
73             return true;
74         }
75         return false;
76
77     }
78
79     public String getStatus() {
80         return this.status;
81     }
82
83 }