Skip to content

Commit

Permalink
rework internal com based on XML-RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
julien6387 committed Apr 18, 2024
1 parent 2b618d0 commit 154c7ac
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 108 deletions.
3 changes: 1 addition & 2 deletions docs/xml_rpc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Status
'port' ``int`` The HTTP port of the |Supvisors| instance.
'statecode' ``int`` The |Supvisors| instance state, in [0;6].
'statename' ``str`` The |Supvisors| instance state as string, in [``'UNKNOWN'``, ``'CHECKING'``,
`'CHECKED'``, ``'RUNNING'``, ``'SILENT'``, ``'FAILED'``, ``'ISOLATED'``].
`'CHECKED'``, ``'RUNNING'``, ``'SILENT'``, ``'ISOLATED'``].
'discovery_mode' ``bool`` True if the discovery mode is activated in the |Supvisors| instance.
'remote_sequence_counter' ``int`` The remote TICK counter, i.e. the number of TICK events received since
the remote |Supvisors| instance is running.
Expand All @@ -87,7 +87,6 @@ Status
|Supvisors| instance, in seconds and in the local reference time.
'loading' ``int`` The sum of the expected loading of the processes running on the |Supvisors|
instance, in [0;100]%.
'rpc_failure' ``bool`` True upon failure of the XML-RPC towards the |Supvisors| instance.
'process_failure' ``bool`` True if one of the local processes has crashed or has exited unexpectedly.
'fsm_statecode' ``int`` The |Supvisors| state as seen by the |Supvisors| instance, in [0;9].
'fsm_statename' ``str`` The |Supvisors| state as string, in [``'OFF'``, ``'INITIALIZATION'``,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,20 @@ public class SupvisorsInstanceInfo implements SupvisorsAnyInfo {
*/
private Integer loading;

/** True if the XML-RPC towards the Supervisor instance are in failure. */
private Boolean rpc_failure;

/** 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 */
/** The instance state. */
private SupvisorsState fsm_statename;

/** The instance discovery mode. */
private Boolean discovery_mode;

/** True if the Supvisors instance has starting jobs in progress. */
private Boolean starting_jobs;

/** True if the Supvisors instance has stopping jobs in progress. */
private Boolean stopping_jobs;

/**
* This constructor gets all information from an HashMap.
Expand All @@ -94,8 +101,11 @@ public SupvisorsInstanceInfo(HashMap instanceInfo) {
this.local_mtime = (Double) instanceInfo.get("local_mtime");
this.local_time = (Integer) instanceInfo.get("local_time");
this.loading = (Integer) instanceInfo.get("loading");
this.rpc_failure = (Boolean) instanceInfo.get("rpc_failure");
this.process_failure = (Boolean) instanceInfo.get("process_failure");
this.fsm_statename = SupvisorsState.valueOf((String) stateInfo.get("fsm_statename"));
this.discovery_mode = (Boolean) stateInfo.get("discovery_mode");
this.starting_jobs = (Boolean) stateInfo.get("starting_jobs");
this.stopping_jobs = (Boolean) stateInfo.get("stopping_jobs");
}

/**
Expand Down Expand Up @@ -159,7 +169,7 @@ public Boolean inDiscoveryMode() {
*
* @return Integer: The number of TICK events received.
*/
public Integer getRemoteSequenceCounter() {
public Integer getRemoteSequenceCounter() {
return this.remote_sequence_counter;
}

Expand Down Expand Up @@ -189,7 +199,7 @@ public Integer getRemoteTime() {
*
* @return Integer: The number of TICK events received.
*/
public Integer getLocalSequenceCounter() {
public Integer getLocalSequenceCounter() {
return this.local_sequence_counter;
}

Expand All @@ -199,7 +209,7 @@ public Integer getLocalSequenceCounter() {
*
* @return Double: The number of seconds since the local node startup.
*/
public Double getLocalMonotonicTime() {
public Double getLocalMonotonicTime() {
return this.local_mtime;
}

Expand All @@ -208,7 +218,7 @@ public Double getLocalMonotonicTime() {
*
* @return Integer: The number of seconds since Epoch.
*/
public Integer getLocalTime() {
public Integer getLocalTime() {
return this.local_time;
}

Expand All @@ -222,21 +232,48 @@ public Integer getLoading() {
}

/**
* The hasRpcFailure method returns True if the XML-RPC towards the Supervisor instance fail.
* The hasProcessFailure method returns True if any process is in FATAL or unexpected EXITED state.
*
* @return Boolean: The XML-RPC failure status.
* @return Boolean: The process failure status.
*/
public Boolean hasRpcFailure() {
return this.rpc_failure;
public Boolean hasProcessFailure() {
return this.process_failure;
}

/**
* The hasProcessFailure method returns True if any process is in FATAL or unexpected EXITED state.
* The getSupvisorsState method returns the state of Supvisors.
*
* @return Boolean: The process failure status.
* @return SupvisorsState: The state of Supvisors.
*/
public Boolean hasProcessFailure() {
return this.process_failure;
public SupvisorsState getSupvisorsState() {
return this.fsm_statename;
}

/**
* 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 hasStartingJobs method returns True if the Supvisors instance has jobs in progress in its Starter.
*
* @return Boolean: The starting jobs progress.
*/
public Boolean hasStartingJobs() {
return this.starting_jobs;
}

/**
* The hasStoppingJobs method returns True if the Supvisors instance has jobs in progress in its Stopper.
*
* @return Boolean: The stopping jobs progress.
*/
public Boolean hasStoppingJobs() {
return this.stopping_jobs;
}

/**
Expand All @@ -258,8 +295,11 @@ public String toString() {
+ " localMonotonicTime=" + this.local_mtime
+ " localTime=\"" + sdf.format(new Date(this.local_time * 1000L)) + "\""
+ " loading=" + this.loading
+ " rpcFailure=" + this.rpc_failure
+ " processFailure=" + this.process_failure + ")";
+ " processFailure=" + this.process_failure
+ " supvisorsState=" + this.fsm_statename
+ " discoveryMode=" + this.discovery_mode
+ " startingJobs=" + this.starting_jobs
+ " stoppingJobs=" + this.stopping_jobs + ")";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
* The SupvisorsInstanceState enumeration.
*
* UNKNOWN: used at initialization, before any heartbeat message is received from this Supvisors instance.
* CHECKING: used when the local Supvisors checks the isolation status of this Supvisors instance.
* RUNNING: used when the local Supvisors receives heartbeat messages from this Supvisors instance.
* CHECKING: used when the local Supvisors is checking the status of the remote Supvisors instance.
* CHECKED: used when the local Supvisors has checked the status of the remote Supvisors instance.
* RUNNING: used when the local Supvisors is ready to work with the remote Supvisors instance.
* SILENT: used when the local Supvisors does not receive any heartbeat message from this Supvisors instance.
* ISOLATING: used when the local Supvisors is about to disconnect this Supvisors instance.
* ISOLATED: used when the local Supvisors has actually disconnected this Supvisors instance.
*/
public enum SupvisorsInstanceState {
UNKNOWN(0),
CHECKING(1),
RUNNING(2),
SILENT(3),
ISOLATING(4),
ISOLATED(5);
CHECKED(2),
RUNNING(3),
SILENT(4),
ISOLATED(5;

/** The state code. */
private final int state;
Expand Down
43 changes: 43 additions & 0 deletions supvisors/client/java/org/supvisors/common/SupvisorsState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2016 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 State enumeration for Supvisors.
*
* INITIALIZATION is used when Supvisors is synchronizing with all other Supvisors instances.
* DEPLOYMENT is used when Supvisors is starting applications automatically.
* OPERATION is used when Supvisors is working normally.
* CONCILIATION is used when Supvisors is conciliating conflicts due to multiple instance of the same process.
*/
public enum SupvisorsState {
INITIALIZATION(0),
DEPLOYMENT(1),
OPERATION(2),
CONCILIATION(3),
RESTARTING(4),
SHUTTING_DOWN(5),
FINAL(7);

/** The state code. */
private int stateCode;

/** The constructor links the state code to the state name. */
private State(final int stateCode) {
this.stateCode = stateCode;
}
}
37 changes: 5 additions & 32 deletions supvisors/client/java/org/supvisors/common/SupvisorsStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,8 @@
*/
public class SupvisorsStatus {

/**
* The State enumeration for Supvisors.
*
* INITIALIZATION is used when Supvisors is synchronizing with all other Supvisors instances.
* DEPLOYMENT is used when Supvisors is starting applications automatically.
* OPERATION is used when Supvisors is working normally.
* CONCILIATION is used when Supvisors is conciliating conflicts due to multiple instance of the same process.
*/
public enum State {
INITIALIZATION(0),
DEPLOYMENT(1),
OPERATION(2),
CONCILIATION(3),
RESTARTING(4),
RESTART(5),
SHUTTING_DOWN(6),
SHUTDOWN(7);

/** The state code. */
private int stateCode;

/** The constructor links the state code to the state name. */
private State(final int stateCode) {
this.stateCode = stateCode;
}
}

/** The Supvisors state. */
private State fsm_statename;
private SupvisorsState fsm_statename;

/** The instance discovery mode. */
private Boolean discovery_mode;
Expand All @@ -73,7 +46,7 @@ private State(final int stateCode) {
* @param HashMap stateInfo: The untyped structure got from the XML-RPC.
*/
public SupvisorsStatus(HashMap stateInfo) {
this.fsm_statename = State.valueOf((String) stateInfo.get("fsm_statename"));
this.fsm_statename = SupvisorsState.valueOf((String) stateInfo.get("fsm_statename"));
this.discovery_mode = (Boolean) stateInfo.get("discovery_mode");
Object[] startingJobs = (Object[]) stateInfo.get("starting_jobs");
this.starting_jobs = Arrays.asList(startingJobs);
Expand All @@ -82,11 +55,11 @@ public SupvisorsStatus(HashMap stateInfo) {
}

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

Expand Down
14 changes: 0 additions & 14 deletions supvisors/instancestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ def __init__(self, supvisors_id: SupvisorsInstanceId, supvisors: Any):
self._state: SupvisorsInstanceStates = SupvisorsInstanceStates.UNKNOWN
self.times: SupvisorsTimes = SupvisorsTimes(self.identifier, self.logger)
self.processes: Dict[str, ProcessStatus] = {}
self._rpc_failure: bool = False
# state and modes
self.state_modes = StateModes()
# the local instance may use the process statistics collector
Expand Down Expand Up @@ -298,18 +297,6 @@ def isolated(self) -> bool:
""" Return True if the Supvisors instance is isolated. """
return self.state == SupvisorsInstanceStates.ISOLATED

@property
def rpc_failure(self) -> bool:
""" Property getter for the 'rpc_failure' attribute. """
return self._rpc_failure

@rpc_failure.setter
def rpc_failure(self, failure: bool) -> None:
""" Property setter for the 'rpc_failure' attribute. """
if self._rpc_failure != failure:
self._rpc_failure = failure
# TODO: export status ?

@property
def sequence_counter(self):
""" the remote sequence counter will be used as a reference outside of this class. """
Expand All @@ -323,7 +310,6 @@ def serial(self) -> Payload:
'port': self.supvisors_id.http_port,
'statecode': self.state.value, 'statename': self.state.name,
'loading': self.get_load(),
'rpc_failure': self.rpc_failure,
'process_failure': self.has_error()}
payload.update(self.times.serial())
payload.update(self.state_modes.serial())
Expand Down
5 changes: 2 additions & 3 deletions supvisors/supvisorsctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ def do_instance_status(self, arg):
max_node_names = ControllerPlugin.max_template(info_list, 'node_name', 'Node')
template = (f'%(identifier)-{max_identifiers}s%(node_name)-{max_node_names}s%(port)-7s'
'%(state)-11s%(discovery)-11s%(load)-6s%(ltime)-10s%(counter)-9s'
'%(rpc_failure)-9s%(proc_failure)-11s'
'%(proc_failure)-11s'
f'%(fsm_state)-16s%(discovery)-11s%(master)-{max_node_names}s'
'%(starting)-10s%(stopping)-10s')
# print title
payload = {'identifier': 'Supervisor', 'node_name': 'Node', 'port': 'Port',
'state': 'State', 'discovery': 'Discovery',
'load': 'Load', 'ltime': 'Time', 'counter': 'Counter',
'rpc_failure': 'XML-RPC', 'proc_failure': 'Processes',
'proc_failure': 'Processes',
'fsm_state': 'FSM', 'master': 'Master',
'starting': 'Starting', 'stopping': 'Stopping'}
self.ctl.output(template % payload)
Expand All @@ -218,7 +218,6 @@ def do_instance_status(self, arg):
'load': f"{info['loading']}%",
'ltime': simple_localtime(info['local_time']),
'counter': info['remote_sequence_counter'],
'rpc_failure': 'error' if info['rpc_failure'] else 'ok',
'proc_failure': 'error' if info['process_failure'] else 'ok',
'fsm_state': info['fsm_statename'],
'master': info['master_identifier'],
Expand Down
Loading

0 comments on commit 154c7ac

Please sign in to comment.