Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.jelastic.api.system.persistence.HardwareNode Maven / Gradle / Ivy
/*Server class MD5: 3f022df89ac67e9037412398bb8de2a1*/
package com.jelastic.api.system.persistence;
import com.jelastic.api.common.annotation.Transform;
import com.jelastic.api.common.data.po.HnUsageType;
import com.jelastic.api.core.utils.ArrayUtils;
import com.jelastic.api.core.utils.CommonJSONUtils;
import com.jelastic.api.core.utils.StringUtils;
import com.jelastic.api.core.utils.UsageUtils;
import com.jelastic.api.data.HardwareNodeStatus;
import com.jelastic.api.development.response.interfaces.ArrayItem;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.*;
/**
* @name Jelastic API Client
* @version 8.11.2
* @copyright Jelastic, Inc.
*/
public class HardwareNode extends ArrayItem implements Comparable {
public static final String ID = "id";
public static final String HARDWARE_NODE_COLUMN = "hardwareNode";
public static final String IS_DELETED_FILTER = "isDeletedFilter";
public static final String IS_DELETED_FILTER_PARAM = "isDeleted";
public static final String STATUS = "status";
public static final String L2_IP = "l2Ip";
public static final String L2_ENABLED = "l2Enabled";
public static final String L2_READY = "l2Ready";
public static final String LABELS = "labels";
public static final String ZONE_LABEL_NAME = "zone";
public static final String HOST_NAME = "hostname";
public static final String IP_ADDRESS = "ipAddress";
public static final String HW_TYPE = "hwType";
public static final String OS_TYPE = "osType";
public static final String LOAD_MARK_OFFSET = "loadMarkOffset";
public static final String DOCKER_CACHE_LOCATION_TYPE = "dockerCacheLocationType";
public static final String EXTERNAL_IP = "externalIp";
public static final String REAL_EXTERNAL_IP = "realExternalIp";
public static final String VIRTUAL_NET_IP = "virtualNetIp";
public static final String IPSEC_KEY = "ipsecKey";
public static final String REGION_GATE_NUMBER = "regionGateNumber";
public static final String HARDWARE_NODE_GROUP = "hardwareNodeGroup";
public static final String VIRTUAL_NETWORK_HOST_IDS = "virtualNetworkHostIds";
public static final String OS_TEMPLATES = "osTemplates";
@Transform(required = true)
private String ipAddress;
private String previousIpAddress;
@Transform(required = true)
private int soapPort;
@Transform(required = true)
private String soapProtocol;
private HardwareNodeStatus status;
private HWType hwType;
@Transform(required = true)
private String hostname;
@Transform(required = true)
private Credential soapCredential;
@Transform(required = true)
private int tcpPort;
private int power = 0;
private int cpuNumber = 0;
private int cpuFreq = 0;
private int sshPort = 22;
@Transform(required = true)
private Credential sshCredential;
private VSVersions vsVersion;
@Transform(skip = true)
private HnUsageType hnUsageType;
private Long totalRam;
private String licenceKey;
private boolean isDeleted;
private String tcpProtocol;
private int vzType;
private Set hardwareNodeClusters = new HashSet<>();
private HardwareNodeGroup hardwareNodeGroup;
@Transform(skip = true)
private String hardwareNodeGroupUniqueName;
private String data;
private OSType osType;
private String gateway;
private boolean vzInstall;
private int physCpuNumber = 0;
private VZLicense vzLicense;
private HardwareNodeStatus prevStatus;
private String vzDirectory;
private String l2Ip;
private String previousL2Ip;
private Boolean l2Enabled;
private Boolean l2Ready;
private Boolean previousL2Enabled;
private Set labels = new HashSet<>();
private Integer loadmark;
private boolean isFWUpdated;
private int loadMarkOffset;
private DockerCacheLocationType dockerCacheLocationType = DockerCacheLocationType.NONE;
private String externalIp;
private String realExternalIp;
private String virtualNetIp;
private String ipsecKey;
private Integer regionGateNumber;
private List virtualNetworkHostIds;
private String osTemplates;
public Integer getLoadmark() {
return loadmark;
}
public void setLoadmark(Integer loadmark) {
this.loadmark = loadmark;
}
public boolean isVzInstall() {
return vzInstall;
}
public void setVzInstall(boolean vzInstall) {
this.vzInstall = vzInstall;
}
public int getTcpPort() {
return tcpPort;
}
public void setTcpPort(int tcpPort) {
this.tcpPort = tcpPort;
}
public String getTcpProtocol() {
return tcpProtocol;
}
public void setTcpProtocol(String tcpProtocol) {
this.tcpProtocol = tcpProtocol;
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public HardwareNodeStatus getStatus() {
return this.status;
}
public void setStatus(HardwareNodeStatus status) {
this.prevStatus = this.status;
this.status = status;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.previousIpAddress = this.ipAddress;
this.ipAddress = ipAddress;
}
public boolean isIpChanged() {
return this.previousIpAddress != null && !this.previousIpAddress.equalsIgnoreCase(this.ipAddress);
}
public String getPreviousIpAddress() {
return previousIpAddress;
}
public Credential getSoapCredential() {
return soapCredential;
}
public void setSoapCredential(Credential soapCredential) {
this.soapCredential = soapCredential;
}
public int getSoapPort() {
return soapPort;
}
public void setSoapPort(int soapPort) {
this.soapPort = soapPort;
}
public String getSoapProtocol() {
return soapProtocol;
}
public void setSoapProtocol(String soapProtocol) {
this.soapProtocol = soapProtocol;
}
public String getEndPointAddress() {
return this.soapProtocol + "://" + this.ipAddress + ":" + this.getSoapPort();
}
public int getCpuFreq() {
return cpuFreq;
}
public void setCpuFreq(int cpuFreq) {
this.cpuFreq = cpuFreq;
}
public int getCpuNumber() {
return cpuNumber;
}
public void setCpuNumber(int cpuNumber) {
this.cpuNumber = cpuNumber;
}
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
public int getSshPort() {
return sshPort;
}
public void setSshPort(int sshPort) {
this.sshPort = sshPort;
}
public HnUsageType getHnUsageType() {
return hnUsageType;
}
public void setHnUsageType(HnUsageType hnUsageType) {
this.hnUsageType = hnUsageType;
}
public Long getTotalRam() {
if (totalRam == null) {
return 0L;
}
return totalRam;
}
public boolean isTotalRamInit() {
return totalRam != null && totalRam != 0;
}
public void setTotalRam(Long totalRam) {
this.totalRam = totalRam;
}
public VSVersions getVsVersion() {
return vsVersion;
}
public void setVsVersion(VSVersions vsVersion) {
this.vsVersion = vsVersion;
}
public String getLicenceKey() {
return licenceKey;
}
public void setLicenceKey(String licenceKey) {
this.licenceKey = licenceKey;
}
public Credential getSshCredential() {
return sshCredential;
}
public void setSshCredential(Credential sshCredential) {
this.sshCredential = sshCredential;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean isDeleted) {
this.isDeleted = isDeleted;
}
public int getVzType() {
return vzType;
}
public void setVzType(int vzType) {
this.vzType = vzType;
}
public OSType getOsType() {
return osType;
}
public void setOsType(OSType osType) {
this.osType = osType;
}
public Set getHardwareNodeClusters() {
return hardwareNodeClusters;
}
public void setHardwareNodeClusters(Set hardwareNodeClusters) {
this.hardwareNodeClusters = hardwareNodeClusters;
}
public HardwareNodeGroup getHardwareNodeGroup() {
return hardwareNodeGroup;
}
public void setHardwareNodeGroup(HardwareNodeGroup hardwareNodeGroup) {
this.hardwareNodeGroup = hardwareNodeGroup;
}
public String getHardwareNodeGroupUniqueName() {
if (hardwareNodeGroup == null) {
return hardwareNodeGroupUniqueName;
}
return hardwareNodeGroup.getUniqueName();
}
public void setHardwareNodeGroupUniqueName(String hardwareNodeGroupUniqueName) {
this.hardwareNodeGroupUniqueName = hardwareNodeGroupUniqueName;
}
public String getGateway() {
return gateway;
}
public void setGateway(String gateway) {
this.gateway = gateway;
}
public String getZone() {
return hardwareNodeGroup.getRegion().getDomain();
}
public int getPhysCpuNumber() {
return physCpuNumber;
}
public void setPhysCpuNumber(int physCpuNumber) {
this.physCpuNumber = physCpuNumber;
}
public VZLicense getVzLicense() {
return vzLicense;
}
public void setVzLicense(VZLicense vzLicense) {
this.vzLicense = vzLicense;
}
public HardwareNodeStatus getPrevStatus() {
return prevStatus;
}
public void setPrevStatus(HardwareNodeStatus prevStatus) {
this.prevStatus = prevStatus;
}
public String getVzDirectory() {
return vzDirectory;
}
public void setVzDirectory(String vzDirectory) {
this.vzDirectory = vzDirectory;
}
public String getL2Ip() {
return l2Ip;
}
public void setL2Ip(String l2Ip) {
this.previousL2Ip = this.l2Ip;
this.l2Ip = l2Ip;
}
public boolean isL2IpChanged() {
return this.previousL2Ip != null && !this.previousL2Ip.equalsIgnoreCase(this.l2Ip);
}
public String getPreviousL2Ip() {
return previousL2Ip;
}
public Boolean getL2Enabled() {
return l2Enabled;
}
public boolean isL2Enabled() {
return isL2EnabledNotNull() && l2Enabled;
}
public boolean isL2EnabledNotNull() {
return l2Enabled != null;
}
public void setL2Enabled(Boolean l2Enabled) {
this.previousL2Enabled = this.l2Enabled;
this.l2Enabled = l2Enabled;
}
public Boolean getL2Ready() {
return l2Ready;
}
public void setL2Ready(Boolean l2Ready) {
this.l2Ready = l2Ready;
}
public boolean isL2Ready() {
return l2Ready != null && l2Ready;
}
public Boolean getPreviousL2Enabled() {
return previousL2Enabled;
}
public void setPreviousL2Enabled(Boolean previousL2Enabled) {
this.previousL2Enabled = previousL2Enabled;
}
public boolean isL2EnabledChanged() {
return this.previousL2Enabled != null && this.previousL2Enabled != this.l2Enabled;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public Set getLabels() {
return labels;
}
public void setLabels(Set labels) {
this.labels = labels;
}
public HWType getHwType() {
return hwType;
}
public void setHwType(HWType hwType) {
this.hwType = hwType;
}
public boolean isFWUpdated() {
return isFWUpdated;
}
public void setFWUpdated(boolean isFWUpdated) {
this.isFWUpdated = isFWUpdated;
}
public int getLoadMarkOffset() {
return loadMarkOffset;
}
public void setLoadMarkOffset(int loadMarkOffset) {
this.loadMarkOffset = loadMarkOffset;
}
public DockerCacheLocationType getDockerCacheLocationType() {
return dockerCacheLocationType;
}
public void setDockerCacheLocationType(DockerCacheLocationType dockerCacheLocationType) {
this.dockerCacheLocationType = dockerCacheLocationType;
}
public String getExternalIp() {
return externalIp;
}
public void setExternalIp(String externalIp) {
this.externalIp = externalIp;
}
public String getRealExternalIp() {
return realExternalIp;
}
public void setRealExternalIp(String realExternalIp) {
this.realExternalIp = realExternalIp;
}
public String getVirtualNetIp() {
return virtualNetIp;
}
public void setVirtualNetIp(String virtualNetIp) {
this.virtualNetIp = virtualNetIp;
}
public String getIpsecKey() {
return ipsecKey;
}
public void setIpsecKey(String ipsecKey) {
this.ipsecKey = ipsecKey;
}
public Integer getRegionGateNumber() {
return regionGateNumber;
}
public void setRegionGateNumber(Integer regionGateNumber) {
this.regionGateNumber = regionGateNumber;
}
public List getVirtualNetworkHostIds() {
return virtualNetworkHostIds;
}
public void setVirtualNetworkHostIds(List virtualNetworkHostIds) {
this.virtualNetworkHostIds = virtualNetworkHostIds;
}
public String getOsTemplates() {
return osTemplates;
}
public void setOsTemplates(String osTemplates) {
this.osTemplates = osTemplates;
}
@Override
public JSONObject _toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);
if (sshCredential != null) {
json.put("sshCredential", sshCredential._toJSON());
}
json.put("soapProtocol", soapProtocol);
json.put("cpuNumber", cpuNumber);
json.put("physCpuNumber", physCpuNumber);
json.put("status", status);
if (soapCredential != null) {
json.put("soapCredential", soapCredential._toJSON());
}
json.put("hostname", hostname);
json.put("sshPort", sshPort);
json.put("soapPort", soapPort);
json.put("tcpPort", tcpPort);
if (vsVersion != null) {
json.put("vsVersion", vsVersion._toJSON());
}
if (vzLicense != null) {
json.put("vzLicense", vzLicense._toJSON());
}
json.put("tcpProtocol", tcpProtocol);
json.put("power", power);
json.put("vzType", vzType);
json.put("ipAddress", ipAddress);
json.put("cpuFreq", cpuFreq);
json.put("cpuFreq", cpuFreq);
if (data != null) {
json.put("data", data);
}
if (osType != null) {
json.put(OS_TYPE, osType.toString());
}
if (hwType != null) {
json.put(HW_TYPE, hwType.toString());
}
if (hardwareNodeClusters != null) {
JSONArray hardwareNodeClusterArray = new JSONArray();
for (HardwareNodePcsCluster hardwareNodeCluster : hardwareNodeClusters) {
hardwareNodeClusterArray.put(hardwareNodeCluster._toJSON());
}
json.put("hardwareNodeClusters", hardwareNodeClusterArray);
}
if (hardwareNodeGroup != null) {
json.put("hardwareNodeGroup", hardwareNodeGroup.getUniqueName());
} else if (this.hardwareNodeGroupUniqueName != null) {
json.put("hardwareNodeGroup", this.hardwareNodeGroupUniqueName);
}
if (l2Ip != null) {
json.put(L2_IP, l2Ip);
}
if (l2Enabled != null) {
json.put(L2_ENABLED, l2Enabled);
}
json.put(L2_READY, l2Ready != null ? l2Ready : false);
if (labels != null && !labels.isEmpty()) {
JSONObject labelsJSON = new JSONObject();
for (Label label : labels) {
labelsJSON.put(label.getName(), label.getValue());
}
json.put(LABELS, labelsJSON);
}
json.put(LOAD_MARK_OFFSET, loadMarkOffset);
if (dockerCacheLocationType != null) {
json.put(DOCKER_CACHE_LOCATION_TYPE, dockerCacheLocationType.name());
}
if (realExternalIp != null) {
json.put(REAL_EXTERNAL_IP, realExternalIp);
}
if (externalIp != null) {
json.put(EXTERNAL_IP, externalIp);
}
if (virtualNetIp != null) {
json.put(VIRTUAL_NET_IP, virtualNetIp);
}
if (ipsecKey != null) {
json.put(IPSEC_KEY, ipsecKey);
}
if (regionGateNumber != null) {
json.put(REGION_GATE_NUMBER, regionGateNumber);
}
if (virtualNetworkHostIds != null && !virtualNetworkHostIds.isEmpty()) {
json.put(VIRTUAL_NETWORK_HOST_IDS, virtualNetworkHostIds);
}
if (osTemplates != null) {
json.put(OS_TEMPLATES, osTemplates);
}
return json;
}
@Override
public HardwareNode _fromJSON(JSONObject json) throws JSONException {
if (json.has("id")) {
this.id = json.getInt("id");
}
if (json.has("sshCredential")) {
this.sshCredential = (Credential) new Credential()._fromJSON(json.getJSONObject("sshCredential"));
}
if (json.has("soapProtocol")) {
this.soapProtocol = json.getString("soapProtocol");
}
if (json.has("cpuNumber")) {
this.cpuNumber = json.getInt("cpuNumber");
}
if (json.has("physCpuNumber")) {
this.physCpuNumber = json.getInt("physCpuNumber");
}
if (json.has("status")) {
this.status = HardwareNodeStatus.valueOf(HardwareNodeStatus.class, json.getString("status").toUpperCase());
}
if (json.has("soapCredential")) {
this.soapCredential = (Credential) new Credential()._fromJSON(json.getJSONObject("soapCredential"));
}
if (json.has("hostname")) {
this.hostname = json.getString("hostname");
}
if (json.has("sshPort")) {
this.sshPort = json.getInt("sshPort");
}
if (json.has("soapPort")) {
this.soapPort = json.getInt("soapPort");
}
if (json.has("tcpPort")) {
this.tcpPort = json.getInt("tcpPort");
}
if (json.has("vsVersion")) {
this.vsVersion = (VSVersions) new VSVersions()._fromJSON(json.getJSONObject("vsVersion"));
}
if (json.has("vzLicense")) {
this.vzLicense = (VZLicense) new VZLicense()._fromJSON(json.getJSONObject("vzLicense"));
}
if (json.has("tcpProtocol")) {
this.tcpProtocol = json.getString("tcpProtocol");
}
if (json.has("power")) {
this.power = json.getInt("power");
}
if (json.has("vzType")) {
this.vzType = json.getInt("vzType");
}
if (json.has("ipAddress")) {
this.setIpAddress(json.getString("ipAddress"));
}
if (json.has("data")) {
this.data = json.getString("data");
}
if (json.has("cpuFreq")) {
this.cpuFreq = json.getInt("cpuFreq");
}
if (json.has(OS_TYPE)) {
this.osType = OSType.valueOf(OSType.class, json.getString(OS_TYPE));
}
if (json.has(HW_TYPE)) {
this.hwType = HWType.valueOf(HWType.class, json.getString(HW_TYPE));
}
if (json.has("hardwareNodeClusters")) {
hardwareNodeClusters = new HashSet();
JSONArray array = json.getJSONArray("hardwareNodeClusters");
for (int i = 0; i < array.length(); i++) {
hardwareNodeClusters.add(new HardwareNodePcsCluster()._fromJSON(array.getJSONObject(i)));
}
}
if (json.has("hardwareNodeGroup")) {
this.hardwareNodeGroupUniqueName = json.getString("hardwareNodeGroup");
}
if (json.has("licenceKey")) {
this.licenceKey = json.getString("licenceKey");
}
if (json.has("vzInstall")) {
this.vzInstall = json.getBoolean("vzInstall");
}
if (json.has(L2_IP)) {
this.setL2Ip(json.getString(L2_IP));
}
if (json.has(L2_ENABLED)) {
setL2Enabled(json.getBoolean(L2_ENABLED));
}
this.l2Ready = json.has(L2_READY) && json.getBoolean(L2_READY);
if (json.has(LABELS)) {
JSONObject labelsJSON = json.getJSONObject(LABELS);
Map labelsMap = CommonJSONUtils.convertJSONObjectToStringMap(labelsJSON);
for (Map.Entry entry : labelsMap.entrySet()) {
labels.add(new Label(entry.getKey(), entry.getValue()));
}
}
if (json.has(LOAD_MARK_OFFSET)) {
this.loadMarkOffset = json.getInt(LOAD_MARK_OFFSET);
}
if (json.has(DOCKER_CACHE_LOCATION_TYPE)) {
this.dockerCacheLocationType = DockerCacheLocationType.valueOf(json.getString(DOCKER_CACHE_LOCATION_TYPE));
}
if (json.has(REAL_EXTERNAL_IP)) {
this.realExternalIp = json.getString(REAL_EXTERNAL_IP);
}
if (json.has(EXTERNAL_IP)) {
this.externalIp = json.getString(EXTERNAL_IP);
}
if (json.has(VIRTUAL_NET_IP)) {
String virtualNetIp = json.getString(VIRTUAL_NET_IP);
if (StringUtils.isNotBlank(virtualNetIp)) {
this.virtualNetIp = virtualNetIp;
}
}
if (json.has(IPSEC_KEY)) {
this.ipsecKey = json.getString(IPSEC_KEY);
}
if (json.has(REGION_GATE_NUMBER)) {
this.ipsecKey = json.getString(IPSEC_KEY);
}
if (json.has(VIRTUAL_NETWORK_HOST_IDS)) {
List ids = new ArrayList<>();
JSONArray jsonArray = json.getJSONArray(VIRTUAL_NETWORK_HOST_IDS);
for (int i = 0; i < jsonArray.length(); i++) {
ids.add(jsonArray.getInt(i));
}
this.virtualNetworkHostIds = ids;
}
if (json.has(OS_TEMPLATES)) {
this.osTemplates = json.getString(OS_TEMPLATES);
}
return this;
}
public static HardwareNode fakeHardNodeFromRegionDockerHost(Region region) {
HardwareNode hardwareNode = new HardwareNode();
hardwareNode.setIpAddress(region.getDockerHost());
hardwareNode.setSshCredential(new Credential(region.getDockerLogin(), region.getDockerPassword()));
hardwareNode.setSshPort(region.getDockerSSHPort());
return hardwareNode;
}
@Override
public int compareTo(HardwareNode o) {
if (this.hnUsageType == null || o.hnUsageType == null) {
return 0;
}
double usageMemInPercent1 = UsageUtils.getUsageInPercent(this.hnUsageType.getUsed(), this.hnUsageType.getTotal());
double usageMemInPercent2 = UsageUtils.getUsageInPercent(o.getHnUsageType().getUsed(), o.getHnUsageType().getTotal());
return (Double.compare(usageMemInPercent2, usageMemInPercent1));
}
public boolean equalsAnyStatus(HardwareNodeStatus... statuses) {
return ArrayUtils.contains(statuses, this.status);
}
public Label getLabelByName(String name) {
return labels.stream().filter(l -> StringUtils.equalsIgnoreCase(name, l.getName())).findAny().orElse(null);
}
public String getZoneLabel() {
Label zoneLabel = this.getLabelByName(HardwareNode.ZONE_LABEL_NAME);
if (zoneLabel == null) {
return null;
}
return StringUtils.lowerCase(zoneLabel.getValue());
}
public void initializeLazyFields() {
getLabels().size();
}
@Override
public String toString() {
return "HardwareNode{" + "id='" + id + '\'' + ", ipAddress='" + ipAddress + '\'' + ", status=" + status + ", freq=" + cpuFreq + ", hostname='" + hostname + '\'' + '}';
}
}