summaryrefslogtreecommitdiff
path: root/ick2/controllerapi.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-05 16:15:19 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-05 16:15:19 +0100
commiteb17e187d100b500bd2575e362ea72f657699aa8 (patch)
tree7ff62a49484cc6625d872a94dcfb3db6d46b8cdc /ick2/controllerapi.py
parent9f64f6d8d229fff98e51532a1a8ee1032416af10 (diff)
downloadick2-eb17e187d100b500bd2575e362ea72f657699aa8.tar.gz
Add: PUT to update pipeline state
Diffstat (limited to 'ick2/controllerapi.py')
-rw-r--r--ick2/controllerapi.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py
index 4f2872b..91368c1 100644
--- a/ick2/controllerapi.py
+++ b/ick2/controllerapi.py
@@ -113,7 +113,16 @@ class APIbase: # pragma: no cover
content_type=content_type, body=body)
if 'raw_uri_path' in kwargs:
del kwargs['raw_uri_path']
- body = callback(body, **kwargs)
+ try:
+ body = callback(body, **kwargs)
+ except ick2.NotFound as e:
+ return not_found(e)
+ except ick2.WrongPipelineStatus as e:
+ ick2.log.log(
+ 'error',
+ msg_text='Wrong state for pipeline',
+ exception=str(e))
+ return bad_request(e)
ick2.log.log('trace', msg_text='returned body', body=repr(body))
return OK(body)
return wrapper
@@ -239,6 +248,11 @@ class ProjectAPI(ResourceApiBase):
'callback': self.GET(self.get_pipeline),
},
{
+ 'method': 'PUT',
+ 'path': pipeline_path,
+ 'callback': self.PUT(self.set_pipeline_callback),
+ },
+ {
'method': 'GET',
'path': builds_path,
'callback': self.GET(self.get_builds),
@@ -254,6 +268,27 @@ class ProjectAPI(ResourceApiBase):
}
raise ick2.NotFound()
+ def set_pipeline_callback(
+ self, body, project, pipeline): # pragma: no cover
+ return self.set_pipeline(body['status'], project, pipeline)
+
+ def set_pipeline(self, state, project, pipeline):
+ allowed_changes = {
+ 'idle': 'triggered',
+ 'triggered': 'building',
+ 'building': 'idle',
+ }
+ p = self._state.get_resource(self._type_name, project)
+ for pl in p['pipelines']:
+ if pl['name'] == pipeline:
+ old_state = pl.get('status', 'idle')
+ if allowed_changes[old_state] != state:
+ raise ick2.WrongPipelineStatus(state)
+ pl['status'] = state
+ self._state.update_resource(self._type_name, project, p)
+ return {'status': state}
+ raise ick2.NotFound()
+
def get_builds(self, project):
p = self._state.get_resource(self._type_name, project)
return {
@@ -285,6 +320,13 @@ def not_found(error): # pragma: no cover
return response(apifw.HTTP_NOT_FOUND, str(error), headers)
+def bad_request(error): # pragma: no cover
+ headers = {
+ 'Content-Type': 'text/plain',
+ }
+ return response(apifw.HTTP_BAD_REQUEST, str(error), headers)
+
+
def created(body): # pragma: no cover
headers = {
'Content-Type': 'application/json',