Search in sources :

Example 1 with OffloadPoliciesImpl

use of org.apache.pulsar.common.policies.data.OffloadPoliciesImpl in project pulsar by apache.

the class AdminApiOffloadTest method testOffloadPoliciesAppliedApi.

@Test
public void testOffloadPoliciesAppliedApi() throws Exception {
    final String topicName = testTopic + UUID.randomUUID().toString();
    admin.topics().createPartitionedTopic(topicName, 3);
    pulsarClient.newProducer().topic(topicName).create().close();
    OffloadPoliciesImpl offloadPolicies = (OffloadPoliciesImpl) admin.topics().getOffloadPolicies(topicName, true);
    OffloadPoliciesImpl brokerPolicies = OffloadPoliciesImpl.mergeConfiguration(null, null, pulsar.getConfiguration().getProperties());
    assertEquals(offloadPolicies, brokerPolicies);
    // Since off loader is not really set, avoid code exceptions
    LedgerOffloader topicOffloaded = mock(LedgerOffloader.class);
    when(topicOffloaded.getOffloadDriverName()).thenReturn("mock");
    doReturn(topicOffloaded).when(pulsar).createManagedLedgerOffloader(any());
    OffloadPoliciesImpl namespacePolicies = new OffloadPoliciesImpl();
    namespacePolicies.setManagedLedgerOffloadThresholdInBytes(100L);
    namespacePolicies.setManagedLedgerOffloadDeletionLagInMillis(200L);
    namespacePolicies.setManagedLedgerOffloadDriver("s3");
    namespacePolicies.setManagedLedgerOffloadBucket("buck");
    admin.namespaces().setOffloadPolicies(myNamespace, namespacePolicies);
    Awaitility.await().untilAsserted(() -> assertEquals(admin.namespaces().getOffloadPolicies(myNamespace), namespacePolicies));
    assertEquals(admin.topics().getOffloadPolicies(topicName, true), namespacePolicies);
    OffloadPoliciesImpl topicPolicies = new OffloadPoliciesImpl();
    topicPolicies.setManagedLedgerOffloadThresholdInBytes(200L);
    topicPolicies.setManagedLedgerOffloadDeletionLagInMillis(400L);
    topicPolicies.setManagedLedgerOffloadDriver("s3");
    topicPolicies.setManagedLedgerOffloadBucket("buck2");
    admin.topics().setOffloadPolicies(topicName, topicPolicies);
    Awaitility.await().untilAsserted(() -> assertEquals(admin.topics().getOffloadPolicies(topicName, true), topicPolicies));
    admin.topics().removeOffloadPolicies(topicName);
    Awaitility.await().untilAsserted(() -> assertEquals(admin.topics().getOffloadPolicies(topicName, true), namespacePolicies));
    admin.namespaces().removeOffloadPolicies(myNamespace);
    Awaitility.await().untilAsserted(() -> assertEquals(admin.topics().getOffloadPolicies(topicName, true), brokerPolicies));
}
Also used : OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) LedgerOffloader(org.apache.bookkeeper.mledger.LedgerOffloader) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with OffloadPoliciesImpl

use of org.apache.pulsar.common.policies.data.OffloadPoliciesImpl in project pulsar by apache.

the class AdminApiOffloadTest method testOffloadPoliciesApi.

@Test
public void testOffloadPoliciesApi() throws Exception {
    final String topicName = testTopic + UUID.randomUUID().toString();
    admin.topics().createPartitionedTopic(topicName, 3);
    pulsarClient.newProducer().topic(topicName).create().close();
    OffloadPoliciesImpl offloadPolicies = (OffloadPoliciesImpl) admin.topics().getOffloadPolicies(topicName);
    assertNull(offloadPolicies);
    OffloadPoliciesImpl offload = new OffloadPoliciesImpl();
    String path = "fileSystemPath";
    offload.setFileSystemProfilePath(path);
    admin.topics().setOffloadPolicies(topicName, offload);
    Awaitility.await().untilAsserted(() -> assertNotNull(admin.topics().getOffloadPolicies(topicName)));
    assertEquals(admin.topics().getOffloadPolicies(topicName), offload);
    assertEquals(admin.topics().getOffloadPolicies(topicName).getFileSystemProfilePath(), path);
    admin.topics().removeOffloadPolicies(topicName);
    Awaitility.await().untilAsserted(() -> assertNull(admin.topics().getOffloadPolicies(topicName)));
    assertNull(admin.topics().getOffloadPolicies(topicName));
}
Also used : OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 3 with OffloadPoliciesImpl

use of org.apache.pulsar.common.policies.data.OffloadPoliciesImpl in project pulsar by apache.

the class PulsarAdminToolTest method topics.

@Test
public void topics() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    Topics mockTopics = mock(Topics.class);
    when(admin.topics()).thenReturn(mockTopics);
    Schemas mockSchemas = mock(Schemas.class);
    when(admin.schemas()).thenReturn(mockSchemas);
    Lookup mockLookup = mock(Lookup.class);
    when(admin.lookups()).thenReturn(mockLookup);
    CmdTopics cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("truncate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).truncate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("delete persistent://myprop/clust/ns1/ds1 -f -d"));
    verify(mockTopics).delete("persistent://myprop/clust/ns1/ds1", true, true);
    cmdTopics.run(split("unload persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).unload("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("permissions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPermissions("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("grant-permission persistent://myprop/clust/ns1/ds1 --role admin --actions produce,consume"));
    verify(mockTopics).grantPermission("persistent://myprop/clust/ns1/ds1", "admin", Sets.newHashSet(AuthAction.produce, AuthAction.consume));
    cmdTopics.run(split("revoke-permission persistent://myprop/clust/ns1/ds1 --role admin"));
    verify(mockTopics).revokePermissions("persistent://myprop/clust/ns1/ds1", "admin");
    cmdTopics.run(split("list myprop/clust/ns1"));
    verify(mockTopics).getList("myprop/clust/ns1", null, null);
    cmdTopics.run(split("lookup persistent://myprop/clust/ns1/ds1"));
    verify(mockLookup).lookupTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("partitioned-lookup persistent://myprop/clust/ns1/ds1"));
    verify(mockLookup).lookupPartitionedTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("partitioned-lookup persistent://myprop/clust/ns1/ds1 --sort-by-broker"));
    verify(mockLookup).lookupPartitionedTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("bundle-range persistent://myprop/clust/ns1/ds1"));
    verify(mockLookup).getBundleRange("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptions("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("unsubscribe persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).deleteSubscription("persistent://myprop/clust/ns1/ds1", "sub1", false);
    cmdTopics.run(split("stats persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getStats("persistent://myprop/clust/ns1/ds1", false, false, false);
    cmdTopics.run(split("stats-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInternalStats("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("get-backlog-quotas persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getBacklogQuotaMap("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -l 10 -p producer_request_hold"));
    verify(mockTopics).setBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.builder().limitSize(10).retentionPolicy(RetentionPolicy.producer_request_hold).build(), BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("set-backlog-quota persistent://myprop/clust/ns1/ds1 -lt 1000 -p producer_request_hold -t message_age"));
    verify(mockTopics).setBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.builder().limitSize(-1).limitTime(1000).retentionPolicy(RetentionPolicy.producer_request_hold).build(), BacklogQuota.BacklogQuotaType.message_age);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.destination_storage);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("remove-backlog-quota persistent://myprop/clust/ns1/ds1 -t message_age"));
    verify(mockTopics).removeBacklogQuota("persistent://myprop/clust/ns1/ds1", BacklogQuota.BacklogQuotaType.message_age);
    cmdTopics.run(split("info-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInternalInfo("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("partitioned-stats persistent://myprop/clust/ns1/ds1 --per-partition"));
    verify(mockTopics).getPartitionedStats("persistent://myprop/clust/ns1/ds1", true, false, false);
    cmdTopics.run(split("partitioned-stats-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPartitionedInternalStats("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("clear-backlog persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).skipAllMessages("persistent://myprop/clust/ns1/ds1", "sub1");
    cmdTopics.run(split("skip persistent://myprop/clust/ns1/ds1 -s sub1 -n 100"));
    verify(mockTopics).skipMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    cmdTopics.run(split("expire-messages persistent://myprop/clust/ns1/ds1 -s sub1 -t 100"));
    verify(mockTopics).expireMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    cmdTopics.run(split("get-subscribe-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getSubscribeRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscribe-rate persistent://myprop/clust/ns1/ds1 -sr 2 -st 60"));
    verify(mockTopics).setSubscribeRate("persistent://myprop/clust/ns1/ds1", new SubscribeRate(2, 60));
    cmdTopics.run(split("remove-subscribe-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeSubscribeRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicated-subscription-status persistent://myprop/clust/ns1/ds1 -s sub1 -e"));
    verify(mockTopics).setReplicatedSubscriptionStatus("persistent://myprop/clust/ns1/ds1", "sub1", true);
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("expire-messages persistent://myprop/clust/ns1/ds1 -s sub1 -p 1:1 -e"));
    verify(mockTopics).expireMessages(eq("persistent://myprop/clust/ns1/ds1"), eq("sub1"), eq(new MessageIdImpl(1, 1, -1)), eq(true));
    cmdTopics.run(split("expire-messages-all-subscriptions persistent://myprop/clust/ns1/ds1 -t 100"));
    verify(mockTopics).expireMessagesForAllSubscriptions("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("create-subscription persistent://myprop/clust/ns1/ds1 -s sub1 --messageId earliest"));
    verify(mockTopics).createSubscription("persistent://myprop/clust/ns1/ds1", "sub1", MessageId.earliest);
    cmdTopics.run(split("create-partitioned-topic persistent://myprop/clust/ns1/ds1 --partitions 32"));
    verify(mockTopics).createPartitionedTopic("persistent://myprop/clust/ns1/ds1", 32, null);
    cmdTopics.run(split("create-missed-partitions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).createMissedPartitions("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("create persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).createNonPartitionedTopic("persistent://myprop/clust/ns1/ds1", new HashMap<>());
    cmdTopics.run(split("list-partitioned-topics myprop/clust/ns1"));
    verify(mockTopics).getPartitionedTopicList("myprop/clust/ns1");
    cmdTopics.run(split("update-partitioned-topic persistent://myprop/clust/ns1/ds1 -p 6"));
    verify(mockTopics).updatePartitionedTopic("persistent://myprop/clust/ns1/ds1", 6, false, false);
    cmdTopics.run(split("get-partitioned-topic-metadata persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPartitionedTopicMetadata("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1 -d -f"));
    verify(mockTopics).deletePartitionedTopic("persistent://myprop/clust/ns1/ds1", true, true);
    cmdTopics.run(split("peek-messages persistent://myprop/clust/ns1/ds1 -s sub1 -n 3"));
    verify(mockTopics).peekMessages("persistent://myprop/clust/ns1/ds1", "sub1", 3);
    MessageImpl message = mock(MessageImpl.class);
    when(message.getData()).thenReturn(new byte[] {});
    when(message.getMessageId()).thenReturn(new MessageIdImpl(1L, 1L, 1));
    when(mockTopics.examineMessage("persistent://myprop/clust/ns1/ds1", "latest", 1)).thenReturn(message);
    cmdTopics.run(split("examine-messages persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).examineMessage("persistent://myprop/clust/ns1/ds1", "latest", 1);
    cmdTopics.run(split("enable-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).enableDeduplication("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("disable-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).enableDeduplication("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-deduplication persistent://myprop/clust/ns1/ds1 --disable"));
    verify(mockTopics).setDeduplicationStatus("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopics).setSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-subscription-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeSubscriptionDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-subscription-types-enabled persistent://myprop/clust/ns1/ds1 -t Shared,Failover"));
    verify(mockTopics).setSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1", Sets.newHashSet(SubscriptionType.Shared, SubscriptionType.Failover));
    cmdTopics.run(split("get-subscription-types-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-subscription-types-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeSubscriptionTypesEnabled("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1 -md 10 -bd 11 -dt 12"));
    verify(mockTopics).setReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(10).dispatchThrottlingRateInByte(11).ratePeriodInSecond(12).build());
    cmdTopics.run(split("remove-replicator-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeReplicatorDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication-enabled persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-deduplication persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).getDeduplicationStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-offload-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeOffloadPolicies("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-delayed-delivery persistent://myprop/clust/ns1/ds1 -t 10s --enable"));
    verify(mockTopics).setDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", DelayedDeliveryPolicies.builder().tickTime(10000).active(true).build());
    cmdTopics.run(split("remove-delayed-delivery persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-offload-policies persistent://myprop/clust/ns1/ds1 -d s3 -r region -b bucket -e endpoint -m 8 -rb 9 -t 10 -orp tiered-storage-first"));
    OffloadPoliciesImpl offloadPolicies = OffloadPoliciesImpl.create("s3", "region", "bucket", "endpoint", null, null, null, null, 8, 9, 10L, null, OffloadedReadPriority.TIERED_STORAGE_FIRST);
    verify(mockTopics).setOffloadPolicies("persistent://myprop/clust/ns1/ds1", offloadPolicies);
    cmdTopics.run(split("get-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("get-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).removeMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1 -m 999"));
    verify(mockTopics).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("set-max-unacked-messages-per-consumer persistent://myprop/clust/ns1/ds1 -m 999"));
    verify(mockTopics, times(2)).setMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", 999);
    cmdTopics.run(split("get-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("get-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics, times(2)).removeMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-publish-rate persistent://myprop/clust/ns1/ds1 -m 100 -b 10240"));
    verify(mockTopics).setPublishRate("persistent://myprop/clust/ns1/ds1", new PublishRate(100, 10240L));
    cmdTopics.run(split("remove-publish-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removePublishRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopics).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("set-max-unacked-messages-per-subscription persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopics, times(2)).setMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getCompactionThreshold("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-compaction-threshold persistent://myprop/clust/ns1/ds1 -t 10k"));
    verify(mockTopics).setCompactionThreshold("persistent://myprop/clust/ns1/ds1", 10 * 1024);
    cmdTopics.run(split("remove-compaction-threshold persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeCompactionThreshold("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-max-message-size persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxMessageSize("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1 -c 5"));
    verify(mockTopics).setMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1", 5);
    cmdTopics.run(split("remove-max-consumers-per-subscription persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxConsumersPerSubscription("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-message-size persistent://myprop/clust/ns1/ds1 -m 99"));
    verify(mockTopics).setMaxMessageSize("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-message-by-id persistent://myprop/clust/ns1/ds1 -l 10 -e 2"));
    verify(mockTopics).getMessageById("persistent://myprop/clust/ns1/ds1", 10, 2);
    cmdTopics.run(split("get-dispatch-rate persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getDispatchRate("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("remove-dispatch-rate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDispatchRate("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-dispatch-rate persistent://myprop/clust/ns1/ds1 -md -1 -bd -1 -dt 2"));
    verify(mockTopics).setDispatchRate("persistent://myprop/clust/ns1/ds1", DispatchRate.builder().dispatchThrottlingRateInMsg(-1).dispatchThrottlingRateInByte(-1).ratePeriodInSecond(2).build());
    cmdTopics.run(split("get-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxProducers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-producers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxProducers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-producers persistent://myprop/clust/ns1/ds1 -p 99"));
    verify(mockTopics).setMaxProducers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxConsumers("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-max-consumers persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxConsumers("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-consumers persistent://myprop/clust/ns1/ds1 -c 99"));
    verify(mockTopics).setMaxConsumers("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("remove-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-deduplication-snapshot-interval persistent://myprop/clust/ns1/ds1 -i 99"));
    verify(mockTopics).setDeduplicationSnapshotInterval("persistent://myprop/clust/ns1/ds1", 99);
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("remove-inactive-topic-policies persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-inactive-topic-policies persistent://myprop/clust/ns1/ds1" + " -e -t 1s -m delete_when_no_subscriptions"));
    verify(mockTopics).setInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", new InactiveTopicPolicies(InactiveTopicDeleteMode.delete_when_no_subscriptions, 1, true));
    cmdTopics.run(split("get-max-subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-max-subscriptions persistent://myprop/clust/ns1/ds1 -m 100"));
    verify(mockTopics).setMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1", 100);
    cmdTopics.run(split("remove-max-subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMaxSubscriptionsPerTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("get-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPersistence("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-persistence persistent://myprop/clust/ns1/ds1 -e 2 -w 1 -a 1 -r 100.0"));
    verify(mockTopics).setPersistence("persistent://myprop/clust/ns1/ds1", new PersistencePolicies(2, 1, 1, 100.0d));
    cmdTopics.run(split("remove-persistence persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removePersistence("persistent://myprop/clust/ns1/ds1");
    // range of +/- 1 second of the expected timestamp
    class TimestampMatcher implements ArgumentMatcher<Long> {

        @Override
        public boolean matches(Long timestamp) {
            long expectedTimestamp = System.currentTimeMillis() - (1 * 60 * 1000);
            if (timestamp < (expectedTimestamp + 1000) && timestamp > (expectedTimestamp - 1000)) {
                return true;
            }
            return false;
        }
    }
    cmdTopics.run(split("reset-cursor persistent://myprop/clust/ns1/ds1 -s sub1 -t 1m"));
    verify(mockTopics).resetCursor(eq("persistent://myprop/clust/ns1/ds1"), eq("sub1"), longThat(new TimestampMatcher()));
    when(mockTopics.terminateTopicAsync("persistent://myprop/clust/ns1/ds1")).thenReturn(CompletableFuture.completedFuture(new MessageIdImpl(1L, 1L, 1)));
    cmdTopics.run(split("terminate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).terminateTopicAsync("persistent://myprop/clust/ns1/ds1");
    Map<Integer, MessageId> results = new HashMap<>();
    results.put(0, new MessageIdImpl(1, 1, 0));
    when(mockTopics.terminatePartitionedTopic("persistent://myprop/clust/ns1/ds1")).thenReturn(results);
    cmdTopics.run(split("partitioned-terminate persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).terminatePartitionedTopic("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("compact persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).triggerCompaction("persistent://myprop/clust/ns1/ds1");
    when(mockTopics.compactionStatus("persistent://myprop/clust/ns1/ds1")).thenReturn(new LongRunningProcessStatus());
    cmdTopics.run(split("compaction-status persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).compactionStatus("persistent://myprop/clust/ns1/ds1");
    PersistentTopicInternalStats stats = new PersistentTopicInternalStats();
    stats.ledgers = new ArrayList<>();
    stats.ledgers.add(newLedger(0, 10, 1000));
    stats.ledgers.add(newLedger(1, 10, 2000));
    stats.ledgers.add(newLedger(2, 10, 3000));
    when(mockTopics.getInternalStats("persistent://myprop/clust/ns1/ds1", false)).thenReturn(stats);
    cmdTopics.run(split("offload persistent://myprop/clust/ns1/ds1 -s 1k"));
    verify(mockTopics).triggerOffload("persistent://myprop/clust/ns1/ds1", new MessageIdImpl(2, 0, -1));
    when(mockTopics.offloadStatus("persistent://myprop/clust/ns1/ds1")).thenReturn(new OffloadProcessStatusImpl());
    cmdTopics.run(split("offload-status persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).offloadStatus("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("last-message-id persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getLastMessageId(eq("persistent://myprop/clust/ns1/ds1"));
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getMessageTTL("persistent://myprop/clust/ns1/ds1", false);
    cmdTopics.run(split("set-message-ttl persistent://myprop/clust/ns1/ds1 -t 10"));
    verify(mockTopics).setMessageTTL("persistent://myprop/clust/ns1/ds1", 10);
    cmdTopics.run(split("remove-message-ttl persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeMessageTTL("persistent://myprop/clust/ns1/ds1");
    cmdTopics.run(split("set-replicated-subscription-status persistent://myprop/clust/ns1/ds1 -s sub1 -d"));
    verify(mockTopics).setReplicatedSubscriptionStatus("persistent://myprop/clust/ns1/ds1", "sub1", false);
    cmdTopics.run(split("get-replicated-subscription-status persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).getReplicatedSubscriptionStatus("persistent://myprop/clust/ns1/ds1", "sub1");
    // cmd with option cannot be executed repeatedly.
    cmdTopics = new CmdTopics(() -> admin);
    cmdTopics.run(split("get-max-unacked-messages-on-subscription persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxUnackedMessagesOnSubscription("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("reset-cursor persistent://myprop/clust/ns1/ds2 -s sub1 -m 1:1 -e"));
    verify(mockTopics).resetCursor(eq("persistent://myprop/clust/ns1/ds2"), eq("sub1"), eq(new MessageIdImpl(1, 1, -1)), eq(true));
    cmdTopics.run(split("get-maxProducers persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxProducers("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-maxProducers persistent://myprop/clust/ns1/ds1 -p 3"));
    verify(mockTopics).setMaxProducers("persistent://myprop/clust/ns1/ds1", 3);
    cmdTopics.run(split("remove-maxProducers persistent://myprop/clust/ns1/ds2"));
    verify(mockTopics).removeMaxProducers("persistent://myprop/clust/ns1/ds2");
    cmdTopics.run(split("get-message-ttl persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMessageTTL("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-offload-policies persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getOffloadPolicies("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-max-unacked-messages-on-consumer persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxUnackedMessagesOnConsumer("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-inactive-topic-policies persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getInactiveTopicPolicies("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-delayed-delivery persistent://myprop/clust/ns1/ds1 --applied"));
    verify(mockTopics).getDelayedDeliveryPolicy("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-max-consumers persistent://myprop/clust/ns1/ds1 -ap"));
    verify(mockTopics).getMaxConsumers("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("get-replication-clusters persistent://myprop/clust/ns1/ds1 --applied"));
    verify(mockTopics).getReplicationClusters("persistent://myprop/clust/ns1/ds1", true);
    cmdTopics.run(split("set-replication-clusters persistent://myprop/clust/ns1/ds1 -c test"));
    verify(mockTopics).setReplicationClusters("persistent://myprop/clust/ns1/ds1", Lists.newArrayList("test"));
    cmdTopics.run(split("remove-replication-clusters persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).removeReplicationClusters("persistent://myprop/clust/ns1/ds1");
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) HashMap(java.util.HashMap) OffloadProcessStatusImpl(org.apache.pulsar.client.admin.internal.OffloadProcessStatusImpl) ArgumentMatcher(org.mockito.ArgumentMatcher) PersistentTopicInternalStats(org.apache.pulsar.common.policies.data.PersistentTopicInternalStats) Lookup(org.apache.pulsar.client.admin.Lookup) NonPersistentTopics(org.apache.pulsar.client.admin.NonPersistentTopics) Topics(org.apache.pulsar.client.admin.Topics) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) LongRunningProcessStatus(org.apache.pulsar.client.admin.LongRunningProcessStatus) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl) PublishRate(org.apache.pulsar.common.policies.data.PublishRate) Schemas(org.apache.pulsar.client.admin.Schemas) OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) SubscribeRate(org.apache.pulsar.common.policies.data.SubscribeRate) InactiveTopicPolicies(org.apache.pulsar.common.policies.data.InactiveTopicPolicies) MessageImpl(org.apache.pulsar.client.impl.MessageImpl) MessageId(org.apache.pulsar.client.api.MessageId) Test(org.testng.annotations.Test)

Example 4 with OffloadPoliciesImpl

use of org.apache.pulsar.common.policies.data.OffloadPoliciesImpl in project pulsar by apache.

the class NamespacesBase method internalSetOffloadDeletionLag.

protected void internalSetOffloadDeletionLag(Long newDeletionLagMs) {
    validateNamespacePolicyOperation(namespaceName, PolicyName.OFFLOAD, PolicyOperation.WRITE);
    validatePoliciesReadOnlyAccess();
    try {
        updatePolicies(namespaceName, policies -> {
            if (policies.offload_policies == null) {
                policies.offload_policies = new OffloadPoliciesImpl();
            }
            ((OffloadPoliciesImpl) policies.offload_policies).setManagedLedgerOffloadDeletionLagInMillis(newDeletionLagMs);
            policies.offload_deletion_lag_ms = newDeletionLagMs;
            return policies;
        });
        log.info("[{}] Successfully updated offloadDeletionLagMs configuration: namespace={}, value={}", clientAppId(), namespaceName, newDeletionLagMs);
    } catch (RestException pfe) {
        throw pfe;
    } catch (Exception e) {
        log.error("[{}] Failed to update offloadDeletionLag configuration for namespace {}", clientAppId(), namespaceName, e);
        throw new RestException(e);
    }
}
Also used : OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) RestException(org.apache.pulsar.broker.web.RestException) 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)

Example 5 with OffloadPoliciesImpl

use of org.apache.pulsar.common.policies.data.OffloadPoliciesImpl in project pulsar by apache.

the class NamespacesBase method internalSetOffloadThreshold.

protected void internalSetOffloadThreshold(long newThreshold) {
    validateNamespacePolicyOperation(namespaceName, PolicyName.OFFLOAD, PolicyOperation.WRITE);
    validatePoliciesReadOnlyAccess();
    try {
        updatePolicies(namespaceName, policies -> {
            if (policies.offload_policies == null) {
                policies.offload_policies = new OffloadPoliciesImpl();
            }
            ((OffloadPoliciesImpl) policies.offload_policies).setManagedLedgerOffloadThresholdInBytes(newThreshold);
            policies.offload_threshold = newThreshold;
            return policies;
        });
        log.info("[{}] Successfully updated offloadThreshold configuration: namespace={}, value={}", clientAppId(), namespaceName, newThreshold);
    } catch (RestException pfe) {
        throw pfe;
    } catch (Exception e) {
        log.error("[{}] Failed to update offloadThreshold configuration for namespace {}", clientAppId(), namespaceName, e);
        throw new RestException(e);
    }
}
Also used : OffloadPoliciesImpl(org.apache.pulsar.common.policies.data.OffloadPoliciesImpl) RestException(org.apache.pulsar.broker.web.RestException) 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

OffloadPoliciesImpl (org.apache.pulsar.common.policies.data.OffloadPoliciesImpl)23 Test (org.testng.annotations.Test)9 LedgerOffloader (org.apache.bookkeeper.mledger.LedgerOffloader)6 TopicName (org.apache.pulsar.common.naming.TopicName)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 WebTarget (javax.ws.rs.client.WebTarget)5 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)5 HashMap (java.util.HashMap)4 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)4 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)4 ExecutionException (java.util.concurrent.ExecutionException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)3 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)3 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)3 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)2 Map (java.util.Map)2 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)2 SubscriptionBusyException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)2 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)2