2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.common.database.responses;
24 import java.io.IOException;
25 import java.util.HashMap;
28 import org.elasticsearch.client.Response;
29 import org.json.JSONException;
30 import org.json.JSONObject;
32 public class NodeStatsResponse extends BaseResponse {
34 private NodesInfo nodesInfo;
35 private Map<String,NodeStats> nodeStats;
37 public NodesInfo getNodesInfo() {
38 return this.nodesInfo;
40 public Map<String,NodeStats> getNodeStatistics(){
41 return this.nodeStats;
43 public NodeStatsResponse(Response response) throws UnsupportedOperationException, IOException, JSONException {
46 JSONObject o = this.getJson(response);
49 this.nodesInfo = new NodesInfo(o.getJSONObject("_nodes"));
50 this.nodeStats = new HashMap<>();
51 if(this.nodesInfo.successful>0) {
52 JSONObject stats = o.getJSONObject("nodes");
53 for (Object key : stats.keySet()) {
54 k=String.valueOf(key);
55 this.nodeStats.put(k, new NodeStats(k,stats.getJSONObject(k)));
63 public static class NodesInfo{
65 public String toString() {
66 return "NodesInfo [total=" + total + ", successful=" + successful + ", failed=" + failed + "]";
69 public final int total;
70 public final int successful;
71 public final int failed;
73 public NodesInfo(JSONObject o) {
74 this.total =o.getInt("total");
75 this.successful = o.getInt("successful");
76 this.failed = o.getInt("failed");
79 public static class NodeStats{
80 public final String name;
81 public final NodeTotalDiskStats total;
84 public String toString() {
85 return "NodeStats [name=" + name + ", total=" + total + "]";
88 public NodeStats(String name,JSONObject o) {
90 this.total = new NodeTotalDiskStats(o.getJSONObject("fs").getJSONObject("total"));
93 public static class NodeTotalDiskStats{
94 public final long total;
95 public final long available;
96 public final long free;
99 public String toString() {
100 return "NodeTotalDiskStats [total=" + total + ", available=" + available + ", free=" + free
101 + ", getUseDiskPercentage()=" + getUseDiskPercentage() + "]";
104 public float getUseDiskPercentage() {
105 return (total-available)*100.0f/(float)total;
107 public NodeTotalDiskStats(JSONObject o) {
108 this.total = o.getLong("total_in_bytes");
109 this.available = o.getLong("available_in_bytes");
110 this.free = o.getLong("free_in_bytes");