PageRenderTime 88ms CodeModel.GetById 26ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 1ms

/boto-2.5.2/boto/swf/layer1.py

#
Python | 1561 lines | 1508 code | 15 blank | 38 comment | 8 complexity | e24ad04478a4b095bdefef97f503ffdf MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
   2# Copyright (c) 2012 Amazon.com, Inc. or its affiliates.
   3# All Rights Reserved
   4#
   5# Permission is hereby granted, free of charge, to any person obtaining a
   6# copy of this software and associated documentation files (the
   7# "Software"), to deal in the Software without restriction, including
   8# without limitation the rights to use, copy, modify, merge, publish, dis-
   9# tribute, sublicense, and/or sell copies of the Software, and to permit
  10# persons to whom the Software is furnished to do so, subject to the fol-
  11# lowing conditions:
  12#
  13# The above copyright notice and this permission notice shall be included
  14# in all copies or substantial portions of the Software.
  15#
  16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  18# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  19# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
  20# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22# IN THE SOFTWARE.
  23#
  24
  25import boto
  26from boto.connection import AWSAuthConnection
  27from boto.provider import Provider
  28from boto.exception import SWFResponseError
  29from boto.swf import exceptions as swf_exceptions
  30
  31import time
  32try:
  33    import simplejson as json
  34except ImportError:
  35    import json
  36
  37#
  38# To get full debug output, uncomment the following line and set the
  39# value of Debug to be 2
  40#
  41#boto.set_stream_logger('swf')
  42Debug=0
  43
  44class Layer1(AWSAuthConnection):
  45    """
  46    Low-level interface to Simple WorkFlow Service.
  47    """
  48
  49    DefaultRegionName = 'us-east-1'
  50    """The default region name for Simple Workflow."""
  51
  52    ServiceName = 'com.amazonaws.swf.service.model.SimpleWorkflowService'
  53    """The name of the Service"""
  54
  55    # In some cases, the fault response __type value is mapped to
  56    # an exception class more specific than SWFResponseError.
  57    _fault_excp = {
  58        'com.amazonaws.swf.base.model#DomainAlreadyExistsFault':
  59            swf_exceptions.SWFDomainAlreadyExistsError,
  60        'com.amazonaws.swf.base.model#LimitExceededFault':
  61            swf_exceptions.SWFLimitExceededError,
  62        'com.amazonaws.swf.base.model#OperationNotPermittedFault':
  63            swf_exceptions.SWFOperationNotPermittedError,
  64        'com.amazonaws.swf.base.model#TypeAlreadyExistsFault':
  65            swf_exceptions.SWFTypeAlreadyExistsError,
  66    }
  67
  68    ResponseError = SWFResponseError
  69
  70    def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
  71                 is_secure=True, port=None, proxy=None, proxy_port=None,
  72                 debug=0, session_token=None, region=None):
  73        if not region:
  74            region_name = boto.config.get('SWF', 'region',
  75                                          self.DefaultRegionName)
  76            for reg in boto.swf.regions():
  77                if reg.name == region_name:
  78                    region = reg
  79                    break
  80
  81        self.region = region
  82        AWSAuthConnection.__init__(self, self.region.endpoint,
  83                                   aws_access_key_id, aws_secret_access_key,
  84                                   is_secure, port, proxy, proxy_port,
  85                                   debug, session_token)
  86
  87    def _required_auth_capability(self):
  88        return ['hmac-v3-http']
  89
  90    def _credentials_expired(self, response):
  91        if response.status != 400:
  92            return False
  93        try:
  94            parsed = json.loads(response.read())
  95            # It seems that SWF doesn't really have a specific "Token Expired"
  96            # message, but this is a best effort heuristic.
  97            expected = 'com.amazon.coral.service#UnrecognizedClientException'
  98            return (parsed['__type'] == expected and \
  99                    'security token' in parsed['message'])
 100        except Exception, e:
 101            return False
 102        return False
 103
 104    def make_request(self, action, body='', object_hook=None):
 105        """
 106        :raises: ``SWFResponseError`` if response status is not 200.
 107        """
 108        headers = {'X-Amz-Target': '%s.%s' % (self.ServiceName, action),
 109                   'Host': self.region.endpoint,
 110                   'Content-Type': 'application/json; charset=UTF-8',
 111                   'Content-Encoding': 'amz-1.0',
 112                   'Content-Length': str(len(body))}
 113        http_request = self.build_base_http_request('POST', '/', '/',
 114                                                    {}, headers, body, None)
 115        response = self._mexe(http_request, sender=None,
 116                              override_num_retries=10)
 117        response_body = response.read()
 118        boto.log.debug(response_body)
 119        if response.status == 200:
 120            if response_body:
 121                return json.loads(response_body, object_hook=object_hook)
 122            else:
 123                return None
 124        else:
 125            json_body = json.loads(response_body)
 126            fault_name = json_body.get('__type', None)
 127            # Certain faults get mapped to more specific exception classes.
 128            excp_cls = self._fault_excp.get(fault_name, self.ResponseError)
 129            raise excp_cls(response.status, response.reason, body=json_body)
 130
 131
 132
 133    # Actions related to Activities
 134        
 135    def poll_for_activity_task(self, domain, task_list, identity=None):
 136        """
 137        Used by workers to get an ActivityTask from the specified
 138        activity taskList. This initiates a long poll, where the
 139        service holds the HTTP connection open and responds as soon as
 140        a task becomes available. The maximum time the service holds
 141        on to the request before responding is 60 seconds. If no task
 142        is available within 60 seconds, the poll will return an empty
 143        result. An empty result, in this context, means that an
 144        ActivityTask is returned, but that the value of taskToken is
 145        an empty string. If a task is returned, the worker should use
 146        its type to identify and process it correctly.
 147
 148        :type domain: string
 149        :param domain: The name of the domain that contains the task
 150            lists being polled.
 151
 152        :type task_list: string
 153        :param task_list: Specifies the task list to poll for activity tasks.
 154
 155        :type identity: string
 156        :param identity: Identity of the worker making the request, which
 157            is recorded in the ActivityTaskStarted event in the workflow
 158            history. This enables diagnostic tracing when problems arise.
 159            The form of this identity is user defined.
 160
 161        :raises: UnknownResourceFault, OperationNotPermittedFault
 162        """
 163        data = {'domain': domain, 'taskList': {'name': task_list}}
 164        if identity:
 165            data['identity'] = identity
 166        json_input = json.dumps(data)
 167        return self.make_request('PollForActivityTask', json_input)
 168
 169    def respond_activity_task_completed(self, task_token, result=None):
 170        """
 171        Used by workers to tell the service that the ActivityTask
 172        identified by the taskToken completed successfully with a
 173        result (if provided).
 174
 175        :type task_token: string
 176        :param task_token: The taskToken of the ActivityTask.
 177
 178        :type result: string
 179        :param result: The result of the activity task. It is a free
 180            form string that is implementation specific.
 181
 182        :raises: UnknownResourceFault, OperationNotPermittedFault
 183        """
 184        data = {'taskToken': task_token}
 185        if result:
 186            data['result'] = result
 187        json_input = json.dumps(data)
 188        return self.make_request('RespondActivityTaskCompleted', json_input)
 189
 190    def respond_activity_task_failed(self, task_token,
 191                                     details=None, reason=None):
 192        """
 193        Used by workers to tell the service that the ActivityTask
 194        identified by the taskToken has failed with reason (if
 195        specified).
 196
 197        :type task_token: string
 198        :param task_token: The taskToken of the ActivityTask.
 199
 200        :type details: string
 201        :param details: Optional detailed information about the failure.
 202
 203        :type reason: string
 204        :param reason: Description of the error that may assist in diagnostics.
 205
 206        :raises: UnknownResourceFault, OperationNotPermittedFault
 207        """
 208        data = {'taskToken': task_token}
 209        if details:
 210            data['details'] = details
 211        if reason:
 212            data['reason'] = reason
 213        json_input = json.dumps(data)
 214        return self.make_request('RespondActivityTaskFailed', json_input)
 215
 216    def respond_activity_task_canceled(self, task_token, details=None):
 217        """
 218        Used by workers to tell the service that the ActivityTask
 219        identified by the taskToken was successfully
 220        canceled. Additional details can be optionally provided using
 221        the details argument.
 222
 223        :type task_token: string
 224        :param task_token: The taskToken of the ActivityTask.
 225
 226        :type details: string
 227        :param details: Optional detailed information about the failure.
 228
 229        :raises: UnknownResourceFault, OperationNotPermittedFault
 230        """
 231        data = {'taskToken': task_token}
 232        if details:
 233            data['details'] = details
 234        json_input = json.dumps(data)
 235        return self.make_request('RespondActivityTaskCanceled', json_input)
 236
 237    def record_activity_task_heartbeat(self, task_token, details=None):
 238        """
 239        Used by activity workers to report to the service that the
 240        ActivityTask represented by the specified taskToken is still
 241        making progress. The worker can also (optionally) specify
 242        details of the progress, for example percent complete, using
 243        the details parameter. This action can also be used by the
 244        worker as a mechanism to check if cancellation is being
 245        requested for the activity task. If a cancellation is being
 246        attempted for the specified task, then the boolean
 247        cancelRequested flag returned by the service is set to true.
 248
 249        :type task_token: string
 250        :param task_token: The taskToken of the ActivityTask.
 251
 252        :type details: string
 253        :param details: If specified, contains details about the
 254            progress of the task.
 255
 256        :raises: UnknownResourceFault, OperationNotPermittedFault
 257        """
 258        data = {'taskToken': task_token}
 259        if details:
 260            data['details'] = details
 261        json_input = json.dumps(data)
 262        return self.make_request('RecordActivityTaskHeartbeat', json_input)
 263
 264    # Actions related to Deciders
 265
 266    def poll_for_decision_task(self, domain, task_list, identity=None,
 267                               maximum_page_size=None,
 268                               next_page_token=None,
 269                               reverse_order=None):
 270        """
 271        Used by deciders to get a DecisionTask from the specified
 272        decision taskList. A decision task may be returned for any
 273        open workflow execution that is using the specified task
 274        list. The task includes a paginated view of the history of the
 275        workflow execution. The decider should use the workflow type
 276        and the history to determine how to properly handle the task.
 277
 278        :type domain: string
 279        :param domain: The name of the domain containing the task
 280            lists to poll.
 281
 282        :type task_list: string
 283        :param task_list: Specifies the task list to poll for decision tasks.
 284
 285        :type identity: string
 286        :param identity: Identity of the decider making the request,
 287            which is recorded in the DecisionTaskStarted event in the
 288            workflow history. This enables diagnostic tracing when
 289            problems arise. The form of this identity is user defined.
 290
 291        :type maximum_page_size: integer :param maximum_page_size: The
 292            maximum number of history events returned in each page. The
 293            default is 100, but the caller can override this value to a
 294            page size smaller than the default. You cannot specify a page
 295            size greater than 100.
 296
 297        :type next_page_token: string
 298        :param next_page_token: If on a previous call to this method a
 299            NextPageToken was returned, the results are being paginated.
 300            To get the next page of results, repeat the call with the
 301            returned token and all other arguments unchanged.
 302
 303        :type reverse_order: boolean
 304        :param reverse_order: When set to true, returns the events in
 305            reverse order. By default the results are returned in
 306            ascending order of the eventTimestamp of the events.
 307
 308        :raises: UnknownResourceFault, OperationNotPermittedFault
 309        """
 310        data = {'domain': domain, 'taskList': {'name': task_list}}
 311        if identity:
 312            data['identity'] = identity
 313        if maximum_page_size:
 314            data['maximumPageSize'] = maximum_page_size
 315        if next_page_token:
 316            data['nextPageToken'] = next_page_token
 317        if reverse_order:
 318            data['reverseOrder'] = 'true'
 319        json_input = json.dumps(data)
 320        return self.make_request('PollForDecisionTask', json_input)
 321
 322    def respond_decision_task_completed(self, task_token,
 323                                        decisions=None,
 324                                        execution_context=None):
 325        """
 326        Used by deciders to tell the service that the DecisionTask
 327        identified by the taskToken has successfully completed.
 328        The decisions argument specifies the list of decisions
 329        made while processing the task.
 330
 331        :type task_token: string
 332        :param task_token: The taskToken of the ActivityTask.
 333
 334        :type decisions: list
 335        :param decisions: The list of decisions (possibly empty) made by
 336            the decider while processing this decision task. See the docs
 337            for the Decision structure for details.
 338
 339        :type execution_context: string
 340        :param execution_context: User defined context to add to
 341            workflow execution.
 342
 343        :raises: #UnknownResourceFault, #OperationNotPermittedFault
 344        """
 345        data = {'taskToken': task_token}
 346        if decisions:
 347            data['decisions'] = decisions
 348        if execution_context:
 349            data['executionContext'] = execution_context
 350        json_input = json.dumps(data)
 351        return self.make_request('RespondDecisionTaskCompleted', json_input)
 352
 353    def request_cancel_workflow_execution(self, domain, workflow_id,
 354                                          run_id=None):
 355        """
 356        Records a WorkflowExecutionCancelRequested event in the
 357        currently running workflow execution identified by the given
 358        domain, workflowId, and runId. This logically requests the
 359        cancellation of the workflow execution as a whole. It is up to
 360        the decider to take appropriate actions when it receives an
 361        execution history with this event.
 362
 363        :type domain: string
 364        :param domain: The name of the domain containing the workflow
 365            execution to cancel.
 366
 367        :type run_id: string
 368        :param run_id: The runId of the workflow execution to cancel.
 369
 370        :type workflow_id: string
 371        :param workflow_id: The workflowId of the workflow execution
 372            to cancel.
 373
 374        :raises: UnknownResourceFault, OperationNotPermittedFault
 375        """
 376        data = {'domain': domain, 'workflowId': workflow_id}
 377        if run_id:
 378            data['runId'] = run_id
 379        json_input = json.dumps(data)
 380        return self.make_request('RequestCancelWorkflowExecution', json_input)
 381
 382    def start_workflow_execution(self, domain, workflow_id,
 383                                 workflow_name, workflow_version,
 384                                 task_list=None, child_policy=None,
 385                                 execution_start_to_close_timeout=None,
 386                                 input=None, tag_list=None,
 387                                 task_start_to_close_timeout=None):
 388        """
 389        Starts an execution of the workflow type in the specified
 390        domain using the provided workflowId and input data.
 391
 392        :type domain: string
 393        :param domain: The name of the domain in which the workflow
 394            execution is created.
 395
 396        :type workflow_id: string
 397        :param workflow_id: The user defined identifier associated with
 398            the workflow execution. You can use this to associate a
 399            custom identifier with the workflow execution. You may
 400            specify the same identifier if a workflow execution is
 401            logically a restart of a previous execution. You cannot
 402            have two open workflow executions with the same workflowId
 403            at the same time.
 404
 405        :type workflow_name: string
 406        :param workflow_name: The name of the workflow type.
 407
 408        :type workflow_version: string
 409        :param workflow_version: The version of the workflow type.
 410
 411        :type task_list: string
 412        :param task_list: The task list to use for the decision tasks
 413            generated for this workflow execution. This overrides the
 414            defaultTaskList specified when registering the workflow type.
 415
 416        :type child_policy: string
 417        :param child_policy: If set, specifies the policy to use for the
 418            child workflow executions of this workflow execution if it
 419            is terminated, by calling the TerminateWorkflowExecution
 420            action explicitly or due to an expired timeout. This policy
 421            overrides the default child policy specified when registering
 422            the workflow type using RegisterWorkflowType. The supported
 423            child policies are:
 424
 425             * TERMINATE: the child executions will be terminated.
 426             * REQUEST_CANCEL: a request to cancel will be attempted
 427                 for each child execution by recording a
 428                 WorkflowExecutionCancelRequested event in its history.
 429                 It is up to the decider to take appropriate actions
 430                 when it receives an execution history with this event.
 431             * ABANDON: no action will be taken. The child executions
 432                 will continue to run.
 433                 
 434        :type execution_start_to_close_timeout: string
 435        :param execution_start_to_close_timeout: The total duration for
 436            this workflow execution. This overrides the
 437            defaultExecutionStartToCloseTimeout specified when
 438            registering the workflow type.
 439
 440        :type input: string
 441        :param input: The input for the workflow
 442            execution. This is a free form string which should be
 443            meaningful to the workflow you are starting. This input is
 444            made available to the new workflow execution in the
 445            WorkflowExecutionStarted history event.
 446
 447        :type tag_list: list :param tag_list: The list of tags to
 448            associate with the workflow execution. You can specify a
 449            maximum of 5 tags. You can list workflow executions with a
 450            specific tag by calling list_open_workflow_executions or
 451            list_closed_workflow_executions and specifying a TagFilter.
 452
 453        :type task_start_to_close_timeout: string :param
 454        task_start_to_close_timeout: Specifies the maximum duration of
 455            decision tasks for this workflow execution. This parameter
 456            overrides the defaultTaskStartToCloseTimout specified when
 457            registering the workflow type using register_workflow_type.
 458
 459        :raises: UnknownResourceFault, TypeDeprecatedFault,
 460            WorkflowExecutionAlreadyStartedFault, LimitExceededFault,
 461            OperationNotPermittedFault, DefaultUndefinedFault
 462        """
 463        data = {'domain': domain, 'workflowId': workflow_id}
 464        data['workflowType'] = {'name': workflow_name,
 465                                'version': workflow_version}
 466        if task_list:
 467            data['taskList'] = {'name': task_list}
 468        if child_policy:
 469            data['childPolicy'] = child_policy
 470        if execution_start_to_close_timeout:
 471            data['executionStartToCloseTimeout'] = execution_start_to_close_timeout
 472        if input:
 473            data['input'] = input
 474        if tag_list:
 475            data['tagList'] = tag_list
 476        if task_start_to_close_timeout:
 477            data['taskStartToCloseTimeout'] = task_start_to_close_timeout
 478        json_input = json.dumps(data)
 479        return self.make_request('StartWorkflowExecution', json_input)
 480
 481    def signal_workflow_execution(self, domain, signal_name, workflow_id,
 482                                  input=None, run_id=None):
 483        """
 484        Records a WorkflowExecutionSignaled event in the workflow
 485        execution history and creates a decision task for the workflow
 486        execution identified by the given domain, workflowId and
 487        runId. The event is recorded with the specified user defined
 488        signalName and input (if provided).
 489
 490        :type domain: string
 491        :param domain: The name of the domain containing the workflow
 492            execution to signal.
 493
 494        :type signal_name: string
 495        :param signal_name: The name of the signal. This name must be
 496            meaningful to the target workflow.
 497
 498        :type workflow_id: string
 499        :param workflow_id: The workflowId of the workflow execution
 500            to signal.
 501
 502        :type input: string
 503        :param input: Data to attach to the WorkflowExecutionSignaled
 504            event in the target workflow execution's history.
 505
 506        :type run_id: string
 507        :param run_id: The runId of the workflow execution to signal.
 508
 509        :raises: UnknownResourceFault, OperationNotPermittedFault
 510        """
 511        data = {'domain': domain, 'signalName': signal_name,
 512                'workflowId': workflow_id}
 513        if input:
 514            data['input'] = input
 515        if run_id:
 516            data['runId'] = run_id
 517        json_input = json.dumps(data)
 518        return self.make_request('SignalWorkflowExecution', json_input)
 519
 520    def terminate_workflow_execution(self, domain, workflow_id,
 521                                     child_policy=None, details=None,
 522                                     reason=None, run_id=None):
 523        """
 524        Records a WorkflowExecutionTerminated event and forces closure
 525        of the workflow execution identified by the given domain,
 526        runId, and workflowId. The child policy, registered with the
 527        workflow type or specified when starting this execution, is
 528        applied to any open child workflow executions of this workflow
 529        execution.
 530
 531        :type domain: string
 532        :param domain: The domain of the workflow execution to terminate.
 533
 534        :type workflow_id: string
 535        :param workflow_id: The workflowId of the workflow execution
 536            to terminate.
 537
 538        :type child_policy: string
 539        :param child_policy: If set, specifies the policy to use for
 540            the child workflow executions of the workflow execution being
 541            terminated. This policy overrides the child policy specified
 542            for the workflow execution at registration time or when
 543            starting the execution. The supported child policies are:
 544
 545            * TERMINATE: the child executions will be terminated.
 546            
 547            * REQUEST_CANCEL: a request to cancel will be attempted
 548              for each child execution by recording a
 549              WorkflowExecutionCancelRequested event in its
 550              history. It is up to the decider to take appropriate
 551              actions when it receives an execution history with this
 552              event.
 553            
 554            * ABANDON: no action will be taken. The child executions
 555              will continue to run.
 556
 557        :type details: string
 558        :param details: Optional details for terminating the
 559            workflow execution.
 560
 561        :type reason: string
 562        :param reason: An optional descriptive reason for terminating
 563            the workflow execution.
 564
 565        :type run_id: string
 566        :param run_id: The runId of the workflow execution to terminate.
 567
 568        :raises: UnknownResourceFault, OperationNotPermittedFault
 569        """
 570        data = {'domain': domain, 'workflowId': workflow_id}
 571        if child_policy:
 572            data['childPolicy'] = child_policy
 573        if details:
 574            data['details'] = details
 575        if reason:
 576            data['reason'] = reason
 577        if run_id:
 578            data['runId'] = run_id
 579        json_input = json.dumps(data)
 580        return self.make_request('TerminateWorkflowExecution', json_input)
 581
 582# Actions related to Administration
 583
 584## Activity Management
 585
 586    def register_activity_type(self, domain, name, version, task_list=None,
 587                               default_task_heartbeat_timeout=None,
 588                               default_task_schedule_to_close_timeout=None,
 589                               default_task_schedule_to_start_timeout=None,
 590                               default_task_start_to_close_timeout=None,
 591                               description=None):
 592        """
 593        Registers a new activity type along with its configuration
 594        settings in the specified domain.
 595
 596        :type domain: string
 597        :param domain: The name of the domain in which this activity is
 598            to be registered.
 599
 600        :type name: string
 601        :param name: The name of the activity type within the domain.
 602
 603        :type version: string
 604        :param version: The version of the activity type.
 605
 606        :type task_list: string
 607        :param task_list: If set, specifies the default task list to
 608            use for scheduling tasks of this activity type. This default
 609            task list is used if a task list is not provided when a task
 610            is scheduled through the schedule_activity_task Decision.
 611
 612        :type default_task_heartbeat_timeout: string
 613        :param default_task_heartbeat_timeout: If set, specifies the
 614            default maximum time before which a worker processing a task
 615            of this type must report progress by calling
 616            RecordActivityTaskHeartbeat. If the timeout is exceeded, the
 617            activity task is automatically timed out. This default can be
 618            overridden when scheduling an activity task using the
 619            ScheduleActivityTask Decision. If the activity worker
 620            subsequently attempts to record a heartbeat or returns a
 621            result, the activity worker receives an UnknownResource
 622            fault. In this case, Amazon SWF no longer considers the
 623            activity task to be valid; the activity worker should clean up
 624            the activity task.no docs
 625
 626        :type default_task_schedule_to_close_timeout: string
 627        :param default_task_schedule_to_close_timeout: If set,
 628            specifies the default maximum duration for a task of this
 629            activity type. This default can be overridden when scheduling
 630            an activity task using the ScheduleActivityTask Decision.no
 631            docs
 632
 633        :type default_task_schedule_to_start_timeout: string
 634        :param default_task_schedule_to_start_timeout: If set,
 635            specifies the default maximum duration that a task of this
 636            activity type can wait before being assigned to a worker. This
 637            default can be overridden when scheduling an activity task
 638            using the ScheduleActivityTask Decision.
 639
 640        :type default_task_start_to_close_timeout: string
 641        :param default_task_start_to_close_timeout: If set, specifies
 642            the default maximum duration that a worker can take to process
 643            tasks of this activity type. This default can be overridden
 644            when scheduling an activity task using the
 645            ScheduleActivityTask Decision.
 646
 647        :type description: string
 648        :param description: A textual description of the activity type.
 649
 650        :raises: TypeAlreadyExistsFault, LimitExceededFault,
 651            UnknownResourceFault, OperationNotPermittedFault
 652        """
 653        data = {'domain': domain, 'name': name,'version': version}
 654        if task_list:
 655            data['taskList'] = {'name': task_list}
 656        if default_task_heartbeat_timeout:
 657            data['defaultTaskHeartbeatTimeout'] = default_task_heartbeat_timeout
 658        if default_task_schedule_to_close_timeout:
 659            data['defaultTaskScheduleToCloseTimeout'] = default_task_schedule_to_close_timeout
 660        if default_task_schedule_to_start_timeout:
 661            data['defaultTaskScheduleToStartTimeout'] = default_task_schedule_to_start_timeout
 662        if default_task_start_to_close_timeout:
 663            data['defaultTaskStartToCloseTimeout'] = default_task_start_to_close_timeout
 664        if description:
 665            data['description'] = description
 666        json_input = json.dumps(data)
 667        return self.make_request('RegisterActivityType', json_input)
 668
 669    def deprecate_activity_type(self, domain, activity_name, activity_version):
 670        """
 671        Returns information about the specified activity type. This
 672        includes configuration settings provided at registration time
 673        as well as other general information about the type.
 674
 675        :type domain: string
 676        :param domain: The name of the domain in which the activity
 677            type is registered.
 678
 679        :type activity_name: string
 680        :param activity_name: The name of this activity.
 681
 682        :type activity_version: string
 683        :param activity_version: The version of this activity.
 684
 685        :raises: UnknownResourceFault, TypeDeprecatedFault,
 686            OperationNotPermittedFault
 687        """
 688        data = {'domain': domain}
 689        data['activityType'] = {'name': activity_name,
 690                                'version': activity_version}
 691        json_input = json.dumps(data)
 692        return self.make_request('DeprecateActivityType', json_input)
 693
 694## Workflow Management
 695
 696    def register_workflow_type(self, domain, name, version,
 697                               task_list=None,
 698                               default_child_policy=None,
 699                               default_execution_start_to_close_timeout=None,
 700                               default_task_start_to_close_timeout=None,
 701                               description=None):
 702        """
 703        Registers a new workflow type and its configuration settings
 704        in the specified domain.
 705
 706        :type domain: string
 707        :param domain: The name of the domain in which to register
 708            the workflow type.
 709
 710        :type name: string
 711        :param name: The name of the workflow type.
 712
 713        :type version: string
 714        :param version: The version of the workflow type.
 715
 716        :type task_list: list of name, version of tasks
 717        :param name: If set, specifies the default task list to use
 718            for scheduling decision tasks for executions of this workflow
 719            type. This default is used only if a task list is not provided
 720            when starting the execution through the StartWorkflowExecution
 721            Action or StartChildWorkflowExecution Decision.
 722
 723        :type default_child_policy: string
 724        
 725        :param default_child_policy: If set, specifies the default
 726            policy to use for the child workflow executions when a
 727            workflow execution of this type is terminated, by calling the
 728            TerminateWorkflowExecution action explicitly or due to an
 729            expired timeout. This default can be overridden when starting
 730            a workflow execution using the StartWorkflowExecution action
 731            or the StartChildWorkflowExecution Decision. The supported
 732            child policies are:
 733
 734            * TERMINATE: the child executions will be terminated.
 735            
 736            * REQUEST_CANCEL: a request to cancel will be attempted
 737              for each child execution by recording a
 738              WorkflowExecutionCancelRequested event in its
 739              history. It is up to the decider to take appropriate
 740              actions when it receives an execution history with this
 741              event.
 742            
 743            * ABANDON: no action will be taken. The child executions
 744              will continue to run.no docs
 745
 746        :type default_execution_start_to_close_timeout: string
 747        :param default_execution_start_to_close_timeout: If set,
 748            specifies the default maximum duration for executions of this
 749            workflow type. You can override this default when starting an
 750            execution through the StartWorkflowExecution Action or
 751            StartChildWorkflowExecution Decision.
 752
 753        :type default_task_start_to_close_timeout: string
 754        :param default_task_start_to_close_timeout: If set, specifies
 755            the default maximum duration of decision tasks for this
 756            workflow type. This default can be overridden when starting a
 757            workflow execution using the StartWorkflowExecution action or
 758            the StartChildWorkflowExecution Decision.
 759
 760        :type description: string
 761        :param description: Textual description of the workflow type.
 762
 763        :raises: TypeAlreadyExistsFault, LimitExceededFault,
 764            UnknownResourceFault, OperationNotPermittedFault
 765        """
 766        data = {'domain': domain, 'name': name, 'version': version}
 767        if task_list:
 768            data['defaultTaskList'] = {'name': task_list}
 769        if default_child_policy:
 770            data['defaultChildPolicy'] = default_child_policy
 771        if default_execution_start_to_close_timeout:
 772            data['defaultExecutionStartToCloseTimeout'] = default_execution_start_to_close_timeout
 773        if default_task_start_to_close_timeout:
 774            data['defaultTaskStartToCloseTimeout'] = default_task_start_to_close_timeout
 775        if description:
 776            data['description'] = description
 777        json_input = json.dumps(data)
 778        return self.make_request('RegisterWorkflowType', json_input)
 779
 780    def deprecate_workflow_type(self, domain, workflow_name, workflow_version):
 781        """
 782        Deprecates the specified workflow type. After a workflow type
 783        has been deprecated, you cannot create new executions of that
 784        type. Executions that were started before the type was
 785        deprecated will continue to run. A deprecated workflow type
 786        may still be used when calling visibility actions.
 787
 788        :type domain: string
 789        :param domain: The name of the domain in which the workflow
 790            type is registered.
 791
 792        :type workflow_name: string
 793        :param workflow_name: The name of the workflow type.
 794
 795        :type workflow_version: string
 796        :param workflow_version: The version of the workflow type.
 797
 798        :raises: UnknownResourceFault, TypeDeprecatedFault,
 799            OperationNotPermittedFault
 800        """
 801        data = {'domain': domain}
 802        data['workflowType'] = {'name': workflow_name,
 803                                'version': workflow_version}
 804        json_input = json.dumps(data)
 805        return self.make_request('DeprecateWorkflowType', json_input)
 806
 807## Domain Management
 808
 809    def register_domain(self, name,
 810                        workflow_execution_retention_period_in_days,
 811                        description=None):
 812        """
 813        Registers a new domain.
 814
 815        :type name: string
 816        :param name: Name of the domain to register. The name must be unique.
 817
 818        :type workflow_execution_retention_period_in_days: string
 819        
 820        :param workflow_execution_retention_period_in_days: Specifies
 821            the duration *in days* for which the record (including the
 822            history) of workflow executions in this domain should be kept
 823            by the service. After the retention period, the workflow
 824            execution will not be available in the results of visibility
 825            calls. If a duration of NONE is specified, the records for
 826            workflow executions in this domain are not retained at all.
 827
 828        :type description: string
 829        :param description: Textual description of the domain.
 830
 831        :raises: DomainAlreadyExistsFault, LimitExceededFault,
 832            OperationNotPermittedFault
 833        """
 834        data = {'name': name,
 835                'workflowExecutionRetentionPeriodInDays': workflow_execution_retention_period_in_days}
 836        if description:
 837            data['description'] = description
 838        json_input = json.dumps(data)
 839        return self.make_request('RegisterDomain', json_input)
 840
 841    def deprecate_domain(self, name):
 842        """
 843        Deprecates the specified domain. After a domain has been
 844        deprecated it cannot be used to create new workflow executions
 845        or register new types. However, you can still use visibility
 846        actions on this domain. Deprecating a domain also deprecates
 847        all activity and workflow types registered in the
 848        domain. Executions that were started before the domain was
 849        deprecated will continue to run.
 850
 851        :type name: string
 852        :param name: The name of the domain to deprecate.
 853
 854        :raises: UnknownResourceFault, DomainDeprecatedFault,
 855            OperationNotPermittedFault
 856        """
 857        data = {'name': name}
 858        json_input = json.dumps(data)
 859        return self.make_request('DeprecateDomain', json_input)
 860
 861# Visibility Actions
 862
 863## Activity Visibility
 864
 865    def list_activity_types(self, domain, registration_status,
 866                            name=None,
 867                            maximum_page_size=None,
 868                            next_page_token=None, reverse_order=None):
 869        """
 870        Returns information about all activities registered in the
 871        specified domain that match the specified name and
 872        registration status. The result includes information like
 873        creation date, current status of the activity, etc. The
 874        results may be split into multiple pages. To retrieve
 875        subsequent pages, make the call again using the nextPageToken
 876        returned by the initial call.
 877
 878        :type domain: string
 879        :param domain: The name of the domain in which the activity
 880            types have been registered.
 881
 882        :type registration_status: string
 883        :param registration_status: Specifies the registration status
 884            of the activity types to list.  Valid values are:
 885
 886            * REGISTERED
 887            * DEPRECATED
 888
 889        :type name: string
 890        :param name: If specified, only lists the activity types that
 891            have this name.
 892
 893        :type maximum_page_size: integer
 894        :param maximum_page_size: The maximum number of results
 895            returned in each page. The default is 100, but the caller can
 896            override this value to a page size smaller than the
 897            default. You cannot specify a page size greater than 100.
 898
 899        :type next_page_token: string
 900        :param next_page_token: If on a previous call to this method a
 901            NextResultToken was returned, the results have more than one
 902            page. To get the next page of results, repeat the call with
 903            the nextPageToken and keep all other arguments unchanged.
 904        
 905        :type reverse_order: boolean
 906        
 907        :param reverse_order: When set to true, returns the results in
 908            reverse order. By default the results are returned in
 909            ascending alphabetical order of the name of the activity
 910            types.
 911
 912        :raises: OperationNotPermittedFault, UnknownResourceFault
 913        """
 914        data = {'domain': domain, 'registrationStatus': registration_status}
 915        if name:
 916            data['name'] = name
 917        if maximum_page_size:
 918            data['maximumPageSize'] = maximum_page_size
 919        if next_page_token:
 920            data['nextPageToken'] = next_page_token
 921        if reverse_order:
 922            data['reverseOrder'] = 'true'
 923        json_input = json.dumps(data)
 924        return self.make_request('ListActivityTypes', json_input)
 925
 926    def describe_activity_type(self, domain, activity_name, activity_version):
 927        """
 928        Returns information about the specified activity type. This
 929        includes configuration settings provided at registration time
 930        as well as other general information about the type.
 931
 932        :type domain: string
 933        :param domain: The name of the domain in which the activity
 934            type is registered.
 935
 936        :type activity_name: string
 937        :param activity_name: The name of this activity.
 938
 939        :type activity_version: string
 940        :param activity_version: The version of this activity.
 941
 942        :raises: UnknownResourceFault, OperationNotPermittedFault
 943        """
 944        data = {'domain': domain}
 945        data['activityType'] = {'name': activity_name,
 946                                'version': activity_version}
 947        json_input = json.dumps(data)
 948        return self.make_request('DescribeActivityType', json_input)
 949
 950## Workflow Visibility
 951
 952    def list_workflow_types(self, domain, registration_status,
 953                            maximum_page_size=None, name=None,
 954                            next_page_token=None, reverse_order=None):
 955        """
 956        Returns information about workflow types in the specified
 957        domain. The results may be split into multiple pages that can
 958        be retrieved by making the call repeatedly.
 959
 960        :type domain: string
 961        :param domain: The name of the domain in which the workflow
 962            types have been registered.
 963
 964        :type registration_status: string
 965        :param registration_status: Specifies the registration status
 966            of the activity types to list.  Valid values are:
 967
 968            * REGISTERED
 969            * DEPRECATED
 970
 971        :type name: string
 972        :param name: If specified, lists the workflow type with this name.
 973
 974        :type maximum_page_size: integer
 975        :param maximum_page_size: The maximum number of results
 976            returned in each page. The default is 100, but the caller can
 977            override this value to a page size smaller than the
 978            default. You cannot specify a page size greater than 100.
 979
 980        :type next_page_token: string
 981        :param next_page_token: If on a previous call to this method a
 982            NextPageToken was returned, the results are being
 983            paginated. To get the next page of results, repeat the call
 984            with the returned token and all other arguments unchanged.
 985
 986        :type reverse_order: boolean
 987        :param reverse_order: When set to true, returns the results in
 988            reverse order. By default the results are returned in
 989            ascending alphabetical order of the name of the workflow
 990            types.
 991
 992        :raises: OperationNotPermittedFault, UnknownResourceFault
 993        """
 994        data = {'domain': domain, 'registrationStatus': registration_status}
 995        if maximum_page_size:
 996            data['maximumPageSize'] = maximum_page_size
 997        if name:
 998            data['name'] = name
 999        if next_page_token:
1000            data['nextPageToken'] = next_page_token
1001        if reverse_order:
1002            data['reverseOrder'] = 'true'
1003        json_input = json.dumps(data)
1004        return self.make_request('ListWorkflowTypes', json_input)
1005
1006    def describe_workflow_type(self, domain, workflow_name, workflow_version):
1007        """
1008        Returns information about the specified workflow type. This
1009        includes configuration settings specified when the type was
1010        registered and other information such as creation date,
1011        current status, etc.
1012
1013        :type domain: string
1014        :param domain: The name of the domain in which this workflow
1015            type is registered.
1016
1017        :type workflow_name: string
1018        :param workflow_name: The name of the workflow type.
1019
1020        :type workflow_version: string
1021        :param workflow_version: The version of the workflow type.
1022
1023        :raises: UnknownResourceFault, OperationNotPermittedFault
1024        """
1025        data = {'domain': domain}
1026        data['workflowType'] = {'name': workflow_name,
1027                                'version': workflow_version}
1028        json_input = json.dumps(data)
1029        return self.make_request('DescribeWorkflowType', json_input)
1030
1031## Workflow Execution Visibility
1032
1033    def describe_workflow_execution(self, domain, run_id, workflow_id):
1034        """
1035        Returns information about the specified workflow execution
1036        including its type and some statistics.
1037
1038        :type domain: string
1039        :param domain: The name of the domain containing the
1040            workflow execution.
1041
1042        :type run_id: string
1043        :param run_id: A system generated unique identifier for the
1044            workflow execution.
1045
1046        :type workflow_id: string
1047        :param workflow_id: The user defined identifier associated
1048            with the workflow execution.
1049
1050        :raises: UnknownResourceFault, OperationNotPermittedFault
1051        """
1052        data = {'domain': domain}
1053        data['execution'] = {'runId': run_id, 'workflowId': workflow_id}
1054        json_input = json.dumps(data)
1055        return self.make_request('DescribeWorkflowExecution', json_input)
1056
1057    def get_workflow_execution_history(self, domain, run_id, workflow_id,
1058                                       maximum_page_size=None,
1059                                       next_page_token=None,
1060                                       reverse_order=None):
1061        """
1062        Returns the history of the specified workflow execution. The
1063        results may be split into multiple pages. To retrieve
1064        subsequent pages, make the call again using the nextPageToken
1065        returned by the initial call.
1066
1067        :type domain: string
1068        :param domain: The name of the domain containing the
1069            workflow execution.
1070
1071        :type run_id: string
1072        :param run_id: A system generated unique identifier for the
1073            workflow execution.
1074
1075        :type workflow_id: string
1076        :param workflow_id: The user defined identifier associated
1077            with the workflow execution.
1078
1079        :type maximum_page_size: integer
1080        :param maximum_page_size: Specifies the maximum number of
1081            history events returned in one page. The next page in the
1082            result is identified by the NextPageToken returned. By default
1083            100 history events are returned in a page but the caller can
1084            override this value to a page size smaller than the
1085            default. You cannot specify a page size larger than 100.
1086
1087        :type next_page_token: string
1088        :param next_page_token: If a NextPageToken is returned, the
1089            result has more than one pages. To get the next page, repeat
1090            the call and specify the nextPageToken with all other
1091            arguments unchanged.
1092
1093        :type reverse_order: boolean
1094        :param reverse_order: When set to true, returns the events in
1095            reverse order. By default the results are returned in
1096            ascending order of the eventTimeStamp of the events.
1097
1098        :raises: UnknownResourceFault, OperationNotPermittedFault
1099        """
1100        data = {'domain': domain}
1101        data['execution'] = {'runId': run_id, 'workflowId': workflow_id}
1102        if maximum_page_size:
1103            data['maximumPageSize'] = maximum_page_size
1104        if next_page_token:
1105            data['nextPageToken'] = next_page_token
1106        if reverse_order:
1107            data['reverseOrder'] = 'true'
1108        json_input = json.dumps(data)
1109        return self.make_request('GetWorkflowExecutionHistory', json_input)
1110
1111    def count_open_workflow_executions(self, domain, latest_date, oldest_date,
1112                                       tag=None, workflow_id=None,
1113                                       workflow_name=None,
1114                                       workflow_version=None):
1115        """
1116        Returns the number of open workflow executions within the
1117        given domain that meet the specified filtering criteria.
1118
1119        .. note:
1120            workflow_id, workflow_name/workflow_version and tag are mutually
1121            exclusive. You can specify at most one of these in a request.
1122
1123        :type domain: string
1124        :param domain: The name of the domain containing the
1125            workflow executions to count.
1126
1127        :type latest_date: timestamp
1128        :param latest_date: Specifies the latest start or close date
1129            and time to return.
1130
1131        :type oldest_date: timestamp
1132        :param oldest_date: Specifies the oldest start or close date
1133            and time to return.
1134
1135        :type workflow_name: string
1136        :param workflow_name: Name of the workflow type to filter on.
1137
1138        :type workflow_version: string
1139        :param workflow_version: Version of the workflow type to filter on.
1140
1141        :type tag: string
1142        :param tag: If specified, only executions that have a tag
1143            that matches the filter are counted.
1144
1145        :type workflow_id: string
1146        :param workflow_id: If specified, only workflow executions
1147            matching the workflow_id are counted.
1148
1149        :raises: #UnknownResourceFault, #OperationNotPermittedFault
1150        """
1151        data = {'domain': domain}
1152        data['startTimeFilter'] = {'oldestDate': oldest_date,
1153                                   'latestDate': latest_date}
1154        if workflow_name and workflow_version:
1155            data['typeFilter'] = {'name': workflow_name,
1156                                  'version': workflow_version}
1157        if workflow_id:
1158            data['executionFilter'] = {'workflowId': workflow_id}
1159        if tag:
1160            data['tagFilter'] = {'tag': t

Large files files are truncated, but you can click here to view the full file