All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jelastic.api.system.persistence.TriggerFireData Maven / Gradle / Ivy

There is a newer version: 8.12-1
Show newest version
/*Server class MD5: 03c24c681d48c32899443e13699dd596*/
package com.jelastic.api.system.persistence;

import com.jelastic.api.system.statistic.persistence.StatElement;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;

/**
 * @name Jelastic API Client
 * @version 8.11.2
 * @copyright Jelastic, Inc.
 */
public class TriggerFireData implements Serializable {

    private static String CLOUDLETS_KEY = "cloudlets";

    private static String CPU_KEY = "cpu";

    private static String CPU_MHZ_KEY = "cpumhz";

    private static String DISK_KEY = "disk";

    private static String MEM_KEY = "mem";

    private static String INODES_KEY = "inodes";

    private static String DURATION_KEY = "duration";

    private static String STATISTIC_KEY = "statistic";

    private static String LOAD_MARK_KEY = "loadmark";

    private static String DISK_IOPS_KEY = "disk_iops";

    private static String DISK_IO_KEY = "disk_io";

    private static String NET_IN_EXT = "net_in_ext";

    private static String NET_OUT_EXT = "net_out_ext";

    private StatElement statistic;

    private double loadMark;

    public TriggerFireData() {
    }

    public TriggerFireData(StatElement statistic, double loadMark) {
        this.statistic = statistic;
        this.loadMark = loadMark;
    }

    public StatElement getStatistic() {
        return statistic;
    }

    public void setStatistic(StatElement statistic) {
        this.statistic = statistic;
    }

    public double getLoadMark() {
        return loadMark;
    }

    public void setLoadMark(double loadMark) {
        this.loadMark = loadMark;
    }

    public JSONObject _toJSON() throws JSONException {
        JSONObject json = new JSONObject();
        json.put(LOAD_MARK_KEY, loadMark);
        if (statistic != null) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(CLOUDLETS_KEY, statistic.getChanksUsed());
            jsonObject.put(CPU_KEY, statistic.getCpuUsed());
            jsonObject.put(CPU_MHZ_KEY, statistic.getCpuMHz());
            jsonObject.put(DISK_KEY, statistic.getDiskUsed());
            jsonObject.put(MEM_KEY, statistic.getMemUsed());
            jsonObject.put(INODES_KEY, statistic.getDiskInodesUsed());
            jsonObject.put(DISK_IOPS_KEY, statistic.getDiskIopsUsed());
            jsonObject.put(DISK_IO_KEY, statistic.getDiskIoUsed());
            jsonObject.put(NET_IN_EXT, statistic.getNetInExt());
            jsonObject.put(NET_OUT_EXT, statistic.getNetOutExt());
            jsonObject.put(DURATION_KEY, statistic.getDuration());
            json.put(STATISTIC_KEY, jsonObject);
        }
        return json;
    }

    public TriggerFireData _fromJSON(JSONObject json) throws JSONException {
        if (json.has(LOAD_MARK_KEY)) {
            this.loadMark = json.getDouble(LOAD_MARK_KEY);
        }
        if (json.has(STATISTIC_KEY)) {
            JSONObject jsonObject = json.getJSONObject(STATISTIC_KEY);
            this.statistic = new StatElement();
            this.statistic.setChanksUsed(jsonObject.getInt(CLOUDLETS_KEY));
            this.statistic.setCpuUsed(jsonObject.getInt(CPU_KEY));
            this.statistic.setDiskUsed(jsonObject.getInt(DISK_KEY));
            this.statistic.setMemUsed(jsonObject.getInt(MEM_KEY));
            this.statistic.setDiskInodesUsed(jsonObject.getInt(INODES_KEY));
            this.statistic.setDiskIopsUsed(jsonObject.getInt(DISK_IOPS_KEY));
            this.statistic.setDiskIoUsed(jsonObject.getInt(DISK_IO_KEY));
            this.statistic.setNetInExt(jsonObject.getLong(NET_IN_EXT));
            this.statistic.setNetOutExt(jsonObject.getLong(NET_OUT_EXT));
            this.statistic.setDuration(jsonObject.getInt(DURATION_KEY));
        }
        return this;
    }

    public TriggerFireData fromString(String value) throws JSONException {
        return this._fromJSON(new JSONObject(value));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy