use of org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException in project pulsar by apache.
the class NamespacesBase method internalCreateNamespace.
protected void internalCreateNamespace(Policies policies) {
validateTenantOperation(namespaceName.getTenant(), TenantOperation.CREATE_NAMESPACE);
validatePoliciesReadOnlyAccess();
validatePolicies(namespaceName, policies);
try {
int maxNamespacesPerTenant = pulsar().getConfiguration().getMaxNamespacesPerTenant();
// no distributed locks are added here.In a concurrent scenario, the threshold will be exceeded.
if (maxNamespacesPerTenant > 0) {
List<String> namespaces = tenantResources().getListOfNamespaces(namespaceName.getTenant());
if (namespaces != null && namespaces.size() > maxNamespacesPerTenant) {
throw new RestException(Status.PRECONDITION_FAILED, "Exceed the maximum number of namespace in tenant :" + namespaceName.getTenant());
}
}
namespaceResources().createPolicies(namespaceName, policies);
log.info("[{}] Created namespace {}", clientAppId(), namespaceName);
} catch (AlreadyExistsException e) {
log.warn("[{}] Failed to create namespace {} - already exists", clientAppId(), namespaceName);
throw new RestException(Status.CONFLICT, "Namespace already exists");
} catch (Exception e) {
log.error("[{}] Failed to create namespace {}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException in project pulsar by apache.
the class PulsarWorkerService method initInBroker.
@Override
public void initInBroker(ServiceConfiguration brokerConfig, WorkerConfig workerConfig, PulsarResources pulsarResources, InternalConfigurationData internalConf) throws Exception {
String namespace = workerConfig.getPulsarFunctionsNamespace();
String[] a = workerConfig.getPulsarFunctionsNamespace().split("/");
String tenant = a[0];
String cluster = workerConfig.getPulsarFunctionsCluster();
// create tenant for function worker service
try {
NamedEntity.checkName(tenant);
pulsarResources.getTenantResources().createTenant(tenant, new TenantInfoImpl(Sets.newHashSet(workerConfig.getSuperUserRoles()), Sets.newHashSet(cluster)));
LOG.info("Created tenant {} for function worker", tenant);
} catch (AlreadyExistsException e) {
LOG.debug("Failed to create already existing property {} for function worker service", cluster, e);
} catch (IllegalArgumentException e) {
LOG.error("Failed to create property with invalid name {} for function worker service", cluster, e);
throw e;
} catch (Exception e) {
LOG.error("Failed to create property {} for function worker", cluster, e);
throw e;
}
// create cluster for function worker service
try {
NamedEntity.checkName(cluster);
ClusterDataImpl clusterData = ClusterDataImpl.builder().serviceUrl(workerConfig.getPulsarWebServiceUrl()).brokerServiceUrl(workerConfig.getPulsarServiceUrl()).build();
pulsarResources.getClusterResources().createCluster(cluster, clusterData);
LOG.info("Created cluster {} for function worker", cluster);
} catch (AlreadyExistsException e) {
LOG.debug("Failed to create already existing cluster {} for function worker service", cluster, e);
} catch (IllegalArgumentException e) {
LOG.error("Failed to create cluster with invalid name {} for function worker service", cluster, e);
throw e;
} catch (Exception e) {
LOG.error("Failed to create cluster {} for function worker service", cluster, e);
throw e;
}
// create namespace for function worker service
try {
Policies policies = createFunctionsNamespacePolicies(workerConfig.getPulsarFunctionsCluster());
policies.bundles = getBundles(brokerConfig.getDefaultNumberOfNamespaceBundles());
pulsarResources.getNamespaceResources().createPolicies(NamespaceName.get(namespace), policies);
LOG.info("Created namespace {} for function worker service", namespace);
} catch (AlreadyExistsException e) {
LOG.debug("Failed to create already existing namespace {} for function worker service", namespace);
} catch (Exception e) {
LOG.error("Failed to create namespace {}", namespace, e);
throw e;
}
URI dlogURI;
try {
// initializing dlog namespace for function worker
if (workerConfig.isInitializedDlogMetadata()) {
String metadataStoreUrl = removeIdentifierFromMetadataURL(internalConf.getMetadataStoreUrl());
dlogURI = WorkerUtils.newDlogNamespaceURI(metadataStoreUrl);
} else {
dlogURI = WorkerUtils.initializeDlogNamespace(internalConf);
}
} catch (IOException ioe) {
LOG.error("Failed to initialize dlog namespace with zookeeper {} at at metadata service uri {} for " + "storing function packages", internalConf.getMetadataStoreUrl(), internalConf.getBookkeeperMetadataServiceUri(), ioe);
throw ioe;
}
init(workerConfig, dlogURI, false);
LOG.info("Function worker service setup completed");
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException 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.AlreadyExistsException in project pulsar by yahoo.
the class PulsarWorkerService method initInBroker.
@Override
public void initInBroker(ServiceConfiguration brokerConfig, WorkerConfig workerConfig, PulsarResources pulsarResources, InternalConfigurationData internalConf) throws Exception {
String namespace = workerConfig.getPulsarFunctionsNamespace();
String[] a = workerConfig.getPulsarFunctionsNamespace().split("/");
String tenant = a[0];
String cluster = workerConfig.getPulsarFunctionsCluster();
// create tenant for function worker service
try {
NamedEntity.checkName(tenant);
pulsarResources.getTenantResources().createTenant(tenant, new TenantInfoImpl(Sets.newHashSet(workerConfig.getSuperUserRoles()), Sets.newHashSet(cluster)));
LOG.info("Created tenant {} for function worker", tenant);
} catch (AlreadyExistsException e) {
LOG.debug("Failed to create already existing property {} for function worker service", cluster, e);
} catch (IllegalArgumentException e) {
LOG.error("Failed to create property with invalid name {} for function worker service", cluster, e);
throw e;
} catch (Exception e) {
LOG.error("Failed to create property {} for function worker", cluster, e);
throw e;
}
// create cluster for function worker service
try {
NamedEntity.checkName(cluster);
ClusterDataImpl clusterData = ClusterDataImpl.builder().serviceUrl(workerConfig.getPulsarWebServiceUrl()).brokerServiceUrl(workerConfig.getPulsarServiceUrl()).build();
pulsarResources.getClusterResources().createCluster(cluster, clusterData);
LOG.info("Created cluster {} for function worker", cluster);
} catch (AlreadyExistsException e) {
LOG.debug("Failed to create already existing cluster {} for function worker service", cluster, e);
} catch (IllegalArgumentException e) {
LOG.error("Failed to create cluster with invalid name {} for function worker service", cluster, e);
throw e;
} catch (Exception e) {
LOG.error("Failed to create cluster {} for function worker service", cluster, e);
throw e;
}
// create namespace for function worker service
try {
Policies policies = createFunctionsNamespacePolicies(workerConfig.getPulsarFunctionsCluster());
policies.bundles = getBundles(brokerConfig.getDefaultNumberOfNamespaceBundles());
pulsarResources.getNamespaceResources().createPolicies(NamespaceName.get(namespace), policies);
LOG.info("Created namespace {} for function worker service", namespace);
} catch (AlreadyExistsException e) {
LOG.debug("Failed to create already existing namespace {} for function worker service", namespace);
} catch (Exception e) {
LOG.error("Failed to create namespace {}", namespace, e);
throw e;
}
URI dlogURI = null;
if (brokerConfig.isMetadataStoreBackedByZookeeper()) {
try {
// initializing dlog namespace for function worker
if (workerConfig.isInitializedDlogMetadata()) {
String metadataStoreUrl = removeIdentifierFromMetadataURL(internalConf.getMetadataStoreUrl());
dlogURI = WorkerUtils.newDlogNamespaceURI(metadataStoreUrl);
} else {
dlogURI = WorkerUtils.initializeDlogNamespace(internalConf);
}
} catch (IOException ioe) {
LOG.error("Failed to initialize dlog namespace with zookeeper {} at at metadata service uri {} for " + "storing function packages", internalConf.getMetadataStoreUrl(), internalConf.getBookkeeperMetadataServiceUri(), ioe);
throw ioe;
}
}
init(workerConfig, dlogURI, false);
LOG.info("Function worker service setup completed");
}
use of org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException in project pulsar by yahoo.
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;
}
Aggregations