use of org.apache.pulsar.common.policies.data.BookieAffinityGroupData in project pulsar by apache.
the class NamespacesBase method internalSetBookieAffinityGroup.
protected void internalSetBookieAffinityGroup(BookieAffinityGroupData bookieAffinityGroup) {
validateSuperUserAccess();
log.info("[{}] Setting bookie-affinity-group {} for namespace {}", clientAppId(), bookieAffinityGroup, this.namespaceName);
if (namespaceName.isGlobal()) {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(namespaceName);
} else {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForTenant(namespaceName.getTenant(), namespaceName.getCluster());
}
try {
getLocalPolicies().setLocalPoliciesWithCreate(namespaceName, oldPolicies -> {
LocalPolicies localPolicies = oldPolicies.map(policies -> new LocalPolicies(policies.bundles, bookieAffinityGroup, policies.namespaceAntiAffinityGroup)).orElseGet(() -> new LocalPolicies(defaultBundle(), bookieAffinityGroup, null));
log.info("[{}] Successfully updated local-policies configuration: namespace={}, map={}", clientAppId(), namespaceName, localPolicies);
return localPolicies;
});
} catch (NotFoundException e) {
log.warn("[{}] Failed to update local-policy configuration for namespace {}: does not exist", clientAppId(), namespaceName);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (Exception e) {
log.error("[{}] Failed to update local-policy configuration for namespace {}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.common.policies.data.BookieAffinityGroupData in project pulsar by apache.
the class NamespacesBase method internalGetBookieAffinityGroup.
protected BookieAffinityGroupData internalGetBookieAffinityGroup() {
validateSuperUserAccess();
if (namespaceName.isGlobal()) {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(namespaceName);
} else {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForTenant(namespaceName.getTenant(), namespaceName.getCluster());
}
try {
final BookieAffinityGroupData bookkeeperAffinityGroup = getLocalPolicies().getLocalPolicies(namespaceName).orElseThrow(() -> new RestException(Status.NOT_FOUND, "Namespace local-policies does not exist")).bookieAffinityGroup;
return bookkeeperAffinityGroup;
} catch (NotFoundException e) {
log.warn("[{}] Failed to get local-policy configuration for namespace {}: does not exist", clientAppId(), namespaceName);
throw new RestException(Status.NOT_FOUND, "Namespace policies does not exist");
} catch (RestException re) {
throw re;
} catch (Exception e) {
log.error("[{}] Failed to get local-policy configuration for namespace {}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.common.policies.data.BookieAffinityGroupData in project pulsar by yahoo.
the class NamespaceCreateBundlesTest method testSplitBundleUpdatesLocalPoliciesWithoutOverwriting.
@Test
public void testSplitBundleUpdatesLocalPoliciesWithoutOverwriting() throws Exception {
String namespaceName = "prop/" + UUID.randomUUID().toString();
String topicName = "persistent://" + namespaceName + "/my-topic5";
admin.namespaces().createNamespace(namespaceName);
ProducerBuilder<byte[]> producerBuilder = pulsarClient.newProducer().topic(topicName).sendTimeout(1, TimeUnit.SECONDS);
Producer<byte[]> producer = producerBuilder.create();
String bundle = admin.lookups().getBundleRange(topicName);
BookieAffinityGroupData bookieAffinityGroup = BookieAffinityGroupData.builder().bookkeeperAffinityGroupPrimary("test").build();
admin.namespaces().setBookieAffinityGroup(namespaceName, bookieAffinityGroup);
admin.namespaces().splitNamespaceBundle(namespaceName, bundle, false, null);
assertNotNull(admin.namespaces().getBookieAffinityGroup(namespaceName));
producer.close();
}
use of org.apache.pulsar.common.policies.data.BookieAffinityGroupData in project pulsar by yahoo.
the class NamespacesBase method internalSetBookieAffinityGroup.
protected void internalSetBookieAffinityGroup(BookieAffinityGroupData bookieAffinityGroup) {
validateSuperUserAccess();
log.info("[{}] Setting bookie-affinity-group {} for namespace {}", clientAppId(), bookieAffinityGroup, this.namespaceName);
if (namespaceName.isGlobal()) {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(namespaceName);
} else {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForTenant(namespaceName.getTenant(), namespaceName.getCluster());
}
try {
getLocalPolicies().setLocalPoliciesWithCreate(namespaceName, oldPolicies -> {
LocalPolicies localPolicies = oldPolicies.map(policies -> new LocalPolicies(policies.bundles, bookieAffinityGroup, policies.namespaceAntiAffinityGroup)).orElseGet(() -> new LocalPolicies(defaultBundle(), bookieAffinityGroup, null));
log.info("[{}] Successfully updated local-policies configuration: namespace={}, map={}", clientAppId(), namespaceName, localPolicies);
return localPolicies;
});
} catch (NotFoundException e) {
log.warn("[{}] Failed to update local-policy configuration for namespace {}: does not exist", clientAppId(), namespaceName);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (Exception e) {
log.error("[{}] Failed to update local-policy configuration for namespace {}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.common.policies.data.BookieAffinityGroupData in project pulsar by yahoo.
the class NamespacesImpl method getBookieAffinityGroupAsync.
@Override
public CompletableFuture<BookieAffinityGroupData> getBookieAffinityGroupAsync(String namespace) {
NamespaceName ns = NamespaceName.get(namespace);
WebTarget path = namespacePath(ns, "persistence", "bookieAffinity");
final CompletableFuture<BookieAffinityGroupData> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<BookieAffinityGroupData>() {
@Override
public void completed(BookieAffinityGroupData bookieAffinityGroupData) {
future.complete(bookieAffinityGroupData);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
Aggregations