Search in sources :

Example 1 with PulsarAdminException

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

the class PulsarStandaloneStarter method start.

void start() throws Exception {
    if (config == null) {
        System.exit(1);
    }
    log.debug("--- setup PulsarStandaloneStarter ---");
    if (!onlyBroker) {
        // Start LocalBookKeeper
        bkEnsemble = new LocalBookkeeperEnsemble(numOfBk, zkPort, bkPort, zkDir, bkDir, wipeData, config.getAdvertisedAddress());
        bkEnsemble.startStandalone();
    }
    if (noBroker) {
        return;
    }
    // load aspectj-weaver agent for instrumentation
    AgentLoader.loadAgentClass(Agent.class.getName(), null);
    // initialize the functions worker
    if (!noFunctionsWorker) {
        WorkerConfig workerConfig;
        if (isBlank(fnWorkerConfigFile)) {
            workerConfig = new WorkerConfig();
        } else {
            workerConfig = WorkerConfig.load(fnWorkerConfigFile);
        }
        // worker talks to local broker
        workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePort());
        workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + config.getWebServicePort());
        String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
        workerConfig.setWorkerHostname(hostname);
        workerConfig.setWorkerId("c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort());
        fnWorkerService = new WorkerService(workerConfig);
    }
    // Start Broker
    broker = new PulsarService(config, Optional.ofNullable(fnWorkerService));
    broker.start();
    // Create a sample namespace
    URL webServiceUrl = new URL(String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort()));
    final String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(), config.getBrokerServicePort());
    admin = new PulsarAdmin(webServiceUrl, config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters());
    final String property = "sample";
    final String cluster = config.getClusterName();
    final String globalCluster = "global";
    final String namespace = property + "/" + cluster + "/ns1";
    try {
        ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, /* serviceUrlTls */
        brokerServiceUrl, null);
        if (!admin.clusters().getClusters().contains(cluster)) {
            admin.clusters().createCluster(cluster, clusterData);
        } else {
            admin.clusters().updateCluster(cluster, clusterData);
        }
        // Create marker for "global" cluster
        if (!admin.clusters().getClusters().contains(globalCluster)) {
            admin.clusters().createCluster(globalCluster, new ClusterData(null, null));
        }
        if (!admin.properties().getProperties().contains(property)) {
            admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList(config.getSuperUserRoles()), Sets.newHashSet(cluster)));
        }
        if (!admin.namespaces().getNamespaces(property).contains(namespace)) {
            admin.namespaces().createNamespace(namespace);
        }
    } catch (PulsarAdminException e) {
        log.info(e.getMessage());
    }
    if (null != fnWorkerService) {
        fnWorkerService.start();
    }
    log.debug("--- setup completed ---");
}
Also used : Agent(org.aspectj.weaver.loadtime.Agent) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) WorkerService(org.apache.pulsar.functions.worker.WorkerService) URL(java.net.URL)

Example 2 with PulsarAdminException

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

the class PulsarClientToolTest method testInitialzation.

@Test(timeOut = 10000)
public void testInitialzation() throws MalformedURLException, InterruptedException, ExecutionException, PulsarAdminException {
    Properties properties = new Properties();
    properties.setProperty("serviceUrl", brokerUrl.toString());
    properties.setProperty("useTls", "false");
    admin.properties().createProperty("property", new PropertyAdmin());
    String topicName = "persistent://property/ns/topic-scale-ns-0/topic";
    int numberOfMessages = 10;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    CompletableFuture<Void> future = new CompletableFuture<Void>();
    executor.execute(() -> {
        PulsarClientTool pulsarClientToolConsumer;
        try {
            pulsarClientToolConsumer = new PulsarClientTool(properties);
            String[] args = { "consume", "-t", "Exclusive", "-s", "sub-name", "-n", Integer.toString(numberOfMessages), "--hex", "-r", "30", topicName };
            Assert.assertEquals(pulsarClientToolConsumer.run(args), 0);
            future.complete(null);
        } catch (Throwable t) {
            future.completeExceptionally(t);
        }
    });
    // Make sure subscription has been created
    while (true) {
        try {
            List<String> subscriptions = admin.persistentTopics().getSubscriptions(topicName);
            if (subscriptions.size() == 1) {
                break;
            }
        } catch (Exception e) {
        }
        Thread.sleep(200);
    }
    PulsarClientTool pulsarClientToolProducer = new PulsarClientTool(properties);
    String[] args = { "produce", "--messages", "Have a nice day", "-n", Integer.toString(numberOfMessages), "-r", "20", topicName };
    Assert.assertEquals(pulsarClientToolProducer.run(args), 0);
    future.get();
    executor.shutdown();
}
Also used : Properties(java.util.Properties) MalformedURLException(java.net.MalformedURLException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ExecutionException(java.util.concurrent.ExecutionException) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) ExecutorService(java.util.concurrent.ExecutorService) PulsarClientTool(org.apache.pulsar.client.cli.PulsarClientTool) Test(org.testng.annotations.Test)

Example 3 with PulsarAdminException

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

the class NamespacesImpl method removeBacklogQuota.

@Override
public void removeBacklogQuota(String namespace) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "backlogQuota");
        request(path.queryParam("backlogQuotaType", BacklogQuotaType.destination_storage.toString())).delete(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 4 with PulsarAdminException

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

the class NamespacesImpl method getNamespaceMessageTTL.

@Override
public int getNamespaceMessageTTL(String namespace) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "messageTTL");
        return request(path).get(new GenericType<Integer>() {
        });
    } 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 5 with PulsarAdminException

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

the class NamespacesImpl method setMaxConsumersPerSubscription.

@Override
public void setMaxConsumersPerSubscription(String namespace, int maxConsumersPerSubscription) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "maxConsumersPerSubscription");
        request(path).post(Entity.entity(maxConsumersPerSubscription, 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)

Aggregations

PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)90 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 NotFoundException (org.apache.pulsar.client.admin.PulsarAdminException.NotFoundException)13 WebApplicationException (javax.ws.rs.WebApplicationException)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