use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class PersistentTopicsImpl method updatePartitionedTopicAsync.
@Override
public CompletableFuture<Void> updatePartitionedTopicAsync(String topic, int numPartitions) {
checkArgument(numPartitions > 1, "Number of partitions must be more than 1");
TopicName tn = validateTopic(topic);
WebTarget path = topicPath(tn, "partitions");
return asyncPostRequest(path, Entity.entity(numPartitions, MediaType.APPLICATION_JSON));
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class PersistentTopicsImpl method deleteAsync.
@Override
public CompletableFuture<Void> deleteAsync(String topic) {
TopicName tn = validateTopic(topic);
WebTarget path = topicPath(tn);
return asyncDeleteRequest(path);
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class BinaryProtoLookupService method findBroker.
private CompletableFuture<Pair<InetSocketAddress, InetSocketAddress>> findBroker(InetSocketAddress socketAddress, boolean authoritative, TopicName topicName) {
CompletableFuture<Pair<InetSocketAddress, InetSocketAddress>> addressFuture = new CompletableFuture<>();
client.getCnxPool().getConnection(socketAddress).thenAccept(clientCnx -> {
long requestId = client.newRequestId();
ByteBuf request = Commands.newLookup(topicName.toString(), authoritative, requestId);
clientCnx.newLookup(request, requestId).thenAccept(lookupDataResult -> {
URI uri = null;
try {
// (1) build response broker-address
if (useTls) {
uri = new URI(lookupDataResult.brokerUrlTls);
} else {
String serviceUrl = lookupDataResult.brokerUrl;
uri = new URI(serviceUrl);
}
InetSocketAddress responseBrokerAddress = InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
// (2) redirect to given address if response is: redirect
if (lookupDataResult.redirect) {
findBroker(responseBrokerAddress, lookupDataResult.authoritative, topicName).thenAccept(addressPair -> {
addressFuture.complete(addressPair);
}).exceptionally((lookupException) -> {
// lookup failed
log.warn("[{}] lookup failed : {}", topicName.toString(), lookupException.getMessage(), lookupException);
addressFuture.completeExceptionally(lookupException);
return null;
});
} else {
// (3) received correct broker to connect
if (lookupDataResult.proxyThroughServiceUrl) {
// Connect through proxy
addressFuture.complete(Pair.of(responseBrokerAddress, serviceAddress));
} else {
// Normal result with direct connection to broker
addressFuture.complete(Pair.of(responseBrokerAddress, responseBrokerAddress));
}
}
} catch (Exception parseUrlException) {
// Failed to parse url
log.warn("[{}] invalid url {} : {}", topicName.toString(), uri, parseUrlException.getMessage(), parseUrlException);
addressFuture.completeExceptionally(parseUrlException);
}
}).exceptionally((sendException) -> {
// lookup failed
log.warn("[{}] failed to send lookup request : {}", topicName.toString(), sendException.getMessage(), sendException instanceof ClosedChannelException ? null : sendException);
addressFuture.completeExceptionally(sendException);
return null;
});
}).exceptionally(connectionException -> {
addressFuture.completeExceptionally(connectionException);
return null;
});
return addressFuture;
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class BinaryProtoLookupService method getPartitionedTopicMetadata.
private CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(InetSocketAddress socketAddress, TopicName topicName) {
CompletableFuture<PartitionedTopicMetadata> partitionFuture = new CompletableFuture<PartitionedTopicMetadata>();
client.getCnxPool().getConnection(socketAddress).thenAccept(clientCnx -> {
long requestId = client.newRequestId();
ByteBuf request = Commands.newPartitionMetadataRequest(topicName.toString(), requestId);
clientCnx.newLookup(request, requestId).thenAccept(lookupDataResult -> {
try {
partitionFuture.complete(new PartitionedTopicMetadata(lookupDataResult.partitions));
} catch (Exception e) {
partitionFuture.completeExceptionally(new PulsarClientException.LookupException(format("Failed to parse partition-response redirect=%s , partitions with %s", lookupDataResult.redirect, lookupDataResult.partitions, e.getMessage())));
}
}).exceptionally((e) -> {
log.warn("[{}] failed to get Partitioned metadata : {}", topicName.toString(), e.getCause().getMessage(), e);
partitionFuture.completeExceptionally(e);
return null;
});
}).exceptionally(connectionException -> {
partitionFuture.completeExceptionally(connectionException);
return null;
});
return partitionFuture;
}
use of org.apache.pulsar.common.naming.TopicName in project incubator-pulsar by apache.
the class PulsarClientImpl method getPartitionedTopicMetadata.
public CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(String topic) {
CompletableFuture<PartitionedTopicMetadata> metadataFuture;
try {
TopicName topicName = TopicName.get(topic);
metadataFuture = lookup.getPartitionedTopicMetadata(topicName);
} catch (IllegalArgumentException e) {
return FutureUtil.failedFuture(new PulsarClientException.InvalidConfigurationException(e.getMessage()));
}
return metadataFuture;
}
Aggregations