public static void validateNamespaceName(String tenant, String namespace) { try { checkNotNull(tenant); checkNotNull(namespace); if (tenant.isEmpty() || namespace.isEmpty()) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s", tenant, namespace)); } NamedEntity.checkName(tenant); NamedEntity.checkName(namespace); } catch (NullPointerException e) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", tenant, namespace), e); } }
public static void validateNamespaceName(String tenant, String cluster, String namespace) { try { checkNotNull(tenant); checkNotNull(cluster); checkNotNull(namespace); if (tenant.isEmpty() || cluster.isEmpty() || namespace.isEmpty()) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", tenant, cluster, namespace)); } NamedEntity.checkName(tenant); NamedEntity.checkName(cluster); NamedEntity.checkName(namespace); } catch (NullPointerException e) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", tenant, cluster, namespace), e); } }
/** * Compose the topic name from namespace + topic * * @param domain * @param topic * @return */ String getTopicName(TopicDomain domain, String topic) { try { checkNotNull(domain); NamedEntity.checkName(topic); return String.format("%s://%s/%s", domain.toString(), namespace, topic); } catch (NullPointerException e) { throw new IllegalArgumentException("Null pointer is invalid as domain for topic.", e); } }
public static void validateNamespaceName(String tenant, String cluster, String namespace) { try { checkNotNull(tenant); checkNotNull(cluster); checkNotNull(namespace); if (tenant.isEmpty() || cluster.isEmpty() || namespace.isEmpty()) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", tenant, cluster, namespace)); } NamedEntity.checkName(tenant); NamedEntity.checkName(cluster); NamedEntity.checkName(namespace); } catch (NullPointerException e) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", tenant, cluster, namespace), e); } }
public static void validateNamespaceName(String tenant, String namespace) { try { checkNotNull(tenant); checkNotNull(namespace); if (tenant.isEmpty() || namespace.isEmpty()) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s", tenant, namespace)); } NamedEntity.checkName(tenant); NamedEntity.checkName(namespace); } catch (NullPointerException e) { throw new IllegalArgumentException( String.format("Invalid namespace format. namespace: %s/%s/%s", tenant, namespace), e); } }
/** * Compose the topic name from namespace + topic * * @param domain * @param topic * @return */ String getTopicName(TopicDomain domain, String topic) { try { checkNotNull(domain); NamedEntity.checkName(topic); return String.format("%s://%s/%s", domain.toString(), namespace, topic); } catch (NullPointerException e) { throw new IllegalArgumentException("Null pointer is invalid as domain for topic.", 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 exists"); } 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("/{tenant}") @ApiOperation(value = "Create a new tenant.", notes = "This operation requires Pulsar super-user privileges.") @ApiResponses(value = { @ApiResponse(code = 403, message = "The requester doesn't have admin permissions"), @ApiResponse(code = 409, message = "Tenant already exists"), @ApiResponse(code = 412, message = "Tenant name is not valid") }) public void createTenant(@PathParam("tenant") String tenant, TenantInfo config) { validateSuperUserAccess(); validatePoliciesReadOnlyAccess(); try { NamedEntity.checkName(tenant); zkCreate(path(POLICIES, tenant), jsonMapper().writeValueAsBytes(config)); log.info("[{}] Created tenant {}", clientAppId(), tenant); } catch (KeeperException.NodeExistsException e) { log.warn("[{}] Failed to create already existing tenant {}", clientAppId(), tenant); throw new RestException(Status.CONFLICT, "Tenant already exists"); } catch (IllegalArgumentException e) { log.warn("[{}] Failed to create tenant with invalid name {}", clientAppId(), tenant, e); throw new RestException(Status.PRECONDITION_FAILED, "Tenant name is not valid"); } catch (Exception e) { log.error("[{}] Failed to create tenant {}", clientAppId(), tenant, e); throw new RestException(e); } }