Search in sources :

Example 76 with PulsarAdminException

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

the class NamespacesImpl method clearNamespaceBundleBacklogForSubscription.

@Override
public void clearNamespaceBundleBacklogForSubscription(String namespace, String bundle, String subscription) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, bundle, "clearBacklog", subscription);
        request(path).post(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class);
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) WebTarget(javax.ws.rs.client.WebTarget) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 77 with PulsarAdminException

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

the class PersistentTopicE2ETest method testTopicDeleteWithDisconnectedSubscription.

@Test
public void testTopicDeleteWithDisconnectedSubscription() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic8";
    final String subName = "sub1";
    // 1. client connect
    Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName).subscriptionName(subName).subscribe();
    PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
    PersistentSubscription subRef = topicRef.getSubscription(subName);
    assertNotNull(topicRef);
    assertNotNull(subRef);
    assertTrue(subRef.getDispatcher().isConsumerConnected());
    // 2. client disconnect
    consumer.close();
    assertFalse(subRef.getDispatcher().isConsumerConnected());
    // 3. delete topic
    admin.persistentTopics().delete(topicName);
    try {
        admin.persistentTopics().getStats(topicName);
    } catch (PulsarAdminException e) {
    // ok
    }
}
Also used : PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) PersistentSubscription(org.apache.pulsar.broker.service.persistent.PersistentSubscription) Test(org.testng.annotations.Test)

Example 78 with PulsarAdminException

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

the class AuthenticatedProducerConsumerTest method testInternalServerExceptionOnLookup.

/**
 * verifies that topicLookup/PartitionMetadataLookup gives InternalServerError(500) instead 401(auth_failed) on
 * unknown-exception failure
 *
 * @throws Exception
 */
@Test
public void testInternalServerExceptionOnLookup() throws Exception {
    log.info("-- Starting {} test --", methodName);
    Map<String, String> authParams = new HashMap<>();
    authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    internalSetup(authTls);
    admin.clusters().createCluster("use", new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), "pulsar://localhost:" + BROKER_PORT, "pulsar+ssl://localhost:" + BROKER_PORT_TLS));
    admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    String namespace = "my-property/use/my-ns";
    admin.namespaces().createNamespace(namespace);
    String topic = "persistent://" + namespace + "1/topic1";
    // this will cause NPE and it should throw 500
    mockZookKeeper.shutdown();
    pulsar.getConfiguration().setSuperUserRoles(Sets.newHashSet());
    try {
        admin.persistentTopics().getPartitionedTopicMetadata(topic);
    } catch (PulsarAdminException e) {
        Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
    }
    try {
        admin.lookups().lookupTopic(topic);
    } catch (PulsarAdminException e) {
        Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
    }
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 79 with PulsarAdminException

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

the class AuthenticatedProducerConsumerTest method testAuthenticationFilterNegative.

/**
 * Verifies: on 500 server error, broker invalidates session and client receives 500 correctly.
 *
 * @throws Exception
 */
@Test
public void testAuthenticationFilterNegative() throws Exception {
    log.info("-- Starting {} test --", methodName);
    Map<String, String> authParams = new HashMap<>();
    authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    internalSetup(authTls);
    final String cluster = "use";
    final ClusterData clusterData = new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), "pulsar://localhost:" + BROKER_PORT, "pulsar+ssl://localhost:" + BROKER_PORT_TLS);
    // this will cause NPE and it should throw 500
    doReturn(null).when(pulsar).getGlobalZkCache();
    try {
        admin.clusters().createCluster(cluster, clusterData);
    } catch (PulsarAdminException e) {
        Assert.assertTrue(e.getCause() instanceof InternalServerErrorException);
    }
    log.info("-- Exiting {} test --", methodName);
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 80 with PulsarAdminException

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

the class PulsarBrokerStatsClientTest method testServiceException.

@Test
public void testServiceException() throws Exception {
    URL url = new URL("http://localhost:15000");
    PulsarAdmin admin = new PulsarAdmin(url, (Authentication) null);
    BrokerStatsImpl client = (BrokerStatsImpl) spy(admin.brokerStats());
    try {
        client.getLoadReport();
    } catch (PulsarAdminException e) {
    // Ok
    }
    try {
        client.getPendingBookieOpsStats();
    } catch (PulsarAdminException e) {
    // Ok
    }
    try {
        client.getBrokerResourceAvailability("prop/cluster/ns");
    } catch (PulsarAdminException e) {
    // Ok
    }
    assertTrue(client.getApiException(new ClientErrorException(403)) instanceof NotAuthorizedException);
    assertTrue(client.getApiException(new ClientErrorException(404)) instanceof NotFoundException);
    assertTrue(client.getApiException(new ClientErrorException(409)) instanceof ConflictException);
    assertTrue(client.getApiException(new ClientErrorException(412)) instanceof PreconditionFailedException);
    assertTrue(client.getApiException(new ClientErrorException(400)) instanceof PulsarAdminException);
    assertTrue(client.getApiException(new ServerErrorException(500)) instanceof ServerSideErrorException);
    assertTrue(client.getApiException(new ServerErrorException(503)) instanceof PulsarAdminException);
    log.info("Client: ", client);
    admin.close();
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) BrokerStatsImpl(org.apache.pulsar.client.admin.internal.BrokerStatsImpl) ConflictException(org.apache.pulsar.client.admin.PulsarAdminException.ConflictException) ServerSideErrorException(org.apache.pulsar.client.admin.PulsarAdminException.ServerSideErrorException) ClientErrorException(javax.ws.rs.ClientErrorException) NotFoundException(org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) NotAuthorizedException(org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException) ServerErrorException(javax.ws.rs.ServerErrorException) URL(java.net.URL) Test(org.testng.annotations.Test)

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