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");
}
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");
}
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");
}
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;
}
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;
}
Aggregations