You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2016/10/20 15:13:38 UTC
[1/2] incubator-ariatosca git commit: pylint-aria-events [Forced
Update!]
Repository: incubator-ariatosca
Updated Branches:
refs/heads/pylint-aria-storage bae20ae92 -> 4f3317a0e (forced update)
pylint-aria-events
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/96746515
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/96746515
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/96746515
Branch: refs/heads/pylint-aria-storage
Commit: 96746515446c6aabf05ad4606dd2cbad5878dbaa
Parents: 62cf248
Author: mxmrlv <mx...@gmail.com>
Authored: Wed Oct 19 16:03:31 2016 +0300
Committer: mxmrlv <mx...@gmail.com>
Committed: Thu Oct 20 18:12:29 2016 +0300
----------------------------------------------------------------------
aria/events/__init__.py | 20 +++++++++++++++++++-
aria/events/builtin_event_handler.py | 14 +++++++++++---
aria/events/workflow_engine_event_handler.py | 20 ++++++++++++++------
tests/.pylintrc | 1 -
4 files changed, 44 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/96746515/aria/events/__init__.py
----------------------------------------------------------------------
diff --git a/aria/events/__init__.py b/aria/events/__init__.py
index c9d7b20..6b07213 100644
--- a/aria/events/__init__.py
+++ b/aria/events/__init__.py
@@ -13,13 +13,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+ARIA's events Sub-Package
+Path: aria.events
+
+Events package provides events mechanism for different executions in aria.
+
+
+1. storage_event_handler: implementation of storage handlers for workflow and operation events.
+2. logger_event_handler: implementation of logger handlers for workflow and operation events.
+
+API:
+ * start_task_signal
+ * on_success_task_signal
+ * on_failure_task_signal
+ * start_workflow_signal
+ * on_success_workflow_signal
+ * on_failure_workflow_signal
+"""
+
import os
from blinker import signal
from ..tools.plugin import plugin_installer
-
# workflow engine task signals:
start_task_signal = signal('start_task_signal')
on_success_task_signal = signal('success_task_signal')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/96746515/aria/events/builtin_event_handler.py
----------------------------------------------------------------------
diff --git a/aria/events/builtin_event_handler.py b/aria/events/builtin_event_handler.py
index 404cc01..ec3238f 100644
--- a/aria/events/builtin_event_handler.py
+++ b/aria/events/builtin_event_handler.py
@@ -13,6 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""
+Aria's events Sub-Package
+Path: aria.events.storage_event_handler
+
+Implementation of storage handlers for workflow and operation events.
+"""
+
+
from datetime import datetime
from . import (
@@ -54,13 +62,13 @@ def _task_succeeded(task, *args, **kwargs):
@start_workflow_signal.connect
def _workflow_started(workflow_context, *args, **kwargs):
- Execution = workflow_context.storage.execution.model_cls
- execution = Execution(
+ execution_cls = workflow_context.storage.execution.model_cls
+ execution = execution_cls(
id=workflow_context.execution_id,
deployment_id=workflow_context.deployment_id,
workflow_id=workflow_context.workflow_id,
blueprint_id=workflow_context.blueprint_id,
- status=Execution.PENDING,
+ status=execution_cls.PENDING,
started_at=datetime.utcnow(),
parameters=workflow_context.parameters,
)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/96746515/aria/events/workflow_engine_event_handler.py
----------------------------------------------------------------------
diff --git a/aria/events/workflow_engine_event_handler.py b/aria/events/workflow_engine_event_handler.py
index 6916206..60138e1 100644
--- a/aria/events/workflow_engine_event_handler.py
+++ b/aria/events/workflow_engine_event_handler.py
@@ -13,6 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+
+"""
+Aria's events Sub-Package
+Path: aria.events.storage_event_handler
+
+Implementation of logger handlers for workflow and operation events.
+"""
+
from . import (
start_task_signal,
on_success_task_signal,
@@ -24,37 +32,37 @@ from . import (
@start_task_signal.connect
-def start_task_handler(task, **kwargs):
+def _start_task_handler(task, **kwargs):
task.logger.debug(
'Event: Starting task: {task.name}'.format(task=task))
@on_success_task_signal.connect
-def success_task_handler(task, **kwargs):
+def _success_task_handler(task, **kwargs):
task.logger.debug(
'Event: Task success: {task.name}'.format(task=task))
@on_failure_task_signal.connect
-def failure_operation_handler(task, **kwargs):
+def _failure_operation_handler(task, **kwargs):
task.logger.error(
'Event: Task failure: {task.name}'.format(task=task),
exc_info=kwargs.get('exception', True))
@start_workflow_signal.connect
-def start_workflow_handler(context, **kwargs):
+def _start_workflow_handler(context, **kwargs):
context.logger.debug(
'Event: Starting workflow: {context.name}'.format(context=context))
@on_failure_workflow_signal.connect
-def failure_workflow_handler(context, **kwargs):
+def _failure_workflow_handler(context, **kwargs):
context.logger.debug(
'Event: Workflow failure: {context.name}'.format(context=context))
@on_success_workflow_signal.connect
-def success_workflow_handler(context, **kwargs):
+def _success_workflow_handler(context, **kwargs):
context.logger.debug(
'Event: Workflow success: {context.name}'.format(context=context))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/96746515/tests/.pylintrc
----------------------------------------------------------------------
diff --git a/tests/.pylintrc b/tests/.pylintrc
index 753d619..f6cfd7a 100644
--- a/tests/.pylintrc
+++ b/tests/.pylintrc
@@ -404,5 +404,4 @@ overgeneral-exceptions=Exception
[pre-commit-hook]
-params=--reports=no
limit=9.5
[2/2] incubator-ariatosca git commit: pylint-aria-storage
Posted by mx...@apache.org.
pylint-aria-storage
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/4f3317a0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/4f3317a0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/4f3317a0
Branch: refs/heads/pylint-aria-storage
Commit: 4f3317a0e8adc70b550bf9011aa9b04dff2e5aee
Parents: 9674651
Author: mxmrlv <mx...@gmail.com>
Authored: Wed Oct 19 17:07:45 2016 +0300
Committer: mxmrlv <mx...@gmail.com>
Committed: Thu Oct 20 18:13:28 2016 +0300
----------------------------------------------------------------------
aria/storage/__init__.py | 23 ++++++++++++++--
aria/storage/drivers.py | 11 +++++---
aria/storage/models.py | 60 ++++++++++++++++++++++++++++++++++++++---
aria/storage/structures.py | 18 +++++++++++++
4 files changed, 103 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4f3317a0/aria/storage/__init__.py
----------------------------------------------------------------------
diff --git a/aria/storage/__init__.py b/aria/storage/__init__.py
index 3f9aefa..20c73a6 100644
--- a/aria/storage/__init__.py
+++ b/aria/storage/__init__.py
@@ -72,6 +72,9 @@ __all__ = (
class ModelStorage(Storage):
+ """
+ Managing the models storage.
+ """
def __init__(self, driver, models=(), **kwargs):
"""
Simple storage client api for Aria applications.
@@ -99,12 +102,15 @@ class ModelStorage(Storage):
return super(ModelStorage, self).__getattr__(table)
def register(self, model_cls):
- # todo: add documentation
+ """
+ Registers the model type in the resource storage manager.
+ :param model_cls: the model to register.
+ """
model_name = generate_lower_name(model_cls)
model_api = _ModelApi(model_name, self.driver, model_cls)
self.registered[model_name] = model_api
- for pointer, pointer_schema_register in model_api.pointer_mapping.items():
+ for pointer_schema_register in model_api.pointer_mapping.values():
model_cls = pointer_schema_register.model_cls
self.register(model_cls)
@@ -256,6 +262,12 @@ class _ModelApi(object):
class ResourceApi(object):
+ """
+ Managing the resource in the storage, using the driver.
+
+ :param basestring name: the name of the resource.
+ :param ResourceDriver driver: the driver which supports this resource in the storage.
+ """
def __init__(self, driver, resource_name):
"""
Managing the resources in the storage, using the driver.
@@ -341,6 +353,9 @@ def generate_lower_name(model_cls):
class ResourceStorage(Storage):
+ """
+ Managing the resource storage.
+ """
def __init__(self, driver, resources=(), **kwargs):
"""
Simple storage client api for Aria applications.
@@ -353,6 +368,10 @@ class ResourceStorage(Storage):
super(ResourceStorage, self).__init__(driver, resources, **kwargs)
def register(self, resource):
+ """
+ Registers the resource type in the resource storage manager.
+ :param resource: the resource to register.
+ """
self.registered[resource] = ResourceApi(self.driver, resource_name=resource)
def __getattr__(self, resource):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4f3317a0/aria/storage/drivers.py
----------------------------------------------------------------------
diff --git a/aria/storage/drivers.py b/aria/storage/drivers.py
index 17a99a1..0ad2f49 100644
--- a/aria/storage/drivers.py
+++ b/aria/storage/drivers.py
@@ -29,7 +29,8 @@ classes:
import os
import shutil
-import distutils.dir_util
+# pylint has an issue with distutils and virtualenvs: https://github.com/PyCQA/pylint/issues/73
+import distutils.dir_util # pylint: disable=no-name-in-module, import-error
from functools import partial
from multiprocessing import RLock
@@ -216,6 +217,9 @@ class ResourceDriver(Driver):
class BaseFileSystemDriver(Driver):
+ """
+ Base class which handles storage on the file system.
+ """
def __init__(self, *args, **kwargs):
super(BaseFileSystemDriver, self).__init__(*args, **kwargs)
self._lock = RLock()
@@ -324,6 +328,7 @@ class FileSystemModelDriver(ModelDriver, BaseFileSystemDriver):
entry_dict.update(**kwargs)
self.store(name, entry_id, entry_dict)
+
class FileSystemResourceDriver(ResourceDriver, BaseFileSystemDriver):
"""
FileSystemResourceDriver context manager.
@@ -386,7 +391,7 @@ class FileSystemResourceDriver(ResourceDriver, BaseFileSystemDriver):
if os.path.isfile(resource):
shutil.copy2(resource, destination)
else:
- distutils.dir_util.copy_tree(resource, destination)
+ distutils.dir_util.copy_tree(resource, destination) # pylint: disable=no-member
def upload(self, entry_type, entry_id, source, path=None):
"""
@@ -404,4 +409,4 @@ class FileSystemResourceDriver(ResourceDriver, BaseFileSystemDriver):
if os.path.isfile(source):
shutil.copy2(source, destination)
else:
- distutils.dir_util.copy_tree(source, destination)
+ distutils.dir_util.copy_tree(source, destination) # pylint: disable=no-member
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4f3317a0/aria/storage/models.py
----------------------------------------------------------------------
diff --git a/aria/storage/models.py b/aria/storage/models.py
index d96c74a..32403ed 100644
--- a/aria/storage/models.py
+++ b/aria/storage/models.py
@@ -65,6 +65,9 @@ ENTITY_TYPES = ()
class Blueprint(Model):
+ """
+ A Model which represents a blueprint
+ """
plan = Field(type=dict)
id = Field(type=basestring, default=uuid_generator)
description = Field(type=(basestring, NoneType))
@@ -74,6 +77,9 @@ class Blueprint(Model):
class Snapshot(Model):
+ """
+ A Model which represents a snapshot
+ """
CREATED = 'created'
FAILED = 'failed'
CREATING = 'creating'
@@ -87,13 +93,15 @@ class Snapshot(Model):
class Deployment(Model):
+ """
+ A Model which represents a deployment
+ """
id = Field(type=basestring, default=uuid_generator)
description = Field(type=(basestring, NoneType))
created_at = Field(type=datetime)
updated_at = Field(type=datetime)
blueprint_id = Field(type=basestring)
workflows = Field(type=dict)
- permalink = Field(default=None) # TODO: check if needed... (old todo: implement)
inputs = Field(type=dict, default=lambda: {})
policy_types = Field(type=dict, default=lambda: {})
policy_triggers = Field(type=dict, default=lambda: {})
@@ -103,6 +111,9 @@ class Deployment(Model):
class DeploymentUpdateStep(Model):
+ """
+ A Model which represents a deployment update step
+ """
id = Field(type=basestring, default=uuid_generator)
action = Field(type=basestring, choices=ACTION_TYPES)
entity_type = Field(type=basestring, choices=ENTITY_TYPES)
@@ -123,11 +134,12 @@ class DeploymentUpdateStep(Model):
if self.action != other.action:
if self.action == 'remove':
- return True
+ return_value = True
elif self.action == 'add':
- return False
+ return_value = False
else:
- return other.action == 'add'
+ return_value = other.action == 'add'
+ return return_value
if self.action == 'add':
return self.entity_type == 'node' and other.entity_type == 'relationship'
@@ -137,6 +149,9 @@ class DeploymentUpdateStep(Model):
class DeploymentUpdate(Model):
+ """
+ A Model which represents a deployment update
+ """
INITIALIZING = 'initializing'
SUCCESSFUL = 'successful'
UPDATING = 'updating'
@@ -167,6 +182,9 @@ class DeploymentUpdate(Model):
class Execution(Model):
+ """
+ A Model which represents an execution
+ """
TERMINATED = 'terminated'
FAILED = 'failed'
CANCELLED = 'cancelled'
@@ -199,6 +217,9 @@ class Execution(Model):
class Operation(Model):
+ """
+ A Model which represents an operation
+ """
PENDING = 'pending'
STARTED = 'started'
SUCCESS = 'success'
@@ -222,6 +243,9 @@ class Operation(Model):
class Relationship(Model):
+ """
+ A Model which represents a relationship
+ """
id = Field(type=basestring, default=uuid_generator)
target_id = Field(type=basestring)
source_interfaces = Field(type=dict)
@@ -234,6 +258,9 @@ class Relationship(Model):
class Node(Model):
+ """
+ A Model which represents a node
+ """
id = Field(type=basestring, default=uuid_generator)
blueprint_id = Field(type=basestring)
type = Field(type=basestring)
@@ -251,6 +278,11 @@ class Node(Model):
max_number_of_instances = Field(type=int)
def relationships_by_target(self, target_id):
+ """
+ Retreives all of the relationship by target.
+ :param target_id: the node id of the target of the relationship
+ :yields: a relationship which target and node with the specified target_id
+ """
for relationship in self.relationships:
if relationship.target_id == target_id:
yield relationship
@@ -258,6 +290,9 @@ class Node(Model):
class RelationshipInstance(Model):
+ """
+ A Model which represents a relationship instance
+ """
id = Field(type=basestring, default=uuid_generator)
target_id = Field(type=basestring)
target_name = Field(type=basestring)
@@ -266,6 +301,9 @@ class RelationshipInstance(Model):
class NodeInstance(Model):
+ """
+ A Model which represents a node instance
+ """
# todo: add statuses
UNINITIALIZED = 'uninitialized'
INITIALIZING = 'initializing'
@@ -297,6 +335,11 @@ class NodeInstance(Model):
scaling_groups = Field(default=())
def relationships_by_target(self, target_id):
+ """
+ Retreives all of the relationship by target.
+ :param target_id: the instance id of the target of the relationship
+ :yields: a relationship instance which target and node with the specified target_id
+ """
for relationship_instance in self.relationship_instances:
if relationship_instance.target_id == target_id:
yield relationship_instance
@@ -304,6 +347,9 @@ class NodeInstance(Model):
class DeploymentModification(Model):
+ """
+ A Model which represents a deployment modification
+ """
STARTED = 'started'
FINISHED = 'finished'
ROLLEDBACK = 'rolledback'
@@ -324,12 +370,18 @@ class DeploymentModification(Model):
class ProviderContext(Model):
+ """
+ A Model which represents a provider context
+ """
id = Field(type=basestring, default=uuid_generator)
context = Field(type=dict)
name = Field(type=basestring)
class Plugin(Model):
+ """
+ A Model which represents a plugin
+ """
id = Field(type=basestring, default=uuid_generator)
package_name = Field(type=basestring)
archive_name = Field(type=basestring)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4f3317a0/aria/storage/structures.py
----------------------------------------------------------------------
diff --git a/aria/storage/structures.py b/aria/storage/structures.py
index 5ebd8b8..ea4cf3a 100644
--- a/aria/storage/structures.py
+++ b/aria/storage/structures.py
@@ -48,6 +48,9 @@ __all__ = (
def uuid_generator():
+ """
+ wrapper function which generates ids
+ """
return str(uuid4())
@@ -132,6 +135,9 @@ class Field(ValidatorMixin):
class IterField(Field):
+ """
+ Represents an iterable field.
+ """
def __init__(self, **kwargs):
"""
Simple iterable field manager.
@@ -174,6 +180,11 @@ class IterPointerField(IterField, PointerField):
class Model(object):
+ """
+ Base class for all of the storage models.
+ """
+ id = None
+
def __init__(self, **fields):
"""
Abstract class for any model in the storage.
@@ -206,6 +217,10 @@ class Model(object):
@property
def fields(self):
+ """
+ Iterates over the fields of the model.
+ :yields: the class's field name
+ """
for name, field in vars(self.__class__).items():
if isinstance(field, Field):
yield name
@@ -254,6 +269,9 @@ class Model(object):
class Storage(LoggerMixin):
+ """
+ Represents the storage
+ """
def __init__(self, driver, items=(), **kwargs):
super(Storage, self).__init__(**kwargs)
self.driver = driver