27abbea8a69d7629040685b623edcedf88b4e12e
[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 public class ClusterHealthResponse extends BaseResponse {
30
31     public static final String HEALTHSTATUS_GREEN = "green";
32     public static final String HEALTHSTATUS_YELLOW = "yellow";
33     public static final String HEALTSTATUS_RED = "red";
34
35     private String status;
36     private boolean timedOut;
37
38     /*
39      * "cluster_name": "docker-cluster", "status": "yellow", "timed_out": false,
40      * "number_of_nodes": 1, "number_of_data_nodes": 1, "active_primary_shards": 5,
41      * "active_shards": 5, "relocating_shards": 0, "initializing_shards": 0,
42      * "unassigned_shards": 5, "delayed_unassigned_shards": 0,
43      * "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0,
44      * "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 50
45      */
46     public ClusterHealthResponse(Response response) throws UnsupportedOperationException, IOException, JSONException {
47         super(response);
48
49         JSONObject o = this.getJson(response);
50         if (o != null) {
51             this.status = o.getString("status");
52             this.timedOut = o.getBoolean("timed_out");
53         }
54     }
55
56     public boolean isTimedOut() {
57         return this.timedOut;
58     }
59
60     @SuppressWarnings("hiding")
61     public boolean isStatusMinimal(String status) {
62         if (status == null) {
63             return true;
64         }
65         if (this.status.equals(HEALTHSTATUS_GREEN)) {
66             return true;
67         }
68         if (this.status.equals(HEALTHSTATUS_YELLOW) && !status.equals(HEALTHSTATUS_GREEN)) {
69             return true;
70         }
71         if (this.status.equals(status)) {
72             return true;
73         }
74         return false;
75
76     }
77
78     public String getStatus() {
79         return this.status;
80     }
81
82 }