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);
}
}
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;
}
}
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());
}
}
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;
}
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;
}
Aggregations