# Path: cloudify/dispatch.py
# @task
# def dispatch(__cloudify_context, *args, **kwargs):
#     dispatch_type = __cloudify_context['type']
#     dispatch_handler_cls = TASK_HANDLERS.get(dispatch_type)
#     if not dispatch_handler_cls:
#         raise exceptions.NonRecoverableError('No handler for task type: {0}'
#                                              .format(dispatch_type))
#     handler = dispatch_handler_cls(cloudify_context=__cloudify_context,
#                                    args=args,
#                                    kwargs=kwargs)
#     return handler.handle_or_dispatch_to_subprocess_if_remote()
# 
# Path: cloudify/workflows/workflow_context.py
# DEFAULT_LOCAL_TASK_THREAD_POOL_SIZE = 1


import os
import tempfile
import copy
import importlib
import shutil
import uuid
import json
import threading
from StringIO import StringIO
from contextlib import contextmanager
from cloudify_rest_client.nodes import Node
from cloudify_rest_client.node_instances import NodeInstance
from cloudify import dispatch
from cloudify.workflows.workflow_context import (
    DEFAULT_LOCAL_TASK_THREAD_POOL_SIZE)
    from dsl_parser.constants import HOST_TYPE
    from dsl_parser import parser as dsl_parser, tasks as dsl_tasks
    from dsl_parser import functions as dsl_functions
                subgraph_retries=0,
                task_thread_pool_size=DEFAULT_LOCAL_TASK_THREAD_POOL_SIZE):
        workflows = self.plan['workflows']
        workflow_name = workflow
        if workflow_name not in workflows:
            raise ValueError("'{0}' workflow does not exist. "
                             "existing workflows are: {1}"
                             .format(workflow_name,
                                     workflows.keys()))

        workflow = workflows[workflow_name]
        execution_id = str(uuid.uuid4())
        ctx = {
            'type': 'workflow',
            'local': True,
            'deployment_id': self.name,
            'blueprint_id': self.name,
            'execution_id': execution_id,
            'workflow_id': workflow_name,
            'storage': self.storage,
            'task_retries': task_retries,
            'task_retry_interval': task_retry_interval,
            'subgraph_retries': subgraph_retries,
            'local_task_thread_pool_size': task_thread_pool_size,
            'task_name': workflow['operation']
        }

        merged_parameters = _merge_and_validate_execution_parameters(
            workflow, workflow_name, parameters, allow_custom_parameters)


# Path: cloudify/dispatch.py
# @task
# def dispatch(__cloudify_context, *args, **kwargs):
#     dispatch_type = __cloudify_context['type']
#     dispatch_handler_cls = TASK_HANDLERS.get(dispatch_type)
#     if not dispatch_handler_cls:
#         raise exceptions.NonRecoverableError('No handler for task type: {0}'
#                                              .format(dispatch_type))
#     handler = dispatch_handler_cls(cloudify_context=__cloudify_context,
#                                    args=args,
#                                    kwargs=kwargs)
#     return handler.handle_or_dispatch_to_subprocess_if_remote()
# 
# Path: cloudify/workflows/workflow_context.py
# DEFAULT_LOCAL_TASK_THREAD_POOL_SIZE = 1


# Path: cloudify/workflows/local.py
import os
import tempfile
import copy
import importlib
import shutil
import uuid
import json
import threading
from StringIO import StringIO
from contextlib import contextmanager
from cloudify_rest_client.nodes import Node
from cloudify_rest_client.node_instances import NodeInstance
from cloudify import dispatch
from cloudify.workflows.workflow_context import (
    DEFAULT_LOCAL_TASK_THREAD_POOL_SIZE)
    from dsl_parser.constants import HOST_TYPE
    from dsl_parser import parser as dsl_parser, tasks as dsl_tasks
    from dsl_parser import functions as dsl_functions

                subgraph_retries=0,
                task_thread_pool_size=DEFAULT_LOCAL_TASK_THREAD_POOL_SIZE):
        workflows = self.plan['workflows']
        workflow_name = workflow
        if workflow_name not in workflows:
            raise ValueError("'{0}' workflow does not exist. "
                             "existing workflows are: {1}"
                             .format(workflow_name,
                                     workflows.keys()))

        workflow = workflows[workflow_name]
        execution_id = str(uuid.uuid4())
        ctx = {
            'type': 'workflow',
            'local': True,
            'deployment_id': self.name,
            'blueprint_id': self.name,
            'execution_id': execution_id,
            'workflow_id': workflow_name,
            'storage': self.storage,
            'task_retries': task_retries,
            'task_retry_interval': task_retry_interval,
            'subgraph_retries': subgraph_retries,
            'local_task_thread_pool_size': task_thread_pool_size,
            'task_name': workflow['operation']
        }

        merged_parameters = _merge_and_validate_execution_parameters(
            workflow, workflow_name, parameters, allow_custom_parameters)


        return dispatch.dispatch(__cloudify_context=ctx, **merged_parameters)