public static void validateNamespaceName(String property, String cluster, String namespace) { try { checkNotNull(property); checkNotNull(cluster); checkNotNull(namespace); if (property.isEmpty() || cluster.isEmpty() || namespace.isEmpty()) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", property, cluster, namespace)); } NamedEntity.checkName(property); NamedEntity.checkName(cluster); NamedEntity.checkName(namespace); } catch (NullPointerException e) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", property, cluster, namespace), e); } }
private void validateNamespaceName(String namespace) { // assume the namespace is in the form of <property>/<cluster>/<namespace> try { checkNotNull(namespace); String testUrl = String.format("http://%s", namespace); URI uri = new URI(testUrl); checkNotNull(uri.getPath()); NamedEntity.checkURI(uri, testUrl); String[] parts = uri.getPath().split("/"); if (parts.length != 3) { throw new IllegalArgumentException("Invalid namespace format. namespace: " + namespace); } validateNamespaceName(uri.getHost(), parts[1], parts[2]); property = uri.getHost(); cluster = parts[1]; localName = parts[2]; } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid namespace format. namespace: " + namespace, e); } catch (NullPointerException e) { throw new IllegalArgumentException("Invalid namespace format. namespace: " + namespace, e); } }
/** * Compose the destination name from namespace + destination * * @param domain * @param destination * @return */ String getDestinationName(DestinationDomain domain, String destination) { try { checkNotNull(domain); NamedEntity.checkName(destination); return String.format("%s://%s/%s", domain.toString(), namespace, destination); } catch (NullPointerException e) { throw new IllegalArgumentException("Null pointer is invalid as domain for destination.", e); } }
@PUT @Path("/{cluster}") @ApiOperation(value = "Provisions a new cluster. This operation requires Pulsar super-user privileges.", notes = "The name cannot contain '/' characters.") @ApiResponses(value = { @ApiResponse(code = 204, message = "Cluster has been created"), @ApiResponse(code = 403, message = "You don't have admin permission to create the cluster"), @ApiResponse(code = 409, message = "Cluster already exists"), @ApiResponse(code = 412, message = "Cluster name is not valid") }) public void createCluster(@PathParam("cluster") String cluster, ClusterData clusterData) { validateSuperUserAccess(); validatePoliciesReadOnlyAccess(); try { NamedEntity.checkName(cluster); zkCreate(path("clusters", cluster), jsonMapper().writeValueAsBytes(clusterData)); log.info("[{}] Created cluster {}", clientAppId(), cluster); } catch (KeeperException.NodeExistsException e) { log.warn("[{}] Failed to create already existing cluster {}", clientAppId(), cluster); throw new RestException(Status.CONFLICT, "Cluster already exist"); } catch (IllegalArgumentException e) { log.warn("[{}] Failed to create cluster with invalid name {}", clientAppId(), cluster, e); throw new RestException(Status.PRECONDITION_FAILED, "Cluster name is not valid"); } catch (Exception e) { log.error("[{}] Failed to create cluster {}", clientAppId(), cluster, e); throw new RestException(e); } }
@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); } }
NamedEntity.checkName(namespace); policiesCache().invalidate(path("policies", property, cluster, namespace)); Policies policies = new Policies();