Search in sources :

Example 81 with NamespaceName

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());
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Test(org.testng.annotations.Test)

Example 82 with NamespaceName

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));
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) Test(org.testng.annotations.Test)

Example 83 with NamespaceName

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
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Test(org.testng.annotations.Test)

Example 84 with NamespaceName

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);
    }
}
Also used : ResourceUnit(com.yahoo.pulsar.broker.loadbalance.ResourceUnit) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) MalformedURLException(java.net.MalformedURLException) Set(java.util.Set) HashSet(java.util.HashSet) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) URL(java.net.URL)

Example 85 with NamespaceName

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);
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin)

Aggregations

NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)93 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)41 Test (org.testng.annotations.Test)40 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)38 RestException (com.yahoo.pulsar.broker.web.RestException)25 Policies (com.yahoo.pulsar.common.policies.data.Policies)18 ApiOperation (io.swagger.annotations.ApiOperation)17 ApiResponses (io.swagger.annotations.ApiResponses)17 Path (javax.ws.rs.Path)17 KeeperException (org.apache.zookeeper.KeeperException)17 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)16 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)14 RetentionPolicies (com.yahoo.pulsar.common.policies.data.RetentionPolicies)14 NamespaceBundles (com.yahoo.pulsar.common.naming.NamespaceBundles)13 Field (java.lang.reflect.Field)13 URL (java.net.URL)13 WebApplicationException (javax.ws.rs.WebApplicationException)13 PersistencePolicies (com.yahoo.pulsar.common.policies.data.PersistencePolicies)12 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)10 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)9