summaryrefslogtreecommitdiff
path: root/distbuild/initiator.py
diff options
context:
space:
mode:
Diffstat (limited to 'distbuild/initiator.py')
-rw-r--r--distbuild/initiator.py120
1 files changed, 116 insertions, 4 deletions
diff --git a/distbuild/initiator.py b/distbuild/initiator.py
index 332d54a1..40b56a9d 100644
--- a/distbuild/initiator.py
+++ b/distbuild/initiator.py
@@ -31,6 +31,11 @@ class _Finished(object):
self.msg = msg
+class _Cancelled(object):
+
+ pass
+
+
class _Failed(object):
def __init__(self, msg):
@@ -69,6 +74,7 @@ class Initiator(distbuild.StateMachine):
self._partial = True
self._step_outputs = {}
self.debug_transitions = False
+ self.allow_detach = False
# The build-log output dir is set up in _open_output() when we
# receive the first log message. Thus if we never get that far, we
@@ -88,6 +94,7 @@ class Initiator(distbuild.StateMachine):
('waiting', self._jm, distbuild.JsonNewMessage, 'waiting',
self._handle_json_message),
('waiting', self, _Finished, None, self._succeed),
+ ('waiting', self, _Cancelled, None, self._cancel),
('waiting', self, _Failed, None, self._fail),
]
self.add_transitions(spec)
@@ -107,7 +114,8 @@ class Initiator(distbuild.StateMachine):
original_ref=self._original_ref,
component_names=self._component_names,
partial=self._partial,
- protocol_version=distbuild.protocol.VERSION
+ protocol_version=distbuild.protocol.VERSION,
+ allow_detach=self.allow_detach,
)
self._jm.send(msg)
logging.debug('Initiator: sent to controller: %s', repr(msg))
@@ -118,8 +126,10 @@ class Initiator(distbuild.StateMachine):
logging.debug('Initiator: from controller: %s' % repr(event.msg))
handlers = {
+ 'build-started': lambda msg: None,
'build-finished': self._handle_build_finished_message,
'build-failed': self._handle_build_failed_message,
+ 'build-cancelled': self._handle_build_cancelled_message,
'build-progress': self._handle_build_progress_message,
'step-started': self._handle_step_started_message,
'step-already-started': self._handle_step_already_started_message,
@@ -127,13 +137,17 @@ class Initiator(distbuild.StateMachine):
'step-finished': self._handle_step_finished_message,
'step-failed': self._handle_step_failed_message,
}
-
+
handler = handlers[event.msg['type']]
handler(event.msg)
def _handle_build_finished_message(self, msg):
self.mainloop.queue_event(self, _Finished(msg))
+ # TODO: def _handle_build_cancelled_message(self, who):
+ def _handle_build_cancelled_message(self, msg):
+ self.mainloop.queue_event(self, _Cancelled())
+
def _handle_build_failed_message(self, msg):
self.mainloop.queue_event(self, _Failed(msg))
@@ -224,7 +238,7 @@ class Initiator(distbuild.StateMachine):
self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
self._jm.close()
logging.info('Build finished OK')
-
+
urls = event.msg['urls']
if urls:
for url in urls:
@@ -233,6 +247,12 @@ class Initiator(distbuild.StateMachine):
self._app.status(
msg='Controller did not give us any artifact URLs.')
+ def _cancel(self, event_source, event):
+ self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
+ self._jm.close()
+
+ self._app.status(msg='Build was cancelled')
+
def _fail(self, event_source, event):
self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
self._jm.close()
@@ -257,6 +277,98 @@ class Initiator(distbuild.StateMachine):
self._step_outputs = {}
+class InitiatorStart(Initiator):
+
+ def __init__(self, cm, conn, app, repo_name, ref, morphology,
+ original_ref, component_names):
+ super(InitiatorStart, self).__init__(cm, conn, app, repo_name, ref,
+ morphology, original_ref,
+ component_names)
+ self._step_outputs = {}
+ self.debug_transitions = False
+ self.allow_detach = True
+
+ def _handle_json_message(self, event_source, event):
+ distbuild.crash_point()
+
+ logging.debug('Initiator: from controller: %s' % repr(event.msg))
+
+ handlers = {
+ 'build-started': self._handle_build_started_message,
+ 'build-finished': self._handle_build_finished_message,
+ 'build-failed': self._handle_build_failed_message,
+ 'build-cancelled': self._handle_build_cancelled_message,
+ 'build-progress': self._handle_build_progress_message,
+ }
+
+ msg_type = event.msg['type']
+
+ if msg_type in handlers:
+ handler = handlers[msg_type]
+ handler(event.msg)
+
+ def _handle_build_started_message(self, msg):
+ self._app.status(msg='Detaching distbuild from controller (build'
+ ' will continue on the distbuild network): '
+ 'build request ID: %s' % msg['id'])
+
+ self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
+ self._jm.close()
+
+class InitiatorCancel(distbuild.StateMachine):
+
+ def __init__(self, cm, conn, app, job_id):
+ distbuild.StateMachine.__init__(self, 'waiting')
+ self._cm = cm
+ self._conn = conn
+ self._app = app
+ self._job_id = job_id
+
+ def setup(self):
+ distbuild.crash_point()
+
+ self._jm = distbuild.JsonMachine(self._conn)
+ self.mainloop.add_state_machine(self._jm)
+ logging.debug('initiator: _jm=%s' % repr(self._jm))
+
+ spec = [
+ # state, source, event_class, new_state, callback
+ ('waiting', self._jm, distbuild.JsonEof, None, self._terminate),
+ ('waiting', self._jm, distbuild.JsonNewMessage, None,
+ self._handle_json_message),
+ ]
+ self.add_transitions(spec)
+
+ self._app.status(msg='Sending cancel request for distbuild job.')
+ msg = distbuild.message('build-cancel',
+ id=self._job_id,
+ protocol_version=distbuild.protocol.VERSION,
+ )
+ self._jm.send(msg)
+ logging.debug('Initiator: sent to controller: %s', repr(msg))
+
+ def _handle_json_message(self, event_source, event):
+ distbuild.crash_point()
+
+ logging.debug('Initiator: from controller: %s', str(event.msg))
+
+ handlers = {
+ 'request-output': self._handle_request_output,
+ }
+
+ handler = handlers[event.msg['type']]
+ handler(event.msg)
+
+ def _handle_request_output(self, msg):
+ self._app.status(msg=str(msg['message']))
+ self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
+ self._jm.close()
+
+ def _terminate(self, event_source, event):
+ self.mainloop.queue_event(self._cm, distbuild.StopConnecting())
+ self._jm.close()
+
+
class InitiatorListJobs(distbuild.StateMachine):
def __init__(self, cm, conn, app):
@@ -285,7 +397,7 @@ class InitiatorListJobs(distbuild.StateMachine):
self._app.status(msg='Requesting currently running distbuilds.')
msg = distbuild.message('list-requests',
id=msg_uuid,
- protocol_version=distbuild.protocol.VERSION
+ protocol_version=distbuild.protocol.VERSION,
)
self._jm.send(msg)
logging.debug('Initiator: sent to controller: %s', repr(msg))