use of com.yahoo.pulsar.common.naming.NamespaceName 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.NamespaceName 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.NamespaceName 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.NamespaceName in project pulsar by yahoo.
the class SimpleLoadManagerImpl method getFinalCandidates.
private Multimap<Long, ResourceUnit> getFinalCandidates(ServiceUnitId serviceUnit, Map<Long, Set<ResourceUnit>> availableBrokers) {
// need multimap or at least set of RUs
Multimap<Long, ResourceUnit> matchedPrimaries = TreeMultimap.create();
Multimap<Long, ResourceUnit> matchedShared = TreeMultimap.create();
NamespaceName namespace = serviceUnit.getNamespaceObject();
boolean isIsolationPoliciesPresent = policies.IsIsolationPoliciesPresent(namespace);
if (isIsolationPoliciesPresent) {
log.debug("Isolation Policies Present for namespace - [{}]", namespace.toString());
}
for (Map.Entry<Long, Set<ResourceUnit>> entry : availableBrokers.entrySet()) {
for (ResourceUnit ru : entry.getValue()) {
log.debug("Considering Resource Unit [{}] with Rank [{}] for serviceUnit [{}]", ru.getResourceId(), entry.getKey(), serviceUnit);
URL brokerUrl = null;
try {
brokerUrl = new URL(String.format(ru.getResourceId()));
} catch (MalformedURLException e) {
log.error("Unable to parse brokerUrl from ResourceUnitId - [{}]", e);
continue;
}
// todo: in future check if the resource unit has resources to take the namespace
if (isIsolationPoliciesPresent) {
// note: serviceUnitID is namespace name and ResourceID is brokerName
if (policies.isPrimaryBroker(namespace, brokerUrl.getHost())) {
matchedPrimaries.put(entry.getKey(), ru);
if (log.isDebugEnabled()) {
log.debug("Added Primary Broker - [{}] as possible Candidates for" + " namespace - [{}] with policies", brokerUrl.getHost(), namespace.toString());
}
} else if (policies.isSharedBroker(brokerUrl.getHost())) {
matchedShared.put(entry.getKey(), ru);
if (log.isDebugEnabled()) {
log.debug("Added Shared Broker - [{}] as possible " + "Candidates for namespace - [{}] with policies", brokerUrl.getHost(), namespace.toString());
}
} else {
if (log.isDebugEnabled()) {
log.debug("Skipping Broker - [{}] not primary broker and not shared" + " for namespace - [{}] ", brokerUrl.getHost(), namespace.toString());
}
}
} else {
if (policies.isSharedBroker(brokerUrl.getHost())) {
matchedShared.put(entry.getKey(), ru);
log.debug("Added Shared Broker - [{}] as possible Candidates for namespace - [{}]", brokerUrl.getHost(), namespace.toString());
}
}
}
}
if (isIsolationPoliciesPresent) {
return getFinalCandidatesWithPolicy(namespace, matchedPrimaries, matchedShared);
} else {
log.debug("Policies not present for namespace - [{}] so only " + "considering shared [{}] brokers for possible owner", namespace.toString(), matchedShared.size());
return getFinalCandidatesNoPolicy(matchedShared);
}
}
use of com.yahoo.pulsar.common.naming.NamespaceName 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);
}
Aggregations