use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class PoliciesDataTest method bundlesPolicies.
@Test
void bundlesPolicies() throws JsonGenerationException, JsonMappingException, IOException {
ObjectMapper jsonMapper = ObjectMapperFactory.create();
String oldJsonPolicy = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}},\"replication_clusters\":[]," + "\"backlog_quota_map\":{},\"persistence\":null,\"latency_stats_sample_rate\":{},\"message_ttl_in_seconds\":0}";
Policies policies = jsonMapper.readValue(oldJsonPolicy.getBytes(), Policies.class);
assertEquals(policies, new Policies());
String newJsonPolicy = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}},\"replication_clusters\":[],\"bundles\":null," + "\"backlog_quota_map\":{},\"persistence\":null,\"latency_stats_sample_rate\":{},\"message_ttl_in_seconds\":0}";
OldPolicies oldPolicies = jsonMapper.readValue(newJsonPolicy.getBytes(), OldPolicies.class);
assertEquals(oldPolicies, new OldPolicies());
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class PoliciesDataTest method bundlesData.
@Test
void bundlesData() throws JsonParseException, JsonMappingException, IOException {
ObjectMapper jsonMapper = ObjectMapperFactory.create();
String newJsonPolicy = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}},\"replication_clusters\":[],\"bundles\":{\"boundaries\":[\"0x00000000\",\"0xffffffff\"]},\"backlog_quota_map\":{},\"persistence\":null,\"latency_stats_sample_rate\":{}}";
List<String> bundleSet = Lists.newArrayList();
bundleSet.add("0x00000000");
bundleSet.add("0xffffffff");
String newBundlesDataString = "{\"boundaries\":[\"0x00000000\",\"0xffffffff\"]}";
BundlesData data = jsonMapper.readValue(newBundlesDataString.getBytes(), BundlesData.class);
assertEquals(data.getBoundaries(), bundleSet);
Policies policies = jsonMapper.readValue(newJsonPolicy.getBytes(), Policies.class);
Policies expected = new Policies();
expected.bundles = data;
assertEquals(policies, expected);
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class NamespacesBase method internalUnsubscribeNamespaceBundle.
@SuppressWarnings("deprecation")
protected void internalUnsubscribeNamespaceBundle(String subscription, String bundleRange, boolean authoritative) {
validateAdminAccessOnProperty(namespaceName.getProperty());
Policies policies = getNamespacePolicies(namespaceName);
if (namespaceName.isGlobal()) {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(namespaceName);
} else {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
}
validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, authoritative, true);
unsubscribe(namespaceName, bundleRange, subscription);
log.info("[{}] Successfully unsubscribed {} on namespace bundle {}/{}", clientAppId(), subscription, namespaceName, bundleRange);
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class NamespacesBase method internalUnloadNamespaceBundle.
@SuppressWarnings("deprecation")
public void internalUnloadNamespaceBundle(String bundleRange, boolean authoritative) {
log.info("[{}] Unloading namespace bundle {}/{}", clientAppId(), namespaceName, bundleRange);
validateSuperUserAccess();
Policies policies = getNamespacePolicies(namespaceName);
if (namespaceName.isGlobal()) {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(namespaceName);
} else {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
}
validatePoliciesReadOnlyAccess();
if (!isBundleOwnedByAnyBroker(namespaceName, policies.bundles, bundleRange)) {
log.info("[{}] Namespace bundle is not owned by any broker {}/{}", clientAppId(), namespaceName, bundleRange);
return;
}
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, authoritative, true);
try {
pulsar().getNamespaceService().unloadNamespaceBundle(nsBundle);
log.info("[{}] Successfully unloaded namespace bundle {}", clientAppId(), nsBundle.toString());
} catch (Exception e) {
log.error("[{}] Failed to unload namespace bundle {}/{}", clientAppId(), namespaceName, bundleRange, e);
throw new RestException(e);
}
}
use of org.apache.pulsar.common.policies.data.Policies in project incubator-pulsar by apache.
the class NamespacesBase method internalClearNamespaceBundleBacklogForSubscription.
@SuppressWarnings("deprecation")
protected void internalClearNamespaceBundleBacklogForSubscription(String subscription, String bundleRange, boolean authoritative) {
validateAdminAccessOnProperty(namespaceName.getProperty());
Policies policies = getNamespacePolicies(namespaceName);
if (namespaceName.isGlobal()) {
// check cluster ownership for a given global namespace: redirect if peer-cluster owns it
validateGlobalNamespaceOwnership(namespaceName);
} else {
validateClusterOwnership(namespaceName.getCluster());
validateClusterForProperty(namespaceName.getProperty(), namespaceName.getCluster());
}
validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange, authoritative, true);
clearBacklog(namespaceName, bundleRange, subscription);
log.info("[{}] Successfully cleared backlog for subscription {} on namespace bundle {}/{}", clientAppId(), subscription, namespaceName, bundleRange);
}
Aggregations