Search in sources :

Example 41 with PulsarAdminException

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

the class NamespacesImpl method setDeduplicationStatus.

@Override
public void setDeduplicationStatus(String namespace, boolean enableDeduplication) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "deduplication");
        request(path).post(Entity.entity(enableDeduplication, 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 42 with PulsarAdminException

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

the class NamespacesImpl method getTopics.

@Override
public List<String> getTopics(String namespace) throws PulsarAdminException {
    try {
        NamespaceName ns = NamespaceName.get(namespace);
        WebTarget path = namespacePath(ns, "destinations");
        return request(path).get(new GenericType<List<String>>() {
        });
    } catch (Exception e) {
        throw getApiException(e);
    }
}
Also used : NamespaceName(org.apache.pulsar.common.naming.NamespaceName) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 43 with PulsarAdminException

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

the class CmdBase method run.

public boolean run(String[] args) {
    try {
        jcommander.parse(args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.err.println();
        jcommander.usage();
        return false;
    }
    String cmd = jcommander.getParsedCommand();
    if (cmd == null) {
        jcommander.usage();
        return false;
    } else {
        JCommander obj = jcommander.getCommands().get(cmd);
        CliCommand cmdObj = (CliCommand) obj.getObjects().get(0);
        try {
            cmdObj.run();
            return true;
        } catch (ParameterException e) {
            System.err.println(e.getMessage());
            System.err.println();
            jcommander.usage();
            return false;
        } catch (ConnectException e) {
            System.err.println(e.getMessage());
            System.err.println();
            System.err.println("Error connecting to: " + admin.getServiceUrl());
            return false;
        } catch (PulsarAdminException e) {
            System.err.println(e.getHttpError());
            System.err.println();
            System.err.println("Reason: " + e.getMessage());
            return false;
        } catch (Exception e) {
            System.err.println("Got exception: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }
}
Also used : JCommander(com.beust.jcommander.JCommander) ParameterException(com.beust.jcommander.ParameterException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ConnectException(org.apache.pulsar.client.admin.PulsarAdminException.ConnectException) ParameterException(com.beust.jcommander.ParameterException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ConnectException(org.apache.pulsar.client.admin.PulsarAdminException.ConnectException)

Example 44 with PulsarAdminException

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

the class MembershipManager method getCurrentMembership.

public List<WorkerInfo> getCurrentMembership() {
    List<WorkerInfo> workerIds = new LinkedList<>();
    PersistentTopicStats persistentTopicStats = null;
    PulsarAdmin pulsarAdmin = this.getPulsarAdminClient();
    try {
        persistentTopicStats = pulsarAdmin.persistentTopics().getStats(this.workerConfig.getClusterCoordinationTopic());
    } catch (PulsarAdminException e) {
        log.error("Failed to get status of coordinate topic {}", this.workerConfig.getClusterCoordinationTopic(), e);
        throw new RuntimeException(e);
    }
    for (ConsumerStats consumerStats : persistentTopicStats.subscriptions.get(COORDINATION_TOPIC_SUBSCRIPTION).consumers) {
        WorkerInfo workerInfo = WorkerInfo.parseFrom(consumerStats.metadata.get(WORKER_IDENTIFIER));
        workerIds.add(workerInfo);
    }
    return workerIds;
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) ConsumerStats(org.apache.pulsar.common.policies.data.ConsumerStats) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) PersistentTopicStats(org.apache.pulsar.common.policies.data.PersistentTopicStats) LinkedList(java.util.LinkedList)

Example 45 with PulsarAdminException

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

the class FunctionMetadataSetup method setupFunctionMetadata.

/**
 * Setup function metadata.
 *
 * @param workerConfig worker config
 * @return dlog uri for store function jars
 * @throws InterruptedException interrupted at setting up metadata
 * @throws PulsarAdminException when encountering exception on pulsar admin operation
 * @throws IOException when create dlog namespace for storing function jars.
 */
public static URI setupFunctionMetadata(WorkerConfig workerConfig) throws InterruptedException, PulsarAdminException, IOException {
    // initializing pulsar functions namespace
    PulsarAdmin admin = Utils.getPulsarAdminClient(workerConfig.getPulsarWebServiceUrl());
    InternalConfigurationData internalConf;
    // make sure pulsar broker is up
    log.info("Checking if pulsar service at {} is up...", workerConfig.getPulsarWebServiceUrl());
    int maxRetries = workerConfig.getInitialBrokerReconnectMaxRetries();
    int retries = 0;
    while (true) {
        try {
            admin.clusters().getClusters();
            break;
        } catch (PulsarAdminException e) {
            log.warn("Failed to retrieve clusters from pulsar service", e);
            log.warn("Retry to connect to Pulsar service at {}", workerConfig.getPulsarWebServiceUrl());
            if (retries >= maxRetries) {
                log.error("Failed to connect to Pulsar service at {} after {} attempts", workerConfig.getPulsarFunctionsNamespace(), maxRetries);
                throw e;
            }
            retries++;
            Thread.sleep(1000);
        }
    }
    // getting namespace policy
    log.info("Initializing Pulsar Functions namespace...");
    try {
        try {
            admin.namespaces().getPolicies(workerConfig.getPulsarFunctionsNamespace());
        } catch (PulsarAdminException e) {
            if (e.getStatusCode() == Response.Status.NOT_FOUND.getStatusCode()) {
                // if not found than create
                try {
                    admin.namespaces().createNamespace(workerConfig.getPulsarFunctionsNamespace());
                } catch (PulsarAdminException e1) {
                    // prevent race condition with other workers starting up
                    if (e1.getStatusCode() != Response.Status.CONFLICT.getStatusCode()) {
                        log.error("Failed to create namespace {} for pulsar functions", workerConfig.getPulsarFunctionsNamespace(), e1);
                        throw e1;
                    }
                }
                try {
                    admin.namespaces().setRetention(workerConfig.getPulsarFunctionsNamespace(), new RetentionPolicies(Integer.MAX_VALUE, Integer.MAX_VALUE));
                } catch (PulsarAdminException e1) {
                    log.error("Failed to set retention policy for pulsar functions namespace", e);
                    throw new RuntimeException(e1);
                }
            } else {
                log.error("Failed to get retention policy for pulsar function namespace {}", workerConfig.getPulsarFunctionsNamespace(), e);
                throw e;
            }
        }
        try {
            internalConf = admin.brokers().getInternalConfigurationData();
        } catch (PulsarAdminException e) {
            log.error("Failed to retrieve broker internal configuration", e);
            throw e;
        }
    } finally {
        admin.close();
    }
    // TODO: move this as part of pulsar cluster initialization later
    try {
        return Utils.initializeDlogNamespace(internalConf.getZookeeperServers(), internalConf.getLedgersRootPath());
    } catch (IOException ioe) {
        log.error("Failed to initialize dlog namespace at zookeeper {} for storing function packages", internalConf.getZookeeperServers(), ioe);
        throw ioe;
    }
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) InternalConfigurationData(org.apache.pulsar.common.conf.InternalConfigurationData) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) IOException(java.io.IOException)

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