Skip to content

Commit

Permalink
update the JAVA client
Browse files Browse the repository at this point in the history
  • Loading branch information
julien6387 committed Jan 19, 2025
1 parent 9605148 commit 2bc0ecc
Show file tree
Hide file tree
Showing 19 changed files with 1,015 additions and 182 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

* Consider variable CPU frequency value returned by `psutil`.

* Apply the XML-RPC updates on the JAVA client and the Flask interface.


## 0.18.7 (2025-01-10)

Expand Down
32 changes: 31 additions & 1 deletion supvisors/client/java/org/supvisors/common/DataConversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package org.supvisors.common;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Objects;
Expand Down Expand Up @@ -110,7 +112,7 @@ public static String[] namespecToStrings(final String namespec) {
}

/**
* The stringsToNamespec function joins group and process names into a namspec.
* The stringsToNamespec function joins group and process names into a namespec.
* The function accepts 3 patterns:
* "processName" + "processName" returns "processName",
* "groupName" + "processName" returns "groupName:processName",
Expand All @@ -130,6 +132,34 @@ public static String stringsToNamespec(final String groupName, final String proc
return groupName + ":" + processName;
}

/**
* The timestampToDate function converts a POSIX timestamp into a printable date and time.
*
* @param Double timestamp: The POSIX timestamp.
* @return String: The date and time.
*/
public static String timestampToDate(final Double timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (timestamp > 0.0) {
return "\"" + sdf.format(new Date(new Double(timestamp * 1000L).longValue())) + "\"";
}
return "0";
}

/**
* The timestampToDate function converts a POSIX timestamp into a printable date and time.
*
* @param Integer timestamp: The POSIX timestamp.
* @return String: The date and time.
*/
public static String timestampToDate(final Integer timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (timestamp > 0) {
return "\"" + sdf.format(new Date(new Long(timestamp * 1000L))) + "\"";
}
return "0";
}

/**
* The main for Supvisors self-tests.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ private State(int value) {
*/
private Boolean managed;

/** The monotonic time of the message, in the local reference time. */
private Double now_monotonic;

/**
* A status telling if the running application has a major failure,
* i.e. at least one of its required processes is stopped.
Expand All @@ -83,6 +86,7 @@ public SupvisorsApplicationInfo(HashMap applicationInfo) {
this.application_name = (String) applicationInfo.get("application_name");
this.statename = State.valueOf((String) applicationInfo.get("statename"));
this.managed = (Boolean) applicationInfo.get("managed");
this.now_monotonic = (Double) applicationInfo.get("now_monotonic");
this.major_failure = (Boolean) applicationInfo.get("major_failure");
this.minor_failure = (Boolean) applicationInfo.get("minor_failure");
}
Expand Down Expand Up @@ -123,6 +127,15 @@ public Boolean isManaged() {
return this.managed;
}

/**
* The getNowMonotonic method returns the monotonic time of the event.
*
* @return Double: The number of seconds since the local node startup.
*/
public Double getNowMonotonic() {
return this.now_monotonic;
}

/**
* The hasMajorFailure method returns the status of the major failure for the application.
*
Expand All @@ -147,10 +160,10 @@ public Boolean hasMinorFailure() {
* @return String: The contents of the instance.
*/
public String toString() {
return "SupvisorsApplicationInfo("
+ "name=" + this.application_name
return "SupvisorsApplicationInfo(name=" + this.application_name
+ " state=" + this.statename
+ " managed=" + this.managed
+ " nowMonotonic=" + this.now_monotonic
+ " majorFailure=" + this.major_failure
+ " minorFailure=" + this.minor_failure + ")";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Copyright 2025 Julien LE CLEACH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.supvisors.common;

import java.util.HashMap;

/**
* The Class SupvisorsCommonStateModes.
*
* Common part for SupvisorsStatus and SupvisorsStateModes.
*/

public class SupvisorsCommonStateModes implements SupvisorsAnyInfo {

/** The identifier of the Supvisors instance. */
protected String identifier;

/** The nickname of the Supervisor instance. */
protected String nick_identifier;

/** The monotonic time of the message, in the local reference time. */
protected Double now_monotonic;

/** The Supvisors state, as seen by the Supvisors instance. */
protected SupvisorsState fsm_statename;

/** The identifier of the Supervisor Master instance. */
protected String master_identifier;

/** The Supvisors degraded status. */
protected Boolean degraded_mode;

/** The Supvisors discovery mode. */
protected Boolean discovery_mode;

/** All Supvisors instance states per identifier. */
protected HashMap<String, SupvisorsInstanceState> instance_states;

/**
* This constructor gets all information from an HashMap.
*
* @param HashMap instanceInfo: The untyped structure got from the XML-RPC.
*/
@SuppressWarnings({"unchecked"})
public SupvisorsCommonStateModes(HashMap info) {
this.identifier = (String) info.get("identifier");
this.nick_identifier = (String) info.get("nick_identifier");
this.now_monotonic = (Double) info.get("now_monotonic");
this.fsm_statename = SupvisorsState.valueOf((String) info.get("fsm_statename"));
this.master_identifier = (String) info.get("master_identifier");
this.degraded_mode = (Boolean) info.get("degraded_mode");
this.discovery_mode = (Boolean) info.get("discovery_mode");
// no safe way to convert an Object to HashMap
this.instance_states = (HashMap<String, SupvisorsInstanceState>) info.get("instance_states");
}

/**
* The getName method uses the getIdentifier method.
*
* @return String: The identifier of the Supvisors instance.
*/
public String getName() {
return this.getIdentifier();
}

/**
* The getIdentifier method returns the identifier of the Supvisors instance.
*
* @return String: The identifier of the Supvisors instance.
*/
public String getIdentifier() {
return this.identifier;
}

/**
* The getNickIdentifier method returns the nickname of the Supervisor instance.
*
* @return String: The nickname of the Supervisor instance.
*/
public String getNickIdentifier() {
return this.nick_identifier;
}

/**
* The getSupvisorsIdentifier method returns the identification of the Supvisors instance,
* as a SupvisorsIdentifier instance.
*
* @return SupvisorsIdentifier: a SupvisorsIdentifier instance.
*/
public SupvisorsIdentifier getSupvisorsIdentifier() {
return new SupvisorsIdentifier(this.identifier, this.nick_identifier);
}

/**
* The getNowMonotonic method returns the monotonic time of the event.
*
* @return Double: The number of seconds since the local node startup.
*/
public Double getNowMonotonic() {
return this.now_monotonic;
}

/**
* The getState method returns the state of Supvisors.
*
* @return SupvisorsState: The state of Supvisors.
*/
public SupvisorsState getState() {
return this.fsm_statename;
}

/**
* The inDegradedMode method returns True if the Supvisors instance is in degraded mode.
*
* @return Boolean: The degraded mode status.
*/
public Boolean inDegradedMode() {
return this.degraded_mode;
}

/**
* The inDiscoveryMode method returns True if the Supvisors instance is in discovery mode.
*
* @return Boolean: The discovery mode status.
*/
public Boolean inDiscoveryMode() {
return this.discovery_mode;
}

/**
* The getInstanceStates method returns all Supvisors instance states per identifier.
*
* @return HashMap<String, SupvisorsInstanceState>: The Supvisors instances states.
*/
public HashMap<String, SupvisorsInstanceState> getInstanceStates() {
return this.instance_states;
}

/**
* The toString method returns a printable form of the SupvisorsStatus instance.
*
* @return String: The contents of the SupvisorsStatus.
*/
public String toString() {
return "identifier=" + this.identifier
+ " nickIdentifier=" + this.nick_identifier
+ " nowMonotonic=" + this.now_monotonic
+ " state=" + this.fsm_statename
+ " degradedMode=" + this.degraded_mode
+ " discoveryMode=" + this.discovery_mode
+ " instance_states=" + this.instance_states;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2025 Julien LE CLEACH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.supvisors.common;


/**
* The SupvisorsFailureStrategies enumeration.
*/
public enum SupvisorsFailureStrategies {
CONTINUE(0),
RESYNC(1),
SHUTDOWN(2);

/** The strategy code. */
private int strategyCode;

/** The constructor links the state code to the state name. */
private SupvisorsFailureStrategies(final int strategyCode) {
this.strategyCode = strategyCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public IOBytes(float recvBytes, float sentBytes) {
/** The identifier of the Supvisors instance. */
private String identifier;

/** The monotonic time of the message, in the local reference time. */
private Double now_monotonic;

/** The configured integration period. */
private Float target_period;

Expand Down Expand Up @@ -86,6 +89,7 @@ public IOBytes(float recvBytes, float sentBytes) {
@SuppressWarnings({"unchecked"})
public SupvisorsHostStatistics(HashMap statsInfo) {
this.identifier = (String) statsInfo.get("identifier");
this.now_monotonic = (Double) statsInfo.get("now_monotonic");
this.target_period = (Float) statsInfo.get("target_period");
this.period = DataConversion.arrayToFloatList((Object[]) statsInfo.get("period"));
this.cpu = DataConversion.arrayToFloatList((Object[]) statsInfo.get("cpu"));
Expand All @@ -104,6 +108,15 @@ public String getIdentifier() {
return this.identifier;
}

/**
* The getNowMonotonic method returns the monotonic time of the event.
*
* @return Double: The number of seconds since the local node startup.
*/
public Double getNowMonotonic() {
return this.now_monotonic;
}

/**
* The getTargetPeriod method returns the configured integration period.
*
Expand Down Expand Up @@ -215,6 +228,7 @@ IOBytes getInterfaceBytes(final String interfaceName) {
public String toString() {
return "SupvisorsHostStatistics("
+ "identifier=" + this.identifier
+ " nowMonotonic=" + this.now_monotonic
+ " target_period=" + this.target_period
+ " startPeriod=" + this.getStartPeriod()
+ " endPeriod=" + this.getEndPeriod()
Expand Down
Loading

0 comments on commit 2bc0ecc

Please sign in to comment.