ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxmrlv <...@git.apache.org>
Subject [GitHub] incubator-ariatosca pull request #12: ARIA-3 Create an API for creating work...
Date Mon, 07 Nov 2016 10:35:48 GMT
Github user mxmrlv commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/12#discussion_r86737581
  
    --- Diff: aria/workflows/api/task.py ---
    @@ -0,0 +1,98 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#     http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +
    +"""
    +Provides the tasks to be enterd into the task graph
    +"""
    +from uuid import uuid4
    +
    +from aria import context
    +
    +
    +class BaseTask(object):
    +    """
    +    Abstract task_graph task
    +    """
    +    pass
    +
    +
    +class OperationTask(BaseTask):
    +    """
    +    Represents an operation task in the task_graph
    +    """
    +
    +    def __init__(self,
    +                 name,
    +                 operation_details,
    +                 node_instance,
    +                 inputs=None):
    +        """
    +        Creates an operation task using the name, details, node instance and any additional
kwargs.
    +        :param name: the operation of the name.
    +        :param operation_details: the details for the operation.
    +        :param node_instance: the node instance on which this operation is registered.
    +        :param inputs: operation inputs.
    +        """
    +        self.id = uuid4()
    +        self.workflow_context = context.workflow.current.get()
    +        self.name = name
    +        self.operation_details = operation_details
    +        self.node_instance = node_instance
    +        self.inputs = inputs or {}
    +
    +    def __getattr__(self, item):
    +        try:
    +            return self.__getattribute__(item)
    +        except AttributeError:
    +            return getattr(self._workflow_context.model.task.get(self._task_model.id),
item)
    +
    +
    +class WorkflowTask(BaseTask):
    +    """
    +    Represents an workflow task in the task_graph
    +    """
    +    def __init__(self, workflow_func, **kwargs):
    +        """
    +        Creates a workflow task using the workflow_func provided and its kwargs
    +        :param workflow_func: the function to run
    +        :param kwargs: the kwargs that would be passed to the workflow_func
    +        """
    +        kwargs.setdefault('ctx', context.workflow.current.get())
    +        self._graph = workflow_func(**kwargs)
    +
    +    @property
    +    def graph(self):
    +        """
    +        The graph constructed by the sub workflow
    +        :return:
    +        """
    +        return self._graph
    +
    +    def __getattr__(self, item):
    +        try:
    +            return self.__getattribute__(item)
    +        except AttributeError:
    +            try:
    +                return getattr(self._graph, item)
    +            except AttributeError:
    +                return getattr(context.workflow.current.get(), item)
    +
    +
    +class StubTask(WorkflowTask):
    --- End diff --
    
    Create common ancestor to stub and workflow (and a corresponding one to operationTask)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message