use of org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl in project pulsar by apache.
the class PersistentTopicsBase method internalSetBacklogQuota.
protected CompletableFuture<Void> internalSetBacklogQuota(BacklogQuota.BacklogQuotaType backlogQuotaType, BacklogQuotaImpl backlogQuota, boolean isGlobal) {
BacklogQuota.BacklogQuotaType finalBacklogQuotaType = backlogQuotaType == null ? BacklogQuota.BacklogQuotaType.destination_storage : backlogQuotaType;
return validateTopicPolicyOperationAsync(topicName, PolicyName.BACKLOG, PolicyOperation.WRITE).thenAccept(__ -> validatePoliciesReadOnlyAccess()).thenCompose(__ -> getTopicPoliciesAsyncWithRetry(topicName, isGlobal)).thenCompose(op -> {
TopicPolicies topicPolicies = op.orElseGet(TopicPolicies::new);
return getRetentionPoliciesAsync(topicName, topicPolicies).thenCompose(retentionPolicies -> {
if (!checkBacklogQuota(backlogQuota, retentionPolicies)) {
log.warn("[{}] Failed to update backlog configuration for topic {}: conflicts with" + " retention quota", clientAppId(), topicName);
return FutureUtil.failedFuture(new RestException(Status.PRECONDITION_FAILED, "Backlog Quota exceeds configured retention quota for topic. " + "Please increase retention quota and retry"));
}
if (backlogQuota != null) {
topicPolicies.getBackLogQuotaMap().put(finalBacklogQuotaType.name(), backlogQuota);
} else {
topicPolicies.getBackLogQuotaMap().remove(finalBacklogQuotaType.name());
}
Map<String, BacklogQuotaImpl> backLogQuotaMap = topicPolicies.getBackLogQuotaMap();
topicPolicies.setIsGlobal(isGlobal);
return pulsar().getTopicPoliciesService().updateTopicPoliciesAsync(topicName, topicPolicies).thenRun(() -> {
try {
log.info("[{}] Successfully updated backlog quota map: namespace={}, " + "topic={}, map={}", clientAppId(), namespaceName, topicName.getLocalName(), jsonMapper().writeValueAsString(backLogQuotaMap));
} catch (JsonProcessingException ignore) {
}
});
});
});
}
use of org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl in project pulsar by apache.
the class ReplicatorTopicPoliciesTest method testReplicateQuotaTopicPolicies.
@Test
public void testReplicateQuotaTopicPolicies() throws Exception {
final String namespace = "pulsar/partitionedNs-" + UUID.randomUUID();
final String topic = "persistent://" + namespace + "/topic" + UUID.randomUUID();
init(namespace, topic);
// set BacklogQuota
BacklogQuotaImpl backlogQuota = new BacklogQuotaImpl();
backlogQuota.setLimitSize(1);
backlogQuota.setLimitTime(2);
// local
admin1.topicPolicies().setBacklogQuota(topic, backlogQuota);
Awaitility.await().untilAsserted(() -> assertEquals(admin2.topicPolicies().getBacklogQuotaMap(topic).size(), 0));
Awaitility.await().untilAsserted(() -> assertEquals(admin3.topicPolicies().getBacklogQuotaMap(topic).size(), 0));
// global
admin1.topicPolicies(true).setBacklogQuota(topic, backlogQuota);
Awaitility.await().untilAsserted(() -> assertTrue(admin2.topicPolicies(true).getBacklogQuotaMap(topic).containsValue(backlogQuota)));
Awaitility.await().untilAsserted(() -> assertTrue(admin3.topicPolicies(true).getBacklogQuotaMap(topic).containsValue(backlogQuota)));
// remove BacklogQuota
admin1.topicPolicies(true).removeBacklogQuota(topic);
Awaitility.await().untilAsserted(() -> assertEquals(admin2.topicPolicies(true).getBacklogQuotaMap(topic).size(), 0));
Awaitility.await().untilAsserted(() -> assertEquals(admin3.topicPolicies(true).getBacklogQuotaMap(topic).size(), 0));
}
use of org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl in project pulsar by apache.
the class BacklogQuotaCompatibilityTest method testV27ClientSetV28BrokerRead.
@Test
public void testV27ClientSetV28BrokerRead() throws Exception {
Policies writePolicy = new Policies();
BacklogQuotaImpl writeBacklogQuota = new BacklogQuotaImpl();
writeBacklogQuota.setLimit(1024);
writeBacklogQuota.setLimitTime(60);
writeBacklogQuota.setPolicy(testPolicy);
HashMap<BacklogQuota.BacklogQuotaType, BacklogQuota> quotaHashMap = new HashMap<>();
quotaHashMap.put(BacklogQuota.BacklogQuotaType.destination_storage, writeBacklogQuota);
writePolicy.backlog_quota_map = quotaHashMap;
byte[] serialize = simpleType.serialize("/path", writePolicy);
Policies policies = simpleType.deserialize("/path", serialize, null);
BacklogQuota readBacklogQuota = policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage);
Assert.assertEquals(readBacklogQuota.getLimitSize(), 1024);
Assert.assertEquals(readBacklogQuota.getLimitTime(), 60);
Assert.assertEquals(readBacklogQuota.getPolicy(), testPolicy);
}
use of org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl in project pulsar by apache.
the class BacklogQuotaCompatibilityTest method testV28ClientSetV28BrokerRead.
@Test
public void testV28ClientSetV28BrokerRead() throws Exception {
Policies writePolicy = new Policies();
BacklogQuotaImpl writeBacklogQuota = new BacklogQuotaImpl();
writeBacklogQuota.setLimitSize(1024);
writeBacklogQuota.setLimitTime(60);
writeBacklogQuota.setPolicy(testPolicy);
HashMap<BacklogQuota.BacklogQuotaType, BacklogQuota> quotaHashMap = new HashMap<>();
quotaHashMap.put(BacklogQuota.BacklogQuotaType.destination_storage, writeBacklogQuota);
writePolicy.backlog_quota_map = quotaHashMap;
byte[] serialize = simpleType.serialize("/path", writePolicy);
Policies policies = simpleType.deserialize("/path", serialize, null);
BacklogQuota readBacklogQuota = policies.backlog_quota_map.get(BacklogQuota.BacklogQuotaType.destination_storage);
Assert.assertEquals(readBacklogQuota.getLimit(), 1024);
Assert.assertEquals(readBacklogQuota.getLimitTime(), 60);
Assert.assertEquals(readBacklogQuota.getPolicy(), testPolicy);
}
use of org.apache.pulsar.common.policies.data.impl.BacklogQuotaImpl in project pulsar by apache.
the class BacklogQuotaCompatibilityTest method testV28ClientSetV27BrokerRead.
@Test
public void testV28ClientSetV27BrokerRead() {
BacklogQuotaImpl writeBacklogQuota = new BacklogQuotaImpl();
writeBacklogQuota.setLimitSize(1024);
Assert.assertEquals(1024, writeBacklogQuota.getLimit());
}
Aggregations