Search in sources :

Example 1 with DeploymentRecord

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

the class BrokerDeployProcessRequest method toResponseDto.

@Override
protected DeploymentRecord toResponseDto(final DirectBuffer buffer) {
    final DeploymentRecord responseDto = new DeploymentRecord();
    responseDto.wrap(buffer);
    return responseDto;
}
Also used : DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)

Example 2 with DeploymentRecord

use of io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord in project zeebe-process-test by camunda.

the class GrpcResponseWriter method createDeployResponse.

private DeployProcessResponse createDeployResponse() {
    final DeploymentRecord deployment = new DeploymentRecord();
    deployment.wrap(valueBufferView);
    return DeployProcessResponse.newBuilder().setKey(key).addAllProcesses(deployment.getProcessesMetadata().stream().map(metadata -> ProcessMetadata.newBuilder().setProcessDefinitionKey(metadata.getProcessDefinitionKey()).setBpmnProcessId(metadata.getBpmnProcessId()).setVersion(metadata.getVersion()).setResourceName(metadata.getResourceName()).build()).collect(Collectors.toList())).build();
}
Also used : RecordType(io.camunda.zeebe.protocol.record.RecordType) CompleteJobResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CompleteJobResponse) VariableDocumentRecord(io.camunda.zeebe.protocol.impl.record.value.variable.VariableDocumentRecord) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) CreateProcessInstanceResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CreateProcessInstanceResponse) FailJobResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.FailJobResponse) ValueType(io.camunda.zeebe.protocol.record.ValueType) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord) ProcessMetadata(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ProcessMetadata) DeployProcessResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.DeployProcessResponse) CreateProcessInstanceWithResultResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CreateProcessInstanceWithResultResponse) Map(java.util.Map) ActivatedJob(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob) Code(com.google.rpc.Code) ResolveIncidentResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ResolveIncidentResponse) Intent(io.camunda.zeebe.protocol.record.intent.Intent) MsgPackConverter(io.camunda.zeebe.protocol.impl.encoding.MsgPackConverter) SetVariablesResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesResponse) ProcessInstanceCreationRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceCreationRecord) ThrowErrorResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ThrowErrorResponse) UpdateJobRetriesResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.UpdateJobRetriesResponse) Status(com.google.rpc.Status) BufferWriter(io.camunda.zeebe.util.buffer.BufferWriter) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) CancelProcessInstanceResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.CancelProcessInstanceResponse) Collectors(java.util.stream.Collectors) ActivateJobsResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) PublishMessageResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ProcessInstanceResultRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceResultRecord) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) MutableDirectBuffer(org.agrona.MutableDirectBuffer) IncidentRecord(io.camunda.zeebe.protocol.impl.record.value.incident.IncidentRecord) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) DirectBuffer(org.agrona.DirectBuffer) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)

Example 3 with DeploymentRecord

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

the class TypedEventSerializationTest method createRecordTuple.

private static Tuple<TypedRecord, CopiedRecord> createRecordTuple() {
    final RecordMetadata recordMetadata = new RecordMetadata();
    final DeploymentIntent intent = DeploymentIntent.CREATE;
    final int protocolVersion = 1;
    final ValueType valueType = ValueType.DEPLOYMENT;
    final RecordType recordType = RecordType.COMMAND;
    final String rejectionReason = "fails";
    final RejectionType rejectionType = RejectionType.INVALID_ARGUMENT;
    final int requestId = 23;
    final int requestStreamId = 1;
    recordMetadata.intent(intent).protocolVersion(protocolVersion).valueType(valueType).recordType(recordType).rejectionReason(rejectionReason).rejectionType(rejectionType).requestId(requestId).requestStreamId(requestStreamId);
    final String resourceName = "resource";
    final DirectBuffer resource = wrapString("contents");
    final String bpmnProcessId = "testProcess";
    final long processDefinitionKey = 123;
    final int processVersion = 12;
    final DeploymentRecord record = new DeploymentRecord();
    record.resources().add().setResourceName(wrapString(resourceName)).setResource(resource);
    record.processesMetadata().add().setBpmnProcessId(wrapString(bpmnProcessId)).setKey(processDefinitionKey).setResourceName(wrapString(resourceName)).setVersion(processVersion).setChecksum(wrapString("checksum"));
    final long key = 1234;
    final long position = 4321;
    final long sourcePosition = 231;
    final long timestamp = 2191L;
    final LoggedEvent loggedEvent = mock(LoggedEvent.class);
    when(loggedEvent.getPosition()).thenReturn(position);
    when(loggedEvent.getKey()).thenReturn(key);
    when(loggedEvent.getSourceEventPosition()).thenReturn(sourcePosition);
    when(loggedEvent.getTimestamp()).thenReturn(timestamp);
    final TypedEventImpl typedEvent = new TypedEventImpl(0);
    typedEvent.wrap(loggedEvent, recordMetadata, record);
    final CopiedRecord copiedRecord = new CopiedRecord<>(record, recordMetadata, key, 0, position, sourcePosition, timestamp);
    return new Tuple<>(typedEvent, copiedRecord);
}
Also used : RejectionType(io.camunda.zeebe.protocol.record.RejectionType) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) ValueType(io.camunda.zeebe.protocol.record.ValueType) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DirectBuffer(org.agrona.DirectBuffer) RecordType(io.camunda.zeebe.protocol.record.RecordType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) CopiedRecord(io.camunda.zeebe.protocol.impl.record.CopiedRecord) Tuple(io.camunda.zeebe.util.collection.Tuple)

Example 4 with DeploymentRecord

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

the class TypedStreamProcessorTest method shouldSkipFailingEvent.

@Test
public void shouldSkipFailingEvent() {
    // given
    streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> TypedRecordProcessors.processors(keyGenerator, processingContext.getWriters()).onCommand(ValueType.DEPLOYMENT, DeploymentIntent.CREATE, new ErrorProneProcessor()));
    final AtomicLong requestId = new AtomicLong(0);
    final AtomicInteger requestStreamId = new AtomicInteger(0);
    when(mockCommandResponseWriter.tryWriteResponse(anyInt(), anyLong())).then((invocationOnMock -> {
        final int streamIdArg = invocationOnMock.getArgument(0);
        final long requestIdArg = invocationOnMock.getArgument(1);
        requestId.set(requestIdArg);
        requestStreamId.set(streamIdArg);
        return true;
    }));
    final long failingKey = keyGenerator.nextKey();
    streams.newRecord(STREAM_NAME).event(deployment("foo")).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).requestId(255L).requestStreamId(99).key(failingKey).write();
    final long secondEventPosition = streams.newRecord(STREAM_NAME).event(deployment("foo2")).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(keyGenerator.nextKey()).write();
    // when
    final LoggedEvent writtenEvent = TestUtil.doRepeatedly(() -> streams.events(STREAM_NAME).filter(e -> Records.isEvent(e, ValueType.DEPLOYMENT, DeploymentIntent.CREATED)).findFirst()).until(o -> o.isPresent()).get();
    // then
    assertThat(writtenEvent.getKey()).isEqualTo(1);
    assertThat(writtenEvent.getSourceEventPosition()).isEqualTo(secondEventPosition);
    // error response
    verify(mockCommandResponseWriter).tryWriteResponse(anyInt(), anyLong());
    assertThat(requestId.get()).isEqualTo(255L);
    assertThat(requestStreamId.get()).isEqualTo(99);
    final Record<DeploymentRecord> deploymentRejection = new RecordStream(streams.events(STREAM_NAME)).onlyDeploymentRecords().onlyRejections().withIntent(DeploymentIntent.CREATE).getFirst();
    assertThat(deploymentRejection.getKey()).isEqualTo(failingKey);
    assertThat(deploymentRejection.getRejectionType()).isEqualTo(RejectionType.PROCESSING_ERROR);
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) RecordType(io.camunda.zeebe.protocol.record.RecordType) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) DefaultZeebeDbFactory(io.camunda.zeebe.engine.state.DefaultZeebeDbFactory) DeploymentIntent(io.camunda.zeebe.protocol.record.intent.DeploymentIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ValueType(io.camunda.zeebe.protocol.record.ValueType) CommandResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) Record(io.camunda.zeebe.protocol.record.Record) MockitoAnnotations(org.mockito.MockitoAnnotations) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SynchronousLogStream(io.camunda.zeebe.logstreams.util.SynchronousLogStream) TestUtil(io.camunda.zeebe.test.util.TestUtil) ActorSchedulerRule(io.camunda.zeebe.util.sched.testing.ActorSchedulerRule) Records(io.camunda.zeebe.engine.util.Records) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) Before(org.junit.Before) TestStreams(io.camunda.zeebe.engine.util.TestStreams) KeyGenerator(io.camunda.zeebe.engine.state.KeyGenerator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) RuleChain(org.junit.rules.RuleChain) AtomicLong(java.util.concurrent.atomic.AtomicLong) Rule(org.junit.Rule) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) RecordStream(io.camunda.zeebe.engine.util.RecordStream) TemporaryFolder(org.junit.rules.TemporaryFolder) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordStream(io.camunda.zeebe.engine.util.RecordStream) LoggedEvent(io.camunda.zeebe.logstreams.log.LoggedEvent) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 5 with DeploymentRecord

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

the class SkipFailingEventsTest method shouldNotBlacklistInstanceAndIgnoreTimerStartEvents.

@Test
public void shouldNotBlacklistInstanceAndIgnoreTimerStartEvents() {
    // given
    when(commandResponseWriter.tryWriteResponse(anyInt(), anyLong())).thenReturn(true);
    final List<Long> processedInstances = new ArrayList<>();
    final TypedRecordProcessor<DeploymentRecord> errorProneProcessor = new TypedRecordProcessor<>() {

        @Override
        public void processRecord(final TypedRecord<DeploymentRecord> record, final TypedResponseWriter responseWriter, final TypedStreamWriter streamWriter) {
            if (record.getKey() == 0) {
                throw new RuntimeException("expected");
            }
            processedInstances.add(TimerInstance.NO_ELEMENT_INSTANCE);
            streamWriter.appendFollowUpEvent(record.getKey(), TimerIntent.CREATED, Records.timer(TimerInstance.NO_ELEMENT_INSTANCE));
        }
    };
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().timerWithDuration("PT1S").endEvent().done();
    final DeploymentRecord deploymentRecord = new DeploymentRecord();
    deploymentRecord.resources().add().setResourceName("process.bpmn").setResource(Bpmn.convertToString(process).getBytes());
    streams.startStreamProcessor(STREAM_NAME, DefaultZeebeDbFactory.defaultFactory(), (processingContext) -> {
        zeebeState = processingContext.getZeebeState();
        return TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), processingContext.getWriters()).onCommand(ValueType.DEPLOYMENT, DeploymentIntent.CREATE, errorProneProcessor);
    });
    streams.newRecord(STREAM_NAME).event(deploymentRecord).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(0).write();
    streams.newRecord(STREAM_NAME).event(deploymentRecord).recordType(RecordType.COMMAND).intent(DeploymentIntent.CREATE).key(1).write();
    // when
    waitForRecordWhichSatisfies(e -> Records.isEvent(e, ValueType.TIMER, TimerIntent.CREATED));
    // then
    final RecordMetadata metadata = new RecordMetadata();
    metadata.valueType(ValueType.TIMER);
    final MockTypedRecord<TimerRecord> mockTypedRecord = new MockTypedRecord<>(0, metadata, Records.timer(TimerInstance.NO_ELEMENT_INSTANCE));
    Assertions.assertThat(zeebeState.getBlackListState().isOnBlacklist(mockTypedRecord)).isFalse();
    assertThat(processedInstances).containsExactly(TimerInstance.NO_ELEMENT_INSTANCE);
}
Also used : TimerRecord(io.camunda.zeebe.protocol.impl.record.value.timer.TimerRecord) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) ArrayList(java.util.ArrayList) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) TypedStreamWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedStreamWriter) TypedResponseWriter(io.camunda.zeebe.engine.processing.streamprocessor.writers.TypedResponseWriter) RecordMetadata(io.camunda.zeebe.protocol.impl.record.RecordMetadata) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) MockTypedRecord(io.camunda.zeebe.engine.util.MockTypedRecord) Test(org.junit.Test)

Aggregations

DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)90 Test (org.junit.Test)45 ControlledTestExporter (io.camunda.zeebe.broker.exporter.util.ControlledTestExporter)12 RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)12 DeploymentIntent (io.camunda.zeebe.protocol.record.intent.DeploymentIntent)12 IncidentRecord (io.camunda.zeebe.protocol.impl.record.value.incident.IncidentRecord)11 RecordType (io.camunda.zeebe.protocol.record.RecordType)11 ValueType (io.camunda.zeebe.protocol.record.ValueType)11 AbstractFlowElement (io.camunda.zeebe.engine.processing.deployment.model.element.AbstractFlowElement)9 ExecutableProcess (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess)9 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)9 Record (io.camunda.zeebe.protocol.record.Record)9 CommandResponseWriter (io.camunda.zeebe.engine.processing.streamprocessor.writers.CommandResponseWriter)8 BrokerResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse)8 MsgPackConverter (io.camunda.zeebe.protocol.impl.encoding.MsgPackConverter)8 JobRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)8 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)8 BufferUtil (io.camunda.zeebe.util.buffer.BufferUtil)8 BufferUtil.wrapString (io.camunda.zeebe.util.buffer.BufferUtil.wrapString)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7