From 506a5753f24c5abb18dcd03d0b40344da3bf7cc4 Mon Sep 17 00:00:00 2001 From: ShawnAbshire Date: Sun, 5 Nov 2023 14:05:41 -0600 Subject: [PATCH 1/9] feat(multitenancy): ActivateJobsCommand updated to set tenantIds. --- Client.UnitTests/ActivateJobTest.cs | 39 +++++++++++++++++++ .../Api/Commands/IActivateJobsCommandStep1.cs | 4 +- Client/Api/Commands/ITenantIdsCommandStep.cs | 23 +++++++++++ Client/Impl/Commands/ActivateJobsCommand.cs | 14 +++++++ 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 Client/Api/Commands/ITenantIdsCommandStep.cs diff --git a/Client.UnitTests/ActivateJobTest.cs b/Client.UnitTests/ActivateJobTest.cs index 3d4ef607..dc1ead8e 100644 --- a/Client.UnitTests/ActivateJobTest.cs +++ b/Client.UnitTests/ActivateJobTest.cs @@ -163,5 +163,44 @@ public async Task ShouldSendRequestWithFetchVariablesListReceiveResponseAsExpect AssertJob(receivedJobs[1], 2); AssertJob(receivedJobs[2], 3); } + + [Test] + public async Task ShouldSendRequestWithTenantIdsListReceiveResponseAsExpected() + { + // given + var expectedRequest = new ActivateJobsRequest + { + Type = "foo", + Worker = "jobWorker", + Timeout = 10_000L, + MaxJobsToActivate = 1, + RequestTimeout = 5_000L, + TenantIds = { "1234", "5678" } + }; + + IList tenantIds = new List { "1234", "5678" }; + TestService.AddRequestHandler(typeof(ActivateJobsRequest), _ => CreateExpectedResponse()); + + // when + var response = await ZeebeClient.NewActivateJobsCommand() + .AddTenantIds(tenantIds) + .JobType("foo") + .MaxJobsToActivate(1) + .Timeout(TimeSpan.FromSeconds(10)) + .WorkerName("jobWorker") + .PollingTimeout(TimeSpan.FromSeconds(5)) + .Send(); + + // then + var actualRequest = TestService.Requests[typeof(ActivateJobsRequest)][0]; + Assert.AreEqual(expectedRequest, actualRequest); + + var receivedJobs = response.Jobs; + Assert.AreEqual(receivedJobs.Count, 3); + + AssertJob(receivedJobs[0], 1); + AssertJob(receivedJobs[1], 2); + AssertJob(receivedJobs[2], 3); + } } } diff --git a/Client/Api/Commands/IActivateJobsCommandStep1.cs b/Client/Api/Commands/IActivateJobsCommandStep1.cs index b757a993..ce65bfb2 100644 --- a/Client/Api/Commands/IActivateJobsCommandStep1.cs +++ b/Client/Api/Commands/IActivateJobsCommandStep1.cs @@ -18,7 +18,7 @@ namespace Zeebe.Client.Api.Commands { - public interface IActivateJobsCommandStep1 + public interface IActivateJobsCommandStep1 : ITenantIdsCommandStep { /// /// Set the type of jobs to work on. @@ -28,7 +28,7 @@ public interface IActivateJobsCommandStep1 IActivateJobsCommandStep2 JobType(string jobType); } - public interface IActivateJobsCommandStep2 + public interface IActivateJobsCommandStep2 { /// /// Set the maximum of jobs to activate. If less jobs are available for activation the diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs new file mode 100644 index 00000000..d9407354 --- /dev/null +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace Zeebe.Client.Api.Commands +{ + public interface ITenantIdsCommandStep + { + /// + /// Set a lit of tenantIds to associate to this resource. + /// + /// the tenant to associate to this resource. + /// The builder for this command. Call to complete the command and send it + /// to the broker. + T AddTenantIds(IList tenantIds); + + /// + /// Set a list of tenantIds to associate to this resource. + /// + /// the tenant to associate to this resource. + /// The builder for this command. Call to complete the command and send it + /// to the broker. + T AddTenantIds(params string[] tenantIds); + } +} \ No newline at end of file diff --git a/Client/Impl/Commands/ActivateJobsCommand.cs b/Client/Impl/Commands/ActivateJobsCommand.cs index 3beaf005..976428fa 100644 --- a/Client/Impl/Commands/ActivateJobsCommand.cs +++ b/Client/Impl/Commands/ActivateJobsCommand.cs @@ -29,6 +29,20 @@ public IActivateJobsCommandStep2 JobType(string jobType) return this; } + public IActivateJobsCommandStep1 AddTenantIds(IList tenantIds) + { + Request.TenantIds.AddRange(tenantIds); + + return this; + } + + public IActivateJobsCommandStep1 AddTenantIds(params string[] tenantIds) + { + Request.TenantIds.AddRange(tenantIds); + + return this; + } + public IActivateJobsCommandStep3 MaxJobsToActivate(int maxJobsToActivate) { Request.MaxJobsToActivate = maxJobsToActivate; From 4eafab45f273760a6e705708f32ce1af416b09fd Mon Sep 17 00:00:00 2001 From: ShawnAbshire Date: Fri, 17 Nov 2023 18:49:20 -0600 Subject: [PATCH 2/9] refactor(multitenancy): Move ITenantIdsCommandStep to before final step. --- Client.UnitTests/ActivateJobTest.cs | 2 +- .../Api/Commands/IActivateJobsCommandStep1.cs | 4 +-- Client/Api/Commands/ITenantIdsCommandStep.cs | 4 +-- Client/Impl/Commands/ActivateJobsCommand.cs | 28 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Client.UnitTests/ActivateJobTest.cs b/Client.UnitTests/ActivateJobTest.cs index dc1ead8e..e7a41611 100644 --- a/Client.UnitTests/ActivateJobTest.cs +++ b/Client.UnitTests/ActivateJobTest.cs @@ -183,12 +183,12 @@ public async Task ShouldSendRequestWithTenantIdsListReceiveResponseAsExpected() // when var response = await ZeebeClient.NewActivateJobsCommand() - .AddTenantIds(tenantIds) .JobType("foo") .MaxJobsToActivate(1) .Timeout(TimeSpan.FromSeconds(10)) .WorkerName("jobWorker") .PollingTimeout(TimeSpan.FromSeconds(5)) + .TenantIds(tenantIds) .Send(); // then diff --git a/Client/Api/Commands/IActivateJobsCommandStep1.cs b/Client/Api/Commands/IActivateJobsCommandStep1.cs index ce65bfb2..80e4b138 100644 --- a/Client/Api/Commands/IActivateJobsCommandStep1.cs +++ b/Client/Api/Commands/IActivateJobsCommandStep1.cs @@ -18,7 +18,7 @@ namespace Zeebe.Client.Api.Commands { - public interface IActivateJobsCommandStep1 : ITenantIdsCommandStep + public interface IActivateJobsCommandStep1 { /// /// Set the type of jobs to work on. @@ -39,7 +39,7 @@ public interface IActivateJobsCommandStep2 IActivateJobsCommandStep3 MaxJobsToActivate(int maxJobsToActivate); } - public interface IActivateJobsCommandStep3 : IFinalCommandWithRetryStep + public interface IActivateJobsCommandStep3 : ITenantIdsCommandStep, IFinalCommandWithRetryStep { /// /// Set the time for how long a job is exclusively assigned for this subscription. diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index d9407354..fae77391 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -10,7 +10,7 @@ public interface ITenantIdsCommandStep /// the tenant to associate to this resource. /// The builder for this command. Call to complete the command and send it /// to the broker. - T AddTenantIds(IList tenantIds); + T TenantIds(IList tenantIds); /// /// Set a list of tenantIds to associate to this resource. @@ -18,6 +18,6 @@ public interface ITenantIdsCommandStep /// the tenant to associate to this resource. /// The builder for this command. Call to complete the command and send it /// to the broker. - T AddTenantIds(params string[] tenantIds); + T TenantIds(params string[] tenantIds); } } \ No newline at end of file diff --git a/Client/Impl/Commands/ActivateJobsCommand.cs b/Client/Impl/Commands/ActivateJobsCommand.cs index 976428fa..6890aa64 100644 --- a/Client/Impl/Commands/ActivateJobsCommand.cs +++ b/Client/Impl/Commands/ActivateJobsCommand.cs @@ -29,20 +29,6 @@ public IActivateJobsCommandStep2 JobType(string jobType) return this; } - public IActivateJobsCommandStep1 AddTenantIds(IList tenantIds) - { - Request.TenantIds.AddRange(tenantIds); - - return this; - } - - public IActivateJobsCommandStep1 AddTenantIds(params string[] tenantIds) - { - Request.TenantIds.AddRange(tenantIds); - - return this; - } - public IActivateJobsCommandStep3 MaxJobsToActivate(int maxJobsToActivate) { Request.MaxJobsToActivate = maxJobsToActivate; @@ -79,6 +65,20 @@ public IActivateJobsCommandStep3 WorkerName(string workerName) return this; } + public IActivateJobsCommandStep3 TenantIds(IList tenantIds) + { + Request.TenantIds.AddRange(tenantIds); + + return this; + } + + public IActivateJobsCommandStep3 TenantIds(params string[] tenantIds) + { + Request.TenantIds.AddRange(tenantIds); + + return this; + } + public async Task Send(TimeSpan? timeout = null, CancellationToken token = default) { var activateJobsResponses = new Responses.ActivateJobsResponses(); From d594989a665f09484dce9ac63c35e4a22aba803b Mon Sep 17 00:00:00 2001 From: ShawnAbshire Date: Fri, 17 Nov 2023 18:57:45 -0600 Subject: [PATCH 3/9] feat(multitenancy): Reword ITenantIdsCommandStep method summaries. --- Client/Api/Commands/ITenantIdsCommandStep.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index fae77391..cfc5e31f 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -5,7 +5,7 @@ namespace Zeebe.Client.Api.Commands public interface ITenantIdsCommandStep { /// - /// Set a lit of tenantIds to associate to this resource. + /// Set a list of tenantIds to associate with this resource. /// /// the tenant to associate to this resource. /// The builder for this command. Call to complete the command and send it @@ -13,7 +13,7 @@ public interface ITenantIdsCommandStep T TenantIds(IList tenantIds); /// - /// Set a list of tenantIds to associate to this resource. + /// Set a list of tenantIds to associate with this resource. /// /// the tenant to associate to this resource. /// The builder for this command. Call to complete the command and send it From f759a0dd249b4f4a28cdbc68677aa846f481fc6c Mon Sep 17 00:00:00 2001 From: "Christopher Kujawa (Zell)" Date: Thu, 1 Feb 2024 14:57:53 +0100 Subject: [PATCH 4/9] docs: enhnace method doc --- Client/Api/Commands/ITenantIdsCommandStep.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index cfc5e31f..b9f874b6 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -7,6 +7,9 @@ public interface ITenantIdsCommandStep /// /// Set a list of tenantIds to associate with this resource. /// + /// + /// This can be useful when requesting jobs for multiple tenants at once. Each of the activated + /// jobs will be owned by the tenant that owns the corresponding process instance. /// the tenant to associate to this resource. /// The builder for this command. Call to complete the command and send it /// to the broker. From 42f4cd7839be56df69e54c4e0771cdd909d659b6 Mon Sep 17 00:00:00 2001 From: "Christopher Kujawa (Zell)" Date: Thu, 1 Feb 2024 14:58:01 +0100 Subject: [PATCH 5/9] docs: enhnace method doc --- Client/Api/Commands/ITenantIdsCommandStep.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index b9f874b6..afa65ff8 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -10,7 +10,7 @@ public interface ITenantIdsCommandStep /// /// This can be useful when requesting jobs for multiple tenants at once. Each of the activated /// jobs will be owned by the tenant that owns the corresponding process instance. - /// the tenant to associate to this resource. + /// the identifiers of the tenants to specify for this command, e.g. ["ACME", "OTHER"] /// The builder for this command. Call to complete the command and send it /// to the broker. T TenantIds(IList tenantIds); From 84f688015782980cfe8d6aa2a5de38e91dec4ed1 Mon Sep 17 00:00:00 2001 From: "Christopher Kujawa (Zell)" Date: Thu, 1 Feb 2024 14:58:14 +0100 Subject: [PATCH 6/9] docs: enhnace method doc --- Client/Api/Commands/ITenantIdsCommandStep.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index afa65ff8..a37e3c14 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -5,7 +5,7 @@ namespace Zeebe.Client.Api.Commands public interface ITenantIdsCommandStep { /// - /// Set a list of tenantIds to associate with this resource. + /// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command. /// /// /// This can be useful when requesting jobs for multiple tenants at once. Each of the activated From f78e3c693b04efd40689e11e96e3f5c06f92d9fb Mon Sep 17 00:00:00 2001 From: "Christopher Kujawa (Zell)" Date: Thu, 1 Feb 2024 15:24:30 +0100 Subject: [PATCH 7/9] docs: enhnace method doc --- Client/Api/Commands/ITenantIdsCommandStep.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index a37e3c14..22bc30ac 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -16,7 +16,7 @@ public interface ITenantIdsCommandStep T TenantIds(IList tenantIds); /// - /// Set a list of tenantIds to associate with this resource. + /// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command. /// /// the tenant to associate to this resource. /// The builder for this command. Call to complete the command and send it From ee7da1c3d403f8f68549cf6bcb8707a5b7aeafe1 Mon Sep 17 00:00:00 2001 From: "Christopher Kujawa (Zell)" Date: Thu, 1 Feb 2024 15:24:47 +0100 Subject: [PATCH 8/9] docs: enhance method doc --- Client/Api/Commands/ITenantIdsCommandStep.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index 22bc30ac..0974b017 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -18,6 +18,9 @@ public interface ITenantIdsCommandStep /// /// Specifies the tenants that may own any entities (e.g. process definition, process instances, etc.) resulting from this command. /// + /// + /// This can be useful when requesting jobs for multiple tenants at once. Each of the activated + /// jobs will be owned by the tenant that owns the corresponding process instance. /// the tenant to associate to this resource. /// The builder for this command. Call to complete the command and send it /// to the broker. From 8ffaa88d84b862c9458b2ef016750cb77c5c5c42 Mon Sep 17 00:00:00 2001 From: "Christopher Kujawa (Zell)" Date: Thu, 1 Feb 2024 15:25:01 +0100 Subject: [PATCH 9/9] docs: enhance method doc --- Client/Api/Commands/ITenantIdsCommandStep.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs index 0974b017..62fafe9c 100644 --- a/Client/Api/Commands/ITenantIdsCommandStep.cs +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -21,7 +21,7 @@ public interface ITenantIdsCommandStep /// /// This can be useful when requesting jobs for multiple tenants at once. Each of the activated /// jobs will be owned by the tenant that owns the corresponding process instance. - /// the tenant to associate to this resource. + /// the identifiers of the tenants to specify for this command, e.g. ["ACME", "OTHER"] /// The builder for this command. Call to complete the command and send it /// to the broker. T TenantIds(params string[] tenantIds);