use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyData in project incubator-pulsar by apache.
the class NamespaceIsolationPolicyImplTest method testConstructor.
@Test
public void testConstructor() throws Exception {
NamespaceIsolationPolicyImpl defaultPolicy = this.getDefaultPolicy();
NamespaceIsolationData policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/test.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add("prod1-broker[1-3].messaging.use.example.com");
policyData.secondary = new ArrayList<String>();
policyData.secondary.add("prod1-broker.*.use.example.com");
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "3");
policyData.auto_failover_policy.parameters.put("usage_threshold", "90");
NamespaceIsolationPolicyImpl newPolicy = new NamespaceIsolationPolicyImpl(policyData);
assertTrue(defaultPolicy.equals(newPolicy));
policyData.auto_failover_policy.parameters.put("usage_threshold", "80");
newPolicy = new NamespaceIsolationPolicyImpl(policyData);
assertTrue(!defaultPolicy.equals(newPolicy));
assertTrue(!newPolicy.equals(new OldPolicies()));
}
use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyData in project incubator-pulsar by apache.
the class AutoFailoverPolicyDataTest method testAutoFailoverPolicyData.
@Test
public void testAutoFailoverPolicyData() {
AutoFailoverPolicyData policy0 = new AutoFailoverPolicyData();
AutoFailoverPolicyData policy1 = new AutoFailoverPolicyData();
policy0.policy_type = AutoFailoverPolicyType.min_available;
policy0.parameters = new HashMap<>();
policy0.parameters.put("min_limit", "3");
policy0.parameters.put("usage_threshold", "10");
policy1.policy_type = AutoFailoverPolicyType.min_available;
policy1.parameters = new HashMap<>();
policy1.parameters.put("min_limit", "3");
policy1.parameters.put("usage_threshold", "10");
try {
policy0.validate();
policy1.validate();
} catch (Exception e) {
fail("Should not happen");
}
assertTrue(policy0.equals(policy1));
policy1.parameters.put("min_limit", "5");
assertFalse(policy0.equals(policy1));
assertFalse(policy1.equals(new OldPolicies()));
}
use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyData in project incubator-pulsar by apache.
the class LoadBalancerTest method createNamespacePolicies.
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
// // prepare three policies for the namespace isolation
NamespaceIsolationPolicies policies = new NamespaceIsolationPolicies();
// set up policy that use this broker as primary
NamespaceIsolationData policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/primary-ns.*");
policyData.primary = new ArrayList<String>();
for (int i = 0; i < BROKER_COUNT; i++) {
policyData.primary.add(pulsarServices[i].getAdvertisedAddress());
}
policyData.secondary = new ArrayList<String>();
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("primaryBrokerPolicy", policyData);
// set up policy that use this broker as secondary
policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/secondary-ns.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add(pulsarServices[0].getAdvertisedAddress());
policyData.secondary = new ArrayList<String>();
for (int i = 1; i < BROKER_COUNT; i++) {
policyData.secondary.add(pulsarServices[i].getAdvertisedAddress());
}
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("secondaryBrokerPolicy", policyData);
// set up policy that do not use this broker (neither primary nor secondary)
policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/shared-ns.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add(pulsarServices[0].getAdvertisedAddress());
policyData.secondary = new ArrayList<String>();
for (int i = 1; i < BROKER_COUNT; i++) {
policyData.secondary.add(pulsarServices[i].getAdvertisedAddress());
}
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("otherBrokerPolicy", policyData);
ObjectMapper jsonMapper = ObjectMapperFactory.create();
ZooKeeper globalZk = pulsar.getGlobalZkCache().getZooKeeper();
ZkUtils.createFullPathOptimistic(globalZk, AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
byte[] content = jsonMapper.writeValueAsBytes(policies.getPolicies());
globalZk.setData(AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), content, -1);
}
use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyData in project incubator-pulsar by apache.
the class SimpleLoadManagerImplTest method createNamespacePolicies.
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
NamespaceIsolationPolicies policies = new NamespaceIsolationPolicies();
// set up policy that use this broker as primary
NamespaceIsolationData policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/primary-ns.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add(pulsar1.getAdvertisedAddress() + "*");
policyData.secondary = new ArrayList<String>();
policyData.secondary.add("prod2-broker([78]).messaging.usw.example.co.*");
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("primaryBrokerPolicy", policyData);
ObjectMapper jsonMapper = ObjectMapperFactory.create();
ZooKeeper globalZk = pulsar.getGlobalZkCache().getZooKeeper();
ZkUtils.createFullPathOptimistic(globalZk, AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
byte[] content = jsonMapper.writeValueAsBytes(policies.getPolicies());
globalZk.setData(AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), content, -1);
}
use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyData in project incubator-pulsar by apache.
the class AdminApiTest method clusterNamespaceIsolationPolicies.
@Test
public void clusterNamespaceIsolationPolicies() throws PulsarAdminException {
try {
// create
String policyName1 = "policy-1";
NamespaceIsolationData nsPolicyData1 = new NamespaceIsolationData();
nsPolicyData1.namespaces = new ArrayList<String>();
nsPolicyData1.namespaces.add("other/use/other.*");
nsPolicyData1.primary = new ArrayList<String>();
nsPolicyData1.primary.add("prod1-broker[4-6].messaging.use.example.com");
nsPolicyData1.secondary = new ArrayList<String>();
nsPolicyData1.secondary.add("prod1-broker.*.messaging.use.example.com");
nsPolicyData1.auto_failover_policy = new AutoFailoverPolicyData();
nsPolicyData1.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
nsPolicyData1.auto_failover_policy.parameters = new HashMap<String, String>();
nsPolicyData1.auto_failover_policy.parameters.put("min_limit", "1");
nsPolicyData1.auto_failover_policy.parameters.put("usage_threshold", "100");
admin.clusters().createNamespaceIsolationPolicy("use", policyName1, nsPolicyData1);
String policyName2 = "policy-2";
NamespaceIsolationData nsPolicyData2 = new NamespaceIsolationData();
nsPolicyData2.namespaces = new ArrayList<String>();
nsPolicyData2.namespaces.add("other/use/other.*");
nsPolicyData2.primary = new ArrayList<String>();
nsPolicyData2.primary.add("prod1-broker[4-6].messaging.use.example.com");
nsPolicyData2.secondary = new ArrayList<String>();
nsPolicyData2.secondary.add("prod1-broker.*.messaging.use.example.com");
nsPolicyData2.auto_failover_policy = new AutoFailoverPolicyData();
nsPolicyData2.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
nsPolicyData2.auto_failover_policy.parameters = new HashMap<String, String>();
nsPolicyData2.auto_failover_policy.parameters.put("min_limit", "1");
nsPolicyData2.auto_failover_policy.parameters.put("usage_threshold", "100");
admin.clusters().createNamespaceIsolationPolicy("use", policyName2, nsPolicyData2);
// verify create indirectly with get
Map<String, NamespaceIsolationData> policiesMap = admin.clusters().getNamespaceIsolationPolicies("use");
assertEquals(policiesMap.get(policyName1), nsPolicyData1);
assertEquals(policiesMap.get(policyName2), nsPolicyData2);
// verify update of primary
nsPolicyData1.primary.remove(0);
nsPolicyData1.primary.add("prod1-broker[1-2].messaging.use.example.com");
admin.clusters().updateNamespaceIsolationPolicy("use", policyName1, nsPolicyData1);
// verify primary change
policiesMap = admin.clusters().getNamespaceIsolationPolicies("use");
assertEquals(policiesMap.get(policyName1), nsPolicyData1);
// verify update of secondary
nsPolicyData1.secondary.remove(0);
nsPolicyData1.secondary.add("prod1-broker[3-4].messaging.use.example.com");
admin.clusters().updateNamespaceIsolationPolicy("use", policyName1, nsPolicyData1);
// verify secondary change
policiesMap = admin.clusters().getNamespaceIsolationPolicies("use");
assertEquals(policiesMap.get(policyName1), nsPolicyData1);
// verify update of failover policy limit
nsPolicyData1.auto_failover_policy.parameters.put("min_limit", "10");
admin.clusters().updateNamespaceIsolationPolicy("use", policyName1, nsPolicyData1);
// verify min_limit change
policiesMap = admin.clusters().getNamespaceIsolationPolicies("use");
assertEquals(policiesMap.get(policyName1), nsPolicyData1);
// verify update of failover usage_threshold limit
nsPolicyData1.auto_failover_policy.parameters.put("usage_threshold", "80");
admin.clusters().updateNamespaceIsolationPolicy("use", policyName1, nsPolicyData1);
// verify usage_threshold change
policiesMap = admin.clusters().getNamespaceIsolationPolicies("use");
assertEquals(policiesMap.get(policyName1), nsPolicyData1);
// verify single get
NamespaceIsolationData policy1Data = admin.clusters().getNamespaceIsolationPolicy("use", policyName1);
assertEquals(policy1Data, nsPolicyData1);
// verify creation of more than one policy
admin.clusters().createNamespaceIsolationPolicy("use", policyName2, nsPolicyData1);
try {
admin.clusters().getNamespaceIsolationPolicy("use", "no-such-policy");
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof NotFoundException);
}
// verify delete cluster failed
try {
admin.clusters().deleteCluster("use");
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof PreconditionFailedException);
}
// verify delete
admin.clusters().deleteNamespaceIsolationPolicy("use", policyName1);
admin.clusters().deleteNamespaceIsolationPolicy("use", policyName2);
try {
admin.clusters().getNamespaceIsolationPolicy("use", policyName1);
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof NotFoundException);
}
try {
admin.clusters().getNamespaceIsolationPolicy("use", policyName2);
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof NotFoundException);
}
try {
admin.clusters().getNamespaceIsolationPolicies("usc");
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof NotFoundException);
}
try {
admin.clusters().getNamespaceIsolationPolicy("usc", "no-such-cluster");
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof PreconditionFailedException);
}
try {
admin.clusters().createNamespaceIsolationPolicy("usc", "no-such-cluster", nsPolicyData1);
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof PreconditionFailedException);
}
try {
admin.clusters().updateNamespaceIsolationPolicy("usc", "no-such-cluster", policy1Data);
fail("should have raised exception");
} catch (PulsarAdminException e) {
assertTrue(e instanceof PreconditionFailedException);
}
} catch (PulsarAdminException e) {
LOG.warn("TEST FAILED [{}]", e.getMessage());
throw e;
}
}
Aggregations