use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class NamespacesImpl method unloadNamespaceBundle.
@Override
public void unloadNamespaceBundle(String namespace, String bundle) throws PulsarAdminException {
try {
NamespaceName ns = new NamespaceName(namespace);
request(namespaces.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path(bundle).path("unload")).put(Entity.entity("", MediaType.APPLICATION_JSON), ErrorData.class);
} catch (Exception e) {
throw getApiException(e);
}
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class AdminApiTest method testNamespaceBundleUnload.
@Test(dataProvider = "numBundles")
public void testNamespaceBundleUnload(Integer numBundles) throws Exception {
admin.namespaces().createNamespace("prop-xyz/use/ns1-bundles", numBundles);
assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1-bundles"), Lists.newArrayList());
// Force to create a destination
publishMessagesOnPersistentTopic("persistent://prop-xyz/use/ns1-bundles/ds2", 0);
assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1-bundles"), Lists.newArrayList("persistent://prop-xyz/use/ns1-bundles/ds2"));
// create consumer and subscription
ConsumerConfiguration conf = new ConsumerConfiguration();
Consumer consumer = pulsarClient.subscribe("persistent://prop-xyz/use/ns1-bundles/ds2", "my-sub", conf);
assertEquals(admin.persistentTopics().getSubscriptions("persistent://prop-xyz/use/ns1-bundles/ds2"), Lists.newArrayList("my-sub"));
// Create producer
Producer producer = pulsarClient.createProducer("persistent://prop-xyz/use/ns1-bundles/ds2");
for (int i = 0; i < 10; i++) {
String message = "message-" + i;
producer.send(message.getBytes());
}
NamespaceBundle bundle = (NamespaceBundle) pulsar.getNamespaceService().getBundle(DestinationName.get("persistent://prop-xyz/use/ns1-bundles/ds2"));
consumer.close();
producer.close();
admin.namespaces().unloadNamespaceBundle("prop-xyz/use/ns1-bundles", bundle.getBundleRange());
// check that no one owns the namespace bundle
assertFalse(pulsar.getNamespaceService().isServiceUnitOwned(bundle));
assertFalse(otherPulsar.getNamespaceService().isServiceUnitOwned(bundle));
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-bundles/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-bundles/ds2", "my-sub");
admin.persistentTopics().delete("persistent://prop-xyz/use/ns1-bundles/ds2");
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class AdminApiTest method clusters.
@Test
public void clusters() throws Exception {
admin.clusters().createCluster("usw", new ClusterData("http://broker.messaging.use.example.com" + ":" + BROKER_WEBSERVICE_PORT));
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
assertEquals(admin.clusters().getCluster("use"), new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
admin.clusters().updateCluster("usw", new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT));
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
assertEquals(admin.clusters().getCluster("usw"), new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT));
admin.clusters().updateCluster("usw", new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT, "https://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT_TLS));
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
assertEquals(admin.clusters().getCluster("usw"), new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT, "https://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT_TLS));
admin.clusters().deleteCluster("usw");
Thread.sleep(300);
assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use"));
admin.namespaces().deleteNamespace("prop-xyz/use/ns1");
admin.clusters().deleteCluster("use");
assertEquals(admin.clusters().getClusters(), Lists.newArrayList());
// Check name validation
try {
admin.clusters().createCluster("bf!", new ClusterData("http://dummy.messaging.example.com"));
fail("should have failed");
} catch (PulsarAdminException e) {
assertTrue(e instanceof PreconditionFailedException);
}
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class Namespaces method unsubscribeNamespace.
@POST
@Path("/{property}/{cluster}/{namespace}/unsubscribe/{subscription}")
@ApiOperation(value = "Unsubscribes the given subscription on all destinations on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void unsubscribeNamespace(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("subscription") String subscription, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
validateAdminAccessOnProperty(property);
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
try {
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName);
Exception exception = null;
for (NamespaceBundle nsBundle : bundles.getBundles()) {
try {
// check if the bundle is owned by any broker, if not then there are no subscriptions
if (pulsar().getNamespaceService().getOwner(nsBundle).isPresent()) {
// TODO: make this admin call asynchronous
pulsar().getAdminClient().namespaces().unsubscribeNamespaceBundle(nsName.toString(), nsBundle.getBundleRange(), subscription);
}
} catch (Exception e) {
if (exception == null) {
exception = e;
}
}
}
if (exception != null) {
if (exception instanceof PulsarAdminException) {
throw new RestException((PulsarAdminException) exception);
} else {
throw new RestException(exception.getCause());
}
}
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
throw new RestException(e);
}
log.info("[{}] Successfully unsubscribed {} on all the bundles for namespace {}", clientAppId(), subscription, nsName.toString());
}
use of com.yahoo.pulsar.client.admin.PulsarAdminException in project pulsar by yahoo.
the class Namespaces method clearNamespaceBacklogForSubscription.
@POST
@Path("/{property}/{cluster}/{namespace}/clearBacklog/{subscription}")
@ApiOperation(value = "Clear backlog for a given subscription on all destinations on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public void clearNamespaceBacklogForSubscription(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("subscription") String subscription, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
validateAdminAccessOnProperty(property);
NamespaceName nsName = new NamespaceName(property, cluster, namespace);
try {
NamespaceBundles bundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(nsName);
Exception exception = null;
for (NamespaceBundle nsBundle : bundles.getBundles()) {
try {
// clear
if (pulsar().getNamespaceService().getOwner(nsBundle).isPresent()) {
// TODO: make this admin call asynchronous
pulsar().getAdminClient().namespaces().clearNamespaceBundleBacklogForSubscription(nsName.toString(), nsBundle.getBundleRange(), subscription);
}
} catch (Exception e) {
if (exception == null) {
exception = e;
}
}
}
if (exception != null) {
if (exception instanceof PulsarAdminException) {
throw new RestException((PulsarAdminException) exception);
} else {
throw new RestException(exception.getCause());
}
}
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
throw new RestException(e);
}
log.info("[{}] Successfully cleared backlog for subscription {} on all the bundles for namespace {}", clientAppId(), subscription, nsName.toString());
}
Aggregations