@Override void run() throws PulsarAdminException { String topic = validateTopicName(params); topics.deleteSubscription(topic, subName); } }
@Override void run() throws PulsarAdminException { String topic = validateTopicName(params); topics.expireMessages(topic, subName, expireTimeInSeconds); } }
@Override void run() throws PulsarAdminException { String topic = validateTopicName(params); topics.expireMessagesForAllSubscriptions(topic, expireTimeInSeconds); } }
@Override void run() throws PulsarAdminException { long sizeThreshold = validateSizeString(sizeThresholdStr); String persistentTopic = validatePersistentTopic(params); PersistentTopicInternalStats stats = topics.getInternalStats(persistentTopic); if (stats.ledgers.size() < 1) { throw new PulsarAdminException("Topic doesn't have any data"); } LinkedList<PersistentTopicInternalStats.LedgerInfo> ledgers = new LinkedList(stats.ledgers); ledgers.get(ledgers.size()-1).size = stats.currentLedgerSize; // doesn't get filled in now it seems MessageId messageId = findFirstLedgerWithinThreshold(ledgers, sizeThreshold); if (messageId == null) { System.out.println("Nothing to offload"); return; } topics.triggerOffload(persistentTopic, messageId); System.out.println("Offload triggered for " + persistentTopic + " for messages before " + messageId); } }
@Override void run() throws PulsarAdminException { String topic = validateTopicName(params); print(topics.getStats(topic)); } }
@Override void run() throws Exception { String topic = validateTopicName(params); print(topics.getSubscriptions(topic)); } }
@Override void run() throws PulsarAdminException { String topic = validateTopicName(params); print(topics.getInternalStats(topic)); } }
@Override void run() throws PulsarAdminException { String topic = validateTopicName(params); topics.skipAllMessages(topic, subName); } }
@Override void run() throws PulsarAdminException { String persistentTopic = validatePersistentTopic(params); if (isNotBlank(resetMessageIdStr)) { MessageId messageId = validateMessageIdString(resetMessageIdStr); topics.resetCursor(persistentTopic, subName, messageId); } else if (isNotBlank(resetTimeStr)) { int resetBackTimeInMin = validateTimeString(resetTimeStr); long resetTimeInMillis = TimeUnit.MILLISECONDS.convert(resetBackTimeInMin, TimeUnit.MINUTES); // now - go back time long timestamp = System.currentTimeMillis() - resetTimeInMillis; topics.resetCursor(persistentTopic, subName, timestamp); } else { throw new PulsarAdminException( "Either Timestamp (--time) or Position (--position) has to be provided to reset cursor"); } } }
@Override void run() throws Exception { String topic = validateTopicName(params); topics.createPartitionedTopic(topic, numPartitions); } }
@Override void run() throws PulsarAdminException { String persistentTopic = validatePersistentTopic(params); try { LongRunningProcessStatus status = topics.compactionStatus(persistentTopic); while (wait && status.status == LongRunningProcessStatus.Status.RUNNING) { Thread.sleep(1000); status = topics.compactionStatus(persistentTopic); } switch (status.status) { case NOT_RUN: System.out.println("Compaction has not been run for " + persistentTopic + " since broker startup"); break; case RUNNING: System.out.println("Compaction is currently running"); break; case SUCCESS: System.out.println("Compaction was a success"); break; case ERROR: System.out.println("Error in compaction"); throw new PulsarAdminException("Error compacting: " + status.lastError); } } catch (InterruptedException e) { throw new PulsarAdminException(e); } } }
protected PartitionedTopicStats internalGetPartitionedStats(boolean authoritative) { PartitionedTopicMetadata partitionMetadata = getPartitionedTopicMetadata(topicName, authoritative); if (partitionMetadata.partitions == 0) { throw new RestException(Status.NOT_FOUND, "Partitioned Topic not found"); } if (topicName.isGlobal()) { validateGlobalNamespaceOwnership(namespaceName); } PartitionedTopicStats stats = new PartitionedTopicStats(partitionMetadata); try { for (int i = 0; i < partitionMetadata.partitions; i++) { TopicStats partitionStats = pulsar().getAdminClient().topics() .getStats(topicName.getPartition(i).toString()); stats.add(partitionStats); stats.partitions.put(topicName.getPartition(i).toString(), partitionStats); } } catch (PulsarAdminException e) { if (e.getStatusCode() == Status.NOT_FOUND.getStatusCode()) { throw new RestException(Status.NOT_FOUND, "Internal topics have not been generated yet"); } else { throw new RestException(e); } } catch (Exception e) { throw new RestException(e); } return stats; }
.getSubscriptions(topicName.getPartition(0).toString())); } catch (PulsarAdminException e) { if (e.getStatusCode() == Status.NOT_FOUND.getStatusCode()) {
protected PartitionedTopicInternalStats internalGetPartitionedStatsInternal(boolean authoritative) { PartitionedTopicMetadata partitionMetadata = getPartitionedTopicMetadata(topicName, authoritative); if (partitionMetadata.partitions == 0) { throw new RestException(Status.NOT_FOUND, "Partitioned Topic not found"); } if (topicName.isGlobal()) { validateGlobalNamespaceOwnership(namespaceName); } PartitionedTopicInternalStats stats = new PartitionedTopicInternalStats(partitionMetadata); try { for (int i = 0; i < partitionMetadata.partitions; i++) { PersistentTopicInternalStats partitionStats = pulsar().getAdminClient().topics() .getInternalStats(topicName.getPartition(i).toString()); stats.partitions.put(topicName.getPartition(i).toString(), partitionStats); } } catch (PulsarAdminException e) { if (e.getStatusCode() == Status.NOT_FOUND.getStatusCode()) { throw new RestException(Status.NOT_FOUND, "Internal topics have not been generated yet"); } else { throw new RestException(e); } } catch (Exception e) { throw new RestException(e); } return stats; }
for (int i = 0; i < partitionMetadata.partitions; i++) { pulsar().getAdminClient().topics() .skipAllMessages(topicName.getPartition(i).toString(), subName);
try { for (int i = 0; i < numParts; i++) { pulsar().getAdminClient().topics().resetCursor(topicName.getPartition(i).toString(), subName, timestamp);
for (int i = 0; i < partitionMetadata.partitions; i++) { pulsar().getAdminClient().topics() .expireMessages(topicName.getPartition(i).toString(), subName, expireTimeInSeconds);
protected void internalExpireMessagesForAllSubscriptions(int expireTimeInSeconds, boolean authoritative) { if (topicName.isGlobal()) { validateGlobalNamespaceOwnership(namespaceName); } PartitionedTopicMetadata partitionMetadata = getPartitionedTopicMetadata(topicName, authoritative); if (partitionMetadata.partitions > 0) { try { // expire messages for each partition topic for (int i = 0; i < partitionMetadata.partitions; i++) { pulsar().getAdminClient().topics().expireMessagesForAllSubscriptions( topicName.getPartition(i).toString(), expireTimeInSeconds); } } catch (Exception e) { log.error("[{}] Failed to expire messages up to {} on {} {}", clientAppId(), expireTimeInSeconds, topicName, e); throw new RestException(e); } } else { // validate ownership and redirect if current broker is not owner validateAdminOperationOnTopic(authoritative); PersistentTopic topic = (PersistentTopic) getTopicReference(topicName); topic.getReplicators().forEach((subName, replicator) -> { internalExpireMessages(subName, expireTimeInSeconds, authoritative); }); topic.getSubscriptions().forEach((subName, subscriber) -> { internalExpireMessages(subName, expireTimeInSeconds, authoritative); }); } }
for (int i = 0; i < partitionMetadata.partitions; i++) { pulsar().getAdminClient().topics() .deleteSubscription(topicName.getPartition(i).toString(), subName);