Search in sources :

Example 1 with DeployedProcess

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()));
            }
        }
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess) DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess) Process(io.camunda.zeebe.model.bpmn.instance.Process) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) ProcessRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord)

Example 2 with DeployedProcess

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);
            });
        }
    }
}
Also used : ExecutableMessage(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMessage) DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess) ExecutableStartEvent(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableStartEvent) ExecutableCatchEventElement(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableCatchEventElement) ExecutableProcess(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess)

Example 3 with DeployedProcess

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()));
}
Also used : DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess)

Example 4 with DeployedProcess

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;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess)

Example 5 with DeployedProcess

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);
            });
        }
    }
}
Also used : ExecutableMessage(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMessage) DeployedProcess(io.camunda.zeebe.engine.state.deployment.DeployedProcess) ExecutableStartEvent(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableStartEvent) ExecutableCatchEventElement(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableCatchEventElement) ExecutableProcess(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess)

Aggregations

DeployedProcess (io.camunda.zeebe.engine.state.deployment.DeployedProcess)18 DirectBuffer (org.agrona.DirectBuffer)6 ProcessEngineMetrics (io.camunda.zeebe.engine.metrics.ProcessEngineMetrics)3 BpmnElementContainerProcessor (io.camunda.zeebe.engine.processing.bpmn.BpmnElementContainerProcessor)3 BpmnElementContext (io.camunda.zeebe.engine.processing.bpmn.BpmnElementContext)3 BpmnProcessingException (io.camunda.zeebe.engine.processing.bpmn.BpmnProcessingException)3 ProcessInstanceLifecycle (io.camunda.zeebe.engine.processing.bpmn.ProcessInstanceLifecycle)3 Failure (io.camunda.zeebe.engine.processing.common.Failure)3 ExecutableCallActivity (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableCallActivity)3 ExecutableCatchEventElement (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableCatchEventElement)3 ExecutableFlowElement (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableFlowElement)3 ExecutableFlowNode (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableFlowNode)3 ExecutableMessage (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMessage)3 ExecutableProcess (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess)3 ExecutableSequenceFlow (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableSequenceFlow)3 ExecutableStartEvent (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableStartEvent)3 StateWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.StateWriter)3 TypedCommandWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedCommandWriter)3 Writers (io.camunda.zeebe.engine.processing.streamprocessor.writers.Writers)3 KeyGenerator (io.camunda.zeebe.engine.state.KeyGenerator)3