Search in sources :

Example 6 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class WorkflowInstanceFunctionalTest method shouldSpitOnExclusiveGateway.

@Test
public void shouldSpitOnExclusiveGateway() {
    final WorkflowDefinition workflowDefinition = Bpmn.createExecutableWorkflow("workflow").startEvent().exclusiveGateway("xor").sequenceFlow("s1", s -> s.condition("$.foo < 5")).endEvent("a").sequenceFlow("s2", s -> s.condition("$.foo >= 5 && $.foo < 10")).endEvent("b").sequenceFlow("s3", s -> s.defaultFlow()).endEvent("c").done();
    testClient.deploy(workflowDefinition);
    final long workflowInstance1 = testClient.createWorkflowInstance("workflow", asMsgPack("foo", 4));
    final long workflowInstance2 = testClient.createWorkflowInstance("workflow", asMsgPack("foo", 8));
    final long workflowInstance3 = testClient.createWorkflowInstance("workflow", asMsgPack("foo", 12));
    SubscribedEvent endEvent = testClient.receiveSingleEvent(workflowInstanceEvents("END_EVENT_OCCURRED", workflowInstance1));
    assertThat(endEvent.event()).containsEntry(PROP_WORKFLOW_ACTIVITY_ID, "a");
    endEvent = testClient.receiveSingleEvent(workflowInstanceEvents("END_EVENT_OCCURRED", workflowInstance2));
    assertThat(endEvent.event()).containsEntry(PROP_WORKFLOW_ACTIVITY_ID, "b");
    endEvent = testClient.receiveSingleEvent(workflowInstanceEvents("END_EVENT_OCCURRED", workflowInstance3));
    assertThat(endEvent.event()).containsEntry(PROP_WORKFLOW_ACTIVITY_ID, "c");
}
Also used : WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 7 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class WorkflowInstanceFunctionalTest method shouldJoinOnExclusiveGateway.

@Test
public void shouldJoinOnExclusiveGateway() {
    final WorkflowDefinition workflowDefinition = Bpmn.createExecutableWorkflow("workflow").startEvent().exclusiveGateway("split").sequenceFlow("s1", s -> s.condition("$.foo < 5")).exclusiveGateway("join").continueAt("split").sequenceFlow("s2", s -> s.defaultFlow()).joinWith("join").endEvent("end").done();
    testClient.deploy(workflowDefinition);
    final long workflowInstance1 = testClient.createWorkflowInstance("workflow", asMsgPack("foo", 4));
    final long workflowInstance2 = testClient.createWorkflowInstance("workflow", asMsgPack("foo", 8));
    testClient.receiveSingleEvent(workflowInstanceEvents("WORKFLOW_INSTANCE_COMPLETED", workflowInstance1));
    testClient.receiveSingleEvent(workflowInstanceEvents("WORKFLOW_INSTANCE_COMPLETED", workflowInstance2));
    List<String> takenSequenceFlows = testClient.receiveEvents(workflowInstanceEvents("SEQUENCE_FLOW_TAKEN", workflowInstance1)).limit(3).map(s -> (String) s.event().get("activityId")).collect(Collectors.toList());
    assertThat(takenSequenceFlows).contains("s1");
    takenSequenceFlows = testClient.receiveEvents(workflowInstanceEvents("SEQUENCE_FLOW_TAKEN", workflowInstance2)).limit(3).map(s -> (String) s.event().get("activityId")).collect(Collectors.toList());
    assertThat(takenSequenceFlows).contains("s2");
}
Also used : java.util(java.util) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EmbeddedBrokerRule(io.zeebe.broker.test.EmbeddedBrokerRule) Bpmn(io.zeebe.model.bpmn.Bpmn) Protocol(io.zeebe.protocol.Protocol) MsgPackUtil.asMsgPack(io.zeebe.test.util.MsgPackUtil.asMsgPack) Collectors(java.util.stream.Collectors) File(java.io.File) TestTopicClient.taskEvents(io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents) RuleChain(org.junit.rules.RuleChain) MsgPackUtil(io.zeebe.test.util.MsgPackUtil) ResourceType(io.zeebe.broker.workflow.data.ResourceType) io.zeebe.test.broker.protocol.clientapi(io.zeebe.test.broker.protocol.clientapi) EventType(io.zeebe.protocol.clientapi.EventType) WorkflowInstanceEvent(io.zeebe.broker.workflow.data.WorkflowInstanceEvent) Files(org.assertj.core.util.Files) org.junit(org.junit) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) TestTopicClient.workflowInstanceEvents(io.zeebe.test.broker.protocol.clientapi.TestTopicClient.workflowInstanceEvents) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 8 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class WorkflowDeploymentCache method getWorkflowIndex.

private int getWorkflowIndex(WorkflowEvent event) {
    final DirectBuffer bpmnProcessId = event.getBpmnProcessId();
    final DirectBuffer bpmnXml = event.getBpmnXml();
    int index = 0;
    final WorkflowDefinition workflowDefinition = bpmn.readFromXmlBuffer(bpmnXml);
    final Iterator<Workflow> workflows = workflowDefinition.getWorkflows().iterator();
    while (workflows.hasNext()) {
        final Workflow workflow = workflows.next();
        if (BufferUtil.equals(bpmnProcessId, workflow.getBpmnProcessId())) {
            return index;
        }
        index += 1;
    }
    throw new RuntimeException("workflow not found");
}
Also used : DirectBuffer(org.agrona.DirectBuffer) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) Workflow(io.zeebe.model.bpmn.instance.Workflow)

Example 9 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class WorkflowDeploymentCache method lookupWorkflow.

private DeployedWorkflow lookupWorkflow(long key) {
    DeployedWorkflow deployedWorkflow = null;
    final DirectBuffer positionWorkflowBuffer = keyToPositionWorkflowMap.get(key);
    if (positionWorkflowBuffer != null) {
        final long eventPosition = positionWorkflowBuffer.getLong(POSITION_OFFSET, BYTE_ORDER);
        final int workflowIndex = positionWorkflowBuffer.getInt(WORKFLOW_INDEX_OFFSET, BYTE_ORDER);
        final boolean found = logStreamReader.seek(eventPosition);
        if (found && logStreamReader.hasNext()) {
            final LoggedEvent event = logStreamReader.next();
            workflowEvent.reset();
            event.readValue(workflowEvent);
            final WorkflowDefinition workflowDefinition = bpmn.readFromXmlBuffer(workflowEvent.getBpmnXml());
            final Workflow workflow = getWorkflowAt(workflowDefinition, workflowIndex);
            deployedWorkflow = new DeployedWorkflow(workflow, workflowEvent.getVersion());
        }
    }
    return deployedWorkflow;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LoggedEvent(io.zeebe.logstreams.log.LoggedEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) Workflow(io.zeebe.model.bpmn.instance.Workflow)

Example 10 with WorkflowDefinition

use of io.zeebe.model.bpmn.instance.WorkflowDefinition in project zeebe by zeebe-io.

the class DeploymentCreateProcessor method readAndValidateWorkflowsOfResource.

private boolean readAndValidateWorkflowsOfResource(final DeploymentResource deploymentResource, final DirectBuffer topicName, final StringBuilder validationErrors) {
    final WorkflowDefinition definition = readWorkflowDefinition(deploymentResource);
    final ValidationResult validationResult = bpmn.validate(definition);
    final boolean isValid = !validationResult.hasErrors();
    if (isValid) {
        assignVersionToWorkflows(deploymentResourceIterator, topicName, definition);
        transformWorkflowResource(deploymentResource, definition);
    }
    if (validationResult.hasErrors() || validationResult.hasWarnings()) {
        validationErrors.append(String.format("Resource '%s':\n", bufferAsString(deploymentResource.getResourceName())));
        validationErrors.append(validationResult.format());
    }
    return isValid;
}
Also used : WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) ValidationResult(io.zeebe.model.bpmn.ValidationResult)

Aggregations

WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)27 Bpmn (io.zeebe.model.bpmn.Bpmn)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 RuleChain (org.junit.rules.RuleChain)8 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)7 EventType (io.zeebe.protocol.clientapi.EventType)7 ResourceType (io.zeebe.broker.workflow.data.ResourceType)6 Protocol (io.zeebe.protocol.Protocol)6 ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)6 File (java.io.File)6 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)6 Files (org.assertj.core.util.Files)6 Test (org.junit.Test)6 org.junit (org.junit)5 WorkflowInstanceEvent (io.zeebe.broker.workflow.data.WorkflowInstanceEvent)4 TestTopicClient.taskEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents)4 TestTopicClient.workflowInstanceEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.workflowInstanceEvents)4 MsgPackUtil.asMsgPack (io.zeebe.test.util.MsgPackUtil.asMsgPack)4 WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)3 io.zeebe.test.broker.protocol.clientapi (io.zeebe.test.broker.protocol.clientapi)3