Adding job_execution_update api call

Adding ability to update job executions in order
to change their public/protected attributes later

APIImpact

PATCH /v1.1/{tenant_id}/job-executions/{job_execution_id}

Partially implements: blueprint api-for-objects-update

Change-Id: I3bec4d66d3cf1968e344bf746549c16770f4cef6
This commit is contained in:
Andrey Pavlov
2015-08-11 12:40:38 +03:00
parent ad24e1a84c
commit 52dd81efa9
8 changed files with 92 additions and 34 deletions

View File

@@ -37,6 +37,7 @@
"data-processing:job-executions:refresh_status": "",
"data-processing:job-executions:cancel": "",
"data-processing:job-executions:delete": "",
"data-processing:job-executions:modify": "",
"data-processing:data-sources:get_all": "",
"data-processing:data-sources:get": "",

View File

@@ -26,6 +26,7 @@ from sahara.service.validations.edp import job_binary_internal as v_j_b_i
from sahara.service.validations.edp import job_binary_internal_schema as vjbi_s
from sahara.service.validations.edp import job_binary_schema as v_j_b_schema
from sahara.service.validations.edp import job_execution as v_j_e
from sahara.service.validations.edp import job_execution_schema as v_j_e_schema
import sahara.utils.api as u
@@ -65,6 +66,14 @@ def job_executions_cancel(job_execution_id):
return u.to_wrapped_dict(api.cancel_job_execution, job_execution_id)
@rest.patch('/job-executions/<job_execution_id>')
@acl.enforce("data-processing:job-executions:modify")
@v.check_exists(api.get_job_execution, id='job_execution_id')
@v.validate(v_j_e_schema.JOB_EXEC_UPDATE_SCHEMA)
def job_executions_update(job_execution_id, data):
return u.to_wrapped_dict(api.update_job_execution, job_execution_id, data)
@rest.delete('/job-executions/<job_execution_id>')
@acl.enforce("data-processing:job-executions:delete")
@v.check_exists(api.get_job_execution, id='job_execution_id')
@@ -147,7 +156,7 @@ def job_delete(job_id):
@rest.post('/jobs/<job_id>/execute')
@acl.enforce("data-processing:jobs:execute")
@v.check_exists(api.get_job, id='job_id')
@v.validate(v_j_e.JOB_EXEC_SCHEMA, v_j_e.check_job_execution)
@v.validate(v_j_e_schema.JOB_EXEC_SCHEMA, v_j_e.check_job_execution)
def job_execute(job_id, data):
return u.render(job_execution=api.execute_job(job_id, data).to_dict())

View File

@@ -160,6 +160,10 @@ def cancel_job_execution(id):
return job_execution
def update_job_execution(id, values):
return conductor.job_execution_update(context.ctx(), id, values)
def delete_job_execution(id):
context.set_current_job_execution_id(id)
OPS.delete_job_execution(id)

View File

@@ -21,32 +21,6 @@ from sahara.plugins import base as plugin_base
import sahara.service.validations.edp.base as b
import sahara.service.validations.edp.job_interface as j_i
JOB_EXEC_SCHEMA = {
"type": "object",
"properties": {
"input_id": {
"type": "string",
"format": "uuid",
},
"output_id": {
"type": "string",
"format": "uuid",
},
"cluster_id": {
"type": "string",
"format": "uuid",
},
"interface": {
"type": "simple_config",
},
"job_configs": b.job_configs,
},
"additionalProperties": False,
"required": [
"cluster_id"
]
}
conductor = c.API

View File

@@ -0,0 +1,52 @@
# Copyright (c) 2015 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sahara.service.validations.edp.base as b
JOB_EXEC_SCHEMA = {
"type": "object",
"properties": {
"input_id": {
"type": "string",
"format": "uuid",
},
"output_id": {
"type": "string",
"format": "uuid",
},
"cluster_id": {
"type": "string",
"format": "uuid",
},
"interface": {
"type": "simple_config",
},
"job_configs": b.job_configs,
},
"additionalProperties": False,
"required": [
"cluster_id"
]
}
JOB_EXEC_UPDATE_SCHEMA = {
"type": "object",
"properties": {},
"additionalProperties": False,
"required": []
}

View File

@@ -23,7 +23,7 @@ import testtools
from sahara.service.validations.edp import data_source_schema
from sahara.service.validations.edp import job
from sahara.service.validations.edp import job_binary_schema
from sahara.service.validations.edp import job_execution
from sahara.service.validations.edp import job_execution_schema
from sahara.utils import api_validator
@@ -55,7 +55,7 @@ class TestJSONApiExamplesV11(testtools.TestCase):
self._test(schema, path, formatter)
def test_job_executions(self):
schema = job_execution.JOB_EXEC_SCHEMA
schema = job_execution_schema.JOB_EXEC_SCHEMA
path = self.EXAMPLES_PATH % 'job-executions'
formatter = self._formatter("cluster_id",
"input_source_id",

View File

@@ -21,6 +21,7 @@ import six
from sahara import main
from sahara.service import api
from sahara.service.validations.edp import job_execution as je
from sahara.service.validations.edp import job_execution_schema as je_schema
from sahara.tests.unit.service.validation import utils as u
from sahara.tests.unit import testutils as tu
from sahara.utils import edp
@@ -30,12 +31,12 @@ def wrap_it(data):
je.check_job_execution(data, 0)
class TestJobExecValidation(u.ValidationTestCase):
class TestJobExecCreateValidation(u.ValidationTestCase):
def setUp(self):
super(TestJobExecValidation, self).setUp()
super(TestJobExecCreateValidation, self).setUp()
self._create_object_fun = wrap_it
self.scheme = je.JOB_EXEC_SCHEMA
self.scheme = je_schema.JOB_EXEC_SCHEMA
# Make sure that the spark plugin is loaded
if 'spark' not in main.CONF['plugins']:
self.override_config('plugins', main.CONF['plugins'] + ['spark'])
@@ -249,3 +250,20 @@ class TestJobExecValidation(u.ValidationTestCase):
"params": {},
"args": []}
})
class TestJobExecUpdateValidation(u.ValidationTestCase):
def setUp(self):
super(TestJobExecUpdateValidation, self).setUp()
self._create_object_fun = mock.Mock()
self.scheme = je_schema.JOB_EXEC_UPDATE_SCHEMA
def test_job_execution_update_types(self):
data = {}
self._assert_types(data)
def test_job_execution_update_nothing_required(self):
self._assert_create_object_validation(
data={}
)

View File

@@ -19,7 +19,7 @@ import itertools
import mock
from sahara.service.validations.edp import job as j
from sahara.service.validations.edp import job_execution as j_e
from sahara.service.validations.edp import job_execution_schema as j_e_schema
from sahara.service.validations.edp import job_interface as j_i
from sahara.tests.unit.service.validation import utils as u
from sahara.utils import edp
@@ -219,7 +219,7 @@ class TestJobExecutionInterfaceValidation(u.ValidationTestCase):
def setUp(self):
super(TestJobExecutionInterfaceValidation, self).setUp()
self._create_object_fun = j_e_i_wrapper
self.scheme = j_e.JOB_EXEC_SCHEMA
self.scheme = j_e_schema.JOB_EXEC_SCHEMA
def test_valid_execution(self):
data = {"cluster_id": "DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF",