private void SignalReady()
            {
                switch (signalReadyHitCounter)
                {
                case 0:
                    Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady for giving approval to FC's job.");
                    signalReadyHitCounter++;
                    break;

                case 1:
                    Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady after job execution and completion of health check from CM.");
                    Verify.AreEqual(state, State.FromCMAckedCompletedJob,
                                    string.Format(CultureInfo.InvariantCulture, "SignalReady invoked after after health checks from CM to ack completed job: {0}", state));
                    signalReadyHitCounter++;
                    break;

                case 2:
                    Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady 2nd time since MR/FC missed out the previous CompleteJobStep ack.");
                    Verify.AreEqual(state, State.FromISSendSignalReady,
                                    string.Format(CultureInfo.InvariantCulture, "SignalReady invoked 2nd time to re-ack completed job: {0}", state));

                    CompletedEvent.Set();
                    break;
                }
            }
            private void SignalReady()
            {
                switch (signalReadyHitCounter)
                {
                case 0:
                    Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady for MANUAL VendorRepairBegin job.");
                    signalReadyHitCounter++;
                    break;

                case 1:
                    Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady for giving approval to a normal FC's job's StartJobStep.");
                    signalReadyHitCounter++;
                    break;

                case 2:
                    Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady for MANUAL VendorRepairEnd job.");
                    signalReadyHitCounter++;

                    NotificationContext.ImpactedInstances = new List <ImpactedInstance>
                    {
                        new ImpactedInstance("RoleA_IN_1", new List <ImpactReason> {
                            ImpactReason.Reboot
                        })
                    };

                    break;

                case 3:
                    Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady for giving approval to a normal FC's job's CompleteJobStep.");
                    signalReadyHitCounter++;

                    CompletedEvent.Set();
                    break;
                }
            }
            private void SignalError(string errorDescription)
            {
                Trace.ConsoleWriteLine(TraceType,
                                       "IS: Invoking SignalError after job execution and task failure from CM. Error description: {0}", errorDescription);
                Verify.AreEqual(state, State.FromCMHealthCheckFailed,
                                string.Format(CultureInfo.InvariantCulture, "SignalError invoked after health checks from CM failed. Workflow state: {0}", state));

                CompletedEvent.Set();
            }
            private MockManagementNotificationContext GetCurrentNotification()
            {
                switch (state)
                {
                case State.Unknown:
                    Trace.ConsoleWriteLine(TraceType, "MR: Setting NotificationType = StartJobStep to simulate start of a job");
                    NotificationContext.NotificationType = NotificationType.StartJobStep;
                    state = State.FromMRStartingJob;
                    break;

                case State.FromMRStartingJob:
                    // called 2nd time we enter this method after the StartJobStep part above
                    Trace.ConsoleWriteLine(TraceType, "CM: ReportStartTaskSuccessAsync to change job state from WaitingForApproval to Executing inside state machine of WindowsAzureInfrastructureCoordinator");

                    Task.Factory.StartNew(
                        () =>
                    {
                        NotificationContext.NotificationType = NotificationType.StartJobStep;
                        Coordinator.ReportStartTaskSuccessAsync(Coordinator.TaskId, 0, TimeSpan.MaxValue,
                                                                CancellationToken.None);
                    }).Wait();

                    state = State.FromCMStartedJob;
                    break;

                case State.FromCMStartedJob:
                    Trace.ConsoleWriteLine(TraceType, "MR: Setting NotificationType = CompleteJobStep to simulate completion of a job");
                    NotificationContext.NotificationType = NotificationType.CompleteJobStep;
                    state = State.FromMRCompletedJob;
                    break;

                case State.FromMRCompletedJob:
                    Trace.ConsoleWriteLine(TraceType, "CM: ReportFinishTaskSuccessAsync to change job state from WaitingForHealthCheck to Idle inside state machine of WindowsAzureInfrastructureCoordinator");

                    Task.Factory.StartNew(
                        () =>
                    {
                        NotificationContext.NotificationType = NotificationType.CompleteJobStep;
                        Coordinator.ReportFinishTaskSuccessAsync(Coordinator.TaskId, 0, TimeSpan.MaxValue,
                                                                 CancellationToken.None);
                    }).Wait();

                    state = State.FromCMAckedCompletedJob;
                    break;

                case State.FromCMAckedCompletedJob:
                    // MR/FC has missed the previous complete job step. So it sends it again
                    Trace.ConsoleWriteLine(TraceType, "MR: Setting NotificationType = CompleteJobStep to simulate completion of a job");
                    NotificationContext.NotificationType = NotificationType.CompleteJobStep;
                    state = State.FromMRCompletedJob2;
                    break;
                }

                return(NotificationContext);
            }
 public void RunAsyncTest1()
 {
     try
     {
         new WorkflowRunAsyncTest1().Execute();
         Trace.ConsoleWriteLine(TraceType, "Cancellation of coordinator.RunAsync successful");
     }
     catch (Exception ex)
     {
         Verify.Fail(
             string.Format(CultureInfo.InvariantCulture, "Exception unexpected during normal flow of execution till cancellation. Exception: {0}", ex));
     }
 }
        public void HandleCommands1()
        {
            var coordinator1 = new MockInfrastructureCoordinatorFactory(new MockManagementClient()).Create();

            {
                var result =
                    coordinator1.RunCommandAsync(false, "GetRoleInstances", TimeSpan.MaxValue,
                                                 CancellationToken.None).Result;
                Verify.IsNotNull(result, "GetRoleInstances returned a valid string");
            }

            {
                var result = coordinator1.RunCommandAsync(false, "GetJobs", TimeSpan.MaxValue,
                                                          CancellationToken.None).Result;
                Verify.IsNotNull(result, "GetJobs returned a valid string");
            }

            {
                var result =
                    coordinator1.RunCommandAsync(false, "GetCurrentState", TimeSpan.MaxValue,
                                                 CancellationToken.None).Result;
                Verify.IsNotNull(result, "GetCurrentState returned a valid string");
            }

            {
                try
                {
                    // a common typo - GetCurrentStatus instead of GetCurrentState
                    var result =
                        coordinator1.RunCommandAsync(false, "GetCurrentStatus", TimeSpan.MaxValue,
                                                     CancellationToken.None).Result;
                    Verify.Fail("Exception should have been thrown due to an invalid command");
                }
                catch (AggregateException ae)
                {
                    ae.Flatten().Handle(ex =>
                    {
                        if (ex is ArgumentException)
                        {
                            Trace.ConsoleWriteLine(TraceType, "Handling expected exception: {0}", ex);
                            return(true);
                        }

                        return(false);
                    });
                }
            }
        }
예제 #7
0
        private MockPropertyBatchResultWrapper WorkflowForUpdatePolicyAsyncTest3(
            Uri parentName,
            ICollection <PropertyBatchOperation> operations)
        {
            var result = new MockPropertyBatchResultWrapper();

            if (funcToInvoke == 0)
            {
                Trace.ConsoleWriteLine(
                    TraceType,
                    "Setting FailedOperationIndex = -1 to simulate success from ReadProperties() inside UpdatePolicyAsync");
                result.FailedOperationIndex = -1; // operation succeeds
                result.NamedProperties.Add(new MockNamedPropertyWrapper {
                    Value = (Int64)1
                });
                result.NamedProperties.Add(new MockNamedPropertyWrapper
                {
                    Value = JobBlockingPolicy.BlockNone.ToString()
                });

                funcToInvoke++;
            }
            else
            {
                Trace.ConsoleWriteLine(TraceType, "Setting FailedOperationIndex = -1 (i.e. success) to simulate success inside UpdatePolicyAsync");

                // there are 6 operations that are batched up inside UpdatePropertiesAsync
                // If we succeed, we get the values of indices 2 and 4 to update the cache.
                // Simulating this behavior
                result.NamedProperties.Add(new MockNamedPropertyWrapper());
                result.NamedProperties.Add(new MockNamedPropertyWrapper());
                result.NamedProperties.Add(new MockNamedPropertyWrapper {
                    Value = (Int64)2
                });
                result.NamedProperties.Add(new MockNamedPropertyWrapper());
                result.NamedProperties.Add(new MockNamedPropertyWrapper {
                    Value = JobBlockingPolicy.BlockAllJobs.ToString()
                });
                result.NamedProperties.Add(new MockNamedPropertyWrapper());
            }

            return(result);
        }
예제 #8
0
        private MockPropertyBatchResultWrapper WorkflowForUpdatePolicyAsyncTest1(
            Uri parentName,
            ICollection <PropertyBatchOperation> operations)
        {
            var result = new MockPropertyBatchResultWrapper();

            if (funcToInvoke == 0)
            {
                Trace.ConsoleWriteLine(TraceType, "Setting FailedOperationIndex = -1 to simulate success from ReadProperties() inside UpdatePolicyAsync");
                result.FailedOperationIndex = -1; // operation succeeds
                result.NamedProperties.Add(new MockNamedPropertyWrapper {
                    Value = (Int64)1
                });
                result.NamedProperties.Add(new MockNamedPropertyWrapper {
                    Value = JobBlockingPolicy.BlockAllJobs.ToString()
                });

                funcToInvoke++;
            }
            else if (funcToInvoke == 1)
            {
                Trace.ConsoleWriteLine(TraceType, "Setting FailedOperationIndex = 0 to simulate version mismatch from SubmitPropertyBatchAsync inside UpdatePolicyAsync");
                result.FailedOperationIndex     = 0; // operation fails
                result.FailedOperationException = new FabricException(FabricErrorCode.Unknown);

                funcToInvoke++; // the next time SubmitFunc is called, it should succeed
            }
            else
            {
                Trace.ConsoleWriteLine(TraceType, "Setting FailedOperationIndex = -1 to simulate success from ReadProperties() inside UpdatePolicyAsync");
                result.FailedOperationIndex = -1; // operation succeeds
                result.NamedProperties.Add(new MockNamedPropertyWrapper {
                    Value = (Int64)1
                });
                result.NamedProperties.Add(new MockNamedPropertyWrapper {
                    Value = JobBlockingPolicy.BlockAllJobs.ToString()
                });
            }

            return(result);
        }
            public MockManagementNotificationContext GetCurrentNotification()
            {
                switch (state)
                {
                case State.FromMRInitialVendorRepairBegin:
                    Trace.ConsoleWriteLine(TraceType, "MR: Sending a job to IS with impact reason {0}", ImpactReason.VendorRepairBegin);
                    NotificationContext.NotificationType  = NotificationType.StartJobStep;
                    NotificationContext.ImpactedInstances = new List <ImpactedInstance>
                    {
                        new ImpactedInstance("RoleA_IN_0", new List <ImpactReason> {
                            ImpactReason.VendorRepairBegin
                        })
                    };

                    vendorRepairNotificationCounter++;

                    // At this point, the operator has to intervene with a signal ready.
                    // We are simulating this by looping a few times in the same state in this switch-case.
                    if (vendorRepairNotificationCounter >= 3)
                    {
                        state = State.FromISSendSignalReady;
                        vendorRepairNotificationCounter = 0;
                    }

                    break;

                case State.FromISSendSignalReady:
                    Trace.ConsoleWriteLine(TraceType, "IS: Manually issuing a SignalReady to unblock manual approval job (vendor repair begin job)");

                    NotificationContext.SignalReady();

                    state = State.ReadyForNextJob;
                    break;

                case State.ReadyForNextJob:
                    Trace.ConsoleWriteLine(TraceType, "MR: Setting NotificationType = StartJobStep to simulate start of a job with an impact reason not requiring manual approval");

                    NotificationContext.NotificationType  = NotificationType.StartJobStep;
                    NotificationContext.ImpactedInstances = new List <ImpactedInstance>
                    {
                        new ImpactedInstance("RoleA_IN_1", new List <ImpactReason> {
                            ImpactReason.Reboot
                        })
                    };

                    state = State.FromMRStartingJob;
                    break;

                case State.FromMRStartingJob:
                    Trace.ConsoleWriteLine(TraceType, "CM: ReportStartTaskSuccessAsync to change job state from WaitingForApproval to Executing inside state machine of WindowsAzureInfrastructureCoordinator");

                    Task.Factory.StartNew(
                        () =>
                    {
                        NotificationContext.NotificationType = NotificationType.StartJobStep;
                        Coordinator.ReportStartTaskSuccessAsync(Coordinator.TaskId, 0, TimeSpan.MaxValue,
                                                                CancellationToken.None);
                    }).Wait();

                    state = State.FromMRVendorRepairEnd;
                    break;

                case State.FromMRVendorRepairEnd:
                    Trace.ConsoleWriteLine(TraceType, "MR: Sending a new job to IS with impact reason {0}", ImpactReason.VendorRepairEnd);

                    NotificationContext.NotificationType  = NotificationType.StartJobStep;    // TODO or is it a CompleteJobStep
                    NotificationContext.ImpactedInstances = new List <ImpactedInstance>
                    {
                        new ImpactedInstance("RoleA_IN_0", new List <ImpactReason> {
                            ImpactReason.VendorRepairEnd
                        })
                    };

                    vendorRepairNotificationCounter++;

                    if (vendorRepairNotificationCounter >= 3)
                    {
                        state = State.FromISSendSignalReady2;
                        vendorRepairNotificationCounter = 0;
                    }

                    break;

                case State.FromISSendSignalReady2:
                    Trace.ConsoleWriteLine(TraceType, "IS: Manually issuing a SignalReady again to unblock manual approval job (vendor repair end job)");

                    NotificationContext.SignalReady();

                    state = State.FromMRNewCompletedJob;
                    break;

                case State.FromMRNewCompletedJob:
                    Trace.ConsoleWriteLine(TraceType, "MR: Setting NotificationType = CompleteJobStep to simulate completion of a job with an impact reason not requiring manual approval");

                    Task.Factory.StartNew(
                        () =>
                    {
                        NotificationContext.NotificationType = NotificationType.CompleteJobStep;
                        Coordinator.ReportFinishTaskSuccessAsync(Coordinator.TaskId, 0, TimeSpan.MaxValue,
                                                                 CancellationToken.None);
                    }).Wait();

                    state = State.FromCMAckedCompletedJob;
                    break;
                }

                return(NotificationContext);
            }
 private static void SignalReady()
 {
     Trace.ConsoleWriteLine(TraceType, "IS: Invoking SignalReady for giving approval to FC's job.");
 }