Java Code Examples for org.apache.pulsar.client.admin.PulsarAdminException#ConflictException
The following examples show how to use
org.apache.pulsar.client.admin.PulsarAdminException#ConflictException .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: V1_AdminApiTest2.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void clusterFailureDomain() throws PulsarAdminException { final String cluster = pulsar.getConfiguration().getClusterName(); admin.clusters().createCluster(cluster, new ClusterData(pulsar.getSafeWebServiceAddress(), 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")); }
Example 2
Source File: AdminApiTest2.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void clusterFailureDomain() throws PulsarAdminException { final String cluster = pulsar.getConfiguration().getClusterName(); // 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")); }
Example 3
Source File: V1_AdminApiTest2.java From pulsar with Apache License 2.0 | 4 votes |
/** * It validates that peer-cluster can't coexist in replication-cluster list * * @throws Exception */ @Test public void testReplicationPeerCluster() throws Exception { admin.clusters().createCluster("us-west1", new ClusterData("http://broker.messaging.west1.example.com:8080")); admin.clusters().createCluster("us-west2", new ClusterData("http://broker.messaging.west2.example.com:8080")); admin.clusters().createCluster("us-west3", new ClusterData("http://broker.messaging.west2.example.com:8080")); admin.clusters().createCluster("us-west4", new ClusterData("http://broker.messaging.west2.example.com:8080")); admin.clusters().createCluster("us-east1", new ClusterData("http://broker.messaging.east1.example.com:8080")); admin.clusters().createCluster("us-east2", new ClusterData("http://broker.messaging.east2.example.com:8080")); admin.clusters().createCluster("global", new ClusterData()); final String property = "peer-prop"; Set<String> allowedClusters = Sets.newHashSet("us-west1", "us-west2", "us-west3", "us-west4", "us-east1", "us-east2"); TenantInfo propConfig = new TenantInfo(Sets.newHashSet("test"), allowedClusters); admin.tenants().createTenant(property, propConfig); final String namespace = property + "/global/conflictPeer"; admin.namespaces().createNamespace(namespace); admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west2", "us-west3"))); assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), Lists.newArrayList("us-west2", "us-west3")); // (1) no conflicting peer Set<String> clusterIds = Sets.newHashSet("us-east1", "us-east2"); admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); // (2) conflicting peer clusterIds = Sets.newHashSet("us-west2", "us-west3", "us-west1"); try { admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); fail("Peer-cluster can't coexist in replication cluster list"); } catch (PulsarAdminException.ConflictException e) { // Ok } clusterIds = Sets.newHashSet("us-west2", "us-west3"); // no peer coexist in replication clusters admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); clusterIds = Sets.newHashSet("us-west1", "us-west4"); // no peer coexist in replication clusters admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); }
Example 4
Source File: AdminApiTest2.java From pulsar with Apache License 2.0 | 4 votes |
/** * It validates that peer-cluster can't coexist in replication-cluster list * * @throws Exception */ @Test public void testReplicationPeerCluster() throws Exception { admin.clusters().createCluster("us-west1", new ClusterData("http://broker.messaging.west1.example.com:8080")); admin.clusters().createCluster("us-west2", new ClusterData("http://broker.messaging.west2.example.com:8080")); admin.clusters().createCluster("us-west3", new ClusterData("http://broker.messaging.west2.example.com:8080")); admin.clusters().createCluster("us-west4", new ClusterData("http://broker.messaging.west2.example.com:8080")); admin.clusters().createCluster("us-east1", new ClusterData("http://broker.messaging.east1.example.com:8080")); admin.clusters().createCluster("us-east2", new ClusterData("http://broker.messaging.east2.example.com:8080")); admin.clusters().createCluster("global", new ClusterData()); List<String> allClusters = admin.clusters().getClusters(); Collections.sort(allClusters); assertEquals(allClusters, Lists.newArrayList("test", "us-east1", "us-east2", "us-west1", "us-west2", "us-west3", "us-west4")); final String property = "peer-prop"; Set<String> allowedClusters = Sets.newHashSet("us-west1", "us-west2", "us-west3", "us-west4", "us-east1", "us-east2", "global"); TenantInfo propConfig = new TenantInfo(Sets.newHashSet("test"), allowedClusters); admin.tenants().createTenant(property, propConfig); final String namespace = property + "/global/conflictPeer"; admin.namespaces().createNamespace(namespace); admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west2", "us-west3"))); assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), Lists.newArrayList("us-west2", "us-west3")); // (1) no conflicting peer Set<String> clusterIds = Sets.newHashSet("us-east1", "us-east2"); admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); // (2) conflicting peer clusterIds = Sets.newHashSet("us-west2", "us-west3", "us-west1"); try { admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); fail("Peer-cluster can't coexist in replication cluster list"); } catch (PulsarAdminException.ConflictException e) { // Ok } clusterIds = Sets.newHashSet("us-west2", "us-west3"); // no peer coexist in replication clusters admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); clusterIds = Sets.newHashSet("us-west1", "us-west4"); // no peer coexist in replication clusters admin.namespaces().setNamespaceReplicationClusters(namespace, clusterIds); }