From 89ba7a30cf72e2f527052697630182e9aa510ac9 Mon Sep 17 00:00:00 2001 From: Nicolas Pepin-Perreault Date: Sun, 29 Dec 2024 21:20:03 +0100 Subject: [PATCH 1/5] feat: add support for REST API --- .../containers/ZeebeGatewayContainer.java | 5 +- .../io/zeebe/containers/ZeebeGatewayNode.java | 189 +++++++++++++++++- .../java/io/zeebe/containers/ZeebeNode.java | 1 + .../java/io/zeebe/containers/ZeebePort.java | 16 +- .../containers/cluster/ZeebeCluster.java | 3 +- .../containers/cluster/ZeebeClusterTest.java | 9 +- ...lusterWithEmbeddedGatewaysExampleTest.java | 3 +- .../ClusterWithGatewayExampleTest.java | 3 +- .../examples/ReusableVolumeExampleTest.java | 13 +- .../containers/examples/SingleNodeTest.java | 11 +- .../RestartWithExtractedDataExampleTest.java | 14 +- .../clock/TriggerTimerCatchEventTest.java | 11 +- .../clock/TriggerTimerStartEventTest.java | 11 +- .../exporter/BrokerWithDebugExporterIT.java | 8 +- .../io/zeebe/containers/util/TestSupport.java | 3 +- .../containers/engine/ZeebeClusterEngine.java | 8 +- .../engine/ZeebeContainerEngine.java | 6 +- .../engine/ZeebeClusterEngineIT.java | 1 + .../engine/ZeebeContainerEngineIT.java | 1 + 19 files changed, 249 insertions(+), 67 deletions(-) diff --git a/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java b/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java index a6046dc0..c1e5438b 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java @@ -56,13 +56,14 @@ * *
{@code
  * ZeebeClient.newClientBuilder()
- *   .brokerContainerPoint(container.getExternalGatewayAddress())
+ *   .grpcAddress(container.getGrpcAddress())
+ *   .restAddress(container.getRestAddress())
  *   .usePlaintext()
  *   .build();
  * }
* *

Note that if your client is also a container within the same network, you can and should use - * the {@link #getInternalGatewayAddress()}. + * the {@link #getInternalGrpcAddress()} and {@link #getInternalRestAddress()} variants. */ @API(status = Status.STABLE) @SuppressWarnings({"WeakerAccess", "UnusedReturnValue"}) diff --git a/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java b/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java index 3dfa8ebb..56a09d48 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java @@ -19,15 +19,16 @@ import org.apiguardian.api.API.Status; import org.testcontainers.containers.GenericContainer; +import java.net.URI; + /** * Represents common properties of nodes which can act as a gateway for a Zeebe cluster, e.g. {@link * ZeebeContainer} or {@link ZeebeGatewayContainer}. * - *

You can use {@link #getExternalGatewayAddress()} for clients which are not part of the gateway - * container's network; this is most likely what you want to use, so when in doubt use this. - * - *

You can use {@link #getInternalGatewayAddress()} for clients which are within the gateway - * container's network. + *

You should typically use {@link #getGrpcAddress()} and {@link #getRestAddress()} to wire your + * clients with this gateway. If your client happens to be running in the same network as the Docker + * container, then you may want to use {@link #getInternalGrpcAddress()} or {@link + * #getInternalRestAddress()} instead. * * @param the concrete type of the underlying container */ @@ -73,13 +74,16 @@ public interface ZeebeGatewayNode & ZeebeGatewayNo * *

@{code
    *   ZeebeClient.newClientBuilder()
-   *     .withBrokerContactPoint(container.getExternalGatewayAddress())
+   *     .gatewayAddress(container.getExternalGatewayAddress())
    *     .usePlaintext()
    *     .build();
    * }
* * @return the gateway address visible from outside the docker network + * @deprecated Use the protocol specific variants from now on, {@link #getGrpcAddress()} or {@link + * #getRestAddress()} */ + @Deprecated default String getExternalGatewayAddress() { return getExternalAddress(ZeebePort.GATEWAY.getPort()); } @@ -91,14 +95,185 @@ default String getExternalGatewayAddress() { * *
@{code
    *   ZeebeClient.newClientBuilder()
-   *     .withBrokerContactPoint(container.getInternalGatewayAddress())
+   *     .gatewayAddress(container.getInternalGatewayAddress())
    *     .usePlaintext()
    *     .build();
    * }
* * @return the gateway address visible from within the docker network + * @deprecated Use the protocol specific variants from now on, {@link #getInternalGrpcAddress()} + * or {@link #getInternalRestAddress()} */ + @Deprecated default String getInternalGatewayAddress() { return getInternalAddress(ZeebePort.GATEWAY.getPort()); } + + /** + * Returns an address accessible from within the container's network for the REST API. Primarily + * meant to be used by clients. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getInternalRestUrl())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return internally accessible REST API address + */ + default URI getInternalRestAddress() { + return getInternalRestAddress("http"); + } + + /** + * Returns an address accessible from within the container's network for the REST API. Primarily + * meant to be used by clients. + * + *

Use this variant if you need to specify a different scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getInternalRestUrl("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return internally accessible REST API address + */ + default URI getInternalRestAddress(final String scheme) { + final int port = ZeebePort.GATEWAY_REST.getPort(); + return URI.create(String.format("%s://%s:%d", scheme, getInternalHost(), port)); + } + + /** + * Returns the address of the REST API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use * + * {@link #getInternalRestAddress()} + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getRestAddress())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return externally accessible REST API address + */ + default URI getRestAddress() { + return getRestAddress("http"); + } + + /** + * Returns the address of the REST API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use + * {@link #getInternalRestAddress(String)}. + * + *

Use this method if you need to specify a different connection scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .restAddress(container.getExternalRestAddress("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return externally accessible REST API address + */ + default URI getRestAddress(final String scheme) { + final int port = getMappedPort(ZeebePort.GATEWAY_REST.getPort()); + return URI.create(String.format("%s://%s:%d", scheme, getExternalHost(), port)); + } + + /** + * Returns an address accessible from within the container's network for the gRPC API. Primarily + * meant to be used by clients. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getInternalGrpcAddress())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return internally accessible REST API address + */ + default URI getInternalGrpcAddress() { + return getInternalGrpcAddress("http"); + } + + /** + * Returns an address accessible from within the container's network for the REST API. Primarily + * meant to be used by clients. + * + *

Use this variant if you need to specify a different scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getInternalGrpcAddress("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return internally accessible REST API address + */ + default URI getInternalGrpcAddress(final String scheme) { + final int port = ZeebePort.GATEWAY_REST.getPort(); + return URI.create(String.format("%s://%s:%d", scheme, getInternalHost(), port)); + } + + /** + * Returns the address of the gRPC API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use + * {@link #getInternalGrpcAddress()}. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getGrpcAddress())
+   *     .usePlaintext()
+   *     .build();
+   * }
+ * + * @return externally accessible gRPC API address + */ + default URI getGrpcAddress() { + return getGrpcAddress("http"); + } + + /** + * Returns the address of the gRPC API a client which is not part of the container's network + * should use. If you want an address accessible from within the container's own network, use + * {@link #getInternalGrpcAddress(String)}. + * + *

Use this method if you need to specify a different connection scheme, e.g. HTTPS. + * + *

You can build your client like this: + * + *

@{code
+   *   ZeebeClient.newClientBuilder()
+   *     .grpcAddress(container.getGrpcAddress("https"))
+   *     .build();
+   * }
+ * + * @param scheme the expected scheme (e.g. HTTP, HTTPS) + * @return externally accessible gRPC API address + */ + default URI getGrpcAddress(final String scheme) { + final int port = getMappedPort(ZeebePort.GATEWAY_GRPC.getPort()); + return URI.create(String.format("%s://%s:%d", scheme, getExternalHost(), port)); + } } diff --git a/core/src/main/java/io/zeebe/containers/ZeebeNode.java b/core/src/main/java/io/zeebe/containers/ZeebeNode.java index 4e11af3c..33f5f905 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeNode.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeNode.java @@ -17,6 +17,7 @@ import java.time.Duration; import java.util.List; + import org.apiguardian.api.API; import org.apiguardian.api.API.Status; import org.testcontainers.containers.Container; diff --git a/core/src/main/java/io/zeebe/containers/ZeebePort.java b/core/src/main/java/io/zeebe/containers/ZeebePort.java index 0ffbf978..fca65066 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebePort.java +++ b/core/src/main/java/io/zeebe/containers/ZeebePort.java @@ -23,12 +23,24 @@ public enum ZeebePort { /** Port of the command API, i.e. the port used by the gateway to communicate with the broker */ COMMAND(26501), - /** Port of the gateway API, i.e. the port used by the client to communicate with any gateway */ + /** + * Deprecated reference to the old GATEWAY port, which is the gRPC port; use {@link #GATEWAY_REST} + * or {@link #GATEWAY_GRPC} in the future + */ + @Deprecated GATEWAY(26500), /** Port for internal communication, i.e. what all nodes use to communicate for clustering */ INTERNAL(26502), /** Port for the management server, i.e. actuators, metrics, etc. */ - MONITORING(9600); + MONITORING(9600), + /** + * Port of the gateway REST API, i.e. the port used by the client to communicate with any gateway + */ + GATEWAY_REST(8080), + /** + * Port of the gateway gRPC API, i.e. the port used by the client to communicate with any gateway + */ + GATEWAY_GRPC(26500); private final int port; diff --git a/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java b/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java index b914d81a..e821a92a 100644 --- a/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java +++ b/core/src/main/java/io/zeebe/containers/cluster/ZeebeCluster.java @@ -234,7 +234,8 @@ public ZeebeClientBuilder newClientBuilder() { final ZeebeGatewayNode gateway = getAvailableGateway(); return ZeebeClient.newClientBuilder() - .gatewayAddress(gateway.getExternalGatewayAddress()) + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) .usePlaintext(); } diff --git a/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java b/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java index 251664c8..40eb4107 100644 --- a/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java +++ b/core/src/test/java/io/zeebe/containers/cluster/ZeebeClusterTest.java @@ -82,7 +82,11 @@ void shouldStartClusterWithEmbeddedGateways() { for (final ZeebeGatewayNode gateway : cluster.getGateways().values()) { final Topology topology; try (final ZeebeClient client = - cluster.newClientBuilder().gatewayAddress(gateway.getExternalGatewayAddress()).build()) { + cluster + .newClientBuilder() + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) + .build()) { topology = client.newTopologyRequest().send().join(); } @@ -154,7 +158,8 @@ void shouldStartClusterWithMixedGateways() { try (final ZeebeClient client = ZeebeClient.newClientBuilder() .usePlaintext() - .gatewayAddress(gateway.getExternalGatewayAddress()) + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) .build()) { final Topology topology = client.newTopologyRequest().send().join(); assertThat(topology.getPartitionsCount()) diff --git a/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java index 27c51c95..21a67b59 100644 --- a/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/ClusterWithEmbeddedGatewaysExampleTest.java @@ -116,7 +116,8 @@ private ZeebeContainer getConfiguredClusterBroker( private ZeebeClient newZeebeClient(final ZeebeContainer node) { return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) + .grpcAddress(node.getGrpcAddress()) + .restAddress(node.getRestAddress()) .usePlaintext() .build(); } diff --git a/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java index b27cc16d..ec7dce00 100644 --- a/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/ClusterWithGatewayExampleTest.java @@ -123,7 +123,8 @@ private ZeebeBrokerContainer getConfiguredClusterBroker( private ZeebeClient newZeebeClient(final ZeebeGatewayContainer node) { return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) + .grpcAddress(node.getGrpcAddress()) + .restAddress(node.getRestAddress()) .usePlaintext() .build(); } diff --git a/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java index 7417abcb..b83435cb 100644 --- a/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java @@ -24,6 +24,8 @@ import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.ZeebeVolume; import java.util.concurrent.TimeUnit; + +import io.zeebe.containers.util.TestSupport; import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -56,7 +58,7 @@ void shouldReuseVolume() { Bpmn.createExecutableProcess("process").startEvent().endEvent().done(); // when - try (final ZeebeClient client = newZeebeClient(zeebeContainer)) { + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer)) { client.newDeployResourceCommand().addProcessModel(process, "process.bpmn").send().join(); } @@ -67,7 +69,7 @@ void shouldReuseVolume() { // create a process instance from the one we previously deployed - this would fail if we hadn't // previously deployed our process model final ProcessInstanceEvent processInstance; - try (final ZeebeClient client = newZeebeClient(zeebeContainer)) { + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer)) { processInstance = client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().send().join(); } @@ -77,11 +79,4 @@ void shouldReuseVolume() { .as("a process instance was successfully created") .isPositive(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java b/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java index bf84039c..39af9c39 100644 --- a/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java @@ -24,6 +24,8 @@ import io.zeebe.containers.ZeebeContainer; import java.util.Map; import java.util.concurrent.TimeUnit; + +import io.zeebe.containers.util.TestSupport; import org.assertj.core.api.Assertions; import org.assertj.core.util.Maps; import org.junit.jupiter.api.AutoClose; @@ -61,7 +63,7 @@ void shouldConnectToZeebe() { final ProcessInstanceResult workflowInstanceResult; // when - try (final ZeebeClient client = newZeebeClient(zeebeContainer)) { + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer)) { try (final JobWorker ignored = createJobWorker(variables, client)) { deploymentEvent = client @@ -99,11 +101,4 @@ private JobWorker createJobWorker( jobClient.newCompleteCommand(job.getKey()).variables(variables).send()) .open(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java index a6c76a8b..5c29d38d 100644 --- a/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java @@ -26,6 +26,8 @@ import io.zeebe.containers.archive.ContainerArchive; import java.nio.file.Path; import java.util.concurrent.TimeUnit; + +import io.zeebe.containers.util.TestSupport; import org.junit.jupiter.api.*; import org.junit.jupiter.api.io.TempDir; import org.slf4j.LoggerFactory; @@ -102,11 +104,7 @@ void shouldReuseData(final @TempDir Path tempDir) { } private void deployProcess(final ZeebeContainer container) { - try (final ZeebeClient client = - ZeebeClient.newClientBuilder() - .usePlaintext() - .gatewayAddress(container.getExternalGatewayAddress()) - .build()) { + try (final ZeebeClient client = TestSupport.newZeebeClient(container)) { client .newDeployResourceCommand() .addProcessModel( @@ -118,11 +116,7 @@ private void deployProcess(final ZeebeContainer container) { } private ProcessInstanceEvent createProcessInstance(final ZeebeContainer container) { - try (final ZeebeClient client = - ZeebeClient.newClientBuilder() - .usePlaintext() - .gatewayAddress(container.getExternalGatewayAddress()) - .build()) { + try (final ZeebeClient client = TestSupport.newZeebeClient(container)) { return client .newCreateInstanceCommand() .bpmnProcessId(PROCESS_ID) diff --git a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java index 11b58cf3..e23471fc 100644 --- a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; + +import io.zeebe.containers.util.TestSupport; import org.assertj.core.api.Assertions; import org.awaitility.Awaitility; import org.junit.jupiter.api.AutoClose; @@ -77,7 +79,7 @@ void shouldTriggerTimerStartEvent() { // when final JobHandler handler = (client, job) -> activatedJobs.add(job); - try (final ZeebeClient client = newZeebeClient(zeebeContainer); + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer); final JobWorker ignored = newJobWorker(handler, client)) { client.newDeployResourceCommand().addProcessModel(process, "process.bpmn").send().join(); client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().send().join(); @@ -98,11 +100,4 @@ void shouldTriggerTimerStartEvent() { private JobWorker newJobWorker(final JobHandler handler, final ZeebeClient client) { return client.newWorker().jobType(JOB_TYPE).handler(handler).open(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java index cea905fa..e97846a4 100644 --- a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; + +import io.zeebe.containers.util.TestSupport; import org.assertj.core.api.Assertions; import org.awaitility.Awaitility; import org.junit.jupiter.api.AutoClose; @@ -76,7 +78,7 @@ void shouldTriggerTimerStartEvent() { // when final JobHandler handler = (client, job) -> activatedJobs.add(job); - try (final ZeebeClient client = newZeebeClient(zeebeContainer); + try (final ZeebeClient client = TestSupport.newZeebeClient(zeebeContainer); final JobWorker ignored = newJobWorker(handler, client)) { client.newDeployResourceCommand().addProcessModel(process, "process.bpmn").send().join(); brokerTime = clock.addTime(TIME_OFFSET); @@ -96,11 +98,4 @@ void shouldTriggerTimerStartEvent() { private JobWorker newJobWorker(final JobHandler handler, final ZeebeClient client) { return client.newWorker().jobType(JOB_TYPE).handler(handler).open(); } - - private ZeebeClient newZeebeClient(final ZeebeContainer node) { - return ZeebeClient.newClientBuilder() - .gatewayAddress(node.getExternalGatewayAddress()) - .usePlaintext() - .build(); - } } diff --git a/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java b/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java index 824e6883..3385180c 100644 --- a/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java +++ b/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; + +import io.zeebe.containers.util.TestSupport; import org.assertj.core.groups.Tuple; import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; @@ -67,11 +69,7 @@ void afterEach() { @Test void shouldReadExportedRecords() { // given - try (final ZeebeClient client = - ZeebeClient.newClientBuilder() - .usePlaintext() - .gatewayAddress(container.getExternalGatewayAddress()) - .build()) { + try (final ZeebeClient client = TestSupport.newZeebeClient(container)) { // when client diff --git a/core/src/test/java/io/zeebe/containers/util/TestSupport.java b/core/src/test/java/io/zeebe/containers/util/TestSupport.java index 16c952fb..ed68a09f 100644 --- a/core/src/test/java/io/zeebe/containers/util/TestSupport.java +++ b/core/src/test/java/io/zeebe/containers/util/TestSupport.java @@ -60,7 +60,8 @@ public static String getUid() { public static ZeebeClient newZeebeClient(final ZeebeGatewayNode gateway) { return ZeebeClient.newClientBuilder() .usePlaintext() - .gatewayAddress(gateway.getExternalGatewayAddress()) + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress()) .build(); } diff --git a/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java b/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java index ce216652..1eff04f8 100644 --- a/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java +++ b/engine/src/main/java/io/zeebe/containers/engine/ZeebeClusterEngine.java @@ -20,6 +20,7 @@ import io.camunda.zeebe.client.ZeebeClientBuilder; import io.camunda.zeebe.client.impl.ZeebeObjectMapper; import io.camunda.zeebe.process.test.api.RecordStreamSource; +import io.zeebe.containers.ZeebeGatewayNode; import io.zeebe.containers.ZeebeNode; import io.zeebe.containers.clock.ZeebeClock; import io.zeebe.containers.cluster.ZeebeCluster; @@ -77,6 +78,7 @@ public ZeebeClient createClient(final ObjectMapper customObjectMapper) { return createClient(b -> b.withJsonMapper(new ZeebeObjectMapper(customObjectMapper))); } + @SuppressWarnings("deprecation") @Override public String getGatewayAddress() { return cluster.getAvailableGateway().getExternalGatewayAddress(); @@ -114,9 +116,13 @@ public void stop() { } private ZeebeClient createClient(final UnaryOperator configurator) { + final ZeebeGatewayNode gateway = cluster.getAvailableGateway(); final ZeebeClientBuilder builder = configurator.apply( - ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(getGatewayAddress())); + ZeebeClient.newClientBuilder() + .usePlaintext() + .grpcAddress(gateway.getGrpcAddress()) + .restAddress(gateway.getRestAddress())); final ZeebeClient client = builder.build(); clients.add(client); diff --git a/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java b/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java index 3893fef8..517c50b5 100644 --- a/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java +++ b/engine/src/main/java/io/zeebe/containers/engine/ZeebeContainerEngine.java @@ -75,6 +75,7 @@ public ZeebeClient createClient(final ObjectMapper objectMapper) { return createClient(b -> b.withJsonMapper(new ZeebeObjectMapper(objectMapper))); } + @SuppressWarnings("deprecation") @Override public String getGatewayAddress() { return container.getExternalGatewayAddress(); @@ -114,7 +115,10 @@ public void stop() { private ZeebeClient createClient(final UnaryOperator configurator) { final ZeebeClientBuilder builder = configurator.apply( - ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(getGatewayAddress())); + ZeebeClient.newClientBuilder() + .usePlaintext() + .grpcAddress(container.getGrpcAddress()) + .restAddress(container.getRestAddress())); final ZeebeClient client = builder.build(); clients.add(client); diff --git a/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java b/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java index 861a1e6a..2f82efe7 100644 --- a/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java +++ b/engine/src/test/java/io/zeebe/containers/engine/ZeebeClusterEngineIT.java @@ -114,6 +114,7 @@ void shouldCreateClient() { .succeedsWithin(Duration.ofSeconds(1)); } + @SuppressWarnings("deprecation") @Test void shouldReturnGatewayAddress() { // given diff --git a/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java b/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java index d17dadb7..81c49923 100644 --- a/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java +++ b/engine/src/test/java/io/zeebe/containers/engine/ZeebeContainerEngineIT.java @@ -97,6 +97,7 @@ void shouldCreateClient() { .succeedsWithin(Duration.ofSeconds(1)); } + @SuppressWarnings("deprecation") @Test void shouldReturnGatewayAddress() { // given From dc2bda45764c7d03efca651703ec2f10777b4a37 Mon Sep 17 00:00:00 2001 From: Nicolas Pepin-Perreault Date: Sun, 29 Dec 2024 21:23:32 +0100 Subject: [PATCH 2/5] style: apply formatting rules --- core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java | 3 +-- core/src/main/java/io/zeebe/containers/ZeebeNode.java | 1 - .../zeebe/containers/examples/ReusableVolumeExampleTest.java | 3 +-- .../test/java/io/zeebe/containers/examples/SingleNodeTest.java | 3 +-- .../examples/archive/RestartWithExtractedDataExampleTest.java | 3 +-- .../containers/examples/clock/TriggerTimerCatchEventTest.java | 3 +-- .../containers/examples/clock/TriggerTimerStartEventTest.java | 3 +-- .../examples/exporter/BrokerWithDebugExporterIT.java | 3 +-- 8 files changed, 7 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java b/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java index 56a09d48..ee7b2348 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeGatewayNode.java @@ -15,12 +15,11 @@ */ package io.zeebe.containers; +import java.net.URI; import org.apiguardian.api.API; import org.apiguardian.api.API.Status; import org.testcontainers.containers.GenericContainer; -import java.net.URI; - /** * Represents common properties of nodes which can act as a gateway for a Zeebe cluster, e.g. {@link * ZeebeContainer} or {@link ZeebeGatewayContainer}. diff --git a/core/src/main/java/io/zeebe/containers/ZeebeNode.java b/core/src/main/java/io/zeebe/containers/ZeebeNode.java index 33f5f905..4e11af3c 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeNode.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeNode.java @@ -17,7 +17,6 @@ import java.time.Duration; import java.util.List; - import org.apiguardian.api.API; import org.apiguardian.api.API.Status; import org.testcontainers.containers.Container; diff --git a/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java index b83435cb..361ee4a3 100644 --- a/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/ReusableVolumeExampleTest.java @@ -23,9 +23,8 @@ import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.ZeebeVolume; -import java.util.concurrent.TimeUnit; - import io.zeebe.containers.util.TestSupport; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AutoClose; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; diff --git a/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java b/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java index 39af9c39..68885170 100644 --- a/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/SingleNodeTest.java @@ -22,10 +22,9 @@ import io.camunda.zeebe.model.bpmn.Bpmn; import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; +import io.zeebe.containers.util.TestSupport; import java.util.Map; import java.util.concurrent.TimeUnit; - -import io.zeebe.containers.util.TestSupport; import org.assertj.core.api.Assertions; import org.assertj.core.util.Maps; import org.junit.jupiter.api.AutoClose; diff --git a/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java b/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java index 5c29d38d..e0748014 100644 --- a/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/archive/RestartWithExtractedDataExampleTest.java @@ -24,10 +24,9 @@ import io.zeebe.containers.ZeebeDefaults; import io.zeebe.containers.ZeebeVolume; import io.zeebe.containers.archive.ContainerArchive; +import io.zeebe.containers.util.TestSupport; import java.nio.file.Path; import java.util.concurrent.TimeUnit; - -import io.zeebe.containers.util.TestSupport; import org.junit.jupiter.api.*; import org.junit.jupiter.api.io.TempDir; import org.slf4j.LoggerFactory; diff --git a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java index e23471fc..1b75cebf 100644 --- a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerCatchEventTest.java @@ -23,13 +23,12 @@ import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.clock.ZeebeClock; +import io.zeebe.containers.util.TestSupport; import java.time.Duration; import java.time.Instant; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; - -import io.zeebe.containers.util.TestSupport; import org.assertj.core.api.Assertions; import org.awaitility.Awaitility; import org.junit.jupiter.api.AutoClose; diff --git a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java index e97846a4..4e79b95b 100644 --- a/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java +++ b/core/src/test/java/io/zeebe/containers/examples/clock/TriggerTimerStartEventTest.java @@ -23,13 +23,12 @@ import io.camunda.zeebe.model.bpmn.BpmnModelInstance; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.clock.ZeebeClock; +import io.zeebe.containers.util.TestSupport; import java.time.Duration; import java.time.Instant; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; - -import io.zeebe.containers.util.TestSupport; import org.assertj.core.api.Assertions; import org.awaitility.Awaitility; import org.junit.jupiter.api.AutoClose; diff --git a/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java b/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java index 3385180c..a6b87c72 100644 --- a/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java +++ b/core/src/test/java/io/zeebe/containers/examples/exporter/BrokerWithDebugExporterIT.java @@ -23,12 +23,11 @@ import io.camunda.zeebe.protocol.record.intent.MessageIntent; import io.zeebe.containers.ZeebeContainer; import io.zeebe.containers.exporter.DebugReceiver; +import io.zeebe.containers.util.TestSupport; import java.time.Duration; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; - -import io.zeebe.containers.util.TestSupport; import org.assertj.core.groups.Tuple; import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterEach; From 9ca838ba72b14a27983f7ec9fac652dece2d94c1 Mon Sep 17 00:00:00 2001 From: Nicolas Pepin-Perreault Date: Sun, 29 Dec 2024 21:26:08 +0100 Subject: [PATCH 3/5] docs: update README with new address methods --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 13dc6bb8..25598c2d 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,8 @@ public class MyFeatureTest { // given final ZeebeClient client = ZeebeClient.newClientBuilder() - .gatewayAddress(zeebeContainer.getExternalGatewayAddress()) + .grpcAddress(zeebeContainer.getGrpcAddress()) + .restAddress(zeebeContainer.getRestAddress()) .usePlaintext() .build(); final BpmnModelInstance process = @@ -249,7 +250,8 @@ public class MyFeatureTest { // given final ZeebeClient client = ZeebeClient.newClientBuilder() - .gatewayAddress(zeebeContainer.getExternalGatewayAddress()) + .grpcAddress(zeebeContainer.getGrpcAddress()) + .restAddress(zeebeContainer.getRestAddress()) .usePlaintext() .build(); final BpmnModelInstance process = @@ -309,7 +311,7 @@ The container is considered started if and only if: > A topology is considered complete if there is a leader for all partitions. Once started, the container is ready to accept commands, and a client can connect to it by setting -its `gatewayAddress` to `ZeebeContainer#getExternalGatewayAddress()`. +its `grpcAddress` to `ZeebeContainer#getGrpcAddress()`, and its `restAddress` to `ZeebeContainer#getRestAddress()`. ## Standalone broker without gateway @@ -348,7 +350,7 @@ The container is considered started if and only if: > A topology is considered complete if there is a leader for all partitions. Once started, the container is ready to accept commands, and a client can connect to it by setting -its `gatewayAddress` to `ZeebeContainer#getExternalGatewayAddress()`. +its `grpcAddress` to `ZeebeContainer#getGrpcAddress()`, and its `restAddress` to `ZeebeContainer#getRestAddress()`. ## Configuring your container From 9ee0fe982b2b1f5583aa001b0797953dc06c2371 Mon Sep 17 00:00:00 2001 From: Nicolas Pepin-Perreault Date: Sun, 29 Dec 2024 21:27:54 +0100 Subject: [PATCH 4/5] fix: expose REST port --- core/src/main/java/io/zeebe/containers/ZeebeContainer.java | 3 ++- .../main/java/io/zeebe/containers/ZeebeGatewayContainer.java | 3 ++- .../java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java | 2 +- .../src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/io/zeebe/containers/ZeebeContainer.java b/core/src/main/java/io/zeebe/containers/ZeebeContainer.java index 6b5f59f6..669c6131 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeContainer.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeContainer.java @@ -99,7 +99,8 @@ private void applyDefaultConfiguration() { .withEnv("ZEEBE_BROKER_NETWORK_HOST", "0.0.0.0") .withEnv("ZEEBE_BROKER_NETWORK_ADVERTISEDHOST", getInternalHost()) .addExposedPorts( - ZeebePort.GATEWAY.getPort(), + ZeebePort.GATEWAY_REST.getPort(), + ZeebePort.GATEWAY_GRPC.getPort(), ZeebePort.COMMAND.getPort(), ZeebePort.INTERNAL.getPort(), ZeebePort.MONITORING.getPort()); diff --git a/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java b/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java index c1e5438b..1ac0583c 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeGatewayContainer.java @@ -116,7 +116,8 @@ private void applyDefaultConfiguration() { .withEnv("ZEEBE_STANDALONE_GATEWAY", "true") .withStartupTimeout(DEFAULT_STARTUP_TIMEOUT) .addExposedPorts( - ZeebePort.GATEWAY.getPort(), + ZeebePort.GATEWAY_REST.getPort(), + ZeebePort.GATEWAY_GRPC.getPort(), ZeebePort.INTERNAL.getPort(), ZeebePort.MONITORING.getPort()); } diff --git a/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java b/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java index ec5903e8..ff80e4d9 100644 --- a/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java +++ b/core/src/main/java/io/zeebe/containers/ZeebeTopologyWaitStrategy.java @@ -103,7 +103,7 @@ public ZeebeTopologyWaitStrategy(final int brokersCount, final int replicationFa */ public ZeebeTopologyWaitStrategy( final int brokersCount, final int replicationFactor, final int partitionsCount) { - this(brokersCount, replicationFactor, partitionsCount, ZeebePort.GATEWAY.getPort()); + this(brokersCount, replicationFactor, partitionsCount, ZeebePort.GATEWAY_GRPC.getPort()); } /** diff --git a/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java b/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java index 5e1b5743..b9fff387 100644 --- a/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java +++ b/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java @@ -137,7 +137,8 @@ void shouldExposeAllPortsButGateway( // when final List exposedPorts = node.getExposedPorts(); - expectedPorts.remove((Integer) ZeebePort.GATEWAY.getPort()); + expectedPorts.remove((Integer) ZeebePort.GATEWAY_GRPC.getPort()); + expectedPorts.remove((Integer) ZeebePort.GATEWAY_REST.getPort()); // then assertThat(exposedPorts) From e8e850f7ee83d011a08143ff41764a5ed482f960 Mon Sep 17 00:00:00 2001 From: Nicolas Pepin-Perreault Date: Sun, 29 Dec 2024 21:34:27 +0100 Subject: [PATCH 5/5] fix: remove all (not just first) gateway ports --- .../test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java b/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java index b9fff387..8bebc88e 100644 --- a/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java +++ b/core/src/test/java/io/zeebe/containers/ZeebeBrokerNodeTest.java @@ -134,11 +134,12 @@ void shouldExposeAllPortsButGateway( // given final List expectedPorts = Arrays.stream(ZeebePort.values()).map(ZeebePort::getPort).collect(Collectors.toList()); + final List gatewayPorts = + Arrays.asList(ZeebePort.GATEWAY_GRPC.getPort(), ZeebePort.GATEWAY_REST.getPort()); + expectedPorts.removeAll(gatewayPorts); // when final List exposedPorts = node.getExposedPorts(); - expectedPorts.remove((Integer) ZeebePort.GATEWAY_GRPC.getPort()); - expectedPorts.remove((Integer) ZeebePort.GATEWAY_REST.getPort()); // then assertThat(exposedPorts)