Skip to content

Commit

Permalink
repair JAVA client
Browse files Browse the repository at this point in the history
  • Loading branch information
julien6387 committed Apr 9, 2024
1 parent 1860527 commit 7a9a7b3
Show file tree
Hide file tree
Showing 18 changed files with 664 additions and 103 deletions.
2 changes: 1 addition & 1 deletion supvisors/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def serial(self) -> Payload:
'starting_strategy': self.starting_strategy.name,
'starting_failure_strategy': self.starting_failure_strategy.name,
'running_failure_strategy': self.running_failure_strategy.name,
'status_formula': self.status_formula}
'status_formula': self.status_formula or ''}
return payload
return {'managed': False}

Expand Down
3 changes: 3 additions & 0 deletions supvisors/client/java/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<path refid="project.classpath"/>
<pathelement path="lib/${supvisors.jar}"/>
</classpath>
<arg value="60000"/>
</java>
</target>

Expand All @@ -44,6 +45,7 @@
<path refid="project.classpath"/>
<pathelement path="lib/${supvisors.jar}"/>
</classpath>
<arg value="60000"/>
</java>
</target>

Expand All @@ -53,6 +55,7 @@
<path refid="project.classpath"/>
<pathelement path="lib/${supvisors.jar}"/>
</classpath>
<arg value="60000"/>
</java>
</target>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 2024 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;
import java.util.List;


/**
* The Class SupvisorsDistributionInfo.
*
* It gives a structured form to the process information received from a XML-RPC.
*/
public class SupvisorsDistributionInfo implements SupvisorsAnyInfo {

/** The name of the process' application. */
private String application_name;

/** The process name. */
private String process_name;

/** The predicted process state. */
private ProcessState state;

/** The reason of the starting failure if state is FATAL. */
private String forced_reason;

/** The identifiers of the Supvisors instances where the process is expected to run. */
private List<String> running_identifiers;

/**
* This constructor gets all information from an HashMap.
*
* @param HashMap processInfo: The untyped structure got from the XML-RPC.
*/
public SupvisorsDistributionInfo(HashMap processInfo) {
this.process_name = (String) processInfo.get("process_name");
this.application_name = (String) processInfo.get("application_name");
this.state = ProcessState.valueOf((String) processInfo.get("state"));
this.forced_reason = (String) processInfo.get("forced_reason");
this.running_identifiers = DataConversion.arrayToStringList((Object[]) processInfo.get("running_identifiers"));
}

/**
* The getApplicationName method returns the name of the process' application.
*
* @return String: The name of the application.
*/
public String getApplicationName() {
return this.application_name;
}

/**
* The getProcessName method returns the name of the process.
*
* @return String: The name of the process.
*/
public String getProcessName() {
return this.process_name;
}

/**
* The getName method returns the namespec of the process.
*
* @return String: The namespec of the process.
*/
public String getName() {
return DataConversion.stringsToNamespec(this.application_name, this.process_name);
}

/**
* The getState method returns the predicted state of the process.
*
* @return ProcessState: The predicted state of the process.
*/
public ProcessState getState() {
return this.state;
}

/**
* The getForcedReason method returns the reason of the expected starting failure in the event where the process
* cannot be started (state is expected to be FATAL).
*
* @return String: The reason of the failure.
*/
public String getForcedReason() {
return this.forced_reason;
}

/**
* The getRunningIdentifiers method returns the list of identifiers of the Supvisors instances
* where the process is expected to run (one identifier only expected, unless the process is already conflicting).
*
* @return List: The identifiers list of Supvisors instances.
*/
public List getRunningIdentifiers() {
return this.running_identifiers;
}

/**
* The toString method returns a printable form of the contents of the SupvisorsDistributionInfo instance.
*
* @return String: The contents of the SupvisorsDistributionInfo instance.
*/
public String toString() {
return "SupvisorsDistributionInfo(namespec=" + this.getName()
+ " applicationName=" + this.application_name
+ " processName=" + this.process_name
+ " state=" + this.state
+ " forcedReason=\"" + this.forced_reason + "\""
+ " runningIdentifiers=" + this.running_identifiers + ")";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* It gives a structured form to the Supvisors Instance information received from a XML-RPC.
*/

public class SupvisorsInstanceInfo implements SupvisorsAnyInfo {

/** The identifier of the Supvisors instance. */
Expand All @@ -47,7 +48,7 @@ public class SupvisorsInstanceInfo implements SupvisorsAnyInfo {
private Integer remote_sequence_counter;

/** The monotonic time of the last heartbeat message, as received. */
private Integer remote_mtime;
private Double remote_mtime;

/** The time of the last heartbeat message, as received. */
private Integer remote_time;
Expand All @@ -56,7 +57,7 @@ public class SupvisorsInstanceInfo implements SupvisorsAnyInfo {
private Integer local_sequence_counter;

/** The monotonic time of the last heartbeat message, in the local reference time. */
private Integer local_mtime;
private Double local_mtime;

/** The time of the last heartbeat message, in the local reference time. */
private Integer local_time;
Expand All @@ -70,6 +71,8 @@ public class SupvisorsInstanceInfo implements SupvisorsAnyInfo {
/** True if one of the local processes has crashed or has exited unexpectedly. */
private Boolean process_failure;

/** TODO: fsm_statename discovery_mode master_identifier starting_jobs stopping_jobs */

/**
* This constructor gets all information from an HashMap.
*
Expand All @@ -82,10 +85,10 @@ public SupvisorsInstanceInfo(HashMap instanceInfo) {
this.statename = SupvisorsInstanceState.valueOf((String) instanceInfo.get("statename"));
this.discovery_mode = (Boolean) instanceInfo.get("discovery_mode");
this.remote_sequence_counter = (Integer) instanceInfo.get("remote_sequence_counter");
this.remote_time = (Integer) instanceInfo.get("remote_mtime");
this.remote_mtime = (Double) instanceInfo.get("remote_mtime");
this.remote_time = (Integer) instanceInfo.get("remote_time");
this.remote_sequence_counter = (Integer) instanceInfo.get("local_sequence_counter");
this.local_time = (Integer) instanceInfo.get("local_mtime");
this.local_mtime = (Double) instanceInfo.get("local_mtime");
this.local_time = (Integer) instanceInfo.get("local_time");
this.loading = (Integer) instanceInfo.get("loading");
this.process_failure = (Boolean) instanceInfo.get("process_failure");
Expand Down Expand Up @@ -160,9 +163,9 @@ public Integer getRemoteSequenceCounter() {
* The getRemoteMonotonicTime method returns the monotonic time of the last heartbeat message,
* in the reference time of the remote node.
*
* @return Integer: The number of seconds since the remote node startup.
* @return Double: The number of seconds since the remote node startup.
*/
public Integer getRemoteMonotonicTime() {
public Double getRemoteMonotonicTime() {
return this.remote_mtime;
}

Expand Down Expand Up @@ -190,9 +193,9 @@ public Integer getLocalSequenceCounter() {
* The getLocalMonotonicTime method returns the monotonic time taken when the latest TICK was received
* from the remote node.
*
* @return Integer: The number of seconds since the local node startup.
* @return Double: The number of seconds since the local node startup.
*/
public Integer getLocalMonotonicTime() {
public Double getLocalMonotonicTime() {
return this.local_mtime;
}

Expand Down Expand Up @@ -235,11 +238,11 @@ public String toString() {
+ " port=" + this.port
+ " state=" + this.statename
+ " discoveryMode=" + this.discovery_mode
+ " remoteSequenceCounter=" + this.sequence_counter
+ " remoteMonotonicTime=\"" + this.remote_mtime + "\""
+ " remoteTime=\"" + sdf.format(new Date(this.local_time * 1000L)) + "\""
+ " remoteSequenceCounter=" + this.remote_sequence_counter
+ " remoteMonotonicTime=" + this.remote_mtime
+ " remoteTime=\"" + sdf.format(new Date(this.remote_time * 1000L)) + "\""
+ " localSequenceCounter=" + this.local_sequence_counter
+ " localMonotonicTime=\"" + this.local_mtime + "\""
+ " localMonotonicTime=" + this.local_mtime
+ " localTime=\"" + sdf.format(new Date(this.local_time * 1000L)) + "\""
+ " loading=" + this.loading
+ " processFailure=" + this.process_failure + ")";
Expand Down
Loading

0 comments on commit 7a9a7b3

Please sign in to comment.