Merge "Added plugin configuration checks to validate methods"

This commit is contained in:
Jenkins 2013-07-08 17:40:02 +00:00 committed by Gerrit Code Review
commit 032460f83e
5 changed files with 64 additions and 4 deletions

View File

@ -188,6 +188,7 @@ def convert_to_cluster_template(plugin_name, version, config_file):
return s.persist_cluster_template(ct)
# TODO(aignatov): Will be removed after implementing scaling validation
def _validate(cluster, plugin):
# Validate that user configs are not included in plugin configs set
pl_confs = _get_plugin_configs(cluster, plugin)
@ -195,6 +196,7 @@ def _validate(cluster, plugin):
_validate_node_group(pl_confs, ng)
# TODO(aignatov): Will be removed after implementing scaling validation
def _validate_cluster(cluster, plugin, node_groups):
# Validate that user configs are not included in plugin configs set
pl_confs = _get_plugin_configs(cluster, plugin)
@ -204,6 +206,7 @@ def _validate_cluster(cluster, plugin, node_groups):
ng.cluster = None
# TODO(aignatov): Will be removed after implementing scaling validation
def _get_plugin_configs(cluster, plugin):
pl_confs = {}
for config in plugin.get_configs(cluster.hadoop_version):
@ -214,6 +217,7 @@ def _get_plugin_configs(cluster, plugin):
return pl_confs
# TODO(aignatov): Will be removed after implementing scaling validation
def _validate_node_group(pl_confs, node_group):
for app_target, configs in node_group.configuration.items():
if app_target not in pl_confs:

View File

@ -21,7 +21,19 @@ import savanna.service.api as api
import savanna.utils.openstack.nova as nova
# Common validation checks
def _get_plugin_configs(plugin_name, hadoop_version, scope=None):
pl_confs = {}
for config in plugin_base.PLUGINS.get_plugin(
plugin_name).get_configs(hadoop_version):
if pl_confs.get(config.applicable_target):
pl_confs[config.applicable_target].append(config.name)
else:
pl_confs[config.applicable_target] = [config.name]
return pl_confs
## Common validation checks
def check_plugin_name_exists(name):
if name not in [p.name for p in api.get_plugins()]:
raise ex.InvalidException("Savanna doesn't contain plugin with name %s"
@ -65,7 +77,41 @@ def check_node_processes(plugin_name, version, node_processes):
"node procesess: " % plugin_procesess)
# Cluster creation related checks
def check_node_group_configs(plugin_name, hadoop_version, ng_configs,
plugin_configs=None):
# TODO(aignatov): Should have scope and config type validations
pl_confs = plugin_configs or _get_plugin_configs(plugin_name,
hadoop_version)
for app_target, configs in ng_configs.items():
if app_target not in pl_confs:
raise ex.InvalidException("Plugin doesn't contain applicable "
"target '%s'" % app_target)
for name, values in configs.items():
if name not in pl_confs[app_target]:
raise ex.InvalidException("Plugin's applicable target '%s' "
"doesn't contain config with name "
"'%s'" % (app_target, name))
def check_all_configurations(data):
pl_confs = _get_plugin_configs(data['plugin_name'], data['hadoop_version'])
if data.get('cluster_configs'):
check_node_group_configs(data['plugin_name'], data['hadoop_version'],
data['cluster_configs'],
plugin_configs=pl_confs)
if data.get('node_groups'):
for ng in data['node_groups']:
if ng.get('node_configs'):
check_node_group_configs(data['plugin_name'],
data['hadoop_version'],
ng['node_configs'],
plugin_configs=pl_confs)
## Cluster creation related checks
def check_cluster_unique_name(name):
if name in [cluster.name for cluster in api.get_clusters()]:
raise ex.NameAlreadyExistsException("Cluster with name '%s' already"
@ -79,14 +125,16 @@ def check_keypair_exists(keypair):
raise ex.InvalidException("Requested keypair '%s' not found" % keypair)
# Cluster templates creation related checks
## Cluster templates creation related checks
def check_cluster_template_unique_name(name):
if name in [t.name for t in api.get_cluster_templates()]:
raise ex.NameAlreadyExistsException("Cluster template with name '%s'"
" already exists" % name)
# NodeGroup templates related checks
## NodeGroup templates related checks
def check_node_group_template_unique_name(name):
if name in [t.name for t in api.get_node_group_templates()]:
raise ex.NameAlreadyExistsException("NodeGroup template with name '%s'"

View File

@ -101,3 +101,5 @@ def check_cluster_template_create(data):
if data.get('default_image_id'):
b.check_image_exists(data['default_image_id'])
b.check_all_configurations(data)

View File

@ -47,3 +47,5 @@ def check_cluster_create(data):
if data.get('default_image_id'):
b.check_image_exists(data['default_image_id'])
b.check_all_configurations(data)

View File

@ -84,3 +84,7 @@ def check_node_group_template_create(data):
if data.get('image_id'):
b.check_image_exists(data['image_id'])
if data.get('node_configs'):
b.check_node_group_configs(data['plugin_name'], data['hadoop_version'],
data['node_configs'])