summaryrefslogtreecommitdiff
path: root/ick2/projectapi.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-26 16:41:33 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-26 17:59:59 +0100
commit964e646b2c26bcb007390dc6af625835f98887ec (patch)
treeae7ea88c5894ad71167959ed82d81b984f78b5e7 /ick2/projectapi.py
parentf0ccb8150a67b10e11b3358d6385e31619e6d1e3 (diff)
downloadick2-964e646b2c26bcb007390dc6af625835f98887ec.tar.gz
Update: project and work apis to handle named pipelines
Diffstat (limited to 'ick2/projectapi.py')
-rw-r--r--ick2/projectapi.py58
1 files changed, 42 insertions, 16 deletions
diff --git a/ick2/projectapi.py b/ick2/projectapi.py
index b0c9da1..f46fe14 100644
--- a/ick2/projectapi.py
+++ b/ick2/projectapi.py
@@ -50,33 +50,59 @@ class ProjectAPI(ick2.ResourceApiBase):
def get_pipeline(self, project, pipeline, **kwargs):
p = self._state.get_resource(self._type_name, project)
- for pl in p['pipelines']:
- if pl['name'] == pipeline:
- return {
- 'status': pl.get('status', 'idle'),
- }
- raise ick2.NotFound()
+ if pipeline not in p['pipelines']:
+ raise ick2.NotFound()
+
+ pp = self._pipeline_instance_name(project, pipeline)
+ try:
+ pl = self._state.get_resource('pipeline_instances', pp)
+ except ick2.NotFound:
+ pl = {}
+ return {
+ 'status': pl.get('status', 'idle'),
+ }
+
+ def _pipeline_instance_name(self, project_name, pipeline_name):
+ return '{} {}'.format(project_name, pipeline_name)
def set_pipeline_callback(
self, body, project, pipeline, **kwargs): # pragma: no cover
return self.set_pipeline(body['status'], project, pipeline)
- def set_pipeline(self, state, project, pipeline):
+ def set_pipeline(self, status, project, pipeline):
+ ick2.log.log(
+ 'trace', msg_text='Setting pipeline status',
+ project=project, pipeline=pipeline, status=status)
+
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()
+ 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)
+
+ pp = self._pipeline_instance_name(project, pipeline)
+ try:
+ pl = self._state.get_resource('pipeline_instances', pp)
+ except ick2.NotFound:
+ pl = {
+ 'name': pipeline,
+ 'status': 'idle',
+ }
+ self._state.add_resource('pipeline_instances', pp, pl)
+
+ old_status = pl.get('status', 'idle')
+ if allowed_changes[old_status] != status:
+ raise ick2.WrongPipelineStatus(status)
+ pl['status'] = status
+ self._state.update_resource('pipeline_instances', pp, pl)
+ return {'status': status}
# This needs to go away as it is not protected. Once an IDP is
# added.