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);
}
}
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);
}
}
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;
}
}
}
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;
}
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;
}
}
Aggregations