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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.common.database.responses;
20 import java.io.IOException;
21 import java.util.HashMap;
24 import org.elasticsearch.client.Response;
25 import org.json.JSONException;
26 import org.json.JSONObject;
28 public class NodeStatsResponse extends BaseResponse {
30 private NodesInfo nodesInfo;
31 private Map<String,NodeStats> nodeStats;
33 public NodesInfo getNodesInfo() {
34 return this.nodesInfo;
36 public Map<String,NodeStats> getNodeStatistics(){
37 return this.nodeStats;
39 public NodeStatsResponse(Response response) throws UnsupportedOperationException, IOException, JSONException {
42 JSONObject o = this.getJson(response);
45 this.nodesInfo = new NodesInfo(o.getJSONObject("_nodes"));
46 this.nodeStats = new HashMap<>();
47 if(this.nodesInfo.successful>0) {
48 JSONObject stats = o.getJSONObject("nodes");
49 for (Object key : stats.keySet()) {
50 k=String.valueOf(key);
51 this.nodeStats.put(k, new NodeStats(k,stats.getJSONObject(k)));
59 public static class NodesInfo{
61 public String toString() {
62 return "NodesInfo [total=" + total + ", successful=" + successful + ", failed=" + failed + "]";
65 public final int total;
66 public final int successful;
67 public final int failed;
69 public NodesInfo(JSONObject o) {
70 this.total =o.getInt("total");
71 this.successful = o.getInt("successful");
72 this.failed = o.getInt("failed");
75 public static class NodeStats{
76 public final String name;
77 public final NodeTotalDiskStats total;
80 public String toString() {
81 return "NodeStats [name=" + name + ", total=" + total + "]";
84 public NodeStats(String name,JSONObject o) {
86 this.total = new NodeTotalDiskStats(o.getJSONObject("fs").getJSONObject("total"));
89 public static class NodeTotalDiskStats{
90 public final long total;
91 public final long available;
92 public final long free;
95 public String toString() {
96 return "NodeTotalDiskStats [total=" + total + ", available=" + available + ", free=" + free
97 + ", getUseDiskPercentage()=" + getUseDiskPercentage() + "]";
100 public float getUseDiskPercentage() {
101 return (total-available)*100.0f/(float)total;
103 public NodeTotalDiskStats(JSONObject o) {
104 this.total = o.getLong("total_in_bytes");
105 this.available = o.getLong("available_in_bytes");
106 this.free = o.getLong("free_in_bytes");