use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class NamespacesBase method internalGetDispatchRate.
protected DispatchRate internalGetDispatchRate() {
validateAdminAccessOnProperty(namespaceName.getProperty());
Policies policies = getNamespacePolicies(namespaceName);
DispatchRate dispatchRate = policies.clusterDispatchRate.get(pulsar().getConfiguration().getClusterName());
if (dispatchRate != null) {
return dispatchRate;
} else {
throw new RestException(Status.NOT_FOUND, "Dispatch-rate is not configured for cluster " + pulsar().getConfiguration().getClusterName());
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class NamespacesBase method internalSetRetention.
protected void internalSetRetention(RetentionPolicies retention) {
validatePoliciesReadOnlyAccess();
try {
Stat nodeStat = new Stat();
final String path = path(POLICIES, namespaceName.toString());
byte[] content = globalZk().getData(path, null, nodeStat);
Policies policies = jsonMapper().readValue(content, Policies.class);
if (!checkQuotas(policies, retention)) {
log.warn("[{}] Failed to update retention configuration for namespace {}: conflicts with backlog quota", clientAppId(), namespaceName);
throw new RestException(Status.PRECONDITION_FAILED, "Retention Quota must exceed configured backlog quota for namespace.");
}
policies.retention_policies = retention;
globalZk().setData(path, jsonMapper().writeValueAsBytes(policies), nodeStat.getVersion());
policiesCache().invalidate(path(POLICIES, namespaceName.toString()));
log.info("[{}] Successfully updated retention configuration: namespace={}, map={}", clientAppId(), namespaceName, jsonMapper().writeValueAsString(policies.retention_policies));
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to update retention configuration for namespace {}: does not exist", clientAppId(), namespaceName);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (KeeperException.BadVersionException e) {
log.warn("[{}] Failed to update retention configuration for namespace {}: concurrent modification", clientAppId(), namespaceName);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (RestException pfe) {
throw pfe;
} catch (Exception e) {
log.error("[{}] Failed to update retention configuration for namespace {}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class NamespacesBase method internalRemoveBacklogQuota.
protected void internalRemoveBacklogQuota(BacklogQuotaType backlogQuotaType) {
validateAdminAccessOnProperty(namespaceName.getProperty());
validatePoliciesReadOnlyAccess();
if (backlogQuotaType == null) {
backlogQuotaType = BacklogQuotaType.destination_storage;
}
try {
Stat nodeStat = new Stat();
final String path = path(POLICIES, namespaceName.toString());
byte[] content = globalZk().getData(path, null, nodeStat);
Policies policies = jsonMapper().readValue(content, Policies.class);
policies.backlog_quota_map.remove(backlogQuotaType);
globalZk().setData(path, jsonMapper().writeValueAsBytes(policies), nodeStat.getVersion());
policiesCache().invalidate(path(POLICIES, namespaceName.toString()));
log.info("[{}] Successfully removed backlog namespace={}, quota={}", clientAppId(), namespaceName, backlogQuotaType);
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to update backlog quota map for namespace {}: does not exist", clientAppId(), namespaceName);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (KeeperException.BadVersionException e) {
log.warn("[{}] Failed to update backlog quota map for namespace {}: concurrent modification", clientAppId(), namespaceName);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (Exception e) {
log.error("[{}] Failed to update backlog quota map for namespace {}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class NamespacesBase method internalSetSubscriptionAuthMode.
protected void internalSetSubscriptionAuthMode(SubscriptionAuthMode subscriptionAuthMode) {
validateAdminAccessOnProperty(namespaceName.getProperty());
validatePoliciesReadOnlyAccess();
if (subscriptionAuthMode == null) {
subscriptionAuthMode = SubscriptionAuthMode.None;
}
try {
Stat nodeStat = new Stat();
final String path = path(POLICIES, namespaceName.toString());
byte[] content = globalZk().getData(path, null, nodeStat);
Policies policies = jsonMapper().readValue(content, Policies.class);
policies.subscription_auth_mode = subscriptionAuthMode;
globalZk().setData(path, jsonMapper().writeValueAsBytes(policies), nodeStat.getVersion());
policiesCache().invalidate(path(POLICIES, namespaceName.toString()));
log.info("[{}] Successfully updated subscription auth mode: namespace={}, map={}", clientAppId(), namespaceName, jsonMapper().writeValueAsString(policies.backlog_quota_map));
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to update subscription auth mode for namespace {}: does not exist", clientAppId(), namespaceName);
throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
} catch (KeeperException.BadVersionException e) {
log.warn("[{}] Failed to update subscription auth mode for namespace {}/{}/{}: concurrent modification", clientAppId(), namespaceName);
throw new RestException(Status.CONFLICT, "Concurrent modification");
} catch (RestException pfe) {
throw pfe;
} catch (Exception e) {
log.error("[{}] Failed to update subscription auth mode for namespace {}/{}/{}", clientAppId(), namespaceName, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class NamespacesBase method validateBundlesData.
protected BundlesData validateBundlesData(BundlesData initialBundles) {
SortedSet<String> partitions = new TreeSet<String>();
for (String partition : initialBundles.getBoundaries()) {
Long partBoundary = Long.decode(partition);
partitions.add(String.format("0x%08x", partBoundary));
}
if (partitions.size() != initialBundles.getBoundaries().size()) {
log.debug("Input bundles included repeated partition points. Ignored.");
}
try {
NamespaceBundleFactory.validateFullRange(partitions);
} catch (IllegalArgumentException iae) {
throw new RestException(Status.BAD_REQUEST, "Input bundles do not cover the whole hash range. first:" + partitions.first() + ", last:" + partitions.last());
}
List<String> bundles = Lists.newArrayList();
bundles.addAll(partitions);
return new BundlesData(bundles);
}
Aggregations