Merge pull request #225 from mesosphere/schema

dcos-447 read json-schema from Marathon
This commit is contained in:
tamarrow
2015-06-22 13:31:04 -07:00
2 changed files with 33 additions and 4 deletions

View File

@@ -322,15 +322,18 @@ def _add(app_resource):
:rtype: int
"""
application_resource = _get_resource(app_resource)
schema = _app_schema()
# Add application to marathon
client = marathon.create_client()
schema = client.get_app_schema()
if schema is None:
schema = _app_schema()
errs = util.validate_json(application_resource, schema)
if errs:
raise DCOSException(util.list_to_err(errs))
# Add application to marathon
client = marathon.create_client()
# Check that the application doesn't exist
app_id = client.normalize_app_id(application_resource['id'])

View File

@@ -81,6 +81,7 @@ class Client(object):
min_version = "0.8.1"
version = LooseVersion(self.get_about()["version"])
self._version = version
if version < LooseVersion(min_version):
msg = ("The configured Marathon with version {0} is outdated. " +
"Please use version {1} or later.").format(
@@ -98,6 +99,14 @@ class Client(object):
return urllib.parse.urljoin(self._base_uri, path)
def get_version(self):
"""Get marathon version
:returns: marathon version
rtype: LooseVersion
"""
return self._version
def get_about(self):
"""Returns info about Marathon instance
@@ -556,6 +565,23 @@ class Client(object):
return task
def get_app_schema(self):
"""Returns app json schema
:returns: application json schema
:rtype: json schema or None if endpoint doesn't exist
"""
version = self.get_version()
schema_version = LooseVersion("0.9.0")
if version < schema_version:
return None
url = self._create_url('v2/schemas/app')
response = http.get(url)
return response.json()
def normalize_app_id(self, app_id):
"""Normalizes the application id.