public static int GetDoc(string[] args) { CoordinatorEnvironment env = new CoordinatorEnvironment( "fabric:/System/InfrastructureService", new ConfigSection(Constants.TraceType, new MockConfigStore(), "ConfigSection"), string.Empty, new MockInfrastructureAgentWrapper()); Uri zeroSdkUri = null; if (args.Length >= 2) { zeroSdkUri = new Uri(args[1], UriKind.Absolute); } var activityLogger = new ActivityLoggerFactory().Create(Constants.TraceType); var pac = new PolicyAgentClient(env, new PolicyAgentServiceWrapper(env, activityLogger, zeroSdkUri), activityLogger); IPolicyAgentDocumentForTenant doc = pac.GetDocumentAsync(Guid.NewGuid(), CancellationToken.None).GetAwaiter().GetResult(); Constants.TraceType.ConsoleWriteLine("Doc: {0}", doc); foreach (ITenantJob job in doc.Jobs) { Constants.TraceType.ConsoleWriteLine(job.ToJson()); } foreach (RoleInstanceHealthInfo health in doc.RoleInstanceHealthInfos) { Constants.TraceType.ConsoleWriteLine(health.ToJson()); } return(0); }
protected BaseWorkflowExecutor( IDictionary <string, string> configSettings = null, MockPolicyAgentService policyAgentService = null, MockRepairManager repairManager = null) { PolicyAgentService = policyAgentService ?? new MockPolicyAgentService(); var activityLogger = new ActivityLoggerFactory().Create(Constants.TraceType); var env = new CoordinatorEnvironment( "fabric:/System/InfrastructureService", new ConfigSection(Constants.TraceType, new MockConfigStore(), "ConfigSection"), string.Empty, new MockInfrastructureAgentWrapper()); var policyAgentClient = new PolicyAgentClient(env, PolicyAgentService, activityLogger); RepairManager = repairManager ?? new MockRepairManagerFactory().Create() as MockRepairManager; Coordinator = new MockInfrastructureCoordinatorFactory( configSettings, policyAgentClient, RepairManager).Create() as AzureParallelInfrastructureCoordinator; CompletedEvent = new ManualResetEvent(false); TestExecutionTimeInSeconds = 300; }
private static async Task ApproveAllJobsAsync() { Console.WriteLine( "{0:O}: Starting to approve all Azure jobs (max run time = {1})", DateTime.UtcNow, MaximumAutoApproveRunDuration); Stopwatch watch = Stopwatch.StartNew(); try { // Limit maximum run time to avoid inadvertently leaving this running and auto-approving jobs forever while (watch.Elapsed < MaximumAutoApproveRunDuration) { PolicyAgentClient policyAgentClient = null; try { policyAgentClient = CreatePolicyAgentClient(); } catch (Exception e) { Console.WriteLine("ERROR: {0}", e.Message); } if (policyAgentClient == null) { Console.WriteLine("ERROR: Azure infrastructure coordination channel not enabled on this VM. Check tenant configuration or try running this tool on another VM."); return; } try { await ApproveAllJobsOnceAsync(policyAgentClient); } catch (Exception e) { Console.WriteLine("ERROR: {0}", e.Message); } await Task.Delay(JobPollingInterval); } Console.WriteLine( "{0:O}: Exiting because max run time has elapsed ({1})", DateTime.UtcNow, MaximumAutoApproveRunDuration); } catch (Exception e) { Console.WriteLine("ERROR: {0}", e.Message); } }
private static PolicyAgentClient CreatePolicyAgentClient() { CoordinatorEnvironment env = new CoordinatorEnvironment( ToolName, new NullConfigSection(), string.Empty, null); var traceType = new TraceType(ToolName); var activityLogger = new ActivityLoggerFactory().Create(traceType); var policyAgentServiceWrapper = new PolicyAgentServiceWrapper(env, activityLogger, new Uri("http://169.254.169.254:80/mrzerosdk")); var policyAgentClient = new PolicyAgentClient(env, policyAgentServiceWrapper, activityLogger); return(policyAgentClient); }
public static int AcknowledgeJob(string[] args) { CoordinatorEnvironment env = new CoordinatorEnvironment( "fabric:/System/InfrastructureService", new ConfigSection(Constants.TraceType, new MockConfigStore(), "ConfigSection"), string.Empty, new MockInfrastructureAgentWrapper()); Uri zeroSdkUri = null; if (args.Length >= 2) { zeroSdkUri = new Uri(args[1], UriKind.Absolute); } int incarnationNumber = int.Parse(args[2]); Guid jobId = Guid.Parse(args[3]); var activityLogger = new ActivityLoggerFactory().Create(Constants.TraceType); var pac = new PolicyAgentClient(env, new PolicyAgentServiceWrapper(env, activityLogger, zeroSdkUri), activityLogger); var jobResponseMap = new Dictionary <Guid, JobStepResponseEnum> { { jobId, JobStepResponseEnum.Acknowledged } }; try { pac.SendJobResponseAsync( Guid.NewGuid(), incarnationNumber, jobResponseMap, "{0} by operator command".ToString(JobStepResponseEnum.Acknowledged), CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); Console.WriteLine("{0} job response sent successfully", JobStepResponseEnum.Acknowledged); } catch (ManagementException ex) { Console.WriteLine("Error in management protocol while sending job response. Exception: {0}", ex); return(-1); } return(0); }
private static async Task ApproveAllJobsOnceAsync(PolicyAgentClient policyAgentClient) { IPolicyAgentDocumentForTenant doc = null; try { doc = await policyAgentClient.GetDocumentAsync(Guid.Empty, CancellationToken.None); } catch (Exception e) { // PA client can return huge multi-line error messages. Most of that info is not necessary. string msgFirstLine = new StringReader(e.Message ?? string.Empty).ReadLine(); throw new InvalidOperationException( $"Failed to get job information. If you continue to receive this error, check tenant configuration or try running this tool on another VM. {msgFirstLine}", e); } if (doc == null) { // Parallel job mode is not enabled throw new InvalidOperationException("Failed to get job information. Check tenant configuration."); } Dictionary <Guid, JobStepResponseEnum> jobResponses = new Dictionary <Guid, JobStepResponseEnum>(); // Log all incomplete jobs, and record the ID of any that are waiting for tenant approval. foreach (var job in doc.Jobs.Where(j => j.JobStatus != JobStatusEnum.Completed)) { bool approve = IsJobWaitingForApproval(job); if (approve) { jobResponses.Add(job.Id, JobStepResponseEnum.Acknowledged); } Console.WriteLine( "{0:O}: Job {1} ({2}/{3}/UD{4}/{5}/{6}): {7}", DateTime.UtcNow, job.Id, job.GetImpactAction(), job.JobStatus, job.JobStep == null ? "-" : string.Join(",", job.JobStep.CurrentlyImpactedRoleInstances.Select(r => r.UpdateDomain).Distinct().OrderBy(ud => ud)), job.JobStep == null ? "-" : job.JobStep.ImpactStep.ToString(), job.JobStep == null ? "-" : job.JobStep.AcknowledgementStatus.ToString(), approve ? "Sending acknowledgement" : "Acknowledgement not needed in this state"); } if (jobResponses.Count > 0) { // Send all job responses (if any) as a single batch response await policyAgentClient.SendJobResponseAsync( Guid.Empty, doc.JobDocumentIncarnation, jobResponses, $"Manually approved by {ToolName}", CancellationToken.None); Console.WriteLine( "{0:O}: Approved job count = {1}, incarnation = {2}", DateTime.UtcNow, jobResponses.Count, doc.JobDocumentIncarnation); } else { Console.WriteLine( "{0:O}: No jobs to approve", DateTime.UtcNow); } }