From 2ea3bcac833d9fdb215f3ef288c9cbdc083d64c8 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 07:13:06 +1000 Subject: [PATCH 01/37] Create DeploymentTarget type. --- .../Model/DeploymentTargetResource.cs | 133 ++++++++++++++ .../Model/MachineBasedResource.cs | 50 ++++++ .../Octopus.Client/Model/MachineResource.cs | 169 +----------------- 3 files changed, 187 insertions(+), 165 deletions(-) create mode 100644 source/Octopus.Client/Model/DeploymentTargetResource.cs create mode 100644 source/Octopus.Client/Model/MachineBasedResource.cs diff --git a/source/Octopus.Client/Model/DeploymentTargetResource.cs b/source/Octopus.Client/Model/DeploymentTargetResource.cs new file mode 100644 index 000000000..9d1505ed2 --- /dev/null +++ b/source/Octopus.Client/Model/DeploymentTargetResource.cs @@ -0,0 +1,133 @@ +using System.Linq; +using Octopus.Client.Extensibility.Attributes; + +namespace Octopus.Client.Model +{ + public class DeploymentTargetResource : MachineBasedResource + { + public DeploymentTargetResource() + { + EnvironmentIds = new ReferenceCollection(); + Roles = new ReferenceCollection(); + TenantTags = new ReferenceCollection(); + TenantIds = new ReferenceCollection(); + } + + [Writeable] + public ReferenceCollection EnvironmentIds { get; set; } + + [Writeable] + public ReferenceCollection Roles { get; set; } + + // Nullable backing-field is to support backwards-compatibility + TenantedDeploymentMode? tenantedDeploymentParticipation; + + [Writeable] + public TenantedDeploymentMode TenantedDeploymentParticipation + { + set => tenantedDeploymentParticipation = value; + + get + { + if (tenantedDeploymentParticipation.HasValue) + return tenantedDeploymentParticipation.Value; + + // Responses from server versions before TenantedDeploymentParticipation was implemented will default + // to pre-existing behaviour + return TenantIds.Any() || TenantTags.Any() + ? TenantedDeploymentMode.Tenanted + : TenantedDeploymentMode.Untenanted; + } + } + + [Writeable] + public ReferenceCollection TenantIds { get; set; } + + [Writeable] + public ReferenceCollection TenantTags { get; set; } + + public DeploymentTargetResource AddOrUpdateEnvironments(params EnvironmentResource[] environments) + { + foreach (var environment in environments) + { + EnvironmentIds.Add(environment.Id); + } + return this; + } + + public DeploymentTargetResource RemoveEnvironment(EnvironmentResource environment) + { + EnvironmentIds.Remove(environment.Id); + return this; + } + + public DeploymentTargetResource ClearEnvironments() + { + EnvironmentIds.Clear(); + return this; + } + + public DeploymentTargetResource AddOrUpdateRoles(params string[] roles) + { + foreach (var role in roles) + { + Roles.Add(role); + } + return this; + } + + public DeploymentTargetResource RemoveRole(string role) + { + Roles.Remove(role); + return this; + } + + public DeploymentTargetResource ClearRoles() + { + Roles.Clear(); + return this; + } + + public DeploymentTargetResource AddOrUpdateTenants(params TenantResource[] tenants) + { + foreach (var tenant in tenants) + { + TenantIds.Add(tenant.Id); + } + return this; + } + + public DeploymentTargetResource RemoveTenant(TenantResource tenant) + { + TenantIds.Remove(tenant.Id); + return this; + } + + public DeploymentTargetResource ClearTenants() + { + TenantIds.Clear(); + return this; + } + + public DeploymentTargetResource AddOrUpdateTenantTags(params TagResource[] tenantTags) + { + foreach (var tenantTag in tenantTags) + { + TenantTags.Add(tenantTag.CanonicalTagName); + } + return this; + } + + public DeploymentTargetResource RemoveTenantTag(TagResource tenantTag) + { + TenantTags.Remove(tenantTag.CanonicalTagName); + return this; + } + + public DeploymentTargetResource ClearTenantTags() + { + TenantTags.Clear(); + return this; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Model/MachineBasedResource.cs b/source/Octopus.Client/Model/MachineBasedResource.cs new file mode 100644 index 000000000..7126c81dd --- /dev/null +++ b/source/Octopus.Client/Model/MachineBasedResource.cs @@ -0,0 +1,50 @@ +using System.Linq; +using Octopus.Client.Extensibility; +using Octopus.Client.Extensibility.Attributes; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Client.Model +{ + public abstract class MachineBasedResource : Resource, INamedResource + { + + + [Trim] + [Writeable] + public string Name { get; set; } + + /// + /// Obsoleted as Server 3.4 + /// + [Trim] + [Writeable] + public string Thumbprint { get; set; } + + /// + /// Obsoleted as Server 3.4 + /// + [Trim] + [Writeable] + public string Uri { get; set; } + + [Writeable] + public bool IsDisabled { get; set; } + + [Writeable] + public string MachinePolicyId { get; set; } + + /// + /// Obsoleted as Server 3.4 + /// + public MachineModelStatus Status { get; set; } + + public MachineModelHealthStatus HealthStatus { get; set; } + public bool HasLatestCalamari { get; set; } + public string StatusSummary { get; set; } + + public bool IsInProcess { get; set; } + + [Writeable] + public EndpointResource Endpoint { get; set; } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Model/MachineResource.cs b/source/Octopus.Client/Model/MachineResource.cs index 80f3f73fa..aad179981 100644 --- a/source/Octopus.Client/Model/MachineResource.cs +++ b/source/Octopus.Client/Model/MachineResource.cs @@ -1,174 +1,13 @@ -using System.Linq; -using Octopus.Client.Extensibility; -using Octopus.Client.Extensibility.Attributes; -using Octopus.Client.Model.Endpoints; +using System; namespace Octopus.Client.Model { - public class MachineResource : Resource, INamedResource + [Obsolete("MachineResource was deprecated in Octopus 2018.5.0. Please use DeploymentTargetResource instead.")] + public class MachineResource : DeploymentTargetResource { - public MachineResource() + public MachineResource() : base() { - EnvironmentIds = new ReferenceCollection(); - Roles = new ReferenceCollection(); - TenantTags = new ReferenceCollection(); - TenantIds = new ReferenceCollection(); - } - - [Trim] - [Writeable] - public string Name { get; set; } - - /// - /// Obsoleted as Server 3.4 - /// - [Trim] - [Writeable] - public string Thumbprint { get; set; } - - /// - /// Obsoleted as Server 3.4 - /// - [Trim] - [Writeable] - public string Uri { get; set; } - - [Writeable] - public bool IsDisabled { get; set; } - - [Writeable] - public ReferenceCollection EnvironmentIds { get; set; } - - [Writeable] - public ReferenceCollection Roles { get; set; } - - [Writeable] - public string MachinePolicyId { get; set; } - - // Nullable backing-field is to support backwards-compatibility - TenantedDeploymentMode? tenantedDeploymentParticipation; - - [Writeable] - public TenantedDeploymentMode TenantedDeploymentParticipation - { - set => tenantedDeploymentParticipation = value; - - get - { - if (tenantedDeploymentParticipation.HasValue) - return tenantedDeploymentParticipation.Value; - - // Responses from server versions before TenantedDeploymentParticipation was implemented will default - // to pre-existing behaviour - return TenantIds.Any() || TenantTags.Any() - ? TenantedDeploymentMode.Tenanted - : TenantedDeploymentMode.Untenanted; - } - } - - [Writeable] - public ReferenceCollection TenantIds { get; set; } - - [Writeable] - public ReferenceCollection TenantTags { get; set; } - - - /// - /// Obsoleted as Server 3.4 - /// - public MachineModelStatus Status { get; set; } - - public MachineModelHealthStatus HealthStatus { get; set; } - public bool HasLatestCalamari { get; set; } - public string StatusSummary { get; set; } - - public bool IsInProcess { get; set; } - - [Writeable] - public EndpointResource Endpoint { get; set; } - - public MachineResource AddOrUpdateEnvironments(params EnvironmentResource[] environments) - { - foreach (var environment in environments) - { - EnvironmentIds.Add(environment.Id); - } - return this; - } - - public MachineResource RemoveEnvironment(EnvironmentResource environment) - { - EnvironmentIds.Remove(environment.Id); - return this; - } - - public MachineResource ClearEnvironments() - { - EnvironmentIds.Clear(); - return this; - } - - public MachineResource AddOrUpdateRoles(params string[] roles) - { - foreach (var role in roles) - { - Roles.Add(role); - } - return this; - } - - public MachineResource RemoveRole(string role) - { - Roles.Remove(role); - return this; - } - - public MachineResource ClearRoles() - { - Roles.Clear(); - return this; - } - - public MachineResource AddOrUpdateTenants(params TenantResource[] tenants) - { - foreach (var tenant in tenants) - { - TenantIds.Add(tenant.Id); - } - return this; - } - public MachineResource RemoveTenant(TenantResource tenant) - { - TenantIds.Remove(tenant.Id); - return this; - } - - public MachineResource ClearTenants() - { - TenantIds.Clear(); - return this; - } - - public MachineResource AddOrUpdateTenantTags(params TagResource[] tenantTags) - { - foreach (var tenantTag in tenantTags) - { - TenantTags.Add(tenantTag.CanonicalTagName); - } - return this; - } - - public MachineResource RemoveTenantTag(TagResource tenantTag) - { - TenantTags.Remove(tenantTag.CanonicalTagName); - return this; - } - - public MachineResource ClearTenantTags() - { - TenantTags.Clear(); - return this; } } } \ No newline at end of file From 27b2b6c37096e26aa103751eb7a3dca72ab9a3bd Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 10:15:14 +1000 Subject: [PATCH 02/37] Add Worker resources --- .../Octopus.Client/Model/MachineResource.cs | 1 - .../Model/WorkerMachineResource.cs | 39 +++++++++++++++++++ .../Model/WorkerPoolResource.cs | 34 ++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 source/Octopus.Client/Model/WorkerMachineResource.cs create mode 100644 source/Octopus.Client/Model/WorkerPoolResource.cs diff --git a/source/Octopus.Client/Model/MachineResource.cs b/source/Octopus.Client/Model/MachineResource.cs index aad179981..0124aca90 100644 --- a/source/Octopus.Client/Model/MachineResource.cs +++ b/source/Octopus.Client/Model/MachineResource.cs @@ -2,7 +2,6 @@ namespace Octopus.Client.Model { - [Obsolete("MachineResource was deprecated in Octopus 2018.5.0. Please use DeploymentTargetResource instead.")] public class MachineResource : DeploymentTargetResource { public MachineResource() : base() diff --git a/source/Octopus.Client/Model/WorkerMachineResource.cs b/source/Octopus.Client/Model/WorkerMachineResource.cs new file mode 100644 index 000000000..d8363635c --- /dev/null +++ b/source/Octopus.Client/Model/WorkerMachineResource.cs @@ -0,0 +1,39 @@ +using System.Linq; +using Octopus.Client.Extensibility; +using Octopus.Client.Extensibility.Attributes; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Client.Model +{ + public class WorkerMachineResource : MachineBasedResource + { + public WorkerMachineResource() + { + WorkerPoolIds = new ReferenceCollection(); + } + + [Writeable] + public ReferenceCollection WorkerPoolIds { get; set; } + + public WorkerMachineResource AddOrUpdateWorkerPools(params WorkerPoolResource[] pools) + { + foreach (var pool in pools) + { + WorkerPoolIds.Add(pool.Id); + } + return this; + } + + public WorkerMachineResource RemoveWorkerPool(WorkerPoolResource pool) + { + WorkerPoolIds.Remove(pool.Id); + return this; + } + + public WorkerMachineResource ClearWorkerPools() + { + WorkerPoolIds.Clear(); + return this; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Model/WorkerPoolResource.cs b/source/Octopus.Client/Model/WorkerPoolResource.cs new file mode 100644 index 000000000..ca32aafba --- /dev/null +++ b/source/Octopus.Client/Model/WorkerPoolResource.cs @@ -0,0 +1,34 @@ +using Octopus.Client.Extensibility; +using Octopus.Client.Extensibility.Attributes; + +namespace Octopus.Client.Model +{ + /// + /// Represents a pool of worker machines. WorkerPools are user-defined and map to pools of machines that + /// can do work as part of a deployment: for example, running scripts and deploying to Azure. + /// + public class WorkerPoolResource : Resource, INamedResource + { + /// + /// Gets or sets the name of this pool. This should be short, preferably 5-20 characters. + /// + [Writeable] + [Trim] + public string Name { get; set; } + + /// + /// Gets or sets a short description that can be used to explain the purpose of + /// the pool to other users. This field may contain markdown. + /// + [Writeable] + [Trim] + public string Description { get; set; } + + /// + /// Gets or sets a number indicating the priority of this pool in sort order. WorkerPools with + /// a lower sort order will appear in the UI before items with a higher sort order. + /// + [Writeable] + public int SortOrder { get; set; } + } +} \ No newline at end of file From e7faf05e4344df1629fd4ae886a2df0fc163fe7b Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 10:16:56 +1000 Subject: [PATCH 03/37] Create summary resources for worker pools. --- .../Model/EnvironmentSummaryResource.cs | 8 +------- .../Model/EnvironmentsSummaryResource.cs | 8 +------- source/Octopus.Client/Model/SummaryResource.cs | 14 ++++++++++++++ .../Model/SummaryResourcesCombined.cs | 14 ++++++++++++++ .../Model/WorkerPoolSummaryResource.cs | 9 +++++++++ .../Model/WorkerPoolsSummaryResource.cs | 9 +++++++++ 6 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 source/Octopus.Client/Model/SummaryResource.cs create mode 100644 source/Octopus.Client/Model/SummaryResourcesCombined.cs create mode 100644 source/Octopus.Client/Model/WorkerPoolSummaryResource.cs create mode 100644 source/Octopus.Client/Model/WorkerPoolsSummaryResource.cs diff --git a/source/Octopus.Client/Model/EnvironmentSummaryResource.cs b/source/Octopus.Client/Model/EnvironmentSummaryResource.cs index c9d2f41a6..9d16327f1 100644 --- a/source/Octopus.Client/Model/EnvironmentSummaryResource.cs +++ b/source/Octopus.Client/Model/EnvironmentSummaryResource.cs @@ -2,16 +2,10 @@ namespace Octopus.Client.Model { - public class EnvironmentSummaryResource + public class EnvironmentSummaryResource : SummaryResource { public EnvironmentResource Environment { get; set; } - public int TotalMachines { get; set; } - public int TotalDisabledMachines { get; set; } - public Dictionary MachineHealthStatusSummaries { get; set; } - public Dictionary MachineEndpointSummaries { get; set; } public Dictionary MachineTenantSummaries { get; set; } public Dictionary MachineTenantTagSummaries { get; set; } - public bool TentacleUpgradesRequired { get; set; } - public string[] MachineIdsForCalamariUpgrade { get; set; } } } diff --git a/source/Octopus.Client/Model/EnvironmentsSummaryResource.cs b/source/Octopus.Client/Model/EnvironmentsSummaryResource.cs index cefb485d9..31631c78b 100644 --- a/source/Octopus.Client/Model/EnvironmentsSummaryResource.cs +++ b/source/Octopus.Client/Model/EnvironmentsSummaryResource.cs @@ -2,16 +2,10 @@ namespace Octopus.Client.Model { - public class EnvironmentsSummaryResource + public class EnvironmentsSummaryResource : SummaryResourcesCombined { - public int TotalMachines { get; set; } - public int TotalDisabledMachines { get; set; } - public Dictionary MachineHealthStatusSummaries { get; set; } - public Dictionary MachineEndpointSummaries { get; set; } public Dictionary MachineTenantSummaries { get; set; } public Dictionary MachineTenantTagSummaries { get; set; } public List EnvironmentSummaries { get; set; } - public bool TentacleUpgradesRequired { get; set; } - public string[] MachineIdsForCalamariUpgrade { get; set; } } } diff --git a/source/Octopus.Client/Model/SummaryResource.cs b/source/Octopus.Client/Model/SummaryResource.cs new file mode 100644 index 000000000..d2206f70a --- /dev/null +++ b/source/Octopus.Client/Model/SummaryResource.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Octopus.Client.Model +{ + public class SummaryResource + { + public int TotalMachines { get; set; } + public int TotalDisabledMachines { get; set; } + public Dictionary MachineHealthStatusSummaries { get; set; } + public Dictionary MachineEndpointSummaries { get; set; } + public bool TentacleUpgradesRequired { get; set; } + public string[] MachineIdsForCalamariUpgrade { get; set; } + } +} diff --git a/source/Octopus.Client/Model/SummaryResourcesCombined.cs b/source/Octopus.Client/Model/SummaryResourcesCombined.cs new file mode 100644 index 000000000..7ed038ca1 --- /dev/null +++ b/source/Octopus.Client/Model/SummaryResourcesCombined.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace Octopus.Client.Model +{ + public class SummaryResourcesCombined + { + public int TotalMachines { get; set; } + public int TotalDisabledMachines { get; set; } + public Dictionary MachineHealthStatusSummaries { get; set; } + public Dictionary MachineEndpointSummaries { get; set; } + public bool TentacleUpgradesRequired { get; set; } + public string[] MachineIdsForCalamariUpgrade { get; set; } + } +} diff --git a/source/Octopus.Client/Model/WorkerPoolSummaryResource.cs b/source/Octopus.Client/Model/WorkerPoolSummaryResource.cs new file mode 100644 index 000000000..648b0c512 --- /dev/null +++ b/source/Octopus.Client/Model/WorkerPoolSummaryResource.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Octopus.Client.Model +{ + public class WorkerPoolSummaryResource : SummaryResource + { + public WorkerPoolResource WorkerPool { get; set; } + } +} diff --git a/source/Octopus.Client/Model/WorkerPoolsSummaryResource.cs b/source/Octopus.Client/Model/WorkerPoolsSummaryResource.cs new file mode 100644 index 000000000..2fadb1ca4 --- /dev/null +++ b/source/Octopus.Client/Model/WorkerPoolsSummaryResource.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Octopus.Client.Model +{ + public class WorkerPoolsSummaryResource : SummaryResourcesCombined + { + public List WorkerPoolSummaries { get; set; } + } +} From e72689e06591b3129dbdf1cff64d7b2efe9d20f2 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 10:18:47 +1000 Subject: [PATCH 04/37] Create repositories and editors for workers and pools. --- .../Commands/HealthStatusProvider.cs | 10 +- .../Editors/Async/WorkerMachineEditor.cs | 60 +++++++++++ .../Editors/Async/WorkerPoolEditor.cs | 73 +++++++++++++ .../Editors/WorkerMachineEditor.cs | 59 +++++++++++ .../Editors/WorkerPoolEditor.cs | 72 +++++++++++++ .../Async/WorkerMachineRepository.cs | 87 +++++++++++++++ .../Async/WorkerPoolRepository.cs | 100 ++++++++++++++++++ .../Repositories/WorkerMachineRepository.cs | 87 +++++++++++++++ .../Repositories/WorkerPoolRepository.cs | 99 +++++++++++++++++ 9 files changed, 642 insertions(+), 5 deletions(-) create mode 100644 source/Octopus.Client/Editors/Async/WorkerMachineEditor.cs create mode 100644 source/Octopus.Client/Editors/Async/WorkerPoolEditor.cs create mode 100644 source/Octopus.Client/Editors/WorkerMachineEditor.cs create mode 100644 source/Octopus.Client/Editors/WorkerPoolEditor.cs create mode 100644 source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs create mode 100644 source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs create mode 100644 source/Octopus.Client/Repositories/WorkerMachineRepository.cs create mode 100644 source/Octopus.Client/Repositories/WorkerPoolRepository.cs diff --git a/source/Octopus.Cli/Commands/HealthStatusProvider.cs b/source/Octopus.Cli/Commands/HealthStatusProvider.cs index 818bdc5c1..22822ea0a 100644 --- a/source/Octopus.Cli/Commands/HealthStatusProvider.cs +++ b/source/Octopus.Cli/Commands/HealthStatusProvider.cs @@ -11,7 +11,7 @@ namespace Octopus.Cli.Commands { /// - /// This class exists to provide backwards compataility to the pre 3.4.0 changes to machine state. + /// This class exists to provide backwards compataility to the pre 3.4.0 changes to machine state. /// As of 3.4.0 the enum has been marked as obselete to be replaced with /// public class HealthStatusProvider @@ -61,7 +61,7 @@ void ValidateOptions() $"The following health status value is unknown: {string.Join(", ", missingHealthStatuses)}. Please choose from {string.Join(", ", HealthStatusNames)}"); } - public string GetStatus(MachineResource machineResource) + public string GetStatus(MachineBasedResource machineResource) { if (IsHealthStatusPendingDeprication) { @@ -76,14 +76,14 @@ public string GetStatus(MachineResource machineResource) private bool IsHealthStatusPendingDeprication { get; } - public IEnumerable Filter(IEnumerable machines) + public IEnumerable Filter(IEnumerable machines) where TMachineResource : MachineBasedResource { machines = FilterByProvidedStatus(machines); machines = FilterByProvidedHealthStatus(machines); return machines; } - IEnumerable FilterByProvidedStatus(IEnumerable machines) + IEnumerable FilterByProvidedStatus(IEnumerable machines) where TMachineResource : MachineBasedResource { var statusFilter = new List(); if (statuses.Count > 0) @@ -102,7 +102,7 @@ IEnumerable FilterByProvidedStatus(IEnumerable : machines; } - IEnumerable FilterByProvidedHealthStatus(IEnumerable machines) + IEnumerable FilterByProvidedHealthStatus(IEnumerable machines) where TMachineResource : MachineBasedResource { var statusFilter = new List(); if (healthStatuses.Count > 0) diff --git a/source/Octopus.Client/Editors/Async/WorkerMachineEditor.cs b/source/Octopus.Client/Editors/Async/WorkerMachineEditor.cs new file mode 100644 index 000000000..0ec679f56 --- /dev/null +++ b/source/Octopus.Client/Editors/Async/WorkerMachineEditor.cs @@ -0,0 +1,60 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; +using Octopus.Client.Repositories.Async; + +namespace Octopus.Client.Editors.Async +{ + public class WorkerMachineEditor : IResourceEditor + { + private readonly IWorkerMachineRepository repository; + + public WorkerMachineEditor(IWorkerMachineRepository repository) + { + this.repository = repository; + } + + public WorkerMachineResource Instance { get; private set; } + + public async Task CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] workerpools) + { + var existing = await repository.FindByName(name).ConfigureAwait(false); + if (existing == null) + { + Instance = await repository.Create(new WorkerMachineResource + { + Name = name, + Endpoint = endpoint, + WorkerPoolIds = new ReferenceCollection(workerpools.Select(e => e.Id)) + }).ConfigureAwait(false); + } + else + { + existing.Name = name; + existing.Endpoint = endpoint; + existing.WorkerPoolIds.ReplaceAll(workerpools.Select(e => e.Id)); + + Instance = await repository.Modify(existing).ConfigureAwait(false); + } + + return this; + } + + public WorkerMachineEditor Customize(Action customize) + { + customize?.Invoke(Instance); + return this; + } + + public async Task Save() + { + Instance = await repository.Modify(Instance).ConfigureAwait(false); + return this; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Editors/Async/WorkerPoolEditor.cs b/source/Octopus.Client/Editors/Async/WorkerPoolEditor.cs new file mode 100644 index 000000000..6a827c0b7 --- /dev/null +++ b/source/Octopus.Client/Editors/Async/WorkerPoolEditor.cs @@ -0,0 +1,73 @@ +using System; +using System.Threading.Tasks; +using Octopus.Client.Model; +using Octopus.Client.Repositories.Async; + +namespace Octopus.Client.Editors.Async +{ + public class WorkerPoolEditor : IResourceEditor + { + private readonly IWorkerPoolRepository repository; + + public WorkerPoolEditor(IWorkerPoolRepository repository) + { + this.repository = repository; + } + + public WorkerPoolResource Instance { get; private set; } + + public async Task CreateOrModify(string name) + { + var existing = await repository.FindByName(name).ConfigureAwait(false); + if (existing == null) + { + Instance = await repository.Create(new WorkerPoolResource + { + Name = name, + }).ConfigureAwait(false); + } + else + { + existing.Name = name; + + Instance = await repository.Modify(existing).ConfigureAwait(false); + } + + return this; + } + + public async Task CreateOrModify(string name, string description) + { + var existing = await repository.FindByName(name).ConfigureAwait(false); + if (existing == null) + { + Instance = await repository.Create(new WorkerPoolResource + { + Name = name, + Description = description + }).ConfigureAwait(false); + } + else + { + existing.Name = name; + existing.Description = description; + + Instance = await repository.Modify(existing).ConfigureAwait(false); + } + + return this; + } + + public WorkerPoolEditor Customize(Action customize) + { + customize?.Invoke(Instance); + return this; + } + + public async Task Save() + { + Instance = await repository.Modify(Instance).ConfigureAwait(false); + return this; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Editors/WorkerMachineEditor.cs b/source/Octopus.Client/Editors/WorkerMachineEditor.cs new file mode 100644 index 000000000..61b90f2f1 --- /dev/null +++ b/source/Octopus.Client/Editors/WorkerMachineEditor.cs @@ -0,0 +1,59 @@ +using System; +using System.Linq; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; +using Octopus.Client.Repositories; + +namespace Octopus.Client.Editors +{ + public class WorkerMachineEditor : IResourceEditor + { + private readonly IWorkerMachineRepository repository; + + public WorkerMachineEditor(IWorkerMachineRepository repository) + { + this.repository = repository; + } + + public WorkerMachineResource Instance { get; private set; } + + public WorkerMachineEditor CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] pools) + { + var existing = repository.FindByName(name); + if (existing == null) + { + Instance = repository.Create(new WorkerMachineResource + { + Name = name, + Endpoint = endpoint, + WorkerPoolIds = new ReferenceCollection(pools.Select(e => e.Id)) + }); + } + else + { + existing.Name = name; + existing.Endpoint = endpoint; + existing.WorkerPoolIds.ReplaceAll(pools.Select(e => e.Id)); + + Instance = repository.Modify(existing); + } + + return this; + } + + public WorkerMachineEditor Customize(Action customize) + { + customize?.Invoke(Instance); + return this; + } + + public WorkerMachineEditor Save() + { + Instance = repository.Modify(Instance); + return this; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Editors/WorkerPoolEditor.cs b/source/Octopus.Client/Editors/WorkerPoolEditor.cs new file mode 100644 index 000000000..094b15725 --- /dev/null +++ b/source/Octopus.Client/Editors/WorkerPoolEditor.cs @@ -0,0 +1,72 @@ +using System; +using Octopus.Client.Model; +using Octopus.Client.Repositories; + +namespace Octopus.Client.Editors +{ + public class WorkerPoolEditor : IResourceEditor + { + private readonly IWorkerPoolRepository repository; + + public WorkerPoolEditor(IWorkerPoolRepository repository) + { + this.repository = repository; + } + + public WorkerPoolResource Instance { get; private set; } + + public WorkerPoolEditor CreateOrModify(string name) + { + var existing = repository.FindByName(name); + if (existing == null) + { + Instance = repository.Create(new WorkerPoolResource + { + Name = name, + }); + } + else + { + existing.Name = name; + + Instance = repository.Modify(existing); + } + + return this; + } + + public WorkerPoolEditor CreateOrModify(string name, string description) + { + var existing = repository.FindByName(name); + if (existing == null) + { + Instance = repository.Create(new WorkerPoolResource + { + Name = name, + Description = description + }); + } + else + { + existing.Name = name; + existing.Description = description; + + Instance = repository.Modify(existing); + } + + return this; + } + + public WorkerPoolEditor Customize(Action customize) + { + customize?.Invoke(Instance); + return this; + } + + public WorkerPoolEditor Save() + { + Instance = repository.Modify(Instance); + return this; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs b/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs new file mode 100644 index 000000000..699462408 --- /dev/null +++ b/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Octopus.Client.Editors.Async; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Client.Repositories.Async +{ + public interface IWorkerMachineRepository : IFindByName, IGet, ICreate, IModify, IDelete + { + Task Discover(string host, int port = 10933, DiscoverableEndpointType? discoverableEndpointType = null); + Task GetConnectionStatus(WorkerMachineResource machine); + Task> FindByThumbprint(string thumbprint); + + Task CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] pools); + + Task> List(int skip = 0, + int? take = null, + string ids = null, + string name = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + string workerpoolIds = null); + } + + class WorkerMachineRepository : BasicRepository, IWorkerMachineRepository + { + public WorkerMachineRepository(IOctopusAsyncClient client) : base(client, "Workers") + { + } + + public Task Discover(string host, int port = 10933, DiscoverableEndpointType? type = null) + { + return Client.Get(Client.RootDocument.Link("DiscoverMachine"), new { host, port, type }); + } + + public Task GetConnectionStatus(WorkerMachineResource workerMachine) + { + if (workerMachine == null) throw new ArgumentNullException("workerMachine"); + return Client.Get(workerMachine.Link("Connection")); + } + + public Task> FindByThumbprint(string thumbprint) + { + if (thumbprint == null) throw new ArgumentNullException("thumbprint"); + return Client.Get>(Client.RootDocument.Link("workers"), new { id = "all", thumbprint }); + } + + public Task CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] workerpools) + { + return new WorkerMachineEditor(this).CreateOrModify(name, endpoint, workerpools); + } + + public Task> List(int skip = 0, + int? take = null, + string ids = null, + string name = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + string workerpoolIds = null) + { + return Client.List(Client.RootDocument.Link("Workers"), new + { + skip, + take, + ids, + name, + partialName, + isDisabled, + healthStatuses, + commStyles, + workerpoolIds + }); + } + } +} diff --git a/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs b/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs new file mode 100644 index 000000000..50307b654 --- /dev/null +++ b/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Octopus.Client.Editors.Async; +using Octopus.Client.Model; + +namespace Octopus.Client.Repositories.Async +{ + public interface IWorkerPoolRepository : IFindByName, IGet, ICreate, IModify, IDelete, IGetAll + { + Task> GetMachines(WorkerPoolResource pool, + int? skip = 0, + int? take = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null); + Task Summary( + string ids = null, + string partialName = null, + string machinePartialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + bool? hideEmptyPools = false); + Task Sort(string[] workerpoolIdsInOrder); + Task CreateOrModify(string name); + Task CreateOrModify(string name, string description); + } + + class WorkerPoolRepository : BasicRepository, IWorkerPoolRepository + { + public WorkerPoolRepository(IOctopusAsyncClient client) + : base(client, "WorkerPools") + { + } + + public async Task> GetMachines(WorkerPoolResource environment, + int? skip = 0, + int? take = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null) + { + var resources = new List(); + + await Client.Paginate(environment.Link("WorkerMachines"), new { + skip, + take, + partialName, + isDisabled, + healthStatuses, + commStyles, + }, page => + { + resources.AddRange(page.Items); + return true; + }).ConfigureAwait(false); + + return resources; + } + + public Task Summary( + string ids = null, + string partialName = null, + string machinePartialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + bool? hideEmptyPools = false) + { + return Client.Get(Client.RootDocument.Link("WorkerPoolsSummary"), new + { + ids, + partialName, + machinePartialName, + isDisabled, + healthStatuses, + commStyles, + hideEmptyPools, + }); + } + + public Task Sort(string[] environmentIdsInOrder) + { + return Client.Put(Client.RootDocument.Link("WorkerPoolSortOrder"), environmentIdsInOrder); + } + + public Task CreateOrModify(string name) + { + return new WorkerPoolEditor(this).CreateOrModify(name); + } + + public Task CreateOrModify(string name, string description) + { + return new WorkerPoolEditor(this).CreateOrModify(name, description); + } + } +} diff --git a/source/Octopus.Client/Repositories/WorkerMachineRepository.cs b/source/Octopus.Client/Repositories/WorkerMachineRepository.cs new file mode 100644 index 000000000..a60bfea12 --- /dev/null +++ b/source/Octopus.Client/Repositories/WorkerMachineRepository.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using Octopus.Client.Editors; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Client.Repositories +{ + public interface IWorkerMachineRepository : IFindByName, IGet, ICreate, IModify, IDelete + { + WorkerMachineResource Discover(string host, int port = 10933, DiscoverableEndpointType? discoverableEndpointType = null); + MachineConnectionStatus GetConnectionStatus(WorkerMachineResource machine); + List FindByThumbprint(string thumbprint); + + WorkerMachineEditor CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] pools); + + ResourceCollection List(int skip = 0, + int? take = null, + string ids = null, + string name = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + string workerpoolIds = null); + } + + class WorkerMachineRepository : BasicRepository, IWorkerMachineRepository + { + public WorkerMachineRepository(IOctopusClient client) : base(client, "Workers") + { + } + + public WorkerMachineResource Discover(string host, int port = 10933, DiscoverableEndpointType? type = null) + { + return Client.Get(Client.RootDocument.Link("DiscoverMachine"), new { host, port, type }); + } + + public MachineConnectionStatus GetConnectionStatus(WorkerMachineResource machine) + { + if (machine == null) throw new ArgumentNullException("machine"); + return Client.Get(machine.Link("Connection")); + } + + public List FindByThumbprint(string thumbprint) + { + if (thumbprint == null) throw new ArgumentNullException("thumbprint"); + return Client.Get>(Client.RootDocument.Link("workers"), new { id = "all", thumbprint }); + } + + + public WorkerMachineEditor CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] pools) + { + return new WorkerMachineEditor(this).CreateOrModify(name, endpoint, pools); + } + + public ResourceCollection List(int skip = 0, + int? take = null, + string ids = null, + string name = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + string workerpoolIds = null) + { + return Client.List(Client.RootDocument.Link("workers"), new + { + skip, + take, + ids, + name, + partialName, + isDisabled, + healthStatuses, + commStyles, + workerpoolIds + }); + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Repositories/WorkerPoolRepository.cs b/source/Octopus.Client/Repositories/WorkerPoolRepository.cs new file mode 100644 index 000000000..c8e4cecff --- /dev/null +++ b/source/Octopus.Client/Repositories/WorkerPoolRepository.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using Octopus.Client.Editors; +using Octopus.Client.Model; + +namespace Octopus.Client.Repositories +{ + public interface IWorkerPoolRepository : IFindByName, IGet, ICreate, IModify, IDelete, IGetAll + { + List GetMachines(WorkerPoolResource workerpool, + int? skip = 0, + int? take = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null); + WorkerPoolsSummaryResource Summary( + string ids = null, + string partialName = null, + string machinePartialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + bool? hideEmptypools = false); + void Sort(string[] workerpoolIdsInOrder); + WorkerPoolEditor CreateOrModify(string name); + WorkerPoolEditor CreateOrModify(string name, string description); + } + + class WorkerPoolRepository : BasicRepository, IWorkerPoolRepository + { + public WorkerPoolRepository(IOctopusClient client) + : base(client, "WorkerPools") + { + } + + public List GetMachines(WorkerPoolResource pool, + int? skip = 0, + int? take = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null) + { + var resources = new List(); + + Client.Paginate(pool.Link("WorkerMachines"), new + { + skip, + take, + partialName, + isDisabled, + healthStatuses, + commStyles + }, page => + { + resources.AddRange(page.Items); + return true; + }); + + return resources; + } + + public WorkerPoolsSummaryResource Summary( + string ids = null, + string partialName = null, + string machinePartialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + bool? hideEmptyPools = false) + { + return Client.Get(Client.RootDocument.Link("WorkerPoolsSummary"), new + { + ids, + partialName, + machinePartialName, + isDisabled, + healthStatuses, + commStyles, + hideEmptyPools, + }); + } + + public void Sort(string[] workerpoolIdsInOrder) + { + Client.Put(Client.RootDocument.Link("WorkerPoolsSortOrder"), workerpoolIdsInOrder); + } + + public WorkerPoolEditor CreateOrModify(string name) + { + return new WorkerPoolEditor(this).CreateOrModify(name); + } + + public WorkerPoolEditor CreateOrModify(string name, string description) + { + return new WorkerPoolEditor(this).CreateOrModify(name, description); + } + } +} \ No newline at end of file From 47f9afd68574091c66325bfe9d62dca33b6f674a Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 10:20:00 +1000 Subject: [PATCH 05/37] Add worker repositories to Octopus repositories. --- source/Octopus.Client/IOctopusAsyncRepository.cs | 2 ++ source/Octopus.Client/IOctopusRepository.cs | 2 ++ source/Octopus.Client/OctopusAsyncRepository.cs | 4 ++++ source/Octopus.Client/OctopusRepository.cs | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/source/Octopus.Client/IOctopusAsyncRepository.cs b/source/Octopus.Client/IOctopusAsyncRepository.cs index cc45ea93d..1826d519b 100644 --- a/source/Octopus.Client/IOctopusAsyncRepository.cs +++ b/source/Octopus.Client/IOctopusAsyncRepository.cs @@ -59,5 +59,7 @@ public interface IOctopusAsyncRepository IUserRepository Users { get; } IUserRolesRepository UserRoles { get; } IVariableSetRepository VariableSets { get; } + IWorkerPoolRepository WorkerPools { get; } + IWorkerMachineRepository WorkerMachines { get; } } } \ No newline at end of file diff --git a/source/Octopus.Client/IOctopusRepository.cs b/source/Octopus.Client/IOctopusRepository.cs index e7fd7883e..c7dfd881d 100644 --- a/source/Octopus.Client/IOctopusRepository.cs +++ b/source/Octopus.Client/IOctopusRepository.cs @@ -60,6 +60,8 @@ public interface IOctopusRepository IUserRepository Users { get; } IUserRolesRepository UserRoles { get; } IVariableSetRepository VariableSets { get; } + IWorkerPoolRepository WorkerPools { get; } + IWorkerMachineRepository WorkerMachines { get; } } } #endif \ No newline at end of file diff --git a/source/Octopus.Client/OctopusAsyncRepository.cs b/source/Octopus.Client/OctopusAsyncRepository.cs index c511441bc..03c4a727f 100644 --- a/source/Octopus.Client/OctopusAsyncRepository.cs +++ b/source/Octopus.Client/OctopusAsyncRepository.cs @@ -74,6 +74,8 @@ public OctopusAsyncRepository(IOctopusAsyncClient client) UserRoles = new UserRolesRepository(client); Users = new UserRepository(client); VariableSets = new VariableSetRepository(client); + WorkerMachines = new WorkerMachineRepository(client); + WorkerPools = new WorkerPoolRepository(client); } public IOctopusAsyncClient Client { get; } @@ -122,5 +124,7 @@ public OctopusAsyncRepository(IOctopusAsyncClient client) public IUserRepository Users { get; } public IUserRolesRepository UserRoles { get; } public IVariableSetRepository VariableSets { get; } + public IWorkerPoolRepository WorkerPools { get; } + public IWorkerMachineRepository WorkerMachines { get; } } } \ No newline at end of file diff --git a/source/Octopus.Client/OctopusRepository.cs b/source/Octopus.Client/OctopusRepository.cs index f1afcdc27..b6ac8f482 100644 --- a/source/Octopus.Client/OctopusRepository.cs +++ b/source/Octopus.Client/OctopusRepository.cs @@ -68,6 +68,8 @@ public OctopusRepository(IOctopusClient client) UserRoles = new UserRolesRepository(client); Users = new UserRepository(client); VariableSets = new VariableSetRepository(client); + WorkerMachines = new WorkerMachineRepository(client); + WorkerPools = new WorkerPoolRepository(client); } public IOctopusClient Client { get; } @@ -116,6 +118,8 @@ public OctopusRepository(IOctopusClient client) public IUserRepository Users { get; } public IUserRolesRepository UserRoles { get; } public IVariableSetRepository VariableSets { get; } + public IWorkerPoolRepository WorkerPools { get; } + public IWorkerMachineRepository WorkerMachines { get; } } } #endif \ No newline at end of file From d5201fa9c890e2f80d2776d8018a7f382c6c734f Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 10:34:10 +1000 Subject: [PATCH 06/37] Update PublicSurfaceArea --- ...AreaShouldNotRegress..NETCore.approved.txt | 196 +++++++++++--- ...houldNotRegress..NETFramework.approved.txt | 250 +++++++++++++++--- 2 files changed, 364 insertions(+), 82 deletions(-) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 960175c09..1f1725df9 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -88,6 +88,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } + Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } + Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } } interface IOctopusClientFactory { @@ -173,6 +175,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } + Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } + Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } } class OctopusClientFactory Octopus.Client.IOctopusClientFactory @@ -468,6 +472,27 @@ Octopus.Client.Editors.Async Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary) Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary, String, String) } + class WorkerMachineEditor + Octopus.Client.Editors.Async.IResourceEditor + Octopus.Client.Editors.Async.IResourceBuilder + { + .ctor(Octopus.Client.Repositories.Async.IWorkerMachineRepository) + Octopus.Client.Model.WorkerMachineResource Instance { get; } + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Editors.Async.WorkerMachineEditor Customize(Action) + Task Save() + } + class WorkerPoolEditor + Octopus.Client.Editors.Async.IResourceEditor + Octopus.Client.Editors.Async.IResourceBuilder + { + .ctor(Octopus.Client.Repositories.Async.IWorkerPoolRepository) + Octopus.Client.Model.WorkerPoolResource Instance { get; } + Task CreateOrModify(String) + Task CreateOrModify(String, String) + Octopus.Client.Editors.Async.WorkerPoolEditor Customize(Action) + Task Save() + } } Octopus.Client.Exceptions { @@ -1535,6 +1560,31 @@ Octopus.Client.Model StartAfterPrevious = 0 StartWithPrevious = 1 } + class DeploymentTargetResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.MachineBasedResource + { + .ctor() + Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } + Octopus.Client.Model.ReferenceCollection Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } + Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } + Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) + Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() + Octopus.Client.Model.DeploymentTargetResource ClearRoles() + Octopus.Client.Model.DeploymentTargetResource ClearTenants() + Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() + Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) + Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) + Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) + Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) + } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource @@ -1600,30 +1650,20 @@ Octopus.Client.Model Boolean UseGuidedFailure { get; set; } } class EnvironmentsSummaryResource + Octopus.Client.Model.SummaryResourcesCombined { .ctor() List EnvironmentSummaries { get; set; } - Dictionary MachineEndpointSummaries { get; set; } - Dictionary MachineHealthStatusSummaries { get; set; } - String[] MachineIdsForCalamariUpgrade { get; set; } Dictionary MachineTenantSummaries { get; set; } Dictionary MachineTenantTagSummaries { get; set; } - Boolean TentacleUpgradesRequired { get; set; } - Int32 TotalDisabledMachines { get; set; } - Int32 TotalMachines { get; set; } } class EnvironmentSummaryResource + Octopus.Client.Model.SummaryResource { .ctor() Octopus.Client.Model.EnvironmentResource Environment { get; set; } - Dictionary MachineEndpointSummaries { get; set; } - Dictionary MachineHealthStatusSummaries { get; set; } - String[] MachineIdsForCalamariUpgrade { get; set; } Dictionary MachineTenantSummaries { get; set; } Dictionary MachineTenantTagSummaries { get; set; } - Boolean TentacleUpgradesRequired { get; set; } - Int32 TotalDisabledMachines { get; set; } - Int32 TotalMachines { get; set; } } class EventNotificationSubscription { @@ -1907,6 +1947,24 @@ Octopus.Client.Model .ctor() Boolean UsingSecureConnection { get; set; } } + abstract class MachineBasedResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.Resource + { + Octopus.Client.Model.Endpoints.EndpointResource Endpoint { get; set; } + Boolean HasLatestCalamari { get; set; } + Octopus.Client.Model.MachineModelHealthStatus HealthStatus { get; set; } + Boolean IsDisabled { get; set; } + Boolean IsInProcess { get; set; } + String MachinePolicyId { get; set; } + String Name { get; set; } + Octopus.Client.Model.MachineModelStatus Status { get; set; } + String StatusSummary { get; set; } + String Thumbprint { get; set; } + String Uri { get; set; } + } class MachineCleanupPolicy { .ctor() @@ -1993,37 +2051,9 @@ Octopus.Client.Model Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.Resource + Octopus.Client.Model.DeploymentTargetResource { .ctor() - Octopus.Client.Model.Endpoints.EndpointResource Endpoint { get; set; } - Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } - Boolean HasLatestCalamari { get; set; } - Octopus.Client.Model.MachineModelHealthStatus HealthStatus { get; set; } - Boolean IsDisabled { get; set; } - Boolean IsInProcess { get; set; } - String MachinePolicyId { get; set; } - String Name { get; set; } - Octopus.Client.Model.ReferenceCollection Roles { get; set; } - Octopus.Client.Model.MachineModelStatus Status { get; set; } - String StatusSummary { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } - Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } - String Thumbprint { get; set; } - String Uri { get; set; } - Octopus.Client.Model.MachineResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) - Octopus.Client.Model.MachineResource AddOrUpdateRoles(String[]) - Octopus.Client.Model.MachineResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) - Octopus.Client.Model.MachineResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) - Octopus.Client.Model.MachineResource ClearEnvironments() - Octopus.Client.Model.MachineResource ClearRoles() - Octopus.Client.Model.MachineResource ClearTenants() - Octopus.Client.Model.MachineResource ClearTenantTags() - Octopus.Client.Model.MachineResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) - Octopus.Client.Model.MachineResource RemoveRole(String) - Octopus.Client.Model.MachineResource RemoveTenant(Octopus.Client.Model.TenantResource) - Octopus.Client.Model.MachineResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class MachineScriptPolicy { @@ -2907,6 +2937,26 @@ Octopus.Client.Model { Event = 0 } + class SummaryResource + { + .ctor() + Dictionary MachineEndpointSummaries { get; set; } + Dictionary MachineHealthStatusSummaries { get; set; } + String[] MachineIdsForCalamariUpgrade { get; set; } + Boolean TentacleUpgradesRequired { get; set; } + Int32 TotalDisabledMachines { get; set; } + Int32 TotalMachines { get; set; } + } + class SummaryResourcesCombined + { + .ctor() + Dictionary MachineEndpointSummaries { get; set; } + Dictionary MachineHealthStatusSummaries { get; set; } + String[] MachineIdsForCalamariUpgrade { get; set; } + Boolean TentacleUpgradesRequired { get; set; } + Int32 TotalDisabledMachines { get; set; } + Int32 TotalMachines { get; set; } + } class SupportsRestrictionAttribute Attribute { @@ -3321,6 +3371,41 @@ Octopus.Client.Model String ReferrerPolicy { get; set; } Octopus.Client.Model.XOptionsResource XOptions { get; set; } } + class WorkerMachineResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.MachineBasedResource + { + .ctor() + Octopus.Client.Model.ReferenceCollection WorkerPoolIds { get; set; } + Octopus.Client.Model.WorkerMachineResource AddOrUpdateWorkerPools(Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Model.WorkerMachineResource ClearWorkerPools() + Octopus.Client.Model.WorkerMachineResource RemoveWorkerPool(Octopus.Client.Model.WorkerPoolResource) + } + class WorkerPoolResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.Resource + { + .ctor() + String Description { get; set; } + String Name { get; set; } + Int32 SortOrder { get; set; } + } + class WorkerPoolsSummaryResource + Octopus.Client.Model.SummaryResourcesCombined + { + .ctor() + List WorkerPoolSummaries { get; set; } + } + class WorkerPoolSummaryResource + Octopus.Client.Model.SummaryResource + { + .ctor() + Octopus.Client.Model.WorkerPoolResource WorkerPool { get; set; } + } class XOptionsResource { static System.String XFrameAllowFromDescription @@ -4350,6 +4435,35 @@ Octopus.Client.Repositories.Async { Task GetVariableNames(String, String[]) } + interface IWorkerMachineRepository + Octopus.Client.Repositories.Async.IFindByName + Octopus.Client.Repositories.Async.IPaginate + Octopus.Client.Repositories.Async.IGet + Octopus.Client.Repositories.Async.ICreate + Octopus.Client.Repositories.Async.IModify + Octopus.Client.Repositories.Async.IDelete + { + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Task Discover(String, Int32, Nullable) + Task> FindByThumbprint(String) + Task GetConnectionStatus(Octopus.Client.Model.WorkerMachineResource) + Task> List(Int32, Nullable, String, String, String, Nullable, String, String, String) + } + interface IWorkerPoolRepository + Octopus.Client.Repositories.Async.IFindByName + Octopus.Client.Repositories.Async.IPaginate + Octopus.Client.Repositories.Async.IGet + Octopus.Client.Repositories.Async.ICreate + Octopus.Client.Repositories.Async.IModify + Octopus.Client.Repositories.Async.IDelete + Octopus.Client.Repositories.Async.IGetAll + { + Task CreateOrModify(String) + Task CreateOrModify(String, String) + Task> GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) + Task Sort(String[]) + Task Summary(String, String, String, Nullable, String, String, Nullable) + } } Octopus.Client.Serialization { diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index b6124d3a2..61f2aa84e 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -95,6 +95,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } + Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } + Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } } interface IOctopusClient IDisposable @@ -173,6 +175,8 @@ Octopus.Client Octopus.Client.Repositories.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.IUserRepository Users { get; } Octopus.Client.Repositories.IVariableSetRepository VariableSets { get; } + Octopus.Client.Repositories.IWorkerMachineRepository WorkerMachines { get; } + Octopus.Client.Repositories.IWorkerPoolRepository WorkerPools { get; } } class OctopusAsyncClient Octopus.Client.IOctopusAsyncClient @@ -254,6 +258,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } + Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } + Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } } class OctopusClient Octopus.Client.IHttpOctopusClient @@ -352,6 +358,8 @@ Octopus.Client Octopus.Client.Repositories.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.IUserRepository Users { get; } Octopus.Client.Repositories.IVariableSetRepository VariableSets { get; } + Octopus.Client.Repositories.IWorkerMachineRepository WorkerMachines { get; } + Octopus.Client.Repositories.IWorkerPoolRepository WorkerPools { get; } } abstract class OctopusRepositoryExtensions { @@ -631,6 +639,27 @@ Octopus.Client.Editors Octopus.Client.Editors.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary) Octopus.Client.Editors.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary, String, String) } + class WorkerMachineEditor + Octopus.Client.Editors.IResourceEditor + Octopus.Client.Editors.IResourceBuilder + { + .ctor(Octopus.Client.Repositories.IWorkerMachineRepository) + Octopus.Client.Model.WorkerMachineResource Instance { get; } + Octopus.Client.Editors.WorkerMachineEditor CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Editors.WorkerMachineEditor Customize(Action) + Octopus.Client.Editors.WorkerMachineEditor Save() + } + class WorkerPoolEditor + Octopus.Client.Editors.IResourceEditor + Octopus.Client.Editors.IResourceBuilder + { + .ctor(Octopus.Client.Repositories.IWorkerPoolRepository) + Octopus.Client.Model.WorkerPoolResource Instance { get; } + Octopus.Client.Editors.WorkerPoolEditor CreateOrModify(String) + Octopus.Client.Editors.WorkerPoolEditor CreateOrModify(String, String) + Octopus.Client.Editors.WorkerPoolEditor Customize(Action) + Octopus.Client.Editors.WorkerPoolEditor Save() + } } Octopus.Client.Editors.Async { @@ -859,6 +888,27 @@ Octopus.Client.Editors.Async Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary) Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary, String, String) } + class WorkerMachineEditor + Octopus.Client.Editors.Async.IResourceEditor + Octopus.Client.Editors.Async.IResourceBuilder + { + .ctor(Octopus.Client.Repositories.Async.IWorkerMachineRepository) + Octopus.Client.Model.WorkerMachineResource Instance { get; } + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Editors.Async.WorkerMachineEditor Customize(Action) + Task Save() + } + class WorkerPoolEditor + Octopus.Client.Editors.Async.IResourceEditor + Octopus.Client.Editors.Async.IResourceBuilder + { + .ctor(Octopus.Client.Repositories.Async.IWorkerPoolRepository) + Octopus.Client.Model.WorkerPoolResource Instance { get; } + Task CreateOrModify(String) + Task CreateOrModify(String, String) + Octopus.Client.Editors.Async.WorkerPoolEditor Customize(Action) + Task Save() + } } Octopus.Client.Exceptions { @@ -1939,6 +1989,31 @@ Octopus.Client.Model StartAfterPrevious = 0 StartWithPrevious = 1 } + class DeploymentTargetResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.MachineBasedResource + { + .ctor() + Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } + Octopus.Client.Model.ReferenceCollection Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } + Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } + Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) + Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() + Octopus.Client.Model.DeploymentTargetResource ClearRoles() + Octopus.Client.Model.DeploymentTargetResource ClearTenants() + Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() + Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) + Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) + Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) + Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) + } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource @@ -2004,30 +2079,20 @@ Octopus.Client.Model Boolean UseGuidedFailure { get; set; } } class EnvironmentsSummaryResource + Octopus.Client.Model.SummaryResourcesCombined { .ctor() List EnvironmentSummaries { get; set; } - Dictionary MachineEndpointSummaries { get; set; } - Dictionary MachineHealthStatusSummaries { get; set; } - String[] MachineIdsForCalamariUpgrade { get; set; } Dictionary MachineTenantSummaries { get; set; } Dictionary MachineTenantTagSummaries { get; set; } - Boolean TentacleUpgradesRequired { get; set; } - Int32 TotalDisabledMachines { get; set; } - Int32 TotalMachines { get; set; } } class EnvironmentSummaryResource + Octopus.Client.Model.SummaryResource { .ctor() Octopus.Client.Model.EnvironmentResource Environment { get; set; } - Dictionary MachineEndpointSummaries { get; set; } - Dictionary MachineHealthStatusSummaries { get; set; } - String[] MachineIdsForCalamariUpgrade { get; set; } Dictionary MachineTenantSummaries { get; set; } Dictionary MachineTenantTagSummaries { get; set; } - Boolean TentacleUpgradesRequired { get; set; } - Int32 TotalDisabledMachines { get; set; } - Int32 TotalMachines { get; set; } } class EventNotificationSubscription { @@ -2311,6 +2376,24 @@ Octopus.Client.Model .ctor() Boolean UsingSecureConnection { get; set; } } + abstract class MachineBasedResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.Resource + { + Octopus.Client.Model.Endpoints.EndpointResource Endpoint { get; set; } + Boolean HasLatestCalamari { get; set; } + Octopus.Client.Model.MachineModelHealthStatus HealthStatus { get; set; } + Boolean IsDisabled { get; set; } + Boolean IsInProcess { get; set; } + String MachinePolicyId { get; set; } + String Name { get; set; } + Octopus.Client.Model.MachineModelStatus Status { get; set; } + String StatusSummary { get; set; } + String Thumbprint { get; set; } + String Uri { get; set; } + } class MachineCleanupPolicy { .ctor() @@ -2397,37 +2480,9 @@ Octopus.Client.Model Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.Resource + Octopus.Client.Model.DeploymentTargetResource { .ctor() - Octopus.Client.Model.Endpoints.EndpointResource Endpoint { get; set; } - Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } - Boolean HasLatestCalamari { get; set; } - Octopus.Client.Model.MachineModelHealthStatus HealthStatus { get; set; } - Boolean IsDisabled { get; set; } - Boolean IsInProcess { get; set; } - String MachinePolicyId { get; set; } - String Name { get; set; } - Octopus.Client.Model.ReferenceCollection Roles { get; set; } - Octopus.Client.Model.MachineModelStatus Status { get; set; } - String StatusSummary { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } - Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } - String Thumbprint { get; set; } - String Uri { get; set; } - Octopus.Client.Model.MachineResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) - Octopus.Client.Model.MachineResource AddOrUpdateRoles(String[]) - Octopus.Client.Model.MachineResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) - Octopus.Client.Model.MachineResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) - Octopus.Client.Model.MachineResource ClearEnvironments() - Octopus.Client.Model.MachineResource ClearRoles() - Octopus.Client.Model.MachineResource ClearTenants() - Octopus.Client.Model.MachineResource ClearTenantTags() - Octopus.Client.Model.MachineResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) - Octopus.Client.Model.MachineResource RemoveRole(String) - Octopus.Client.Model.MachineResource RemoveTenant(Octopus.Client.Model.TenantResource) - Octopus.Client.Model.MachineResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class MachineScriptPolicy { @@ -3316,6 +3371,26 @@ Octopus.Client.Model { Event = 0 } + class SummaryResource + { + .ctor() + Dictionary MachineEndpointSummaries { get; set; } + Dictionary MachineHealthStatusSummaries { get; set; } + String[] MachineIdsForCalamariUpgrade { get; set; } + Boolean TentacleUpgradesRequired { get; set; } + Int32 TotalDisabledMachines { get; set; } + Int32 TotalMachines { get; set; } + } + class SummaryResourcesCombined + { + .ctor() + Dictionary MachineEndpointSummaries { get; set; } + Dictionary MachineHealthStatusSummaries { get; set; } + String[] MachineIdsForCalamariUpgrade { get; set; } + Boolean TentacleUpgradesRequired { get; set; } + Int32 TotalDisabledMachines { get; set; } + Int32 TotalMachines { get; set; } + } class SupportsRestrictionAttribute _Attribute Attribute @@ -3733,6 +3808,41 @@ Octopus.Client.Model String ReferrerPolicy { get; set; } Octopus.Client.Model.XOptionsResource XOptions { get; set; } } + class WorkerMachineResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.MachineBasedResource + { + .ctor() + Octopus.Client.Model.ReferenceCollection WorkerPoolIds { get; set; } + Octopus.Client.Model.WorkerMachineResource AddOrUpdateWorkerPools(Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Model.WorkerMachineResource ClearWorkerPools() + Octopus.Client.Model.WorkerMachineResource RemoveWorkerPool(Octopus.Client.Model.WorkerPoolResource) + } + class WorkerPoolResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.Resource + { + .ctor() + String Description { get; set; } + String Name { get; set; } + Int32 SortOrder { get; set; } + } + class WorkerPoolsSummaryResource + Octopus.Client.Model.SummaryResourcesCombined + { + .ctor() + List WorkerPoolSummaries { get; set; } + } + class WorkerPoolSummaryResource + Octopus.Client.Model.SummaryResource + { + .ctor() + Octopus.Client.Model.WorkerPoolResource WorkerPool { get; set; } + } class XOptionsResource { static System.String XFrameAllowFromDescription @@ -4768,6 +4878,35 @@ Octopus.Client.Repositories { String[] GetVariableNames(String, String[]) } + interface IWorkerMachineRepository + Octopus.Client.Repositories.IFindByName + Octopus.Client.Repositories.IPaginate + Octopus.Client.Repositories.IGet + Octopus.Client.Repositories.ICreate + Octopus.Client.Repositories.IModify + Octopus.Client.Repositories.IDelete + { + Octopus.Client.Editors.WorkerMachineEditor CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Model.WorkerMachineResource Discover(String, Int32, Nullable) + List FindByThumbprint(String) + Octopus.Client.Model.MachineConnectionStatus GetConnectionStatus(Octopus.Client.Model.WorkerMachineResource) + Octopus.Client.Model.ResourceCollection List(Int32, Nullable, String, String, String, Nullable, String, String, String) + } + interface IWorkerPoolRepository + Octopus.Client.Repositories.IFindByName + Octopus.Client.Repositories.IPaginate + Octopus.Client.Repositories.IGet + Octopus.Client.Repositories.ICreate + Octopus.Client.Repositories.IModify + Octopus.Client.Repositories.IDelete + Octopus.Client.Repositories.IGetAll + { + Octopus.Client.Editors.WorkerPoolEditor CreateOrModify(String) + Octopus.Client.Editors.WorkerPoolEditor CreateOrModify(String, String) + List GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) + void Sort(String[]) + Octopus.Client.Model.WorkerPoolsSummaryResource Summary(String, String, String, Nullable, String, String, Nullable) + } } Octopus.Client.Repositories.Async { @@ -5234,6 +5373,35 @@ Octopus.Client.Repositories.Async { Task GetVariableNames(String, String[]) } + interface IWorkerMachineRepository + Octopus.Client.Repositories.Async.IFindByName + Octopus.Client.Repositories.Async.IPaginate + Octopus.Client.Repositories.Async.IGet + Octopus.Client.Repositories.Async.ICreate + Octopus.Client.Repositories.Async.IModify + Octopus.Client.Repositories.Async.IDelete + { + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Task Discover(String, Int32, Nullable) + Task> FindByThumbprint(String) + Task GetConnectionStatus(Octopus.Client.Model.WorkerMachineResource) + Task> List(Int32, Nullable, String, String, String, Nullable, String, String, String) + } + interface IWorkerPoolRepository + Octopus.Client.Repositories.Async.IFindByName + Octopus.Client.Repositories.Async.IPaginate + Octopus.Client.Repositories.Async.IGet + Octopus.Client.Repositories.Async.ICreate + Octopus.Client.Repositories.Async.IModify + Octopus.Client.Repositories.Async.IDelete + Octopus.Client.Repositories.Async.IGetAll + { + Task CreateOrModify(String) + Task CreateOrModify(String, String) + Task> GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) + Task Sort(String[]) + Task Summary(String, String, String, Nullable, String, String, Nullable) + } } Octopus.Client.Serialization { From 2f04f5b007d5168bb83df817b93ef321032be007 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 11:58:29 +1000 Subject: [PATCH 07/37] Add workers to Octo.exe --- .../Commands/CleanWorkerPoolCommandFixture.cs | 170 +++++++++++ .../CreateWorkerPoolCommandFixture.cs | 58 ++++ .../ListWorkerMachinesCommandFixture.cs | 274 ++++++++++++++++++ .../Commands/ListWorkerPoolsCommandFixture.cs | 59 ++++ .../Machine/ListWorkerMachinesCommand.cs | 131 +++++++++ .../WorkerPool/CleanWorkerPoolCommand.cs | 176 +++++++++++ .../WorkerPool/CreateWorkerPoolCommand.cs | 60 ++++ .../WorkerPool/ListWorkerPoolsCommand.cs | 47 +++ 8 files changed, 975 insertions(+) create mode 100644 source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs create mode 100644 source/Octo.Tests/Commands/CreateWorkerPoolCommandFixture.cs create mode 100644 source/Octo.Tests/Commands/ListWorkerMachinesCommandFixture.cs create mode 100644 source/Octo.Tests/Commands/ListWorkerPoolsCommandFixture.cs create mode 100644 source/Octopus.Cli/Commands/Machine/ListWorkerMachinesCommand.cs create mode 100644 source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs create mode 100644 source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs create mode 100644 source/Octopus.Cli/Commands/WorkerPool/ListWorkerPoolsCommand.cs diff --git a/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs new file mode 100644 index 000000000..1a4ff5a60 --- /dev/null +++ b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using FluentAssertions; +using Newtonsoft.Json; +using NSubstitute; +using NUnit.Framework; +using Octopus.Cli.Commands.WorkerPool; +using Octopus.Cli.Infrastructure; +using Octopus.Client.Model; + +namespace Octopus.Cli.Tests.Commands +{ + [TestFixture] + public class CleanWorkerPoolCommandFixture : ApiCommandFixtureBase + { + [SetUp] + public void SetUp() + { + cleanPoolCommand = new CleanWorkerPoolCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); + } + + CleanWorkerPoolCommand cleanPoolCommand; + + [Test] + public void ShouldCleanPool() + { + CommandLineArgs.Add("-workerpool=SomePool"); + CommandLineArgs.Add("-status=Offline"); + + Repository.WorkerPools.FindByName("SomePool").Returns( + new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} + ); + + var workerList = MakeWorkerMachineList(2, + new List + { + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-001") + }); + + Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + + cleanPoolCommand.Execute(CommandLineArgs.ToArray()).GetAwaiter().GetResult(); + + LogLines.Should().Contain(string.Format("Found {0} machines in {1} with the status {2}", workerList.Count, "SomePool", MachineModelStatus.Offline.ToString())); + + LogLines.Should().Contain(string.Format("Deleting {0} {1} (ID: {2})", workerList[0].Name, workerList[0].Status, workerList[0].Id)); + Repository.WorkerMachines.Received().Delete(workerList[0]); + + LogLines.Should().Contain(string.Format("Deleting {0} {1} (ID: {2})", workerList[1].Name, workerList[1].Status, workerList[1].Id)); + Repository.WorkerMachines.Received().Delete(workerList[1]); + } + + [Test] + public void ShouldRemoveMachinesBelongingToMultiplePoolsInsteadOfDeleting() + { + CommandLineArgs.Add("-workerpool=SomePool"); + CommandLineArgs.Add("-status=Offline"); + + Repository.WorkerPools.FindByName("SomePool").Returns( + new WorkerPoolResource { Name = "SomePool", Id = "WorkerPools-001"} + ); + + var workerList = MakeWorkerMachineList(2, + new List + { + new ReferenceCollection(new List { "WorkerPools-001", "WorkerPools-002" }), + new ReferenceCollection("WorkerPools-001") + }); + + Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + + cleanPoolCommand.Execute(CommandLineArgs.ToArray()).GetAwaiter().GetResult(); + + LogLines.Should().Contain(string.Format("Found {0} machines in {1} with the status {2}", workerList.Count, "SomePool", MachineModelStatus.Offline.ToString())); + LogLines.Should().Contain("Note: Some of these machines belong to multiple pools. Instead of being deleted, these machines will be removed from the SomePool pool."); + + LogLines.Should().Contain($"Removing {workerList[0].Name} {workerList[0].Status} (ID: {workerList[0].Id}) from SomePool"); + Assert.That(workerList[0].WorkerPoolIds.Count, Is.EqualTo(1), "The machine should have been removed from the SomePool pool."); + Repository.WorkerMachines.Received().Modify(workerList[0]); + + LogLines.Should().Contain(string.Format("Deleting {0} {1} (ID: {2})", workerList[1].Name, workerList[1].Status, workerList[1].Id)); + Repository.WorkerMachines.Received().Delete(workerList[1]); + } + + [Test] + public void ShouldNotCleanPoolWithMissingPoolArgs() + { + Func exec = () => cleanPoolCommand.Execute(CommandLineArgs.ToArray()); + exec.ShouldThrow() + .WithMessage("Please specify a worker pool name using the parameter: --workerpool=XYZ"); + } + + [Test] + public void ShouldNotCleanPoolWithMissingStatusArgs() + { + CommandLineArgs.Add("-workerpool=SomePool"); + Func exec = () => cleanPoolCommand.Execute(CommandLineArgs.ToArray()); + exec.ShouldThrow() + .WithMessage("Please specify a status using the parameter: --health-status"); + } + + [Test] + public void ShouldNotCleanIfPoolNotFound() + { + CommandLineArgs.Add("-workerpool=SomePool"); + CommandLineArgs.Add("-status=Offline"); + + Func exec = () => cleanPoolCommand.Execute(CommandLineArgs.ToArray()); + exec.ShouldThrow() + .WithMessage("Could not find the specified worker pool; either it does not exist or you lack permissions to view it."); + } + + + [Test] + public async Task JsonOutput_ShouldBeWellFormed() + { + Repository.WorkerPools.FindByName("SomePool").Returns( + new WorkerPoolResource { Name = "SomePool", Id = "WorkerPools-001" }); + + CommandLineArgs.Add("--outputFormat=json"); + CommandLineArgs.Add($"--workerpool=SomePool"); + CommandLineArgs.Add("-status=Offline"); + + var workerList = MakeWorkerMachineList(2, + new List + { + new ReferenceCollection(new List { "WorkerPools-001", "WorkerPools-002" }), + new ReferenceCollection("WorkerPools-001") + }); + + Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + + await cleanPoolCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + string logoutput = LogOutput.ToString(); + Console.WriteLine(logoutput); + JsonConvert.DeserializeObject(logoutput); + Regex.Matches(logoutput, CleanWorkerPoolCommand.MachineAction.Deleted.ToString()).Count.Should() + .Be(1, "should only have one deleted machine"); + Regex.Matches(logoutput, CleanWorkerPoolCommand.MachineAction.RemovedFromPool.ToString()).Count.Should() + .Be(1, "should only have one machine removed from the environment"); + logoutput.Should().Contain(workerList[0].Name); + logoutput.Should().Contain(workerList[0].Id); + logoutput.Should().Contain(workerList[1].Name); + logoutput.Should().Contain(workerList[1].Id); + } + + + private List MakeWorkerMachineList(int numWorkers, List pools) + { + var result = new List(); + for (int i = 0; i < numWorkers; i++) + { + result.Add( + new WorkerMachineResource + { + Name = Guid.NewGuid().ToString(), + Id = "Machines-00" + i, + Status = MachineModelStatus.Offline, + WorkerPoolIds = pools[i] + }); + } + + return result; + } + } +} \ No newline at end of file diff --git a/source/Octo.Tests/Commands/CreateWorkerPoolCommandFixture.cs b/source/Octo.Tests/Commands/CreateWorkerPoolCommandFixture.cs new file mode 100644 index 000000000..952f97d79 --- /dev/null +++ b/source/Octo.Tests/Commands/CreateWorkerPoolCommandFixture.cs @@ -0,0 +1,58 @@ +using System; +using System.Threading.Tasks; +using FluentAssertions; +using Newtonsoft.Json; +using NSubstitute; +using NUnit.Framework; +using Octopus.Cli.Commands.WorkerPool; +using Octopus.Cli.Tests.Commands; +using Octopus.Client.Model; + +namespace Octo.Tests.Commands +{ + public class CreateWorkerPoolCommandFixture : ApiCommandFixtureBase + { + private CreateWorkerPoolCommand createWorkerPoolCommand; + + [SetUp] + public void Setup() + { + createWorkerPoolCommand = new CreateWorkerPoolCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); + } + + [Test] + public async Task DefaultOutput_CreateNewWorkerPool() + { + var newPool = Guid.NewGuid().ToString(); + CommandLineArgs.Add($"--name={newPool}"); + + Repository.WorkerPools.FindByName(Arg.Any()).Returns((WorkerPoolResource)null); + Repository.WorkerPools.Create(Arg.Any()) + .Returns(new WorkerPoolResource { Id = Guid.NewGuid().ToString(), Name = newPool }); + + await createWorkerPoolCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + LogLines.Should().Contain($"Creating worker pool: {newPool}"); + } + + [Test] + public async Task JsonOutput_CreateNewWorkerPool() + { + var newPool = Guid.NewGuid().ToString(); + CommandLineArgs.Add($"--name={newPool}"); + CommandLineArgs.Add("--outputFormat=json"); + + Repository.WorkerPools.FindByName(Arg.Any()).Returns((WorkerPoolResource)null); + Repository.WorkerPools.Create(Arg.Any()) + .Returns(new WorkerPoolResource { Id = Guid.NewGuid().ToString(), Name = newPool}); + + await createWorkerPoolCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + var logoutput = LogOutput.ToString(); + Console.WriteLine(logoutput); + JsonConvert.DeserializeObject(logoutput); + logoutput.Should().Contain(newPool); + } + + } +} \ No newline at end of file diff --git a/source/Octo.Tests/Commands/ListWorkerMachinesCommandFixture.cs b/source/Octo.Tests/Commands/ListWorkerMachinesCommandFixture.cs new file mode 100644 index 000000000..7da214d57 --- /dev/null +++ b/source/Octo.Tests/Commands/ListWorkerMachinesCommandFixture.cs @@ -0,0 +1,274 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using FluentAssertions; +using Newtonsoft.Json; +using NSubstitute; +using NUnit.Framework; +using Octopus.Cli.Commands.Machine; +using Octopus.Cli.Infrastructure; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Cli.Tests.Commands +{ + [TestFixture] + public class ListWorkerMachinesCommandFixture : ApiCommandFixtureBase + { + const string MachineLogFormat = " - {0} {1} (ID: {2}) in {3}"; + + [SetUp] + public void SetUp() + { + listWorkerMachinesCommand = new ListWorkerMachinesCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); + } + + ListWorkerMachinesCommand listWorkerMachinesCommand; + + [Test] + public async Task ShouldGetListOfWorkerMachinesWithPoolAndStatusArgs() + { + CommandLineArgs.Add("-workerpool=SomePool"); + CommandLineArgs.Add("-status=Offline"); + + Repository.WorkerPools.FindAll().Returns(new List + { + new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} + }); + + var workerList = MakeWorkerMachineList(3, + new List + { + MachineModelStatus.Online, + MachineModelStatus.Offline, + MachineModelStatus.Offline + }, + new List + { + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-001") + }); + + Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + + await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + LogLines.Should().Contain("Worker Machines: 2"); + LogLines.Should().NotContain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); + LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[1].Name, workerList[1].Status.ToString(), workerList[1].Id, "SomePool")); + LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[2].Name, workerList[2].Status.ToString(), workerList[2].Id, "SomePool")); + } + + [Test] + public async Task ShouldGetListOfWorkerMachinesWithPoolArgs() + { + CommandLineArgs.Add("-workerpool=SomePool"); + + Repository.WorkerPools.FindAll().Returns(new List + { + new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} + }); + + var workerList = MakeWorkerMachineList(1, + new List + { + MachineModelStatus.Online + }, + new List + { + new ReferenceCollection("WorkerPools-001") + }); + Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + + await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + LogLines.Should().Contain("Worker Machines: 1"); + LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); + } + + [Test] + public async Task ShouldGetListOfWorkerMachinesWithNoArgs() + { + Repository.WorkerPools.FindAll().Returns(new List + { + new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"}, + new WorkerPoolResource {Name = "SomeOtherPool", Id = "WorkerPools-002"} + }); + + var workerList = MakeWorkerMachineList(3, + new List + { + MachineModelStatus.Online, + MachineModelStatus.Offline, + MachineModelStatus.Offline + }, + new List + { + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-002"), + new ReferenceCollection("WorkerPools-002") + }); + Repository.WorkerMachines.FindAll().Returns(workerList); + + await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + LogLines.Should().Contain("Worker Machines: 3"); + LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); + LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[1].Name, workerList[1].Status.ToString(), workerList[1].Id, "SomeOtherPool")); + LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[2].Name, workerList[2].Status.ToString(), workerList[2].Id, "SomeOtherPool")); + } + + [Test] + public async Task ShouldGetListOfWorkerMachinesWithOfflineStatusArgs() + { + CommandLineArgs.Add("-status=Offline"); + + Repository.WorkerPools.FindAll().Returns(new List + { + new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} + }); + + var workerList = MakeWorkerMachineList(3, + new List + { + MachineModelStatus.Online, + MachineModelStatus.Online, + MachineModelStatus.Offline + }, + new List + { + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-001") + }); + + Repository.WorkerMachines.FindAll().Returns(workerList); + + await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + LogLines.Should().Contain("Worker Machines: 1"); + LogLines.Should().NotContain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); + LogLines.Should().NotContain(string.Format(MachineLogFormat, workerList[1].Name, workerList[1].Status.ToString(), workerList[1].Id, "SomePool")); + LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[2].Name, workerList[2].Status.ToString(), workerList[2].Id, "SomePool")); + } + + [Test] + public async Task ShouldSupportStateFilters() + { + CommandLineArgs.Add("--health-status=Healthy"); + CommandLineArgs.Add("--calamari-outdated=false"); + CommandLineArgs.Add("--tentacle-outdated=true"); + CommandLineArgs.Add("--disabled=true"); + Repository.Client.RootDocument.Version = "3.4.0"; + Repository.WorkerPools.FindAll().Returns(new List + { + new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} + }); + + Repository.WorkerMachines.FindAll().Returns(new List + { + new WorkerMachineResource { + Name = "PC0123", + Id = "Machines-001", + HealthStatus = MachineModelHealthStatus.Unavailable, + WorkerPoolIds = new ReferenceCollection("WorkerPools-001") + }, + new WorkerMachineResource { + Name = "PC01466", + Id = "Machines-002", + HealthStatus = MachineModelHealthStatus.Healthy, + IsDisabled = true, + HasLatestCalamari = true, + Endpoint = new ListeningTentacleEndpointResource() {TentacleVersionDetails = new TentacleDetailsResource { UpgradeSuggested = true } }, + WorkerPoolIds = new ReferenceCollection("WorkerPools-001") + }, + new WorkerMachineResource { + Name = "PC01467", + Id = "Machines-003", + HealthStatus = MachineModelHealthStatus.Healthy, + IsDisabled = true, + HasLatestCalamari = true, + Endpoint = new ListeningTentacleEndpointResource() {TentacleVersionDetails = new TentacleDetailsResource { UpgradeSuggested = false } }, + WorkerPoolIds = new ReferenceCollection("WorkerPools-001") + }, + new WorkerMachineResource { + Name = "PC01468", + Id = "Machines-004", + HealthStatus = MachineModelHealthStatus.Healthy, + IsDisabled = true, + WorkerPoolIds = new ReferenceCollection("WorkerPools-001"), + HasLatestCalamari = false + }, + new WorkerMachineResource { + Name = "PC01999", + Id = "Machines-005", + HealthStatus = MachineModelHealthStatus.Healthy, + IsDisabled = false, + WorkerPoolIds = new ReferenceCollection("WorkerPools-001")} + }); + + await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + LogLines.Should().Contain("Worker Machines: 1"); + LogLines.Should().Contain(string.Format(MachineLogFormat, "PC01466", "Healthy - Disabled", "Machines-002", "SomePool")); + } + + + [Test] + public async Task JsonFormat_ShouldBeWellFormed() + { + CommandLineArgs.Add("--outputFormat=json"); + CommandLineArgs.Add("-status=Online"); + + Repository.WorkerPools.FindAll().Returns(new List + { + new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} + }); + + var workerList = MakeWorkerMachineList(3, + new List + { + MachineModelStatus.Online, + MachineModelStatus.Online, + MachineModelStatus.Offline + }, + new List + { + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-001"), + new ReferenceCollection("WorkerPools-001") + }); + + Repository.WorkerMachines.FindAll().Returns(workerList); + + await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + var logoutput = LogOutput.ToString(); + JsonConvert.DeserializeObject(logoutput); + logoutput.Should().Contain(workerList[0].Name); + logoutput.Should().Contain(workerList[1].Name); + logoutput.Should().NotContain(workerList[2].Name); + } + + + private List MakeWorkerMachineList(int numWorkers, List statuses, + List pools) + { + var result = new List(); + for (int i = 0; i < numWorkers; i++) + { + result.Add( + new WorkerMachineResource + { + Name = Guid.NewGuid().ToString(), + Id = "Machines-00" + i, + Status = statuses[i], + WorkerPoolIds = pools[i] + }); + } + + return result; + } + } +} \ No newline at end of file diff --git a/source/Octo.Tests/Commands/ListWorkerPoolsCommandFixture.cs b/source/Octo.Tests/Commands/ListWorkerPoolsCommandFixture.cs new file mode 100644 index 000000000..4bef7d457 --- /dev/null +++ b/source/Octo.Tests/Commands/ListWorkerPoolsCommandFixture.cs @@ -0,0 +1,59 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using FluentAssertions; +using Newtonsoft.Json; +using NSubstitute; +using NUnit.Framework; +using Octopus.Cli.Commands.WorkerPool; +using Octopus.Client.Model; + +namespace Octopus.Cli.Tests.Commands +{ + [TestFixture] + public class ListWorkerPoolsCommandFixture: ApiCommandFixtureBase + { + ListWorkerPoolsCommand listWorkerPoolsCommand; + + [SetUp] + public void SetUp() + { + listWorkerPoolsCommand = new ListWorkerPoolsCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); + } + + [Test] + public async Task ShouldGetListOfWorkerPools() + { + SetupPools(); + + await listWorkerPoolsCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + LogLines.Should().Contain("WorkerPools: 2"); + LogLines.Should().Contain(" - default (ID: defaultid)"); + LogLines.Should().Contain(" - windows (ID: windowsid)"); + } + + [Test] + public async Task JsonFormat_ShouldBeWellFormed() + { + SetupPools(); + + CommandLineArgs.Add("--outputFormat=json"); + await listWorkerPoolsCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + + var logoutput = LogOutput.ToString(); + JsonConvert.DeserializeObject(logoutput); + logoutput.Should().Contain("defaultid"); + logoutput.Should().Contain("windowsid"); + } + + private void SetupPools() + { + Repository.WorkerPools.FindAll().Returns(new List + { + new WorkerPoolResource() {Name = "default", Id = "defaultid"}, + new WorkerPoolResource() {Name = "windows", Id = "windowsid"} + }); + } + + } +} \ No newline at end of file diff --git a/source/Octopus.Cli/Commands/Machine/ListWorkerMachinesCommand.cs b/source/Octopus.Cli/Commands/Machine/ListWorkerMachinesCommand.cs new file mode 100644 index 000000000..1d84eb06f --- /dev/null +++ b/source/Octopus.Cli/Commands/Machine/ListWorkerMachinesCommand.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Octopus.Cli.Infrastructure; +using Octopus.Cli.Repositories; +using Octopus.Cli.Util; +using Octopus.Client; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Cli.Commands.Machine +{ + [Command("list-workermachines", Description = "Lists all worker machines")] + public class ListWorkerMachinesCommand : ApiCommand, ISupportFormattedOutput + { + readonly HashSet pools = new HashSet(StringComparer.OrdinalIgnoreCase); + readonly HashSet statuses = new HashSet(StringComparer.OrdinalIgnoreCase); + readonly HashSet healthStatuses = new HashSet(StringComparer.OrdinalIgnoreCase); + private HealthStatusProvider provider; + List workerpoolResources; + IEnumerable workerpoolMachines; + private bool? isDisabled; + private bool? isCalamariOutdated; + private bool? isTentacleOutdated; + + public ListWorkerMachinesCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider) + : base(clientFactory, repositoryFactory, fileSystem, commandOutputProvider) + { + var options = Options.For("Listing Worker Machines"); + options.Add("workerpool=", "Name of a worker pool to filter by. Can be specified many times.", v => pools.Add(v)); + options.Add("status=", $"[Optional] Status of Machines filter by ({string.Join(", ", HealthStatusProvider.StatusNames)}). Can be specified many times.", v => statuses.Add(v)); + options.Add("health-status=|healthstatus=", $"[Optional] Health status of Machines filter by ({string.Join(", ", HealthStatusProvider.HealthStatusNames)}). Can be specified many times.", v => healthStatuses.Add(v)); + options.Add("disabled=", "[Optional] Disabled status filter of Machine.", v => SetFlagState(v, ref isDisabled)); + options.Add("calamari-outdated=", "[Optional] State of Calamari to filter. By default ignores Calamari state.", v => SetFlagState(v, ref isCalamariOutdated)); + options.Add("tentacle-outdated=", "[Optional] State of Tentacle version to filter. By default ignores Tentacle state", v => SetFlagState(v, ref isTentacleOutdated)); + } + + public async Task Request() + { + provider = new HealthStatusProvider(Repository, statuses, healthStatuses, commandOutputProvider); + + workerpoolResources = await GetPools().ConfigureAwait(false); + + workerpoolMachines = await FilterByWorkerPools(workerpoolResources).ConfigureAwait(false); + workerpoolMachines = FilterByState(workerpoolMachines, provider); + } + + public void PrintDefaultOutput() + { + LogFilteredMachines(workerpoolMachines, provider, workerpoolResources); + } + + public void PrintJsonOutput() + { + commandOutputProvider.Json(workerpoolMachines.Select(machine => new + { + machine.Id, + machine.Name, + Status = provider.GetStatus(machine), + WorkerPools = machine.WorkerPoolIds.Select(id => workerpoolResources.First(e => e.Id == id).Name) + .ToArray() + })); + } + + private void LogFilteredMachines(IEnumerable poolMachines, HealthStatusProvider provider, List poolResources) + { + var orderedMachines = poolMachines.OrderBy(m => m.Name).ToList(); + commandOutputProvider.Information("Worker Machines: {Count}", orderedMachines.Count); + foreach (var machine in orderedMachines) + { + commandOutputProvider.Information(" - {Machine:l} {Status:l} (ID: {MachineId:l}) in {WorkerPool:l}", machine.Name, provider.GetStatus(machine), machine.Id, + string.Join(" and ", machine.WorkerPoolIds.Select(id => poolResources.First(e => e.Id == id).Name))); + } + } + + private Task> GetPools() + { + commandOutputProvider.Debug("Loading pools..."); + return Repository.WorkerPools.FindAll(); + } + + private IEnumerable FilterByState(IEnumerable poolMachines, HealthStatusProvider provider) + { + poolMachines = provider.Filter(poolMachines); + + if (isDisabled.HasValue) + { + poolMachines = poolMachines.Where(m => m.IsDisabled == isDisabled.Value); + } + if (isCalamariOutdated.HasValue) + { + poolMachines = poolMachines.Where(m => m.HasLatestCalamari == !isCalamariOutdated.Value); + } + if (isTentacleOutdated.HasValue) + { + poolMachines = + poolMachines.Where( + m => + (m.Endpoint as ListeningTentacleEndpointResource)?.TentacleVersionDetails.UpgradeSuggested == + isTentacleOutdated.Value); + } + return poolMachines; + } + + private Task> FilterByWorkerPools(List poolResources) + { + var poolsToInclude = poolResources.Where(e => pools.Contains(e.Name, StringComparer.OrdinalIgnoreCase)).ToList(); + var missingPools = pools.Except(poolsToInclude.Select(e => e.Name), StringComparer.OrdinalIgnoreCase).ToList(); + if (missingPools.Any()) + throw new CouldNotFindException("pools(s) named", string.Join(", ", missingPools)); + + + var poolsFilter = poolsToInclude.Select(p => p.Id).ToList(); + + commandOutputProvider.Debug("Loading worker machines..."); + if (poolsFilter.Count > 0) + { + commandOutputProvider.Debug("Loading machines from {WorkerPools:l}...", string.Join(", ", poolsToInclude.Select(e => e.Name))); + return + Repository.WorkerMachines.FindMany( + x => { return x.WorkerPoolIds.Any(poolId => poolsFilter.Contains(poolId)); }); + } + else + { + commandOutputProvider.Debug("Loading worker machines from all pools..."); + return Repository.WorkerMachines.FindAll(); + } + } + } +} \ No newline at end of file diff --git a/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs new file mode 100644 index 000000000..eb4e9f2e1 --- /dev/null +++ b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Octopus.Cli.Infrastructure; +using Octopus.Cli.Repositories; +using Octopus.Cli.Util; +using Octopus.Client; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Cli.Commands.WorkerPools +{ + [Command("clean-workerpool", Description = "Cleans all Offline Worker Machines from a WorkerPool")] + public class CleanWorkerPoolCommand : ApiCommand, ISupportFormattedOutput + { + string poolName; + readonly HashSet statuses = new HashSet(StringComparer.OrdinalIgnoreCase); + readonly HashSet healthStatuses = new HashSet(StringComparer.OrdinalIgnoreCase); + private bool? isDisabled; + private bool? isCalamariOutdated; + private bool? isTentacleOutdated; + WorkerPoolResource workerpoolResource; + IEnumerable machines; + List commandResults = new List(); + + + public CleanWorkerPoolCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider) + : base(clientFactory, repositoryFactory, fileSystem, commandOutputProvider) + { + var options = Options.For("WorkerPool Cleanup"); + options.Add("workerpool=", "Name of a worker pool to clean up.", v => poolName = v); + options.Add("status=", $"Status of Worker Machines to clean up ({string.Join(", ", HealthStatusProvider.StatusNames)}). Can be specified many times.", v => statuses.Add(v)); + options.Add("health-status=", $"Health status of Worker Machines to clean up ({string.Join(", ", HealthStatusProvider.HealthStatusNames)}). Can be specified many times.", v => healthStatuses.Add(v)); + options.Add("disabled=", "[Optional] Disabled status filter of Worker Machine to clean up.", v => SetFlagState(v, ref isDisabled)); + options.Add("calamari-outdated=", "[Optional] State of Calamari to clean up. By default ignores Calamari state.", v => SetFlagState(v, ref isCalamariOutdated)); + options.Add("tentacle-outdated=", "[Optional] State of Tentacle version to clean up. By default ignores Tentacle state", v => SetFlagState(v, ref isTentacleOutdated)); + } + + 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() && !statuses.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 = FilterByState(machines); + + await CleanUpPool(machines.ToList(), workerpoolResource); + } + + private async Task CleanUpPool(List 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) + { + MachineResult 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.WorkerMachines.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.WorkerMachines.Delete(machine).ConfigureAwait(false); + result.Action = MachineAction.Deleted; + } + + this.commandResults.Add(result); + } + } + + private IEnumerable FilterByState(IEnumerable workerMachines) + { + var provider = new HealthStatusProvider(Repository, statuses, healthStatuses, commandOutputProvider); + workerMachines = provider.Filter(workerMachines); + + if (isDisabled.HasValue) + { + workerMachines = workerMachines.Where(m => m.IsDisabled == isDisabled.Value); + } + if (isCalamariOutdated.HasValue) + { + workerMachines = workerMachines.Where(m => m.HasLatestCalamari == !isCalamariOutdated.Value); + } + if (isTentacleOutdated.HasValue) + { + workerMachines = workerMachines.Where(m => (m.Endpoint as ListeningTentacleEndpointResource)?.TentacleVersionDetails.UpgradeSuggested == isTentacleOutdated.Value); + } + return workerMachines; + } + + private string GetStateFilterDescription() + { + var description = string.Join(",", statuses.Concat(healthStatuses)); + + if (isDisabled.HasValue) + { + description += isDisabled.Value ? "and disabled" : "and not disabled"; + } + + if (isCalamariOutdated.HasValue) + { + description += $" and its Calamari version {(isCalamariOutdated.Value ? "" : "not")}out of date"; + } + + if (isTentacleOutdated.HasValue) + { + description += $" and its Tentacle version {(isTentacleOutdated.Value ? "" : "not")}out of date"; + } + + return description; + } + + private Task> FilterByWorkerPool(WorkerPoolResource poolResource) + { + commandOutputProvider.Debug("Loading worker machines..."); + return Repository.WorkerMachines.FindMany(x => x.WorkerPoolIds.Any(poolId => poolId == poolResource.Id)); + } + + private async Task GetWorkerPool() + { + commandOutputProvider.Debug("Loading worker pools..."); + var poolResource = await Repository.WorkerPools.FindByName(poolName).ConfigureAwait(false); + if (poolResource == null) + { + throw new CouldNotFindException("the specified worker pool"); + } + return poolResource; + } + + public void PrintDefaultOutput() + { + + } + + public void PrintJsonOutput() + { + commandOutputProvider.Json(commandResults.Select(x =>new + { + Machine = new { x.Machine.Id,x.Machine.Name, x.Machine.Status }, + Environment = x.Action == MachineAction.RemovedFromPool ? new { workerpoolResource.Id, workerpoolResource.Name } : null, + Action = x.Action.ToString() + })); + } + + public enum MachineAction + { + RemovedFromPool, + Deleted + } + + private class MachineResult + { + public MachineBasedResource Machine { get; set; } + public MachineAction Action { get; set; } + } + } +} \ No newline at end of file diff --git a/source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs b/source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs new file mode 100644 index 000000000..c84099621 --- /dev/null +++ b/source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs @@ -0,0 +1,60 @@ +using System.Threading.Tasks; +using Octopus.Cli.Infrastructure; +using Octopus.Cli.Repositories; +using Octopus.Cli.Util; +using Octopus.Client; +using Octopus.Client.Model; + +namespace Octopus.Cli.Commands.WorkerPool +{ + [Command("create-workerpool", Description = "Creates a pool for worker machines")] + public class CreateWorkerPoolCommand : ApiCommand, ISupportFormattedOutput + { + WorkerPoolResource pool; + + public CreateWorkerPoolCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider) + : base(clientFactory, repositoryFactory, fileSystem, commandOutputProvider) + { + var options = Options.For("WorkerPool creation"); + options.Add("name=", "The name of the worker pool", v => WorkerPoolName = v); + options.Add("ignoreIfExists", "If the pool already exists, an error will be returned. Set this flag to ignore the error.", v => IgnoreIfExists = true); + } + + public string WorkerPoolName { get; set; } + public bool IgnoreIfExists { get; set; } + + 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); + } + + public void PrintDefaultOutput() + { + commandOutputProvider.Information("WorkerPool created. ID: {Id:l}", pool.Id); + } + + public void PrintJsonOutput() + { + commandOutputProvider.Json(new + { + pool.Id, + pool.Name, + }); + } + } +} \ No newline at end of file diff --git a/source/Octopus.Cli/Commands/WorkerPool/ListWorkerPoolsCommand.cs b/source/Octopus.Cli/Commands/WorkerPool/ListWorkerPoolsCommand.cs new file mode 100644 index 000000000..92484884f --- /dev/null +++ b/source/Octopus.Cli/Commands/WorkerPool/ListWorkerPoolsCommand.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Octopus.Cli.Infrastructure; +using Octopus.Cli.Repositories; +using Octopus.Cli.Util; +using Octopus.Client; +using Octopus.Client.Model; + +namespace Octopus.Cli.Commands.WorkerPool +{ + [Command("list-workerpools", Description = "List worker pools")] + public class ListWorkerPoolsCommand : ApiCommand, ISupportFormattedOutput + { + List pools; + + public ListWorkerPoolsCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider) + : base(clientFactory, repositoryFactory, fileSystem, commandOutputProvider) + { + } + + public async Task Request() + { + pools = await Repository.WorkerPools.FindAll().ConfigureAwait(false); + } + + public void PrintDefaultOutput() + { + commandOutputProvider.Information("WorkerPools: {Count}", pools.Count); + + foreach (var pool in pools) + { + commandOutputProvider.Information(" - {WorkerPools:l} (ID: {Id:l})", pool.Name, pool.Id); + } + } + + public void PrintJsonOutput() + { + commandOutputProvider.Json( + pools.Select(pool => new + { + pool.Id, + pool.Name + })); + } + } +} \ No newline at end of file From f9da800789fcb8894c6b719f520d3401976bcb3d Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 13:27:06 +1000 Subject: [PATCH 08/37] fixup namespace --- source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs index 1a4ff5a60..4abafe3e7 100644 --- a/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs +++ b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; using NSubstitute; using NUnit.Framework; -using Octopus.Cli.Commands.WorkerPool; +using Octopus.Cli.Commands.WorkerPools; using Octopus.Cli.Infrastructure; using Octopus.Client.Model; From 0b3f8e2f0a292d6720ae5cba85180711f71da4b1 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Wed, 18 Apr 2018 09:01:05 +1000 Subject: [PATCH 09/37] Refactor RegisterMachineOperation and add RegisterWorkerMachineOperation --- ...AreaShouldNotRegress..NETCore.approved.txt | 45 +++- ...houldNotRegress..NETFramework.approved.txt | 47 +++- .../Operations/IRegisterMachineOperation.cs | 91 +------ .../IRegisterMachineOperationBase.cs | 95 ++++++++ .../IRegisterWorkerMachineOperation.cs | 17 ++ .../Operations/RegisterMachineOperation.cs | 203 +--------------- .../RegisterMachineOperationBase.cs | 228 ++++++++++++++++++ .../RegisterWorkerMachineOperation.cs | 142 +++++++++++ 8 files changed, 565 insertions(+), 303 deletions(-) create mode 100644 source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs create mode 100644 source/Octopus.Client/Operations/IRegisterWorkerMachineOperation.cs create mode 100644 source/Octopus.Client/Operations/RegisterMachineOperationBase.cs create mode 100644 source/Octopus.Client/Operations/RegisterWorkerMachineOperation.cs diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 1f1725df9..066bbae7d 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -3927,18 +3927,21 @@ Octopus.Client.Model.Versioning Octopus.Client.Operations { interface IRegisterMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase + { + String[] EnvironmentNames { get; set; } + String[] Roles { get; set; } + String[] Tenants { get; set; } + String[] TenantTags { get; set; } + } + interface IRegisterMachineOperationBase { Boolean AllowOverwrite { get; set; } Octopus.Client.Model.CommunicationStyle CommunicationStyle { get; set; } - String[] EnvironmentNames { get; set; } String MachineName { get; set; } String MachinePolicy { get; set; } String ProxyName { get; set; } - String[] Roles { get; set; } Uri SubscriptionId { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - String[] Tenants { get; set; } - String[] TenantTags { get; set; } String TentacleHostname { get; set; } Int32 TentaclePort { get; set; } String TentacleThumbprint { get; set; } @@ -3946,22 +3949,34 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } + interface IRegisterWorkerMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase + { + String[] WorkerPoolNames { get; set; } + } class RegisterMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase Octopus.Client.Operations.IRegisterMachineOperation + Octopus.Client.Operations.RegisterMachineOperationBase { .ctor() + .ctor(Octopus.Client.IOctopusClientFactory) + String[] EnvironmentNames { get; set; } + String[] Roles { get; set; } + String[] Tenants { get; set; } + String[] TenantTags { get; set; } + Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) + } + abstract class RegisterMachineOperationBase + Octopus.Client.Operations.IRegisterMachineOperationBase + { .ctor(Octopus.Client.IOctopusClientFactory) Boolean AllowOverwrite { get; set; } Octopus.Client.Model.CommunicationStyle CommunicationStyle { get; set; } - String[] EnvironmentNames { get; set; } String MachineName { get; set; } String MachinePolicy { get; set; } String ProxyName { get; set; } - String[] Roles { get; set; } Uri SubscriptionId { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - String[] Tenants { get; set; } - String[] TenantTags { get; set; } String TentacleHostname { get; set; } Int32 TentaclePort { get; set; } String TentacleThumbprint { get; set; } @@ -3969,6 +3984,16 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } + class RegisterWorkerMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase + Octopus.Client.Operations.IRegisterWorkerMachineOperation + Octopus.Client.Operations.RegisterMachineOperationBase + { + .ctor() + .ctor(Octopus.Client.IOctopusClientFactory) + String[] WorkerPoolNames { get; set; } + Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) + } } Octopus.Client.Repositories.Async { diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 61f2aa84e..25496f46c 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -4365,18 +4365,21 @@ Octopus.Client.Model.Versioning Octopus.Client.Operations { interface IRegisterMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase + { + String[] EnvironmentNames { get; set; } + String[] Roles { get; set; } + String[] Tenants { get; set; } + String[] TenantTags { get; set; } + } + interface IRegisterMachineOperationBase { Boolean AllowOverwrite { get; set; } Octopus.Client.Model.CommunicationStyle CommunicationStyle { get; set; } - String[] EnvironmentNames { get; set; } String MachineName { get; set; } String MachinePolicy { get; set; } String ProxyName { get; set; } - String[] Roles { get; set; } Uri SubscriptionId { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - String[] Tenants { get; set; } - String[] TenantTags { get; set; } String TentacleHostname { get; set; } Int32 TentaclePort { get; set; } String TentacleThumbprint { get; set; } @@ -4387,22 +4390,35 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } + interface IRegisterWorkerMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase + { + String[] WorkerPoolNames { get; set; } + } class RegisterMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase Octopus.Client.Operations.IRegisterMachineOperation + Octopus.Client.Operations.RegisterMachineOperationBase { .ctor() + .ctor(Octopus.Client.IOctopusClientFactory) + String[] EnvironmentNames { get; set; } + String[] Roles { get; set; } + String[] Tenants { get; set; } + String[] TenantTags { get; set; } + void Execute(Octopus.Client.IOctopusRepository) + Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) + } + abstract class RegisterMachineOperationBase + Octopus.Client.Operations.IRegisterMachineOperationBase + { .ctor(Octopus.Client.IOctopusClientFactory) Boolean AllowOverwrite { get; set; } Octopus.Client.Model.CommunicationStyle CommunicationStyle { get; set; } - String[] EnvironmentNames { get; set; } String MachineName { get; set; } String MachinePolicy { get; set; } String ProxyName { get; set; } - String[] Roles { get; set; } Uri SubscriptionId { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - String[] Tenants { get; set; } - String[] TenantTags { get; set; } String TentacleHostname { get; set; } Int32 TentaclePort { get; set; } String TentacleThumbprint { get; set; } @@ -4413,6 +4429,17 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } + class RegisterWorkerMachineOperation + Octopus.Client.Operations.IRegisterMachineOperationBase + Octopus.Client.Operations.IRegisterWorkerMachineOperation + Octopus.Client.Operations.RegisterMachineOperationBase + { + .ctor() + .ctor(Octopus.Client.IOctopusClientFactory) + String[] WorkerPoolNames { get; set; } + void Execute(Octopus.Client.IOctopusRepository) + Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) + } } Octopus.Client.Repositories { diff --git a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs index 38aabef18..f0271c632 100644 --- a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs +++ b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs @@ -7,7 +7,7 @@ namespace Octopus.Client.Operations /// /// Encapsulates the operation for registering machines. /// - public interface IRegisterMachineOperation + public interface IRegisterMachineOperation : IRegisterMachineOperationBase { /// /// Gets or sets the environments that this machine should be added to. @@ -28,94 +28,5 @@ public interface IRegisterMachineOperation /// Gets or sets the tenant tags that this machine is linked to. /// string[] TenantTags { get; set; } - - /// - /// Gets or sets the name of the machine that will be used within Octopus to identify this machine. - /// - string MachineName { get; set; } - - /// - /// Gets or sets the machine policy that applies to this machine. - /// - string MachinePolicy { get; set; } - - /// - /// Gets or sets the hostname that Octopus should use when communicating with the Tentacle. - /// - string TentacleHostname { get; set; } - - /// - /// Gets or sets the TCP port that Octopus should use when communicating with the Tentacle. - /// - int TentaclePort { get; set; } - - /// - /// Gets or sets the certificate thumbprint that Octopus should expect when communicating with the Tentacle. - /// - string TentacleThumbprint { get; set; } - - /// - /// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle. - /// - string ProxyName { get; set; } - - /// - /// If a machine with the same name already exists, it won't be overwritten by default (instead, an - /// will be thrown). - /// Set this property to true if you do want the existing machine to be overwritten. - /// - bool AllowOverwrite { get; set; } - - /// - /// The communication style to use with the Tentacle. Allowed values are: TentacleActive, in which case the - /// Tentacle will connect to the Octopus server for instructions; or, TentaclePassive, in which case the - /// Tentacle will listen for commands from the server (default). - /// - CommunicationStyle CommunicationStyle { get; set; } - - Uri SubscriptionId { get; set; } - - /// - /// How the machine should participate in Tenanted Deployments. - /// Allowed values are Untenanted, TenantedOrUntenanted or Tenanted - /// - TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - -#if SYNC_CLIENT - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy server endpoint. - void Execute(OctopusServerEndpoint serverEndpoint); - - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy repository. - void Execute(OctopusRepository repository); - - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy repository. - void Execute(IOctopusRepository repository); -#endif - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy server endpoint. - Task ExecuteAsync(OctopusServerEndpoint serverEndpoint); - - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy repository. - Task ExecuteAsync(OctopusAsyncRepository repository); - - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy repository. - Task ExecuteAsync(IOctopusAsyncRepository repository); } } \ No newline at end of file diff --git a/source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs b/source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs new file mode 100644 index 000000000..2fb142741 --- /dev/null +++ b/source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs @@ -0,0 +1,95 @@ +using System; +using System.Threading.Tasks; +using Octopus.Client.Model; + +namespace Octopus.Client.Operations +{ + /// + /// Base for registering Deployment Targets and Worker Machines + /// + public interface IRegisterMachineOperationBase + { + /// + /// Gets or sets the name of the machine that will be used within Octopus to identify this machine. + /// + string MachineName { get; set; } + + /// + /// Gets or sets the machine policy that applies to this machine. + /// + string MachinePolicy { get; set; } + + /// + /// Gets or sets the hostname that Octopus should use when communicating with the Tentacle. + /// + string TentacleHostname { get; set; } + + /// + /// Gets or sets the TCP port that Octopus should use when communicating with the Tentacle. + /// + int TentaclePort { get; set; } + + /// + /// Gets or sets the certificate thumbprint that Octopus should expect when communicating with the Tentacle. + /// + string TentacleThumbprint { get; set; } + + /// + /// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle. + /// + string ProxyName { get; set; } + + /// + /// If a machine with the same name already exists, it won't be overwritten by default (instead, an + /// will be thrown). + /// Set this property to true if you do want the existing machine to be overwritten. + /// + bool AllowOverwrite { get; set; } + + /// + /// The communication style to use with the Tentacle. Allowed values are: TentacleActive, in which case the + /// Tentacle will connect to the Octopus server for instructions; or, TentaclePassive, in which case the + /// Tentacle will listen for commands from the server (default). + /// + CommunicationStyle CommunicationStyle { get; set; } + + Uri SubscriptionId { get; set; } + +#if SYNC_CLIENT + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server endpoint. + void Execute(OctopusServerEndpoint serverEndpoint); + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy repository. + void Execute(OctopusRepository repository); + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy repository. + void Execute(IOctopusRepository repository); +#endif + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server endpoint. + Task ExecuteAsync(OctopusServerEndpoint serverEndpoint); + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy repository. + Task ExecuteAsync(OctopusAsyncRepository repository); + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy repository. + Task ExecuteAsync(IOctopusAsyncRepository repository); + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Operations/IRegisterWorkerMachineOperation.cs b/source/Octopus.Client/Operations/IRegisterWorkerMachineOperation.cs new file mode 100644 index 000000000..d34d52e19 --- /dev/null +++ b/source/Octopus.Client/Operations/IRegisterWorkerMachineOperation.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; +using Octopus.Client.Model; + +namespace Octopus.Client.Operations +{ + /// + /// Encapsulates the operation for registering worker machines. + /// + public interface IRegisterWorkerMachineOperation : IRegisterMachineOperationBase + { + /// + /// Gets or sets the worker pools that this machine should be added to. + /// + string[] WorkerPoolNames { get; set; } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Operations/RegisterMachineOperation.cs b/source/Octopus.Client/Operations/RegisterMachineOperation.cs index e007807bf..f40a329b2 100644 --- a/source/Octopus.Client/Operations/RegisterMachineOperation.cs +++ b/source/Octopus.Client/Operations/RegisterMachineOperation.cs @@ -12,10 +12,8 @@ namespace Octopus.Client.Operations /// /// Encapsulates the operation for registering machines. /// - public class RegisterMachineOperation : IRegisterMachineOperation + public class RegisterMachineOperation : RegisterMachineOperationBase, IRegisterMachineOperation { - readonly IOctopusClientFactory clientFactory; - /// /// Initializes a new instance of the class. /// @@ -27,9 +25,9 @@ public RegisterMachineOperation() : this(null) /// Initializes a new instance of the class. /// /// The client factory. - public RegisterMachineOperation(IOctopusClientFactory clientFactory) + public RegisterMachineOperation(IOctopusClientFactory clientFactory) : base(clientFactory) { - this.clientFactory = clientFactory ?? new OctopusClientFactory(); + } /// @@ -52,86 +50,7 @@ public RegisterMachineOperation(IOctopusClientFactory clientFactory) /// public string[] TenantTags { get; set; } - /// - /// Gets or sets the name of the machine that will be used within Octopus to identify this machine. - /// - public string MachineName { get; set; } - - /// - /// Get or sets the machine policy that applied to this machine. - /// - public string MachinePolicy { get; set; } - - /// - /// Gets or sets the hostname that Octopus should use when communicating with the Tentacle. - /// - public string TentacleHostname { get; set; } - - /// - /// Gets or sets the TCP port that Octopus should use when communicating with the Tentacle. - /// - public int TentaclePort { get; set; } - - /// - /// Gets or sets the certificate thumbprint that Octopus should expect when communicating with the Tentacle. - /// - public string TentacleThumbprint { get; set; } - - /// - /// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle. - /// - public string ProxyName { get; set; } - - /// - /// If a machine with the same name already exists, it won't be overwritten by default (instead, an - /// will be thrown). - /// Set this property to true if you do want the existing machine to be overwritten. - /// - public bool AllowOverwrite { get; set; } - - /// - /// The communication style to use with the Tentacle. Allowed values are: TentacleActive, in which case the - /// Tentacle will connect to the Octopus server for instructions; or, TentaclePassive, in which case the - /// Tentacle will listen for commands from the server (default). - /// - public CommunicationStyle CommunicationStyle { get; set; } - - public Uri SubscriptionId { get; set; } - - /// - /// How the machine should participate in Tenanted Deployments. - /// Allowed values are Untenanted, TenantedOrUntenanted or Tenanted - /// - public TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - #if SYNC_CLIENT - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy server endpoint. - /// - /// - public void Execute(OctopusServerEndpoint serverEndpoint) - { - using (var client = clientFactory.CreateClient(serverEndpoint)) - { - var repository = new OctopusRepository(client); - - Execute(repository); - } - } - - - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy server repository. - /// - /// - public void Execute(OctopusRepository repository) - { - Execute((IOctopusRepository)repository); - } /// /// Executes the operation against the specified Octopus Deploy server. @@ -139,7 +58,7 @@ public void Execute(OctopusRepository repository) /// The Octopus Deploy server repository. /// /// - public void Execute(IOctopusRepository repository) + public override void Execute(IOctopusRepository repository) { var selectedEnvironments = GetEnvironments(repository); var machinePolicy = GetMachinePolicy(repository); @@ -148,7 +67,8 @@ public void Execute(IOctopusRepository repository) ValidateTenantTags(repository); var proxy = GetProxy(repository); - ApplyChanges(machine, selectedEnvironments, machinePolicy, tenants, proxy); + ApplyBaseChanges(machine, machinePolicy, proxy); + ApplyDeploymentTargetChanges(machine, selectedEnvironments, tenants); if (machine.Id != null) repository.Machines.Modify(machine); @@ -199,30 +119,6 @@ List GetEnvironments(IOctopusRepository repository) return selectedEnvironments; } - MachinePolicyResource GetMachinePolicy(IOctopusRepository repository) - { - var machinePolicy = default(MachinePolicyResource); - if (!string.IsNullOrEmpty(MachinePolicy)) - { - machinePolicy = repository.MachinePolicies.FindByName(MachinePolicy); - if (machinePolicy == null) - throw new ArgumentException(CouldNotFindMessage("machine policy", MachinePolicy)); - } - return machinePolicy; - } - - ProxyResource GetProxy(IOctopusRepository repository) - { - var proxy = default(ProxyResource); - if (!string.IsNullOrEmpty(ProxyName)) - { - proxy = repository.Proxies.FindByName(ProxyName); - if (proxy == null) - throw new ArgumentException(CouldNotFindMessage("proxy name", ProxyName)); - } - return proxy; - } - MachineResource GetMachine(IOctopusRepository repository) { var existing = default(MachineResource); @@ -239,40 +135,13 @@ MachineResource GetMachine(IOctopusRepository repository) } #endif - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy server endpoint. - /// - /// - public async Task ExecuteAsync(OctopusServerEndpoint serverEndpoint) - { - using (var client = await clientFactory.CreateAsyncClient(serverEndpoint).ConfigureAwait(false)) - { - var repository = new OctopusAsyncRepository(client); - - await ExecuteAsync(repository).ConfigureAwait(false); - } - } - - /// - /// Executes the operation against the specified Octopus Deploy server. - /// - /// The Octopus Deploy server repository. - /// - /// - public async Task ExecuteAsync(OctopusAsyncRepository repository) - { - await ExecuteAsync((IOctopusAsyncRepository) repository); - } - /// /// Executes the operation against the specified Octopus Deploy server. /// /// The Octopus Deploy server repository. /// /// - public async Task ExecuteAsync(IOctopusAsyncRepository repository) + public override async Task ExecuteAsync(IOctopusAsyncRepository repository) { var selectedEnvironments = GetEnvironments(repository).ConfigureAwait(false); var machinePolicy = GetMachinePolicy(repository).ConfigureAwait(false); @@ -282,7 +151,8 @@ public async Task ExecuteAsync(IOctopusAsyncRepository repository) var proxy = GetProxy(repository).ConfigureAwait(false); var machine = await machineTask; - ApplyChanges(machine, await selectedEnvironments, await machinePolicy, await tenants, await proxy); + ApplyBaseChanges(machine, await machinePolicy, await proxy); + ApplyDeploymentTargetChanges(machine, await selectedEnvironments, await tenants); if (machine.Id != null) await repository.Machines.Modify(machine).ConfigureAwait(false); @@ -333,31 +203,6 @@ async Task> GetEnvironments(IOctopusAsyncRepository re return selectedEnvironments; } - async Task GetMachinePolicy(IOctopusAsyncRepository repository) - { - - var machinePolicy = default(MachinePolicyResource); - if (!string.IsNullOrEmpty(MachinePolicy)) - { - machinePolicy = await repository.MachinePolicies.FindByName(MachinePolicy).ConfigureAwait(false); - if (machinePolicy == null) - throw new ArgumentException(CouldNotFindMessage("machine policy", MachinePolicy)); - } - return machinePolicy; - } - - async Task GetProxy(IOctopusAsyncRepository repository) - { - var proxy = default(ProxyResource); - if (!string.IsNullOrEmpty(ProxyName)) - { - proxy = await repository.Proxies.FindByName(ProxyName).ConfigureAwait(false); - if (proxy == null) - throw new ArgumentException(CouldNotFindMessage("proxy name", ProxyName)); - } - return proxy; - } - async Task GetMachine(IOctopusAsyncRepository repository) { var existing = default(MachineResource); @@ -373,40 +218,12 @@ async Task GetMachine(IOctopusAsyncRepository repository) return existing ?? new MachineResource(); } - void ApplyChanges(MachineResource machine, IEnumerable environment, MachinePolicyResource machinePolicy, IEnumerable tenants, ProxyResource proxy) + void ApplyDeploymentTargetChanges(MachineResource machine, IEnumerable environment, IEnumerable tenants) { machine.EnvironmentIds = new ReferenceCollection(environment.Select(e => e.Id).ToArray()); machine.TenantIds = new ReferenceCollection(tenants.Select(t => t.Id).ToArray()); machine.TenantTags = new ReferenceCollection(TenantTags); machine.Roles = new ReferenceCollection(Roles); - machine.Name = MachineName; - machine.TenantedDeploymentParticipation = TenantedDeploymentParticipation; - - if (machinePolicy != null) - machine.MachinePolicyId = machinePolicy.Id; - - if (CommunicationStyle == CommunicationStyle.TentaclePassive) - { - var listening = new ListeningTentacleEndpointResource(); - listening.Uri = new Uri("https://" + TentacleHostname.ToLowerInvariant() + ":" + TentaclePort.ToString(CultureInfo.InvariantCulture) + "/").ToString(); - listening.Thumbprint = TentacleThumbprint; - listening.ProxyId = proxy?.Id; - machine.Endpoint = listening; - } - else if (CommunicationStyle == CommunicationStyle.TentacleActive) - { - var polling = new PollingTentacleEndpointResource(); - polling.Uri = SubscriptionId.ToString(); - polling.Thumbprint = TentacleThumbprint; - machine.Endpoint = polling; - } - } - - static string CouldNotFindMessage(string modelType, params string[] missing) - { - return missing.Length == 1 - ? $"Could not find the {modelType} named {missing.Single()} on the Octopus server. Ensure the {modelType} exists and you have permission to access it." - : $"Could not find the {modelType}s named: {string.Join(", ", missing)} on the Octopus server. Ensure the {modelType}s exist and you have permission to access them."; } } } \ No newline at end of file diff --git a/source/Octopus.Client/Operations/RegisterMachineOperationBase.cs b/source/Octopus.Client/Operations/RegisterMachineOperationBase.cs new file mode 100644 index 000000000..23f2d5db8 --- /dev/null +++ b/source/Octopus.Client/Operations/RegisterMachineOperationBase.cs @@ -0,0 +1,228 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; +using Octopus.Client.Exceptions; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Client.Operations +{ + /// + /// Encapsulates the operation for registering machines. + /// + public abstract class RegisterMachineOperationBase : IRegisterMachineOperationBase + { + readonly IOctopusClientFactory clientFactory; + + /// + /// Initializes a new instance of the class. + /// + /// The client factory. + public RegisterMachineOperationBase(IOctopusClientFactory clientFactory) + { + this.clientFactory = clientFactory ?? new OctopusClientFactory(); + } + + + /// + /// Gets or sets the name of the machine that will be used within Octopus to identify this machine. + /// + public string MachineName { get; set; } + + /// + /// Get or sets the machine policy that applied to this machine. + /// + public string MachinePolicy { get; set; } + + /// + /// Gets or sets the hostname that Octopus should use when communicating with the Tentacle. + /// + public string TentacleHostname { get; set; } + + /// + /// Gets or sets the TCP port that Octopus should use when communicating with the Tentacle. + /// + public int TentaclePort { get; set; } + + /// + /// Gets or sets the certificate thumbprint that Octopus should expect when communicating with the Tentacle. + /// + public string TentacleThumbprint { get; set; } + + /// + /// Gets or sets the name of the proxy that Octopus should use when communicating with the Tentacle. + /// + public string ProxyName { get; set; } + + /// + /// If a machine with the same name already exists, it won't be overwritten by default (instead, an + /// will be thrown). + /// Set this property to true if you do want the existing machine to be overwritten. + /// + public bool AllowOverwrite { get; set; } + + /// + /// The communication style to use with the Tentacle. Allowed values are: TentacleActive, in which case the + /// Tentacle will connect to the Octopus server for instructions; or, TentaclePassive, in which case the + /// Tentacle will listen for commands from the server (default). + /// + public CommunicationStyle CommunicationStyle { get; set; } + + public Uri SubscriptionId { get; set; } + +#if SYNC_CLIENT + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server endpoint. + /// + /// + public void Execute(OctopusServerEndpoint serverEndpoint) + { + using (var client = clientFactory.CreateClient(serverEndpoint)) + { + var repository = new OctopusRepository(client); + + Execute(repository); + } + } + + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server repository. + /// + /// + public void Execute(OctopusRepository repository) + { + Execute((IOctopusRepository)repository); + } + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server repository. + /// + /// + public abstract void Execute(IOctopusRepository repository); + + protected MachinePolicyResource GetMachinePolicy(IOctopusRepository repository) + { + var machinePolicy = default(MachinePolicyResource); + if (!string.IsNullOrEmpty(MachinePolicy)) + { + machinePolicy = repository.MachinePolicies.FindByName(MachinePolicy); + if (machinePolicy == null) + throw new ArgumentException(CouldNotFindMessage("machine policy", MachinePolicy)); + } + return machinePolicy; + } + + protected ProxyResource GetProxy(IOctopusRepository repository) + { + var proxy = default(ProxyResource); + if (!string.IsNullOrEmpty(ProxyName)) + { + proxy = repository.Proxies.FindByName(ProxyName); + if (proxy == null) + throw new ArgumentException(CouldNotFindMessage("proxy name", ProxyName)); + } + return proxy; + } +#endif + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server endpoint. + /// + /// + public async Task ExecuteAsync(OctopusServerEndpoint serverEndpoint) + { + using (var client = await clientFactory.CreateAsyncClient(serverEndpoint).ConfigureAwait(false)) + { + var repository = new OctopusAsyncRepository(client); + + await ExecuteAsync(repository).ConfigureAwait(false); + } + } + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server repository. + /// + /// + public async Task ExecuteAsync(OctopusAsyncRepository repository) + { + await ExecuteAsync((IOctopusAsyncRepository) repository); + } + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server repository. + /// + /// + public abstract Task ExecuteAsync(IOctopusAsyncRepository repository); + + protected async Task GetMachinePolicy(IOctopusAsyncRepository repository) + { + + var machinePolicy = default(MachinePolicyResource); + if (!string.IsNullOrEmpty(MachinePolicy)) + { + machinePolicy = await repository.MachinePolicies.FindByName(MachinePolicy).ConfigureAwait(false); + if (machinePolicy == null) + throw new ArgumentException(CouldNotFindMessage("machine policy", MachinePolicy)); + } + return machinePolicy; + } + + protected async Task GetProxy(IOctopusAsyncRepository repository) + { + var proxy = default(ProxyResource); + if (!string.IsNullOrEmpty(ProxyName)) + { + proxy = await repository.Proxies.FindByName(ProxyName).ConfigureAwait(false); + if (proxy == null) + throw new ArgumentException(CouldNotFindMessage("proxy name", ProxyName)); + } + return proxy; + } + + + protected void ApplyBaseChanges(MachineBasedResource machine, MachinePolicyResource machinePolicy, ProxyResource proxy) + { + machine.Name = MachineName; + if (machinePolicy != null) + machine.MachinePolicyId = machinePolicy.Id; + + if (CommunicationStyle == CommunicationStyle.TentaclePassive) + { + var listening = new ListeningTentacleEndpointResource(); + listening.Uri = new Uri("https://" + TentacleHostname.ToLowerInvariant() + ":" + TentaclePort.ToString(CultureInfo.InvariantCulture) + "/").ToString(); + listening.Thumbprint = TentacleThumbprint; + listening.ProxyId = proxy?.Id; + machine.Endpoint = listening; + } + else if (CommunicationStyle == CommunicationStyle.TentacleActive) + { + var polling = new PollingTentacleEndpointResource(); + polling.Uri = SubscriptionId.ToString(); + polling.Thumbprint = TentacleThumbprint; + machine.Endpoint = polling; + } + } + + protected static string CouldNotFindMessage(string modelType, params string[] missing) + { + return missing.Length == 1 + ? $"Could not find the {modelType} named {missing.Single()} on the Octopus server. Ensure the {modelType} exists and you have permission to access it." + : $"Could not find the {modelType}s named: {string.Join(", ", missing)} on the Octopus server. Ensure the {modelType}s exist and you have permission to access them."; + } + } +} \ No newline at end of file diff --git a/source/Octopus.Client/Operations/RegisterWorkerMachineOperation.cs b/source/Octopus.Client/Operations/RegisterWorkerMachineOperation.cs new file mode 100644 index 000000000..8997a35fa --- /dev/null +++ b/source/Octopus.Client/Operations/RegisterWorkerMachineOperation.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; +using Octopus.Client.Exceptions; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Client.Operations +{ + /// + /// Encapsulates the operation for registering machines. + /// + public class RegisterWorkerMachineOperation : RegisterMachineOperationBase, IRegisterWorkerMachineOperation + { + /// + /// Initializes a new instance of the class. + /// + public RegisterWorkerMachineOperation() : this(null) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The client factory. + public RegisterWorkerMachineOperation(IOctopusClientFactory clientFactory) : base(clientFactory) + { + + } + + /// + /// Gets or sets the worker pools that this machine should be added to. + /// + public string[] WorkerPoolNames { get; set; } + +#if SYNC_CLIENT + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server repository. + /// + /// + public override void Execute(IOctopusRepository repository) + { + var selectedPools = GetWorkerPools(repository); + var machinePolicy = GetMachinePolicy(repository); + var machine = GetWorkerMachine(repository); + var proxy = GetProxy(repository); + + ApplyBaseChanges(machine, machinePolicy, proxy); + + machine.WorkerPoolIds = new ReferenceCollection(selectedPools.Select(p => p.Id).ToArray()); + + if (machine.Id != null) + repository.WorkerMachines.Modify(machine); + else + repository.WorkerMachines.Create(machine); + } + + List GetWorkerPools(IOctopusRepository repository) + { + var selectedPools = repository.WorkerPools.FindByNames(WorkerPoolNames); + + var missing = WorkerPoolNames.Except(selectedPools.Select(p => p.Name), StringComparer.OrdinalIgnoreCase).ToList(); + + if (missing.Any()) + throw new ArgumentException(CouldNotFindMessage("worker pool", missing.ToArray())); + + return selectedPools; + } + + WorkerMachineResource GetWorkerMachine(IOctopusRepository repository) + { + var existing = default(WorkerMachineResource); + try + { + existing = repository.WorkerMachines.FindByName(MachineName); + if (!AllowOverwrite && existing?.Id != null) + throw new ArgumentException($"A worker machine named '{MachineName}' already exists. Use the 'force' parameter if you intended to update the existing machine."); + } + catch (OctopusDeserializationException) // eat it, probably caused by resource incompatability between versions + { + } + return existing ?? new WorkerMachineResource(); + } +#endif + + /// + /// Executes the operation against the specified Octopus Deploy server. + /// + /// The Octopus Deploy server repository. + /// + /// + public override async Task ExecuteAsync(IOctopusAsyncRepository repository) + { + var selectedPools = GetWorkerPools(repository).ConfigureAwait(false); + var machinePolicy = GetMachinePolicy(repository).ConfigureAwait(false); + var machineTask = GetWorkerMachine(repository).ConfigureAwait(false); + var proxy = GetProxy(repository).ConfigureAwait(false); + + var machine = await machineTask; + ApplyBaseChanges(machine, await machinePolicy, await proxy); + + machine.WorkerPoolIds = new ReferenceCollection((await selectedPools).Select(p => p.Id).ToArray()); + + if (machine.Id != null) + await repository.WorkerMachines.Modify(machine).ConfigureAwait(false); + else + await repository.WorkerMachines.Create(machine).ConfigureAwait(false); + } + + async Task> GetWorkerPools(IOctopusAsyncRepository repository) + { + var selectedPools = await repository.WorkerPools.FindByNames(WorkerPoolNames).ConfigureAwait(false); + + var missing = WorkerPoolNames.Except(selectedPools.Select(p => p.Name), StringComparer.OrdinalIgnoreCase).ToList(); + + if (missing.Any()) + throw new ArgumentException(CouldNotFindMessage("worker pool", missing.ToArray())); + + return selectedPools; + } + + async Task GetWorkerMachine(IOctopusAsyncRepository repository) + { + var existing = default(WorkerMachineResource); + try + { + existing = await repository.WorkerMachines.FindByName(MachineName).ConfigureAwait(false); + if (!AllowOverwrite && existing?.Id != null) + throw new ArgumentException($"A worker machine named '{MachineName}' already exists. Use the 'force' parameter if you intended to update the existing machine."); + } + catch (OctopusDeserializationException) // eat it, probably caused by resource incompatability between versions + { + } + return existing ?? new WorkerMachineResource(); + } + } +} \ No newline at end of file From bfe8c789ad8ded114bd6c93f30bda80c95379dc5 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 20 Apr 2018 15:29:37 +1000 Subject: [PATCH 10/37] Fixup worker param names --- .../Repositories/Async/WorkerMachineRepository.cs | 2 +- .../Repositories/Async/WorkerPoolRepository.cs | 12 ++++++------ .../Repositories/WorkerMachineRepository.cs | 2 +- .../Repositories/WorkerPoolRepository.cs | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs b/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs index 699462408..62049fad1 100644 --- a/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs +++ b/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs @@ -49,7 +49,7 @@ public Task GetConnectionStatus(WorkerMachineResource w public Task> FindByThumbprint(string thumbprint) { if (thumbprint == null) throw new ArgumentNullException("thumbprint"); - return Client.Get>(Client.RootDocument.Link("workers"), new { id = "all", thumbprint }); + return Client.Get>(Client.RootDocument.Link("Workers"), new { id = "all", thumbprint }); } public Task CreateOrModify( diff --git a/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs b/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs index 50307b654..d104fcd82 100644 --- a/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs +++ b/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs @@ -8,7 +8,7 @@ namespace Octopus.Client.Repositories.Async { public interface IWorkerPoolRepository : IFindByName, IGet, ICreate, IModify, IDelete, IGetAll { - Task> GetMachines(WorkerPoolResource pool, + Task> GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -23,7 +23,7 @@ Task Summary( string healthStatuses = null, string commStyles = null, bool? hideEmptyPools = false); - Task Sort(string[] workerpoolIdsInOrder); + Task Sort(string[] workerPoolIdsInOrder); Task CreateOrModify(string name); Task CreateOrModify(string name, string description); } @@ -35,7 +35,7 @@ public WorkerPoolRepository(IOctopusAsyncClient client) { } - public async Task> GetMachines(WorkerPoolResource environment, + public async Task> GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -45,7 +45,7 @@ public async Task> GetMachines(WorkerPoolResource en { var resources = new List(); - await Client.Paginate(environment.Link("WorkerMachines"), new { + await Client.Paginate(workerPool.Link("WorkerMachines"), new { skip, take, partialName, @@ -82,9 +82,9 @@ public Task Summary( }); } - public Task Sort(string[] environmentIdsInOrder) + public Task Sort(string[] workerPoolIdsInOrder) { - return Client.Put(Client.RootDocument.Link("WorkerPoolSortOrder"), environmentIdsInOrder); + return Client.Put(Client.RootDocument.Link("WorkerPoolSortOrder"), workerPoolIdsInOrder); } public Task CreateOrModify(string name) diff --git a/source/Octopus.Client/Repositories/WorkerMachineRepository.cs b/source/Octopus.Client/Repositories/WorkerMachineRepository.cs index a60bfea12..4c817c48d 100644 --- a/source/Octopus.Client/Repositories/WorkerMachineRepository.cs +++ b/source/Octopus.Client/Repositories/WorkerMachineRepository.cs @@ -48,7 +48,7 @@ public MachineConnectionStatus GetConnectionStatus(WorkerMachineResource machine public List FindByThumbprint(string thumbprint) { if (thumbprint == null) throw new ArgumentNullException("thumbprint"); - return Client.Get>(Client.RootDocument.Link("workers"), new { id = "all", thumbprint }); + return Client.Get>(Client.RootDocument.Link("Workers"), new { id = "all", thumbprint }); } diff --git a/source/Octopus.Client/Repositories/WorkerPoolRepository.cs b/source/Octopus.Client/Repositories/WorkerPoolRepository.cs index c8e4cecff..a8cafd702 100644 --- a/source/Octopus.Client/Repositories/WorkerPoolRepository.cs +++ b/source/Octopus.Client/Repositories/WorkerPoolRepository.cs @@ -6,7 +6,7 @@ namespace Octopus.Client.Repositories { public interface IWorkerPoolRepository : IFindByName, IGet, ICreate, IModify, IDelete, IGetAll { - List GetMachines(WorkerPoolResource workerpool, + List GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -33,7 +33,7 @@ public WorkerPoolRepository(IOctopusClient client) { } - public List GetMachines(WorkerPoolResource pool, + public List GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -43,7 +43,7 @@ public List GetMachines(WorkerPoolResource pool, { var resources = new List(); - Client.Paginate(pool.Link("WorkerMachines"), new + Client.Paginate(workerPool.Link("WorkerMachines"), new { skip, take, From 24a078e4d90ffce7b06ad6ac5a1395d3b6e4c105 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Wed, 18 Apr 2018 14:39:34 +1000 Subject: [PATCH 11/37] Add workers to DeploymentActionResource --- source/Octopus.Client/Model/DeploymentActionResource.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Octopus.Client/Model/DeploymentActionResource.cs b/source/Octopus.Client/Model/DeploymentActionResource.cs index 933935860..ac23a8a24 100644 --- a/source/Octopus.Client/Model/DeploymentActionResource.cs +++ b/source/Octopus.Client/Model/DeploymentActionResource.cs @@ -10,6 +10,7 @@ public class DeploymentActionResource : Resource public string Name { get; set; } public string ActionType { get; set; } public bool IsDisabled { get; set; } + public string WorkerPoolId { get; set; } [JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Reuse)] public ReferenceCollection Environments { get; } = new ReferenceCollection(); From 06bb87256b6ab2bb197615bfe88c4079f1e3de3a Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 14:35:31 +1000 Subject: [PATCH 12/37] Add worker health checks and upgrades. --- source/Octopus.Client/Model/BuiltInTasks.cs | 33 +++++++++++++++++++ .../Repositories/Async/TaskRepository.cs | 26 +++++++++------ .../Repositories/TaskRepository.cs | 19 +++++++---- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/source/Octopus.Client/Model/BuiltInTasks.cs b/source/Octopus.Client/Model/BuiltInTasks.cs index a3a167398..cd52e2c72 100644 --- a/source/Octopus.Client/Model/BuiltInTasks.cs +++ b/source/Octopus.Client/Model/BuiltInTasks.cs @@ -39,14 +39,35 @@ public static class Arguments } } + public static class TaskRestrictedTo + { + public static readonly string Environment = "Environment"; + public static readonly string WorkerPool = "WorkerPool"; + public static readonly string Policy = "Policy"; + public static readonly string Unrestricted = "Unlimited"; + } + public static class Health { public const string Name = "Health"; + public static string[] CanBeRestrictedTo() + { + return new string[] + { + TaskRestrictedTo.Environment, + TaskRestrictedTo.WorkerPool, + TaskRestrictedTo.Policy, + TaskRestrictedTo.Unrestricted + }; + } + public static class Arguments { public static string EnvironmentId = "EnvironmentId"; + public static string WorkerpoolId = "WorkerpoolId"; public static string MachineIds = "MachineIds"; + public static string RestrictedTo = "RestrictedTo"; public static string Timeout = "Timeout"; public static string MachineTimeout = "MachineTimeout"; } @@ -92,10 +113,22 @@ public static class Upgrade { public const string Name = "Upgrade"; + public static string[] CanBeRestrictedTo() + { + return new string[] + { + TaskRestrictedTo.Environment, + TaskRestrictedTo.WorkerPool, + TaskRestrictedTo.Unrestricted + }; + } + public static class Arguments { public static string EnvironmentId = "EnvironmentId"; + public static string WorkerpoolId = "WorkerpoolId"; public static string MachineIds = "MachineIds"; + public static string RestrictedTo = "RestrictedTo"; } } diff --git a/source/Octopus.Client/Repositories/Async/TaskRepository.cs b/source/Octopus.Client/Repositories/Async/TaskRepository.cs index 2b8a14aa3..ec0e168a1 100644 --- a/source/Octopus.Client/Repositories/Async/TaskRepository.cs +++ b/source/Octopus.Client/Repositories/Async/TaskRepository.cs @@ -10,10 +10,10 @@ namespace Octopus.Client.Repositories.Async { public interface ITaskRepository : IPaginate, IGet, ICreate { - Task ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null); + Task ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null); Task ExecuteCalamariUpdate(string description = null, string[] machineIds = null); Task ExecuteBackup(string description = null); - Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null); + Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpooltId = null, string[] workermachineIds = null); Task ExecuteAdHocScript(string scriptBody, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null, string syntax = "PowerShell"); Task GetDetails(TaskResource resource); Task ExecuteActionTemplate(ActionTemplateResource resource, Dictionary properties, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null); @@ -37,7 +37,9 @@ public TaskRepository(IOctopusAsyncClient client) { } - public Task ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null) + public Task ExecuteHealthCheck( + string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, + string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null) { var resource = new TaskResource(); resource.Name = BuiltInTasks.Health.Name; @@ -47,7 +49,9 @@ public Task ExecuteHealthCheck(string description = null, int time {BuiltInTasks.Health.Arguments.Timeout, TimeSpan.FromMinutes(timeoutAfterMinutes)}, {BuiltInTasks.Health.Arguments.MachineTimeout, TimeSpan.FromMinutes(machineTimeoutAfterMinutes)}, {BuiltInTasks.Health.Arguments.EnvironmentId, environmentId}, - {BuiltInTasks.Health.Arguments.MachineIds, machineIds} + {BuiltInTasks.Health.Arguments.WorkerpoolId, workerpoolId}, + {BuiltInTasks.Health.Arguments.RestrictedTo, restrictTo}, + {BuiltInTasks.Health.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} }; return Create(resource); } @@ -72,7 +76,7 @@ public Task ExecuteBackup(string description = null) return Create(resource); } - public Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null) + public Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null) { var resource = new TaskResource(); resource.Name = BuiltInTasks.Upgrade.Name; @@ -80,7 +84,9 @@ public Task ExecuteTentacleUpgrade(string description = null, stri resource.Arguments = new Dictionary { {BuiltInTasks.Upgrade.Arguments.EnvironmentId, environmentId}, - {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds} + {BuiltInTasks.Upgrade.Arguments.WorkerpoolId, workerpoolId}, + {BuiltInTasks.Upgrade.Arguments.RestrictedTo, restrictTo}, + {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} }; return Create(resource); } @@ -143,7 +149,7 @@ public Task Rerun(TaskResource resource) { return Client.Post(resource.Link("Rerun"), (TaskResource)null); } - + public Task Cancel(TaskResource resource) { return Client.Post(resource.Link("Cancel"), (TaskResource)null); @@ -173,11 +179,11 @@ public Task WaitForCompletion(TaskResource[] tasks, int pollIntervalSeconds = 4, return WaitForCompletion(tasks, pollIntervalSeconds, timeoutAfterMinutes, taskInterval); } - public Task WaitForCompletion(TaskResource[] tasks, int pollIntervalSeconds = 4, int timeoutAfterMinutes = 0, Func interval = null) + public Task WaitForCompletion(TaskResource[] tasks, int pollIntervalSeconds = 4, int timeoutAfterMinutes = 0, Func interval = null) => WaitForCompletion(tasks, pollIntervalSeconds, TimeSpan.FromMinutes(timeoutAfterMinutes), interval); public async Task WaitForCompletion(TaskResource[] tasks, int pollIntervalSeconds = 4, TimeSpan? timeoutAfter = null, Func interval = null) - { + { var start = Stopwatch.StartNew(); if (tasks == null || tasks.Length == 0) return; @@ -205,7 +211,7 @@ public async Task WaitForCompletion(TaskResource[] tasks, int pollIntervalSecond } /// - /// + /// /// /// Number of items per page, setting to less than the total items still retreives all items, but uses multiple requests reducing memory load on the server /// diff --git a/source/Octopus.Client/Repositories/TaskRepository.cs b/source/Octopus.Client/Repositories/TaskRepository.cs index d632ccf0f..81017e24b 100644 --- a/source/Octopus.Client/Repositories/TaskRepository.cs +++ b/source/Octopus.Client/Repositories/TaskRepository.cs @@ -9,10 +9,10 @@ namespace Octopus.Client.Repositories { public interface ITaskRepository : IPaginate, IGet, ICreate { - TaskResource ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null); + TaskResource ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null); TaskResource ExecuteCalamariUpdate(string description = null, string[] machineIds = null); TaskResource ExecuteBackup(string description = null); - TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null); + TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null); TaskResource ExecuteAdHocScript(string scriptBody, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null, string syntax = "PowerShell"); TaskResource ExecuteActionTemplate(ActionTemplateResource resource, Dictionary properties, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null); TaskResource ExecuteCommunityActionTemplatesSynchronisation(string description = null); @@ -35,7 +35,10 @@ public TaskRepository(IOctopusClient client) { } - public TaskResource ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null) + public TaskResource ExecuteHealthCheck( + string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, + string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null + ) { var resource = new TaskResource(); resource.Name = BuiltInTasks.Health.Name; @@ -45,7 +48,9 @@ public TaskResource ExecuteHealthCheck(string description = null, int timeoutAft {BuiltInTasks.Health.Arguments.Timeout, TimeSpan.FromMinutes(timeoutAfterMinutes)}, {BuiltInTasks.Health.Arguments.MachineTimeout, TimeSpan.FromMinutes(machineTimeoutAfterMinutes)}, {BuiltInTasks.Health.Arguments.EnvironmentId, environmentId}, - {BuiltInTasks.Health.Arguments.MachineIds, machineIds} + {BuiltInTasks.Health.Arguments.WorkerpoolId, workerpoolId}, + {BuiltInTasks.Health.Arguments.RestrictedTo, restrictTo}, + {BuiltInTasks.Health.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} }; return Create(resource); } @@ -70,7 +75,7 @@ public TaskResource ExecuteBackup(string description = null) return Create(resource); } - public TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null) + public TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null) { var resource = new TaskResource(); resource.Name = BuiltInTasks.Upgrade.Name; @@ -78,7 +83,9 @@ public TaskResource ExecuteTentacleUpgrade(string description = null, string env resource.Arguments = new Dictionary { {BuiltInTasks.Upgrade.Arguments.EnvironmentId, environmentId}, - {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds} + {BuiltInTasks.Upgrade.Arguments.WorkerpoolId, workerpoolId}, + {BuiltInTasks.Upgrade.Arguments.RestrictedTo, restrictTo}, + {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} }; return Create(resource); } From cc15438bf9a1be462edcc4824b80bc8e6b464529 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 6 Apr 2018 14:55:49 +1000 Subject: [PATCH 13/37] Update public surface area --- ...AreaShouldNotRegress..NETCore.approved.txt | 34 ++++++++++++++++- ...houldNotRegress..NETFramework.approved.txt | 38 +++++++++++++++++-- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 1f1725df9..dcb3b837f 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -889,7 +889,9 @@ Octopus.Client.Model static System.String EnvironmentId static System.String MachineIds static System.String MachineTimeout + static System.String RestrictedTo static System.String Timeout + static System.String WorkerpoolId } abstract class Arguments { @@ -905,6 +907,8 @@ Octopus.Client.Model { static System.String EnvironmentId static System.String MachineIds + static System.String RestrictedTo + static System.String WorkerpoolId } abstract class Arguments { @@ -1055,12 +1059,15 @@ Octopus.Client.Model abstract class Health { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds static System.String MachineTimeout + static System.String RestrictedTo static System.String Timeout + static System.String WorkerpoolId } } abstract class Migration @@ -1087,6 +1094,13 @@ Octopus.Client.Model { static System.String Name } + abstract class TaskRestrictedTo + { + static System.String Environment + static System.String Policy + static System.String Unrestricted + static System.String WorkerPool + } abstract class TestAzureAccount { static System.String Name @@ -1114,10 +1128,13 @@ Octopus.Client.Model abstract class Upgrade { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds + static System.String RestrictedTo + static System.String WorkerpoolId } } } @@ -1785,12 +1802,15 @@ Octopus.Client.Model abstract class Health { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds static System.String MachineTimeout + static System.String RestrictedTo static System.String Timeout + static System.String WorkerpoolId } } HealthCheckErrorHandling @@ -3072,6 +3092,13 @@ Octopus.Client.Model Nullable StartTime { get; set; } Octopus.Client.Model.TaskState State { get; set; } } + abstract class TaskRestrictedTo + { + static System.String Environment + static System.String Policy + static System.String Unrestricted + static System.String WorkerPool + } TaskState { Queued = 1 @@ -3211,10 +3238,13 @@ Octopus.Client.Model abstract class Upgrade { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds + static System.String RestrictedTo + static System.String WorkerpoolId } } class UserPermissionRestriction @@ -4356,8 +4386,8 @@ Octopus.Client.Repositories.Async Task ExecuteBackup(String) Task ExecuteCalamariUpdate(String, String[]) Task ExecuteCommunityActionTemplatesSynchronisation(String) - Task ExecuteHealthCheck(String, Int32, Int32, String, String[]) - Task ExecuteTentacleUpgrade(String, String, String[]) + Task ExecuteHealthCheck(String, Int32, Int32, String, String[], String, String, String[]) + Task ExecuteTentacleUpgrade(String, String, String[], String, String, String[]) Task> GetAllActive(Int32) Task GetDetails(Octopus.Client.Model.TaskResource) Task> GetQueuedBehindTasks(Octopus.Client.Model.TaskResource) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 61f2aa84e..9367e168a 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -1318,7 +1318,9 @@ Octopus.Client.Model static System.String EnvironmentId static System.String MachineIds static System.String MachineTimeout + static System.String RestrictedTo static System.String Timeout + static System.String WorkerpoolId } abstract class Arguments { @@ -1334,6 +1336,8 @@ Octopus.Client.Model { static System.String EnvironmentId static System.String MachineIds + static System.String RestrictedTo + static System.String WorkerpoolId } abstract class Arguments { @@ -1484,12 +1488,15 @@ Octopus.Client.Model abstract class Health { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds static System.String MachineTimeout + static System.String RestrictedTo static System.String Timeout + static System.String WorkerpoolId } } abstract class Migration @@ -1516,6 +1523,13 @@ Octopus.Client.Model { static System.String Name } + abstract class TaskRestrictedTo + { + static System.String Environment + static System.String Policy + static System.String Unrestricted + static System.String WorkerPool + } abstract class TestAzureAccount { static System.String Name @@ -1543,10 +1557,13 @@ Octopus.Client.Model abstract class Upgrade { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds + static System.String RestrictedTo + static System.String WorkerpoolId } } } @@ -2214,12 +2231,15 @@ Octopus.Client.Model abstract class Health { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds static System.String MachineTimeout + static System.String RestrictedTo static System.String Timeout + static System.String WorkerpoolId } } HealthCheckErrorHandling @@ -3507,6 +3527,13 @@ Octopus.Client.Model Nullable StartTime { get; set; } Octopus.Client.Model.TaskState State { get; set; } } + abstract class TaskRestrictedTo + { + static System.String Environment + static System.String Policy + static System.String Unrestricted + static System.String WorkerPool + } TaskState { Queued = 1 @@ -3648,10 +3675,13 @@ Octopus.Client.Model abstract class Upgrade { static System.String Name + static String[] CanBeRestrictedTo() abstract class Arguments { static System.String EnvironmentId static System.String MachineIds + static System.String RestrictedTo + static System.String WorkerpoolId } } class UserPermissionRestriction @@ -4800,8 +4830,8 @@ Octopus.Client.Repositories Octopus.Client.Model.TaskResource ExecuteBackup(String) Octopus.Client.Model.TaskResource ExecuteCalamariUpdate(String, String[]) Octopus.Client.Model.TaskResource ExecuteCommunityActionTemplatesSynchronisation(String) - Octopus.Client.Model.TaskResource ExecuteHealthCheck(String, Int32, Int32, String, String[]) - Octopus.Client.Model.TaskResource ExecuteTentacleUpgrade(String, String, String[]) + Octopus.Client.Model.TaskResource ExecuteHealthCheck(String, Int32, Int32, String, String[], String, String, String[]) + Octopus.Client.Model.TaskResource ExecuteTentacleUpgrade(String, String, String[], String, String, String[]) List GetAllActive(Int32) Octopus.Client.Model.TaskDetailsResource GetDetails(Octopus.Client.Model.TaskResource) IReadOnlyList GetQueuedBehindTasks(Octopus.Client.Model.TaskResource) @@ -5294,8 +5324,8 @@ Octopus.Client.Repositories.Async Task ExecuteBackup(String) Task ExecuteCalamariUpdate(String, String[]) Task ExecuteCommunityActionTemplatesSynchronisation(String) - Task ExecuteHealthCheck(String, Int32, Int32, String, String[]) - Task ExecuteTentacleUpgrade(String, String, String[]) + Task ExecuteHealthCheck(String, Int32, Int32, String, String[], String, String, String[]) + Task ExecuteTentacleUpgrade(String, String, String[], String, String, String[]) Task> GetAllActive(Int32) Task GetDetails(Octopus.Client.Model.TaskResource) Task> GetQueuedBehindTasks(Octopus.Client.Model.TaskResource) From 44c695c75cf28a21570dc00b1bd6eb9a6ca0e248 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 20 Apr 2018 16:17:00 +1000 Subject: [PATCH 14/37] fix public surface area --- ...re.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 1 + ...ePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 1f1725df9..3185be3d3 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -1419,6 +1419,7 @@ Octopus.Client.Model String Name { get; set; } IDictionary Properties { get; } Octopus.Client.Model.ReferenceCollection TenantTags { get; } + String WorkerPoolId { get; set; } Octopus.Client.Model.DeploymentActionResource ClearAllConditions() Octopus.Client.Model.DeploymentActionResource ForChannels(Octopus.Client.Model.ChannelResource[]) Octopus.Client.Model.DeploymentActionResource ForEnvironments(Octopus.Client.Model.EnvironmentResource[]) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 61f2aa84e..5da3d24bd 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -1848,6 +1848,7 @@ Octopus.Client.Model String Name { get; set; } IDictionary Properties { get; } Octopus.Client.Model.ReferenceCollection TenantTags { get; } + String WorkerPoolId { get; set; } Octopus.Client.Model.DeploymentActionResource ClearAllConditions() Octopus.Client.Model.DeploymentActionResource ForChannels(Octopus.Client.Model.ChannelResource[]) Octopus.Client.Model.DeploymentActionResource ForEnvironments(Octopus.Client.Model.EnvironmentResource[]) From 52261d440b2eb918861c0e35ec510a35dcb3d0db Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 7 May 2018 08:09:51 +1000 Subject: [PATCH 15/37] Touch up capitalisation. --- .../Commands/WorkerPool/CleanWorkerPoolCommand.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs index eb4e9f2e1..9b21afd87 100644 --- a/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs +++ b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs @@ -20,7 +20,7 @@ public class CleanWorkerPoolCommand : ApiCommand, ISupportFormattedOutput private bool? isDisabled; private bool? isCalamariOutdated; private bool? isTentacleOutdated; - WorkerPoolResource workerpoolResource; + WorkerPoolResource workerPoolResource; IEnumerable machines; List commandResults = new List(); @@ -44,12 +44,12 @@ public async Task Request() if (!healthStatuses.Any() && !statuses.Any()) throw new CommandException("Please specify a status using the parameter: --health-status"); - workerpoolResource = await GetWorkerPool().ConfigureAwait(false); + workerPoolResource = await GetWorkerPool().ConfigureAwait(false); - machines = await FilterByWorkerPool(workerpoolResource).ConfigureAwait(false); + machines = await FilterByWorkerPool(workerPoolResource).ConfigureAwait(false); machines = FilterByState(machines); - await CleanUpPool(machines.ToList(), workerpoolResource); + await CleanUpPool(machines.ToList(), workerPoolResource); } private async Task CleanUpPool(List filteredMachines, WorkerPoolResource poolResource) @@ -156,7 +156,7 @@ public void PrintJsonOutput() commandOutputProvider.Json(commandResults.Select(x =>new { Machine = new { x.Machine.Id,x.Machine.Name, x.Machine.Status }, - Environment = x.Action == MachineAction.RemovedFromPool ? new { workerpoolResource.Id, workerpoolResource.Name } : null, + Environment = x.Action == MachineAction.RemovedFromPool ? new { workerPoolResource.Id, workerPoolResource.Name } : null, Action = x.Action.ToString() })); } From 5bd8697c130c0464d5320264b9754e67ecdcccfb Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 7 May 2018 08:15:30 +1000 Subject: [PATCH 16/37] Don't use obsolete MachineModeStatus --- .../Commands/WorkerPool/CleanWorkerPoolCommand.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs index 9b21afd87..86d13687c 100644 --- a/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs +++ b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs @@ -15,7 +15,6 @@ namespace Octopus.Cli.Commands.WorkerPools public class CleanWorkerPoolCommand : ApiCommand, ISupportFormattedOutput { string poolName; - readonly HashSet statuses = new HashSet(StringComparer.OrdinalIgnoreCase); readonly HashSet healthStatuses = new HashSet(StringComparer.OrdinalIgnoreCase); private bool? isDisabled; private bool? isCalamariOutdated; @@ -30,7 +29,6 @@ public CleanWorkerPoolCommand(IOctopusAsyncRepositoryFactory repositoryFactory, { var options = Options.For("WorkerPool Cleanup"); options.Add("workerpool=", "Name of a worker pool to clean up.", v => poolName = v); - options.Add("status=", $"Status of Worker Machines to clean up ({string.Join(", ", HealthStatusProvider.StatusNames)}). Can be specified many times.", v => statuses.Add(v)); options.Add("health-status=", $"Health status of Worker Machines to clean up ({string.Join(", ", HealthStatusProvider.HealthStatusNames)}). Can be specified many times.", v => healthStatuses.Add(v)); options.Add("disabled=", "[Optional] Disabled status filter of Worker Machine to clean up.", v => SetFlagState(v, ref isDisabled)); options.Add("calamari-outdated=", "[Optional] State of Calamari to clean up. By default ignores Calamari state.", v => SetFlagState(v, ref isCalamariOutdated)); @@ -41,7 +39,7 @@ 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() && !statuses.Any()) + if (!healthStatuses.Any()) throw new CommandException("Please specify a status using the parameter: --health-status"); workerPoolResource = await GetWorkerPool().ConfigureAwait(false); @@ -89,7 +87,7 @@ private async Task CleanUpPool(List filteredMachines, Wor private IEnumerable FilterByState(IEnumerable workerMachines) { - var provider = new HealthStatusProvider(Repository, statuses, healthStatuses, commandOutputProvider); + var provider = new HealthStatusProvider(Repository, new HashSet(StringComparer.OrdinalIgnoreCase), healthStatuses, commandOutputProvider); workerMachines = provider.Filter(workerMachines); if (isDisabled.HasValue) @@ -109,7 +107,7 @@ private IEnumerable FilterByState(IEnumerable Date: Thu, 10 May 2018 16:57:08 +1000 Subject: [PATCH 17/37] Update clean worker pool fixture --- .../Commands/CleanWorkerPoolCommandFixture.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs index 4abafe3e7..79a67fe20 100644 --- a/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs +++ b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs @@ -19,6 +19,7 @@ public class CleanWorkerPoolCommandFixture : ApiCommandFixtureBase public void SetUp() { cleanPoolCommand = new CleanWorkerPoolCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); + Repository.Client.RootDocument.Version = "2018.6.0"; } CleanWorkerPoolCommand cleanPoolCommand; @@ -27,7 +28,7 @@ public void SetUp() public void ShouldCleanPool() { CommandLineArgs.Add("-workerpool=SomePool"); - CommandLineArgs.Add("-status=Offline"); + CommandLineArgs.Add("-health-status=Unhealthy"); Repository.WorkerPools.FindByName("SomePool").Returns( new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} @@ -44,7 +45,7 @@ public void ShouldCleanPool() cleanPoolCommand.Execute(CommandLineArgs.ToArray()).GetAwaiter().GetResult(); - LogLines.Should().Contain(string.Format("Found {0} machines in {1} with the status {2}", workerList.Count, "SomePool", MachineModelStatus.Offline.ToString())); + LogLines.Should().Contain(string.Format("Found {0} machines in {1} with the status {2}", workerList.Count, "SomePool", MachineModelHealthStatus.Unhealthy.ToString())); LogLines.Should().Contain(string.Format("Deleting {0} {1} (ID: {2})", workerList[0].Name, workerList[0].Status, workerList[0].Id)); Repository.WorkerMachines.Received().Delete(workerList[0]); @@ -57,7 +58,7 @@ public void ShouldCleanPool() public void ShouldRemoveMachinesBelongingToMultiplePoolsInsteadOfDeleting() { CommandLineArgs.Add("-workerpool=SomePool"); - CommandLineArgs.Add("-status=Offline"); + CommandLineArgs.Add("-health-status=Unhealthy"); Repository.WorkerPools.FindByName("SomePool").Returns( new WorkerPoolResource { Name = "SomePool", Id = "WorkerPools-001"} @@ -74,7 +75,7 @@ public void ShouldRemoveMachinesBelongingToMultiplePoolsInsteadOfDeleting() cleanPoolCommand.Execute(CommandLineArgs.ToArray()).GetAwaiter().GetResult(); - LogLines.Should().Contain(string.Format("Found {0} machines in {1} with the status {2}", workerList.Count, "SomePool", MachineModelStatus.Offline.ToString())); + LogLines.Should().Contain(string.Format("Found {0} machines in {1} with the status {2}", workerList.Count, "SomePool", MachineModelHealthStatus.Unhealthy.ToString())); LogLines.Should().Contain("Note: Some of these machines belong to multiple pools. Instead of being deleted, these machines will be removed from the SomePool pool."); LogLines.Should().Contain($"Removing {workerList[0].Name} {workerList[0].Status} (ID: {workerList[0].Id}) from SomePool"); @@ -106,7 +107,7 @@ public void ShouldNotCleanPoolWithMissingStatusArgs() public void ShouldNotCleanIfPoolNotFound() { CommandLineArgs.Add("-workerpool=SomePool"); - CommandLineArgs.Add("-status=Offline"); + CommandLineArgs.Add("-health-status=Unhealthy"); Func exec = () => cleanPoolCommand.Execute(CommandLineArgs.ToArray()); exec.ShouldThrow() @@ -122,7 +123,7 @@ public async Task JsonOutput_ShouldBeWellFormed() CommandLineArgs.Add("--outputFormat=json"); CommandLineArgs.Add($"--workerpool=SomePool"); - CommandLineArgs.Add("-status=Offline"); + CommandLineArgs.Add("-health-status=Unhealthy"); var workerList = MakeWorkerMachineList(2, new List @@ -159,7 +160,7 @@ private List MakeWorkerMachineList(int numWorkers, List Date: Fri, 11 May 2018 13:45:28 +1000 Subject: [PATCH 18/37] Missed TenantedDeploymentMode in merge --- .../Operations/IRegisterMachineOperation.cs | 7 +++++++ .../Octopus.Client/Operations/RegisterMachineOperation.cs | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs index f0271c632..98333b71e 100644 --- a/source/Octopus.Client/Operations/IRegisterMachineOperation.cs +++ b/source/Octopus.Client/Operations/IRegisterMachineOperation.cs @@ -28,5 +28,12 @@ public interface IRegisterMachineOperation : IRegisterMachineOperationBase /// Gets or sets the tenant tags that this machine is linked to. /// string[] TenantTags { get; set; } + + /// + /// How the machine should participate in Tenanted Deployments. + /// Allowed values are Untenanted, TenantedOrUntenanted or Tenanted + /// + TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } + } } \ No newline at end of file diff --git a/source/Octopus.Client/Operations/RegisterMachineOperation.cs b/source/Octopus.Client/Operations/RegisterMachineOperation.cs index 9a2fd129b..313ca2893 100644 --- a/source/Octopus.Client/Operations/RegisterMachineOperation.cs +++ b/source/Octopus.Client/Operations/RegisterMachineOperation.cs @@ -50,6 +50,13 @@ public RegisterMachineOperation(IOctopusClientFactory clientFactory) : base(clie /// public string[] TenantTags { get; set; } + + /// + /// How the machine should participate in Tenanted Deployments. + /// Allowed values are Untenanted, TenantedOrUntenanted or Tenanted + /// + public TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } + #if SYNC_CLIENT /// @@ -237,6 +244,7 @@ void ApplyDeploymentTargetChanges(MachineResource machine, IEnumerable t.Id).ToArray()); machine.TenantTags = new ReferenceCollection(TenantTags); machine.Roles = new ReferenceCollection(Roles); + machine.TenantedDeploymentParticipation = TenantedDeploymentParticipation; } } } \ No newline at end of file From a9a162101f3f822a6fa0f105ddacfeeb96c22904 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 11 May 2018 14:12:28 +1000 Subject: [PATCH 19/37] Bump Assent version --- source/Octopus.Client.Tests/Octopus.Client.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octopus.Client.Tests/Octopus.Client.Tests.csproj b/source/Octopus.Client.Tests/Octopus.Client.Tests.csproj index af54be30b..957befcec 100644 --- a/source/Octopus.Client.Tests/Octopus.Client.Tests.csproj +++ b/source/Octopus.Client.Tests/Octopus.Client.Tests.csproj @@ -32,7 +32,7 @@ - + From c1e216f70269d483f95d407acf548eab9d5d1204 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 11 May 2018 14:13:13 +1000 Subject: [PATCH 20/37] Fix public surface area --- ...e.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 2 ++ ...PublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index cd56a6da2..17d55f7eb 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -4298,6 +4298,7 @@ Octopus.Client.Operations { String[] EnvironmentNames { get; set; } String[] Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } String[] Tenants { get; set; } String[] TenantTags { get; set; } } @@ -4330,6 +4331,7 @@ Octopus.Client.Operations .ctor(Octopus.Client.IOctopusClientFactory) String[] EnvironmentNames { get; set; } String[] Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } String[] Tenants { get; set; } String[] TenantTags { get; set; } Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index b0210c0f7..2470d7ccb 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -4809,6 +4809,7 @@ Octopus.Client.Operations { String[] EnvironmentNames { get; set; } String[] Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } String[] Tenants { get; set; } String[] TenantTags { get; set; } } @@ -4844,6 +4845,7 @@ Octopus.Client.Operations .ctor(Octopus.Client.IOctopusClientFactory) String[] EnvironmentNames { get; set; } String[] Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } String[] Tenants { get; set; } String[] TenantTags { get; set; } void Execute(Octopus.Client.IOctopusRepository) From d200dc739e289e0c538e7c082f1366595080e1e4 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 11 May 2018 16:31:56 +1000 Subject: [PATCH 21/37] move deployment target fluent functions to extensions --- ...AreaShouldNotRegress..NETCore.approved.txt | 27 +++-- ...houldNotRegress..NETFramework.approved.txt | 27 +++-- .../DeploymentTargetResourceExtensions.cs | 108 ++++++++++++++++++ .../Model/DeploymentTargetResource.cs | 84 -------------- 4 files changed, 138 insertions(+), 108 deletions(-) create mode 100644 source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 17d55f7eb..60cfd2b09 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -717,6 +717,21 @@ Octopus.Client.Extensibility.Extensions.Infrastructure.Configuration } Octopus.Client.Extensions { + abstract class DeploymentTargetResourceExtensions + { + static Octopus.Client.Extensions.T AddOrUpdateEnvironments(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource[]) + static Octopus.Client.Extensions.T AddOrUpdateRoles(Octopus.Client.Extensions.T, String[]) + static Octopus.Client.Extensions.T AddOrUpdateTenants(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource[]) + static Octopus.Client.Extensions.T AddOrUpdateTenantTags(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource[]) + static Octopus.Client.Extensions.T ClearEnvironments(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T ClearRoles(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T ClearTenants(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T ClearTenantTags(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T RemoveEnvironment(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource) + static Octopus.Client.Extensions.T RemoveRole(Octopus.Client.Extensions.T, String) + static Octopus.Client.Extensions.T RemoveTenant(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource) + static Octopus.Client.Extensions.T RemoveTenantTag(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource) + } abstract class StringExtensions { static String CommaSeperate(IEnumerable) @@ -1678,18 +1693,6 @@ Octopus.Client.Model Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) - Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() - Octopus.Client.Model.DeploymentTargetResource ClearRoles() - Octopus.Client.Model.DeploymentTargetResource ClearTenants() - Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() - Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) - Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) - Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) - Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 2470d7ccb..0803675f5 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -1218,6 +1218,21 @@ Octopus.Client.Extensibility.Extensions.Infrastructure.Configuration } Octopus.Client.Extensions { + abstract class DeploymentTargetResourceExtensions + { + static Octopus.Client.Extensions.T AddOrUpdateEnvironments(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource[]) + static Octopus.Client.Extensions.T AddOrUpdateRoles(Octopus.Client.Extensions.T, String[]) + static Octopus.Client.Extensions.T AddOrUpdateTenants(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource[]) + static Octopus.Client.Extensions.T AddOrUpdateTenantTags(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource[]) + static Octopus.Client.Extensions.T ClearEnvironments(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T ClearRoles(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T ClearTenants(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T ClearTenantTags(Octopus.Client.Extensions.T) + static Octopus.Client.Extensions.T RemoveEnvironment(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource) + static Octopus.Client.Extensions.T RemoveRole(Octopus.Client.Extensions.T, String) + static Octopus.Client.Extensions.T RemoveTenant(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource) + static Octopus.Client.Extensions.T RemoveTenantTag(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource) + } abstract class StringExtensions { static String CommaSeperate(IEnumerable) @@ -2180,18 +2195,6 @@ Octopus.Client.Model Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) - Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() - Octopus.Client.Model.DeploymentTargetResource ClearRoles() - Octopus.Client.Model.DeploymentTargetResource ClearTenants() - Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() - Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) - Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) - Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) - Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource diff --git a/source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs b/source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs new file mode 100644 index 000000000..7cb5e0f3e --- /dev/null +++ b/source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Octopus.Client.Model; + +namespace Octopus.Client.Extensions +{ + public static class DeploymentTargetResourceExtensions + { + public static T AddOrUpdateEnvironments(this T deploymentTarget, params EnvironmentResource[] environments) + where T : DeploymentTargetResource + { + foreach (var environment in environments) + { + deploymentTarget.EnvironmentIds.Add(environment.Id); + } + return deploymentTarget; + } + + public static T RemoveEnvironment(this T deploymentTarget, EnvironmentResource environment) + where T : DeploymentTargetResource + { + deploymentTarget.EnvironmentIds.Remove(environment.Id); + return deploymentTarget; + } + + public static T ClearEnvironments(this T deploymentTarget) + where T : DeploymentTargetResource + { + deploymentTarget.EnvironmentIds.Clear(); + return deploymentTarget; + } + + public static T AddOrUpdateRoles(this T deploymentTarget, params string[] roles) + where T : DeploymentTargetResource + { + foreach (var role in roles) + { + deploymentTarget.Roles.Add(role); + } + return deploymentTarget; + } + + public static T RemoveRole(this T deploymentTarget, string role) + where T : DeploymentTargetResource + { + deploymentTarget.Roles.Remove(role); + return deploymentTarget; + } + + public static T ClearRoles(this T deploymentTarget) + where T : DeploymentTargetResource + { + deploymentTarget.Roles.Clear(); + return deploymentTarget; + } + + public static T AddOrUpdateTenants(this T deploymentTarget, params TenantResource[] tenants) + where T : DeploymentTargetResource + { + foreach (var tenant in tenants) + { + deploymentTarget.TenantIds.Add(tenant.Id); + } + return deploymentTarget; + } + + public static T RemoveTenant(this T deploymentTarget, TenantResource tenant) + where T : DeploymentTargetResource + { + deploymentTarget.TenantIds.Remove(tenant.Id); + return deploymentTarget; + } + + public static T ClearTenants(this T deploymentTarget) + where T : DeploymentTargetResource + { + deploymentTarget.TenantIds.Clear(); + return deploymentTarget; + } + + public static T AddOrUpdateTenantTags(this T deploymentTarget, params TagResource[] tenantTags) + where T : DeploymentTargetResource + { + foreach (var tenantTag in tenantTags) + { + deploymentTarget.TenantTags.Add(tenantTag.CanonicalTagName); + } + return deploymentTarget; + } + + public static T RemoveTenantTag(this T deploymentTarget, TagResource tenantTag) + where T : DeploymentTargetResource + { + deploymentTarget.TenantTags.Remove(tenantTag.CanonicalTagName); + return deploymentTarget; + } + + public static T ClearTenantTags(this T deploymentTarget) + where T : DeploymentTargetResource + { + deploymentTarget.TenantTags.Clear(); + return deploymentTarget; + } + } +} diff --git a/source/Octopus.Client/Model/DeploymentTargetResource.cs b/source/Octopus.Client/Model/DeploymentTargetResource.cs index 9d1505ed2..f1ec647c9 100644 --- a/source/Octopus.Client/Model/DeploymentTargetResource.cs +++ b/source/Octopus.Client/Model/DeploymentTargetResource.cs @@ -45,89 +45,5 @@ public TenantedDeploymentMode TenantedDeploymentParticipation [Writeable] public ReferenceCollection TenantTags { get; set; } - - public DeploymentTargetResource AddOrUpdateEnvironments(params EnvironmentResource[] environments) - { - foreach (var environment in environments) - { - EnvironmentIds.Add(environment.Id); - } - return this; - } - - public DeploymentTargetResource RemoveEnvironment(EnvironmentResource environment) - { - EnvironmentIds.Remove(environment.Id); - return this; - } - - public DeploymentTargetResource ClearEnvironments() - { - EnvironmentIds.Clear(); - return this; - } - - public DeploymentTargetResource AddOrUpdateRoles(params string[] roles) - { - foreach (var role in roles) - { - Roles.Add(role); - } - return this; - } - - public DeploymentTargetResource RemoveRole(string role) - { - Roles.Remove(role); - return this; - } - - public DeploymentTargetResource ClearRoles() - { - Roles.Clear(); - return this; - } - - public DeploymentTargetResource AddOrUpdateTenants(params TenantResource[] tenants) - { - foreach (var tenant in tenants) - { - TenantIds.Add(tenant.Id); - } - return this; - } - - public DeploymentTargetResource RemoveTenant(TenantResource tenant) - { - TenantIds.Remove(tenant.Id); - return this; - } - - public DeploymentTargetResource ClearTenants() - { - TenantIds.Clear(); - return this; - } - - public DeploymentTargetResource AddOrUpdateTenantTags(params TagResource[] tenantTags) - { - foreach (var tenantTag in tenantTags) - { - TenantTags.Add(tenantTag.CanonicalTagName); - } - return this; - } - - public DeploymentTargetResource RemoveTenantTag(TagResource tenantTag) - { - TenantTags.Remove(tenantTag.CanonicalTagName); - return this; - } - - public DeploymentTargetResource ClearTenantTags() - { - TenantTags.Clear(); - return this; - } } } \ No newline at end of file From 0c0b09023138a760142fefb70fe95a79375d1eba Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 21 May 2018 19:45:33 +1000 Subject: [PATCH 22/37] Add default option for worker pools --- source/Octopus.Client/Model/WorkerPoolResource.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/Octopus.Client/Model/WorkerPoolResource.cs b/source/Octopus.Client/Model/WorkerPoolResource.cs index ca32aafba..48224ed2c 100644 --- a/source/Octopus.Client/Model/WorkerPoolResource.cs +++ b/source/Octopus.Client/Model/WorkerPoolResource.cs @@ -24,6 +24,12 @@ public class WorkerPoolResource : Resource, INamedResource [Trim] public string Description { get; set; } + /// + /// Is this the default pool. The default pool is used for steps that don't specify a worker pool. + /// The default pool, if empty, uses the builtin worker to run steps. + /// + public bool IsDefault { get; set; } + /// /// Gets or sets a number indicating the priority of this pool in sort order. WorkerPools with /// a lower sort order will appear in the UI before items with a higher sort order. From 7f7723b9edf9156cb6e76a53b7f961e81fa1fc54 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 21 May 2018 20:07:06 +1000 Subject: [PATCH 23/37] update public surface area --- ...re.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 1 + ...ePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 60cfd2b09..c11f51c0e 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -3524,6 +3524,7 @@ Octopus.Client.Model { .ctor() String Description { get; set; } + Boolean IsDefault { get; set; } String Name { get; set; } Int32 SortOrder { get; set; } } diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 0803675f5..bf3792557 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -4034,6 +4034,7 @@ Octopus.Client.Model { .ctor() String Description { get; set; } + Boolean IsDefault { get; set; } String Name { get; set; } Int32 SortOrder { get; set; } } From 43659bb840920bdd7344d53c4bc31723692ed1ae Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Wed, 23 May 2018 08:37:40 +1000 Subject: [PATCH 24/37] Add feature switch for built-in worker --- source/Octopus.Client/Model/FeaturesConfigurationResource.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/Octopus.Client/Model/FeaturesConfigurationResource.cs b/source/Octopus.Client/Model/FeaturesConfigurationResource.cs index 4ac9bca15..fffa8442a 100644 --- a/source/Octopus.Client/Model/FeaturesConfigurationResource.cs +++ b/source/Octopus.Client/Model/FeaturesConfigurationResource.cs @@ -7,6 +7,9 @@ public class FeaturesConfigurationResource : Resource [Writeable] public bool IsMultiTenancyEnabled { get; set; } + [Writeable] + public bool IsBuiltinWorkerEnabled { get; set; } + [Writeable] public bool IsCommunityActionTemplatesEnabled { get; set; } From fed951e15714487ec9a3b6939767cfae6688b733 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Wed, 23 May 2018 09:05:38 +1000 Subject: [PATCH 25/37] fix public surface area --- ...re.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 1 + ...ePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 3c370aed5..3b6dfac1c 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -1873,6 +1873,7 @@ Octopus.Client.Model { .ctor() Boolean IsBuiltInRepoSyncEnabled { get; set; } + Boolean IsBuiltinWorkerEnabled { get; set; } Boolean IsCommunityActionTemplatesEnabled { get; set; } Boolean IsMultiTenancyEnabled { get; set; } } diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 8625d8234..5ded7db4a 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -2368,6 +2368,7 @@ Octopus.Client.Model { .ctor() Boolean IsBuiltInRepoSyncEnabled { get; set; } + Boolean IsBuiltinWorkerEnabled { get; set; } Boolean IsCommunityActionTemplatesEnabled { get; set; } Boolean IsMultiTenancyEnabled { get; set; } } From a8f79d42a11f7769d1d04075bf66e393abcbee29 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 25 May 2018 13:39:11 +1000 Subject: [PATCH 26/37] add default true for builtin worker feature --- source/Octopus.Client/Model/FeaturesConfigurationResource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Octopus.Client/Model/FeaturesConfigurationResource.cs b/source/Octopus.Client/Model/FeaturesConfigurationResource.cs index fffa8442a..e3510ebee 100644 --- a/source/Octopus.Client/Model/FeaturesConfigurationResource.cs +++ b/source/Octopus.Client/Model/FeaturesConfigurationResource.cs @@ -8,7 +8,7 @@ public class FeaturesConfigurationResource : Resource public bool IsMultiTenancyEnabled { get; set; } [Writeable] - public bool IsBuiltinWorkerEnabled { get; set; } + public bool IsBuiltinWorkerEnabled { get; set; } = true; [Writeable] public bool IsCommunityActionTemplatesEnabled { get; set; } From b3f5e3c49d9dfe5e18b75418ccf0bcf945101f6c Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 28 May 2018 11:13:55 +1000 Subject: [PATCH 27/37] Add project import with worker pools --- .../Octopus.Cli/Importers/ProjectImporter.cs | 38 ++++++++++++++++++- source/Octopus.Client/Model/ScopeField.cs | 3 +- .../Model/VariableScopeValues.cs | 2 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/source/Octopus.Cli/Importers/ProjectImporter.cs b/source/Octopus.Cli/Importers/ProjectImporter.cs index 31793938c..8739e4ec4 100644 --- a/source/Octopus.Cli/Importers/ProjectImporter.cs +++ b/source/Octopus.Cli/Importers/ProjectImporter.cs @@ -33,6 +33,7 @@ class ValidatedImportSettings : BaseValidatedImportSettings public IDictionary LibraryVariableSets { get; set; } public DeploymentProcessResource DeploymentProcess { get; set; } public IDictionary Environments { get; set; } + public IDictionary WorkerPools { get; set; } public IDictionary Machines { get; set; } public IDictionary Feeds { get; set; } public IDictionary Templates { get; set; } @@ -76,6 +77,7 @@ protected override async Task Validate(Dictionary paramDic var scopeValuesUsed = GetScopeValuesUsed(variableSet.Variables, deploymentProcess.Steps, variableSet.ScopeValues); var environmentChecksTask = CheckEnvironmentsExist(scopeValuesUsed[ScopeField.Environment]).ConfigureAwait(false); + var workerPoolChecksTask = CheckWorkerPoolsExist(scopeValuesUsed[ScopeField.WorkerPool]).ConfigureAwait(false); var machineChecksTask = CheckMachinesExist(scopeValuesUsed[ScopeField.Machine]).ConfigureAwait(false); var feedChecksTask = CheckNuGetFeedsExist(nugetFeeds).ConfigureAwait(false); var templateChecksTask = CheckActionTemplates(actionTemplates).ConfigureAwait(false); @@ -84,6 +86,7 @@ protected override async Task Validate(Dictionary paramDic var channelLifecycleChecksTask = CheckChannelLifecycles(channelLifecycles).ConfigureAwait(false); var environmentChecks = await environmentChecksTask; + var workerPoolChecks = await workerPoolChecksTask; var machineChecks = await machineChecksTask; var feedChecks = await feedChecksTask; var templateChecks = await templateChecksTask; @@ -95,6 +98,7 @@ protected override async Task Validate(Dictionary paramDic errorList.AddRange( environmentChecks.MissingDependencyErrors + .Concat(workerPoolChecks.MissingDependencyErrors) .Concat(machineChecks.MissingDependencyErrors) .Concat(feedChecks.MissingDependencyErrors) .Concat(templateChecks.MissingDependencyErrors) @@ -109,6 +113,7 @@ protected override async Task Validate(Dictionary paramDic ProjectGroupId = projectGroupChecks.FoundDependencies.Values.FirstOrDefault()?.Id, LibraryVariableSets = libraryVariableSetChecks.FoundDependencies, Environments = environmentChecks.FoundDependencies, + WorkerPools = workerPoolChecks.FoundDependencies, Feeds = feedChecks.FoundDependencies, Templates = templateChecks.FoundDependencies, Machines = machineChecks.FoundDependencies, @@ -144,7 +149,7 @@ protected override async Task Import(Dictionary paramDictionary) var oldActionChannels = validatedImportSettings.DeploymentProcess.Steps.SelectMany(s => s.Actions).ToDictionary(x => x.Id, x => x.Channels.Clone()); - var importeDeploymentProcess = await ImportDeploymentProcess(validatedImportSettings.DeploymentProcess, importedProject, validatedImportSettings.Environments, validatedImportSettings.Feeds, validatedImportSettings.Templates).ConfigureAwait(false); + var importeDeploymentProcess = await ImportDeploymentProcess(validatedImportSettings.DeploymentProcess, importedProject, validatedImportSettings.Environments, validatedImportSettings.WorkerPools, validatedImportSettings.Feeds, validatedImportSettings.Templates).ConfigureAwait(false); var importedChannels = (await ImportProjectChannels(validatedImportSettings.Channels.ToList(), importedProject, validatedImportSettings.ChannelLifecycles).ConfigureAwait(false)) @@ -233,6 +238,7 @@ protected Dictionary> GetScopeValuesUsed(ILi {ScopeField.Environment, new List()}, {ScopeField.Machine, new List()}, {ScopeField.Channel, new List()}, + {ScopeField.WorkerPool, new List()}, }; foreach (var variable in variables) @@ -298,12 +304,21 @@ protected Dictionary> GetScopeValuesUsed(ILi usedScopeValues[ScopeField.Channel].Add(channel); } } + + if (!string.IsNullOrWhiteSpace(action.WorkerPoolId)) + { + var pool = variableScopeValues.WorkerPools.Find(p => p.Id == action.WorkerPoolId); + if (pool != null && !usedScopeValues[ScopeField.WorkerPool].Exists(p => p.Id == action.WorkerPoolId)) + { + usedScopeValues[ScopeField.WorkerPool].Add(pool); + } + } } } return usedScopeValues; } - + async Task ImportVariableSets(VariableSetResource variableSet, ProjectResource importedProject, IDictionary environments, @@ -416,6 +431,7 @@ IList UpdateVariables(VariableSetResource variableSet, IDictio async Task ImportDeploymentProcess(DeploymentProcessResource deploymentProcess, ProjectResource importedProject, IDictionary environments, + IDictionary workerPools, IDictionary nugetFeeds, IDictionary actionTemplates) { @@ -450,6 +466,12 @@ async Task ImportDeploymentProcess(DeploymentProcessR action.Environments.Clear(); action.Environments.AddRange(newEnvironmentIds); + if (!string.IsNullOrWhiteSpace(action.WorkerPoolId)) + { + Log.Debug("Updating ID of Worker Pool"); + action.WorkerPoolId = workerPools[action.WorkerPoolId].Id; + } + // Make sure source channels are clear, will be added later action.Channels.Clear(); } @@ -624,6 +646,18 @@ protected async Task> CheckEnvironmentsEx return dependencies; } + protected async Task> CheckWorkerPoolsExist(List poolList) + { + Log.Debug("Checking that all worker pools exist"); + var dependencies = new CheckedReferences(); + foreach (var p in poolList) + { + var pool = await Repository.WorkerPools.FindByName(p.Name).ConfigureAwait(false); + dependencies.Register(p.Name, p.Id, pool); + } + return dependencies; + } + protected async Task> CheckChannelLifecycles(List channelLifecycles) { Log.Debug("Checking that all channel lifecycles exist"); diff --git a/source/Octopus.Client/Model/ScopeField.cs b/source/Octopus.Client/Model/ScopeField.cs index 8c00754c3..9aad006e0 100644 --- a/source/Octopus.Client/Model/ScopeField.cs +++ b/source/Octopus.Client/Model/ScopeField.cs @@ -14,6 +14,7 @@ public enum ScopeField Private, // Allows inbuilt vars to override user ones Channel, TenantTag, - Tenant + Tenant, + WorkerPool } } \ No newline at end of file diff --git a/source/Octopus.Client/Model/VariableScopeValues.cs b/source/Octopus.Client/Model/VariableScopeValues.cs index a934b8022..4871dd6df 100644 --- a/source/Octopus.Client/Model/VariableScopeValues.cs +++ b/source/Octopus.Client/Model/VariableScopeValues.cs @@ -7,6 +7,7 @@ public class VariableScopeValues : IVariableScopeValues public VariableScopeValues() { Environments = new List(); + WorkerPools = new List(); Machines = new List(); Actions = new List(); Roles = new List(); @@ -15,6 +16,7 @@ public VariableScopeValues() } public List Environments { get; set; } + public List WorkerPools { get; set; } public List Machines { get; set; } public List Actions { get; set; } public List Roles { get; set; } From 99cdac3b14508c2e791cdc91d39daf9e9c2e0631 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 28 May 2018 11:38:49 +1000 Subject: [PATCH 28/37] touch up public surface area for workers migrator --- ...e.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 2 ++ ...PublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index f168cce5c..8eb50e488 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -2887,6 +2887,7 @@ Octopus.Client.Model Channel = 8 TenantTag = 9 Tenant = 10 + WorkerPool = 11 } class ScopeSpecification IDictionary @@ -3483,6 +3484,7 @@ Octopus.Client.Model List Machines { get; set; } List Roles { get; set; } List TenantTags { get; set; } + List WorkerPools { get; set; } } VariableSetContentType { diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 736d5fd50..000fc5eac 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -3385,6 +3385,7 @@ Octopus.Client.Model Channel = 8 TenantTag = 9 Tenant = 10 + WorkerPool = 11 } class ScopeSpecification IDictionary @@ -3986,6 +3987,7 @@ Octopus.Client.Model List Machines { get; set; } List Roles { get; set; } List TenantTags { get; set; } + List WorkerPools { get; set; } } VariableSetContentType { From 1ea22e914df1fff57486abfe77267ceb58a391fc Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 1 Jun 2018 10:27:32 +1000 Subject: [PATCH 29/37] Fixed casing of IsBuiltInWorkerEnabled --- ...e.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 2 +- ...PublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 2 +- source/Octopus.Client/Model/FeaturesConfigurationResource.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index a03d6b46c..42df68f7f 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -1874,7 +1874,7 @@ Octopus.Client.Model { .ctor() Boolean IsBuiltInRepoSyncEnabled { get; set; } - Boolean IsBuiltinWorkerEnabled { get; set; } + Boolean IsBuiltInWorkerEnabled { get; set; } Boolean IsCommunityActionTemplatesEnabled { get; set; } Boolean IsMultiTenancyEnabled { get; set; } } diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 6e7b8cd7f..4dfd4120b 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -2369,7 +2369,7 @@ Octopus.Client.Model { .ctor() Boolean IsBuiltInRepoSyncEnabled { get; set; } - Boolean IsBuiltinWorkerEnabled { get; set; } + Boolean IsBuiltInWorkerEnabled { get; set; } Boolean IsCommunityActionTemplatesEnabled { get; set; } Boolean IsMultiTenancyEnabled { get; set; } } diff --git a/source/Octopus.Client/Model/FeaturesConfigurationResource.cs b/source/Octopus.Client/Model/FeaturesConfigurationResource.cs index e3510ebee..a613ad7a9 100644 --- a/source/Octopus.Client/Model/FeaturesConfigurationResource.cs +++ b/source/Octopus.Client/Model/FeaturesConfigurationResource.cs @@ -8,7 +8,7 @@ public class FeaturesConfigurationResource : Resource public bool IsMultiTenancyEnabled { get; set; } [Writeable] - public bool IsBuiltinWorkerEnabled { get; set; } = true; + public bool IsBuiltInWorkerEnabled { get; set; } = true; [Writeable] public bool IsCommunityActionTemplatesEnabled { get; set; } From bebcb1d0ab4d1eaef943a2ff8be23270b5235c11 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 1 Jun 2018 22:00:57 +1000 Subject: [PATCH 30/37] aligne health check args with server --- source/Octopus.Client/Model/BuiltInTasks.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/Octopus.Client/Model/BuiltInTasks.cs b/source/Octopus.Client/Model/BuiltInTasks.cs index cd52e2c72..50841b05f 100644 --- a/source/Octopus.Client/Model/BuiltInTasks.cs +++ b/source/Octopus.Client/Model/BuiltInTasks.cs @@ -41,9 +41,9 @@ public static class Arguments public static class TaskRestrictedTo { - public static readonly string Environment = "Environment"; - public static readonly string WorkerPool = "WorkerPool"; - public static readonly string Policy = "Policy"; + public static readonly string DeploymentTargets = "DeploymentTargets"; + public static readonly string Workers = "Workers"; + public static readonly string Policies = "Policies"; public static readonly string Unrestricted = "Unlimited"; } @@ -55,9 +55,9 @@ public static string[] CanBeRestrictedTo() { return new string[] { - TaskRestrictedTo.Environment, - TaskRestrictedTo.WorkerPool, - TaskRestrictedTo.Policy, + TaskRestrictedTo.DeploymentTargets, + TaskRestrictedTo.Workers, + TaskRestrictedTo.Policies, TaskRestrictedTo.Unrestricted }; } @@ -117,8 +117,8 @@ public static string[] CanBeRestrictedTo() { return new string[] { - TaskRestrictedTo.Environment, - TaskRestrictedTo.WorkerPool, + TaskRestrictedTo.DeploymentTargets, + TaskRestrictedTo.Workers, TaskRestrictedTo.Unrestricted }; } From 6a5b20956b5b044f1dc2287575636dc2aba47150 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Fri, 1 Jun 2018 22:15:54 +1000 Subject: [PATCH 31/37] update public surface area for new health args --- ...SurfaceAreaShouldNotRegress..NETCore.approved.txt | 12 ++++++------ ...ceAreaShouldNotRegress..NETFramework.approved.txt | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index fd15fe992..cd474841f 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -1174,10 +1174,10 @@ Octopus.Client.Model } abstract class TaskRestrictedTo { - static System.String Environment - static System.String Policy + static System.String DeploymentTargets + static System.String Policies static System.String Unrestricted - static System.String WorkerPool + static System.String Workers } abstract class TestAzureAccount { @@ -3243,10 +3243,10 @@ Octopus.Client.Model } abstract class TaskRestrictedTo { - static System.String Environment - static System.String Policy + static System.String DeploymentTargets + static System.String Policies static System.String Unrestricted - static System.String WorkerPool + static System.String Workers } TaskState { diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 10360eb0d..89712ab92 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -1669,10 +1669,10 @@ Octopus.Client.Model } abstract class TaskRestrictedTo { - static System.String Environment - static System.String Policy + static System.String DeploymentTargets + static System.String Policies static System.String Unrestricted - static System.String WorkerPool + static System.String Workers } abstract class TestAzureAccount { @@ -3744,10 +3744,10 @@ Octopus.Client.Model } abstract class TaskRestrictedTo { - static System.String Environment - static System.String Policy + static System.String DeploymentTargets + static System.String Policies static System.String Unrestricted - static System.String WorkerPool + static System.String Workers } TaskState { From 1fb215333dff1ea78ec6ce966a05a0006ee02bec Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 4 Jun 2018 14:22:17 +1000 Subject: [PATCH 32/37] Added writeable tag to IsDefault --- source/Octopus.Client/Model/WorkerPoolResource.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/Octopus.Client/Model/WorkerPoolResource.cs b/source/Octopus.Client/Model/WorkerPoolResource.cs index 48224ed2c..84691dcb7 100644 --- a/source/Octopus.Client/Model/WorkerPoolResource.cs +++ b/source/Octopus.Client/Model/WorkerPoolResource.cs @@ -28,6 +28,7 @@ public class WorkerPoolResource : Resource, INamedResource /// Is this the default pool. The default pool is used for steps that don't specify a worker pool. /// The default pool, if empty, uses the builtin worker to run steps. /// + [Writeable] public bool IsDefault { get; set; } /// From 3908905f77d2f919769a17809f070d84c01f3665 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 4 Jun 2018 14:29:03 +1000 Subject: [PATCH 33/37] Renamed `WorkerMachine` to `Worker` --- .../Commands/CleanWorkerPoolCommandFixture.cs | 26 ++-- ...ixture.cs => ListWorkersCommandFixture.cs} | 74 +++++----- ...chinesCommand.cs => ListWorkersCommand.cs} | 34 ++--- .../WorkerPool/CleanWorkerPoolCommand.cs | 32 ++--- .../WorkerPool/CreateWorkerPoolCommand.cs | 2 +- ...AreaShouldNotRegress..NETCore.approved.txt | 78 +++++------ ...houldNotRegress..NETFramework.approved.txt | 126 +++++++++--------- ...WorkerMachineEditor.cs => WorkerEditor.cs} | 16 +-- ...WorkerMachineEditor.cs => WorkerEditor.cs} | 16 +-- .../Octopus.Client/IOctopusAsyncRepository.cs | 2 +- source/Octopus.Client/IOctopusRepository.cs | 2 +- .../Model/WorkerPoolResource.cs | 2 +- ...erMachineResource.cs => WorkerResource.cs} | 10 +- .../Octopus.Client/OctopusAsyncRepository.cs | 4 +- source/Octopus.Client/OctopusRepository.cs | 4 +- .../IRegisterMachineOperationBase.cs | 2 +- ...eration.cs => IRegisterWorkerOperation.cs} | 4 +- ...peration.cs => RegisterWorkerOperation.cs} | 42 +++--- .../Repositories/Async/TaskRepository.cs | 12 +- .../Async/WorkerMachineRepository.cs | 87 ------------ .../Async/WorkerPoolRepository.cs | 8 +- .../Repositories/Async/WorkerRepository.cs | 87 ++++++++++++ .../Repositories/TaskRepository.cs | 12 +- .../Repositories/WorkerPoolRepository.cs | 8 +- ...chineRepository.cs => WorkerRepository.cs} | 34 ++--- 25 files changed, 362 insertions(+), 362 deletions(-) rename source/Octo.Tests/Commands/{ListWorkerMachinesCommandFixture.cs => ListWorkersCommandFixture.cs} (77%) rename source/Octopus.Cli/Commands/Machine/{ListWorkerMachinesCommand.cs => ListWorkersCommand.cs} (75%) rename source/Octopus.Client/Editors/Async/{WorkerMachineEditor.cs => WorkerEditor.cs} (69%) rename source/Octopus.Client/Editors/{WorkerMachineEditor.cs => WorkerEditor.cs} (67%) rename source/Octopus.Client/Model/{WorkerMachineResource.cs => WorkerResource.cs} (67%) rename source/Octopus.Client/Operations/{IRegisterWorkerMachineOperation.cs => IRegisterWorkerOperation.cs} (68%) rename source/Octopus.Client/Operations/{RegisterWorkerMachineOperation.cs => RegisterWorkerOperation.cs} (70%) delete mode 100644 source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs create mode 100644 source/Octopus.Client/Repositories/Async/WorkerRepository.cs rename source/Octopus.Client/Repositories/{WorkerMachineRepository.cs => WorkerRepository.cs} (52%) diff --git a/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs index 79a67fe20..3574635c9 100644 --- a/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs +++ b/source/Octo.Tests/Commands/CleanWorkerPoolCommandFixture.cs @@ -34,24 +34,24 @@ public void ShouldCleanPool() new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} ); - var workerList = MakeWorkerMachineList(2, + var workerList = MakeWorkerList(2, new List { new ReferenceCollection("WorkerPools-001"), new ReferenceCollection("WorkerPools-001") }); - Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + Repository.Workers.FindMany(Arg.Any>()).Returns(workerList); cleanPoolCommand.Execute(CommandLineArgs.ToArray()).GetAwaiter().GetResult(); LogLines.Should().Contain(string.Format("Found {0} machines in {1} with the status {2}", workerList.Count, "SomePool", MachineModelHealthStatus.Unhealthy.ToString())); LogLines.Should().Contain(string.Format("Deleting {0} {1} (ID: {2})", workerList[0].Name, workerList[0].Status, workerList[0].Id)); - Repository.WorkerMachines.Received().Delete(workerList[0]); + Repository.Workers.Received().Delete(workerList[0]); LogLines.Should().Contain(string.Format("Deleting {0} {1} (ID: {2})", workerList[1].Name, workerList[1].Status, workerList[1].Id)); - Repository.WorkerMachines.Received().Delete(workerList[1]); + Repository.Workers.Received().Delete(workerList[1]); } [Test] @@ -64,14 +64,14 @@ public void ShouldRemoveMachinesBelongingToMultiplePoolsInsteadOfDeleting() new WorkerPoolResource { Name = "SomePool", Id = "WorkerPools-001"} ); - var workerList = MakeWorkerMachineList(2, + var workerList = MakeWorkerList(2, new List { new ReferenceCollection(new List { "WorkerPools-001", "WorkerPools-002" }), new ReferenceCollection("WorkerPools-001") }); - Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + Repository.Workers.FindMany(Arg.Any>()).Returns(workerList); cleanPoolCommand.Execute(CommandLineArgs.ToArray()).GetAwaiter().GetResult(); @@ -80,10 +80,10 @@ public void ShouldRemoveMachinesBelongingToMultiplePoolsInsteadOfDeleting() LogLines.Should().Contain($"Removing {workerList[0].Name} {workerList[0].Status} (ID: {workerList[0].Id}) from SomePool"); Assert.That(workerList[0].WorkerPoolIds.Count, Is.EqualTo(1), "The machine should have been removed from the SomePool pool."); - Repository.WorkerMachines.Received().Modify(workerList[0]); + Repository.Workers.Received().Modify(workerList[0]); LogLines.Should().Contain(string.Format("Deleting {0} {1} (ID: {2})", workerList[1].Name, workerList[1].Status, workerList[1].Id)); - Repository.WorkerMachines.Received().Delete(workerList[1]); + Repository.Workers.Received().Delete(workerList[1]); } [Test] @@ -125,14 +125,14 @@ public async Task JsonOutput_ShouldBeWellFormed() CommandLineArgs.Add($"--workerpool=SomePool"); CommandLineArgs.Add("-health-status=Unhealthy"); - var workerList = MakeWorkerMachineList(2, + var workerList = MakeWorkerList(2, new List { new ReferenceCollection(new List { "WorkerPools-001", "WorkerPools-002" }), new ReferenceCollection("WorkerPools-001") }); - Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + Repository.Workers.FindMany(Arg.Any>()).Returns(workerList); await cleanPoolCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); @@ -150,13 +150,13 @@ public async Task JsonOutput_ShouldBeWellFormed() } - private List MakeWorkerMachineList(int numWorkers, List pools) + private List MakeWorkerList(int numWorkers, List pools) { - var result = new List(); + var result = new List(); for (int i = 0; i < numWorkers; i++) { result.Add( - new WorkerMachineResource + new WorkerResource { Name = Guid.NewGuid().ToString(), Id = "Machines-00" + i, diff --git a/source/Octo.Tests/Commands/ListWorkerMachinesCommandFixture.cs b/source/Octo.Tests/Commands/ListWorkersCommandFixture.cs similarity index 77% rename from source/Octo.Tests/Commands/ListWorkerMachinesCommandFixture.cs rename to source/Octo.Tests/Commands/ListWorkersCommandFixture.cs index 7da214d57..d712639ee 100644 --- a/source/Octo.Tests/Commands/ListWorkerMachinesCommandFixture.cs +++ b/source/Octo.Tests/Commands/ListWorkersCommandFixture.cs @@ -13,20 +13,20 @@ namespace Octopus.Cli.Tests.Commands { [TestFixture] - public class ListWorkerMachinesCommandFixture : ApiCommandFixtureBase + public class ListWorkersCommandFixture : ApiCommandFixtureBase { const string MachineLogFormat = " - {0} {1} (ID: {2}) in {3}"; [SetUp] public void SetUp() { - listWorkerMachinesCommand = new ListWorkerMachinesCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); + listWorkersCommand = new ListWorkersCommand(RepositoryFactory, FileSystem, ClientFactory, CommandOutputProvider); } - ListWorkerMachinesCommand listWorkerMachinesCommand; + ListWorkersCommand listWorkersCommand; [Test] - public async Task ShouldGetListOfWorkerMachinesWithPoolAndStatusArgs() + public async Task ShouldGetListOfWorkersWithPoolAndStatusArgs() { CommandLineArgs.Add("-workerpool=SomePool"); CommandLineArgs.Add("-status=Offline"); @@ -36,7 +36,7 @@ public async Task ShouldGetListOfWorkerMachinesWithPoolAndStatusArgs() new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} }); - var workerList = MakeWorkerMachineList(3, + var workerList = MakeWorkerList(3, new List { MachineModelStatus.Online, @@ -50,18 +50,18 @@ public async Task ShouldGetListOfWorkerMachinesWithPoolAndStatusArgs() new ReferenceCollection("WorkerPools-001") }); - Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + Repository.Workers.FindMany(Arg.Any>()).Returns(workerList); - await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + await listWorkersCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); - LogLines.Should().Contain("Worker Machines: 2"); + LogLines.Should().Contain("Workers: 2"); LogLines.Should().NotContain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[1].Name, workerList[1].Status.ToString(), workerList[1].Id, "SomePool")); LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[2].Name, workerList[2].Status.ToString(), workerList[2].Id, "SomePool")); } [Test] - public async Task ShouldGetListOfWorkerMachinesWithPoolArgs() + public async Task ShouldGetListOfWorkersWithPoolArgs() { CommandLineArgs.Add("-workerpool=SomePool"); @@ -70,7 +70,7 @@ public async Task ShouldGetListOfWorkerMachinesWithPoolArgs() new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} }); - var workerList = MakeWorkerMachineList(1, + var workerList = MakeWorkerList(1, new List { MachineModelStatus.Online @@ -79,16 +79,16 @@ public async Task ShouldGetListOfWorkerMachinesWithPoolArgs() { new ReferenceCollection("WorkerPools-001") }); - Repository.WorkerMachines.FindMany(Arg.Any>()).Returns(workerList); + Repository.Workers.FindMany(Arg.Any>()).Returns(workerList); - await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + await listWorkersCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); - LogLines.Should().Contain("Worker Machines: 1"); + LogLines.Should().Contain("Workers: 1"); LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); } [Test] - public async Task ShouldGetListOfWorkerMachinesWithNoArgs() + public async Task ShouldGetListOfWorkerWithNoArgs() { Repository.WorkerPools.FindAll().Returns(new List { @@ -96,7 +96,7 @@ public async Task ShouldGetListOfWorkerMachinesWithNoArgs() new WorkerPoolResource {Name = "SomeOtherPool", Id = "WorkerPools-002"} }); - var workerList = MakeWorkerMachineList(3, + var workerList = MakeWorkerList(3, new List { MachineModelStatus.Online, @@ -109,18 +109,18 @@ public async Task ShouldGetListOfWorkerMachinesWithNoArgs() new ReferenceCollection("WorkerPools-002"), new ReferenceCollection("WorkerPools-002") }); - Repository.WorkerMachines.FindAll().Returns(workerList); + Repository.Workers.FindAll().Returns(workerList); - await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + await listWorkersCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); - LogLines.Should().Contain("Worker Machines: 3"); + LogLines.Should().Contain("Workers: 3"); LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[1].Name, workerList[1].Status.ToString(), workerList[1].Id, "SomeOtherPool")); LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[2].Name, workerList[2].Status.ToString(), workerList[2].Id, "SomeOtherPool")); } [Test] - public async Task ShouldGetListOfWorkerMachinesWithOfflineStatusArgs() + public async Task ShouldGetListOfWorkersWithOfflineStatusArgs() { CommandLineArgs.Add("-status=Offline"); @@ -129,7 +129,7 @@ public async Task ShouldGetListOfWorkerMachinesWithOfflineStatusArgs() new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} }); - var workerList = MakeWorkerMachineList(3, + var workerList = MakeWorkerList(3, new List { MachineModelStatus.Online, @@ -143,11 +143,11 @@ public async Task ShouldGetListOfWorkerMachinesWithOfflineStatusArgs() new ReferenceCollection("WorkerPools-001") }); - Repository.WorkerMachines.FindAll().Returns(workerList); + Repository.Workers.FindAll().Returns(workerList); - await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + await listWorkersCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); - LogLines.Should().Contain("Worker Machines: 1"); + LogLines.Should().Contain("Workers: 1"); LogLines.Should().NotContain(string.Format(MachineLogFormat, workerList[0].Name, workerList[0].Status.ToString(), workerList[0].Id, "SomePool")); LogLines.Should().NotContain(string.Format(MachineLogFormat, workerList[1].Name, workerList[1].Status.ToString(), workerList[1].Id, "SomePool")); LogLines.Should().Contain(string.Format(MachineLogFormat, workerList[2].Name, workerList[2].Status.ToString(), workerList[2].Id, "SomePool")); @@ -166,15 +166,15 @@ public async Task ShouldSupportStateFilters() new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} }); - Repository.WorkerMachines.FindAll().Returns(new List + Repository.Workers.FindAll().Returns(new List { - new WorkerMachineResource { + new WorkerResource { Name = "PC0123", Id = "Machines-001", HealthStatus = MachineModelHealthStatus.Unavailable, WorkerPoolIds = new ReferenceCollection("WorkerPools-001") }, - new WorkerMachineResource { + new WorkerResource { Name = "PC01466", Id = "Machines-002", HealthStatus = MachineModelHealthStatus.Healthy, @@ -183,7 +183,7 @@ public async Task ShouldSupportStateFilters() Endpoint = new ListeningTentacleEndpointResource() {TentacleVersionDetails = new TentacleDetailsResource { UpgradeSuggested = true } }, WorkerPoolIds = new ReferenceCollection("WorkerPools-001") }, - new WorkerMachineResource { + new WorkerResource { Name = "PC01467", Id = "Machines-003", HealthStatus = MachineModelHealthStatus.Healthy, @@ -192,7 +192,7 @@ public async Task ShouldSupportStateFilters() Endpoint = new ListeningTentacleEndpointResource() {TentacleVersionDetails = new TentacleDetailsResource { UpgradeSuggested = false } }, WorkerPoolIds = new ReferenceCollection("WorkerPools-001") }, - new WorkerMachineResource { + new WorkerResource { Name = "PC01468", Id = "Machines-004", HealthStatus = MachineModelHealthStatus.Healthy, @@ -200,7 +200,7 @@ public async Task ShouldSupportStateFilters() WorkerPoolIds = new ReferenceCollection("WorkerPools-001"), HasLatestCalamari = false }, - new WorkerMachineResource { + new WorkerResource { Name = "PC01999", Id = "Machines-005", HealthStatus = MachineModelHealthStatus.Healthy, @@ -208,9 +208,9 @@ public async Task ShouldSupportStateFilters() WorkerPoolIds = new ReferenceCollection("WorkerPools-001")} }); - await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + await listWorkersCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); - LogLines.Should().Contain("Worker Machines: 1"); + LogLines.Should().Contain("Workers: 1"); LogLines.Should().Contain(string.Format(MachineLogFormat, "PC01466", "Healthy - Disabled", "Machines-002", "SomePool")); } @@ -226,7 +226,7 @@ public async Task JsonFormat_ShouldBeWellFormed() new WorkerPoolResource {Name = "SomePool", Id = "WorkerPools-001"} }); - var workerList = MakeWorkerMachineList(3, + var workerList = MakeWorkerList(3, new List { MachineModelStatus.Online, @@ -240,9 +240,9 @@ public async Task JsonFormat_ShouldBeWellFormed() new ReferenceCollection("WorkerPools-001") }); - Repository.WorkerMachines.FindAll().Returns(workerList); + Repository.Workers.FindAll().Returns(workerList); - await listWorkerMachinesCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); + await listWorkersCommand.Execute(CommandLineArgs.ToArray()).ConfigureAwait(false); var logoutput = LogOutput.ToString(); JsonConvert.DeserializeObject(logoutput); @@ -252,14 +252,14 @@ public async Task JsonFormat_ShouldBeWellFormed() } - private List MakeWorkerMachineList(int numWorkers, List statuses, + private List MakeWorkerList(int numWorkers, List statuses, List pools) { - var result = new List(); + var result = new List(); for (int i = 0; i < numWorkers; i++) { result.Add( - new WorkerMachineResource + new WorkerResource { Name = Guid.NewGuid().ToString(), Id = "Machines-00" + i, diff --git a/source/Octopus.Cli/Commands/Machine/ListWorkerMachinesCommand.cs b/source/Octopus.Cli/Commands/Machine/ListWorkersCommand.cs similarity index 75% rename from source/Octopus.Cli/Commands/Machine/ListWorkerMachinesCommand.cs rename to source/Octopus.Cli/Commands/Machine/ListWorkersCommand.cs index 1d84eb06f..f63f11d51 100644 --- a/source/Octopus.Cli/Commands/Machine/ListWorkerMachinesCommand.cs +++ b/source/Octopus.Cli/Commands/Machine/ListWorkersCommand.cs @@ -11,23 +11,23 @@ namespace Octopus.Cli.Commands.Machine { - [Command("list-workermachines", Description = "Lists all worker machines")] - public class ListWorkerMachinesCommand : ApiCommand, ISupportFormattedOutput + [Command("list-workers", Description = "Lists all workers")] + public class ListWorkersCommand : ApiCommand, ISupportFormattedOutput { readonly HashSet pools = new HashSet(StringComparer.OrdinalIgnoreCase); readonly HashSet statuses = new HashSet(StringComparer.OrdinalIgnoreCase); readonly HashSet healthStatuses = new HashSet(StringComparer.OrdinalIgnoreCase); private HealthStatusProvider provider; List workerpoolResources; - IEnumerable workerpoolMachines; + IEnumerable workerpoolWorkers; private bool? isDisabled; private bool? isCalamariOutdated; private bool? isTentacleOutdated; - public ListWorkerMachinesCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider) + public ListWorkersCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider) : base(clientFactory, repositoryFactory, fileSystem, commandOutputProvider) { - var options = Options.For("Listing Worker Machines"); + var options = Options.For("Listing Workers"); options.Add("workerpool=", "Name of a worker pool to filter by. Can be specified many times.", v => pools.Add(v)); options.Add("status=", $"[Optional] Status of Machines filter by ({string.Join(", ", HealthStatusProvider.StatusNames)}). Can be specified many times.", v => statuses.Add(v)); options.Add("health-status=|healthstatus=", $"[Optional] Health status of Machines filter by ({string.Join(", ", HealthStatusProvider.HealthStatusNames)}). Can be specified many times.", v => healthStatuses.Add(v)); @@ -42,18 +42,18 @@ public async Task Request() workerpoolResources = await GetPools().ConfigureAwait(false); - workerpoolMachines = await FilterByWorkerPools(workerpoolResources).ConfigureAwait(false); - workerpoolMachines = FilterByState(workerpoolMachines, provider); + workerpoolWorkers = await FilterByWorkerPools(workerpoolResources).ConfigureAwait(false); + workerpoolWorkers = FilterByState(workerpoolWorkers, provider); } public void PrintDefaultOutput() { - LogFilteredMachines(workerpoolMachines, provider, workerpoolResources); + LogFilteredMachines(workerpoolWorkers, provider, workerpoolResources); } public void PrintJsonOutput() { - commandOutputProvider.Json(workerpoolMachines.Select(machine => new + commandOutputProvider.Json(workerpoolWorkers.Select(machine => new { machine.Id, machine.Name, @@ -63,10 +63,10 @@ public void PrintJsonOutput() })); } - private void LogFilteredMachines(IEnumerable poolMachines, HealthStatusProvider provider, List poolResources) + private void LogFilteredMachines(IEnumerable poolMachines, HealthStatusProvider provider, List poolResources) { var orderedMachines = poolMachines.OrderBy(m => m.Name).ToList(); - commandOutputProvider.Information("Worker Machines: {Count}", orderedMachines.Count); + commandOutputProvider.Information("Workers: {Count}", orderedMachines.Count); foreach (var machine in orderedMachines) { commandOutputProvider.Information(" - {Machine:l} {Status:l} (ID: {MachineId:l}) in {WorkerPool:l}", machine.Name, provider.GetStatus(machine), machine.Id, @@ -80,7 +80,7 @@ private Task> GetPools() return Repository.WorkerPools.FindAll(); } - private IEnumerable FilterByState(IEnumerable poolMachines, HealthStatusProvider provider) + private IEnumerable FilterByState(IEnumerable poolMachines, HealthStatusProvider provider) { poolMachines = provider.Filter(poolMachines); @@ -103,7 +103,7 @@ private IEnumerable FilterByState(IEnumerable> FilterByWorkerPools(List poolResources) + private Task> FilterByWorkerPools(List poolResources) { var poolsToInclude = poolResources.Where(e => pools.Contains(e.Name, StringComparer.OrdinalIgnoreCase)).ToList(); var missingPools = pools.Except(poolsToInclude.Select(e => e.Name), StringComparer.OrdinalIgnoreCase).ToList(); @@ -113,18 +113,18 @@ private Task> FilterByWorkerPools(List p.Id).ToList(); - commandOutputProvider.Debug("Loading worker machines..."); + commandOutputProvider.Debug("Loading workers..."); if (poolsFilter.Count > 0) { commandOutputProvider.Debug("Loading machines from {WorkerPools:l}...", string.Join(", ", poolsToInclude.Select(e => e.Name))); return - Repository.WorkerMachines.FindMany( + Repository.Workers.FindMany( x => { return x.WorkerPoolIds.Any(poolId => poolsFilter.Contains(poolId)); }); } else { - commandOutputProvider.Debug("Loading worker machines from all pools..."); - return Repository.WorkerMachines.FindAll(); + commandOutputProvider.Debug("Loading workers from all pools..."); + return Repository.Workers.FindAll(); } } } diff --git a/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs index 86d13687c..de3c97699 100644 --- a/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs +++ b/source/Octopus.Cli/Commands/WorkerPool/CleanWorkerPoolCommand.cs @@ -11,7 +11,7 @@ namespace Octopus.Cli.Commands.WorkerPools { - [Command("clean-workerpool", Description = "Cleans all Offline Worker Machines from a WorkerPool")] + [Command("clean-workerpool", Description = "Cleans all Offline Workers from a WorkerPool")] public class CleanWorkerPoolCommand : ApiCommand, ISupportFormattedOutput { string poolName; @@ -20,7 +20,7 @@ public class CleanWorkerPoolCommand : ApiCommand, ISupportFormattedOutput private bool? isCalamariOutdated; private bool? isTentacleOutdated; WorkerPoolResource workerPoolResource; - IEnumerable machines; + IEnumerable machines; List commandResults = new List(); @@ -29,8 +29,8 @@ public CleanWorkerPoolCommand(IOctopusAsyncRepositoryFactory repositoryFactory, { var options = Options.For("WorkerPool Cleanup"); options.Add("workerpool=", "Name of a worker pool to clean up.", v => poolName = v); - options.Add("health-status=", $"Health status of Worker Machines to clean up ({string.Join(", ", HealthStatusProvider.HealthStatusNames)}). Can be specified many times.", v => healthStatuses.Add(v)); - options.Add("disabled=", "[Optional] Disabled status filter of Worker Machine to clean up.", v => SetFlagState(v, ref isDisabled)); + options.Add("health-status=", $"Health status of Workers to clean up ({string.Join(", ", HealthStatusProvider.HealthStatusNames)}). Can be specified many times.", v => healthStatuses.Add(v)); + options.Add("disabled=", "[Optional] Disabled status filter of Worker to clean up.", v => SetFlagState(v, ref isDisabled)); options.Add("calamari-outdated=", "[Optional] State of Calamari to clean up. By default ignores Calamari state.", v => SetFlagState(v, ref isCalamariOutdated)); options.Add("tentacle-outdated=", "[Optional] State of Tentacle version to clean up. By default ignores Tentacle state", v => SetFlagState(v, ref isTentacleOutdated)); } @@ -50,7 +50,7 @@ public async Task Request() await CleanUpPool(machines.ToList(), workerPoolResource); } - private async Task CleanUpPool(List filteredMachines, WorkerPoolResource poolResource) + private async Task CleanUpPool(List filteredMachines, WorkerPoolResource poolResource) { commandOutputProvider.Information("Found {MachineCount} machines in {WorkerPool:l} with the status {Status:l}", filteredMachines.Count, poolResource.Name, GetStateFilterDescription()); @@ -71,13 +71,13 @@ private async Task CleanUpPool(List filteredMachines, Wor 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.WorkerMachines.Modify(machine).ConfigureAwait(false); + 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.WorkerMachines.Delete(machine).ConfigureAwait(false); + await Repository.Workers.Delete(machine).ConfigureAwait(false); result.Action = MachineAction.Deleted; } @@ -85,24 +85,24 @@ private async Task CleanUpPool(List filteredMachines, Wor } } - private IEnumerable FilterByState(IEnumerable workerMachines) + private IEnumerable FilterByState(IEnumerable workers) { var provider = new HealthStatusProvider(Repository, new HashSet(StringComparer.OrdinalIgnoreCase), healthStatuses, commandOutputProvider); - workerMachines = provider.Filter(workerMachines); + workers = provider.Filter(workers); if (isDisabled.HasValue) { - workerMachines = workerMachines.Where(m => m.IsDisabled == isDisabled.Value); + workers = workers.Where(m => m.IsDisabled == isDisabled.Value); } if (isCalamariOutdated.HasValue) { - workerMachines = workerMachines.Where(m => m.HasLatestCalamari == !isCalamariOutdated.Value); + workers = workers.Where(m => m.HasLatestCalamari == !isCalamariOutdated.Value); } if (isTentacleOutdated.HasValue) { - workerMachines = workerMachines.Where(m => (m.Endpoint as ListeningTentacleEndpointResource)?.TentacleVersionDetails.UpgradeSuggested == isTentacleOutdated.Value); + workers = workers.Where(m => (m.Endpoint as ListeningTentacleEndpointResource)?.TentacleVersionDetails.UpgradeSuggested == isTentacleOutdated.Value); } - return workerMachines; + return workers; } private string GetStateFilterDescription() @@ -127,10 +127,10 @@ private string GetStateFilterDescription() return description; } - private Task> FilterByWorkerPool(WorkerPoolResource poolResource) + private Task> FilterByWorkerPool(WorkerPoolResource poolResource) { - commandOutputProvider.Debug("Loading worker machines..."); - return Repository.WorkerMachines.FindMany(x => x.WorkerPoolIds.Any(poolId => poolId == poolResource.Id)); + commandOutputProvider.Debug("Loading workers..."); + return Repository.Workers.FindMany(x => x.WorkerPoolIds.Any(poolId => poolId == poolResource.Id)); } private async Task GetWorkerPool() diff --git a/source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs b/source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs index c84099621..dd4fd6896 100644 --- a/source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs +++ b/source/Octopus.Cli/Commands/WorkerPool/CreateWorkerPoolCommand.cs @@ -7,7 +7,7 @@ namespace Octopus.Cli.Commands.WorkerPool { - [Command("create-workerpool", Description = "Creates a pool for worker machines")] + [Command("create-workerpool", Description = "Creates a pool for workers")] public class CreateWorkerPoolCommand : ApiCommand, ISupportFormattedOutput { WorkerPoolResource pool; diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index a35fb91ef..b09e3dd54 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -88,8 +88,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } - Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } + Octopus.Client.Repositories.Async.IWorkerRepository Workers { get; } } interface IOctopusClientFactory { @@ -175,8 +175,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } - Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } + Octopus.Client.Repositories.Async.IWorkerRepository Workers { get; } } class OctopusClientFactory Octopus.Client.IOctopusClientFactory @@ -538,15 +538,15 @@ Octopus.Client.Editors.Async Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary) Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary, String, String) } - class WorkerMachineEditor - Octopus.Client.Editors.Async.IResourceEditor + class WorkerEditor + Octopus.Client.Editors.Async.IResourceEditor Octopus.Client.Editors.Async.IResourceBuilder { - .ctor(Octopus.Client.Repositories.Async.IWorkerMachineRepository) - Octopus.Client.Model.WorkerMachineResource Instance { get; } - Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) - Octopus.Client.Editors.Async.WorkerMachineEditor Customize(Action) - Task Save() + .ctor(Octopus.Client.Repositories.Async.IWorkerRepository) + Octopus.Client.Model.WorkerResource Instance { get; } + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Editors.Async.WorkerEditor Customize(Action) + Task Save() } class WorkerPoolEditor Octopus.Client.Editors.Async.IResourceEditor @@ -3555,18 +3555,6 @@ Octopus.Client.Model String ReferrerPolicy { get; set; } Octopus.Client.Model.XOptionsResource XOptions { get; set; } } - class WorkerMachineResource - Octopus.Client.Extensibility.IResource - Octopus.Client.Model.IAuditedResource - Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.MachineBasedResource - { - .ctor() - Octopus.Client.Model.ReferenceCollection WorkerPoolIds { get; set; } - Octopus.Client.Model.WorkerMachineResource AddOrUpdateWorkerPools(Octopus.Client.Model.WorkerPoolResource[]) - Octopus.Client.Model.WorkerMachineResource ClearWorkerPools() - Octopus.Client.Model.WorkerMachineResource RemoveWorkerPool(Octopus.Client.Model.WorkerPoolResource) - } class WorkerPoolResource Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource @@ -3591,6 +3579,18 @@ Octopus.Client.Model .ctor() Octopus.Client.Model.WorkerPoolResource WorkerPool { get; set; } } + class WorkerResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.MachineBasedResource + { + .ctor() + Octopus.Client.Model.ReferenceCollection WorkerPoolIds { get; set; } + Octopus.Client.Model.WorkerResource AddOrUpdateWorkerPools(Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Model.WorkerResource ClearWorkerPools() + Octopus.Client.Model.WorkerResource RemoveWorkerPool(Octopus.Client.Model.WorkerPoolResource) + } class X509Certificate { .ctor() @@ -4405,7 +4405,7 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } - interface IRegisterWorkerMachineOperation + interface IRegisterWorkerOperation Octopus.Client.Operations.IRegisterMachineOperationBase { String[] WorkerPoolNames { get; set; } @@ -4441,9 +4441,9 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } - class RegisterWorkerMachineOperation + class RegisterWorkerOperation Octopus.Client.Operations.IRegisterMachineOperationBase - Octopus.Client.Operations.IRegisterWorkerMachineOperation + Octopus.Client.Operations.IRegisterWorkerOperation Octopus.Client.Operations.RegisterMachineOperationBase { .ctor() @@ -4937,20 +4937,6 @@ Octopus.Client.Repositories.Async { Task GetVariableNames(String, String[]) } - interface IWorkerMachineRepository - Octopus.Client.Repositories.Async.IFindByName - Octopus.Client.Repositories.Async.IPaginate - Octopus.Client.Repositories.Async.IGet - Octopus.Client.Repositories.Async.ICreate - Octopus.Client.Repositories.Async.IModify - Octopus.Client.Repositories.Async.IDelete - { - Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) - Task Discover(String, Int32, Nullable) - Task> FindByThumbprint(String) - Task GetConnectionStatus(Octopus.Client.Model.WorkerMachineResource) - Task> List(Int32, Nullable, String, String, String, Nullable, String, String, String) - } interface IWorkerPoolRepository Octopus.Client.Repositories.Async.IFindByName Octopus.Client.Repositories.Async.IPaginate @@ -4962,10 +4948,24 @@ Octopus.Client.Repositories.Async { Task CreateOrModify(String) Task CreateOrModify(String, String) - Task> GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) + Task> GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) Task Sort(String[]) Task Summary(String, String, String, Nullable, String, String, Nullable) } + interface IWorkerRepository + Octopus.Client.Repositories.Async.IFindByName + Octopus.Client.Repositories.Async.IPaginate + Octopus.Client.Repositories.Async.IGet + Octopus.Client.Repositories.Async.ICreate + Octopus.Client.Repositories.Async.IModify + Octopus.Client.Repositories.Async.IDelete + { + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Task Discover(String, Int32, Nullable) + Task> FindByThumbprint(String) + Task GetConnectionStatus(Octopus.Client.Model.WorkerResource) + Task> List(Int32, Nullable, String, String, String, Nullable, String, String, String) + } } Octopus.Client.Serialization { diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 45f65c926..479631dc8 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -95,8 +95,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } - Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } + Octopus.Client.Repositories.Async.IWorkerRepository Workers { get; } } interface IOctopusClient IDisposable @@ -175,8 +175,8 @@ Octopus.Client Octopus.Client.Repositories.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.IUserRepository Users { get; } Octopus.Client.Repositories.IVariableSetRepository VariableSets { get; } - Octopus.Client.Repositories.IWorkerMachineRepository WorkerMachines { get; } Octopus.Client.Repositories.IWorkerPoolRepository WorkerPools { get; } + Octopus.Client.Repositories.IWorkerRepository Workers { get; } } class OctopusAsyncClient Octopus.Client.IOctopusAsyncClient @@ -258,8 +258,8 @@ Octopus.Client Octopus.Client.Repositories.Async.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.Async.IUserRepository Users { get; } Octopus.Client.Repositories.Async.IVariableSetRepository VariableSets { get; } - Octopus.Client.Repositories.Async.IWorkerMachineRepository WorkerMachines { get; } Octopus.Client.Repositories.Async.IWorkerPoolRepository WorkerPools { get; } + Octopus.Client.Repositories.Async.IWorkerRepository Workers { get; } } class OctopusClient Octopus.Client.IHttpOctopusClient @@ -358,8 +358,8 @@ Octopus.Client Octopus.Client.Repositories.IUserRolesRepository UserRoles { get; } Octopus.Client.Repositories.IUserRepository Users { get; } Octopus.Client.Repositories.IVariableSetRepository VariableSets { get; } - Octopus.Client.Repositories.IWorkerMachineRepository WorkerMachines { get; } Octopus.Client.Repositories.IWorkerPoolRepository WorkerPools { get; } + Octopus.Client.Repositories.IWorkerRepository Workers { get; } } abstract class OctopusRepositoryExtensions { @@ -705,15 +705,15 @@ Octopus.Client.Editors Octopus.Client.Editors.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary) Octopus.Client.Editors.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary, String, String) } - class WorkerMachineEditor - Octopus.Client.Editors.IResourceEditor + class WorkerEditor + Octopus.Client.Editors.IResourceEditor Octopus.Client.Editors.IResourceBuilder { - .ctor(Octopus.Client.Repositories.IWorkerMachineRepository) - Octopus.Client.Model.WorkerMachineResource Instance { get; } - Octopus.Client.Editors.WorkerMachineEditor CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) - Octopus.Client.Editors.WorkerMachineEditor Customize(Action) - Octopus.Client.Editors.WorkerMachineEditor Save() + .ctor(Octopus.Client.Repositories.IWorkerRepository) + Octopus.Client.Model.WorkerResource Instance { get; } + Octopus.Client.Editors.WorkerEditor CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Editors.WorkerEditor Customize(Action) + Octopus.Client.Editors.WorkerEditor Save() } class WorkerPoolEditor Octopus.Client.Editors.IResourceEditor @@ -1020,15 +1020,15 @@ Octopus.Client.Editors.Async Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary) Octopus.Client.Editors.Async.VariableTemplateContainerEditor AddOrUpdateVariableTemplate(String, String, IDictionary, String, String) } - class WorkerMachineEditor - Octopus.Client.Editors.Async.IResourceEditor + class WorkerEditor + Octopus.Client.Editors.Async.IResourceEditor Octopus.Client.Editors.Async.IResourceBuilder { - .ctor(Octopus.Client.Repositories.Async.IWorkerMachineRepository) - Octopus.Client.Model.WorkerMachineResource Instance { get; } - Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) - Octopus.Client.Editors.Async.WorkerMachineEditor Customize(Action) - Task Save() + .ctor(Octopus.Client.Repositories.Async.IWorkerRepository) + Octopus.Client.Model.WorkerResource Instance { get; } + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Editors.Async.WorkerEditor Customize(Action) + Task Save() } class WorkerPoolEditor Octopus.Client.Editors.Async.IResourceEditor @@ -4058,18 +4058,6 @@ Octopus.Client.Model String ReferrerPolicy { get; set; } Octopus.Client.Model.XOptionsResource XOptions { get; set; } } - class WorkerMachineResource - Octopus.Client.Extensibility.IResource - Octopus.Client.Model.IAuditedResource - Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.MachineBasedResource - { - .ctor() - Octopus.Client.Model.ReferenceCollection WorkerPoolIds { get; set; } - Octopus.Client.Model.WorkerMachineResource AddOrUpdateWorkerPools(Octopus.Client.Model.WorkerPoolResource[]) - Octopus.Client.Model.WorkerMachineResource ClearWorkerPools() - Octopus.Client.Model.WorkerMachineResource RemoveWorkerPool(Octopus.Client.Model.WorkerPoolResource) - } class WorkerPoolResource Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource @@ -4094,6 +4082,18 @@ Octopus.Client.Model .ctor() Octopus.Client.Model.WorkerPoolResource WorkerPool { get; set; } } + class WorkerResource + Octopus.Client.Extensibility.IResource + Octopus.Client.Model.IAuditedResource + Octopus.Client.Extensibility.INamedResource + Octopus.Client.Model.MachineBasedResource + { + .ctor() + Octopus.Client.Model.ReferenceCollection WorkerPoolIds { get; set; } + Octopus.Client.Model.WorkerResource AddOrUpdateWorkerPools(Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Model.WorkerResource ClearWorkerPools() + Octopus.Client.Model.WorkerResource RemoveWorkerPool(Octopus.Client.Model.WorkerPoolResource) + } class X509Certificate { .ctor() @@ -4912,7 +4912,7 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } - interface IRegisterWorkerMachineOperation + interface IRegisterWorkerOperation Octopus.Client.Operations.IRegisterMachineOperationBase { String[] WorkerPoolNames { get; set; } @@ -4952,9 +4952,9 @@ Octopus.Client.Operations Task ExecuteAsync(Octopus.Client.OctopusAsyncRepository) Task ExecuteAsync(Octopus.Client.IOctopusAsyncRepository) } - class RegisterWorkerMachineOperation + class RegisterWorkerOperation Octopus.Client.Operations.IRegisterMachineOperationBase - Octopus.Client.Operations.IRegisterWorkerMachineOperation + Octopus.Client.Operations.IRegisterWorkerOperation Octopus.Client.Operations.RegisterMachineOperationBase { .ctor() @@ -5448,20 +5448,6 @@ Octopus.Client.Repositories { String[] GetVariableNames(String, String[]) } - interface IWorkerMachineRepository - Octopus.Client.Repositories.IFindByName - Octopus.Client.Repositories.IPaginate - Octopus.Client.Repositories.IGet - Octopus.Client.Repositories.ICreate - Octopus.Client.Repositories.IModify - Octopus.Client.Repositories.IDelete - { - Octopus.Client.Editors.WorkerMachineEditor CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) - Octopus.Client.Model.WorkerMachineResource Discover(String, Int32, Nullable) - List FindByThumbprint(String) - Octopus.Client.Model.MachineConnectionStatus GetConnectionStatus(Octopus.Client.Model.WorkerMachineResource) - Octopus.Client.Model.ResourceCollection List(Int32, Nullable, String, String, String, Nullable, String, String, String) - } interface IWorkerPoolRepository Octopus.Client.Repositories.IFindByName Octopus.Client.Repositories.IPaginate @@ -5473,10 +5459,24 @@ Octopus.Client.Repositories { Octopus.Client.Editors.WorkerPoolEditor CreateOrModify(String) Octopus.Client.Editors.WorkerPoolEditor CreateOrModify(String, String) - List GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) + List GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) void Sort(String[]) Octopus.Client.Model.WorkerPoolsSummaryResource Summary(String, String, String, Nullable, String, String, Nullable) } + interface IWorkerRepository + Octopus.Client.Repositories.IFindByName + Octopus.Client.Repositories.IPaginate + Octopus.Client.Repositories.IGet + Octopus.Client.Repositories.ICreate + Octopus.Client.Repositories.IModify + Octopus.Client.Repositories.IDelete + { + Octopus.Client.Editors.WorkerEditor CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Octopus.Client.Model.WorkerResource Discover(String, Int32, Nullable) + List FindByThumbprint(String) + Octopus.Client.Model.MachineConnectionStatus GetConnectionStatus(Octopus.Client.Model.WorkerResource) + Octopus.Client.Model.ResourceCollection List(Int32, Nullable, String, String, String, Nullable, String, String, String) + } } Octopus.Client.Repositories.Async { @@ -5963,20 +5963,6 @@ Octopus.Client.Repositories.Async { Task GetVariableNames(String, String[]) } - interface IWorkerMachineRepository - Octopus.Client.Repositories.Async.IFindByName - Octopus.Client.Repositories.Async.IPaginate - Octopus.Client.Repositories.Async.IGet - Octopus.Client.Repositories.Async.ICreate - Octopus.Client.Repositories.Async.IModify - Octopus.Client.Repositories.Async.IDelete - { - Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) - Task Discover(String, Int32, Nullable) - Task> FindByThumbprint(String) - Task GetConnectionStatus(Octopus.Client.Model.WorkerMachineResource) - Task> List(Int32, Nullable, String, String, String, Nullable, String, String, String) - } interface IWorkerPoolRepository Octopus.Client.Repositories.Async.IFindByName Octopus.Client.Repositories.Async.IPaginate @@ -5988,10 +5974,24 @@ Octopus.Client.Repositories.Async { Task CreateOrModify(String) Task CreateOrModify(String, String) - Task> GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) + Task> GetMachines(Octopus.Client.Model.WorkerPoolResource, Nullable, Nullable, String, Nullable, String, String) Task Sort(String[]) Task Summary(String, String, String, Nullable, String, String, Nullable) } + interface IWorkerRepository + Octopus.Client.Repositories.Async.IFindByName + Octopus.Client.Repositories.Async.IPaginate + Octopus.Client.Repositories.Async.IGet + Octopus.Client.Repositories.Async.ICreate + Octopus.Client.Repositories.Async.IModify + Octopus.Client.Repositories.Async.IDelete + { + Task CreateOrModify(String, Octopus.Client.Model.Endpoints.EndpointResource, Octopus.Client.Model.WorkerPoolResource[]) + Task Discover(String, Int32, Nullable) + Task> FindByThumbprint(String) + Task GetConnectionStatus(Octopus.Client.Model.WorkerResource) + Task> List(Int32, Nullable, String, String, String, Nullable, String, String, String) + } } Octopus.Client.Serialization { diff --git a/source/Octopus.Client/Editors/Async/WorkerMachineEditor.cs b/source/Octopus.Client/Editors/Async/WorkerEditor.cs similarity index 69% rename from source/Octopus.Client/Editors/Async/WorkerMachineEditor.cs rename to source/Octopus.Client/Editors/Async/WorkerEditor.cs index 0ec679f56..6eae3fb0e 100644 --- a/source/Octopus.Client/Editors/Async/WorkerMachineEditor.cs +++ b/source/Octopus.Client/Editors/Async/WorkerEditor.cs @@ -7,18 +7,18 @@ namespace Octopus.Client.Editors.Async { - public class WorkerMachineEditor : IResourceEditor + public class WorkerEditor : IResourceEditor { - private readonly IWorkerMachineRepository repository; + private readonly IWorkerRepository repository; - public WorkerMachineEditor(IWorkerMachineRepository repository) + public WorkerEditor(IWorkerRepository repository) { this.repository = repository; } - public WorkerMachineResource Instance { get; private set; } + public WorkerResource Instance { get; private set; } - public async Task CreateOrModify( + public async Task CreateOrModify( string name, EndpointResource endpoint, WorkerPoolResource[] workerpools) @@ -26,7 +26,7 @@ public async Task CreateOrModify( var existing = await repository.FindByName(name).ConfigureAwait(false); if (existing == null) { - Instance = await repository.Create(new WorkerMachineResource + Instance = await repository.Create(new WorkerResource { Name = name, Endpoint = endpoint, @@ -45,13 +45,13 @@ public async Task CreateOrModify( return this; } - public WorkerMachineEditor Customize(Action customize) + public WorkerEditor Customize(Action customize) { customize?.Invoke(Instance); return this; } - public async Task Save() + public async Task Save() { Instance = await repository.Modify(Instance).ConfigureAwait(false); return this; diff --git a/source/Octopus.Client/Editors/WorkerMachineEditor.cs b/source/Octopus.Client/Editors/WorkerEditor.cs similarity index 67% rename from source/Octopus.Client/Editors/WorkerMachineEditor.cs rename to source/Octopus.Client/Editors/WorkerEditor.cs index 61b90f2f1..75d0a0fb9 100644 --- a/source/Octopus.Client/Editors/WorkerMachineEditor.cs +++ b/source/Octopus.Client/Editors/WorkerEditor.cs @@ -6,18 +6,18 @@ namespace Octopus.Client.Editors { - public class WorkerMachineEditor : IResourceEditor + public class WorkerEditor : IResourceEditor { - private readonly IWorkerMachineRepository repository; + private readonly IWorkerRepository repository; - public WorkerMachineEditor(IWorkerMachineRepository repository) + public WorkerEditor(IWorkerRepository repository) { this.repository = repository; } - public WorkerMachineResource Instance { get; private set; } + public WorkerResource Instance { get; private set; } - public WorkerMachineEditor CreateOrModify( + public WorkerEditor CreateOrModify( string name, EndpointResource endpoint, WorkerPoolResource[] pools) @@ -25,7 +25,7 @@ public WorkerMachineEditor CreateOrModify( var existing = repository.FindByName(name); if (existing == null) { - Instance = repository.Create(new WorkerMachineResource + Instance = repository.Create(new WorkerResource { Name = name, Endpoint = endpoint, @@ -44,13 +44,13 @@ public WorkerMachineEditor CreateOrModify( return this; } - public WorkerMachineEditor Customize(Action customize) + public WorkerEditor Customize(Action customize) { customize?.Invoke(Instance); return this; } - public WorkerMachineEditor Save() + public WorkerEditor Save() { Instance = repository.Modify(Instance); return this; diff --git a/source/Octopus.Client/IOctopusAsyncRepository.cs b/source/Octopus.Client/IOctopusAsyncRepository.cs index 1826d519b..fdc4a7c3e 100644 --- a/source/Octopus.Client/IOctopusAsyncRepository.cs +++ b/source/Octopus.Client/IOctopusAsyncRepository.cs @@ -60,6 +60,6 @@ public interface IOctopusAsyncRepository IUserRolesRepository UserRoles { get; } IVariableSetRepository VariableSets { get; } IWorkerPoolRepository WorkerPools { get; } - IWorkerMachineRepository WorkerMachines { get; } + IWorkerRepository Workers { get; } } } \ No newline at end of file diff --git a/source/Octopus.Client/IOctopusRepository.cs b/source/Octopus.Client/IOctopusRepository.cs index c7dfd881d..81205d1e4 100644 --- a/source/Octopus.Client/IOctopusRepository.cs +++ b/source/Octopus.Client/IOctopusRepository.cs @@ -61,7 +61,7 @@ public interface IOctopusRepository IUserRolesRepository UserRoles { get; } IVariableSetRepository VariableSets { get; } IWorkerPoolRepository WorkerPools { get; } - IWorkerMachineRepository WorkerMachines { get; } + IWorkerRepository Workers { get; } } } #endif \ No newline at end of file diff --git a/source/Octopus.Client/Model/WorkerPoolResource.cs b/source/Octopus.Client/Model/WorkerPoolResource.cs index 84691dcb7..372bf8356 100644 --- a/source/Octopus.Client/Model/WorkerPoolResource.cs +++ b/source/Octopus.Client/Model/WorkerPoolResource.cs @@ -4,7 +4,7 @@ namespace Octopus.Client.Model { /// - /// Represents a pool of worker machines. WorkerPools are user-defined and map to pools of machines that + /// Represents a pool of workers. WorkerPools are user-defined and map to pools of machines that /// can do work as part of a deployment: for example, running scripts and deploying to Azure. /// public class WorkerPoolResource : Resource, INamedResource diff --git a/source/Octopus.Client/Model/WorkerMachineResource.cs b/source/Octopus.Client/Model/WorkerResource.cs similarity index 67% rename from source/Octopus.Client/Model/WorkerMachineResource.cs rename to source/Octopus.Client/Model/WorkerResource.cs index d8363635c..8552f8d99 100644 --- a/source/Octopus.Client/Model/WorkerMachineResource.cs +++ b/source/Octopus.Client/Model/WorkerResource.cs @@ -5,9 +5,9 @@ namespace Octopus.Client.Model { - public class WorkerMachineResource : MachineBasedResource + public class WorkerResource : MachineBasedResource { - public WorkerMachineResource() + public WorkerResource() { WorkerPoolIds = new ReferenceCollection(); } @@ -15,7 +15,7 @@ public WorkerMachineResource() [Writeable] public ReferenceCollection WorkerPoolIds { get; set; } - public WorkerMachineResource AddOrUpdateWorkerPools(params WorkerPoolResource[] pools) + public WorkerResource AddOrUpdateWorkerPools(params WorkerPoolResource[] pools) { foreach (var pool in pools) { @@ -24,13 +24,13 @@ public WorkerMachineResource AddOrUpdateWorkerPools(params WorkerPoolResource[] return this; } - public WorkerMachineResource RemoveWorkerPool(WorkerPoolResource pool) + public WorkerResource RemoveWorkerPool(WorkerPoolResource pool) { WorkerPoolIds.Remove(pool.Id); return this; } - public WorkerMachineResource ClearWorkerPools() + public WorkerResource ClearWorkerPools() { WorkerPoolIds.Clear(); return this; diff --git a/source/Octopus.Client/OctopusAsyncRepository.cs b/source/Octopus.Client/OctopusAsyncRepository.cs index 03c4a727f..0e1ae235f 100644 --- a/source/Octopus.Client/OctopusAsyncRepository.cs +++ b/source/Octopus.Client/OctopusAsyncRepository.cs @@ -74,7 +74,7 @@ public OctopusAsyncRepository(IOctopusAsyncClient client) UserRoles = new UserRolesRepository(client); Users = new UserRepository(client); VariableSets = new VariableSetRepository(client); - WorkerMachines = new WorkerMachineRepository(client); + Workers = new WorkerRepository(client); WorkerPools = new WorkerPoolRepository(client); } @@ -125,6 +125,6 @@ public OctopusAsyncRepository(IOctopusAsyncClient client) public IUserRolesRepository UserRoles { get; } public IVariableSetRepository VariableSets { get; } public IWorkerPoolRepository WorkerPools { get; } - public IWorkerMachineRepository WorkerMachines { get; } + public IWorkerRepository Workers { get; } } } \ No newline at end of file diff --git a/source/Octopus.Client/OctopusRepository.cs b/source/Octopus.Client/OctopusRepository.cs index b6ac8f482..0236987f7 100644 --- a/source/Octopus.Client/OctopusRepository.cs +++ b/source/Octopus.Client/OctopusRepository.cs @@ -68,7 +68,7 @@ public OctopusRepository(IOctopusClient client) UserRoles = new UserRolesRepository(client); Users = new UserRepository(client); VariableSets = new VariableSetRepository(client); - WorkerMachines = new WorkerMachineRepository(client); + Workers = new WorkerRepository(client); WorkerPools = new WorkerPoolRepository(client); } @@ -119,7 +119,7 @@ public OctopusRepository(IOctopusClient client) public IUserRolesRepository UserRoles { get; } public IVariableSetRepository VariableSets { get; } public IWorkerPoolRepository WorkerPools { get; } - public IWorkerMachineRepository WorkerMachines { get; } + public IWorkerRepository Workers { get; } } } #endif \ No newline at end of file diff --git a/source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs b/source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs index 2fb142741..ddf669a6b 100644 --- a/source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs +++ b/source/Octopus.Client/Operations/IRegisterMachineOperationBase.cs @@ -5,7 +5,7 @@ namespace Octopus.Client.Operations { /// - /// Base for registering Deployment Targets and Worker Machines + /// Base for registering Deployment Targets and Workers /// public interface IRegisterMachineOperationBase { diff --git a/source/Octopus.Client/Operations/IRegisterWorkerMachineOperation.cs b/source/Octopus.Client/Operations/IRegisterWorkerOperation.cs similarity index 68% rename from source/Octopus.Client/Operations/IRegisterWorkerMachineOperation.cs rename to source/Octopus.Client/Operations/IRegisterWorkerOperation.cs index d34d52e19..8a255142c 100644 --- a/source/Octopus.Client/Operations/IRegisterWorkerMachineOperation.cs +++ b/source/Octopus.Client/Operations/IRegisterWorkerOperation.cs @@ -5,9 +5,9 @@ namespace Octopus.Client.Operations { /// - /// Encapsulates the operation for registering worker machines. + /// Encapsulates the operation for registering workers. /// - public interface IRegisterWorkerMachineOperation : IRegisterMachineOperationBase + public interface IRegisterWorkerOperation : IRegisterMachineOperationBase { /// /// Gets or sets the worker pools that this machine should be added to. diff --git a/source/Octopus.Client/Operations/RegisterWorkerMachineOperation.cs b/source/Octopus.Client/Operations/RegisterWorkerOperation.cs similarity index 70% rename from source/Octopus.Client/Operations/RegisterWorkerMachineOperation.cs rename to source/Octopus.Client/Operations/RegisterWorkerOperation.cs index 8997a35fa..dbaa6cfee 100644 --- a/source/Octopus.Client/Operations/RegisterWorkerMachineOperation.cs +++ b/source/Octopus.Client/Operations/RegisterWorkerOperation.cs @@ -12,20 +12,20 @@ namespace Octopus.Client.Operations /// /// Encapsulates the operation for registering machines. /// - public class RegisterWorkerMachineOperation : RegisterMachineOperationBase, IRegisterWorkerMachineOperation + public class RegisterWorkerOperation : RegisterMachineOperationBase, IRegisterWorkerOperation { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public RegisterWorkerMachineOperation() : this(null) + public RegisterWorkerOperation() : this(null) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The client factory. - public RegisterWorkerMachineOperation(IOctopusClientFactory clientFactory) : base(clientFactory) + public RegisterWorkerOperation(IOctopusClientFactory clientFactory) : base(clientFactory) { } @@ -47,7 +47,7 @@ public override void Execute(IOctopusRepository repository) { var selectedPools = GetWorkerPools(repository); var machinePolicy = GetMachinePolicy(repository); - var machine = GetWorkerMachine(repository); + var machine = GetWorker(repository); var proxy = GetProxy(repository); ApplyBaseChanges(machine, machinePolicy, proxy); @@ -55,9 +55,9 @@ public override void Execute(IOctopusRepository repository) machine.WorkerPoolIds = new ReferenceCollection(selectedPools.Select(p => p.Id).ToArray()); if (machine.Id != null) - repository.WorkerMachines.Modify(machine); + repository.Workers.Modify(machine); else - repository.WorkerMachines.Create(machine); + repository.Workers.Create(machine); } List GetWorkerPools(IOctopusRepository repository) @@ -72,19 +72,19 @@ List GetWorkerPools(IOctopusRepository repository) return selectedPools; } - WorkerMachineResource GetWorkerMachine(IOctopusRepository repository) + WorkerResource GetWorker(IOctopusRepository repository) { - var existing = default(WorkerMachineResource); + var existing = default(WorkerResource); try { - existing = repository.WorkerMachines.FindByName(MachineName); + existing = repository.Workers.FindByName(MachineName); if (!AllowOverwrite && existing?.Id != null) - throw new ArgumentException($"A worker machine named '{MachineName}' already exists. Use the 'force' parameter if you intended to update the existing machine."); + throw new ArgumentException($"A worker named '{MachineName}' already exists. Use the 'force' parameter if you intended to update the existing machine."); } catch (OctopusDeserializationException) // eat it, probably caused by resource incompatability between versions { } - return existing ?? new WorkerMachineResource(); + return existing ?? new WorkerResource(); } #endif @@ -98,7 +98,7 @@ public override async Task ExecuteAsync(IOctopusAsyncRepository repository) { var selectedPools = GetWorkerPools(repository).ConfigureAwait(false); var machinePolicy = GetMachinePolicy(repository).ConfigureAwait(false); - var machineTask = GetWorkerMachine(repository).ConfigureAwait(false); + var machineTask = GetWorker(repository).ConfigureAwait(false); var proxy = GetProxy(repository).ConfigureAwait(false); var machine = await machineTask; @@ -107,9 +107,9 @@ public override async Task ExecuteAsync(IOctopusAsyncRepository repository) machine.WorkerPoolIds = new ReferenceCollection((await selectedPools).Select(p => p.Id).ToArray()); if (machine.Id != null) - await repository.WorkerMachines.Modify(machine).ConfigureAwait(false); + await repository.Workers.Modify(machine).ConfigureAwait(false); else - await repository.WorkerMachines.Create(machine).ConfigureAwait(false); + await repository.Workers.Create(machine).ConfigureAwait(false); } async Task> GetWorkerPools(IOctopusAsyncRepository repository) @@ -124,19 +124,19 @@ async Task> GetWorkerPools(IOctopusAsyncRepository repo return selectedPools; } - async Task GetWorkerMachine(IOctopusAsyncRepository repository) + async Task GetWorker(IOctopusAsyncRepository repository) { - var existing = default(WorkerMachineResource); + var existing = default(WorkerResource); try { - existing = await repository.WorkerMachines.FindByName(MachineName).ConfigureAwait(false); + existing = await repository.Workers.FindByName(MachineName).ConfigureAwait(false); if (!AllowOverwrite && existing?.Id != null) - throw new ArgumentException($"A worker machine named '{MachineName}' already exists. Use the 'force' parameter if you intended to update the existing machine."); + throw new ArgumentException($"A worker named '{MachineName}' already exists. Use the 'force' parameter if you intended to update the existing machine."); } catch (OctopusDeserializationException) // eat it, probably caused by resource incompatability between versions { } - return existing ?? new WorkerMachineResource(); + return existing ?? new WorkerResource(); } } } \ No newline at end of file diff --git a/source/Octopus.Client/Repositories/Async/TaskRepository.cs b/source/Octopus.Client/Repositories/Async/TaskRepository.cs index 3e25d37c4..033143312 100644 --- a/source/Octopus.Client/Repositories/Async/TaskRepository.cs +++ b/source/Octopus.Client/Repositories/Async/TaskRepository.cs @@ -10,10 +10,10 @@ namespace Octopus.Client.Repositories.Async { public interface ITaskRepository : IPaginate, IGet, ICreate { - Task ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null); + Task ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workerIds = null); Task ExecuteCalamariUpdate(string description = null, string[] machineIds = null); Task ExecuteBackup(string description = null); - Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpooltId = null, string[] workermachineIds = null); + Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpooltId = null, string[] workerIds = null); Task ExecuteAdHocScript(string scriptBody, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null, string syntax = "PowerShell"); Task GetDetails(TaskResource resource, bool? includeVerboseOutput = null, int? tail = null); Task ExecuteActionTemplate(ActionTemplateResource resource, Dictionary properties, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null); @@ -39,7 +39,7 @@ public TaskRepository(IOctopusAsyncClient client) public Task ExecuteHealthCheck( string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, - string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null) + string restrictTo = null, string workerpoolId = null, string[] workerIds = null) { var resource = new TaskResource(); resource.Name = BuiltInTasks.Health.Name; @@ -51,7 +51,7 @@ public Task ExecuteHealthCheck( {BuiltInTasks.Health.Arguments.EnvironmentId, environmentId}, {BuiltInTasks.Health.Arguments.WorkerpoolId, workerpoolId}, {BuiltInTasks.Health.Arguments.RestrictedTo, restrictTo}, - {BuiltInTasks.Health.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} + {BuiltInTasks.Health.Arguments.MachineIds, machineIds?.Concat(workerIds ?? new string[0]).ToArray() ?? workerIds} }; return Create(resource); } @@ -76,7 +76,7 @@ public Task ExecuteBackup(string description = null) return Create(resource); } - public Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null) + public Task ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workerIds = null) { var resource = new TaskResource(); resource.Name = BuiltInTasks.Upgrade.Name; @@ -86,7 +86,7 @@ public Task ExecuteTentacleUpgrade(string description = null, stri {BuiltInTasks.Upgrade.Arguments.EnvironmentId, environmentId}, {BuiltInTasks.Upgrade.Arguments.WorkerpoolId, workerpoolId}, {BuiltInTasks.Upgrade.Arguments.RestrictedTo, restrictTo}, - {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} + {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds?.Concat(workerIds ?? new string[0]).ToArray() ?? workerIds} }; return Create(resource); } diff --git a/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs b/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs deleted file mode 100644 index 62049fad1..000000000 --- a/source/Octopus.Client/Repositories/Async/WorkerMachineRepository.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Octopus.Client.Editors.Async; -using Octopus.Client.Model; -using Octopus.Client.Model.Endpoints; - -namespace Octopus.Client.Repositories.Async -{ - public interface IWorkerMachineRepository : IFindByName, IGet, ICreate, IModify, IDelete - { - Task Discover(string host, int port = 10933, DiscoverableEndpointType? discoverableEndpointType = null); - Task GetConnectionStatus(WorkerMachineResource machine); - Task> FindByThumbprint(string thumbprint); - - Task CreateOrModify( - string name, - EndpointResource endpoint, - WorkerPoolResource[] pools); - - Task> List(int skip = 0, - int? take = null, - string ids = null, - string name = null, - string partialName = null, - bool? isDisabled = false, - string healthStatuses = null, - string commStyles = null, - string workerpoolIds = null); - } - - class WorkerMachineRepository : BasicRepository, IWorkerMachineRepository - { - public WorkerMachineRepository(IOctopusAsyncClient client) : base(client, "Workers") - { - } - - public Task Discover(string host, int port = 10933, DiscoverableEndpointType? type = null) - { - return Client.Get(Client.RootDocument.Link("DiscoverMachine"), new { host, port, type }); - } - - public Task GetConnectionStatus(WorkerMachineResource workerMachine) - { - if (workerMachine == null) throw new ArgumentNullException("workerMachine"); - return Client.Get(workerMachine.Link("Connection")); - } - - public Task> FindByThumbprint(string thumbprint) - { - if (thumbprint == null) throw new ArgumentNullException("thumbprint"); - return Client.Get>(Client.RootDocument.Link("Workers"), new { id = "all", thumbprint }); - } - - public Task CreateOrModify( - string name, - EndpointResource endpoint, - WorkerPoolResource[] workerpools) - { - return new WorkerMachineEditor(this).CreateOrModify(name, endpoint, workerpools); - } - - public Task> List(int skip = 0, - int? take = null, - string ids = null, - string name = null, - string partialName = null, - bool? isDisabled = false, - string healthStatuses = null, - string commStyles = null, - string workerpoolIds = null) - { - return Client.List(Client.RootDocument.Link("Workers"), new - { - skip, - take, - ids, - name, - partialName, - isDisabled, - healthStatuses, - commStyles, - workerpoolIds - }); - } - } -} diff --git a/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs b/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs index d104fcd82..33f176802 100644 --- a/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs +++ b/source/Octopus.Client/Repositories/Async/WorkerPoolRepository.cs @@ -8,7 +8,7 @@ namespace Octopus.Client.Repositories.Async { public interface IWorkerPoolRepository : IFindByName, IGet, ICreate, IModify, IDelete, IGetAll { - Task> GetMachines(WorkerPoolResource workerPool, + Task> GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -35,7 +35,7 @@ public WorkerPoolRepository(IOctopusAsyncClient client) { } - public async Task> GetMachines(WorkerPoolResource workerPool, + public async Task> GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -43,9 +43,9 @@ public async Task> GetMachines(WorkerPoolResource wo string healthStatuses = null, string commStyles = null) { - var resources = new List(); + var resources = new List(); - await Client.Paginate(workerPool.Link("WorkerMachines"), new { + await Client.Paginate(workerPool.Link("Workers"), new { skip, take, partialName, diff --git a/source/Octopus.Client/Repositories/Async/WorkerRepository.cs b/source/Octopus.Client/Repositories/Async/WorkerRepository.cs new file mode 100644 index 000000000..e6a2313be --- /dev/null +++ b/source/Octopus.Client/Repositories/Async/WorkerRepository.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Octopus.Client.Editors.Async; +using Octopus.Client.Model; +using Octopus.Client.Model.Endpoints; + +namespace Octopus.Client.Repositories.Async +{ + public interface IWorkerRepository : IFindByName, IGet, ICreate, IModify, IDelete + { + Task Discover(string host, int port = 10933, DiscoverableEndpointType? discoverableEndpointType = null); + Task GetConnectionStatus(WorkerResource machine); + Task> FindByThumbprint(string thumbprint); + + Task CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] pools); + + Task> List(int skip = 0, + int? take = null, + string ids = null, + string name = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + string workerpoolIds = null); + } + + class WorkerRepository : BasicRepository, IWorkerRepository + { + public WorkerRepository(IOctopusAsyncClient client) : base(client, "Workers") + { + } + + public Task Discover(string host, int port = 10933, DiscoverableEndpointType? type = null) + { + return Client.Get(Client.RootDocument.Link("DiscoverMachine"), new { host, port, type }); + } + + public Task GetConnectionStatus(WorkerResource worker) + { + if (worker == null) throw new ArgumentNullException("worker"); + return Client.Get(worker.Link("Connection")); + } + + public Task> FindByThumbprint(string thumbprint) + { + if (thumbprint == null) throw new ArgumentNullException("thumbprint"); + return Client.Get>(Client.RootDocument.Link("Workers"), new { id = "all", thumbprint }); + } + + public Task CreateOrModify( + string name, + EndpointResource endpoint, + WorkerPoolResource[] workerpools) + { + return new WorkerEditor(this).CreateOrModify(name, endpoint, workerpools); + } + + public Task> List(int skip = 0, + int? take = null, + string ids = null, + string name = null, + string partialName = null, + bool? isDisabled = false, + string healthStatuses = null, + string commStyles = null, + string workerpoolIds = null) + { + return Client.List(Client.RootDocument.Link("Workers"), new + { + skip, + take, + ids, + name, + partialName, + isDisabled, + healthStatuses, + commStyles, + workerpoolIds + }); + } + } +} diff --git a/source/Octopus.Client/Repositories/TaskRepository.cs b/source/Octopus.Client/Repositories/TaskRepository.cs index 876968e33..be2eb46cf 100644 --- a/source/Octopus.Client/Repositories/TaskRepository.cs +++ b/source/Octopus.Client/Repositories/TaskRepository.cs @@ -9,10 +9,10 @@ namespace Octopus.Client.Repositories { public interface ITaskRepository : IPaginate, IGet, ICreate { - TaskResource ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null); + TaskResource ExecuteHealthCheck(string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workerIds = null); TaskResource ExecuteCalamariUpdate(string description = null, string[] machineIds = null); TaskResource ExecuteBackup(string description = null); - TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null); + TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workerIds = null); TaskResource ExecuteAdHocScript(string scriptBody, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null, string syntax = "PowerShell"); TaskResource ExecuteActionTemplate(ActionTemplateResource resource, Dictionary properties, string[] machineIds = null, string[] environmentIds = null, string[] targetRoles = null, string description = null); TaskResource ExecuteCommunityActionTemplatesSynchronisation(string description = null); @@ -37,7 +37,7 @@ public TaskRepository(IOctopusClient client) public TaskResource ExecuteHealthCheck( string description = null, int timeoutAfterMinutes = 5, int machineTimeoutAfterMinutes = 1, string environmentId = null, string[] machineIds = null, - string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null + string restrictTo = null, string workerpoolId = null, string[] workerIds = null ) { var resource = new TaskResource(); @@ -50,7 +50,7 @@ public TaskResource ExecuteHealthCheck( {BuiltInTasks.Health.Arguments.EnvironmentId, environmentId}, {BuiltInTasks.Health.Arguments.WorkerpoolId, workerpoolId}, {BuiltInTasks.Health.Arguments.RestrictedTo, restrictTo}, - {BuiltInTasks.Health.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} + {BuiltInTasks.Health.Arguments.MachineIds, machineIds?.Concat(workerIds ?? new string[0]).ToArray() ?? workerIds} }; return Create(resource); } @@ -75,7 +75,7 @@ public TaskResource ExecuteBackup(string description = null) return Create(resource); } - public TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workermachineIds = null) + public TaskResource ExecuteTentacleUpgrade(string description = null, string environmentId = null, string[] machineIds = null, string restrictTo = null, string workerpoolId = null, string[] workerIds = null) { var resource = new TaskResource(); resource.Name = BuiltInTasks.Upgrade.Name; @@ -85,7 +85,7 @@ public TaskResource ExecuteTentacleUpgrade(string description = null, string env {BuiltInTasks.Upgrade.Arguments.EnvironmentId, environmentId}, {BuiltInTasks.Upgrade.Arguments.WorkerpoolId, workerpoolId}, {BuiltInTasks.Upgrade.Arguments.RestrictedTo, restrictTo}, - {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds?.Concat(workermachineIds ?? new string[0]).ToArray() ?? workermachineIds} + {BuiltInTasks.Upgrade.Arguments.MachineIds, machineIds?.Concat(workerIds ?? new string[0]).ToArray() ?? workerIds} }; return Create(resource); } diff --git a/source/Octopus.Client/Repositories/WorkerPoolRepository.cs b/source/Octopus.Client/Repositories/WorkerPoolRepository.cs index a8cafd702..bddbf5e67 100644 --- a/source/Octopus.Client/Repositories/WorkerPoolRepository.cs +++ b/source/Octopus.Client/Repositories/WorkerPoolRepository.cs @@ -6,7 +6,7 @@ namespace Octopus.Client.Repositories { public interface IWorkerPoolRepository : IFindByName, IGet, ICreate, IModify, IDelete, IGetAll { - List GetMachines(WorkerPoolResource workerPool, + List GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -33,7 +33,7 @@ public WorkerPoolRepository(IOctopusClient client) { } - public List GetMachines(WorkerPoolResource workerPool, + public List GetMachines(WorkerPoolResource workerPool, int? skip = 0, int? take = null, string partialName = null, @@ -41,9 +41,9 @@ public List GetMachines(WorkerPoolResource workerPool, string healthStatuses = null, string commStyles = null) { - var resources = new List(); + var resources = new List(); - Client.Paginate(workerPool.Link("WorkerMachines"), new + Client.Paginate(workerPool.Link("Workers"), new { skip, take, diff --git a/source/Octopus.Client/Repositories/WorkerMachineRepository.cs b/source/Octopus.Client/Repositories/WorkerRepository.cs similarity index 52% rename from source/Octopus.Client/Repositories/WorkerMachineRepository.cs rename to source/Octopus.Client/Repositories/WorkerRepository.cs index 4c817c48d..f35bca3ea 100644 --- a/source/Octopus.Client/Repositories/WorkerMachineRepository.cs +++ b/source/Octopus.Client/Repositories/WorkerRepository.cs @@ -6,18 +6,18 @@ namespace Octopus.Client.Repositories { - public interface IWorkerMachineRepository : IFindByName, IGet, ICreate, IModify, IDelete + public interface IWorkerRepository : IFindByName, IGet, ICreate, IModify, IDelete { - WorkerMachineResource Discover(string host, int port = 10933, DiscoverableEndpointType? discoverableEndpointType = null); - MachineConnectionStatus GetConnectionStatus(WorkerMachineResource machine); - List FindByThumbprint(string thumbprint); + WorkerResource Discover(string host, int port = 10933, DiscoverableEndpointType? discoverableEndpointType = null); + MachineConnectionStatus GetConnectionStatus(WorkerResource machine); + List FindByThumbprint(string thumbprint); - WorkerMachineEditor CreateOrModify( + WorkerEditor CreateOrModify( string name, EndpointResource endpoint, WorkerPoolResource[] pools); - ResourceCollection List(int skip = 0, + ResourceCollection List(int skip = 0, int? take = null, string ids = null, string name = null, @@ -28,39 +28,39 @@ ResourceCollection List(int skip = 0, string workerpoolIds = null); } - class WorkerMachineRepository : BasicRepository, IWorkerMachineRepository + class WorkerRepository : BasicRepository, IWorkerRepository { - public WorkerMachineRepository(IOctopusClient client) : base(client, "Workers") + public WorkerRepository(IOctopusClient client) : base(client, "Workers") { } - public WorkerMachineResource Discover(string host, int port = 10933, DiscoverableEndpointType? type = null) + public WorkerResource Discover(string host, int port = 10933, DiscoverableEndpointType? type = null) { - return Client.Get(Client.RootDocument.Link("DiscoverMachine"), new { host, port, type }); + return Client.Get(Client.RootDocument.Link("DiscoverMachine"), new { host, port, type }); } - public MachineConnectionStatus GetConnectionStatus(WorkerMachineResource machine) + public MachineConnectionStatus GetConnectionStatus(WorkerResource machine) { if (machine == null) throw new ArgumentNullException("machine"); return Client.Get(machine.Link("Connection")); } - public List FindByThumbprint(string thumbprint) + public List FindByThumbprint(string thumbprint) { if (thumbprint == null) throw new ArgumentNullException("thumbprint"); - return Client.Get>(Client.RootDocument.Link("Workers"), new { id = "all", thumbprint }); + return Client.Get>(Client.RootDocument.Link("Workers"), new { id = "all", thumbprint }); } - public WorkerMachineEditor CreateOrModify( + public WorkerEditor CreateOrModify( string name, EndpointResource endpoint, WorkerPoolResource[] pools) { - return new WorkerMachineEditor(this).CreateOrModify(name, endpoint, pools); + return new WorkerEditor(this).CreateOrModify(name, endpoint, pools); } - public ResourceCollection List(int skip = 0, + public ResourceCollection List(int skip = 0, int? take = null, string ids = null, string name = null, @@ -70,7 +70,7 @@ public ResourceCollection List(int skip = 0, string commStyles = null, string workerpoolIds = null) { - return Client.List(Client.RootDocument.Link("workers"), new + return Client.List(Client.RootDocument.Link("workers"), new { skip, take, From 99f586336eb6d4a9f5b1534cbe41a1d89406b971 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 4 Jun 2018 17:49:13 +1000 Subject: [PATCH 34/37] remove workers from scopes --- source/Octopus.Cli/Model/ProjectExport.cs | 3 ++- ....ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt | 2 -- ...ublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt | 2 -- source/Octopus.Client/Model/ScopeField.cs | 3 +-- source/Octopus.Client/Model/VariableScopeValues.cs | 2 -- 5 files changed, 3 insertions(+), 9 deletions(-) diff --git a/source/Octopus.Cli/Model/ProjectExport.cs b/source/Octopus.Cli/Model/ProjectExport.cs index f9257512f..b90f2d54e 100644 --- a/source/Octopus.Cli/Model/ProjectExport.cs +++ b/source/Octopus.Cli/Model/ProjectExport.cs @@ -14,6 +14,7 @@ public class ProjectExport public List LibraryVariableSets { get; set; } public ReferenceDataItem Lifecycle { get; set; } public List Channels { get; set; } - public List ChannelLifecycles { get; set; } + public List ChannelLifecycles { get; set; } + public List WorkerPools { get; set; } } } \ No newline at end of file diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index a35fb91ef..cd474841f 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -2887,7 +2887,6 @@ Octopus.Client.Model Channel = 8 TenantTag = 9 Tenant = 10 - WorkerPool = 11 } class ScopeSpecification IDictionary @@ -3484,7 +3483,6 @@ Octopus.Client.Model List Machines { get; set; } List Roles { get; set; } List TenantTags { get; set; } - List WorkerPools { get; set; } } VariableSetContentType { diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index 45f65c926..89712ab92 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -3385,7 +3385,6 @@ Octopus.Client.Model Channel = 8 TenantTag = 9 Tenant = 10 - WorkerPool = 11 } class ScopeSpecification IDictionary @@ -3987,7 +3986,6 @@ Octopus.Client.Model List Machines { get; set; } List Roles { get; set; } List TenantTags { get; set; } - List WorkerPools { get; set; } } VariableSetContentType { diff --git a/source/Octopus.Client/Model/ScopeField.cs b/source/Octopus.Client/Model/ScopeField.cs index 9aad006e0..8c00754c3 100644 --- a/source/Octopus.Client/Model/ScopeField.cs +++ b/source/Octopus.Client/Model/ScopeField.cs @@ -14,7 +14,6 @@ public enum ScopeField Private, // Allows inbuilt vars to override user ones Channel, TenantTag, - Tenant, - WorkerPool + Tenant } } \ No newline at end of file diff --git a/source/Octopus.Client/Model/VariableScopeValues.cs b/source/Octopus.Client/Model/VariableScopeValues.cs index 4871dd6df..a934b8022 100644 --- a/source/Octopus.Client/Model/VariableScopeValues.cs +++ b/source/Octopus.Client/Model/VariableScopeValues.cs @@ -7,7 +7,6 @@ public class VariableScopeValues : IVariableScopeValues public VariableScopeValues() { Environments = new List(); - WorkerPools = new List(); Machines = new List(); Actions = new List(); Roles = new List(); @@ -16,7 +15,6 @@ public VariableScopeValues() } public List Environments { get; set; } - public List WorkerPools { get; set; } public List Machines { get; set; } public List Actions { get; set; } public List Roles { get; set; } From 64733ee2990e372b36487ee52d119bc72f74b87d Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Mon, 4 Jun 2018 17:50:16 +1000 Subject: [PATCH 35/37] workers as ReferencedDataItem in export/import --- .../Octopus.Cli/Exporters/ProjectExporter.cs | 23 +++++++++++++++++++ .../Octopus.Cli/Importers/ProjectImporter.cs | 15 +++--------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/source/Octopus.Cli/Exporters/ProjectExporter.cs b/source/Octopus.Cli/Exporters/ProjectExporter.cs index c07ba8f83..3bb4624ce 100644 --- a/source/Octopus.Cli/Exporters/ProjectExporter.cs +++ b/source/Octopus.Cli/Exporters/ProjectExporter.cs @@ -125,6 +125,28 @@ protected override async Task Export(Dictionary parameters) } } + Log.Debug("Finding all worker pools for deployment process..."); + var workerPools = new List(); + foreach (var step in deploymentProcess.Steps) + { + foreach (var action in step.Actions) + { + if (!string.IsNullOrWhiteSpace(action.WorkerPoolId)) + { + Log.Debug("Finding worker pool for action {ActionName:l}", action.Name); + var pool = await Repository.WorkerPools.Get(action.WorkerPoolId).ConfigureAwait(false); + + if (pool == null) + throw new CouldNotFindException("Worker pool feed for step", step.Name); + + if (workerPools.All(wp => wp.Id != pool.Id)) + { + workerPools.Add(new ReferenceDataItem(pool.Id, pool.Name)); + } + } + } + } + var libraryVariableSets = new List(); foreach (var libraryVariableSetId in project.IncludedLibraryVariableSetIds) { @@ -158,6 +180,7 @@ protected override async Task Export(Dictionary parameters) Lifecycle = lifecycle != null ? new ReferenceDataItem(lifecycle.Id, lifecycle.Name) : null, Channels = channels.ToList(), ChannelLifecycles = channelLifecycles, + WorkerPools = workerPools }; var metadata = new ExportMetadata diff --git a/source/Octopus.Cli/Importers/ProjectImporter.cs b/source/Octopus.Cli/Importers/ProjectImporter.cs index 8739e4ec4..1c5142bd0 100644 --- a/source/Octopus.Cli/Importers/ProjectImporter.cs +++ b/source/Octopus.Cli/Importers/ProjectImporter.cs @@ -73,17 +73,18 @@ protected override async Task Validate(Dictionary paramDic var projectGroup = importedObject.ProjectGroup; var channels = importedObject.Channels; var channelLifecycles = importedObject.ChannelLifecycles; + var workerPools = importedObject.WorkerPools; var scopeValuesUsed = GetScopeValuesUsed(variableSet.Variables, deploymentProcess.Steps, variableSet.ScopeValues); var environmentChecksTask = CheckEnvironmentsExist(scopeValuesUsed[ScopeField.Environment]).ConfigureAwait(false); - var workerPoolChecksTask = CheckWorkerPoolsExist(scopeValuesUsed[ScopeField.WorkerPool]).ConfigureAwait(false); var machineChecksTask = CheckMachinesExist(scopeValuesUsed[ScopeField.Machine]).ConfigureAwait(false); var feedChecksTask = CheckNuGetFeedsExist(nugetFeeds).ConfigureAwait(false); var templateChecksTask = CheckActionTemplates(actionTemplates).ConfigureAwait(false); var libraryVariableSetChecksTask = CheckLibraryVariableSets(libVariableSets).ConfigureAwait(false); var projectGroupChecksTask = CheckProjectGroup(projectGroup).ConfigureAwait(false); var channelLifecycleChecksTask = CheckChannelLifecycles(channelLifecycles).ConfigureAwait(false); + var workerPoolChecksTask = CheckWorkerPoolsExist(workerPools).ConfigureAwait(false); var environmentChecks = await environmentChecksTask; var workerPoolChecks = await workerPoolChecksTask; @@ -237,8 +238,7 @@ protected Dictionary> GetScopeValuesUsed(ILi { {ScopeField.Environment, new List()}, {ScopeField.Machine, new List()}, - {ScopeField.Channel, new List()}, - {ScopeField.WorkerPool, new List()}, + {ScopeField.Channel, new List()} }; foreach (var variable in variables) @@ -304,15 +304,6 @@ protected Dictionary> GetScopeValuesUsed(ILi usedScopeValues[ScopeField.Channel].Add(channel); } } - - if (!string.IsNullOrWhiteSpace(action.WorkerPoolId)) - { - var pool = variableScopeValues.WorkerPools.Find(p => p.Id == action.WorkerPoolId); - if (pool != null && !usedScopeValues[ScopeField.WorkerPool].Exists(p => p.Id == action.WorkerPoolId)) - { - usedScopeValues[ScopeField.WorkerPool].Add(pool); - } - } } } From f99b06706b85e9960102bab82a2f4c42630ed4c2 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Tue, 5 Jun 2018 16:55:19 +1000 Subject: [PATCH 36/37] Revert "move deployment target fluent functions to extensions" This reverts commit d200dc739e289e0c538e7c082f1366595080e1e4. part of removing DeploymentTargetResource --- ...AreaShouldNotRegress..NETCore.approved.txt | 27 ++--- ...houldNotRegress..NETFramework.approved.txt | 27 ++--- .../DeploymentTargetResourceExtensions.cs | 108 ------------------ .../Model/DeploymentTargetResource.cs | 84 ++++++++++++++ 4 files changed, 108 insertions(+), 138 deletions(-) delete mode 100644 source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 2043faf39..732347901 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -710,21 +710,6 @@ Octopus.Client.Extensibility.Extensions.Infrastructure.Configuration } Octopus.Client.Extensions { - abstract class DeploymentTargetResourceExtensions - { - static Octopus.Client.Extensions.T AddOrUpdateEnvironments(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource[]) - static Octopus.Client.Extensions.T AddOrUpdateRoles(Octopus.Client.Extensions.T, String[]) - static Octopus.Client.Extensions.T AddOrUpdateTenants(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource[]) - static Octopus.Client.Extensions.T AddOrUpdateTenantTags(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource[]) - static Octopus.Client.Extensions.T ClearEnvironments(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T ClearRoles(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T ClearTenants(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T ClearTenantTags(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T RemoveEnvironment(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource) - static Octopus.Client.Extensions.T RemoveRole(Octopus.Client.Extensions.T, String) - static Octopus.Client.Extensions.T RemoveTenant(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource) - static Octopus.Client.Extensions.T RemoveTenantTag(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource) - } abstract class StringExtensions { static String CommaSeperate(IEnumerable) @@ -1704,6 +1689,18 @@ Octopus.Client.Model Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) + Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() + Octopus.Client.Model.DeploymentTargetResource ClearRoles() + Octopus.Client.Model.DeploymentTargetResource ClearTenants() + Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() + Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) + Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) + Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) + Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index a866a6e1e..a28fedc61 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -1204,21 +1204,6 @@ Octopus.Client.Extensibility.Extensions.Infrastructure.Configuration } Octopus.Client.Extensions { - abstract class DeploymentTargetResourceExtensions - { - static Octopus.Client.Extensions.T AddOrUpdateEnvironments(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource[]) - static Octopus.Client.Extensions.T AddOrUpdateRoles(Octopus.Client.Extensions.T, String[]) - static Octopus.Client.Extensions.T AddOrUpdateTenants(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource[]) - static Octopus.Client.Extensions.T AddOrUpdateTenantTags(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource[]) - static Octopus.Client.Extensions.T ClearEnvironments(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T ClearRoles(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T ClearTenants(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T ClearTenantTags(Octopus.Client.Extensions.T) - static Octopus.Client.Extensions.T RemoveEnvironment(Octopus.Client.Extensions.T, Octopus.Client.Model.EnvironmentResource) - static Octopus.Client.Extensions.T RemoveRole(Octopus.Client.Extensions.T, String) - static Octopus.Client.Extensions.T RemoveTenant(Octopus.Client.Extensions.T, Octopus.Client.Model.TenantResource) - static Octopus.Client.Extensions.T RemoveTenantTag(Octopus.Client.Extensions.T, Octopus.Client.Model.TagResource) - } abstract class StringExtensions { static String CommaSeperate(IEnumerable) @@ -2199,6 +2184,18 @@ Octopus.Client.Model Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) + Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) + Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() + Octopus.Client.Model.DeploymentTargetResource ClearRoles() + Octopus.Client.Model.DeploymentTargetResource ClearTenants() + Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() + Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) + Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) + Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) + Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource diff --git a/source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs b/source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs deleted file mode 100644 index 7cb5e0f3e..000000000 --- a/source/Octopus.Client/Extensions/DeploymentTargetResourceExtensions.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Octopus.Client.Model; - -namespace Octopus.Client.Extensions -{ - public static class DeploymentTargetResourceExtensions - { - public static T AddOrUpdateEnvironments(this T deploymentTarget, params EnvironmentResource[] environments) - where T : DeploymentTargetResource - { - foreach (var environment in environments) - { - deploymentTarget.EnvironmentIds.Add(environment.Id); - } - return deploymentTarget; - } - - public static T RemoveEnvironment(this T deploymentTarget, EnvironmentResource environment) - where T : DeploymentTargetResource - { - deploymentTarget.EnvironmentIds.Remove(environment.Id); - return deploymentTarget; - } - - public static T ClearEnvironments(this T deploymentTarget) - where T : DeploymentTargetResource - { - deploymentTarget.EnvironmentIds.Clear(); - return deploymentTarget; - } - - public static T AddOrUpdateRoles(this T deploymentTarget, params string[] roles) - where T : DeploymentTargetResource - { - foreach (var role in roles) - { - deploymentTarget.Roles.Add(role); - } - return deploymentTarget; - } - - public static T RemoveRole(this T deploymentTarget, string role) - where T : DeploymentTargetResource - { - deploymentTarget.Roles.Remove(role); - return deploymentTarget; - } - - public static T ClearRoles(this T deploymentTarget) - where T : DeploymentTargetResource - { - deploymentTarget.Roles.Clear(); - return deploymentTarget; - } - - public static T AddOrUpdateTenants(this T deploymentTarget, params TenantResource[] tenants) - where T : DeploymentTargetResource - { - foreach (var tenant in tenants) - { - deploymentTarget.TenantIds.Add(tenant.Id); - } - return deploymentTarget; - } - - public static T RemoveTenant(this T deploymentTarget, TenantResource tenant) - where T : DeploymentTargetResource - { - deploymentTarget.TenantIds.Remove(tenant.Id); - return deploymentTarget; - } - - public static T ClearTenants(this T deploymentTarget) - where T : DeploymentTargetResource - { - deploymentTarget.TenantIds.Clear(); - return deploymentTarget; - } - - public static T AddOrUpdateTenantTags(this T deploymentTarget, params TagResource[] tenantTags) - where T : DeploymentTargetResource - { - foreach (var tenantTag in tenantTags) - { - deploymentTarget.TenantTags.Add(tenantTag.CanonicalTagName); - } - return deploymentTarget; - } - - public static T RemoveTenantTag(this T deploymentTarget, TagResource tenantTag) - where T : DeploymentTargetResource - { - deploymentTarget.TenantTags.Remove(tenantTag.CanonicalTagName); - return deploymentTarget; - } - - public static T ClearTenantTags(this T deploymentTarget) - where T : DeploymentTargetResource - { - deploymentTarget.TenantTags.Clear(); - return deploymentTarget; - } - } -} diff --git a/source/Octopus.Client/Model/DeploymentTargetResource.cs b/source/Octopus.Client/Model/DeploymentTargetResource.cs index f1ec647c9..9d1505ed2 100644 --- a/source/Octopus.Client/Model/DeploymentTargetResource.cs +++ b/source/Octopus.Client/Model/DeploymentTargetResource.cs @@ -45,5 +45,89 @@ public TenantedDeploymentMode TenantedDeploymentParticipation [Writeable] public ReferenceCollection TenantTags { get; set; } + + public DeploymentTargetResource AddOrUpdateEnvironments(params EnvironmentResource[] environments) + { + foreach (var environment in environments) + { + EnvironmentIds.Add(environment.Id); + } + return this; + } + + public DeploymentTargetResource RemoveEnvironment(EnvironmentResource environment) + { + EnvironmentIds.Remove(environment.Id); + return this; + } + + public DeploymentTargetResource ClearEnvironments() + { + EnvironmentIds.Clear(); + return this; + } + + public DeploymentTargetResource AddOrUpdateRoles(params string[] roles) + { + foreach (var role in roles) + { + Roles.Add(role); + } + return this; + } + + public DeploymentTargetResource RemoveRole(string role) + { + Roles.Remove(role); + return this; + } + + public DeploymentTargetResource ClearRoles() + { + Roles.Clear(); + return this; + } + + public DeploymentTargetResource AddOrUpdateTenants(params TenantResource[] tenants) + { + foreach (var tenant in tenants) + { + TenantIds.Add(tenant.Id); + } + return this; + } + + public DeploymentTargetResource RemoveTenant(TenantResource tenant) + { + TenantIds.Remove(tenant.Id); + return this; + } + + public DeploymentTargetResource ClearTenants() + { + TenantIds.Clear(); + return this; + } + + public DeploymentTargetResource AddOrUpdateTenantTags(params TagResource[] tenantTags) + { + foreach (var tenantTag in tenantTags) + { + TenantTags.Add(tenantTag.CanonicalTagName); + } + return this; + } + + public DeploymentTargetResource RemoveTenantTag(TagResource tenantTag) + { + TenantTags.Remove(tenantTag.CanonicalTagName); + return this; + } + + public DeploymentTargetResource ClearTenantTags() + { + TenantTags.Clear(); + return this; + } } } \ No newline at end of file From 16392664c3d2713a418dcd17bb10aadbc9a0c149 Mon Sep 17 00:00:00 2001 From: Michael Compton Date: Tue, 5 Jun 2018 17:10:48 +1000 Subject: [PATCH 37/37] Remove DeploymentTargetResource --- ...AreaShouldNotRegress..NETCore.approved.txt | 44 +++--- ...houldNotRegress..NETFramework.approved.txt | 44 +++--- .../Model/DeploymentTargetResource.cs | 133 ------------------ .../Octopus.Client/Model/MachineResource.cs | 127 ++++++++++++++++- 4 files changed, 160 insertions(+), 188 deletions(-) delete mode 100644 source/Octopus.Client/Model/DeploymentTargetResource.cs diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt index 732347901..3ee961f25 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETCore.approved.txt @@ -1677,31 +1677,6 @@ Octopus.Client.Model StartAfterPrevious = 0 StartWithPrevious = 1 } - class DeploymentTargetResource - Octopus.Client.Extensibility.IResource - Octopus.Client.Model.IAuditedResource - Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.MachineBasedResource - { - .ctor() - Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } - Octopus.Client.Model.ReferenceCollection Roles { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } - Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) - Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() - Octopus.Client.Model.DeploymentTargetResource ClearRoles() - Octopus.Client.Model.DeploymentTargetResource ClearTenants() - Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() - Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) - Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) - Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) - Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) - } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource @@ -2211,9 +2186,26 @@ Octopus.Client.Model Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.DeploymentTargetResource + Octopus.Client.Model.MachineBasedResource { .ctor() + Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } + Octopus.Client.Model.ReferenceCollection Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } + Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } + Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } + Octopus.Client.Model.MachineResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) + Octopus.Client.Model.MachineResource AddOrUpdateRoles(String[]) + Octopus.Client.Model.MachineResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) + Octopus.Client.Model.MachineResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) + Octopus.Client.Model.MachineResource ClearEnvironments() + Octopus.Client.Model.MachineResource ClearRoles() + Octopus.Client.Model.MachineResource ClearTenants() + Octopus.Client.Model.MachineResource ClearTenantTags() + Octopus.Client.Model.MachineResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) + Octopus.Client.Model.MachineResource RemoveRole(String) + Octopus.Client.Model.MachineResource RemoveTenant(Octopus.Client.Model.TenantResource) + Octopus.Client.Model.MachineResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class MachineScriptPolicy { diff --git a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt index a28fedc61..d6dba2a22 100644 --- a/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt +++ b/source/Octopus.Client.Tests/PublicSurfaceAreaFixture.ThePublicSurfaceAreaShouldNotRegress..NETFramework.approved.txt @@ -2172,31 +2172,6 @@ Octopus.Client.Model StartAfterPrevious = 0 StartWithPrevious = 1 } - class DeploymentTargetResource - Octopus.Client.Extensibility.IResource - Octopus.Client.Model.IAuditedResource - Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.MachineBasedResource - { - .ctor() - Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } - Octopus.Client.Model.ReferenceCollection Roles { get; set; } - Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } - Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } - Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateRoles(String[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) - Octopus.Client.Model.DeploymentTargetResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) - Octopus.Client.Model.DeploymentTargetResource ClearEnvironments() - Octopus.Client.Model.DeploymentTargetResource ClearRoles() - Octopus.Client.Model.DeploymentTargetResource ClearTenants() - Octopus.Client.Model.DeploymentTargetResource ClearTenantTags() - Octopus.Client.Model.DeploymentTargetResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) - Octopus.Client.Model.DeploymentTargetResource RemoveRole(String) - Octopus.Client.Model.DeploymentTargetResource RemoveTenant(Octopus.Client.Model.TenantResource) - Octopus.Client.Model.DeploymentTargetResource RemoveTenantTag(Octopus.Client.Model.TagResource) - } class DeploymentTemplateResource Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource @@ -2706,9 +2681,26 @@ Octopus.Client.Model Octopus.Client.Extensibility.IResource Octopus.Client.Model.IAuditedResource Octopus.Client.Extensibility.INamedResource - Octopus.Client.Model.DeploymentTargetResource + Octopus.Client.Model.MachineBasedResource { .ctor() + Octopus.Client.Model.ReferenceCollection EnvironmentIds { get; set; } + Octopus.Client.Model.ReferenceCollection Roles { get; set; } + Octopus.Client.Model.TenantedDeploymentMode TenantedDeploymentParticipation { get; set; } + Octopus.Client.Model.ReferenceCollection TenantIds { get; set; } + Octopus.Client.Model.ReferenceCollection TenantTags { get; set; } + Octopus.Client.Model.MachineResource AddOrUpdateEnvironments(Octopus.Client.Model.EnvironmentResource[]) + Octopus.Client.Model.MachineResource AddOrUpdateRoles(String[]) + Octopus.Client.Model.MachineResource AddOrUpdateTenants(Octopus.Client.Model.TenantResource[]) + Octopus.Client.Model.MachineResource AddOrUpdateTenantTags(Octopus.Client.Model.TagResource[]) + Octopus.Client.Model.MachineResource ClearEnvironments() + Octopus.Client.Model.MachineResource ClearRoles() + Octopus.Client.Model.MachineResource ClearTenants() + Octopus.Client.Model.MachineResource ClearTenantTags() + Octopus.Client.Model.MachineResource RemoveEnvironment(Octopus.Client.Model.EnvironmentResource) + Octopus.Client.Model.MachineResource RemoveRole(String) + Octopus.Client.Model.MachineResource RemoveTenant(Octopus.Client.Model.TenantResource) + Octopus.Client.Model.MachineResource RemoveTenantTag(Octopus.Client.Model.TagResource) } class MachineScriptPolicy { diff --git a/source/Octopus.Client/Model/DeploymentTargetResource.cs b/source/Octopus.Client/Model/DeploymentTargetResource.cs deleted file mode 100644 index 9d1505ed2..000000000 --- a/source/Octopus.Client/Model/DeploymentTargetResource.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System.Linq; -using Octopus.Client.Extensibility.Attributes; - -namespace Octopus.Client.Model -{ - public class DeploymentTargetResource : MachineBasedResource - { - public DeploymentTargetResource() - { - EnvironmentIds = new ReferenceCollection(); - Roles = new ReferenceCollection(); - TenantTags = new ReferenceCollection(); - TenantIds = new ReferenceCollection(); - } - - [Writeable] - public ReferenceCollection EnvironmentIds { get; set; } - - [Writeable] - public ReferenceCollection Roles { get; set; } - - // Nullable backing-field is to support backwards-compatibility - TenantedDeploymentMode? tenantedDeploymentParticipation; - - [Writeable] - public TenantedDeploymentMode TenantedDeploymentParticipation - { - set => tenantedDeploymentParticipation = value; - - get - { - if (tenantedDeploymentParticipation.HasValue) - return tenantedDeploymentParticipation.Value; - - // Responses from server versions before TenantedDeploymentParticipation was implemented will default - // to pre-existing behaviour - return TenantIds.Any() || TenantTags.Any() - ? TenantedDeploymentMode.Tenanted - : TenantedDeploymentMode.Untenanted; - } - } - - [Writeable] - public ReferenceCollection TenantIds { get; set; } - - [Writeable] - public ReferenceCollection TenantTags { get; set; } - - public DeploymentTargetResource AddOrUpdateEnvironments(params EnvironmentResource[] environments) - { - foreach (var environment in environments) - { - EnvironmentIds.Add(environment.Id); - } - return this; - } - - public DeploymentTargetResource RemoveEnvironment(EnvironmentResource environment) - { - EnvironmentIds.Remove(environment.Id); - return this; - } - - public DeploymentTargetResource ClearEnvironments() - { - EnvironmentIds.Clear(); - return this; - } - - public DeploymentTargetResource AddOrUpdateRoles(params string[] roles) - { - foreach (var role in roles) - { - Roles.Add(role); - } - return this; - } - - public DeploymentTargetResource RemoveRole(string role) - { - Roles.Remove(role); - return this; - } - - public DeploymentTargetResource ClearRoles() - { - Roles.Clear(); - return this; - } - - public DeploymentTargetResource AddOrUpdateTenants(params TenantResource[] tenants) - { - foreach (var tenant in tenants) - { - TenantIds.Add(tenant.Id); - } - return this; - } - - public DeploymentTargetResource RemoveTenant(TenantResource tenant) - { - TenantIds.Remove(tenant.Id); - return this; - } - - public DeploymentTargetResource ClearTenants() - { - TenantIds.Clear(); - return this; - } - - public DeploymentTargetResource AddOrUpdateTenantTags(params TagResource[] tenantTags) - { - foreach (var tenantTag in tenantTags) - { - TenantTags.Add(tenantTag.CanonicalTagName); - } - return this; - } - - public DeploymentTargetResource RemoveTenantTag(TagResource tenantTag) - { - TenantTags.Remove(tenantTag.CanonicalTagName); - return this; - } - - public DeploymentTargetResource ClearTenantTags() - { - TenantTags.Clear(); - return this; - } - } -} \ No newline at end of file diff --git a/source/Octopus.Client/Model/MachineResource.cs b/source/Octopus.Client/Model/MachineResource.cs index 0124aca90..0eb1fe3be 100644 --- a/source/Octopus.Client/Model/MachineResource.cs +++ b/source/Octopus.Client/Model/MachineResource.cs @@ -1,12 +1,133 @@ -using System; +using System.Linq; +using Octopus.Client.Extensibility.Attributes; namespace Octopus.Client.Model { - public class MachineResource : DeploymentTargetResource + public class MachineResource : MachineBasedResource { - public MachineResource() : base() + public MachineResource() { + EnvironmentIds = new ReferenceCollection(); + Roles = new ReferenceCollection(); + TenantTags = new ReferenceCollection(); + TenantIds = new ReferenceCollection(); + } + + [Writeable] + public ReferenceCollection EnvironmentIds { get; set; } + + [Writeable] + public ReferenceCollection Roles { get; set; } + + // Nullable backing-field is to support backwards-compatibility + TenantedDeploymentMode? tenantedDeploymentParticipation; + + [Writeable] + public TenantedDeploymentMode TenantedDeploymentParticipation + { + set => tenantedDeploymentParticipation = value; + + get + { + if (tenantedDeploymentParticipation.HasValue) + return tenantedDeploymentParticipation.Value; + + // Responses from server versions before TenantedDeploymentParticipation was implemented will default + // to pre-existing behaviour + return TenantIds.Any() || TenantTags.Any() + ? TenantedDeploymentMode.Tenanted + : TenantedDeploymentMode.Untenanted; + } + } + + [Writeable] + public ReferenceCollection TenantIds { get; set; } + + [Writeable] + public ReferenceCollection TenantTags { get; set; } + + public MachineResource AddOrUpdateEnvironments(params EnvironmentResource[] environments) + { + foreach (var environment in environments) + { + EnvironmentIds.Add(environment.Id); + } + return this; + } + + public MachineResource RemoveEnvironment(EnvironmentResource environment) + { + EnvironmentIds.Remove(environment.Id); + return this; + } + + public MachineResource ClearEnvironments() + { + EnvironmentIds.Clear(); + return this; + } + + public MachineResource AddOrUpdateRoles(params string[] roles) + { + foreach (var role in roles) + { + Roles.Add(role); + } + return this; + } + public MachineResource RemoveRole(string role) + { + Roles.Remove(role); + return this; + } + + public MachineResource ClearRoles() + { + Roles.Clear(); + return this; + } + + public MachineResource AddOrUpdateTenants(params TenantResource[] tenants) + { + foreach (var tenant in tenants) + { + TenantIds.Add(tenant.Id); + } + return this; + } + + public MachineResource RemoveTenant(TenantResource tenant) + { + TenantIds.Remove(tenant.Id); + return this; + } + + public MachineResource ClearTenants() + { + TenantIds.Clear(); + return this; + } + + public MachineResource AddOrUpdateTenantTags(params TagResource[] tenantTags) + { + foreach (var tenantTag in tenantTags) + { + TenantTags.Add(tenantTag.CanonicalTagName); + } + return this; + } + + public MachineResource RemoveTenantTag(TagResource tenantTag) + { + TenantTags.Remove(tenantTag.CanonicalTagName); + return this; + } + + public MachineResource ClearTenantTags() + { + TenantTags.Clear(); + return this; } } } \ No newline at end of file