TemplatesRelation is now NodeGroup-like object.

* model extended;
* storage layer updated;
* tests fixed.

Change-Id: I94be8da85e35ee5db876bc0614ee3de87e42bb8f
This commit is contained in:
Sergey Lukjanov 2013-06-05 23:46:44 +04:00
parent 0c416d7918
commit 8271455750
3 changed files with 31 additions and 26 deletions

View File

@ -24,9 +24,6 @@ from savanna.utils import remote
from savanna.utils import sqlatypes as st
CLUSTER_STATUSES = ['Starting', 'Active', 'Stopping', 'Error']
class Cluster(mb.SavannaBase, mb.IdMixin, mb.TenantMixin,
mb.PluginSpecificMixin, mb.ExtraMixin):
"""Contains all info about cluster."""
@ -203,16 +200,15 @@ class ClusterTemplate(mb.SavannaBase, mb.IdMixin, mb.TenantMixin,
self.cluster_configs = cluster_configs or {}
self.description = description
def add_node_group_template(self, node_group_template_id, name, count):
relation = TemplatesRelation(self.id, node_group_template_id, name,
count)
def add_node_group_template(self, kwargs):
relation = TemplatesRelation(self.id, **kwargs)
self.templates_relations.append(relation)
return relation
def to_dict(self):
d = super(ClusterTemplate, self).to_dict()
d['node_group_templates'] = [tr.dict for tr in
self.templates_relations]
d['node_groups'] = [tr.dict for tr in
self.templates_relations]
return d
@ -244,29 +240,36 @@ class NodeGroupTemplate(mb.SavannaBase, mb.IdMixin, mb.TenantMixin,
# todo it should be replaced with NodeGroup-based relation
class TemplatesRelation(mb.SavannaBase):
class TemplatesRelation(mb.SavannaBase, mb.IdMixin):
"""NodeGroupTemplate - ClusterTemplate relationship."""
__filter_cols__ = ['cluster_template_id', 'created', 'updated']
__filter_cols__ = ['cluster_template_id', 'created', 'updated', 'id']
cluster_template_id = sa.Column(sa.String(36),
sa.ForeignKey('ClusterTemplate.id'),
primary_key=True)
node_group_template_id = sa.Column(sa.String(36),
sa.ForeignKey('NodeGroupTemplate.id'),
primary_key=True)
sa.ForeignKey('ClusterTemplate.id'))
cluster_template = relationship(ClusterTemplate,
backref='templates_relations')
node_group_template_id = sa.Column(sa.String(36),
sa.ForeignKey('NodeGroupTemplate.id'))
node_group_template = relationship(NodeGroupTemplate,
backref='templates_relations')
node_group_name = sa.Column(sa.String(80), nullable=False)
count = sa.Column(sa.Integer, nullable=False)
def __init__(self, cluster_template_id, node_group_template_id,
node_group_name, count):
name = sa.Column(sa.String(80), nullable=False)
flavor_id = sa.Column(sa.String(36))
node_processes = sa.Column(st.JsonListType())
node_configs = sa.Column(st.JsonDictType())
count = sa.Column(sa.Integer)
def __init__(self, cluster_template_id, name, count,
node_processes=None, flavor_id=None, node_configs=None,
node_group_template_id=None):
self.cluster_template_id = cluster_template_id
self.node_group_template_id = node_group_template_id
self.node_group_name = node_group_name
self.name = name
self.flavor_id = flavor_id
self.node_processes = node_processes
self.node_configs = node_configs or {}
self.count = count

View File

@ -62,12 +62,10 @@ def create_cluster_template(values):
session = ctx.current().session
with session.begin():
values['tenant_id'] = ctx.current().tenant_id
ngts_vals = values.pop('node_group_templates', [])
ngts_vals = values.pop('node_groups', [])
cluster_template = m.ClusterTemplate(**values)
for ngt in ngts_vals:
relation = cluster_template.add_node_group_template(
ngt['node_group_template_id'], ngt['node_group_name'],
ngt['count'])
relation = cluster_template.add_node_group_template(ngt)
session.add(relation)
session.add(cluster_template)

View File

@ -72,7 +72,7 @@ class TemplatesModelTest(models_test_base.ModelTestCase):
'hadoop_version': 'hv-1',
'name': 'c-1',
'plugin_name': 'p-1',
'node_group_templates': []
'node_groups': []
})
def testCreateClusterTemplateWithNodeGroupTemplates(self):
@ -87,7 +87,11 @@ class TemplatesModelTest(models_test_base.ModelTestCase):
'hv-1', ['np-1', 'np-2'])
session.add(ngt)
session.flush()
rel = ct.add_node_group_template(ngt.id, 'group-%s' % i, 5 + i)
rel = ct.add_node_group_template({
'node_group_template_id': ngt.id,
'name': 'group-%s' % i,
'count': 5 + i
})
session.add(rel)
ngts.append(ngt)