You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by ra...@apache.org on 2017/03/30 11:30:05 UTC
incubator-ariatosca git commit: fixed service-inputs;
service now has a default name
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-48-aria-cli 0833c0d39 -> 2811e1ec1
fixed service-inputs; service now has a default name
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/2811e1ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/2811e1ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/2811e1ec
Branch: refs/heads/ARIA-48-aria-cli
Commit: 2811e1ec1311c244d676969877e37477bef008d6
Parents: 0833c0d
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Thu Mar 30 14:30:01 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Thu Mar 30 14:30:01 2017 +0300
----------------------------------------------------------------------
aria/cli/commands/services.py | 15 +++++++++------
aria/core.py | 18 ++++++++++--------
aria/modeling/service_template.py | 11 ++---------
aria/modeling/utils.py | 14 +++++++-------
aria/orchestrator/workflow_runner.py | 5 +++--
aria/utils/conversion.py | 8 +++++---
6 files changed, 36 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2811e1ec/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index 0352ff0..9ddb272 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -93,7 +93,6 @@ def create(service_template_name,
"""
logger.info('Creating new service from service template {0}...'.format(
service_template_name))
- service_name = service_name or service_template_name
try:
core = Core(model_storage, resource_storage, plugin_manager)
@@ -165,8 +164,12 @@ def inputs(service_name, model_storage, logger):
"""
logger.info('Showing inputs for service {0}...'.format(service_name))
service = model_storage.service.get_by_name(service_name)
- inputs_ = StringIO()
- for input_name, input in service.inputs.iteritems():
- inputs_.write(' - "{0}":{1}'.format(input_name, os.linesep))
- inputs_.write(' Value: {0}{1}'.format(input.value, os.linesep))
- logger.info(inputs_.getvalue())
+ if service.inputs:
+ inputs_ = StringIO()
+ for input_name, input in service.inputs.iteritems():
+ inputs_.write(' - "{0}":{1}'.format(input_name, os.linesep))
+ inputs_.write(' Value: {0}{1}'.format(input.value, os.linesep))
+ logger.info(inputs_.getvalue())
+ else:
+ logger.info('\tNo inputs')
+ logger.info('')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2811e1ec/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index dc8eba5..50487b6 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -14,7 +14,7 @@
# limitations under the License.
from .modeling import models
-from .modeling import utils as storage_utils
+from .modeling import utils as modeling_utils
from .exceptions import AriaException
from .parser.consumption import (
ConsumptionContext,
@@ -68,21 +68,23 @@ class Core(object):
self.model_storage.service_template.delete(service_template)
self.resource_storage.service_template.delete(entry_id=str(service_template.id))
- def create_service(self, service_template_name, inputs, service_name):
+ def create_service(self, service_template_name, inputs, service_name=None):
service_template = self.model_storage.service_template.get_by_name(service_template_name)
- context = ConsumptionContext()
+ # creating an empty ConsumptionContext, initiating a threadlocal context
+ ConsumptionContext()
with self.model_storage._all_api_kwargs['session'].no_autoflush:
service = service_template.instantiate(None)
- # template_inputs = self.model_storage.service_template.inputs
- # input_models = storage_utils.create_inputs(inputs, template_inputs)
- # service.inputs = input_models
-
+ template_inputs = service_template.inputs
+ input_models = modeling_utils.create_inputs(inputs, template_inputs)
+ service.inputs = {input.name: input for input in input_models}
# TODO: now that we have inputs, we should scan properties and inputs and evaluate functions
- service.name = service_name
+ # first put the service model so it could have an id, as fallback for setting its name
self.model_storage.service.put(service)
+ service.name = service_name or '{0}_{1}'.format(service_template_name, service.id)
+ self.model_storage.service.update(service)
return service
def delete_service(self, service_name, force=False):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2811e1ec/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 20c24b6..fd13c7f 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -258,7 +258,6 @@ class ServiceTemplateBase(TemplateModelMixin): # pylint: disable=too-many-public
updated_at=now,
description=deepcopy_with_locators(self.description),
service_template=self)
- #service.name = '{0}_{1}'.format(self.name, service.id)
context.modeling.instance = service
@@ -274,18 +273,12 @@ class ServiceTemplateBase(TemplateModelMixin): # pylint: disable=too-many-public
utils.instantiate_dict(self, service.workflows, self.workflow_templates)
utils.instantiate_dict(self, service.plugin_specifications, self.plugin_specifications)
- # if self.substitution_template is not None:
- # service.substitution = self.substitution_template.instantiate(container)
+ if self.substitution_template is not None:
+ service.substitution = self.substitution_template.instantiate(container)
utils.instantiate_dict(self, service.inputs, self.inputs)
utils.instantiate_dict(self, service.outputs, self.outputs)
- for name, the_input in context.modeling.inputs.iteritems():
- if name not in service.inputs:
- context.validation.report('input "{0}" is not supported'.format(name))
- else:
- service.inputs[name].value = the_input
-
return service
def validate(self):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2811e1ec/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index faf4186..250df6d 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -37,9 +37,9 @@ def create_inputs(inputs, template_inputs):
for input_name, input_val in inputs.iteritems():
parameter = models.Parameter(
name=input_name,
- type=template_inputs[input_name].type,
+ type_name=template_inputs[input_name].type_name,
description=template_inputs[input_name].description,
- str_value=str(input_val))
+ value=input_val)
input_models.append(parameter)
return input_models
@@ -64,9 +64,9 @@ def _merge_and_validate_inputs(inputs, template_inputs):
else:
# Validate type of inputs
try:
- convert_value_to_type(str(inputs[input_name]), input_template.type)
+ convert_value_to_type(str(inputs[input_name]), input_template.type_name)
except ValueError:
- wrong_type_inputs[input_name] = input_template.type
+ wrong_type_inputs[input_name] = input_template.type_name
if missing_inputs:
raise exceptions.MissingRequiredInputsException(
@@ -80,12 +80,12 @@ def _merge_and_validate_inputs(inputs, template_inputs):
format(param_name, param_type))
raise exceptions.InputOfWrongTypeException(error_message.getvalue())
- unknown_inputs = [input_name for input_name in inputs.keys()
+ undeclared_inputs = [input_name for input_name in inputs.keys()
if input_name not in template_inputs]
- if unknown_inputs:
+ if undeclared_inputs:
raise exceptions.UndeclaredInputsException(
'Undeclared inputs have been specified: {0}; Expected inputs: {1}'
- .format(unknown_inputs, template_inputs.keys()))
+ .format(undeclared_inputs, template_inputs.keys()))
return merged_inputs
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2811e1ec/aria/orchestrator/workflow_runner.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflow_runner.py b/aria/orchestrator/workflow_runner.py
index d6b3b5c..a529a84 100644
--- a/aria/orchestrator/workflow_runner.py
+++ b/aria/orchestrator/workflow_runner.py
@@ -25,7 +25,7 @@ from .workflows.builtin import BUILTIN_WORKFLOWS, BUILTIN_WORKFLOWS_PATH_PREFIX
from .workflows.core.engine import Engine
from .workflows.executor.process import ProcessExecutor
from ..exceptions import AriaException
-from ..modeling import utils as storage_utils
+from ..modeling import utils as modeling_utils
from ..modeling import models
from ..utils.imports import import_fullname
@@ -85,6 +85,7 @@ class WorkflowRunner(object):
return self._model_storage.service.get(self._service_id)
def execute(self):
+ #TODO uncomment, commented for testing purposes
# self._validate_no_active_executions()
self._engine.execute()
@@ -101,7 +102,7 @@ class WorkflowRunner(object):
# self.service.workflows[self._workflow_name].properties
# if k not in WORKFLOW_POLICY_INTERNAL_PROPERTIES}
- # input_models = storage_utils.create_inputs(inputs, workflow_inputs)
+ # input_models = modeling_utils.create_inputs(inputs, workflow_inputs)
# execution.parameters = input_models
self._model_storage.execution.put(execution)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2811e1ec/aria/utils/conversion.py
----------------------------------------------------------------------
diff --git a/aria/utils/conversion.py b/aria/utils/conversion.py
index fa99ece..7136a90 100644
--- a/aria/utils/conversion.py
+++ b/aria/utils/conversion.py
@@ -15,12 +15,14 @@
def convert_value_to_type(str_value, type_name):
+ """Supports both python and yaml type names"""
+ #TODO add timestamp type?
try:
- if type_name.lower() in ['str', 'unicode']:
+ if type_name.lower() in ['str', 'unicode', 'string']:
return str_value.decode('utf-8')
- elif type_name.lower() == 'int':
+ elif type_name.lower() in ['int', 'integer']:
return int(str_value)
- elif type_name.lower() == 'bool':
+ elif type_name.lower() in ['bool', 'boolean']:
return bool(str_value)
elif type_name.lower() == 'float':
return float(str_value)