use of org.apache.pulsar.common.policies.data.FailureDomain in project incubator-pulsar by apache.
the class PulsarAdminToolTest method clusters.
@Test
void clusters() throws Exception {
PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
Clusters mockClusters = mock(Clusters.class);
when(admin.clusters()).thenReturn(mockClusters);
CmdClusters clusters = new CmdClusters(admin);
clusters.run(split("list"));
verify(mockClusters).getClusters();
clusters.run(split("get use"));
verify(mockClusters).getCluster("use");
clusters.run(split("create use --url http://my-service.url:8080"));
verify(mockClusters).createCluster("use", new ClusterData("http://my-service.url:8080", null));
clusters.run(split("update use --url http://my-service.url:8080"));
verify(mockClusters).updateCluster("use", new ClusterData("http://my-service.url:8080", null));
clusters.run(split("delete use"));
verify(mockClusters).deleteCluster("use");
clusters.run(split("list-failure-domains use"));
verify(mockClusters).getFailureDomains("use");
clusters.run(split("get-failure-domain use --domain-name domain"));
verify(mockClusters).getFailureDomain("use", "domain");
clusters.run(split("create-failure-domain use --domain-name domain --broker-list b1"));
FailureDomain domain = new FailureDomain();
domain.setBrokers(Sets.newHashSet("b1"));
verify(mockClusters).createFailureDomain("use", "domain", domain);
clusters.run(split("update-failure-domain use --domain-name domain --broker-list b1"));
verify(mockClusters).updateFailureDomain("use", "domain", domain);
clusters.run(split("delete-failure-domain use --domain-name domain"));
verify(mockClusters).deleteFailureDomain("use", "domain");
// Re-create CmdClusters to avoid a issue.
// See https://github.com/cbeust/jcommander/issues/271
clusters = new CmdClusters(admin);
clusters.run(split("create my-cluster --url http://my-service.url:8080 --url-secure https://my-service.url:4443"));
verify(mockClusters).createCluster("my-cluster", new ClusterData("http://my-service.url:8080", "https://my-service.url:4443"));
clusters.run(split("update my-cluster --url http://my-service.url:8080 --url-secure https://my-service.url:4443"));
verify(mockClusters).updateCluster("my-cluster", new ClusterData("http://my-service.url:8080", "https://my-service.url:4443"));
clusters.run(split("delete my-cluster"));
verify(mockClusters).deleteCluster("my-cluster");
clusters.run(split("update-peer-clusters my-cluster --peer-clusters c1,c2"));
verify(mockClusters).updatePeerClusterNames("my-cluster", Sets.newLinkedHashSet(Lists.newArrayList("c1", "c2")));
clusters.run(split("get-peer-clusters my-cluster"));
verify(mockClusters).getPeerClusterNames("my-cluster");
}
use of org.apache.pulsar.common.policies.data.FailureDomain in project incubator-pulsar by apache.
the class ClustersBase method getFailureDomains.
@GET
@Path("/{cluster}/failureDomains")
@ApiOperation(value = "Get the cluster failure domains", response = FailureDomain.class, responseContainer = "Map")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public Map<String, FailureDomain> getFailureDomains(@PathParam("cluster") String cluster) throws Exception {
validateSuperUserAccess();
Map<String, FailureDomain> domains = Maps.newHashMap();
try {
final String failureDomainRootPath = pulsar().getConfigurationCache().CLUSTER_FAILURE_DOMAIN_ROOT;
for (String domainName : failureDomainListCache().get()) {
try {
Optional<FailureDomain> domain = failureDomainCache().get(joinPath(failureDomainRootPath, domainName));
if (domain.isPresent()) {
domains.put(domainName, domain.get());
}
} catch (Exception e) {
log.warn("Failed to get domain {}", domainName, e);
}
}
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failure-domain is not configured for cluster {}", clientAppId(), cluster, e);
return Collections.emptyMap();
} catch (Exception e) {
log.error("[{}] Failed to get failure-domains for cluster {}", clientAppId(), cluster, e);
throw new RestException(e);
}
return domains;
}
use of org.apache.pulsar.common.policies.data.FailureDomain in project incubator-pulsar by apache.
the class AntiAffinityNamespaceGroupTest method testBrokerSelectionForAntiAffinityGroup.
/**
* It verifies anti-affinity with failure domain enabled with 2 brokers.
*
* <pre>
* 1. Register brokers to domain: domain-1: broker1 & domain-2: broker2
* 2. Load-Manager receives a watch and updates brokerToDomain cache with new domain data
* 3. Create two namespace with anti-affinity
* 4. Load-manager selects broker for each namespace such that from different domains
*
* </pre>
*
* @throws Exception
*/
@Test
public void testBrokerSelectionForAntiAffinityGroup() throws Exception {
final String broker1 = primaryHost;
final String broker2 = secondaryHost;
final String cluster = pulsar1.getConfiguration().getClusterName();
final String property = "prop";
final String namespace1 = property + "/" + cluster + "/ns1";
final String namespace2 = property + "/" + cluster + "/ns2";
final String namespaceAntiAffinityGroup = "group";
FailureDomain domain = new FailureDomain();
domain.brokers = Sets.newHashSet(broker1);
admin1.clusters().createFailureDomain(cluster, "domain1", domain);
domain.brokers = Sets.newHashSet(broker2);
admin1.clusters().createFailureDomain(cluster, "domain1", domain);
admin1.properties().createProperty(property, new PropertyAdmin(null, Sets.newHashSet(cluster)));
admin1.namespaces().createNamespace(namespace1);
admin1.namespaces().createNamespace(namespace2);
admin1.namespaces().setNamespaceAntiAffinityGroup(namespace1, namespaceAntiAffinityGroup);
admin1.namespaces().setNamespaceAntiAffinityGroup(namespace2, namespaceAntiAffinityGroup);
// validate strategically if brokerToDomainCache updated
for (int i = 0; i < 5; i++) {
if (!isLoadManagerUpdatedDomainCache(primaryLoadManager) || !isLoadManagerUpdatedDomainCache(secondaryLoadManager) || i != 4) {
Thread.sleep(200);
}
}
assertTrue(isLoadManagerUpdatedDomainCache(primaryLoadManager));
assertTrue(isLoadManagerUpdatedDomainCache(secondaryLoadManager));
ServiceUnitId serviceUnit = makeBundle(property, cluster, "ns1");
String selectedBroker1 = primaryLoadManager.selectBrokerForAssignment(serviceUnit).get();
serviceUnit = makeBundle(property, cluster, "ns2");
String selectedBroker2 = primaryLoadManager.selectBrokerForAssignment(serviceUnit).get();
assertNotEquals(selectedBroker1, selectedBroker2);
}
use of org.apache.pulsar.common.policies.data.FailureDomain in project incubator-pulsar by apache.
the class AdminApiTest2 method clusterFailureDomain.
@Test
public void clusterFailureDomain() throws PulsarAdminException {
final String cluster = pulsar.getConfiguration().getClusterName();
admin.clusters().createCluster(cluster, new ClusterData(pulsar.getWebServiceAddress(), pulsar.getWebServiceAddressTls()));
// create
FailureDomain domain = new FailureDomain();
domain.setBrokers(Sets.newHashSet("b1", "b2", "b3"));
admin.clusters().createFailureDomain(cluster, "domain-1", domain);
admin.clusters().updateFailureDomain(cluster, "domain-1", domain);
assertEquals(admin.clusters().getFailureDomain(cluster, "domain-1"), domain);
Map<String, FailureDomain> domains = admin.clusters().getFailureDomains(cluster);
assertEquals(domains.size(), 1);
assertTrue(domains.containsKey("domain-1"));
try {
// try to create domain with already registered brokers
admin.clusters().createFailureDomain(cluster, "domain-2", domain);
fail("should have failed because of brokers are already registered");
} catch (PulsarAdminException.ConflictException e) {
// Ok
}
admin.clusters().deleteFailureDomain(cluster, "domain-1");
assertTrue(admin.clusters().getFailureDomains(cluster).isEmpty());
admin.clusters().createFailureDomain(cluster, "domain-2", domain);
domains = admin.clusters().getFailureDomains(cluster);
assertEquals(domains.size(), 1);
assertTrue(domains.containsKey("domain-2"));
}
Aggregations