You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by av...@apache.org on 2017/04/02 13:38:47 UTC

[1/2] incubator-ariatosca git commit: Make Execution, Task and Node status properties into methods

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-48-aria-cli 3f30fa35d -> 36981a7e3


Make Execution, Task and Node status properties into methods


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e1b174fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e1b174fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e1b174fd

Branch: refs/heads/ARIA-48-aria-cli
Commit: e1b174fdac9366648a0bef5cb712b52ede5b8bb4
Parents: 3f30fa3
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sun Apr 2 16:11:43 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Apr 2 16:11:43 2017 +0300

----------------------------------------------------------------------
 aria/modeling/orchestration.py             | 6 +-----
 aria/modeling/service_instance.py          | 1 -
 aria/orchestrator/workflows/core/engine.py | 6 +++---
 aria/orchestrator/workflows/core/task.py   | 2 --
 4 files changed, 4 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1b174fd/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index 15abde4..3ad6b58 100644
--- a/aria/modeling/orchestration.py
+++ b/aria/modeling/orchestration.py
@@ -98,13 +98,11 @@ class ExecutionBase(ModelMixin):
     status = Column(Enum(*STATES, name='execution_status'), default=PENDING)
     workflow_name = Column(Text)
 
-    @property
     def has_ended(self):
         return self.status in self.END_STATES
 
-    @property
     def is_active(self):
-        return not self.has_ended
+        return not self.has_ended()
 
     @declared_attr
     def logs(cls):
@@ -290,11 +288,9 @@ class TaskBase(ModelMixin):
     implementation = Column(String)
     _runs_on = Column(Enum(*RUNS_ON, name='runs_on'), name='runs_on')
 
-    @property
     def has_ended(self):
         return self.status in [self.SUCCESS, self.FAILED]
 
-    @property
     def is_waiting(self):
         return self.status in [self.PENDING, self.RETRYING]
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1b174fd/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index 48615af..a8fe71b 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -415,7 +415,6 @@ class NodeBase(InstanceModelMixin):
         except KeyError:
             return None
 
-    @property
     def is_available(self):
         return self.state not in [self.INITIAL, self.DELETED, self.ERROR]
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1b174fd/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py
index d32abb8..0503142 100644
--- a/aria/orchestrator/workflows/core/engine.py
+++ b/aria/orchestrator/workflows/core/engine.py
@@ -88,12 +88,12 @@ class Engine(logger.LoggerMixin):
     def _executable_tasks(self):
         now = datetime.utcnow()
         return (task for task in self._tasks_iter()
-                if task.is_waiting and
+                if task.is_waiting() and
                 task.due_at <= now and
                 not self._task_has_dependencies(task))
 
     def _ended_tasks(self):
-        return (task for task in self._tasks_iter() if task.has_ended)
+        return (task for task in self._tasks_iter() if task.has_ended())
 
     def _task_has_dependencies(self, task):
         return len(self._execution_graph.pred.get(task.id, {})) > 0
@@ -105,7 +105,7 @@ class Engine(logger.LoggerMixin):
         for _, data in self._execution_graph.nodes_iter(data=True):
             task = data['task']
             if isinstance(task, engine_task.OperationTask):
-                if not task.model_task.has_ended:
+                if not task.model_task.has_ended():
                     self._workflow_context.model.task.refresh(task.model_task)
             yield task
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1b174fd/aria/orchestrator/workflows/core/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py
index aa8963f..540988c 100644
--- a/aria/orchestrator/workflows/core/task.py
+++ b/aria/orchestrator/workflows/core/task.py
@@ -69,11 +69,9 @@ class StubTask(BaseTask):
         self.status = models.Task.PENDING
         self.due_at = datetime.utcnow()
 
-    @property
     def has_ended(self):
         return self.status in [models.Task.SUCCESS, models.Task.FAILED]
 
-    @property
     def is_waiting(self):
         return self.status in [models.Task.PENDING, models.Task.RETRYING]
 


[2/2] incubator-ariatosca git commit: Enforce Uniqueness on ServiceTemplate and Service names

Posted by av...@apache.org.
Enforce Uniqueness on ServiceTemplate and Service names


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/36981a7e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/36981a7e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/36981a7e

Branch: refs/heads/ARIA-48-aria-cli
Commit: 36981a7e3e9f4d7d29ca09a471079c77708e7233
Parents: e1b174f
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sun Apr 2 16:37:51 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Apr 2 16:37:51 2017 +0300

----------------------------------------------------------------------
 aria/cli/commands/service_templates.py | 19 ++++++++++++++-----
 aria/cli/commands/services.py          |  7 +++++++
 aria/cli/constants.py                  |  4 ++++
 aria/modeling/models.py                |  8 ++++++--
 4 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/cli/commands/service_templates.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/service_templates.py b/aria/cli/commands/service_templates.py
index b855529..823a6e8 100644
--- a/aria/cli/commands/service_templates.py
+++ b/aria/cli/commands/service_templates.py
@@ -19,12 +19,14 @@ import json
 
 from .. import utils
 from .. import csar
-from ..cli import aria
 from .. import service_template_utils
+from ..cli import aria
+from ..constants import TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE
 from ..table import print_data
 from ..exceptions import AriaCliError
 from ...core import Core
 from ...exceptions import AriaException
+from ...storage.exceptions import StorageError
 
 
 DESCRIPTION_LIMIT = 20
@@ -112,11 +114,18 @@ def store(service_template_path, service_template_name, model_storage, resource_
 
     service_template_path = service_template_utils.get(service_template_path)
     core = Core(model_storage, resource_storage, plugin_manager)
-    core.create_service_template(service_template_path,
-                                 os.path.dirname(service_template_path),
-                                 service_template_name)
+    try:
+        core.create_service_template(service_template_path,
+                                     os.path.dirname(service_template_path),
+                                     service_template_name)
+    except StorageError:
+        logger.info(TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE.format(
+            model_class='service template',
+            name=service_template_name))
+        raise
 
-    logger.info('Service template stored')
+    else:
+        logger.info('Service template stored')
 
 
 @service_templates.command(name='delete',

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index ce1139b..ae04d7e 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -19,11 +19,13 @@ from StringIO import StringIO
 
 from . import service_templates
 from ..cli import aria, helptexts
+from ..constants import TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE
 from ..exceptions import AriaCliError
 from ..table import print_data
 from ..utils import storage_sort_param
 from ...core import Core
 from ...exceptions import AriaException
+from ...storage.exceptions import StorageError
 
 
 SERVICE_COLUMNS = ['id', 'name', 'service_template_name', 'created_at', 'updated_at']
@@ -97,6 +99,11 @@ def create(service_template_name,
     try:
         core = Core(model_storage, resource_storage, plugin_manager)
         service = core.create_service(service_template_name, inputs, service_name)
+    except StorageError:
+        logger.info(TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE.format(
+            model_class='service',
+            name=service_name))
+        raise
     except AriaException as e:
         logger.info(str(e))
         service_templates.print_service_template_inputs(model_storage, service_template_name)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/cli/constants.py
----------------------------------------------------------------------
diff --git a/aria/cli/constants.py b/aria/cli/constants.py
index 67c094d..fdd37fc 100644
--- a/aria/cli/constants.py
+++ b/aria/cli/constants.py
@@ -16,3 +16,7 @@
 
 SAMPLE_SERVICE_TEMPLATE_FILENAME = 'service_template.yaml'
 HELP_TEXT_COLUMN_BUFFER = 5
+TWO_MODELS_WITH_THE_SAME_NAME_ERROR_TEMPLATE = """
+Could not store {model_class} `{name}`
+There already a exists a {model_class} with the same name
+"""

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/36981a7e/aria/modeling/models.py
----------------------------------------------------------------------
diff --git a/aria/modeling/models.py b/aria/modeling/models.py
index a01783b..db9db07 100644
--- a/aria/modeling/models.py
+++ b/aria/modeling/models.py
@@ -26,6 +26,10 @@ from . import (
     mixins,
 )
 
+from sqlalchemy import (
+    Column,
+    Text
+)
 
 aria_declarative_base = declarative_base(cls=mixins.ModelIDMixin)
 
@@ -84,7 +88,7 @@ __all__ = (
 # region service template models
 
 class ServiceTemplate(aria_declarative_base, service_template.ServiceTemplateBase):
-    pass
+    name = Column(Text, index=True, unique=True)
 
 
 class NodeTemplate(aria_declarative_base, service_template.NodeTemplateBase):
@@ -137,7 +141,7 @@ class ArtifactTemplate(aria_declarative_base, service_template.ArtifactTemplateB
 # region service instance models
 
 class Service(aria_declarative_base, service_instance.ServiceBase):
-    pass
+    name = Column(Text, index=True, unique=True)
 
 
 class Node(aria_declarative_base, service_instance.NodeBase):