Search in sources :

Example 86 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.

the class AdminApiTest method testNamespaceUnloadBundle.

@Test
public void testNamespaceUnloadBundle() throws Exception {
    assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1"), Lists.newArrayList());
    // Force to create a topic
    publishMessagesOnPersistentTopic("persistent://prop-xyz/use/ns1/ds2", 0);
    assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1"), Lists.newArrayList("persistent://prop-xyz/use/ns1/ds2"));
    // create consumer and subscription
    Consumer<byte[]> consumer = pulsarClient.newConsumer().topic("persistent://prop-xyz/use/ns1/ds2").subscriptionName("my-sub").subscribe();
    assertEquals(admin.persistentTopics().getSubscriptions("persistent://prop-xyz/use/ns1/ds2"), Lists.newArrayList("my-sub"));
    // Create producer
    Producer<byte[]> producer = pulsarClient.newProducer().topic("persistent://prop-xyz/use/ns1/ds2").create();
    for (int i = 0; i < 10; i++) {
        String message = "message-" + i;
        producer.send(message.getBytes());
    }
    consumer.close();
    producer.close();
    try {
        admin.namespaces().unloadNamespaceBundle("prop-xyz/use/ns1", "0x00000000_0xffffffff");
    } catch (Exception e) {
        fail("Unload shouldn't have throw exception");
    }
    // check that no one owns the namespace
    NamespaceBundle bundle = bundleFactory.getBundle(NamespaceName.get("prop-xyz/use/ns1"), Range.range(0L, BoundType.CLOSED, 0xffffffffL, BoundType.CLOSED));
    assertFalse(pulsar.getNamespaceService().isServiceUnitOwned(bundle));
    assertFalse(otherPulsar.getNamespaceService().isServiceUnitOwned(bundle));
    pulsarClient.shutdown();
    LOG.info("--- RELOAD ---");
    // Force reload of namespace and wait for topic to be ready
    for (int i = 0; i < 30; i++) {
        try {
            admin.persistentTopics().getStats("persistent://prop-xyz/use/ns1/ds2");
            break;
        } catch (PulsarAdminException e) {
            LOG.warn("Failed to get topic stats.. {}", e.getMessage());
            Thread.sleep(1000);
        }
    }
    admin.persistentTopics().deleteSubscription("persistent://prop-xyz/use/ns1/ds2", "my-sub");
    admin.persistentTopics().delete("persistent://prop-xyz/use/ns1/ds2");
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) ConflictException(org.apache.pulsar.client.admin.PulsarAdminException.ConflictException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) NotAuthorizedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 87 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException 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"));
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) FailureDomain(org.apache.pulsar.common.policies.data.FailureDomain) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 88 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.

the class AdminApiTest2 method testSetPersistencepolicies.

/**
 * verifies validation on persistent-policies
 *
 * @throws Exception
 */
@Test
public void testSetPersistencepolicies() throws Exception {
    final String namespace = "prop-xyz/use/ns2";
    admin.namespaces().createNamespace(namespace);
    assertEquals(admin.namespaces().getPersistence(namespace), new PersistencePolicies(1, 1, 1, 0.0));
    admin.namespaces().setPersistence(namespace, new PersistencePolicies(3, 3, 3, 10.0));
    assertEquals(admin.namespaces().getPersistence(namespace), new PersistencePolicies(3, 3, 3, 10.0));
    try {
        admin.namespaces().setPersistence(namespace, new PersistencePolicies(3, 4, 3, 10.0));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertEquals(e.getStatusCode(), 412);
    }
    try {
        admin.namespaces().setPersistence(namespace, new PersistencePolicies(3, 3, 4, 10.0));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertEquals(e.getStatusCode(), 412);
    }
    try {
        admin.namespaces().setPersistence(namespace, new PersistencePolicies(6, 3, 1, 10.0));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertEquals(e.getStatusCode(), 412);
    }
    // make sure policies has not been changed
    assertEquals(admin.namespaces().getPersistence(namespace), new PersistencePolicies(3, 3, 3, 10.0));
}
Also used : PersistencePolicies(org.apache.pulsar.common.policies.data.PersistencePolicies) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 89 with PulsarAdminException

use of org.apache.pulsar.client.admin.PulsarAdminException in project incubator-pulsar by apache.

the class AdminApiTest2 method testPeerCluster.

@Test
public void testPeerCluster() throws Exception {
    admin.clusters().createCluster("us-west1", new ClusterData("http://broker.messaging.west1.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().createCluster("us-west2", new ClusterData("http://broker.messaging.west2.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().createCluster("us-east1", new ClusterData("http://broker.messaging.east1.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().createCluster("us-east2", new ClusterData("http://broker.messaging.east2.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west2")));
    assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), Lists.newArrayList("us-west2"));
    assertEquals(admin.clusters().getCluster("us-west2").getPeerClusterNames(), null);
    // update cluster with duplicate peer-clusters in the list
    admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west2", "us-east1", "us-west2", "us-east1", "us-west2", "us-east1")));
    assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), Lists.newArrayList("us-west2", "us-east1"));
    admin.clusters().updatePeerClusterNames("us-west1", null);
    assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), null);
    // Check name validation
    try {
        admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("invalid-cluster")));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertTrue(e instanceof PreconditionFailedException);
    }
    // Cluster itselft can't be part of peer-list
    try {
        admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west1")));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertTrue(e instanceof PreconditionFailedException);
    }
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)89 WebTarget (javax.ws.rs.client.WebTarget)57 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)51 Test (org.testng.annotations.Test)18 ClientErrorException (javax.ws.rs.ClientErrorException)14 ExecutionException (java.util.concurrent.ExecutionException)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)12 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)10 ServerErrorException (javax.ws.rs.ServerErrorException)9 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)9 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)8 PreconditionFailedException (org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)7 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)7 TopicName (org.apache.pulsar.common.naming.TopicName)6 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)6 RestException (org.apache.pulsar.broker.web.RestException)5 List (java.util.List)4 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)4 PersistencePolicies (org.apache.pulsar.common.policies.data.PersistencePolicies)4