public AzureParallelInfrastructureCoordinatorFactory( Uri serviceName, IConfigStore configStore, string configSectionName, Guid partitionId, long replicaId, IInfrastructureAgentWrapper agent) { this.serviceName = serviceName.Validate("serviceName"); configStore.Validate("configStore"); configSectionName.Validate("configSectionName"); this.agent = agent.Validate("agent"); this.configSection = new ConfigSection(TraceType, configStore, configSectionName); this.partitionId = partitionId; this.replicaId = replicaId; try { this.tenantId = AzureHelper.GetTenantId(configSection); } catch (Exception ex) { // this happens on the Linux environment (since there is no registry) this.tenantId = PartitionIdPrefix + partitionId; TraceType.WriteWarning("Unable to get tenant Id from configuration. Using partition Id '{0}' text instead. Exception: {1}", this.tenantId, ex); } // TODO use tenant ID or config section name suffix as base trace ID? this.env = new CoordinatorEnvironment(this.serviceName.AbsoluteUri, this.configSection, tenantId, this.agent); this.activityLogger = new ActivityLoggerFactory().Create(env.CreateTraceType("Event")); this.policyAgentServiceWrapper = new PolicyAgentServiceWrapper(env, activityLogger); }
private async Task <DMResponse> SendRequestAsync(string command, bool readOnly, bool logResponseContent = true) { traceType.WriteInfo("Sending {0} command: {1}", readOnly ? "read" : "write", command); var watch = Stopwatch.StartNew(); DMResponse response = await dmClient.SendRequestAsync(command, null, readOnly); string message = string.Format( "DM response to command '{0}': HTTP {1}, status {2}, elapsed {3} msec\n{4}", command, response.HttpResponseCode, response.Status, watch.ElapsedMilliseconds, logResponseContent ? response.Response : $"(response content omitted; length = {response.Response?.Length})"); if (response.Status == DMServerResponseCode.Ok) { traceType.WriteInfo("{0}", message); } else { traceType.WriteWarning("{0}", message); } return(response); }
public static async Task ExecuteActionsAsync( Guid activityId, TraceType traceType, IList <IAction> actions) { traceType.Validate("traceType"); actions.Validate("actions"); var exceptions = new List <Exception>(); foreach (var action in actions) { try { traceType.WriteInfo("{0} Start: {1}", activityId, action); await action.ExecuteAsync(activityId).ConfigureAwait(false); traceType.WriteInfo("{0} Finish: {1}", activityId, action); } catch (Exception ex) { traceType.WriteWarning("{0} Error: {1}{2}Exception: {3}", activityId, action, Environment.NewLine, ex); exceptions.Add(ex); } } if (exceptions.Count > 0) { throw new AggregateException(exceptions); } }
public async Task RemoveNodeStateAsync(Guid activityId, string nodeName, TimeSpan timeout, CancellationToken cancellationToken) { nodeName.Validate("nodeName"); var startTime = DateTimeOffset.UtcNow; try { await this.fabricClient.ClusterManager.RemoveNodeStateAsync(nodeName, timeout, cancellationToken); traceType.WriteInfo("RemoveNodeState succeeded for {0}", nodeName); activityLogger.LogOperation(activityId, startTime, OperationResult.Success, null, nodeName); } catch (Exception ex) { traceType.WriteWarning("RemoveNodeState failed for {0}: {1}", nodeName, ex); activityLogger.LogOperation(activityId, startTime, OperationResult.Failure, ex, nodeName); throw; } }
public async Task <AzureMode> DetectModeAsync() { try { byte[] responseBytes = await GetDocumentFromWireServerAsync().ConfigureAwait(false); var doc = responseBytes.GetBondObjectFromPayload <PolicyAgentDocumentForTenant>(); // The ZeroSDK document should always be present. The presence or absense of the // JobInfo property indicates whether the tenant is in parallel or serial mode. if (doc.JobInfo == null) { return(AzureMode.Serial); } return(AzureMode.Parallel); } catch (Exception e) { traceType.WriteWarning("Failed to detect Azure mode: {0}", e); return(AzureMode.Unknown); } }
public async Task <IList <MachineMaintenanceRecord> > GetDevicesPendingMaintenanceAsync() { var response = await dmClient.GetDevicesPendingMaintenanceAsync(); VerifyResponse(response); using (var csvReader = new CsvReader(new StringReader(response.Response))) { List <MachineMaintenanceRecord> records = new List <MachineMaintenanceRecord>(); while (csvReader.Read()) { string machineName = csvReader["MACHINENAME"]; string repairType = csvReader["ACTION"]; string delayInSec = csvReader["DELAYINSEC"]; int delay; if (!int.TryParse(delayInSec, out delay)) { traceType.WriteWarning( "Unable to parse current delay: MACHINENAME='{0}' ACTION='{1}' DELAYINSEC='{2}'", machineName, repairType, delayInSec); delay = 59; // set this to some small value, so that we assume it is already approved } TimeSpan delaySpan = TimeSpan.FromSeconds(delay); var recordId = new MaintenanceRecordId(machineName, repairType); var record = MachineMaintenanceRecord.FromPendingRepair(recordId, delaySpan); records.Add(record); } return(records); } }
private bool IsInstanceRemoval(ImpactActionEnum jobType, AffectedResourceImpact impactDetail) { bool isInstanceRemovalImpact = jobType == ImpactActionEnum.TenantUpdate && CoordinatorHelper.AllImpactsEqual(impactDetail, Impact.Wipe); bool isInstanceRemovalLegacy = false; if (impactDetail.ListOfImpactTypes != null) { isInstanceRemovalLegacy = impactDetail.ListOfImpactTypes.Contains(ImpactTypeEnum.InstanceRemoval); } if (isInstanceRemovalImpact != isInstanceRemovalLegacy) { tracer.WriteWarning( "Mismatch between IsInstanceRemoval result from resource impacts ({0}) and ImpactTypeEnum ({1}); using {0}", isInstanceRemovalImpact, isInstanceRemovalLegacy); } return(isInstanceRemovalImpact); }
public Task ReportStartTaskSuccessAsync(string taskId, long instanceId, TimeSpan timeout, CancellationToken cancellationToken) { traceType.WriteWarning("Processing unexpected CM callback ReportStartTaskSuccessAsync('{0}',0x{1:X})", taskId, instanceId); return(Task.FromResult(0)); }