use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class BrokersBase method updateDynamicConfigurationOnZk.
/**
* if {@link ServiceConfiguration}-field is allowed to be modified dynamically, update configuration-map into zk, so
* all other brokers get the watch and can see the change and take appropriate action on the change.
*
* @param configName
* : configuration key
* @param configValue
* : configuration value
*/
private synchronized void updateDynamicConfigurationOnZk(String configName, String configValue) {
try {
if (!BrokerService.validateDynamicConfiguration(configName, configValue)) {
throw new RestException(Status.PRECONDITION_FAILED, " Invalid dynamic-config value");
}
if (BrokerService.isDynamicConfiguration(configName)) {
ZooKeeperDataCache<Map<String, String>> dynamicConfigurationCache = pulsar().getBrokerService().getDynamicConfigurationCache();
Map<String, String> configurationMap = dynamicConfigurationCache.get(BROKER_SERVICE_CONFIGURATION_PATH).orElse(null);
if (configurationMap != null) {
configurationMap.put(configName, configValue);
byte[] content = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(configurationMap);
dynamicConfigurationCache.invalidate(BROKER_SERVICE_CONFIGURATION_PATH);
serviceConfigZkVersion = localZk().setData(BROKER_SERVICE_CONFIGURATION_PATH, content, serviceConfigZkVersion).getVersion();
} else {
configurationMap = Maps.newHashMap();
configurationMap.put(configName, configValue);
byte[] content = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(configurationMap);
ZkUtils.createFullPathOptimistic(localZk(), BROKER_SERVICE_CONFIGURATION_PATH, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
LOG.info("[{}] Updated Service configuration {}/{}", clientAppId(), configName, configValue);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("[{}] Can't update non-dynamic configuration {}/{}", clientAppId(), configName, configValue);
}
throw new RestException(Status.PRECONDITION_FAILED, " Can't update non-dynamic configuration");
}
} catch (RestException re) {
throw re;
} catch (Exception ie) {
LOG.error("[{}] Failed to update configuration {}/{}, {}", clientAppId(), configName, configValue, ie.getMessage(), ie);
throw new RestException(ie);
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class BrokersBase method getOwnedNamespaes.
@GET
@Path("/{cluster}/{broker}/ownedNamespaces")
@ApiOperation(value = "Get the list of namespaces served by the specific broker", response = NamespaceOwnershipStatus.class, responseContainer = "Map")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Cluster doesn't exist") })
public Map<String, NamespaceOwnershipStatus> getOwnedNamespaes(@PathParam("cluster") String cluster, @PathParam("broker") String broker) throws Exception {
validateSuperUserAccess();
validateClusterOwnership(cluster);
validateBrokerName(broker);
try {
// now we validated that this is the broker specified in the request
return pulsar().getNamespaceService().getOwnedNameSpacesStatus();
} catch (Exception e) {
LOG.error("[{}] Failed to get the namespace ownership status. cluster={}, broker={}", clientAppId(), cluster, broker);
throw new RestException(e);
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class PropertiesBase method createProperty.
@PUT
@Path("/{property}")
@ApiOperation(value = "Create a new property.", notes = "This operation requires Pulsar super-user privileges.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 409, message = "Property already exist"), @ApiResponse(code = 412, message = "Property name is not valid") })
public void createProperty(@PathParam("property") String property, PropertyAdmin config) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
try {
NamedEntity.checkName(property);
zkCreate(path(POLICIES, property), jsonMapper().writeValueAsBytes(config));
log.info("[{}] Created property {}", clientAppId(), property);
} catch (KeeperException.NodeExistsException e) {
log.warn("[{}] Failed to create already existing property {}", clientAppId(), property);
throw new RestException(Status.CONFLICT, "Property already exist");
} catch (IllegalArgumentException e) {
log.warn("[{}] Failed to create property with invalid name {}", clientAppId(), property, e);
throw new RestException(Status.PRECONDITION_FAILED, "Property name is not valid");
} catch (Exception e) {
log.error("[{}] Failed to create property {}", clientAppId(), property, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class PropertiesBase method deleteProperty.
@DELETE
@Path("/{property}")
@ApiOperation(value = "elete a property and all namespaces and topics under it.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Property does not exist"), @ApiResponse(code = 409, message = "The property still has active namespaces") })
public void deleteProperty(@PathParam("property") String property) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
boolean isPropertyEmpty = false;
try {
isPropertyEmpty = getListOfNamespaces(property).isEmpty();
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to delete property {}: does not exist", clientAppId(), property);
throw new RestException(Status.NOT_FOUND, "The property does not exist");
} catch (Exception e) {
log.error("[{}] Failed to get property status {}", clientAppId(), property, e);
throw new RestException(e);
}
if (!isPropertyEmpty) {
log.warn("[{}] Failed to delete property {}: not empty", clientAppId(), property);
throw new RestException(Status.CONFLICT, "The property still has active namespaces");
}
try {
// First try to delete every cluster z-node
for (String cluster : globalZk().getChildren(path(POLICIES, property), false)) {
globalZk().delete(path(POLICIES, property, cluster), -1);
}
globalZk().delete(path(POLICIES, property), -1);
log.info("[{}] Deleted property {}", clientAppId(), property);
} catch (Exception e) {
log.error("[{}] Failed to delete property {}", clientAppId(), property, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.broker.web.RestException in project incubator-pulsar by apache.
the class ResourceQuotasBase method internalGetNamespaceBundleResourceQuota.
@SuppressWarnings("deprecation")
protected ResourceQuota internalGetNamespaceBundleResourceQuota(String bundleRange) {
validateSuperUserAccess();
Policies policies = getNamespacePolicies(namespaceName);
if (!namespaceName.isGlobal()) {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
}
NamespaceBundle nsBundle = validateNamespaceBundleRange(namespaceName, policies.bundles, bundleRange);
try {
return pulsar().getLocalZkCacheService().getResourceQuotaCache().getQuota(nsBundle);
} catch (Exception e) {
log.error("[{}] Failed to get resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
throw new RestException(e);
}
}
Aggregations