Skip to content

Commit 2bc0ecc

Browse files
committed
update the JAVA client
1 parent 9605148 commit 2bc0ecc

19 files changed

+1015
-182
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

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

58+
* Apply the XML-RPC updates on the JAVA client and the Flask interface.
59+
5860

5961
## 0.18.7 (2025-01-10)
6062

supvisors/client/java/org/supvisors/common/DataConversion.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package org.supvisors.common;
1818

19+
import java.text.SimpleDateFormat;
1920
import java.util.Arrays;
2021
import java.util.ArrayList;
22+
import java.util.Date;
2123
import java.util.List;
2224
import java.util.HashMap;
2325
import java.util.Objects;
@@ -110,7 +112,7 @@ public static String[] namespecToStrings(final String namespec) {
110112
}
111113

112114
/**
113-
* The stringsToNamespec function joins group and process names into a namspec.
115+
* The stringsToNamespec function joins group and process names into a namespec.
114116
* The function accepts 3 patterns:
115117
* "processName" + "processName" returns "processName",
116118
* "groupName" + "processName" returns "groupName:processName",
@@ -130,6 +132,34 @@ public static String stringsToNamespec(final String groupName, final String proc
130132
return groupName + ":" + processName;
131133
}
132134

135+
/**
136+
* The timestampToDate function converts a POSIX timestamp into a printable date and time.
137+
*
138+
* @param Double timestamp: The POSIX timestamp.
139+
* @return String: The date and time.
140+
*/
141+
public static String timestampToDate(final Double timestamp) {
142+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
143+
if (timestamp > 0.0) {
144+
return "\"" + sdf.format(new Date(new Double(timestamp * 1000L).longValue())) + "\"";
145+
}
146+
return "0";
147+
}
148+
149+
/**
150+
* The timestampToDate function converts a POSIX timestamp into a printable date and time.
151+
*
152+
* @param Integer timestamp: The POSIX timestamp.
153+
* @return String: The date and time.
154+
*/
155+
public static String timestampToDate(final Integer timestamp) {
156+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
157+
if (timestamp > 0) {
158+
return "\"" + sdf.format(new Date(new Long(timestamp * 1000L))) + "\"";
159+
}
160+
return "0";
161+
}
162+
133163
/**
134164
* The main for Supvisors self-tests.
135165
*

supvisors/client/java/org/supvisors/common/SupvisorsApplicationInfo.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ private State(int value) {
6262
*/
6363
private Boolean managed;
6464

65+
/** The monotonic time of the message, in the local reference time. */
66+
private Double now_monotonic;
67+
6568
/**
6669
* A status telling if the running application has a major failure,
6770
* i.e. at least one of its required processes is stopped.
@@ -83,6 +86,7 @@ public SupvisorsApplicationInfo(HashMap applicationInfo) {
8386
this.application_name = (String) applicationInfo.get("application_name");
8487
this.statename = State.valueOf((String) applicationInfo.get("statename"));
8588
this.managed = (Boolean) applicationInfo.get("managed");
89+
this.now_monotonic = (Double) applicationInfo.get("now_monotonic");
8690
this.major_failure = (Boolean) applicationInfo.get("major_failure");
8791
this.minor_failure = (Boolean) applicationInfo.get("minor_failure");
8892
}
@@ -123,6 +127,15 @@ public Boolean isManaged() {
123127
return this.managed;
124128
}
125129

130+
/**
131+
* The getNowMonotonic method returns the monotonic time of the event.
132+
*
133+
* @return Double: The number of seconds since the local node startup.
134+
*/
135+
public Double getNowMonotonic() {
136+
return this.now_monotonic;
137+
}
138+
126139
/**
127140
* The hasMajorFailure method returns the status of the major failure for the application.
128141
*
@@ -147,10 +160,10 @@ public Boolean hasMinorFailure() {
147160
* @return String: The contents of the instance.
148161
*/
149162
public String toString() {
150-
return "SupvisorsApplicationInfo("
151-
+ "name=" + this.application_name
163+
return "SupvisorsApplicationInfo(name=" + this.application_name
152164
+ " state=" + this.statename
153165
+ " managed=" + this.managed
166+
+ " nowMonotonic=" + this.now_monotonic
154167
+ " majorFailure=" + this.major_failure
155168
+ " minorFailure=" + this.minor_failure + ")";
156169
}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Copyright 2025 Julien LE CLEACH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.supvisors.common;
18+
19+
import java.util.HashMap;
20+
21+
/**
22+
* The Class SupvisorsCommonStateModes.
23+
*
24+
* Common part for SupvisorsStatus and SupvisorsStateModes.
25+
*/
26+
27+
public class SupvisorsCommonStateModes implements SupvisorsAnyInfo {
28+
29+
/** The identifier of the Supvisors instance. */
30+
protected String identifier;
31+
32+
/** The nickname of the Supervisor instance. */
33+
protected String nick_identifier;
34+
35+
/** The monotonic time of the message, in the local reference time. */
36+
protected Double now_monotonic;
37+
38+
/** The Supvisors state, as seen by the Supvisors instance. */
39+
protected SupvisorsState fsm_statename;
40+
41+
/** The identifier of the Supervisor Master instance. */
42+
protected String master_identifier;
43+
44+
/** The Supvisors degraded status. */
45+
protected Boolean degraded_mode;
46+
47+
/** The Supvisors discovery mode. */
48+
protected Boolean discovery_mode;
49+
50+
/** All Supvisors instance states per identifier. */
51+
protected HashMap<String, SupvisorsInstanceState> instance_states;
52+
53+
/**
54+
* This constructor gets all information from an HashMap.
55+
*
56+
* @param HashMap instanceInfo: The untyped structure got from the XML-RPC.
57+
*/
58+
@SuppressWarnings({"unchecked"})
59+
public SupvisorsCommonStateModes(HashMap info) {
60+
this.identifier = (String) info.get("identifier");
61+
this.nick_identifier = (String) info.get("nick_identifier");
62+
this.now_monotonic = (Double) info.get("now_monotonic");
63+
this.fsm_statename = SupvisorsState.valueOf((String) info.get("fsm_statename"));
64+
this.master_identifier = (String) info.get("master_identifier");
65+
this.degraded_mode = (Boolean) info.get("degraded_mode");
66+
this.discovery_mode = (Boolean) info.get("discovery_mode");
67+
// no safe way to convert an Object to HashMap
68+
this.instance_states = (HashMap<String, SupvisorsInstanceState>) info.get("instance_states");
69+
}
70+
71+
/**
72+
* The getName method uses the getIdentifier method.
73+
*
74+
* @return String: The identifier of the Supvisors instance.
75+
*/
76+
public String getName() {
77+
return this.getIdentifier();
78+
}
79+
80+
/**
81+
* The getIdentifier method returns the identifier of the Supvisors instance.
82+
*
83+
* @return String: The identifier of the Supvisors instance.
84+
*/
85+
public String getIdentifier() {
86+
return this.identifier;
87+
}
88+
89+
/**
90+
* The getNickIdentifier method returns the nickname of the Supervisor instance.
91+
*
92+
* @return String: The nickname of the Supervisor instance.
93+
*/
94+
public String getNickIdentifier() {
95+
return this.nick_identifier;
96+
}
97+
98+
/**
99+
* The getSupvisorsIdentifier method returns the identification of the Supvisors instance,
100+
* as a SupvisorsIdentifier instance.
101+
*
102+
* @return SupvisorsIdentifier: a SupvisorsIdentifier instance.
103+
*/
104+
public SupvisorsIdentifier getSupvisorsIdentifier() {
105+
return new SupvisorsIdentifier(this.identifier, this.nick_identifier);
106+
}
107+
108+
/**
109+
* The getNowMonotonic method returns the monotonic time of the event.
110+
*
111+
* @return Double: The number of seconds since the local node startup.
112+
*/
113+
public Double getNowMonotonic() {
114+
return this.now_monotonic;
115+
}
116+
117+
/**
118+
* The getState method returns the state of Supvisors.
119+
*
120+
* @return SupvisorsState: The state of Supvisors.
121+
*/
122+
public SupvisorsState getState() {
123+
return this.fsm_statename;
124+
}
125+
126+
/**
127+
* The inDegradedMode method returns True if the Supvisors instance is in degraded mode.
128+
*
129+
* @return Boolean: The degraded mode status.
130+
*/
131+
public Boolean inDegradedMode() {
132+
return this.degraded_mode;
133+
}
134+
135+
/**
136+
* The inDiscoveryMode method returns True if the Supvisors instance is in discovery mode.
137+
*
138+
* @return Boolean: The discovery mode status.
139+
*/
140+
public Boolean inDiscoveryMode() {
141+
return this.discovery_mode;
142+
}
143+
144+
/**
145+
* The getInstanceStates method returns all Supvisors instance states per identifier.
146+
*
147+
* @return HashMap<String, SupvisorsInstanceState>: The Supvisors instances states.
148+
*/
149+
public HashMap<String, SupvisorsInstanceState> getInstanceStates() {
150+
return this.instance_states;
151+
}
152+
153+
/**
154+
* The toString method returns a printable form of the SupvisorsStatus instance.
155+
*
156+
* @return String: The contents of the SupvisorsStatus.
157+
*/
158+
public String toString() {
159+
return "identifier=" + this.identifier
160+
+ " nickIdentifier=" + this.nick_identifier
161+
+ " nowMonotonic=" + this.now_monotonic
162+
+ " state=" + this.fsm_statename
163+
+ " degradedMode=" + this.degraded_mode
164+
+ " discoveryMode=" + this.discovery_mode
165+
+ " instance_states=" + this.instance_states;
166+
}
167+
168+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2025 Julien LE CLEACH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.supvisors.common;
18+
19+
20+
/**
21+
* The SupvisorsFailureStrategies enumeration.
22+
*/
23+
public enum SupvisorsFailureStrategies {
24+
CONTINUE(0),
25+
RESYNC(1),
26+
SHUTDOWN(2);
27+
28+
/** The strategy code. */
29+
private int strategyCode;
30+
31+
/** The constructor links the state code to the state name. */
32+
private SupvisorsFailureStrategies(final int strategyCode) {
33+
this.strategyCode = strategyCode;
34+
}
35+
}

supvisors/client/java/org/supvisors/common/SupvisorsHostStatistics.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public IOBytes(float recvBytes, float sentBytes) {
5656
/** The identifier of the Supvisors instance. */
5757
private String identifier;
5858

59+
/** The monotonic time of the message, in the local reference time. */
60+
private Double now_monotonic;
61+
5962
/** The configured integration period. */
6063
private Float target_period;
6164

@@ -86,6 +89,7 @@ public IOBytes(float recvBytes, float sentBytes) {
8689
@SuppressWarnings({"unchecked"})
8790
public SupvisorsHostStatistics(HashMap statsInfo) {
8891
this.identifier = (String) statsInfo.get("identifier");
92+
this.now_monotonic = (Double) statsInfo.get("now_monotonic");
8993
this.target_period = (Float) statsInfo.get("target_period");
9094
this.period = DataConversion.arrayToFloatList((Object[]) statsInfo.get("period"));
9195
this.cpu = DataConversion.arrayToFloatList((Object[]) statsInfo.get("cpu"));
@@ -104,6 +108,15 @@ public String getIdentifier() {
104108
return this.identifier;
105109
}
106110

111+
/**
112+
* The getNowMonotonic method returns the monotonic time of the event.
113+
*
114+
* @return Double: The number of seconds since the local node startup.
115+
*/
116+
public Double getNowMonotonic() {
117+
return this.now_monotonic;
118+
}
119+
107120
/**
108121
* The getTargetPeriod method returns the configured integration period.
109122
*
@@ -215,6 +228,7 @@ IOBytes getInterfaceBytes(final String interfaceName) {
215228
public String toString() {
216229
return "SupvisorsHostStatistics("
217230
+ "identifier=" + this.identifier
231+
+ " nowMonotonic=" + this.now_monotonic
218232
+ " target_period=" + this.target_period
219233
+ " startPeriod=" + this.getStartPeriod()
220234
+ " endPeriod=" + this.getEndPeriod()

0 commit comments

Comments
 (0)