Search in sources :

Example 1 with BrokerResponse

use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.

the class FailJobStub method handle.

@Override
public BrokerResponse<JobRecord> handle(final BrokerFailJobRequest request) throws Exception {
    final JobRecord responseValue = buildDefaultValue();
    responseValue.setRetries(request.getRequestWriter().getRetries());
    return new BrokerResponse<>(responseValue, 0, request.getKey());
}
Also used : BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) JobRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)

Example 2 with BrokerResponse

use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.

the class DeployProcessStub method handle.

@Override
public BrokerResponse<DeploymentRecord> handle(final BrokerDeployResourceRequest request) throws Exception {
    final DeploymentRecord deploymentRecord = request.getRequestWriter();
    deploymentRecord.resources().iterator().forEachRemaining(r -> {
        deploymentRecord.processesMetadata().add().setBpmnProcessId(r.getResourceNameBuffer()).setResourceName(r.getResourceNameBuffer()).setVersion(PROCESS_VERSION).setKey(PROCESS_KEY).setChecksum(CHECKSUM);
    });
    return new BrokerResponse<>(deploymentRecord, 0, KEY);
}
Also used : BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)

Example 3 with BrokerResponse

use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.

the class DeployResourceStub method handle.

@Override
public BrokerResponse<DeploymentRecord> handle(final BrokerDeployResourceRequest request) throws Exception {
    final DeploymentRecord deploymentRecord = request.getRequestWriter();
    deploymentRecord.resources().iterator().forEachRemaining(r -> {
        if (r.getResourceName().endsWith(".bpmn")) {
            deploymentRecord.processesMetadata().add().setBpmnProcessId(r.getResourceNameBuffer()).setResourceName(r.getResourceNameBuffer()).setVersion(PROCESS_VERSION).setKey(PROCESS_KEY).setChecksum(CHECKSUM);
        } else if (r.getResourceName().endsWith(".dmn")) {
            deploymentRecord.decisionsMetadata().add().setDecisionId(r.getResourceName()).setDecisionName(r.getResourceName()).setVersion(456).setDecisionKey(567).setDecisionRequirementsId(r.getResourceName()).setDecisionRequirementsKey(678);
            deploymentRecord.decisionRequirementsMetadata().add().setDecisionRequirementsId(r.getResourceName()).setDecisionRequirementsName(r.getResourceName()).setDecisionRequirementsVersion(456).setDecisionRequirementsKey(678).setNamespace(r.getResourceName()).setResourceName(r.getResourceName()).setChecksum(BufferUtil.wrapString("checksum"));
        }
    });
    return new BrokerResponse<>(deploymentRecord, 0, KEY);
}
Also used : BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)

Example 4 with BrokerResponse

use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.

the class ActivateJobsStub method handle.

@Override
public BrokerResponse<JobBatchRecord> handle(final BrokerActivateJobsRequest request) throws Exception {
    final int partitionId = request.getPartitionId();
    final JobBatchRecord requestDto = request.getRequestWriter();
    final JobBatchRecord response = new JobBatchRecord();
    response.setMaxJobsToActivate(requestDto.getMaxJobsToActivate());
    response.setWorker(requestDto.getWorkerBuffer());
    response.setType(requestDto.getTypeBuffer());
    response.setTimeout(requestDto.getTimeout());
    addJobs(response, partitionId, requestDto.getMaxJobsToActivate(), requestDto.getTypeBuffer(), requestDto.getWorkerBuffer());
    return new BrokerResponse<>(response, partitionId, Protocol.encodePartitionId(partitionId, JOB_BATCH_KEY));
}
Also used : BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) JobBatchRecord(io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)

Example 5 with BrokerResponse

use of io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse in project zeebe by camunda.

the class LongPollingActivateJobsTest method shouldReturnJobsIfSomeBrokersHaveJobsWhileOthersReturnResourceExhaustionResponse.

@Test
public void shouldReturnJobsIfSomeBrokersHaveJobsWhileOthersReturnResourceExhaustionResponse() {
    // given
    final InflightActivateJobsRequest request = new InflightActivateJobsRequest(getNextRequestId(), ActivateJobsRequest.newBuilder().setType(TYPE).setMaxJobsToActivate(15).setRequestTimeout(500).build(), spy(ServerStreamObserver.class));
    brokerClient.registerHandler(BrokerActivateJobsRequest.class, new RequestHandler<BrokerActivateJobsRequest, BrokerResponse<?>>() {

        private final ActivateJobsStub jobsAvailableStub = new ActivateJobsStub();

        {
            jobsAvailableStub.addAvailableJobs(TYPE, 10);
        }

        @Override
        public BrokerResponse<?> handle(final BrokerActivateJobsRequest request) throws Exception {
            final int partitionId = request.getPartitionId();
            if (partitionId == 4) {
                return new BrokerErrorResponse<>(new BrokerError(ErrorCode.RESOURCE_EXHAUSTED, "backpressure"));
            } else {
                return jobsAvailableStub.handle(request);
            }
        }
    });
    // when
    handler.activateJobs(request);
    waitUntil(request::isCompleted);
    // then
    assertThat(request.isTimedOut()).isFalse();
    final ArgumentCaptor<ActivateJobsResponse> responseArgumentCaptor = ArgumentCaptor.forClass(ActivateJobsResponse.class);
    verify(request.getResponseObserver()).onNext(responseArgumentCaptor.capture());
    final ActivateJobsResponse response = responseArgumentCaptor.getValue();
    assertThat(response.getJobsList()).hasSize(10);
}
Also used : InflightActivateJobsRequest(io.camunda.zeebe.gateway.impl.job.InflightActivateJobsRequest) ActivateJobsResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse) BrokerActivateJobsRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) StatusException(io.grpc.StatusException) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) ServerStreamObserver(io.camunda.zeebe.gateway.grpc.ServerStreamObserver) BrokerError(io.camunda.zeebe.gateway.impl.broker.response.BrokerError) Test(org.junit.Test)

Aggregations

BrokerResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse)44 BrokerActivateJobsRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerActivateJobsRequest)18 Test (org.junit.Test)18 BrokerRejectionException (io.camunda.zeebe.gateway.cmd.BrokerRejectionException)15 InflightActivateJobsRequest (io.camunda.zeebe.gateway.impl.job.InflightActivateJobsRequest)15 StatusException (io.grpc.StatusException)15 BrokerError (io.camunda.zeebe.gateway.impl.broker.response.BrokerError)12 ServerStreamObserver (io.camunda.zeebe.gateway.grpc.ServerStreamObserver)9 BrokerRejection (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection)9 ActivateJobsResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsResponse)9 JobBatchRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobBatchRecord)9 JobRecord (io.camunda.zeebe.protocol.impl.record.value.job.JobRecord)9 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)8 RequestHandler (io.camunda.zeebe.gateway.api.util.StubbedBrokerClient.RequestHandler)6 BrokerRejectionResponse (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejectionResponse)6 ActivateJobsRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivateJobsRequest)6 ActivatedJob (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.ActivatedJob)6 RejectionType (io.camunda.zeebe.protocol.record.RejectionType)6 Intent (io.camunda.zeebe.protocol.record.intent.Intent)6 Duration (java.time.Duration)6