Search in sources :

Example 1 with NotFoundException

use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.

the class ClustersBase method getFailureDomains.

@GET
@Path("/{cluster}/failureDomains")
@ApiOperation(value = "Get the cluster failure domains.", response = FailureDomainImpl.class, responseContainer = "Map", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 500, message = "Internal server error") })
public Map<String, FailureDomainImpl> getFailureDomains(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster) throws Exception {
    validateSuperUserAccess();
    Map<String, FailureDomainImpl> domains = Maps.newHashMap();
    try {
        FailureDomainResources fdr = clusterResources().getFailureDomainResources();
        for (String domainName : fdr.listFailureDomains(cluster)) {
            try {
                Optional<FailureDomainImpl> domain = fdr.getFailureDomain(cluster, domainName);
                domain.ifPresent(failureDomain -> domains.put(domainName, failureDomain));
            } catch (Exception e) {
                log.warn("Failed to get domain {}", domainName, e);
            }
        }
    } catch (NotFoundException e) {
        log.warn("[{}] Failure-domain is not configured for cluster {}", clientAppId(), cluster, e);
        return Collections.emptyMap();
    } catch (Exception e) {
        log.error("[{}] Failed to get failure-domains for cluster {}", clientAppId(), cluster, e);
        throw new RestException(e);
    }
    return domains;
}
Also used : FailureDomainImpl(org.apache.pulsar.common.policies.data.FailureDomainImpl) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) FailureDomainResources(org.apache.pulsar.broker.resources.ClusterResources.FailureDomainResources) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with NotFoundException

use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.

the class ClustersBase method deleteFailureDomain.

@DELETE
@Path("/{cluster}/failureDomains/{domainName}")
@ApiOperation(value = "Delete the failure domain of the cluster", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission or policy is read only"), @ApiResponse(code = 404, message = "FailureDomain doesn't exist"), @ApiResponse(code = 412, message = "Cluster doesn't exist"), @ApiResponse(code = 500, message = "Internal server error") })
public void deleteFailureDomain(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster, @ApiParam(value = "The failure domain name", required = true) @PathParam("domainName") String domainName) throws Exception {
    validateSuperUserAccess();
    validateClusterExists(cluster);
    try {
        clusterResources().getFailureDomainResources().deleteFailureDomain(cluster, domainName);
    } catch (NotFoundException nne) {
        log.warn("[{}] Domain {} does not exist in {}", clientAppId(), domainName, cluster);
        throw new RestException(Status.NOT_FOUND, "Domain-name " + domainName + " or cluster " + cluster + " does not exist");
    } catch (Exception e) {
        log.error("[{}] Failed to delete domain {} in cluster {}", clientAppId(), domainName, cluster, e);
        throw new RestException(e);
    }
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with NotFoundException

use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.

the class ClustersBase method updateCluster.

@POST
@Path("/{cluster}")
@ApiOperation(value = "Update the configuration for a cluster.", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Cluster has been updated."), @ApiResponse(code = 403, message = "Don't have admin permission or policies are read-only."), @ApiResponse(code = 404, message = "Cluster doesn't exist."), @ApiResponse(code = 500, message = "Internal server error.") })
public void updateCluster(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster, @ApiParam(value = "The cluster data", required = true, examples = @Example(value = @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = "{\n" + "   'serviceUrl': 'http://pulsar.example.com:8080',\n" + "   'brokerServiceUrl': 'pulsar://pulsar.example.com:6651'\n" + "}"))) ClusterDataImpl clusterData) {
    validateSuperUserAccess();
    validatePoliciesReadOnlyAccess();
    try {
        clusterResources().updateCluster(cluster, old -> clusterData);
        log.info("[{}] Updated cluster {}", clientAppId(), cluster);
    } catch (NotFoundException e) {
        log.warn("[{}] Failed to update cluster {}: Does not exist", clientAppId(), cluster);
        throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
    } catch (Exception e) {
        log.error("[{}] Failed to update cluster {}", clientAppId(), cluster, e);
        throw new RestException(e);
    }
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with NotFoundException

use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.

the class ClustersBase method setPeerClusterNames.

@POST
@Path("/{cluster}/peers")
@ApiOperation(value = "Update peer-cluster-list for a cluster.", notes = "This operation requires Pulsar superuser privileges.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Cluster has been updated."), @ApiResponse(code = 403, message = "Don't have admin permission or policies are read-only."), @ApiResponse(code = 404, message = "Cluster doesn't exist."), @ApiResponse(code = 412, message = "Peer cluster doesn't exist."), @ApiResponse(code = 500, message = "Internal server error.") })
public void setPeerClusterNames(@ApiParam(value = "The cluster name", required = true) @PathParam("cluster") String cluster, @ApiParam(value = "The list of peer cluster names", required = true, examples = @Example(value = @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = "[\n" + "   'cluster-a',\n" + "   'cluster-b'\n" + "]"))) LinkedHashSet<String> peerClusterNames) {
    validateSuperUserAccess();
    validatePoliciesReadOnlyAccess();
    // validate if peer-cluster exist
    if (peerClusterNames != null && !peerClusterNames.isEmpty()) {
        for (String peerCluster : peerClusterNames) {
            try {
                if (cluster.equalsIgnoreCase(peerCluster)) {
                    throw new RestException(Status.PRECONDITION_FAILED, cluster + " itself can't be part of peer-list");
                }
                clusterResources().getCluster(peerCluster).orElseThrow(() -> new RestException(Status.PRECONDITION_FAILED, "Peer cluster " + peerCluster + " does not exist"));
            } catch (RestException e) {
                log.warn("[{}] Peer cluster doesn't exist from {}, {}", clientAppId(), peerClusterNames, e.getMessage());
                throw e;
            } catch (Exception e) {
                log.warn("[{}] Failed to validate peer-cluster list {}, {}", clientAppId(), peerClusterNames, e.getMessage());
                throw new RestException(e);
            }
        }
    }
    try {
        clusterResources().updateCluster(cluster, old -> old.clone().peerClusterNames(peerClusterNames).build());
        log.info("[{}] Successfully added peer-cluster {} for {}", clientAppId(), peerClusterNames, cluster);
    } catch (NotFoundException e) {
        log.warn("[{}] Failed to update cluster {}: Does not exist", clientAppId(), cluster);
        throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
    } catch (Exception e) {
        log.error("[{}] Failed to update cluster {}", clientAppId(), cluster, e);
        throw new RestException(e);
    }
}
Also used : RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with NotFoundException

use of org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException in project pulsar by apache.

the class NamespacesBase method internalSetBookieAffinityGroup.

protected void internalSetBookieAffinityGroup(BookieAffinityGroupData bookieAffinityGroup) {
    validateSuperUserAccess();
    log.info("[{}] Setting bookie-affinity-group {} for namespace {}", clientAppId(), bookieAffinityGroup, this.namespaceName);
    if (namespaceName.isGlobal()) {
        // check cluster ownership for a given global namespace: redirect if peer-cluster owns it
        validateGlobalNamespaceOwnership(namespaceName);
    } else {
        validateClusterOwnership(namespaceName.getCluster());
        validateClusterForTenant(namespaceName.getTenant(), namespaceName.getCluster());
    }
    try {
        getLocalPolicies().setLocalPoliciesWithCreate(namespaceName, oldPolicies -> {
            LocalPolicies localPolicies = oldPolicies.map(policies -> new LocalPolicies(policies.bundles, bookieAffinityGroup, policies.namespaceAntiAffinityGroup)).orElseGet(() -> new LocalPolicies(defaultBundle(), bookieAffinityGroup, null));
            log.info("[{}] Successfully updated local-policies configuration: namespace={}, map={}", clientAppId(), namespaceName, localPolicies);
            return localPolicies;
        });
    } catch (NotFoundException e) {
        log.warn("[{}] Failed to update local-policy configuration for namespace {}: does not exist", clientAppId(), namespaceName);
        throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
    } catch (Exception e) {
        log.error("[{}] Failed to update local-policy configuration for namespace {}", clientAppId(), namespaceName, e);
        throw new RestException(e);
    }
}
Also used : SortedSet(java.util.SortedSet) Topic(org.apache.pulsar.broker.service.Topic) MutableObject(org.apache.commons.lang.mutable.MutableObject) URL(java.net.URL) AdminResource(org.apache.pulsar.broker.admin.AdminResource) BundleType(org.apache.pulsar.common.policies.data.Policies.BundleType) LoggerFactory(org.slf4j.LoggerFactory) TopicHashPositions(org.apache.pulsar.common.policies.data.TopicHashPositions) DelayedDeliveryPolicies(org.apache.pulsar.common.policies.data.DelayedDeliveryPolicies) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) StringUtils(org.apache.commons.lang3.StringUtils) NamespaceBundleSplitAlgorithm(org.apache.pulsar.common.naming.NamespaceBundleSplitAlgorithm) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) NamespaceBundles(org.apache.pulsar.common.naming.NamespaceBundles) PoliciesUtil.defaultBundle(org.apache.pulsar.common.policies.data.PoliciesUtil.defaultBundle) PoliciesUtil.getBundles(org.apache.pulsar.common.policies.data.PoliciesUtil.getBundles) BacklogQuotaType(org.apache.pulsar.common.policies.data.BacklogQuota.BacklogQuotaType) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) PolicyOperation(org.apache.pulsar.common.policies.data.PolicyOperation) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceOperation(org.apache.pulsar.common.policies.data.NamespaceOperation) NamedEntity(org.apache.pulsar.common.naming.NamedEntity) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) DispatchRateImpl(org.apache.pulsar.common.policies.data.impl.DispatchRateImpl) UriBuilder(javax.ws.rs.core.UriBuilder) BookieAffinityGroupData(org.apache.pulsar.common.policies.data.BookieAffinityGroupData) URI(java.net.URI) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) SchemaCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy) PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) AsyncResponse(javax.ws.rs.container.AsyncResponse) OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) Set(java.util.Set) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) List(java.util.List) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) FutureUtil(org.apache.pulsar.common.util.FutureUtil) Response(javax.ws.rs.core.Response) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) PolicyName(org.apache.pulsar.common.policies.data.PolicyName) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) TenantOperation(org.apache.pulsar.common.policies.data.TenantOperation) Subscription(org.apache.pulsar.broker.service.Subscription) TopicName(org.apache.pulsar.common.naming.TopicName) BacklogQuota(org.apache.pulsar.common.policies.data.BacklogQuota) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) AutoTopicCreationOverride(org.apache.pulsar.common.policies.data.AutoTopicCreationOverride) AutoTopicCreationOverrideImpl(org.apache.pulsar.common.policies.data.impl.AutoTopicCreationOverrideImpl) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) Status(javax.ws.rs.core.Response.Status) DispatchRate(org.apache.pulsar.common.policies.data.DispatchRate) RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) PersistentReplicator(org.apache.pulsar.broker.service.persistent.PersistentReplicator) Logger(org.slf4j.Logger) AlreadyExistsException(org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) AutoSubscriptionCreationOverride(org.apache.pulsar.common.policies.data.AutoSubscriptionCreationOverride) Field(java.lang.reflect.Field) SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) SystemTopicClient(org.apache.pulsar.broker.systopic.SystemTopicClient) Policies(org.apache.pulsar.common.policies.data.Policies) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) SchemaAutoUpdateCompatibilityStrategy(org.apache.pulsar.common.policies.data.SchemaAutoUpdateCompatibilityStrategy) SubscriptionAuthMode(org.apache.pulsar.common.policies.data.SubscriptionAuthMode) Codec(org.apache.pulsar.common.util.Codec) BadVersionException(org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException) AuthorizationService(org.apache.pulsar.broker.authorization.AuthorizationService) Collections(java.util.Collections) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) RestException(org.apache.pulsar.broker.web.RestException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) RestException(org.apache.pulsar.broker.web.RestException) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) SubscriptionBusyException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) NotFoundException(org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) AlreadyExistsException(org.apache.pulsar.metadata.api.MetadataStoreException.AlreadyExistsException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) BadVersionException(org.apache.pulsar.metadata.api.MetadataStoreException.BadVersionException)

Aggregations

NotFoundException (org.apache.pulsar.metadata.api.MetadataStoreException.NotFoundException)48 RestException (org.apache.pulsar.broker.web.RestException)45 WebApplicationException (javax.ws.rs.WebApplicationException)37 MetadataStoreException (org.apache.pulsar.metadata.api.MetadataStoreException)37 CompletableFuture (java.util.concurrent.CompletableFuture)33 Map (java.util.Map)32 Response (javax.ws.rs.core.Response)32 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)32 FutureUtil (org.apache.pulsar.common.util.FutureUtil)32 Logger (org.slf4j.Logger)32 LoggerFactory (org.slf4j.LoggerFactory)32 List (java.util.List)30 AsyncResponse (javax.ws.rs.container.AsyncResponse)30 Status (javax.ws.rs.core.Response.Status)30 ApiOperation (io.swagger.annotations.ApiOperation)29 ApiResponses (io.swagger.annotations.ApiResponses)29 Path (javax.ws.rs.Path)29 Collections (java.util.Collections)28 Objects (java.util.Objects)26 Optional (java.util.Optional)26