Example #1
0
        private static EmrActivityState GetStateFromLastStep(JobFlowDetail jobFlowDetail)
        {
            List <StepDetail> steps = jobFlowDetail.Steps;

            if (steps.Count == 0)
            {
                return(EmrActivityState.Completed);
            }

            StepDetail         lastStep      = steps[steps.Count - 1];
            StepExecutionState lastStepState = lastStep.ExecutionStatusDetail.State;

            if (lastStepState == StepExecutionState.PENDING)
            {
                return(EmrActivityState.Running);
            }
            else if (lastStepState != StepExecutionState.COMPLETED)
            {
                return(EmrActivityState.Failed);
            }
            else
            {
                return(EmrActivityState.Completed);
            }
        }
Example #2
0
        async Task <StepExecutionState> IProgressStepOperation.Run(CancellationToken cancellationToken, IProgressStepExecutionEvents progressCallback)
        {
            if (this.ExecutionState != StepExecutionState.NotStarted)
            {
                throw new InvalidOperationException(ProgressResources.StepOperationWasAlreadyExecuted);
            }

            if (this.Cancellable && cancellationToken.IsCancellationRequested)
            {
                return(this.ExecutionState = StepExecutionState.Cancelled);
            }

            VsTaskRunContext context = GetContext(this.Execution);

            StepExecutionState stepState = await VsThreadingHelper.RunTask <StepExecutionState>(this.controller, context,
                                                                                                () =>
            {
                DoStatefulExecution(progressCallback, cancellationToken);
                return(this.ExecutionState);
            },

                                                                                                cancellationToken);

            return(stepState);
        }
 public void AssertStepCorrectExecution(IProgressStep step, StepExecutionState finalState)
 {
     if (finalState == StepExecutionState.NotStarted)
     {
         Assert.IsFalse(this.executionChanges.ContainsKey(step), "Not expecting any changes for a step that was not started");
     }
     else
     {
         List<StepExecutionChangedEventArgs> changes = this.executionChanges[step];
         Assert.IsNotNull(changes, "Cannot find the changes list for the specified step");
         VerifyStateTransitions(changes.Select(e => e.State).ToArray(), finalState);
     }
 }
Example #4
0
 public void AssertStepCorrectExecution(IProgressStep step, StepExecutionState finalState)
 {
     if (finalState == StepExecutionState.NotStarted)
     {
         this.executionChanges.Should().NotContainKey(step, "Not expecting any changes for a step that was not started");
     }
     else
     {
         List <StepExecutionChangedEventArgs> changes = this.executionChanges[step];
         changes.Should().NotBeNull("Cannot find the changes list for the specified step");
         VerifyStateTransitions(changes.Select(e => e.State).ToArray(), finalState);
     }
 }
Example #5
0
 private static void VerifyStateTransitions(StepExecutionState[] transition, StepExecutionState finalState)
 {
     for (int i = 0; i < transition.Length; i++)
     {
         if (IsFinalState(transition[i]))
         {
             transition[i].Should().Be(finalState, "Unexpected final state");
             i.Should().Be(transition.Length - 1, "Final state should be the last one recorded");
         }
         else
         {
             transition[i].Should().Be(StepExecutionState.Executing, "Only Executing is expected");
         }
     }
 }
Example #6
0
 private static void VerifyStateTransitions(StepExecutionState[] transition, StepExecutionState finalState)
 {
     for (int i = 0; i < transition.Length; i++)
     {
         if (IsFinalState(transition[i]))
         {
             Assert.AreEqual(finalState, transition[i], "Unexpected final state");
             Assert.AreEqual(transition.Length - 1, i, "Final state should be the last one recorded");
         }
         else
         {
             Assert.AreEqual(StepExecutionState.Executing, transition[i], "Only Executing is expected");
         }
     }
 }
        private static ConfigurableProgressTestOperation CreateRandomStep(bool visible, bool indeterminate, bool impacting)
        {
            Random             random         = new Random();
            int                maxFlag        = ((int[])Enum.GetValues(typeof(StepExecutionState))).Max();
            StepExecutionState executionState = (StepExecutionState)random.Next(0, maxFlag + 1);

            ConfigurableProgressTestOperation step;

            step                    = new ConfigurableProgressTestOperation((c, e) => { });
            step.DisplayText        = "DisplayText:" + Environment.TickCount.ToString();
            step.ExecutionState     = executionState;
            step.Progress           = random.NextDouble();
            step.ProgressDetailText = "ProgressDetailText:" + Environment.TickCount.ToString();
            step.Indeterminate      = indeterminate;
            step.Hidden             = !visible;
            step.ImpactsProgress    = impacting;
            return(step);
        }
        /// <summary>
        /// Initializes the step
        /// </summary>
        private void Initialize()
        {
            this.state = StepExecutionState.NotStarted;

            bool          indeterminate     = (this.definition.Attributes & StepAttributes.Indeterminate) != 0;
            StepExecution execution         = (this.definition.Attributes & StepAttributes.BackgroundThread) != 0 ? StepExecution.BackgroundThread : StepExecution.ForegroundThread;
            bool          hidden            = (this.definition.Attributes & StepAttributes.Hidden) != 0;
            bool          cancellable       = (this.definition.Attributes & StepAttributes.NonCancellable) == 0;
            bool          impactingProgress = (this.definition.Attributes & StepAttributes.NoProgressImpact) == 0;
            string        displayText       = this.definition.DisplayText;

            this.SetStepKind(indeterminate);
            this.Hidden          = hidden;
            this.DisplayText     = displayText;
            this.Execution       = execution;
            this.Cancellable     = cancellable;
            this.ImpactsProgress = impactingProgress;
        }
Example #9
0
 Task <ProgressControllerResult> IProgressController.StartAsync()
 {
     return(Task.Factory.StartNew(() =>
     {
         stepOperations.ForEach(op =>
         {
             try
             {
                 this.canAbort = op.Step.Cancellable;
                 StepExecutionState state = op.RunAsync(this.cts.Token, this).Result;
                 VerificationHelper.CheckState(op.Step, state);
             }
             catch (Exception ex)
             {
                 FluentAssertions.Execution.Execute.Assertion.FailWith(ex.ToString());
             }
         });
         return this.ReturnResult;
     }));
 }
Example #10
0
 /// <summary>
 /// Instantiates StepExecutionStatusDetail with the parameterized properties
 /// </summary>
 /// <param name="state">The state of the step.</param>
 /// <param name="creationDateTime">The creation date and time of the step.</param>
 public StepExecutionStatusDetail(StepExecutionState state, DateTime creationDateTime)
 {
     _state            = state;
     _creationDateTime = creationDateTime;
 }
 /// <summary>
 /// Instantiates StepExecutionStatusDetail with the parameterized properties
 /// </summary>
 /// <param name="state">The state of the job flow step.</param>
 /// <param name="creationDateTime">The creation date and time of the step.</param>
 public StepExecutionStatusDetail(StepExecutionState state, DateTime creationDateTime)
 {
     _state = state;
     _creationDateTime = creationDateTime;
 }
Example #12
0
 /// <summary>
 /// Returns whether the state is considered to be final
 /// </summary>
 /// <param name="state">The state for which to check</param>
 /// <returns>Whether considered to be a final state</returns>
 public static bool IsFinalState(StepExecutionState state)
 {
     return(state == StepExecutionState.Cancelled || state == StepExecutionState.Failed || state == StepExecutionState.Succeeded);
 }
 /// <summary>
 /// Checks the current state of a <see cref="IProgressStep"/>
 /// </summary>
 /// <param name="testSubject">The step to check</param>
 /// <param name="expectedState">The expected state of the step</param>
 public static void CheckState(IProgressStep testSubject, StepExecutionState expectedState)
 {
     testSubject.ExecutionState.Should().Be(expectedState, "Unexpected state");
 }
 private static bool IsFinalState(StepExecutionState state)
 {
     return state == StepExecutionState.Cancelled || state == StepExecutionState.Failed || state == StepExecutionState.Succeeded;
 }
 private static void VerifyStateTransitions(StepExecutionState[] transition, StepExecutionState finalState)
 {
     for (int i = 0; i < transition.Length; i++)
     {
         if (IsFinalState(transition[i]))
         {
             Assert.AreEqual(finalState, transition[i], "Unexpected final state");
             Assert.AreEqual(transition.Length - 1, i, "Final state should be the last one recorded");
         }
         else
         {
             Assert.AreEqual(StepExecutionState.Executing, transition[i], "Only Executing is expected");
         }
     }
 }
 /// <summary>
 /// Checks the current state of a <see cref="IProgressStep"/>
 /// </summary>
 /// <param name="testSubject">The step to check</param>
 /// <param name="expectedState">The expected state of the step</param>
 public static void CheckState(IProgressStep testSubject, StepExecutionState expectedState)
 {
     Assert.AreEqual(expectedState, testSubject.ExecutionState, "Unexpected state");
 }
Example #17
0
 /// <summary>
 /// Checks the current state of a <see cref="IProgressStep"/>
 /// </summary>
 /// <param name="testSubject">The step to check</param>
 /// <param name="expectedState">The expected state of the step</param>
 public static void CheckState(IProgressStep testSubject, StepExecutionState expectedState)
 {
     Assert.AreEqual(expectedState, testSubject.ExecutionState, "Unexpected state");
 }
Example #18
0
        /// <summary>
        /// Starts executing the initialized steps.
        /// The method is not thread safe but can be called from any thread.
        /// </summary>
        /// <returns>An await-able</returns>
        public async TPL.Task <ProgressControllerResult> Start()
        {
            if (this.IsStarted)
            {
                throw new InvalidOperationException(ProgressResources.AlreadyStartedException);
            }

            this.OnStarted();

            ProgressControllerResult controllerResult = await VsThreadingHelper.RunTask <ProgressControllerResult>(this, VsTaskRunContext.BackgroundThread,
                                                                                                                   () =>
            {
                ThreadHelper.ThrowIfOnUIThread();

                // By default can abort, the individual step may changed that
                this.CanAbort = true;

                ProgressControllerResult result = ProgressControllerResult.Cancelled;
                foreach (IProgressStepOperation operation in this.progressStepOperations)
                {
                    // Try to cancel (in case the step itself will not cancel itself)
                    if (this.cancellationTokenSource.IsCancellationRequested)
                    {
                        result = ProgressControllerResult.Cancelled;
                        break;
                    }

                    this.CanAbort = operation.Step.Cancellable;

                    IProgressStepExecutionEvents notifier = this.stepFactory.GetExecutionCallback(operation);

                    // Give another try before running the operation (there's a test that covers cancellation
                    // before running the operation which requires this check after CanAbort is set)
                    if (this.cancellationTokenSource.IsCancellationRequested)
                    {
                        result = ProgressControllerResult.Cancelled;
                        break;
                    }

                    StepExecutionState stepResult = operation.Run(this.cancellationTokenSource.Token, notifier).Result;

                    /* Not trying to cancel here intentionally. The reason being
                     * in case the step was the last one, there's nothing to cancel really,
                     * otherwise there will be an attempt to cancel just before the next
                     * step execution*/

                    if (stepResult == StepExecutionState.Succeeded)
                    {
                        result = ProgressControllerResult.Succeeded;
                    }
                    else if (stepResult == StepExecutionState.Failed)
                    {
                        result = ProgressControllerResult.Failed;
                        break;
                    }
                    else if (stepResult == StepExecutionState.Cancelled)
                    {
                        result = ProgressControllerResult.Cancelled;
                        break;
                    }
                    else
                    {
                        Debug.Fail("Unexpected step execution result:" + stepResult);
                    }
                }

                return(result);
            },

                                                                                                                   this.cancellationTokenSource.Token);

            this.OnFinished(controllerResult);

            return(controllerResult);
        }
        /// <summary>
        /// Initializes the step
        /// </summary>
        private void Initialize()
        {
            this.state = StepExecutionState.NotStarted;

            bool indeterminate = (this.definition.Attributes & StepAttributes.Indeterminate) != 0 ? true : false;
            StepExecution execution = (this.definition.Attributes & StepAttributes.BackgroundThread) != 0 ? StepExecution.BackgroundThread : StepExecution.ForegroundThread;
            bool hidden = (this.definition.Attributes & StepAttributes.Hidden) != 0 ? true : false;
            bool cancellable = (this.definition.Attributes & StepAttributes.NonCancellable) != 0 ? false : true;
            bool impactingProgress = (this.definition.Attributes & StepAttributes.NoProgressImpact) != 0 ? false : true;
            string displayText = this.definition.DisplayText;

            this.SetStepKind(indeterminate);
            this.Hidden = hidden;
            this.DisplayText = displayText;
            this.Execution = execution;
            this.Cancellable = cancellable;
            this.ImpactsProgress = impactingProgress;
        }