Ejemplo n.º 1
0
 public RequestRepairAction(CoordinatorEnvironment environment, IPolicyAgentClient policyAgentClient, IRepairTask repairTask, RepairActionProvider repairActionProvider)
     : base(environment, ActionType.RequestRepair)
 {
     this.policyAgentClient    = policyAgentClient.Validate("policyAgentClient");
     this.repairTask           = repairTask.Validate("repairTask");
     this.repairActionProvider = repairActionProvider.Validate("repairActionProvider");
 }
        /// <summary>
        /// Cleans up state during coordinator shutdown and releases the lock.
        /// </summary>
        private void CompleteRunAsync()
        {
            traceType.WriteInfo("CompleteRunAsync: coordinator is stopped");

            this.isNotificationAvailable        = false;
            this.lastHealthIncarnation          = 0;
            this.lastHealthIncarnationUpdatedAt = null;
            this.repairActionProvider           = null;

            Interlocked.Exchange(ref this.isCoordinatorRunning, 0);
        }
Ejemplo n.º 3
0
 public ActionFactory(
     CoordinatorEnvironment environment,
     IPolicyAgentClient policyAgentClient,
     IRepairManager repairManager,
     RepairActionProvider repairActionProvider)
 {
     this.environment          = environment.Validate("environment");
     this.policyAgentClient    = policyAgentClient.Validate("policyAgentClient");
     this.repairManager        = repairManager.Validate("repairManager");
     this.repairActionProvider = repairActionProvider.Validate("repairActionProvider");
     this.jobResponseMap       = new Dictionary <Guid, JobStepResponseEnum>();
 }
 public ClaimedRepairTaskAction(
     CoordinatorEnvironment environment,
     IRepairManager repairManager,
     IRepairTask repairTask,
     IList <string> roleInstanceNames,
     RepairActionProvider repairActionProvider)
     : base(environment, ActionType.None)
 {
     this.repairManager        = repairManager.Validate("repairManager");
     this.repairTask           = repairTask.Validate("repairTask");
     this.roleInstanceNames    = roleInstanceNames.Validate("roleInstanceName");
     this.repairActionProvider = repairActionProvider.Validate("repairActionProvider");
 }
Ejemplo n.º 5
0
        // Does repairTask represent a VendorRepair, via action/target match?
        public static bool MatchesVendorRepairJobByActionAndTarget(this IRepairTask repairTask, RepairActionProvider repairActionProvider, IConfigSection configSection, ITenantJob tenantJob)
        {
            repairTask.Validate("repairTask");
            tenantJob.Validate("tenantJob");

            // 1. check action
            RepairActionTypeEnum?actionFromRepairTask = repairActionProvider.GetRepairAction(repairTask.Action);

            if (!actionFromRepairTask.HasValue || RepairActionTypeEnum.Heal != actionFromRepairTask.Value)
            {
                return(false);
            }

            // 2. check targets (nodes)
            // TODO should this be RoleInstancesToBeImpacted or JobStep.CurrentlyImpactedRoleInstances?
            if (tenantJob.RoleInstancesToBeImpacted == null || tenantJob.RoleInstancesToBeImpacted.Count != 1)
            {
                Constants.TraceType.WriteInfo(
                    "Task '{0}' does not match VendorRepair job {1} since RoleInstancesToBeImpacted does not have exactly one instance: {2}",
                    repairTask.TaskId,
                    tenantJob.Id,
                    tenantJob.ToJson());
                return(false);
            }

            var nodeNames = repairTask.GetTargetNodeNames();

            if (nodeNames == null || nodeNames.Count != 1)
            {
                Constants.TraceType.WriteInfo(
                    "Task '{0}' does not match VendorRepair job {1} since task target does not have exactly one node: {2}",
                    repairTask.TaskId,
                    tenantJob.Id,
                    nodeNames.ToJson());
                return(false);
            }

            var repairTaskTargetRoleInstance = nodeNames[0].TranslateNodeNameToRoleInstance();
            var jobRoleInstance = tenantJob.RoleInstancesToBeImpacted[0];

            bool targetsMatch = string.Equals(repairTaskTargetRoleInstance, jobRoleInstance, StringComparison.OrdinalIgnoreCase);

            return(targetsMatch);
        }
        public async Task RunAsync(int primaryEpoch, CancellationToken token)
        {
            if (primaryEpoch < 0)
            {
                throw new ArgumentOutOfRangeException("primaryEpoch");
            }

            if (!this.TryStartRunAsync())
            {
                throw new InvalidOperationException("Coordinator has already been started");
            }

            try
            {
                if (primaryEpoch < this.primaryEpoch)
                {
                    throw new ArgumentException("Primary epoch must be non-decreasing", "primaryEpoch");
                }

                if (this.primaryEpoch < primaryEpoch)
                {
                    this.nextSequenceNumber = 0;
                }

                coordinatorCommandProcessor.Reset();
                coordinatorRunAsyncStartTime = DateTimeOffset.UtcNow;

                coordinatorCommandProcessor.CoordinatorDiagnosticInfo = new CoordinatorDiagnosticInfo
                {
                    CoordinatorStartTime = "{0:o}".ToString(coordinatorRunAsyncStartTime),
                    AzureTenantId        = this.tenantId,
                    AssemblyFileVersion  = this.assemblyFileVersion,
                };

                this.primaryEpoch = primaryEpoch;

                traceType.WriteInfo("RunAsync: primaryEpoch = 0x{0:X}, nextSequenceNumber = 0x{1:X}",
                                    this.primaryEpoch,
                                    this.nextSequenceNumber);

                traceType.WriteAggregatedEvent(
                    InfrastructureService.Constants.CoordinatorModeKey,
                    this.tenantId,
                    "{0}",
                    new CoordinatorStateData().Mode);

                this.isNotificationAvailable        = false;
                this.lastHealthIncarnation          = 0;
                this.lastHealthIncarnationUpdatedAt = null;

                this.repairActionProvider = new RepairActionProvider(configSection);

                ActionHelper.ResetActionPolicies(actionPolicies);

                // Clear old AzureSerial health property
                ClearLegacyNotificationApprovalHealthStatus();

                await StartJobTaskAsync(token).ConfigureAwait(false);
            }
            finally
            {
                this.CompleteRunAsync();
            }
        }