Search in sources :

Example 6 with DeploymentEvent

use of io.zeebe.client.event.DeploymentEvent in project zeebe by zeebe-io.

the class WorkflowInstanceStarter method main.

public static void main(String[] args) {
    final String brokerContactPoint = "127.0.0.1:51015";
    final String bpmnProcessId = "demoProcess";
    final String topicName = "default-topic";
    final int partitionId = 0;
    final Properties clientProperties = new Properties();
    clientProperties.put(ClientProperties.BROKER_CONTACTPOINT, brokerContactPoint);
    final ZeebeClient zeebeClient = new ZeebeClientImpl(clientProperties);
    System.out.println(String.format("> Connecting to %s", brokerContactPoint));
    System.out.println(String.format("> Deploying workflow to topic '%s' and partition '%d'", topicName, partitionId));
    final DeploymentEvent deploymentResult = zeebeClient.workflows().deploy(topicName).addResourceFromClasspath("demoProcess.bpmn").execute();
    try {
        final String deployedWorkflows = deploymentResult.getDeployedWorkflows().stream().map(wf -> String.format("<%s:%d>", wf.getBpmnProcessId(), wf.getVersion())).collect(Collectors.joining(","));
        System.out.println(String.format("> Deployed: %s", deployedWorkflows));
        System.out.println(String.format("> Create workflow instance for workflow: %s", bpmnProcessId));
        zeebeClient.workflows().create(topicName).bpmnProcessId(bpmnProcessId).payload("{\"a\": \"b\"}").execute();
        System.out.println("> Created.");
    } catch (ClientCommandRejectedException exception) {
        System.out.println(String.format("> Fail to deploy: %s", exception.getMessage()));
    }
    System.out.println("> Closing...");
    zeebeClient.close();
    System.out.println("> Closed.");
}
Also used : Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Collectors(java.util.stream.Collectors) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ZeebeClient(io.zeebe.client.ZeebeClient) ZeebeClient(io.zeebe.client.ZeebeClient) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) DeploymentEvent(io.zeebe.client.event.DeploymentEvent)

Example 7 with DeploymentEvent

use of io.zeebe.client.event.DeploymentEvent in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldCreateDeployment.

@Test
public void shouldCreateDeployment() {
    // given
    final List<Map<String, Object>> deployedWorkflows = new ArrayList<>();
    Map<String, Object> deployedWorkflow = new HashMap<>();
    deployedWorkflow.put("bpmnProcessId", "foo");
    deployedWorkflow.put("version", 1);
    deployedWorkflows.add(deployedWorkflow);
    deployedWorkflow = new HashMap<>();
    deployedWorkflow.put("bpmnProcessId", "bar");
    deployedWorkflow.put("version", 2);
    deployedWorkflows.add(deployedWorkflow);
    brokerRule.onExecuteCommandRequest(r -> r.eventType() == DEPLOYMENT_EVENT).respondWith().key(2L).event().put("state", "CREATED").put("deployedWorkflows", deployedWorkflows).done().register();
    // when
    final DeploymentEvent deployment = clientRule.workflows().deploy(clientRule.getDefaultTopicName()).addWorkflowModel(WORKFLOW_MODEL, "model.bpmn").execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(commandRequest.key()).isEqualTo(-1);
    assertThat(commandRequest.getCommand()).containsEntry("state", "CREATE");
    assertThat(deployment.getMetadata().getKey()).isEqualTo(2L);
    assertThat(deployment.getDeployedWorkflows()).hasSize(2);
    assertThat(deployment.getDeployedWorkflows()).extracting("bpmnProcessId").contains("foo", "bar");
    assertThat(deployment.getDeployedWorkflows()).extracting("version").contains(1, 2);
}
Also used : DEPLOYMENT_EVENT(io.zeebe.protocol.clientapi.EventType.DEPLOYMENT_EVENT) java.util(java.util) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.zeebe.model.bpmn.Bpmn) Protocol(io.zeebe.protocol.Protocol) File(java.io.File) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.client.util.ClientRule) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) org.junit(org.junit) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) ExpectedException(org.junit.rules.ExpectedException) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) DeploymentEvent(io.zeebe.client.event.DeploymentEvent)

Example 8 with DeploymentEvent

use of io.zeebe.client.event.DeploymentEvent in project zeebe by zeebe-io.

the class CreateDeploymentTest method shouldSendDeploymentRequestToSystemTopic.

@Test
public void shouldSendDeploymentRequestToSystemTopic() {
    // given
    brokerRule.onExecuteCommandRequest(Protocol.SYSTEM_PARTITION, DEPLOYMENT_EVENT, "CREATE").respondWith().key(2L).event().put("state", "CREATED").done().register();
    // when
    final DeploymentEvent deployment = clientRule.workflows().deploy("test-topic").addWorkflowModel(WORKFLOW_MODEL, "model.bpmn").execute();
    // then
    assertThat(brokerRule.getReceivedCommandRequests()).hasSize(1);
    final ExecuteCommandRequest commandRequest = brokerRule.getReceivedCommandRequests().get(0);
    assertThat(commandRequest.partitionId()).isEqualTo(Protocol.SYSTEM_PARTITION);
    assertThat(commandRequest.getCommand()).containsEntry("topicName", "test-topic");
    assertThat(deployment.getMetadata().getTopicName()).isEqualTo(Protocol.SYSTEM_TOPIC);
}
Also used : ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) DeploymentEvent(io.zeebe.client.event.DeploymentEvent)

Example 9 with DeploymentEvent

use of io.zeebe.client.event.DeploymentEvent in project zeebe by zeebe-io.

the class DeploymentClusteredTest method shouldDeployOnRemainingBrokers.

@Test
public void shouldDeployOnRemainingBrokers() {
    // given
    clusteringRule.createTopic("test", PARTITION_COUNT);
    // when
    clusteringRule.stopBroker(ClusteringRule.BROKER_3_CLIENT_ADDRESS);
    // then
    final DeploymentEvent deploymentEvent = client.workflows().deploy("test").addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    assertThat(deploymentEvent.getDeployedWorkflows().size()).isEqualTo(1);
    assertThat(deploymentEvent.getErrorMessage()).isEmpty();
}
Also used : DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Test(org.junit.Test)

Example 10 with DeploymentEvent

use of io.zeebe.client.event.DeploymentEvent in project zeebe by zeebe-io.

the class DeploymentClusteredTest method shouldDeployOnTopicWithManyPartitions.

@Test
@Ignore("https://github.com/zeebe-io/zeebe/issues/644")
public void shouldDeployOnTopicWithManyPartitions() {
    // given
    clusteringRule.createTopic("test", 15);
    // when
    final DeploymentEvent deploymentEvent = client.workflows().deploy("test").addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    // then
    assertThat(deploymentEvent.getDeployedWorkflows().size()).isEqualTo(1);
    assertThat(deploymentEvent.getErrorMessage()).isEmpty();
}
Also used : DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DeploymentEvent (io.zeebe.client.event.DeploymentEvent)11 Test (org.junit.Test)8 ZeebeClient (io.zeebe.client.ZeebeClient)2 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)2 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)2 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)2 ClientProperties (io.zeebe.client.ClientProperties)1 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)1 ClientRule (io.zeebe.client.util.ClientRule)1 Bpmn (io.zeebe.model.bpmn.Bpmn)1 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)1 Protocol (io.zeebe.protocol.Protocol)1 DEPLOYMENT_EVENT (io.zeebe.protocol.clientapi.EventType.DEPLOYMENT_EVENT)1 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 java.util (java.util)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1