From 13652a5c1cb73592313f6531b3c6ff04630e957e Mon Sep 17 00:00:00 2001 From: Alexander Ignatov Date: Mon, 8 Jul 2013 17:59:07 +0400 Subject: [PATCH] Added plugin configuration checks to validate methods Implements blueprint savanna-rest-api-1-0-validation Change-Id: Ia601ecf51385c5983b13ffdab4d19dec084c7bea --- savanna/service/api.py | 4 ++ savanna/service/validations/base.py | 56 +++++++++++++++++-- .../service/validations/cluster_templates.py | 2 + savanna/service/validations/clusters.py | 2 + .../validations/node_group_templates.py | 4 ++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/savanna/service/api.py b/savanna/service/api.py index 323b079e..61088b0d 100644 --- a/savanna/service/api.py +++ b/savanna/service/api.py @@ -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: diff --git a/savanna/service/validations/base.py b/savanna/service/validations/base.py index 25165a1b..da937d1e 100644 --- a/savanna/service/validations/base.py +++ b/savanna/service/validations/base.py @@ -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'" diff --git a/savanna/service/validations/cluster_templates.py b/savanna/service/validations/cluster_templates.py index 5d22394b..98845e6c 100644 --- a/savanna/service/validations/cluster_templates.py +++ b/savanna/service/validations/cluster_templates.py @@ -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) diff --git a/savanna/service/validations/clusters.py b/savanna/service/validations/clusters.py index b6d4ed90..44873452 100644 --- a/savanna/service/validations/clusters.py +++ b/savanna/service/validations/clusters.py @@ -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) diff --git a/savanna/service/validations/node_group_templates.py b/savanna/service/validations/node_group_templates.py index c7afb909..e7dc4aea 100644 --- a/savanna/service/validations/node_group_templates.py +++ b/savanna/service/validations/node_group_templates.py @@ -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'])