Search in sources :

Example 11 with BundlesData

use of com.yahoo.pulsar.common.policies.data.BundlesData in project pulsar by yahoo.

the class NamespacesTest method testGetBundles.

@Test
public void testGetBundles() throws Exception {
    BundlesData bundle = new BundlesData(Lists.newArrayList("0x00000000", "0x80000000", "0xffffffff"));
    createBundledTestNamespaces(this.testProperty, this.testLocalCluster, "test-bundled-namespace-1", bundle);
    BundlesData responseData = namespaces.getBundlesData(testProperty, this.testLocalCluster, "test-bundled-namespace-1");
    assertEquals(responseData, bundle);
}
Also used : BundlesData(com.yahoo.pulsar.common.policies.data.BundlesData) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 12 with BundlesData

use of com.yahoo.pulsar.common.policies.data.BundlesData in project pulsar by yahoo.

the class Namespaces method validateBundlesData.

private BundlesData validateBundlesData(BundlesData initialBundles) {
    SortedSet<String> partitions = new TreeSet<String>();
    for (String partition : initialBundles.getBoundaries()) {
        Long partBoundary = Long.decode(partition);
        partitions.add(String.format("0x%08x", partBoundary));
    }
    if (partitions.size() != initialBundles.getBoundaries().size()) {
        log.debug("Input bundles included repeated partition points. Ignored.");
    }
    try {
        NamespaceBundleFactory.validateFullRange(partitions);
    } catch (IllegalArgumentException iae) {
        throw new RestException(Status.BAD_REQUEST, "Input bundles do not cover the whole hash range. first:" + partitions.first() + ", last:" + partitions.last());
    }
    List<String> bundles = Lists.newArrayList();
    bundles.addAll(partitions);
    return new BundlesData(bundles);
}
Also used : TreeSet(java.util.TreeSet) RestException(com.yahoo.pulsar.broker.web.RestException) BundlesData(com.yahoo.pulsar.common.policies.data.BundlesData)

Example 13 with BundlesData

use of com.yahoo.pulsar.common.policies.data.BundlesData in project pulsar by yahoo.

the class DiscoveryServiceWebTest method testRiderectUrlWithServerStarted.

@Test
public void testRiderectUrlWithServerStarted() throws Exception {
    // 1. start server
    int port = nextFreePort();
    ServiceConfig config = new ServiceConfig();
    config.setWebServicePort(port);
    ServerManager server = new ServerManager(config);
    DiscoveryZooKeeperClientFactoryImpl.zk = mockZookKeeper;
    Map<String, String> params = new TreeMap<>();
    params.put("zookeeperServers", "dummy-value");
    params.put("zookeeperClientFactoryClass", DiscoveryZooKeeperClientFactoryImpl.class.getName());
    server.addServlet("/", DiscoveryServiceServlet.class, params);
    server.start();
    // 2. create znode for each broker
    List<String> brokers = Lists.newArrayList("broker-1", "broker-2", "broker-3");
    brokers.stream().forEach(b -> {
        try {
            final String broker = b + ":15000";
            LoadReport report = new LoadReport("http://" + broker, null, null, null);
            String reportData = ObjectMapperFactory.getThreadLocal().writeValueAsString(report);
            ZkUtils.createFullPathOptimistic(mockZookKeeper, LOADBALANCE_BROKERS_ROOT + "/" + broker, reportData.getBytes(ZookeeperClientFactoryImpl.ENCODING_SCHEME), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        } catch (KeeperException.NodeExistsException ne) {
        } catch (KeeperException | InterruptedException e) {
            e.printStackTrace();
            fail("failed while creating broker znodes");
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            fail("failed while creating broker znodes");
        }
    });
    String serviceUrl = server.getServiceUri().toString();
    String requestUrl = serviceUrl + "admin/namespaces/p1/c1/n1";
    /**
         * 3. verify : every time when vip receives a request: it redirects to above brokers sequentially and client
         * must get unknown host exception with above brokers in a sequential manner.
         **/
    assertEquals(brokers, validateRequest(brokers, HttpMethod.PUT, requestUrl, new BundlesData(1)), "redirection failed");
    assertEquals(brokers, validateRequest(brokers, HttpMethod.GET, requestUrl, null), "redirection failed");
    assertEquals(brokers, validateRequest(brokers, HttpMethod.POST, requestUrl, new BundlesData(1)), "redirection failed");
    server.stop();
}
Also used : ServerManager(com.yahoo.pulsar.discovery.service.server.ServerManager) BundlesData(com.yahoo.pulsar.common.policies.data.BundlesData) TreeMap(java.util.TreeMap) ServiceConfig(com.yahoo.pulsar.discovery.service.server.ServiceConfig) LoadReport(com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.testng.annotations.Test)

Aggregations

BundlesData (com.yahoo.pulsar.common.policies.data.BundlesData)13 RestException (com.yahoo.pulsar.broker.web.RestException)10 Test (org.testng.annotations.Test)10 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)9 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)8 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)6 URL (java.net.URL)6 OwnershipCache (com.yahoo.pulsar.broker.namespace.OwnershipCache)4 Field (java.lang.reflect.Field)4 NamespaceBundles (com.yahoo.pulsar.common.naming.NamespaceBundles)3 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)2 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)2 PropertyAdmin (com.yahoo.pulsar.common.policies.data.PropertyAdmin)2 ClientErrorException (javax.ws.rs.ClientErrorException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 KeeperException (org.apache.zookeeper.KeeperException)2 Description (org.hamcrest.Description)2 Matcher (org.hamcrest.Matcher)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 NamespaceEphemeralData (com.yahoo.pulsar.broker.namespace.NamespaceEphemeralData)1