summaryrefslogtreecommitdiff
path: root/ick2/projectapi.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-12-15 17:57:35 +0200
committerLars Wirzenius <liw@liw.fi>2017-12-15 17:57:35 +0200
commit8f48a41b221df9b872502ff8f2aca0487e127cb7 (patch)
tree5022d3679a411a7328966be0feb56b53cbba5380 /ick2/projectapi.py
parent4d43122dbf0deb7a143008a1d9ec447392bc17ac (diff)
downloadick2-8f48a41b221df9b872502ff8f2aca0487e127cb7.tar.gz
Refactor: use PipelineInstance in projectapi.py
Diffstat (limited to 'ick2/projectapi.py')
-rw-r--r--ick2/projectapi.py23
1 files changed, 4 insertions, 19 deletions
diff --git a/ick2/projectapi.py b/ick2/projectapi.py
index f46fe14..6952d6d 100644
--- a/ick2/projectapi.py
+++ b/ick2/projectapi.py
@@ -20,6 +20,7 @@ class ProjectAPI(ick2.ResourceApiBase):
def __init__(self, state):
super().__init__('projects', state)
+ self._pi = ick2.PipelineInstances(self.get_state())
def get_resource_name(self, resource):
return resource['project']
@@ -53,18 +54,11 @@ class ProjectAPI(ick2.ResourceApiBase):
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 = {}
+ pl = self._pi.get_instance(project, pipeline)
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)
@@ -87,21 +81,12 @@ class ProjectAPI(ick2.ResourceApiBase):
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)
-
+ pl = self._pi.get_instance(project, pipeline)
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)
+ self._pi.update_instance(project, pipeline, pl)
return {'status': status}
# This needs to go away as it is not protected. Once an IDP is