Search in sources :

Example 1 with RejectionType

use of io.camunda.zeebe.protocol.record.RejectionType in project zeebe by camunda.

the class JobBatchActivateProcessor method rejectCommand.

private void rejectCommand(final TypedRecord<JobBatchRecord> record) {
    final RejectionType rejectionType;
    final String rejectionReason;
    final JobBatchRecord value = record.getValue();
    final var format = "Expected to activate job batch with %s to be %s, but it was %s";
    if (value.getMaxJobsToActivate() < 1) {
        rejectionType = RejectionType.INVALID_ARGUMENT;
        rejectionReason = String.format(format, "max jobs to activate", "greater than zero", String.format("'%d'", value.getMaxJobsToActivate()));
    } else if (value.getTimeout() < 1) {
        rejectionType = RejectionType.INVALID_ARGUMENT;
        rejectionReason = String.format(format, "timeout", "greater than zero", String.format("'%d'", value.getTimeout()));
    } else if (value.getTypeBuffer().capacity() < 1) {
        rejectionType = RejectionType.INVALID_ARGUMENT;
        rejectionReason = String.format(format, "type", "present", "blank");
    } else {
        throw new IllegalStateException("Expected to reject an invalid activate job batch command, but it appears to be valid");
    }
    rejectionWriter.appendRejection(record, rejectionType, rejectionReason);
    responseWriter.writeRejectionOnCommand(record, rejectionType, rejectionReason);
}
Also used : RejectionType(io.camunda.zeebe.protocol.record.RejectionType) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)

Example 2 with RejectionType

use of io.camunda.zeebe.protocol.record.RejectionType 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 3 with RejectionType

use of io.camunda.zeebe.protocol.record.RejectionType in project zeebe by zeebe-io.

the class JobBatchActivateProcessor method rejectCommand.

private void rejectCommand(final TypedRecord<JobBatchRecord> record) {
    final RejectionType rejectionType;
    final String rejectionReason;
    final JobBatchRecord value = record.getValue();
    final var format = "Expected to activate job batch with %s to be %s, but it was %s";
    if (value.getMaxJobsToActivate() < 1) {
        rejectionType = RejectionType.INVALID_ARGUMENT;
        rejectionReason = String.format(format, "max jobs to activate", "greater than zero", String.format("'%d'", value.getMaxJobsToActivate()));
    } else if (value.getTimeout() < 1) {
        rejectionType = RejectionType.INVALID_ARGUMENT;
        rejectionReason = String.format(format, "timeout", "greater than zero", String.format("'%d'", value.getTimeout()));
    } else if (value.getTypeBuffer().capacity() < 1) {
        rejectionType = RejectionType.INVALID_ARGUMENT;
        rejectionReason = String.format(format, "type", "present", "blank");
    } else {
        throw new IllegalStateException("Expected to reject an invalid activate job batch command, but it appears to be valid");
    }
    rejectionWriter.appendRejection(record, rejectionType, rejectionReason);
    responseWriter.writeRejectionOnCommand(record, rejectionType, rejectionReason);
}
Also used : RejectionType(io.camunda.zeebe.protocol.record.RejectionType) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)

Example 4 with RejectionType

use of io.camunda.zeebe.protocol.record.RejectionType in project zeebe by zeebe-io.

the class ActivateJobsTest method shouldSendRejectionWithoutRetrying.

@Test
public void shouldSendRejectionWithoutRetrying() {
    // given
    final RejectionType rejectionType = RejectionType.INVALID_ARGUMENT;
    final AtomicInteger callCounter = new AtomicInteger();
    brokerClient.registerHandler(BrokerActivateJobsRequest.class, (RequestHandler<BrokerRequest<?>, BrokerResponse<?>>) request -> {
        callCounter.incrementAndGet();
        return new BrokerRejectionResponse<>(new BrokerRejection(Intent.UNKNOWN, 1, rejectionType, "expected"));
    });
    final ActivateJobsRequest request = ActivateJobsRequest.newBuilder().setType("").setMaxJobsToActivate(1).build();
    // when/then
    assertThatThrownBy(() -> {
        final Iterator<ActivateJobsResponse> responseIterator = client.activateJobs(request);
        responseIterator.hasNext();
    }).isInstanceOf(StatusRuntimeException.class).extracting(t -> ((StatusRuntimeException) t).getStatus().getCode()).isEqualTo(Status.INVALID_ARGUMENT.getCode());
    assertThat(callCounter).hasValue(1);
}
Also used : BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) Protocol(io.camunda.zeebe.protocol.Protocol) Arrays(java.util.Arrays) BrokerRejectionResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejectionResponse) BufferUtil.wrapString(io.camunda.zeebe.util.buffer.BufferUtil.wrapString) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ActivatedJob(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob) Status(io.grpc.Status) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) Parameterized(org.junit.runners.Parameterized) Intent(io.camunda.zeebe.protocol.record.intent.Intent) RequestHandler(io.camunda.zeebe.gateway.api.util.StubbedBrokerClient.RequestHandler) Iterator(java.util.Iterator) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) JsonUtil(io.camunda.zeebe.test.util.JsonUtil) Test(org.junit.Test) StatusRuntimeException(io.grpc.StatusRuntimeException) List(java.util.List) ActivateJobsResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord) BrokerRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) RejectionType(io.camunda.zeebe.protocol.record.RejectionType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) ActivateJobsRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest) Iterator(java.util.Iterator) BrokerRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 5 with RejectionType

use of io.camunda.zeebe.protocol.record.RejectionType in project zeebe by zeebe-io.

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)

Aggregations

RejectionType (io.camunda.zeebe.protocol.record.RejectionType)9 BufferUtil.wrapString (io.camunda.zeebe.util.buffer.BufferUtil.wrapString)9 JobBatchRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)6 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)3 RequestHandler (io.camunda.zeebe.gateway.api.util.StubbedBrokerClient.RequestHandler)3 BrokerActivateJobsRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest)3 BrokerRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerRequest)3 BrokerRejection (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection)3 BrokerRejectionResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejectionResponse)3 BrokerResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse)3 GatewayCfg (io.camunda.zeebe.gateway.impl.configuration.GatewayCfg)3 ActivateJobsRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest)3 ActivateJobsResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse)3 ActivatedJob (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob)3 LoggedEvent (io.camunda.zeebe.logstreams.log.LoggedEvent)3 Protocol (io.camunda.zeebe.protocol.Protocol)3 CopiedRecord (io.camunda.zeebe.protocol.impl.record.CopiedRecord)3 RecordMetadata (io.camunda.zeebe.protocol.impl.record.RecordMetadata)3 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)3 RecordType (io.camunda.zeebe.protocol.record.RecordType)3