public async Task <IActionResult> Index()
        {
            var orchestrations = new OrchestrationEntity().FetchAll();
            var sb             = new StringBuilder();

            foreach (var orchestration in orchestrations)
            {
                var cl = clientFactory.CreateClient();

                var statusRequest = new HttpRequestMessage(HttpMethod.Get, orchestration.StatusQueryGetUri);
                var statusResult  = await cl.SendAsync(statusRequest);

                var status = OrchestrationStatus.FromJson(await statusResult.Content.ReadAsStringAsync());

                var reg = new RegistrationEntity().Fetch(status.name, status.instanceId);

                sb.Append($"<tr>");
                sb.Append($"<td>{reg?.UserName ?? "unknown"}</td>");
                sb.Append($"<td>{reg?.UserEmail ?? "unknown"}</td>");
                sb.Append($"<td>{HasVerified(reg?.EmailLastVerified ?? TableEntityBase.MinDate, "EmailVerified", orchestration)}</td>");
                sb.Append($"<td>{reg?.UserPhone ?? "unknown"}</td>");
                sb.Append($"<td>{HasVerified(reg?.PhoneLastVerified ?? TableEntityBase.MinDate, "SmsVerified", orchestration)}</td>");
                sb.Append($"<td>{status.customStatus}</td>");
                sb.Append($"<td>{status.runtimeStatus}</td>");
                sb.Append($"</tr>");
            }
            ViewBag.rows = sb.ToString();

            return(View("Index"));
        }
Esempio n. 2
0
        static ConsoleColor GetColorUsingState(OrchestrationStatus status)
        {
            ConsoleColor color = Console.ForegroundColor;

            switch (status)
            {
            case OrchestrationStatus.Failed:
                color = ConsoleColor.Red;
                break;

            case OrchestrationStatus.Canceled:
                color = ConsoleColor.Gray;
                break;

            case OrchestrationStatus.Terminated:
                color = ConsoleColor.DarkRed;
                break;

            case OrchestrationStatus.Completed:
            case OrchestrationStatus.ContinuedAsNew:
                color = ConsoleColor.Green;
                break;

            case OrchestrationStatus.Running:
                color = ConsoleColor.Yellow;
                break;

            default:
                break;
            }

            return(color);
        }
 public ExecutionCompletedEvent(int eventId, string?result, OrchestrationStatus orchestrationStatus, FailureDetails?failureDetails = null)
     : base(eventId)
 {
     Result = result;
     OrchestrationStatus = orchestrationStatus;
     FailureDetails      = failureDetails;
 }
        public void CompleteOrchestration(string result, string details, OrchestrationStatus orchestrationStatus, FailureDetails failureDetails = null)
        {
            int id = this.idCounter++;
            OrchestrationCompleteOrchestratorAction completedOrchestratorAction;

            if (orchestrationStatus == OrchestrationStatus.Completed && this.continueAsNew != null)
            {
                completedOrchestratorAction = this.continueAsNew;
            }
            else
            {
                if (this.executionCompletedOrTerminated)
                {
                    return;
                }

                this.executionCompletedOrTerminated = true;

                completedOrchestratorAction                     = new OrchestrationCompleteOrchestratorAction();
                completedOrchestratorAction.Result              = result;
                completedOrchestratorAction.Details             = details;
                completedOrchestratorAction.OrchestrationStatus = orchestrationStatus;
                completedOrchestratorAction.FailureDetails      = failureDetails;
            }

            completedOrchestratorAction.Id = id;
            this.orchestratorActionsMap.Add(id, completedOrchestratorAction);
        }
        public async Task <OrchestrationState> WaitForCompletion(
            TimeSpan timeout = default,
            OrchestrationStatus expectedStatus = OrchestrationStatus.Completed,
            object expectedOutput      = null,
            string expectedOutputRegex = null,
            bool continuedAsNew        = false)
        {
            AdjustTimeout(ref timeout);

            OrchestrationState state = await this.client.WaitForOrchestrationAsync(this.GetInstanceForAnyExecution(), timeout);

            Assert.NotNull(state);
            Assert.Equal(expectedStatus, state.OrchestrationStatus);

            if (!continuedAsNew)
            {
                if (this.input != null)
                {
                    Assert.Equal(JToken.FromObject(this.input).ToString(), JToken.Parse(state.Input).ToString());
                }
                else
                {
                    Assert.Null(state.Input);
                }
            }

            // For created time, account for potential clock skew
            Assert.True(state.CreatedTime >= this.startTime.AddMinutes(-5));
            Assert.True(state.LastUpdatedTime > state.CreatedTime);
            Assert.True(state.CompletedTime > state.CreatedTime);
            Assert.NotNull(state.OrchestrationInstance);
            Assert.Equal(this.instance.InstanceId, state.OrchestrationInstance.InstanceId);

            // Make sure there is an ExecutionId, but don't require it to match any particular value
            Assert.NotNull(state.OrchestrationInstance.ExecutionId);

            if (expectedOutput != null)
            {
                Assert.NotNull(state.Output);
                try
                {
                    // DTFx usually encodes outputs as JSON values. The exception is error messages.
                    // If this is an error message, we'll throw here and try the logic in the catch block.
                    JToken.Parse(state.Output);
                    Assert.Equal(JToken.FromObject(expectedOutput).ToString(Formatting.None), state.Output);
                }
                catch (JsonReaderException)
                {
                    Assert.Equal(expectedOutput, state?.Output);
                }
            }

            if (expectedOutputRegex != null)
            {
                Assert.Matches(expectedOutputRegex, state.Output);
            }

            return(state);
        }
Esempio n. 6
0
 public CheckpointStartingEvent(
     string name,
     OrchestrationInstance instance,
     OrchestrationStatus status)
 {
     this.Name        = name;
     this.InstanceId  = instance.InstanceId;
     this.ExecutionId = instance.ExecutionId ?? string.Empty;
     this.Status      = status.ToString();
 }
Esempio n. 7
0
        public static void DumpAllInstancesForState(TaskHubClient client, OrchestrationStatus status, int hours)
        {
            DateTime currentTime = DateTime.UtcNow;
            OrchestrationStateQuery statusQuery = new OrchestrationStateQuery();

            statusQuery
            .AddStatusFilter(status)
            .AddTimeRangeFilter(currentTime.Subtract(TimeSpan.FromHours(hours)), currentTime, OrchestrationStateTimeRangeFilterType.OrchestrationCreatedTimeFilter);

            DumpInstances(client.QueryOrchestrationStates(statusQuery));
        }
Esempio n. 8
0
        public void OrchestrationInstanceQuery_RuntimeStatus()
        {
            var runtimeStatus = new OrchestrationStatus[] { OrchestrationStatus.Running };
            var condition     = new OrchestrationInstanceStatusQueryCondition
            {
                RuntimeStatus = runtimeStatus
            };

            var query = condition.ToTableQuery <OrchestrationInstanceStatus>();

            Assert.AreEqual("RuntimeStatus eq 'Running'", query.FilterString);
        }
Esempio n. 9
0
        protected override bool ControlIndividualArtifact(string name, Dictionary <string, object> metadata, BtsCatalogExplorer catalog, Application app)
        {
            BtsOrchestration inst = app.Orchestrations[name];

            OrchestrationStatus status = inst.Status;

            ActionType action = (ActionType)metadata[ActionMetadataKey];

            switch (action)
            {
            case ActionType.Enlist:
                if (status == OrchestrationStatus.Unenlisted)
                {
                    this.Log.LogMessage("Enlisting orchestration '" + name + "'...");
                    inst.Status = OrchestrationStatus.Enlisted;
                    return(true);
                }
                break;

            case ActionType.Unenlist:
                if (status != OrchestrationStatus.Unenlisted)
                {
                    this.Log.LogMessage("Unenlisting orchestration '" + name + "'...");
                    inst.AutoTerminateInstances = false;
                    inst.Status = OrchestrationStatus.Unenlisted;
                    return(true);
                }
                break;

            case ActionType.Start:
                if (status != OrchestrationStatus.Started)
                {
                    StartOrchestration(name, metadata, catalog, inst);
                    return(true);
                }
                break;

            case ActionType.Stop:
                if (status == OrchestrationStatus.Started)
                {
                    this.Log.LogMessage("Stopping orchestration '" + name + "'...");
                    // No auto disable receive locations
                    // Auto suspend running instances
                    inst.AutoSuspendRunningInstances = true;
                    inst.Status = OrchestrationStatus.Enlisted;
                    return(true);
                }
                break;
            }

            return(false);
        }
Esempio n. 10
0
        public void OrchestrationInstanceQuery_Combination()
        {
            var runtimeStatus = new OrchestrationStatus[] { OrchestrationStatus.Running };
            var condition     = new OrchestrationInstanceStatusQueryCondition
            {
                RuntimeStatus   = runtimeStatus,
                CreatedTimeFrom = new DateTime(2018, 1, 10, 10, 10, 10, DateTimeKind.Utc),
                CreatedTimeTo   = new DateTime(2018, 1, 10, 10, 10, 50, DateTimeKind.Utc)
            };

            Assert.AreEqual(
                "((CreatedTime ge datetime'2018-01-10T10:10:10.0000000Z') and (CreatedTime le datetime'2018-01-10T10:10:50.0000000Z')) and (RuntimeStatus eq 'Running')",
                condition.ToTableQuery <OrchestrationInstanceStatus>().FilterString);
        }
 private static List <OrchestrationState> GetInstanceState(OrchestrationStatus status)
 {
     return(new List <OrchestrationState>()
     {
         new OrchestrationState()
         {
             OrchestrationInstance = new OrchestrationInstance
             {
                 InstanceId = "valid_instance_id",
             },
             OrchestrationStatus = status,
         },
     });
 }
        /// <summary>
        ///     Adds a status filter on the returned orchestrations
        /// </summary>
        /// <param name="status">The status to filter by</param>
        /// <returns></returns>
        public OrchestrationStateQuery AddStatusFilter(OrchestrationStatus status)
        {
            if (FilterMap.ContainsKey(typeof(OrchestrationStateStatusFilter)))
            {
                throw new ArgumentException("Cannot add more than one status filters");
            }

            FilterMap.Add(typeof(OrchestrationStateStatusFilter),
                          new OrchestrationStateStatusFilter {
                Status = status
            });

            return(this);
        }
        /// <summary>
        ///     Adds a status filter on the returned orchestrations
        /// </summary>
        /// <param name="status">The status to filter by</param>
        /// <param name="comparisonType">type of comparison to be performed on the status</param>
        /// <returns></returns>
        public OrchestrationStateQuery AddStatusFilter(OrchestrationStatus status, FilterComparisonType comparisonType)
        {
            if (this.FilterMap.ContainsKey(typeof(OrchestrationStateStatusFilter)))
            {
                throw new ArgumentException("Cannot add more than one status filters");
            }

            this.FilterMap.Add(typeof(OrchestrationStateStatusFilter),
                               new OrchestrationStateStatusFilter {
                Status = status, ComparisonType = comparisonType
            });

            return(this);
        }
Esempio n. 14
0
        public void OrchestrationInstanceQuery_MultipleRuntimeStatus()
        {
            var runtimeStatus = new OrchestrationStatus[] { OrchestrationStatus.Running, OrchestrationStatus.Completed };
            var condition     = new OrchestrationInstanceStatusQueryCondition
            {
                RuntimeStatus   = runtimeStatus,
                CreatedTimeFrom = new DateTime(2018, 1, 10, 10, 10, 10, DateTimeKind.Utc),
                CreatedTimeTo   = new DateTime(2018, 1, 10, 10, 10, 50, DateTimeKind.Utc),
                TaskHubNames    = new string[] { "FooProduction", "BarStaging" }
            };

            Assert.AreEqual(
                "(((CreatedTime ge datetime'2018-01-10T10:10:10.0000000Z') and (CreatedTime le datetime'2018-01-10T10:10:50.0000000Z')) and ((RuntimeStatus eq 'Running') or (RuntimeStatus eq 'Completed'))) and ((TaskHubName eq 'FooProduction') or (TaskHubName eq 'BarStaging'))",
                condition.ToTableQuery <OrchestrationInstanceStatus>().FilterString);
        }
Esempio n. 15
0
        internal void InstanceStatusUpdate(
            string account,
            string taskHub,
            string instanceId,
            string executionId,
            OrchestrationStatus runtimeStatus,
            int episode,
            long latencyMs)
        {
            var logEvent = new LogEvents.InstanceStatusUpdate(
                account,
                taskHub,
                instanceId,
                executionId,
                runtimeStatus,
                episode,
                latencyMs);

            this.WriteStructuredLog(logEvent);
        }
        public void CompleteOrchestration(string result, string details, OrchestrationStatus orchestrationStatus)
        {
            int id = idCounter++;
            OrchestrationCompleteOrchestratorAction completedOrchestratorAction;

            if (orchestrationStatus == OrchestrationStatus.Completed && continueAsNew != null)
            {
                completedOrchestratorAction = continueAsNew;
            }
            else
            {
                completedOrchestratorAction                     = new OrchestrationCompleteOrchestratorAction();
                completedOrchestratorAction.Result              = result;
                completedOrchestratorAction.Details             = details;
                completedOrchestratorAction.OrchestrationStatus = orchestrationStatus;
            }

            completedOrchestratorAction.Id = id;
            orchestratorActionsMap.Add(id, completedOrchestratorAction);
        }
        public async Task MockOrchestrationCompletion(OrchestrationStatus forcedStatus)
        {
            TaskOrchestration?orchestration = null;

            this.worker.AddOrchestrationDispatcherMiddleware((context, next) =>
            {
                // Expecting a null here since "FakeName"/"FakeVersion" doesn't exist
                orchestration = context.GetProperty <TaskOrchestration>();

                context.SetProperty(new OrchestratorExecutionResult
                {
                    CustomStatus = "custom",
                    Actions      = new[]
                    {
                        new OrchestrationCompleteOrchestratorAction
                        {
                            OrchestrationStatus = forcedStatus,
                        },
                    },
                });

                // don't call next() - we're short-circuiting the actual orchestration executor logic
                return(Task.FromResult(0));
            });

            // We can safely use non-existing orchestrator names because the orchestration executor gets short-circuited.
            // This allows middleware the flexibility to invent their own dynamic orchestration logic.
            // A practical application of this is out-of-process orchestrator execution.
            OrchestrationInstance instance = await this.client.CreateOrchestrationInstanceAsync(
                name : "FakeName",
                version : "FakeVersion",
                input : null);

            TimeSpan           timeout = TimeSpan.FromSeconds(Debugger.IsAttached ? 1000 : 5);
            OrchestrationState state   = await this.client.WaitForOrchestrationAsync(instance, timeout);

            Assert.AreEqual(forcedStatus, state.OrchestrationStatus);
            Assert.AreEqual("custom", state.Status);
            Assert.IsNull(orchestration, "Expected a null orchestration object in the middleware");
        }
Esempio n. 18
0
        public static OrchestrationState WaitForInstance(TaskHubClient taskHubClient, OrchestrationInstance instance, int timeoutSeconds)
        {
            OrchestrationStatus status = OrchestrationStatus.Running;

            if (string.IsNullOrWhiteSpace(instance?.InstanceId))
            {
                throw new ArgumentException("instance");
            }

            int sleepForSeconds = 30;

            while (timeoutSeconds > 0)
            {
                try
                {
                    var state = taskHubClient.GetOrchestrationStateAsync(instance.InstanceId).Result;
                    if (state != null)
                    {
                        status = state.OrchestrationStatus;
                    }
                    if (status == OrchestrationStatus.Running || status == OrchestrationStatus.Pending)
                    {
                        System.Threading.Thread.Sleep(sleepForSeconds * 1000);
                        timeoutSeconds -= sleepForSeconds;
                    }
                    else
                    {
                        // Session state deleted after completion
                        return(state);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error retrieving state for instance [instanceId: '{instance.InstanceId}', executionId: '{instance.ExecutionId}'].");
                    Console.WriteLine(ex.ToString());
                }
            }

            throw new TimeoutException("Timeout expired: " + timeoutSeconds.ToString());
        }
 /// <summary>
 /// Creates a new ExecutionCompletedEvent with the supplied parameters
 /// </summary>
 /// <param name="eventId">The event integer id</param>
 /// <param name="result">The string serialized completion result</param>
 /// <param name="orchestrationStatus">The orchestration status</param>
 public ExecutionCompletedEvent(int eventId, string result, OrchestrationStatus orchestrationStatus)
     : base(eventId)
 {
     this.Result = result;
     this.OrchestrationStatus = orchestrationStatus;
 }
 private bool IsFinalInstanceStatus(OrchestrationStatus status)
 {
     return(!IsFinalExecutionStatus(status) &&
            status != OrchestrationStatus.ContinuedAsNew);
 }
 private bool IsFinalExecutionStatus(OrchestrationStatus status)
 {
     return(status != OrchestrationStatus.Running &&
            status != OrchestrationStatus.Pending);
 }
        public static IEnumerable <OrchestrationState> GetInstancesByState(this SqlInstanceStore instanceStore, OrchestrationStatus status)
        {
            List <OrchestrationState> instances = new List <OrchestrationState>();

            var byNameQuery = new OrchestrationStateQuery();

            byNameQuery.AddStatusFilter(status);

            return(instanceStore.QueryOrchestrationStatesAsync(byNameQuery).Result);
        }
 public static bool IsRunningOrPending(this OrchestrationStatus status)
 {
     return(status == OrchestrationStatus.Pending || status == OrchestrationStatus.Running);
 }
 public ExecutionCompletedEvent(int eventId, string result, OrchestrationStatus orchestrationStatus)
     : base(eventId)
 {
     Result = result;
     OrchestrationStatus = orchestrationStatus;
 }
        /// <summary>
        ///     Adds a status filter on the returned orchestrations
        /// </summary>
        /// <param name="status">The status to filter by</param>
        /// <returns></returns>
        public OrchestrationStateQuery AddStatusFilter(OrchestrationStatus status)
        {
            if (FilterMap.ContainsKey(typeof (OrchestrationStateStatusFilter)))
            {
                throw new ArgumentException("Cannot add more than one status filters");
            }

            FilterMap.Add(typeof (OrchestrationStateStatusFilter),
                new OrchestrationStateStatusFilter {Status = status});

            return this;
        }
 public static bool IsTerminalState(this OrchestrationStatus status)
 {
     return(!status.IsRunningOrPending());
 }
Esempio n. 27
0
 /// <summary>
 ///     Adds a status filter on the returned orchestrations. Defaults to the equality Comparison Type.
 /// </summary>
 /// <param name="status">The status to filter by</param>
 /// <returns></returns>
 public OrchestrationStateQuery AddStatusFilter(OrchestrationStatus status)
 {
     return(AddStatusFilter(status, FilterComparisonType.Equals));
 }
 bool IsOrchestrationComplete(OrchestrationStatus status)
 {
     return(!(status.IsRunningOrPending() || status == OrchestrationStatus.ContinuedAsNew));
 }
Esempio n. 29
0
 internal PSFKey(OrchestrationStatus status)
 {
     this.column = (int)PsfColumn.RuntimeStatus;
     this.value  = (int)status;
 }