use of org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException in project pulsar by apache.
the class LoadBalancerTest method createNamespacePolicies.
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
// // prepare three policies for the namespace isolation
NamespaceIsolationPolicies policies = new NamespaceIsolationPolicies();
// set up policy that use this broker as primary
Map<String, String> parameters = new HashMap<>();
parameters.put("min_limit", "1");
parameters.put("usage_threshold", "100");
List<String> allBrokers = new ArrayList<>();
for (int i = 0; i < BROKER_COUNT; i++) {
allBrokers.add(pulsarServices[i].getAdvertisedAddress());
}
NamespaceIsolationData policyData = NamespaceIsolationData.builder().namespaces(Collections.singletonList("pulsar/use/primary-ns.*")).primary(allBrokers).secondary(Collections.emptyList()).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters).build()).build();
policies.setPolicy("primaryBrokerPolicy", policyData);
List<String> allExceptFirstBroker = new ArrayList<>();
for (int i = 1; i < BROKER_COUNT; i++) {
allExceptFirstBroker.add(pulsarServices[i].getAdvertisedAddress());
}
// set up policy that use this broker as secondary
policyData = NamespaceIsolationData.builder().namespaces(Collections.singletonList("pulsar/use/secondary-ns.*")).primary(Collections.singletonList(pulsarServices[0].getWebServiceAddress())).secondary(allExceptFirstBroker).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters).build()).build();
policies.setPolicy("secondaryBrokerPolicy", policyData);
// set up policy that do not use this broker (neither primary nor secondary)
policyData = NamespaceIsolationData.builder().namespaces(Collections.singletonList("pulsar/use/shared-ns.*")).primary(Collections.singletonList(pulsarServices[0].getWebServiceAddress())).secondary(allExceptFirstBroker).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters).build()).build();
policies.setPolicy("otherBrokerPolicy", policyData);
try {
pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().createIsolationData("use", policies.getPolicies());
} catch (BadVersionException e) {
// isolation policy already exist
pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().setIsolationData("use", data -> policies.getPolicies());
}
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException in project pulsar by apache.
the class SimpleLoadManagerImplTest method createNamespacePolicies.
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
Map<String, String> parameters = new HashMap<>();
parameters.put("min_limit", "1");
parameters.put("usage_threshold", "100");
NamespaceIsolationPolicies policies = new NamespaceIsolationPolicies();
// set up policy that use this broker as primary
NamespaceIsolationData policyData = NamespaceIsolationData.builder().namespaces(Collections.singletonList("pulsar/use/primary-ns.*")).primary(Collections.singletonList(pulsar1.getAdvertisedAddress() + "*")).secondary(Collections.singletonList("prod2-broker([78]).messaging.usw.example.co.*")).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters).build()).build();
policies.setPolicy("primaryBrokerPolicy", policyData);
try {
pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().createIsolationData("use", policies.getPolicies());
} catch (BadVersionException e) {
// isolation policy already exist
pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().setIsolationData("use", data -> policies.getPolicies());
}
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException in project pulsar by apache.
the class MetadataCacheImpl method create.
@Override
public CompletableFuture<Void> create(String path, T value) {
byte[] content;
try {
content = serde.serialize(path, value);
} catch (Throwable t) {
return FutureUtils.exception(t);
}
CompletableFuture<Void> future = new CompletableFuture<>();
store.put(path, content, Optional.of(-1L)).thenAccept(stat -> {
// Make sure we have the value cached before the operation is completed
// In addition to caching the value, we need to add a watch on the path,
// so when/if it changes on any other node, we are notified and we can
// update the cache
objCache.get(path).whenComplete((stat2, ex) -> {
if (ex == null) {
future.complete(null);
} else {
log.error("Exception while getting path {}", path, ex);
future.completeExceptionally(ex.getCause());
}
});
}).exceptionally(ex -> {
if (ex.getCause() instanceof BadVersionException) {
// Use already exists exception to provide more self-explanatory error message
future.completeExceptionally(new AlreadyExistsException(ex.getCause()));
} else {
future.completeExceptionally(ex.getCause());
}
return null;
});
return future;
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException in project pulsar by yahoo.
the class LoadBalancerTest method createNamespacePolicies.
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
// // prepare three policies for the namespace isolation
NamespaceIsolationPolicies policies = new NamespaceIsolationPolicies();
// set up policy that use this broker as primary
Map<String, String> parameters = new HashMap<>();
parameters.put("min_limit", "1");
parameters.put("usage_threshold", "100");
List<String> allBrokers = new ArrayList<>();
for (int i = 0; i < BROKER_COUNT; i++) {
allBrokers.add(pulsarServices[i].getAdvertisedAddress());
}
NamespaceIsolationData policyData = NamespaceIsolationData.builder().namespaces(Collections.singletonList("pulsar/use/primary-ns.*")).primary(allBrokers).secondary(Collections.emptyList()).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters).build()).build();
policies.setPolicy("primaryBrokerPolicy", policyData);
List<String> allExceptFirstBroker = new ArrayList<>();
for (int i = 1; i < BROKER_COUNT; i++) {
allExceptFirstBroker.add(pulsarServices[i].getAdvertisedAddress());
}
// set up policy that use this broker as secondary
policyData = NamespaceIsolationData.builder().namespaces(Collections.singletonList("pulsar/use/secondary-ns.*")).primary(Collections.singletonList(pulsarServices[0].getWebServiceAddress())).secondary(allExceptFirstBroker).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters).build()).build();
policies.setPolicy("secondaryBrokerPolicy", policyData);
// set up policy that do not use this broker (neither primary nor secondary)
policyData = NamespaceIsolationData.builder().namespaces(Collections.singletonList("pulsar/use/shared-ns.*")).primary(Collections.singletonList(pulsarServices[0].getWebServiceAddress())).secondary(allExceptFirstBroker).autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(AutoFailoverPolicyType.min_available).parameters(parameters).build()).build();
policies.setPolicy("otherBrokerPolicy", policyData);
try {
pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().createIsolationData("use", policies.getPolicies());
} catch (BadVersionException e) {
// isolation policy already exist
pulsar.getPulsarResources().getNamespaceResources().getIsolationPolicies().setIsolationData("use", data -> policies.getPolicies());
}
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException in project pulsar by yahoo.
the class NamespacesBase method updatePoliciesAsync.
private CompletableFuture<Void> updatePoliciesAsync(NamespaceName ns, Function<Policies, Policies> updateFunction) {
CompletableFuture<Void> result = new CompletableFuture<>();
namespaceResources().setPoliciesAsync(ns, updateFunction).thenAccept(v -> {
log.info("[{}] Successfully updated the policies on namespace {}", clientAppId(), namespaceName);
result.complete(null);
}).exceptionally(ex -> {
Throwable cause = ex.getCause();
if (cause instanceof NotFoundException) {
result.completeExceptionally(new RestException(Status.NOT_FOUND, "Namespace does not exist"));
} else if (cause instanceof BadVersionException) {
log.warn("[{}] Failed to update the replication clusters on" + " namespace {} : concurrent modification", clientAppId(), namespaceName);
result.completeExceptionally(new RestException(Status.CONFLICT, "Concurrent modification"));
} else {
log.error("[{}] Failed to update namespace policies {}", clientAppId(), namespaceName, cause);
result.completeExceptionally(new RestException(cause));
}
return null;
});
return result;
}
Aggregations