Add support for job-types-list
This change adds support to the client for the job-types-endpoint. Filtering by a single value for type, plugin, and version is supported. Config hints are not available in this interface. Change-Id: I0240717ac74c52dd915ce1617fb5d34d87660c0b Partial-Implements: blueprint edp-job-types-endpoint
This commit is contained in:
parent
3fa0e0e798
commit
fb9cf4ed62
|
@ -26,6 +26,7 @@ from saharaclient.api import images
|
|||
from saharaclient.api import job_binaries
|
||||
from saharaclient.api import job_binary_internals
|
||||
from saharaclient.api import job_executions
|
||||
from saharaclient.api import job_types
|
||||
from saharaclient.api import jobs
|
||||
from saharaclient.api import node_group_templates
|
||||
from saharaclient.api import plugins
|
||||
|
@ -115,6 +116,7 @@ class Client(object):
|
|||
self.job_binary_internals = (
|
||||
job_binary_internals.JobBinaryInternalsManager(client)
|
||||
)
|
||||
self.job_types = job_types.JobTypesManager(client)
|
||||
|
||||
def get_keystone_client(self, username=None, api_key=None, auth_url=None,
|
||||
token=None, project_id=None, project_name=None):
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# Copyright (c) 2015 Red Hat 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.
|
||||
|
||||
from saharaclient.api import base
|
||||
|
||||
|
||||
class JobType(base.Resource):
|
||||
resource_name = 'JobType'
|
||||
|
||||
|
||||
class JobTypesManager(base.ResourceManager):
|
||||
resource_class = JobType
|
||||
|
||||
def list(self, search_opts=None):
|
||||
query = base.get_query_string(search_opts)
|
||||
return self._list('/job-types%s' % query, 'job_types')
|
|
@ -799,3 +799,53 @@ def do_job_delete(cs, args):
|
|||
"""Delete a job."""
|
||||
cs.job_executions.delete(args.id)
|
||||
# TODO(mattf): No indication of result
|
||||
|
||||
|
||||
#
|
||||
# Job Types
|
||||
# ~~~~~~~~~
|
||||
# job-type-list [--type] [--plugin [--plugin-version]]
|
||||
#
|
||||
|
||||
def _print_plugin_field(job_type):
|
||||
|
||||
def plugin_version_string(plugin):
|
||||
versions = ", ".join(plugin["versions"].keys())
|
||||
if versions:
|
||||
versions = "(" + versions + ")"
|
||||
return plugin["name"] + versions
|
||||
|
||||
return ", ".join(map(lambda x: plugin_version_string(x), job_type.plugins))
|
||||
|
||||
|
||||
@utils.arg('--type',
|
||||
metavar='<job_type>',
|
||||
default=None,
|
||||
help='Report only on this job type')
|
||||
@utils.arg('--plugin',
|
||||
metavar='<plugin>',
|
||||
default=None,
|
||||
help='Report only job types supported by this plugin.')
|
||||
@utils.arg('--plugin-version',
|
||||
metavar='<plugin_version>',
|
||||
default=None,
|
||||
help='Report only on job types supported by this version '
|
||||
'of a specified plugin. Only valid with --plugin.')
|
||||
def do_job_type_list(cs, args):
|
||||
"""Show supported job types."""
|
||||
search_opts = {}
|
||||
if args.type:
|
||||
search_opts["type"] = args.type
|
||||
if args.plugin:
|
||||
search_opts["plugin"] = args.plugin
|
||||
if args.plugin_version:
|
||||
search_opts["version"] = args.plugin_version
|
||||
elif args.plugin_version:
|
||||
raise exceptions.CommandError(
|
||||
'The --plugin-version option is only valid when '
|
||||
'--plugin is specified')
|
||||
|
||||
job_types = cs.job_types.list(search_opts)
|
||||
columns = ('name', 'plugin(versions)')
|
||||
utils.print_list(job_types, columns,
|
||||
{'plugin(versions)': _print_plugin_field})
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
# Copyright (c) 2015 Red Hat 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.
|
||||
|
||||
from saharaclient.api import job_types as jt
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
|
||||
class JobTypesTest(base.BaseTestCase):
|
||||
body = {
|
||||
"name": "Hive",
|
||||
"plugins": [
|
||||
{
|
||||
"description": "The Apache Vanilla plugin.",
|
||||
"name": "vanilla",
|
||||
"title": "Vanilla Apache Hadoop",
|
||||
"versions": {
|
||||
"1.2.1": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "The Hortonworks Sahara plugin.",
|
||||
"name": "hdp",
|
||||
"title": "Hortonworks Data Platform",
|
||||
"versions": {
|
||||
"1.3.2": {},
|
||||
"2.0.6": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def test_job_types_list(self):
|
||||
url = self.URL + '/job-types'
|
||||
self.responses.get(url, json={'job_types': [self.body]})
|
||||
|
||||
resp = self.client.job_types.list()
|
||||
|
||||
self.assertEqual(url, self.responses.last_request.url)
|
||||
self.assertIsInstance(resp[0], jt.JobType)
|
||||
self.assertFields(self.body, resp[0])
|
Loading…
Reference in New Issue