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