Search in sources :

Example 1 with ProcessRecord

use of io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord 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 ProcessRecord

use of io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord in project zeebe by camunda.

the class ProcessStateTest method creatingProcessRecord.

public static ProcessRecord creatingProcessRecord(final MutableZeebeState zeebeState, final String processId, final int version) {
    final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(processId).startEvent().serviceTask("test", task -> task.zeebeJobType("type")).endEvent().done();
    final ProcessRecord processRecord = new ProcessRecord();
    final String resourceName = "process.bpmn";
    final var resource = wrapString(Bpmn.convertToString(modelInstance));
    final var checksum = wrapString("checksum");
    final KeyGenerator keyGenerator = zeebeState.getKeyGenerator();
    final long key = keyGenerator.nextKey();
    processRecord.setResourceName(wrapString(resourceName)).setResource(resource).setBpmnProcessId(BufferUtil.wrapString(processId)).setVersion(version).setKey(key).setResourceName(resourceName).setChecksum(checksum);
    return processRecord;
}
Also used : BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) ProcessRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator)

Example 3 with ProcessRecord

use of io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord in project zeebe by camunda-cloud.

the class ProcessStateTest method creatingProcessRecord.

public static ProcessRecord creatingProcessRecord(final MutableZeebeState zeebeState, final String processId, final int version) {
    final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(processId).startEvent().serviceTask("test", task -> task.zeebeJobType("type")).endEvent().done();
    final ProcessRecord processRecord = new ProcessRecord();
    final String resourceName = "process.bpmn";
    final var resource = wrapString(Bpmn.convertToString(modelInstance));
    final var checksum = wrapString("checksum");
    final KeyGenerator keyGenerator = zeebeState.getKeyGenerator();
    final long key = keyGenerator.nextKey();
    processRecord.setResourceName(wrapString(resourceName)).setResource(resource).setBpmnProcessId(BufferUtil.wrapString(processId)).setVersion(version).setKey(key).setResourceName(resourceName).setChecksum(checksum);
    return processRecord;
}
Also used : BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) ProcessRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator)

Example 4 with ProcessRecord

use of io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord in project zeebe by camunda-cloud.

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 5 with ProcessRecord

use of io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord in project zeebe by zeebe-io.

the class ProcessStateTest method creatingProcessRecord.

public static ProcessRecord creatingProcessRecord(final MutableZeebeState zeebeState, final String processId, final int version) {
    final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(processId).startEvent().serviceTask("test", task -> task.zeebeJobType("type")).endEvent().done();
    final ProcessRecord processRecord = new ProcessRecord();
    final String resourceName = "process.bpmn";
    final var resource = wrapString(Bpmn.convertToString(modelInstance));
    final var checksum = wrapString("checksum");
    final KeyGenerator keyGenerator = zeebeState.getKeyGenerator();
    final long key = keyGenerator.nextKey();
    processRecord.setResourceName(wrapString(resourceName)).setResource(resource).setBpmnProcessId(BufferUtil.wrapString(processId)).setVersion(version).setKey(key).setResourceName(resourceName).setChecksum(checksum);
    return processRecord;
}
Also used : BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) ProcessRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator)

Aggregations

ProcessRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.ProcessRecord)6 BufferUtil.wrapString (io.camunda.zeebe.util.buffer.BufferUtil.wrapString)6 KeyGenerator (io.camunda.zeebe.engine.state.KeyGenerator)3 DeployedProcess (io.camunda.zeebe.engine.state.deployment.DeployedProcess)3 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)3 Process (io.camunda.zeebe.model.bpmn.instance.Process)3 DirectBuffer (org.agrona.DirectBuffer)3