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;
41 public Map<String, NodeStats> getNodeStatistics() {
42 return this.nodeStats;
45 public NodeStatsResponse(Response response) throws UnsupportedOperationException, IOException, JSONException {
48 JSONObject o = this.getJson(response);
51 this.nodesInfo = new NodesInfo(o.getJSONObject("_nodes"));
52 this.nodeStats = new HashMap<>();
53 if (this.nodesInfo.successful > 0) {
54 JSONObject stats = o.getJSONObject("nodes");
55 for (Object key : stats.keySet()) {
56 k = String.valueOf(key);
57 this.nodeStats.put(k, new NodeStats(k, stats.getJSONObject(k)));
65 public static class NodesInfo {
67 public String toString() {
68 return "NodesInfo [total=" + total + ", successful=" + successful + ", failed=" + failed + "]";
71 public final int total;
72 public final int successful;
73 public final int failed;
75 public NodesInfo(JSONObject o) {
76 this.total = o.getInt("total");
77 this.successful = o.getInt("successful");
78 this.failed = o.getInt("failed");
81 public static class NodeStats {
82 public final String name;
83 public final NodeTotalDiskStats total;
86 public String toString() {
87 return "NodeStats [name=" + name + ", total=" + total + "]";
90 public NodeStats(String name, JSONObject o) {
92 this.total = new NodeTotalDiskStats(o.getJSONObject("fs").getJSONObject("total"));
95 public static class NodeTotalDiskStats {
96 public final long total;
97 public final long available;
98 public final long free;
101 public String toString() {
102 return "NodeTotalDiskStats [total=" + total + ", available=" + available + ", free=" + free
103 + ", getUseDiskPercentage()=" + getUseDiskPercentage() + "]";
106 public float getUseDiskPercentage() {
107 return (total - available) * 100.0f / (float) total;
110 public NodeTotalDiskStats(JSONObject o) {
111 this.total = o.getLong("total_in_bytes");
112 this.available = o.getLong("available_in_bytes");
113 this.free = o.getLong("free_in_bytes");