Search in sources :

Example 41 with NamespaceBundle

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

Example 42 with NamespaceBundle

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

Example 43 with NamespaceBundle

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
    }
}
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 44 with NamespaceBundle

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

Example 45 with NamespaceBundle

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);
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) WebApplicationException(javax.ws.rs.WebApplicationException) KeeperException(org.apache.zookeeper.KeeperException) ExecutionException(java.util.concurrent.ExecutionException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)49 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)40 Test (org.testng.annotations.Test)27 KeeperException (org.apache.zookeeper.KeeperException)19 NamespaceBundles (com.yahoo.pulsar.common.naming.NamespaceBundles)14 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)13 RestException (com.yahoo.pulsar.broker.web.RestException)13 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)11 Policies (com.yahoo.pulsar.common.policies.data.Policies)11 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)10 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)9 WebApplicationException (javax.ws.rs.WebApplicationException)9 Field (java.lang.reflect.Field)8 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)8 ServiceUnitNotReadyException (com.yahoo.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException)7 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)7 PersistencePolicies (com.yahoo.pulsar.common.policies.data.PersistencePolicies)7 RetentionPolicies (com.yahoo.pulsar.common.policies.data.RetentionPolicies)7