diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-04-19 22:31:01 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-04-19 22:31:01 +0300 |
commit | f11a8ecd409f280759af7227db52b1e87e389092 (patch) | |
tree | 191dc9e4dda2444fb65bcf097056ef37d5a685bc /ick2/projectapi.py | |
parent | 04e899ded340bc0fd3afd6b0a62dff22c182e735 (diff) | |
download | ick2-f11a8ecd409f280759af7227db52b1e87e389092.tar.gz |
Change: trigger a project, build all pipelines in the project
Diffstat (limited to 'ick2/projectapi.py')
-rw-r--r-- | ick2/projectapi.py | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/ick2/projectapi.py b/ick2/projectapi.py index 9548c38..d689b4a 100644 --- a/ick2/projectapi.py +++ b/ick2/projectapi.py @@ -20,7 +20,7 @@ class ProjectAPI(ick2.ResourceApiBase): def __init__(self, state): super().__init__('projects', state) - self._pi = ick2.PipelineInstances(self.get_state()) + self._ps = ick2.ProjectStatus(self.get_state()) def mangle_new_resource(self, resource): new = dict(resource) @@ -37,47 +37,44 @@ class ProjectAPI(ick2.ResourceApiBase): return resource['project'] def get_routes(self, path): # pragma: no cover - return super().get_routes(path) + self.get_pipeline_routes(path) + return super().get_routes(path) + self.get_status_routes(path) - def get_pipeline_routes(self, path): # pragma: no cover - pipeline_path = '{}/<project>/pipelines/<pipeline>'.format(path) + def get_status_routes(self, path): # pragma: no cover + status_path = '{}/<project>/status'.format(path) + trigger_path = '{}/<project>/+trigger'.format(path) return [ { 'method': 'GET', - 'path': pipeline_path, - 'callback': self.GET(self.get_pipeline), + 'path': status_path, + 'callback': self.GET(self.get_status), }, { 'method': 'PUT', - 'path': pipeline_path, - 'callback': self.PUT(self.set_pipeline_callback), + 'path': status_path, + 'callback': self.PUT(self.set_status_callback), }, { 'needs-authorization': False, 'method': 'GET', - 'path': pipeline_path + '/+trigger', - 'callback': self.GET(self.trigger_pipeline), + 'path': trigger_path, + 'callback': self.GET(self.trigger_project), }, ] - def get_pipeline(self, project, pipeline, **kwargs): - p = self._state.get_resource(self._type_name, project) - if pipeline not in p['pipelines']: - raise ick2.NotFound() - - pl = self._pi.get_instance(project, pipeline) + def get_status(self, project, **kwargs): + _ = self._state.get_resource(self._type_name, project) + ps = self._ps.get_instance(project) return { - 'status': pl.get('status', 'idle'), + 'status': ps.get('status', 'idle'), } - def set_pipeline_callback( - self, body, project, pipeline, **kwargs): # pragma: no cover - return self.set_pipeline(body['status'], project, pipeline) + def set_status_callback(self, body, project, **kwargs): # pragma: no cover + return self.set_status(project, body['status']) - def set_pipeline(self, status, project, pipeline): + def set_status(self, project, status): ick2.log.log( - 'trace', msg_text='Setting pipeline status', - project=project, pipeline=pipeline, status=status) + 'trace', msg_text='Setting project status', + project=project, status=status) allowed_changes = { 'idle': 'triggered', @@ -86,22 +83,17 @@ class ProjectAPI(ick2.ResourceApiBase): } p = self._state.get_resource(self._type_name, project) - if pipeline not in p['pipelines']: - ick2.log.log( - 'error', msg_text='Project not found', project=project) - raise ick2.NotFound() ick2.log.log('trace', msg_text='Found project', project=p) - pl = self._pi.get_instance(project, pipeline) - old_status = pl.get('status', 'idle') + ps = self._ps.get_instance(project) + old_status = ps.get('status', 'idle') if allowed_changes[old_status] != status: - raise ick2.WrongPipelineStatus(status) - pl['status'] = status - self._pi.update_instance(project, pipeline, pl) + raise ick2.WrongProjectStatus(status) + ps['status'] = status + self._ps.update_instance(project, ps) return {'status': status} # This needs to go away as it is not protected. Once an IDP is # added. - def trigger_pipeline( - self, project, pipeline, **kwargs): # pragma: no cover - return self.set_pipeline('triggered', project, pipeline) + def trigger_project(self, project, **kwargs): # pragma: no cover + return self.set_status(project, 'triggered') |