use of com.yahoo.pulsar.common.naming.NamespaceBundle in project pulsar by yahoo.
the class OwnershipCacheTest method testDisableOwnership.
@Test
public void testDisableOwnership() throws Exception {
OwnershipCache cache = new OwnershipCache(this.pulsar, bundleFactory);
NamespaceBundle testBundle = bundleFactory.getFullBundle(new NamespaceName("pulsar/test/ns-1"));
assertFalse(cache.getOwnerAsync(testBundle).get().isPresent());
NamespaceEphemeralData data1 = cache.tryAcquiringOwnership(testBundle).get();
assertTrue(!data1.isDisabled());
cache.disableOwnership(testBundle);
// force the next read to get directly from ZK
// localCache.ownerInfoCache().invalidate(ServiceUnitZkUtils.path(testNs));
data1 = cache.getOwnerAsync(testBundle).get().get();
assertTrue(data1.isDisabled());
}
use of com.yahoo.pulsar.common.naming.NamespaceBundle in project pulsar by yahoo.
the class OwnershipCacheTest method testGetOwnedServiceUnit.
@Test
public void testGetOwnedServiceUnit() throws Exception {
OwnershipCache cache = new OwnershipCache(this.pulsar, bundleFactory);
NamespaceName testNs = new NamespaceName("pulsar/test/ns-5");
NamespaceBundle testBundle = bundleFactory.getFullBundle(testNs);
// case 1: no one owns the namespace
assertFalse(cache.getOwnerAsync(testBundle).get().isPresent());
try {
checkNotNull(cache.getOwnedBundle(testBundle));
fail("Should have failed");
} catch (NullPointerException npe) {
// OK for not owned namespace
}
// case 2: someone else owns the namespace
ServiceUnitZkUtils.acquireNameSpace(zkCache.getZooKeeper(), ServiceUnitZkUtils.path(testBundle), new NamespaceEphemeralData("pulsar://otherhost:8881", "pulsar://otherhost:8884", "http://otherhost:8080", "https://otherhost:4443", false));
try {
checkNotNull(cache.getOwnedBundle(testBundle));
fail("Should have failed");
} catch (NullPointerException npe) {
// OK for not owned namespace
}
// try to acquire, which will load the read-only cache
NamespaceEphemeralData data1 = cache.tryAcquiringOwnership(testBundle).get();
assertEquals(data1.getNativeUrl(), "pulsar://otherhost:8881");
assertEquals(data1.getNativeUrlTls(), "pulsar://otherhost:8884");
assertTrue(!data1.isDisabled());
try {
checkNotNull(cache.getOwnedBundle(testBundle));
fail("Should have failed");
} catch (NullPointerException npe) {
// OK for not owned namespace
}
// case 3: this broker owns the namespace
// delete the ephemeral node by others
zkCache.getZooKeeper().delete(ServiceUnitZkUtils.path(testBundle), -1);
// force to read directly from ZK
localCache.ownerInfoCache().invalidate(ServiceUnitZkUtils.path(testBundle));
data1 = cache.tryAcquiringOwnership(testBundle).get();
assertEquals(data1.getNativeUrl(), selfBrokerUrl);
assertTrue(!data1.isDisabled());
assertNotNull(cache.getOwnedBundle(testBundle));
}
use of com.yahoo.pulsar.common.naming.NamespaceBundle in project pulsar by yahoo.
the class OwnershipCacheTest method testRemoveOwnership.
@Test
public void testRemoveOwnership() throws Exception {
OwnershipCache cache = new OwnershipCache(this.pulsar, bundleFactory);
NamespaceName testNs = new NamespaceName("pulsar/test/ns-7");
NamespaceBundle bundle = bundleFactory.getFullBundle(testNs);
// case 1: no one owns the namespace
assertFalse(cache.getOwnerAsync(bundle).get().isPresent());
cache.removeOwnership(bundle).get();
assertTrue(cache.getOwnedBundles().isEmpty());
// case 2: this broker owns the namespace
NamespaceEphemeralData data1 = cache.tryAcquiringOwnership(bundle).get();
assertEquals(data1.getNativeUrl(), selfBrokerUrl);
assertTrue(!data1.isDisabled());
assertTrue(cache.getOwnedBundles().size() == 1);
cache.removeOwnership(bundle);
Thread.sleep(500);
assertTrue(cache.getOwnedBundles().isEmpty());
Thread.sleep(500);
try {
zkCache.getZooKeeper().getData(ServiceUnitZkUtils.path(bundle), null, null);
fail("Should have failed");
} catch (NoNodeException nne) {
// OK
}
}
use of com.yahoo.pulsar.common.naming.NamespaceBundle in project pulsar by yahoo.
the class NamespaceService method unloadSLANamespace.
public void unloadSLANamespace() throws Exception {
PulsarAdmin adminClient = null;
String namespaceName = getSLAMonitorNamespace(host, config);
if (LOG.isDebugEnabled()) {
LOG.debug("Trying to unload SLA namespace {}", namespaceName);
}
NamespaceBundle nsFullBundle = getFullBundle(new NamespaceName(namespaceName));
if (!getOwner(nsFullBundle).isPresent()) {
// No one owns the namespace so no point trying to unload it
return;
}
adminClient = pulsar.getAdminClient();
adminClient.namespaces().unload(namespaceName);
LOG.debug("Namespace {} unloaded successfully", namespaceName);
}
use of com.yahoo.pulsar.common.naming.NamespaceBundle in project pulsar by yahoo.
the class PulsarWebResource method validateNamespaceBundleOwnership.
protected NamespaceBundle validateNamespaceBundleOwnership(NamespaceName fqnn, BundlesData bundles, String bundleRange, boolean authoritative, boolean readOnly) {
try {
NamespaceBundle nsBundle = validateNamespaceBundleRange(fqnn, bundles, bundleRange);
validateBundleOwnership(nsBundle, authoritative, readOnly);
return nsBundle;
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
log.error("[{}] Failed to validate namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
throw new RestException(e);
}
}
Aggregations