private static WorkerPoolResource CreateWorkerPool(int prefix) { var pool = new WorkerPoolResource() { Name = "GarblovianWorkerPool-" + Guid.NewGuid().ToString().Substring(0, 8) + "-" + prefix.ToString("000"), }; return(pool); }
public async Task Request() { if (string.IsNullOrWhiteSpace(poolName)) { throw new CommandException("Please specify a worker pool name using the parameter: --workerpool=XYZ"); } if (!healthStatuses.Any()) { throw new CommandException("Please specify a status using the parameter: --health-status"); } workerPoolResource = await GetWorkerPool().ConfigureAwait(false); machines = await FilterByWorkerPool(workerPoolResource).ConfigureAwait(false); machines = await FilterByState(machines).ConfigureAwait(false); await CleanUpPool(machines.ToList(), workerPoolResource).ConfigureAwait(false); }
async Task CleanUpPool(List <WorkerResource> filteredMachines, WorkerPoolResource poolResource) { commandOutputProvider.Information("Found {MachineCount} machines in {WorkerPool:l} with the status {Status:l}", filteredMachines.Count, poolResource.Name, GetStateFilterDescription()); if (filteredMachines.Any(m => m.WorkerPoolIds.Count > 1)) { commandOutputProvider.Information("Note: Some of these machines belong to multiple pools. Instead of being deleted, these machines will be removed from the {WorkerPool:l} pool.", poolResource.Name); } foreach (var machine in filteredMachines) { var result = new MachineResult { Machine = machine }; // If the machine belongs to more than one pool, we should remove the machine from the pool rather than delete it altogether. if (machine.WorkerPoolIds.Count > 1) { commandOutputProvider.Information("Removing {Machine:l} {Status} (ID: {Id:l}) from {WorkerPool:l}", machine.Name, machine.Status, machine.Id, poolResource.Name); machine.WorkerPoolIds.Remove(poolResource.Id); await Repository.Workers.Modify(machine).ConfigureAwait(false); result.Action = MachineAction.RemovedFromPool; } else { commandOutputProvider.Information("Deleting {Machine:l} {Status} (ID: {Id:l})", machine.Name, machine.Status, machine.Id); await Repository.Workers.Delete(machine).ConfigureAwait(false); result.Action = MachineAction.Deleted; } commandResults.Add(result); } }
public async Task Request() { if (string.IsNullOrWhiteSpace(WorkerPoolName)) { throw new CommandException("Please specify a worker pool name using the parameter: --name=XYZ"); } pool = await Repository.WorkerPools.FindByName(WorkerPoolName).ConfigureAwait(false); if (pool != null) { if (IgnoreIfExists) { commandOutputProvider.Information("The worker pool {WorkerPool:l} (ID {Id:l}) already exists", pool.Name, pool.Id); return; } throw new CommandException("The worker pool " + pool.Name + " (ID " + pool.Id + ") already exists"); } commandOutputProvider.Information("Creating worker pool: {WorkerPool:l}", WorkerPoolName); pool = await Repository.WorkerPools.Create(new WorkerPoolResource { Name = WorkerPoolName }).ConfigureAwait(false); }
Task <List <WorkerResource> > FilterByWorkerPool(WorkerPoolResource poolResource) { commandOutputProvider.Debug("Loading workers..."); return(Repository.Workers.FindMany(x => x.WorkerPoolIds.Any(poolId => poolId == poolResource.Id))); }