use of org.apache.pulsar.broker.resources.NamespaceResources.PartitionedTopicResources in project pulsar by apache.
the class BrokerService method createDefaultPartitionedTopicAsync.
@SuppressWarnings("deprecation")
private CompletableFuture<PartitionedTopicMetadata> createDefaultPartitionedTopicAsync(TopicName topicName) {
final int defaultNumPartitions = pulsar.getBrokerService().getDefaultNumPartitions(topicName);
final int maxPartitions = pulsar().getConfig().getMaxNumPartitionsPerPartitionedTopic();
checkArgument(defaultNumPartitions > 0, "Default number of partitions should be more than 0");
checkArgument(maxPartitions <= 0 || defaultNumPartitions <= maxPartitions, "Number of partitions should be less than or equal to " + maxPartitions);
PartitionedTopicMetadata configMetadata = new PartitionedTopicMetadata(defaultNumPartitions);
return checkMaxTopicsPerNamespace(topicName, defaultNumPartitions).thenCompose(__ -> {
PartitionedTopicResources partitionResources = pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources();
return partitionResources.createPartitionedTopicAsync(topicName, configMetadata).thenApply(v -> {
log.info("partitioned metadata successfully created for {}", topicName);
return configMetadata;
});
});
}
use of org.apache.pulsar.broker.resources.NamespaceResources.PartitionedTopicResources in project pulsar by apache.
the class PersistentTopic method tryToDeletePartitionedMetadata.
private CompletableFuture<Void> tryToDeletePartitionedMetadata() {
if (TopicName.get(topic).isPartitioned() && !deletePartitionedTopicMetadataWhileInactive()) {
return CompletableFuture.completedFuture(null);
}
TopicName topicName = TopicName.get(TopicName.get(topic).getPartitionedTopicName());
PartitionedTopicResources partitionedTopicResources = getBrokerService().pulsar().getPulsarResources().getNamespaceResources().getPartitionedTopicResources();
return partitionedTopicResources.partitionedTopicExistsAsync(topicName).thenCompose(partitionedTopicExist -> {
if (!partitionedTopicExist) {
return CompletableFuture.completedFuture(null);
} else {
return getBrokerService().fetchPartitionedTopicMetadataAsync(topicName).thenCompose((metadata -> {
List<CompletableFuture<Boolean>> persistentTopicExists = new ArrayList<>(metadata.partitions);
for (int i = 0; i < metadata.partitions; i++) {
persistentTopicExists.add(brokerService.getPulsar().getPulsarResources().getTopicResources().persistentTopicExists(topicName.getPartition(i)));
}
List<CompletableFuture<Boolean>> unmodifiablePersistentTopicExists = Collections.unmodifiableList(persistentTopicExists);
return FutureUtil.waitForAll(unmodifiablePersistentTopicExists).thenCompose(unused -> {
// make sure all sub partitions were deleted after all future complete
Optional<Boolean> anyExistPartition = unmodifiablePersistentTopicExists.stream().map(CompletableFuture::join).filter(topicExist -> topicExist).findAny();
if (anyExistPartition.isPresent()) {
log.error("[{}] Delete topic metadata failed because" + " another partition exist.", topicName);
throw new UnsupportedOperationException(String.format("Another partition exists for [%s].", topicName));
} else {
return partitionedTopicResources.deletePartitionedTopicAsync(topicName);
}
});
}));
}
});
}
use of org.apache.pulsar.broker.resources.NamespaceResources.PartitionedTopicResources in project pulsar by yahoo.
the class PersistentTopic method tryToDeletePartitionedMetadata.
private CompletableFuture<Void> tryToDeletePartitionedMetadata() {
if (TopicName.get(topic).isPartitioned() && !deletePartitionedTopicMetadataWhileInactive()) {
return CompletableFuture.completedFuture(null);
}
TopicName topicName = TopicName.get(TopicName.get(topic).getPartitionedTopicName());
PartitionedTopicResources partitionedTopicResources = getBrokerService().pulsar().getPulsarResources().getNamespaceResources().getPartitionedTopicResources();
return partitionedTopicResources.partitionedTopicExistsAsync(topicName).thenCompose(partitionedTopicExist -> {
if (!partitionedTopicExist) {
return CompletableFuture.completedFuture(null);
} else {
return getBrokerService().fetchPartitionedTopicMetadataAsync(topicName).thenCompose((metadata -> {
List<CompletableFuture<Boolean>> persistentTopicExists = new ArrayList<>(metadata.partitions);
for (int i = 0; i < metadata.partitions; i++) {
persistentTopicExists.add(brokerService.getPulsar().getPulsarResources().getTopicResources().persistentTopicExists(topicName.getPartition(i)));
}
List<CompletableFuture<Boolean>> unmodifiablePersistentTopicExists = Collections.unmodifiableList(persistentTopicExists);
return FutureUtil.waitForAll(unmodifiablePersistentTopicExists).thenCompose(unused -> {
// make sure all sub partitions were deleted after all future complete
Optional<Boolean> anyExistPartition = unmodifiablePersistentTopicExists.stream().map(CompletableFuture::join).filter(topicExist -> topicExist).findAny();
if (anyExistPartition.isPresent()) {
log.error("[{}] Delete topic metadata failed because" + " another partition exist.", topicName);
throw new UnsupportedOperationException(String.format("Another partition exists for [%s].", topicName));
} else {
return partitionedTopicResources.deletePartitionedTopicAsync(topicName);
}
});
}));
}
});
}
use of org.apache.pulsar.broker.resources.NamespaceResources.PartitionedTopicResources in project incubator-pulsar by apache.
the class PersistentTopic method tryToDeletePartitionedMetadata.
private CompletableFuture<Void> tryToDeletePartitionedMetadata() {
if (TopicName.get(topic).isPartitioned() && !deletePartitionedTopicMetadataWhileInactive()) {
return CompletableFuture.completedFuture(null);
}
TopicName topicName = TopicName.get(TopicName.get(topic).getPartitionedTopicName());
PartitionedTopicResources partitionedTopicResources = getBrokerService().pulsar().getPulsarResources().getNamespaceResources().getPartitionedTopicResources();
return partitionedTopicResources.partitionedTopicExistsAsync(topicName).thenCompose(partitionedTopicExist -> {
if (!partitionedTopicExist) {
return CompletableFuture.completedFuture(null);
} else {
return getBrokerService().fetchPartitionedTopicMetadataAsync(topicName).thenCompose((metadata -> {
List<CompletableFuture<Boolean>> persistentTopicExists = new ArrayList<>(metadata.partitions);
for (int i = 0; i < metadata.partitions; i++) {
persistentTopicExists.add(brokerService.getPulsar().getPulsarResources().getTopicResources().persistentTopicExists(topicName.getPartition(i)));
}
List<CompletableFuture<Boolean>> unmodifiablePersistentTopicExists = Collections.unmodifiableList(persistentTopicExists);
return FutureUtil.waitForAll(unmodifiablePersistentTopicExists).thenCompose(unused -> {
// make sure all sub partitions were deleted after all future complete
Optional<Boolean> anyExistPartition = unmodifiablePersistentTopicExists.stream().map(CompletableFuture::join).filter(topicExist -> topicExist).findAny();
if (anyExistPartition.isPresent()) {
log.error("[{}] Delete topic metadata failed because" + " another partition exist.", topicName);
throw new UnsupportedOperationException(String.format("Another partition exists for [%s].", topicName));
} else {
return partitionedTopicResources.deletePartitionedTopicAsync(topicName);
}
});
}));
}
});
}
use of org.apache.pulsar.broker.resources.NamespaceResources.PartitionedTopicResources in project incubator-pulsar by apache.
the class BrokerService method createDefaultPartitionedTopicAsync.
@SuppressWarnings("deprecation")
private CompletableFuture<PartitionedTopicMetadata> createDefaultPartitionedTopicAsync(TopicName topicName) {
if (topicName.getLocalName().contains(TopicName.PARTITIONED_TOPIC_SUFFIX)) {
return FutureUtil.failedFuture(new PulsarServerException.InvalidTopicNameException(String.format("Invalid topic name: %s , should not contain -partition-", topicName)));
}
final int defaultNumPartitions = pulsar.getBrokerService().getDefaultNumPartitions(topicName);
final int maxPartitions = pulsar().getConfig().getMaxNumPartitionsPerPartitionedTopic();
checkArgument(defaultNumPartitions > 0, "Default number of partitions should be more than 0");
checkArgument(maxPartitions <= 0 || defaultNumPartitions <= maxPartitions, "Number of partitions should be less than or equal to " + maxPartitions);
PartitionedTopicMetadata configMetadata = new PartitionedTopicMetadata(defaultNumPartitions);
return checkMaxTopicsPerNamespace(topicName, defaultNumPartitions).thenCompose(__ -> {
PartitionedTopicResources partitionResources = pulsar.getPulsarResources().getNamespaceResources().getPartitionedTopicResources();
return partitionResources.createPartitionedTopicAsync(topicName, configMetadata).thenApply(v -> {
log.info("partitioned metadata successfully created for {}", topicName);
return configMetadata;
});
});
}
Aggregations