use of org.apache.pulsar.broker.service.schema.exceptions.SchemaException in project pulsar by yahoo.
the class TopicsBase method addSchema.
// Add a new schema to schema registry for a topic
private CompletableFuture<SchemaVersion> addSchema(SchemaData schemaData) {
// Only need to add to first partition the broker owns since the schema id in schema registry are
// same for all partitions which is the partitionedTopicName
List<Integer> partitions = pulsar().getBrokerService().getOwningTopics().get(topicName.getPartitionedTopicName()).values();
CompletableFuture<SchemaVersion> result = new CompletableFuture<>();
for (int index = 0; index < partitions.size(); index++) {
CompletableFuture<SchemaVersion> future = new CompletableFuture<>();
String topicPartitionName = topicName.getPartition(partitions.get(index)).toString();
pulsar().getBrokerService().getTopic(topicPartitionName, false).thenAccept(topic -> {
if (!topic.isPresent()) {
future.completeExceptionally(new BrokerServiceException.TopicNotFoundException("Topic " + topicPartitionName + " not found"));
} else {
topic.get().addSchema(schemaData).thenAccept(schemaVersion -> future.complete(schemaVersion)).exceptionally(exception -> {
future.completeExceptionally(exception);
return null;
});
}
});
try {
result.complete(future.get());
break;
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Fail to add schema to topic " + topicName.getPartitionedTopicName() + " for partition " + partitions.get(index) + " for REST produce request.");
}
}
}
// Not able to add schema to any partition
if (!result.isDone()) {
result.completeExceptionally(new SchemaException("Unable to add schema " + schemaData + " to topic " + topicName.getPartitionedTopicName()));
}
return result;
}
use of org.apache.pulsar.broker.service.schema.exceptions.SchemaException in project incubator-pulsar by apache.
the class TopicsBase method addSchema.
// Add a new schema to schema registry for a topic
private CompletableFuture<SchemaVersion> addSchema(SchemaData schemaData) {
// Only need to add to first partition the broker owns since the schema id in schema registry are
// same for all partitions which is the partitionedTopicName
List<Integer> partitions = pulsar().getBrokerService().getOwningTopics().get(topicName.getPartitionedTopicName()).values();
CompletableFuture<SchemaVersion> result = new CompletableFuture<>();
for (int index = 0; index < partitions.size(); index++) {
CompletableFuture<SchemaVersion> future = new CompletableFuture<>();
String topicPartitionName = topicName.getPartition(partitions.get(index)).toString();
pulsar().getBrokerService().getTopic(topicPartitionName, false).thenAccept(topic -> {
if (!topic.isPresent()) {
future.completeExceptionally(new BrokerServiceException.TopicNotFoundException("Topic " + topicPartitionName + " not found"));
} else {
topic.get().addSchema(schemaData).thenAccept(schemaVersion -> future.complete(schemaVersion)).exceptionally(exception -> {
future.completeExceptionally(exception);
return null;
});
}
});
try {
result.complete(future.get());
break;
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Fail to add schema to topic " + topicName.getPartitionedTopicName() + " for partition " + partitions.get(index) + " for REST produce request.");
}
}
}
// Not able to add schema to any partition
if (!result.isDone()) {
result.completeExceptionally(new SchemaException("Unable to add schema " + schemaData + " to topic " + topicName.getPartitionedTopicName()));
}
return result;
}
use of org.apache.pulsar.broker.service.schema.exceptions.SchemaException in project pulsar by apache.
the class TopicsBase method addSchema.
// Add a new schema to schema registry for a topic
private CompletableFuture<SchemaVersion> addSchema(SchemaData schemaData) {
// Only need to add to first partition the broker owns since the schema id in schema registry are
// same for all partitions which is the partitionedTopicName
List<Integer> partitions = pulsar().getBrokerService().getOwningTopics().get(topicName.getPartitionedTopicName()).values();
CompletableFuture<SchemaVersion> result = new CompletableFuture<>();
for (int index = 0; index < partitions.size(); index++) {
CompletableFuture<SchemaVersion> future = new CompletableFuture<>();
String topicPartitionName = topicName.getPartition(partitions.get(index)).toString();
pulsar().getBrokerService().getTopic(topicPartitionName, false).thenAccept(topic -> {
if (!topic.isPresent()) {
future.completeExceptionally(new BrokerServiceException.TopicNotFoundException("Topic " + topicPartitionName + " not found"));
} else {
topic.get().addSchema(schemaData).thenAccept(schemaVersion -> future.complete(schemaVersion)).exceptionally(exception -> {
future.completeExceptionally(exception);
return null;
});
}
});
try {
result.complete(future.get());
break;
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("Fail to add schema to topic " + topicName.getPartitionedTopicName() + " for partition " + partitions.get(index) + " for REST produce request.");
}
}
}
// Not able to add schema to any partition
if (!result.isDone()) {
result.completeExceptionally(new SchemaException("Unable to add schema " + schemaData + " to topic " + topicName.getPartitionedTopicName()));
}
return result;
}
Aggregations