Search in sources :

Example 66 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class CreateTopicProcessor method processEvent.

@Override
public void processEvent(TypedEvent<TopicEvent> event) {
    final TopicEvent value = event.getValue();
    final DirectBuffer nameBuffer = value.getName();
    final boolean topicExists = topics.moveTo(nameBuffer);
    if (topicExists || value.getPartitions() <= 0) {
        value.setState(TopicState.CREATE_REJECTED);
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer)

Example 67 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class PartitionCreatedProcessor method processEvent.

@Override
public void processEvent(TypedEvent<PartitionEvent> event) {
    final PartitionEvent value = event.getValue();
    final DirectBuffer topicName = value.getTopicName();
    topics.moveTo(topicName);
    // == 1 because this is the last partition
    final boolean topicCreationComplete = topics.getRemainingPartitions() == 1;
    if (topicCreationComplete) {
        createRequest = reader.readValue(topics.getRequestPosition(), TopicEvent.class);
        createRequest.getValue().setState(TopicState.CREATED);
        Loggers.SYSTEM_LOGGER.debug("Topic '{}' created.", BufferUtil.bufferAsString(topicName));
    } else {
        Loggers.SYSTEM_LOGGER.debug("Partition '{}' created. Topic '{}' has {} remaining partitions.", value.getId(), BufferUtil.bufferAsString(topicName), topics.getRemainingPartitions());
        createRequest = null;
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer)

Example 68 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class PartitionCreatedProcessor method updateState.

@Override
public void updateState(TypedEvent<PartitionEvent> event) {
    final DirectBuffer topicName = event.getValue().getTopicName();
    topics.moveTo(topicName);
    final int remainingPartitions = topics.getRemainingPartitions();
    if (remainingPartitions > 0) {
        topics.put(topicName, remainingPartitions - 1, topics.getRequestPosition());
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer)

Example 69 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class CreatePartitionProcessor method executeSideEffects.

@Override
public boolean executeSideEffects(TypedEvent<PartitionEvent> event, TypedResponseWriter responseWriter) {
    final PartitionEvent value = event.getValue();
    final TopologyBroker creator = value.getCreator();
    final DirectBuffer creatorHost = creator.getHost();
    creatorAddress.host(creatorHost, 0, creatorHost.capacity());
    creatorAddress.port(creator.getPort());
    final ActorFuture<ClientResponse> partitionRemote = partitionManager.createPartitionRemote(creatorAddress, value.getTopicName(), value.getId());
    actor.runOnCompletion(partitionRemote, ((clientRequest, throwable) -> {
        if (throwable == null) {
            clientRequest.close();
        } else {
            Loggers.SYSTEM_LOGGER.error("Failed to create partitions request.", throwable);
        }
    }));
    return true;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) ActorControl(io.zeebe.util.sched.ActorControl) ActorClock(io.zeebe.util.sched.clock.ActorClock) ActorFuture(io.zeebe.util.sched.future.ActorFuture) io.zeebe.broker.logstreams.processor(io.zeebe.broker.logstreams.processor) io.zeebe.transport(io.zeebe.transport) Duration(java.time.Duration) Loggers(io.zeebe.broker.Loggers) PartitionManager(io.zeebe.broker.clustering.management.PartitionManager) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker) DirectBuffer(org.agrona.DirectBuffer) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker)

Example 70 with DirectBuffer

use of org.agrona.DirectBuffer in project zeebe by zeebe-io.

the class DeploymentCreateProcessor method readAndValidateWorkflows.

private boolean readAndValidateWorkflows(final DeploymentEvent deploymentEvent) {
    final DirectBuffer topicName = deploymentEvent.getTopicName();
    final StringBuilder validationErrors = new StringBuilder();
    boolean success = true;
    deploymentResourceIterator.wrap(deploymentEvent);
    if (!deploymentResourceIterator.hasNext()) {
        validationErrors.append("Deployment doesn't contain a resource to deploy.");
        success = false;
    }
    while (deploymentResourceIterator.hasNext()) {
        final DeploymentResource deploymentResource = deploymentResourceIterator.next();
        try {
            success &= readAndValidateWorkflowsOfResource(deploymentResource, topicName, validationErrors);
        } catch (Exception e) {
            validationErrors.append(String.format("Failed to deploy resource '%s':\n", bufferAsString(deploymentResource.getResourceName())));
            validationErrors.append(generateErrorMessage(e));
            success = false;
        }
    }
    deploymentEvent.setErrorMessage(validationErrors.toString());
    return success;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) DeploymentResource(io.zeebe.broker.workflow.data.DeploymentResource)

Aggregations

DirectBuffer (org.agrona.DirectBuffer)116 Header (io.aeron.logbuffer.Header)21 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)21 MutableDirectBuffer (org.agrona.MutableDirectBuffer)20 File (java.io.File)19 MediaDriver (io.aeron.driver.MediaDriver)18 CountersReader (org.agrona.concurrent.status.CountersReader)15 ThreadingMode (io.aeron.driver.ThreadingMode)12 FragmentHandler (io.aeron.logbuffer.FragmentHandler)12 MappedByteBuffer (java.nio.MappedByteBuffer)12 ClusteredService (io.aeron.cluster.service.ClusteredService)10 InterruptAfter (io.aeron.test.InterruptAfter)10 Test (org.junit.jupiter.api.Test)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 Publication (io.aeron.Publication)9 ClientSession (io.aeron.cluster.service.ClientSession)9 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)8 Assertions (org.junit.jupiter.api.Assertions)8 Mockito.mock (org.mockito.Mockito.mock)8