use of io.camunda.zeebe.engine.state.deployment.DeployedProcess in project zeebe by camunda.
the class BpmnResourceTransformer method transformProcessResource.
private void transformProcessResource(final DeploymentRecord deploymentEvent, final DeploymentResource deploymentResource, final BpmnModelInstance definition) {
final Collection<Process> processes = definition.getDefinitions().getChildElementsByType(Process.class);
for (final Process process : processes) {
if (process.isExecutable()) {
final String bpmnProcessId = process.getId();
final DeployedProcess lastProcess = processState.getLatestProcessVersionByProcessId(BufferUtil.wrapString(bpmnProcessId));
final DirectBuffer lastDigest = processState.getLatestVersionDigest(wrapString(bpmnProcessId));
final DirectBuffer resourceDigest = checksumGenerator.apply(deploymentResource);
// adds process record to deployment record
final var processMetadata = deploymentEvent.processesMetadata().add();
processMetadata.setBpmnProcessId(BufferUtil.wrapString(process.getId())).setChecksum(resourceDigest).setResourceName(deploymentResource.getResourceNameBuffer());
final var isDuplicate = isDuplicateOfLatest(deploymentResource, resourceDigest, lastProcess, lastDigest);
if (isDuplicate) {
processMetadata.setVersion(lastProcess.getVersion()).setKey(lastProcess.getKey()).markAsDuplicate();
} else {
final var key = keyGenerator.nextKey();
processMetadata.setKey(key).setVersion(processState.getProcessVersion(bpmnProcessId) + 1);
stateWriter.appendFollowUpEvent(key, ProcessIntent.CREATED, new ProcessRecord().wrap(processMetadata, deploymentResource.getResource()));
}
}
}
}
use of io.camunda.zeebe.engine.state.deployment.DeployedProcess in project zeebe by camunda.
the class MessageStartEventSubscriptionManager method openMessageStartEventSubscriptions.
private void openMessageStartEventSubscriptions(final ProcessMetadata processRecord, final StateWriter stateWriter) {
final long processDefinitionKey = processRecord.getKey();
final DeployedProcess processDefinition = processState.getProcessByKey(processDefinitionKey);
final ExecutableProcess process = processDefinition.getProcess();
final List<ExecutableStartEvent> startEvents = process.getStartEvents();
// if startEvents contain message events
for (final ExecutableCatchEventElement startEvent : startEvents) {
if (startEvent.isMessage()) {
final ExecutableMessage message = startEvent.getMessage();
message.getMessageName().map(BufferUtil::wrapString).ifPresent(messageNameBuffer -> {
subscriptionRecord.reset();
subscriptionRecord.setMessageName(messageNameBuffer).setProcessDefinitionKey(processDefinitionKey).setBpmnProcessId(process.getId()).setStartEventId(startEvent.getId());
final var subscriptionKey = keyGenerator.nextKey();
stateWriter.appendFollowUpEvent(subscriptionKey, MessageStartEventSubscriptionIntent.CREATED, subscriptionRecord);
});
}
}
}
use of io.camunda.zeebe.engine.state.deployment.DeployedProcess in project zeebe by camunda.
the class MessageStartEventSubscriptionManager method closeExistingMessageStartEventSubscriptions.
private void closeExistingMessageStartEventSubscriptions(final ProcessMetadata processRecord, final StateWriter stateWriter) {
final DeployedProcess lastMsgProcess = findLastMessageStartProcess(processRecord);
if (lastMsgProcess == null) {
return;
}
messageStartEventSubscriptionState.visitSubscriptionsByProcessDefinition(lastMsgProcess.getKey(), subscription -> stateWriter.appendFollowUpEvent(subscription.getKey(), MessageStartEventSubscriptionIntent.DELETED, subscription.getRecord()));
}
use of io.camunda.zeebe.engine.state.deployment.DeployedProcess in project zeebe by camunda.
the class CreateProcessInstanceProcessor method getProcess.
private DeployedProcess getProcess(final ProcessInstanceCreationRecord record, final CommandControl controller) {
final DeployedProcess process;
final DirectBuffer bpmnProcessId = record.getBpmnProcessIdBuffer();
if (bpmnProcessId.capacity() > 0) {
if (record.getVersion() >= 0) {
process = getProcess(bpmnProcessId, record.getVersion(), controller);
} else {
process = getProcess(bpmnProcessId, controller);
}
} else if (record.getProcessDefinitionKey() >= 0) {
process = getProcess(record.getProcessDefinitionKey(), controller);
} else {
controller.reject(RejectionType.INVALID_ARGUMENT, ERROR_MESSAGE_NO_IDENTIFIER_SPECIFIED);
process = null;
}
return process;
}
use of io.camunda.zeebe.engine.state.deployment.DeployedProcess in project zeebe by zeebe-io.
the class MessageStartEventSubscriptionManager method openMessageStartEventSubscriptions.
private void openMessageStartEventSubscriptions(final ProcessMetadata processRecord, final StateWriter stateWriter) {
final long processDefinitionKey = processRecord.getKey();
final DeployedProcess processDefinition = processState.getProcessByKey(processDefinitionKey);
final ExecutableProcess process = processDefinition.getProcess();
final List<ExecutableStartEvent> startEvents = process.getStartEvents();
// if startEvents contain message events
for (final ExecutableCatchEventElement startEvent : startEvents) {
if (startEvent.isMessage()) {
final ExecutableMessage message = startEvent.getMessage();
message.getMessageName().map(BufferUtil::wrapString).ifPresent(messageNameBuffer -> {
subscriptionRecord.reset();
subscriptionRecord.setMessageName(messageNameBuffer).setProcessDefinitionKey(processDefinitionKey).setBpmnProcessId(process.getId()).setStartEventId(startEvent.getId());
final var subscriptionKey = keyGenerator.nextKey();
stateWriter.appendFollowUpEvent(subscriptionKey, MessageStartEventSubscriptionIntent.CREATED, subscriptionRecord);
});
}
}
}
Aggregations