Exemplo n.º 1
0
        /// <summary>
        /// Registers activity type for a specific version.
        /// </summary>
        /// <param name="domainName">Domain where the activity type should be registered.</param>
        /// <param name="client">Interface for accessing Amazon Simple Workflow Service.</param>
        void IRegistrable.Register(string domainName, IAmazonSimpleWorkflow client)
        {
            var listActivityRequest = new ListActivityTypesRequest
            {
                Domain             = domainName,
                Name               = Options.Name,
                RegistrationStatus = RegistrationStatus.REGISTERED
            };


            if (
                client.ListActivityTypesAsync(listActivityRequest).Result
                .ActivityTypeInfos.TypeInfos.FirstOrDefault(x => x.ActivityType.Version == Options.Version) == null)
            {
                Logger.Trace("New Activity Type.");

                RegisterActivityTypeRequest request = new RegisterActivityTypeRequest
                {
                    Name            = Options.Name,
                    Domain          = domainName,
                    Description     = Options.Description,
                    Version         = Options.Version,
                    DefaultTaskList = TaskList,                     //Worker poll based on this
                    DefaultTaskScheduleToCloseTimeout = Options.ScheduleToCloseTimeout.ToStringOrNone(),
                    DefaultTaskScheduleToStartTimeout = Options.ScheduleToStartTimeout.ToStringOrNone(),
                    DefaultTaskStartToCloseTimeout    = Options.StartToCloseTimeout.ToStringOrNone(),
                    DefaultTaskHeartbeatTimeout       = Options.HeartbeatTimeout.ToStringOrNone()
                };

                client.RegisterActivityTypeAsync(request).Wait();
            }

            Logger.Trace("Activity. Name: {0}, Version: {1}", Options.Name, Options.Version);
        }
        public static void RegisterActivity(IAmazonSimpleWorkflow swfClient, string domainName, string name, string tasklistName)
        {
            // Register activities if it is not already registered
            var listActivityRequest = new ListActivityTypesRequest()
            {
                Domain             = domainName,
                Name               = name,
                RegistrationStatus = RegistrationStatus.REGISTERED
            };

            if (swfClient.ListActivityTypes(listActivityRequest).ActivityTypeInfos.TypeInfos.FirstOrDefault(
                    x => x.ActivityType.Version == "2.0") == null)
            {
                RegisterActivityTypeRequest request = new RegisterActivityTypeRequest()
                {
                    Name            = name,
                    Domain          = domainName,
                    Description     = "Hello World Activities",
                    Version         = "2.0",
                    DefaultTaskList = new TaskList()
                    {
                        Name = tasklistName
                    },                                                       //Worker poll based on this
                    DefaultTaskScheduleToCloseTimeout = "300",
                    DefaultTaskScheduleToStartTimeout = "150",
                    DefaultTaskStartToCloseTimeout    = "450",
                    DefaultTaskHeartbeatTimeout       = "NONE",
                };
                swfClient.RegisterActivityType(request);
                Console.WriteLine("Setup: Created Activity Name - " + request.Name);
            }
        }
Exemplo n.º 3
0
        public WorkflowTests()
        {
            _decisionTask = Substitute.For <DecisionTask>();
            _decisionTask.WorkflowType = new WorkflowType {
                Name = "TestWorkflow", Version = "TestVersion"
            };
            _decisionTask.WorkflowExecution = new WorkflowExecution {
                RunId = "TestRunId", WorkflowId = ""
            };

            var results = new ConcurrentDictionary <int, string>();

            results.AddOrUpdate(1, "TestResult", (index, value) => $"{value} - {index}");


            _executionContext = WorkflowStateSerializer.Serialize(new WorkflowState()
            {
                CurrentStepNumber = 1,
                NumberOfActions   = 1,
                Results           = results
            });


            _pollforDecisionTaskRequest        = Substitute.For <PollForDecisionTaskRequest>();
            _pollforDecisionTaskRequest.Domain = "TestDomain";
            _amazonSwf = Substitute.For <IAmazonSimpleWorkflow>();
            _workflow  = Substitute.For <WorkflowBase>("domain", _defaultWorkflowName, "version", "taskList", _amazonSwf);
        }
Exemplo n.º 4
0
        public WorkflowEventsIteratorTest()
        {
            _decisionTask = Substitute.For <DecisionTask>();
            _pollforDecisionTaskRequest = Substitute.For <PollForDecisionTaskRequest>();
            _amazonSwf = Substitute.For <IAmazonSimpleWorkflow>();

            var workflowExecutionStartedEventAttributes = Substitute.For <WorkflowExecutionStartedEventAttributes>();

            workflowExecutionStartedEventAttributes.Input = "Input";

            var workflowExecutionCompletedEventAttributes = Substitute.For <WorkflowExecutionCompletedEventAttributes>();

            workflowExecutionCompletedEventAttributes.Result = "Output";

            var historyEvent1 = Substitute.For <HistoryEvent>();

            historyEvent1.EventId = event1ID;
            historyEvent1.WorkflowExecutionStartedEventAttributes = workflowExecutionStartedEventAttributes;
            historyEvent1.EventType = EventType.WorkflowExecutionStarted;

            var historyEvent2 = Substitute.For <HistoryEvent>();

            historyEvent2.EventId = event2ID;
            historyEvent2.WorkflowExecutionCompletedEventAttributes = Substitute.For <WorkflowExecutionCompletedEventAttributes>();
            historyEvent2.EventType = EventType.ChildWorkflowExecutionCompleted;

            _decisionTask.Events = new List <HistoryEvent>
            {
                historyEvent1,
                historyEvent2
            };
        }
Exemplo n.º 5
0
        public static void RegisterWorkflow(IAmazonSimpleWorkflow swfClient, string name, string domainName)
        {
            // Register workflow type if not already registered
            var listWorkflowRequest = new ListWorkflowTypesRequest()
            {
                Name               = name,
                Domain             = domainName,
                RegistrationStatus = RegistrationStatus.REGISTERED
            };

            if (swfClient.ListWorkflowTypes(listWorkflowRequest).WorkflowTypeInfos.TypeInfos.FirstOrDefault(
                    x => x.WorkflowType.Version == "2.0") == null)
            {
                RegisterWorkflowTypeRequest request = new RegisterWorkflowTypeRequest()
                {
                    DefaultChildPolicy = ChildPolicy.TERMINATE,
                    DefaultExecutionStartToCloseTimeout = "300",
                    DefaultTaskList = new TaskList()
                    {
                        Name = "HelloWorld" // Decider need to poll for this task
                    },
                    DefaultTaskStartToCloseTimeout = "150",
                    Domain  = domainName,
                    Name    = name,
                    Version = "2.0"
                };

                swfClient.RegisterWorkflowType(request);

                Console.WriteLine("Setup: Registerd Workflow Name - " + request.Name);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructor for the workflow event processor.
        /// </summary>
        /// <param name="decisionTask">Decision task passed in from SWF as decision task response.</param>
        /// <param name="workflow">IEnumerable set of string for workflow name and Type for workflow class.</param>
        /// <param name="request">The request used to retrieve <paramref name="decisionTask"/>, which will be used to retrieve subsequent history event pages.</param>
        /// <param name="swfClient">An SWF client.</param>
        public WorkflowEventsProcessor(DecisionTask decisionTask, WorkflowBase workflow, PollForDecisionTaskRequest request,
                                       IAmazonSimpleWorkflow swfClient)
        {
            if (decisionTask == null)
            {
                throw new ArgumentNullException(nameof(decisionTask));
            }
            if (workflow == null)
            {
                throw new ArgumentNullException(nameof(workflow));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (swfClient == null)
            {
                throw new ArgumentNullException(nameof(swfClient));
            }

            // Store the decision task and allocate a new decision context and event dictionary which
            // we will use as we walk through the chain of events
            _decisionTask    = decisionTask;
            _request         = request;
            _decisionContext = new WorkflowDecisionContext();
            _swfClient       = swfClient;

            _workflow = workflow;

            // Set up our events data structure.
            Events = new WorkflowEventsIterator(ref decisionTask, _request, _swfClient);
        }
        /// <summary>
        /// Initialize constructor parameters
        /// </summary>

        public WorkflowEventsProcessorConstructorTest()
        {
            _decisionTask = Substitute.For <DecisionTask>();
            _pollforDecisionTaskRequest = Substitute.For <PollForDecisionTaskRequest>();
            _amazonSwf    = Substitute.For <IAmazonSimpleWorkflow>();
            _workflowBase = Substitute.For <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);
        }
Exemplo n.º 8
0
        public MakeDecisionTests()
        {
            _decisionTask = Substitute.For <DecisionTask>();
            _decisionTask.WorkflowType = new WorkflowType {
                Name = "TestWorkflow", Version = "TestVersion"
            };
            _decisionTask.WorkflowExecution = new WorkflowExecution {
                RunId = "TestRunId", WorkflowId = ""
            };

            var results = new ConcurrentDictionary <int, string>();

            results.AddOrUpdate(1, "TestResult", (key, value) => $"{key} - {value}");

            WorkflowStateSerializer.Serialize(new WorkflowState()
            {
                CurrentStepNumber = 1,
                NumberOfActions   = 1,
                Results           = results
            });


            _pollforDecisionTaskRequest        = Substitute.For <PollForDecisionTaskRequest>();
            _pollforDecisionTaskRequest.Domain = "TestDomain";
            _amazonSwf    = Substitute.For <IAmazonSimpleWorkflow>();
            _workflowBase = Substitute.For <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            var describeWorkflowExecutionRequest = Substitute.For <DescribeWorkflowExecutionRequest>();

            describeWorkflowExecutionRequest.Domain    = _pollforDecisionTaskRequest.Domain;
            describeWorkflowExecutionRequest.Execution = _decisionTask.WorkflowExecution;
        }
Exemplo n.º 9
0
 public override async Task SendAsync(IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken)
 {
     var request = new RespondActivityTaskCanceledRequest()
     {
         TaskToken = _taskToken, Details = _details
     };
     await simpleWorkflow.RespondActivityTaskCanceledAsync(request, cancellationToken);
 }
Exemplo n.º 10
0
 public override async Task SendAsync(IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken)
 {
     var request = new RespondActivityTaskCompletedRequest()
     {
         Result = _result, TaskToken = _taskToken
     };
     await simpleWorkflow.RespondActivityTaskCompletedAsync(request, cancellationToken);
 }
Exemplo n.º 11
0
 private Domain(string name, IAmazonSimpleWorkflow simpleWorkflowClient, IErrorHandler errorHandler)
 {
     Ensure.NotNullAndEmpty(name, () => new ArgumentException(Resources.Domain_name_required, nameof(name)));
     Ensure.NotNull(simpleWorkflowClient, "simpleWorkflowClient");
     _name = name;
     _simpleWorkflowClient = simpleWorkflowClient;
     _errorHandler         = errorHandler;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkflowEventsIterator"/> class.
        /// </summary>
        /// <param name="decisionTask">Reference to the decision task passed in from </param>
        /// <param name="request">The request used to retrieve <paramref name="decisionTask"/>, which will be used to retrieve subsequent history event pages.</param>
        /// <param name="swfClient">An SWF client.</param>
        public WorkflowEventsIterator(ref DecisionTask decisionTask, PollForDecisionTaskRequest request, IAmazonSimpleWorkflow swfClient)
        {
            _lastResponse = decisionTask;
            _request      = request;
            _swfClient    = swfClient;

            _historyEvents = decisionTask.Events;
        }
Exemplo n.º 13
0
        public ActivityWorker(string domain, string taskList, IAmazonSimpleWorkflow swfClient)
        {
            Debug.Assert(swfClient != null);

            _Domain   = domain;
            _TaskList = taskList;

            _swfClient = swfClient;
        }
        PollWriterManager()
        {
            this._snsClient = new AmazonSimpleNotificationServiceClient();

            this._dynamoDBClient = new AmazonDynamoDBClient();
            this._dbContext = new DynamoDBContext(this._dynamoDBClient, new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 });

            this._swfClient = new AmazonSimpleWorkflowClient();
        }
Exemplo n.º 15
0
        PollWriterManager()
        {
            this._snsClient = new AmazonSimpleNotificationServiceClient();

            this._dynamoDBClient = new AmazonDynamoDBClient();
            this._dbContext      = new DynamoDBContext(this._dynamoDBClient, new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            });

            this._swfClient = new AmazonSimpleWorkflowClient();
        }
Exemplo n.º 16
0
        public ActivityWorker(IWorkflow workflow, IAmazonSimpleWorkflow swfClient)
        {
            Debug.Assert(workflow != null);
            Debug.Assert(swfClient != null);

            _Domain   = workflow.Options.Domain;
            _TaskList = workflow.TaskList.Name;

            _workflow  = workflow;
            _swfClient = swfClient;
        }
Exemplo n.º 17
0
        internal override async Task SendAsync(string taskToken, IAmazonSimpleWorkflow simpleWorkflow,
                                               CancellationToken cancellationToken)
        {
            var request = new RespondActivityTaskFailedRequest()
            {
                TaskToken = taskToken,
                Reason    = Reason,
                Details   = _details
            };

            await simpleWorkflow.RespondActivityTaskFailedAsync(request, cancellationToken);
        }
Exemplo n.º 18
0
        public WorkflowEventsProcessorTests()
        {
            _decisionTask = Substitute.For <DecisionTask>();
            _decisionTask.WorkflowType = new WorkflowType {
                Name = "TestWorkflow", Version = "TestVersion"
            };
            _decisionTask.WorkflowExecution = new WorkflowExecution {
                RunId = "TestRunId", WorkflowId = ""
            };

            var results = new ConcurrentDictionary <int, string>();

            results.AddOrUpdate(1, "TestResult", UpdateValueFactory);

            _executionContext = WorkflowStateSerializer.Serialize(new WorkflowState()
            {
                CurrentStepNumber = 1,
                NumberOfActions   = 1,
                Results           = results
            });


            _pollforDecisionTaskRequest        = Substitute.For <PollForDecisionTaskRequest>();
            _pollforDecisionTaskRequest.Domain = "TestDomain";
            _amazonSwf    = Substitute.For <IAmazonSimpleWorkflow>();
            _workflowBase = Substitute.For <WorkflowBase>("domain", "workflowName", "version", "taskList", _amazonSwf);

            var describeWorkflowExecutionRequest = Substitute.For <DescribeWorkflowExecutionRequest>();

            describeWorkflowExecutionRequest.Domain    = _pollforDecisionTaskRequest.Domain;
            describeWorkflowExecutionRequest.Execution = _decisionTask.WorkflowExecution;


            //_amazonSwf.DescribeWorkflowExecution(describeWorkflowExecutionRequest)
            //	.ReturnsForAnyArgs(
            //		info =>
            //			new DescribeWorkflowExecutionResponse()
            //			{
            //				HttpStatusCode = HttpStatusCode.OK,
            //				WorkflowExecutionDetail = new WorkflowExecutionDetail() {LatestExecutionContext = _executionContext}
            //			});


            SDK.Workflow.WorkflowEventsProcessor processor = Substitute.For <SDK.Workflow.WorkflowEventsProcessor>(_decisionTask, _workflowBase,
                                                                                                                   _pollforDecisionTaskRequest, _amazonSwf);

            processor.GetLastExecContext().ReturnsForAnyArgs(info => WorkflowStateSerializer.Deserialize(_executionContext));

            //_workflowEventsIterator = Substitute.For<WorkflowEventsIterator>(_decisionTask, _pollforDecisionTaskRequest,
            //	_amazonSwf);
        }
Exemplo n.º 19
0
        static void StartWorkflow(string name)
        {
            IAmazonSimpleWorkflow swfClient = AWSClientFactory.CreateAmazonSimpleWorkflowClient();
            string workflowID = "Hello World WorkflowID - " + DateTime.Now.Ticks.ToString();

            swfClient.StartWorkflowExecution(new StartWorkflowExecutionRequest()
            {
                Input = "{\"inputparam1\":\"value1\"}", // Serialize input to a string

                WorkflowId   = workflowID,
                Domain       = domainName,
                WorkflowType = new WorkflowType()
                {
                    Name    = name,
                    Version = "2.0"
                }
            });
            Console.WriteLine("Setup: Workflow Instance created ID=" + workflowID);
        }
Exemplo n.º 20
0
        public static void Worker(IAmazonSimpleWorkflow swfClient, string domainName, string tasklistName)
        {
            string prefix = string.Format("Worker{0}:{1:x} ", tasklistName,
                                          System.Threading.Thread.CurrentThread.ManagedThreadId);

            while (true)
            {
                Console.WriteLine(prefix + ": Polling for activity task ...");
                PollForActivityTaskRequest pollForActivityTaskRequest =
                    new PollForActivityTaskRequest()
                {
                    Domain   = domainName,
                    TaskList = new TaskList()
                    {
                        // Poll only the tasks assigned to me
                        Name = tasklistName
                    }
                };
                PollForActivityTaskResponse pollForActivityTaskResponse =
                    swfClient.PollForActivityTask(pollForActivityTaskRequest);

                RespondActivityTaskCompletedRequest respondActivityTaskCompletedRequest =
                    new RespondActivityTaskCompletedRequest()
                {
                    Result    = "{\"activityResult1\":\"Result Value1\"}",
                    TaskToken = pollForActivityTaskResponse.ActivityTask.TaskToken
                };
                if (pollForActivityTaskResponse.ActivityTask.ActivityId == null)
                {
                    Console.WriteLine(prefix + ": NULL");
                }
                else
                {
                    RespondActivityTaskCompletedResponse respondActivityTaskCompletedResponse =
                        swfClient.RespondActivityTaskCompleted(respondActivityTaskCompletedRequest);
                    Console.WriteLine(prefix + ": Activity task completed. ActivityId - " +
                                      pollForActivityTaskResponse.ActivityTask.ActivityId);
                }
            }
        }
Exemplo n.º 21
0
        public static void RegisterDomain(IAmazonSimpleWorkflow swfClient, string domainName)
        {
            // Register if the domain is not already registered.
            var listDomainRequest = new ListDomainsRequest()
            {
                RegistrationStatus = RegistrationStatus.REGISTERED
            };

            if (swfClient.ListDomains(listDomainRequest).DomainInfos.Infos.FirstOrDefault(
                    x => x.Name == domainName) == null)
            {
                RegisterDomainRequest request = new RegisterDomainRequest()
                {
                    Name        = domainName,
                    Description = "Hello World Demo",
                    WorkflowExecutionRetentionPeriodInDays = "1"
                };

                Console.WriteLine("Setup: Created Domain - " + domainName);
                swfClient.RegisterDomain(request);
            }
        }
        /// <summary>
        /// Constructor for the workflow event processor. 
        /// </summary>
        /// <param name="decisionTask">Decision task passed in from SWF as decision task response.</param>
        /// <param name="workflows">IEnumerable set of string for workflow name and Type for workflow class.</param>
        /// <param name="request">The request used to retrieve <paramref name="decisionTask"/>, which will be used to retrieve subsequent history event pages.</param>
        /// <param name="swfClient">An SWF client.</param>
        public WorkflowEventsProcessor(DecisionTask decisionTask, IEnumerable<KeyValuePair<string, Type>> workflows, PollForDecisionTaskRequest request, IAmazonSimpleWorkflow swfClient)
        {
            // Decision task can't be null.
            if (decisionTask == null)
            {
                throw new ArgumentNullException("decisionTask");
            }

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            // Store the decision task and allocate a new decision context and event dictionary which
            // we will use as we walk through the chain of events
            _decisionTask = decisionTask;
            _request = request;
            _decisionContext = new WorkflowDecisionContext();
            _swfClient = swfClient;

            // Set up our events data structure
            _events = new WorkflowEventsIterator(ref decisionTask, _request, _swfClient);
            _workflows = (Dictionary<string, Type>) workflows;
        }
Exemplo n.º 23
0
        /// <summary>
        /// Constructor for the workflow event processor.
        /// </summary>
        /// <param name="decisionTask">Decision task passed in from SWF as decision task response.</param>
        /// <param name="workflows">IEnumerable set of string for workflow name and Type for workflow class.</param>
        /// <param name="request">The request used to retrieve <paramref name="decisionTask"/>, which will be used to retrieve subsequent history event pages.</param>
        /// <param name="swfClient">An SWF client.</param>
        public WorkflowEventsProcessor(DecisionTask decisionTask, IEnumerable <KeyValuePair <string, Type> > workflows, PollForDecisionTaskRequest request, IAmazonSimpleWorkflow swfClient)
        {
            // Decision task can't be null.
            if (decisionTask == null)
            {
                throw new ArgumentNullException("decisionTask");
            }

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            // Store the decision task and allocate a new decision context and event dictionary which
            // we will use as we walk through the chain of events
            _decisionTask    = decisionTask;
            _request         = request;
            _decisionContext = new WorkflowDecisionContext();
            _swfClient       = swfClient;

            // Set up our events data structure
            _events    = new WorkflowEventsIterator(ref decisionTask, _request, _swfClient);
            _workflows = (Dictionary <string, Type>)workflows;
        }
 internal ListActivityTypesPaginator(IAmazonSimpleWorkflow client, ListActivityTypesRequest request)
 {
     this._client  = client;
     this._request = request;
 }
        public ParallelWorkflowCollectionBase(IWorkflowCollectionOptions <TInput, TOutput> collectionOptions, IAmazonSimpleWorkflow swfClient, IStorageManager storeClient)
            : base(collectionOptions, swfClient, storeClient)
        {
            if (collectionOptions == null)
            {
                throw new ArgumentNullException(nameof(collectionOptions));
            }

            Options = collectionOptions;
        }
 internal PollForDecisionTaskPaginator(IAmazonSimpleWorkflow client, PollForDecisionTaskRequest request)
 {
     this._client  = client;
     this._request = request;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Create a domain with given name and a client to communicate with Amazon SWF. You have more control on creating/configuring the AmazonSimpleWorkflowClient.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="simpleWorkflowClient"></param>
 public Domain(string name, IAmazonSimpleWorkflow simpleWorkflowClient)
     : this(name, simpleWorkflowClient, ErrorHandler.NotHandled)
 {
 }
Exemplo n.º 28
0
 internal GetWorkflowExecutionHistoryPaginator(IAmazonSimpleWorkflow client, GetWorkflowExecutionHistoryRequest request)
 {
     this._client  = client;
     this._request = request;
 }
Exemplo n.º 29
0
 internal abstract Task SendAsync(string taskToken, IAmazonSimpleWorkflow simpleWorkflow, CancellationToken cancellationToken);
Exemplo n.º 30
0
 internal override Task SendAsync(string taskToken, IAmazonSimpleWorkflow simpleWorkflow,
                                  CancellationToken cancellationToken)
 {
     return(Task.FromResult(false));
 }
Exemplo n.º 31
0
 private Amazon.SimpleWorkflow.Model.UntagResourceResponse CallAWSServiceOperation(IAmazonSimpleWorkflow client, Amazon.SimpleWorkflow.Model.UntagResourceRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Simple Workflow Service (SWF)", "UntagResource");
     try
     {
         #if DESKTOP
         return(client.UntagResource(request));
         #elif CORECLR
         return(client.UntagResourceAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
 internal ListClosedWorkflowExecutionsPaginator(IAmazonSimpleWorkflow client, ListClosedWorkflowExecutionsRequest request)
 {
     this._client  = client;
     this._request = request;
 }