public static boolean isValid(String destination) { try { get(destination); return true; } catch (Exception e) { return false; } }
@Override public Map<String, Set<AuthAction>> getPermissions(String destination) throws PulsarAdminException { try { DestinationName ds = DestinationName.get(destination); return request(persistentTopics.path(ds.getNamespace()).path(ds.getLocalName()).path("permissions")).get( new GenericType<Map<String, Set<AuthAction>>>() { }); } catch (Exception e) { throw getApiException(e); } }
/** * * @return Backlog quota for topic */ @Override public BacklogQuota getBacklogQuota() { DestinationName destination = DestinationName.get(this.getName()); String namespace = destination.getNamespace(); String policyPath = AdminResource.path("policies", namespace); BacklogQuota backlogQuota = brokerService.getBacklogQuotaManager().getBacklogQuota(namespace, policyPath); return backlogQuota; }
public static DestinationName get(String domain, String property, String cluster, String namespace, String destination) { String name = domain + "://" + property + '/' + cluster + '/' + namespace + '/' + destination; return DestinationName.get(name); }
@Override public void grantPermission(String destination, String role, Set<AuthAction> actions) throws PulsarAdminException { try { DestinationName ds = DestinationName.get(destination); request(persistentTopics.path(ds.getNamespace()).path(ds.getLocalName()).path("permissions").path(role)) .post(Entity.entity(actions, MediaType.APPLICATION_JSON), ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
void checkTopicNsOwnership(final String topic) throws RuntimeException { DestinationName destination = DestinationName.get(topic); boolean ownedByThisInstance; try { ownedByThisInstance = pulsar.getNamespaceService().isServiceUnitOwned(destination); } catch (Exception e) { log.debug(String.format("Failed to check the ownership of the destination: %s", destination), e); throw new RuntimeException(new ServerMetadataException(e)); } if (!ownedByThisInstance) { String msg = String.format("Namespace not served by this instance. Please redo the lookup. " + "Request is denied: namespace=%s", destination.getNamespace()); log.warn(msg); throw new RuntimeException(new ServiceUnitNotReadyException(msg)); } }
private DestinationName validateTopic(String destination) { // Parsing will throw exception if name is not valid return DestinationName.get(destination); }
@Override public void revokePermissions(String destination, String role) throws PulsarAdminException { try { DestinationName ds = DestinationName.get(destination); request(persistentTopics.path(ds.getNamespace()).path(ds.getLocalName()).path("permissions").path(role)) .delete(ErrorData.class); } catch (Exception e) { throw getApiException(e); } }
protected CompletableFuture<ClientCnx> getConnection(final String topic) { DestinationName destinationName = DestinationName.get(topic); return lookup.getBroker(destinationName).thenCompose(cnxPool::getConnection); }
public PersistentOfflineTopicStats getEstimatedUnloadedTopicBacklog(ManagedLedgerFactoryImpl factory, String managedLedgerName) throws Exception { return estimateUnloadedTopicBacklog(factory, DestinationName.get("persistent://" + managedLedgerName)); }
public DestinationName getPartition(int index) { if (this.toString().contains(PARTITIONED_TOPIC_SUFFIX)) { return this; } String partitionName = this.toString() + PARTITIONED_TOPIC_SUFFIX + index; return get(partitionName); }
@Override public String lookupDestination(String destination) throws PulsarAdminException { try { DestinationName destName = DestinationName.get(destination); return doDestinationLookup(v2lookup.path("/destination"), destName); } catch (Exception e) { throw getLookupApiException(e); } }
private CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(String topic) { CompletableFuture<PartitionedTopicMetadata> metadataFuture; try { DestinationName destinationName = DestinationName.get(topic); metadataFuture = lookup.getPartitionedTopicMetadata(destinationName); } catch (IllegalArgumentException e) { return FutureUtil.failedFuture(e); } return metadataFuture; }
@GET @Path("{property}/{cluster}/{namespace}/{destination}/stats") @ApiOperation(value = "Get the stats for the topic.") @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Topic does not exist") }) public PersistentTopicStats getStats(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("destination") @Encoded String destination, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) { destination = decode(destination); DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination); validateAdminAndClientPermission(dn); validateDestinationOwnership(dn, authoritative); PersistentTopic topic = getTopicReference(dn); return topic.getStats(); }
private void sendPartitionMetadataResponse(CommandPartitionedTopicMetadata partitionMetadata) { final long requestId = partitionMetadata.getRequestId(); DestinationName dn = DestinationName.get(partitionMetadata.getTopic()); service.getDiscoveryProvider().getPartitionedTopicMetadata(service, dn, authRole).thenAccept(metadata -> { if (LOG.isDebugEnabled()) { LOG.debug("[{}] Total number of partitions for topic {} is {}", authRole, dn, metadata.partitions); } ctx.writeAndFlush(Commands.newPartitionMetadataResponse(metadata.partitions, requestId)); }).exceptionally(ex -> { LOG.warn("[{}] Failed to get partitioned metadata for topic {} {}", remoteAddress, dn, ex.getMessage(), ex); ctx.writeAndFlush( Commands.newPartitionMetadataResponse(ServerError.ServiceNotReady, ex.getMessage(), requestId)); return null; }); }
@GET @Path("{property}/{cluster}/{namespace}/{destination}/internalStats") @ApiOperation(value = "Get the internal stats for the topic.") @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Topic does not exist") }) public PersistentTopicInternalStats getInternalStats(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("destination") @Encoded String destination, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) { destination = decode(destination); DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination); validateAdminAndClientPermission(dn); validateDestinationOwnership(dn, authoritative); PersistentTopic topic = getTopicReference(dn); return topic.getInternalStats(); }
public void checkPermissions() { DestinationName destination = DestinationName.get(topic.getName()); if (cnx.getBrokerService().getAuthorizationManager() != null) { try { if (cnx.getBrokerService().getAuthorizationManager().canProduce(destination, appId)) { return; } } catch (Exception e) { log.warn("[{}] Get unexpected error while autorizing [{}] {}", appId, topic.getName(), e.getMessage(), e); } log.info("[{}] is not allowed to produce from destination [{}] anymore", appId, topic.getName()); disconnect(); } }
public boolean isActive() { if (DestinationName.get(topic).isGlobal()) { // No local consumers and no local producers return !subscriptions.isEmpty() || hasLocalProducers(); } return USAGE_COUNT_UPDATER.get(this) != 0 || !subscriptions.isEmpty(); }
public void checkPermissions() { DestinationName destination = DestinationName.get(subscription.getDestination()); if (cnx.getBrokerService().getAuthorizationManager() != null) { try { if (cnx.getBrokerService().getAuthorizationManager().canConsume(destination, appId)) { return; } } catch (Exception e) { log.warn("[{}] Get unexpected error while autorizing [{}] {}", appId, subscription.getDestination(), e.getMessage(), e); } log.info("[{}] is not allowed to consume from Destination" + " [{}] anymore", appId, subscription.getDestination()); disconnect(); } }
private Map<String, Map<String, PendingBookieOpsStats>> generate() throws Exception { if (pulsar.getBrokerService() != null && pulsar.getBrokerService().getTopics() != null) { pulsar.getBrokerService().getTopics().forEach((name, topicFuture) -> { PersistentTopic persistentTopic = (PersistentTopic) topicFuture.getNow(null); if (persistentTopic != null) { DestinationName destinationName = DestinationName.get(persistentTopic.getName()); put(destinationName, persistentTopic.getManagedLedger().getStats().getPendingBookieOpsStats()); } }); } return nsBookieClientStatsMap; }