summaryrefslogtreecommitdiff
path: root/ick2/controllerapi.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-06 12:02:03 +0100
committerLars Wirzenius <liw@liw.fi>2017-11-06 12:02:03 +0100
commit599e095cda626ff66c789017a752d7f91678d033 (patch)
tree24202f10b62992c5e0c1864c7e796e308b0a3cb8 /ick2/controllerapi.py
parent854bf88c1a69666db4aacfe540e9797ba6d6a69e (diff)
downloadick2-599e095cda626ff66c789017a752d7f91678d033.tar.gz
Add: /builds
Diffstat (limited to 'ick2/controllerapi.py')
-rw-r--r--ick2/controllerapi.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py
index a7d5fb5..5cf5d64 100644
--- a/ick2/controllerapi.py
+++ b/ick2/controllerapi.py
@@ -33,6 +33,7 @@ class ControllerAPI:
def find_missing_route(self, missing_path): # pragma: no cover
apis = {
'/version': VersionAPI,
+ '/builds': BuildsAPI,
'/projects': ProjectAPI,
'/work': WorkAPI,
'/workers': WorkerAPI,
@@ -226,6 +227,21 @@ class WorkerAPI(ResourceApiBase): # pragma: no cover
return resource['worker']
+class BuildsAPI(ResourceApiBase): # pragma: no cover
+
+ def __init__(self, state):
+ super().__init__('builds', state)
+
+ def get_resource_name(self, resource):
+ return resource['build']
+
+ def create(self, body): # pragma: no cover
+ raise MethodNotAllowed('Creating builds directly is not allowed')
+
+ def update(self, body, name): # pragma: no cover
+ raise MethodNotAllowed('Updating builds directly is not allowed')
+
+
class ProjectAPI(ResourceApiBase):
def __init__(self, state):
@@ -326,8 +342,11 @@ class WorkAPI(APIbase):
pipeline['status'] = 'building'
self._update_project(project)
+ build_id = self._start_build(project, pipeline, worker)
+
index = 0
doing = {
+ 'build_id': build_id,
'worker': worker,
'project': project['project'],
'pipeline': pipeline['name'],
@@ -379,6 +398,7 @@ class WorkAPI(APIbase):
project, pipeline = self._get_pipeline(
update['project'], update['pipeline'])
+ self._append_to_build_log(update)
ick2.log.log(
'trace',
@@ -395,6 +415,7 @@ class WorkAPI(APIbase):
if index >= len(actions):
pipeline['status'] = 'idle'
doing = {}
+ self._finish_build(update)
else:
doing['step_index'] = index
doing['step'] = actions[index]
@@ -407,7 +428,7 @@ class WorkAPI(APIbase):
self._update_worker(worker_state)
def _check_work_update(self, doing, update): # pragma: no cover
- must_match = ['worker', 'project', 'pipeline']
+ must_match = ['worker', 'project', 'pipeline', 'build_id']
for name in must_match:
if name not in update:
raise BadUpdate('{} not specified'.format(name))
@@ -424,6 +445,27 @@ class WorkAPI(APIbase):
return p, pl
raise ick2.NotFound()
+ def _start_build(self, project, pipeline, worker):
+ ick2.log.log('info', msg_text='Starting new build')
+ build_id = 1
+ build = {
+ 'build_id': build_id,
+ 'worker': worker,
+ 'project': project['project'],
+ 'pipeline': pipeline['name'],
+ 'status': 'building',
+ }
+ self._state.add_resource('builds', str(build_id), build)
+ return build_id
+
+ def _append_to_build_log(self, update):
+ pass
+
+ def _finish_build(self, update):
+ build = self._state.get_resource('builds', str(update['build_id']))
+ build['status'] = update['exit_code']
+ self._state.update_resource('builds', str(update['build_id']), build)
+
def create(self, *args, **kwargs): # pragma: no cover
pass
@@ -446,6 +488,12 @@ class BadUpdate(Exception): # pragma: no cover
super().__init__('Work update is BAD: {}'.format(how))
+class MethodNotAllowed(Exception): # pragma: no cover
+
+ def __init__(self, wat):
+ super().__init__(wat)
+
+
def response(status_code, body, headers): # pragma: no cover
obj = {
'status': status_code,