From b7f2461c76edcce9b3c6c5b1fa6c70b239d06c21 Mon Sep 17 00:00:00 2001 From: manan164 Date: Thu, 8 Dec 2022 01:49:39 +0530 Subject: [PATCH 1/6] Workflow level rate limiter test --- .../client/sdk/WorkflowRateLimiterTests.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java diff --git a/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java new file mode 100644 index 00000000..625bc860 --- /dev/null +++ b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java @@ -0,0 +1,127 @@ +package io.orkes.conductor.client.sdk; + +import com.netflix.conductor.common.metadata.tasks.TaskDef; +import com.netflix.conductor.common.metadata.tasks.TaskResult; +import com.netflix.conductor.common.metadata.tasks.TaskType; +import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest; +import com.netflix.conductor.common.metadata.workflow.WorkflowDef; +import com.netflix.conductor.common.metadata.workflow.WorkflowTask; +import com.netflix.conductor.common.run.Workflow; +import io.orkes.conductor.client.ApiClient; +import io.orkes.conductor.client.MetadataClient; +import io.orkes.conductor.client.TaskClient; +import io.orkes.conductor.client.WorkflowClient; +import io.orkes.conductor.client.http.OrkesMetadataClient; +import io.orkes.conductor.client.http.OrkesTaskClient; +import io.orkes.conductor.client.http.OrkesWorkflowClient; +import io.orkes.conductor.client.model.TagObject; +import io.orkes.conductor.sdk.examples.ApiUtil; +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.testcontainers.shaded.org.awaitility.Awaitility.await; + +public class WorkflowRateLimiterTests { + + @Test + @DisplayName("Check workflow with simple task and rerun functionality") + public void testRerunSimpleWorkflow() { + ApiClient apiClient = ApiUtil.getApiClientWithCredentials(); + WorkflowClient workflowClient = new OrkesWorkflowClient(apiClient); + MetadataClient metadataClient = new OrkesMetadataClient(apiClient); + TaskClient taskClient = new OrkesTaskClient(apiClient); + String workflowName = RandomStringUtils.randomAlphanumeric(5).toUpperCase(); + // Register workflow + registerWorkflowDef(workflowName, "simple", metadataClient); + TagObject tagObject = new TagObject(); + tagObject.setType(TagObject.TypeEnum.RATE_LIMIT); + tagObject.setKey(workflowName); + tagObject.setValue(3); // Only 3 invocations are allowed. + metadataClient.addWorkflowTag(tagObject, workflowName); + + StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); + startWorkflowRequest.setName(workflowName); + String workflowId1 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId2 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId3 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId4 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId5 = workflowClient.startWorkflow(startWorkflowRequest); + + Workflow workflow1 = workflowClient.getWorkflow(workflowId1, true); + Workflow workflow2 = workflowClient.getWorkflow(workflowId2, true); + Workflow workflow3 = workflowClient.getWorkflow(workflowId3, true); + AtomicReference workflow4 = new AtomicReference<>(workflowClient.getWorkflow(workflowId4, true)); + AtomicReference workflow5 = new AtomicReference<>(workflowClient.getWorkflow(workflowId4, true)); + + // Assertions + Assertions.assertEquals(workflow1.getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow2.getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow3.getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow4.get().getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow5.get().getStatus(), Workflow.WorkflowStatus.RUNNING); + // Workflow4 tasks should not get scheduled. + Assertions.assertEquals(workflow1.getTasks().size(), 1); + Assertions.assertEquals(workflow2.getTasks().size(), 1); + Assertions.assertEquals(workflow3.getTasks().size(), 1); + Assertions.assertEquals(workflow4.get().getTasks().size(), 0); + Assertions.assertEquals(workflow5.get().getTasks().size(), 0); + + // Complete workflow1. + TaskResult taskResult = new TaskResult(); + taskResult.setWorkflowInstanceId(workflowId1); + taskResult.setTaskId(workflow1.getTasks().get(0).getTaskId()); + taskResult.setStatus(TaskResult.Status.COMPLETED); + taskClient.updateTask(taskResult); + + // Now workflow4 task get scheduled. Workflow5 tasks should not get scheduled. + // Wait for 1 second to let sweeper run + await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> { + workflow4.set(workflowClient.getWorkflow(workflowId4, true)); + assertEquals(workflow4.get().getTasks().size(), 1); + workflow5.set(workflowClient.getWorkflow(workflowId5, true)); + assertEquals(workflow5.get().getTasks().size(), 0); + }); + + // Complete workflow2 + taskResult.setWorkflowInstanceId(workflowId2); + taskResult.setTaskId(workflow2.getTasks().get(0).getTaskId()); + taskResult.setStatus(TaskResult.Status.COMPLETED); + taskClient.updateTask(taskResult); + + await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> { + workflow5.set(workflowClient.getWorkflow(workflowId5, true)); + assertEquals(workflow4.get().getTasks().size(), 1); + }); + } + + private static void registerWorkflowDef(String workflowName, String taskName, MetadataClient metadataClient) { + TaskDef taskDef = new TaskDef(taskName); + taskDef.setOwnerEmail("test@orkes.io"); + taskDef.setRetryCount(0); + + WorkflowTask simpleTask = new WorkflowTask(); + simpleTask.setTaskReferenceName(taskName); + simpleTask.setName(taskName); + simpleTask.setTaskDefinition(taskDef); + simpleTask.setWorkflowTaskType(TaskType.SIMPLE); + simpleTask.setInputParameters(Map.of("value", "${workflow.input.value}", "order", "123")); + + + WorkflowDef workflowDef = new WorkflowDef(); + workflowDef.setName(workflowName); + workflowDef.setOwnerEmail("test@orkes.io"); + workflowDef.setInputParameters(Arrays.asList("value", "inlineValue")); + workflowDef.setDescription("Workflow to monitor order state"); + workflowDef.setTasks(Arrays.asList(simpleTask)); + metadataClient.registerWorkflowDef(workflowDef); + metadataClient.registerTaskDefs(Arrays.asList(taskDef)); + } +} From 97f377c9e55634323f485435a23853adc42e6fdd Mon Sep 17 00:00:00 2001 From: manan164 Date: Thu, 8 Dec 2022 02:04:41 +0530 Subject: [PATCH 2/6] Added correlationId test --- .../client/sdk/WorkflowRateLimiterTests.java | 77 +++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java index 625bc860..b76a2254 100644 --- a/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java +++ b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java @@ -32,15 +32,16 @@ public class WorkflowRateLimiterTests { @Test - @DisplayName("Check workflow with simple task and rerun functionality") - public void testRerunSimpleWorkflow() { + @DisplayName("Check workflow with simple rate limit by name") + public void testRateLimitByWorkflowName() { ApiClient apiClient = ApiUtil.getApiClientWithCredentials(); WorkflowClient workflowClient = new OrkesWorkflowClient(apiClient); MetadataClient metadataClient = new OrkesMetadataClient(apiClient); TaskClient taskClient = new OrkesTaskClient(apiClient); String workflowName = RandomStringUtils.randomAlphanumeric(5).toUpperCase(); + String taskName = RandomStringUtils.randomAlphanumeric(5).toUpperCase(); // Register workflow - registerWorkflowDef(workflowName, "simple", metadataClient); + registerWorkflowDef(workflowName, taskName, metadataClient); TagObject tagObject = new TagObject(); tagObject.setType(TagObject.TypeEnum.RATE_LIMIT); tagObject.setKey(workflowName); @@ -59,7 +60,7 @@ public void testRerunSimpleWorkflow() { Workflow workflow2 = workflowClient.getWorkflow(workflowId2, true); Workflow workflow3 = workflowClient.getWorkflow(workflowId3, true); AtomicReference workflow4 = new AtomicReference<>(workflowClient.getWorkflow(workflowId4, true)); - AtomicReference workflow5 = new AtomicReference<>(workflowClient.getWorkflow(workflowId4, true)); + AtomicReference workflow5 = new AtomicReference<>(workflowClient.getWorkflow(workflowId5, true)); // Assertions Assertions.assertEquals(workflow1.getStatus(), Workflow.WorkflowStatus.RUNNING); @@ -67,7 +68,7 @@ public void testRerunSimpleWorkflow() { Assertions.assertEquals(workflow3.getStatus(), Workflow.WorkflowStatus.RUNNING); Assertions.assertEquals(workflow4.get().getStatus(), Workflow.WorkflowStatus.RUNNING); Assertions.assertEquals(workflow5.get().getStatus(), Workflow.WorkflowStatus.RUNNING); - // Workflow4 tasks should not get scheduled. + // Workflow4 and workflow5 tasks should not get scheduled. Assertions.assertEquals(workflow1.getTasks().size(), 1); Assertions.assertEquals(workflow2.getTasks().size(), 1); Assertions.assertEquals(workflow3.getTasks().size(), 1); @@ -100,6 +101,72 @@ public void testRerunSimpleWorkflow() { workflow5.set(workflowClient.getWorkflow(workflowId5, true)); assertEquals(workflow4.get().getTasks().size(), 1); }); + metadataClient.unregisterWorkflowDef(workflowName, 1); + metadataClient.unregisterTaskDef(taskName); + } + + @Test + @DisplayName("Check workflow with simple rate limit by name") + public void testRateLimitByWorkflowCorrelationId() { + ApiClient apiClient = ApiUtil.getApiClientWithCredentials(); + WorkflowClient workflowClient = new OrkesWorkflowClient(apiClient); + MetadataClient metadataClient = new OrkesMetadataClient(apiClient); + TaskClient taskClient = new OrkesTaskClient(apiClient); + String workflowName = RandomStringUtils.randomAlphanumeric(5).toUpperCase(); + String taskName = RandomStringUtils.randomAlphanumeric(5).toUpperCase(); + // Register workflow + registerWorkflowDef(workflowName, taskName, metadataClient); + TagObject tagObject = new TagObject(); + tagObject.setType(TagObject.TypeEnum.RATE_LIMIT); + tagObject.setKey("${workflow.correlationId}"); + tagObject.setValue(3); // Only 3 invocations are allowed for same correlationId + metadataClient.addWorkflowTag(tagObject, workflowName); + + StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); + startWorkflowRequest.setCorrelationId("rate_limited"); + startWorkflowRequest.setName(workflowName); + String workflowId1 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId2 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId3 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId4 = workflowClient.startWorkflow(startWorkflowRequest); + // Triger workflow5 without. It should not get rate limited. + startWorkflowRequest.setCorrelationId(""); + String workflowId5 = workflowClient.startWorkflow(startWorkflowRequest); + + Workflow workflow1 = workflowClient.getWorkflow(workflowId1, true); + Workflow workflow2 = workflowClient.getWorkflow(workflowId2, true); + Workflow workflow3 = workflowClient.getWorkflow(workflowId3, true); + AtomicReference workflow4 = new AtomicReference<>(workflowClient.getWorkflow(workflowId4, true)); + AtomicReference workflow5 = new AtomicReference<>(workflowClient.getWorkflow(workflowId5, true)); + + // Assertions + Assertions.assertEquals(workflow1.getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow2.getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow3.getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow4.get().getStatus(), Workflow.WorkflowStatus.RUNNING); + Assertions.assertEquals(workflow5.get().getStatus(), Workflow.WorkflowStatus.RUNNING); + // Workflow4 and workflow5 tasks should not get scheduled. + Assertions.assertEquals(workflow1.getTasks().size(), 1); + Assertions.assertEquals(workflow2.getTasks().size(), 1); + Assertions.assertEquals(workflow3.getTasks().size(), 1); + Assertions.assertEquals(workflow4.get().getTasks().size(), 0); + Assertions.assertEquals(workflow5.get().getTasks().size(), 1); + + // Complete workflow1. + TaskResult taskResult = new TaskResult(); + taskResult.setWorkflowInstanceId(workflowId1); + taskResult.setTaskId(workflow1.getTasks().get(0).getTaskId()); + taskResult.setStatus(TaskResult.Status.COMPLETED); + taskClient.updateTask(taskResult); + + // Now workflow4 task get scheduled. Workflow5 tasks should not get scheduled. + // Wait for 1 second to let sweeper run + await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> { + workflow4.set(workflowClient.getWorkflow(workflowId4, true)); + assertEquals(workflow4.get().getTasks().size(), 1); + }); + metadataClient.unregisterWorkflowDef(workflowName, 1); + metadataClient.unregisterTaskDef(taskName); } private static void registerWorkflowDef(String workflowName, String taskName, MetadataClient metadataClient) { From 759e6154e516d8c0db87c601bb5b5fbbb3f98902 Mon Sep 17 00:00:00 2001 From: manan164 Date: Thu, 8 Dec 2022 02:05:32 +0530 Subject: [PATCH 3/6] comments. --- .../orkes/conductor/client/sdk/WorkflowRateLimiterTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java index b76a2254..9ba1f1d7 100644 --- a/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java +++ b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java @@ -106,7 +106,7 @@ public void testRateLimitByWorkflowName() { } @Test - @DisplayName("Check workflow with simple rate limit by name") + @DisplayName("Check workflow with simple rate limit by correlationId") public void testRateLimitByWorkflowCorrelationId() { ApiClient apiClient = ApiUtil.getApiClientWithCredentials(); WorkflowClient workflowClient = new OrkesWorkflowClient(apiClient); @@ -129,7 +129,7 @@ public void testRateLimitByWorkflowCorrelationId() { String workflowId2 = workflowClient.startWorkflow(startWorkflowRequest); String workflowId3 = workflowClient.startWorkflow(startWorkflowRequest); String workflowId4 = workflowClient.startWorkflow(startWorkflowRequest); - // Triger workflow5 without. It should not get rate limited. + // Triger workflow5 without correlationId. It should not get rate limited. startWorkflowRequest.setCorrelationId(""); String workflowId5 = workflowClient.startWorkflow(startWorkflowRequest); From a34f531b55a7950c1250ef7a2e436bfe6a1ad43d Mon Sep 17 00:00:00 2001 From: manan164 Date: Thu, 8 Dec 2022 02:06:57 +0530 Subject: [PATCH 4/6] linter --- .../client/sdk/WorkflowRateLimiterTests.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java index 9ba1f1d7..87b98035 100644 --- a/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java +++ b/src/test/java/io/orkes/conductor/client/sdk/WorkflowRateLimiterTests.java @@ -1,5 +1,27 @@ +/* + * Copyright 2022 Orkes, Inc. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ package io.orkes.conductor.client.sdk; +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + import com.netflix.conductor.common.metadata.tasks.TaskDef; import com.netflix.conductor.common.metadata.tasks.TaskResult; import com.netflix.conductor.common.metadata.tasks.TaskType; @@ -7,6 +29,7 @@ import com.netflix.conductor.common.metadata.workflow.WorkflowDef; import com.netflix.conductor.common.metadata.workflow.WorkflowTask; import com.netflix.conductor.common.run.Workflow; + import io.orkes.conductor.client.ApiClient; import io.orkes.conductor.client.MetadataClient; import io.orkes.conductor.client.TaskClient; @@ -16,15 +39,6 @@ import io.orkes.conductor.client.http.OrkesWorkflowClient; import io.orkes.conductor.client.model.TagObject; import io.orkes.conductor.sdk.examples.ApiUtil; -import org.apache.commons.lang3.RandomStringUtils; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.testcontainers.shaded.org.awaitility.Awaitility.await; From 29a23ab21d8ed148dccc1263343e1da9112a0346 Mon Sep 17 00:00:00 2001 From: manan164 Date: Tue, 13 Dec 2022 18:57:28 +0530 Subject: [PATCH 5/6] rate limiter test --- .../examples/WorkflowRateLimiterCheck.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java diff --git a/example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java b/example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java new file mode 100644 index 00000000..4c0243bb --- /dev/null +++ b/example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java @@ -0,0 +1,86 @@ +/* + * Copyright 2022 Orkes, Inc. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package io.orkes.conductor.sdk.examples; + +import java.util.Arrays; +import java.util.Map; + +import org.apache.commons.lang3.RandomStringUtils; + +import com.netflix.conductor.common.metadata.tasks.TaskDef; +import com.netflix.conductor.common.metadata.tasks.TaskType; +import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest; +import com.netflix.conductor.common.metadata.workflow.WorkflowDef; +import com.netflix.conductor.common.metadata.workflow.WorkflowTask; +import com.netflix.conductor.common.run.Workflow; + +import io.orkes.conductor.client.ApiClient; +import io.orkes.conductor.client.MetadataClient; +import io.orkes.conductor.client.WorkflowClient; +import io.orkes.conductor.client.http.OrkesMetadataClient; +import io.orkes.conductor.client.http.OrkesWorkflowClient; +import io.orkes.conductor.client.model.TagObject; + +public class WorkflowRateLimiterCheck { + + public static void main(String a[]) { + ApiClient apiClient = ApiUtil.getApiClientWithCredentials(); + WorkflowClient workflowClient = new OrkesWorkflowClient(apiClient); + MetadataClient metadataClient = new OrkesMetadataClient(apiClient); + String workflowName = RandomStringUtils.randomAlphanumeric(5).toUpperCase(); + // Register workflow + registerWorkflowDef(workflowName, "simple", metadataClient); + TagObject tagObject = new TagObject(); + tagObject.setType(TagObject.TypeEnum.RATE_LIMIT); + tagObject.setKey(workflowName); + tagObject.setValue(3); // Only 3 invocations are allowed. + metadataClient.addWorkflowTag(tagObject, workflowName); + + StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); + startWorkflowRequest.setName(workflowName); + String workflowId1 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId2 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId3 = workflowClient.startWorkflow(startWorkflowRequest); + String workflowId4 = workflowClient.startWorkflow(startWorkflowRequest); + + Workflow workflow1 = workflowClient.getWorkflow(workflowId1, true); + Workflow workflow2 = workflowClient.getWorkflow(workflowId2, true); + Workflow workflow3 = workflowClient.getWorkflow(workflowId3, true); + Workflow workflow4 = workflowClient.getWorkflow(workflowId4, true); + + // Assertions + } + + private static void registerWorkflowDef(String workflowName, String taskName, MetadataClient metadataClient) { + TaskDef taskDef = new TaskDef(taskName); + taskDef.setOwnerEmail("test@orkes.io"); + taskDef.setRetryCount(0); + + WorkflowTask simpleTask = new WorkflowTask(); + simpleTask.setTaskReferenceName(taskName); + simpleTask.setName(taskName); + simpleTask.setTaskDefinition(taskDef); + simpleTask.setWorkflowTaskType(TaskType.SIMPLE); + simpleTask.setInputParameters(Map.of("value", "${workflow.input.value}", "order", "123")); + + + WorkflowDef workflowDef = new WorkflowDef(); + workflowDef.setName(workflowName); + workflowDef.setOwnerEmail("test@orkes.io"); + workflowDef.setInputParameters(Arrays.asList("value", "inlineValue")); + workflowDef.setDescription("Workflow to monitor order state"); + workflowDef.setTasks(Arrays.asList(simpleTask)); + metadataClient.registerWorkflowDef(workflowDef); + metadataClient.registerTaskDefs(Arrays.asList(taskDef)); + } +} From a6740c8124edec6c634e3373a97b94fd9cdea22d Mon Sep 17 00:00:00 2001 From: manan164 Date: Tue, 20 Dec 2022 09:40:37 +0530 Subject: [PATCH 6/6] remove unused file --- .../examples/WorkflowRateLimiterCheck.java | 86 ------------------- 1 file changed, 86 deletions(-) delete mode 100644 example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java diff --git a/example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java b/example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java deleted file mode 100644 index 4c0243bb..00000000 --- a/example/java/io/orkes/conductor/sdk/examples/WorkflowRateLimiterCheck.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2022 Orkes, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package io.orkes.conductor.sdk.examples; - -import java.util.Arrays; -import java.util.Map; - -import org.apache.commons.lang3.RandomStringUtils; - -import com.netflix.conductor.common.metadata.tasks.TaskDef; -import com.netflix.conductor.common.metadata.tasks.TaskType; -import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest; -import com.netflix.conductor.common.metadata.workflow.WorkflowDef; -import com.netflix.conductor.common.metadata.workflow.WorkflowTask; -import com.netflix.conductor.common.run.Workflow; - -import io.orkes.conductor.client.ApiClient; -import io.orkes.conductor.client.MetadataClient; -import io.orkes.conductor.client.WorkflowClient; -import io.orkes.conductor.client.http.OrkesMetadataClient; -import io.orkes.conductor.client.http.OrkesWorkflowClient; -import io.orkes.conductor.client.model.TagObject; - -public class WorkflowRateLimiterCheck { - - public static void main(String a[]) { - ApiClient apiClient = ApiUtil.getApiClientWithCredentials(); - WorkflowClient workflowClient = new OrkesWorkflowClient(apiClient); - MetadataClient metadataClient = new OrkesMetadataClient(apiClient); - String workflowName = RandomStringUtils.randomAlphanumeric(5).toUpperCase(); - // Register workflow - registerWorkflowDef(workflowName, "simple", metadataClient); - TagObject tagObject = new TagObject(); - tagObject.setType(TagObject.TypeEnum.RATE_LIMIT); - tagObject.setKey(workflowName); - tagObject.setValue(3); // Only 3 invocations are allowed. - metadataClient.addWorkflowTag(tagObject, workflowName); - - StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); - startWorkflowRequest.setName(workflowName); - String workflowId1 = workflowClient.startWorkflow(startWorkflowRequest); - String workflowId2 = workflowClient.startWorkflow(startWorkflowRequest); - String workflowId3 = workflowClient.startWorkflow(startWorkflowRequest); - String workflowId4 = workflowClient.startWorkflow(startWorkflowRequest); - - Workflow workflow1 = workflowClient.getWorkflow(workflowId1, true); - Workflow workflow2 = workflowClient.getWorkflow(workflowId2, true); - Workflow workflow3 = workflowClient.getWorkflow(workflowId3, true); - Workflow workflow4 = workflowClient.getWorkflow(workflowId4, true); - - // Assertions - } - - private static void registerWorkflowDef(String workflowName, String taskName, MetadataClient metadataClient) { - TaskDef taskDef = new TaskDef(taskName); - taskDef.setOwnerEmail("test@orkes.io"); - taskDef.setRetryCount(0); - - WorkflowTask simpleTask = new WorkflowTask(); - simpleTask.setTaskReferenceName(taskName); - simpleTask.setName(taskName); - simpleTask.setTaskDefinition(taskDef); - simpleTask.setWorkflowTaskType(TaskType.SIMPLE); - simpleTask.setInputParameters(Map.of("value", "${workflow.input.value}", "order", "123")); - - - WorkflowDef workflowDef = new WorkflowDef(); - workflowDef.setName(workflowName); - workflowDef.setOwnerEmail("test@orkes.io"); - workflowDef.setInputParameters(Arrays.asList("value", "inlineValue")); - workflowDef.setDescription("Workflow to monitor order state"); - workflowDef.setTasks(Arrays.asList(simpleTask)); - metadataClient.registerWorkflowDef(workflowDef); - metadataClient.registerTaskDefs(Arrays.asList(taskDef)); - } -}