Package com.linkedin.d2.balancer.clients

Examples of com.linkedin.d2.balancer.clients.RewriteClient


      ZKFSLoadBalancer balancer = getBalancer();
      FutureCallback<None> callback = new FutureCallback<None>();
      balancer.start(callback);
      callback.get(30, TimeUnit.SECONDS);

      Directory dir = balancer.getDirectory();

      ZKConnection conn = new ZKConnection("localhost:" + PORT, 30000);
      conn.start();

      ZooKeeperPermanentStore<ServiceProperties> store =
              new ZooKeeperPermanentStore<ServiceProperties>(conn, new ServicePropertiesJsonSerializer(), ZKFSUtil.servicePath(BASE_PATH));
      callback = new FutureCallback<None>();
      store.start(callback);
      callback.get(30, TimeUnit.SECONDS);

      ServiceProperties props = new ServiceProperties(TEST_SERVICE_NAME, "someCluster", "/somePath", "someStrategy");
      store.put(TEST_SERVICE_NAME, props);

      FutureCallback<List<String>> serviceCallback = new FutureCallback<List<String>>();
      dir.getServiceNames(serviceCallback);

      Assert.assertEquals(serviceCallback.get(30, TimeUnit.SECONDS), Collections.singletonList(TEST_SERVICE_NAME));
    }
    finally
    {
View Full Code Here


      ZKFSLoadBalancer balancer = getBalancer();
      FutureCallback<None> callback = new FutureCallback<None>();
      balancer.start(callback);
      callback.get(30, TimeUnit.SECONDS);

      Directory dir = balancer.getDirectory();

      ZKConnection conn = new ZKConnection("localhost:" + PORT, 30000);
      conn.start();

      ZooKeeperPermanentStore<ClusterProperties> store =
              new ZooKeeperPermanentStore<ClusterProperties>(conn, new ClusterPropertiesJsonSerializer(),
                                                             ZKFSUtil.clusterPath(BASE_PATH));
      callback = new FutureCallback<None>();
      store.start(callback);
      callback.get(30, TimeUnit.SECONDS);

      ClusterProperties props = new ClusterProperties(TEST_CLUSTER_NAME);
      store.put(TEST_CLUSTER_NAME, props);

      FutureCallback<List<String>> clusterCallback = new FutureCallback<List<String>>();
      dir.getClusterNames(clusterCallback);

      Assert.assertEquals(clusterCallback.get(30, TimeUnit.SECONDS), Collections.singletonList(TEST_CLUSTER_NAME));
    }
    finally
    {
View Full Code Here

      ZKFSLoadBalancer balancer = getBalancer();
      FutureCallback<None> callback = new FutureCallback<None>();
      balancer.start(callback);
      callback.get(30, TimeUnit.SECONDS);

      Facilities facilities = balancer.getFacilities();
      TransportClientFactory factory = facilities.getClientFactory("http");
      Assert.assertNotNull(factory);
      Assert.assertTrue(factory instanceof HttpClientFactory);
    }
    finally
    {
View Full Code Here

        keys.add(ii);
      }

      for (int ii=0; ii<NUM_ITERATIONS; ++ii)
      {
        KeyMapper mapper = balancer.getKeyMapper();
        @SuppressWarnings("deprecation")
        Map<URI, Set<Integer>> batches = mapper.mapKeys(URI.create("d2://"+TEST_SERVICE_NAME), keys);
        Assert.assertEquals(batches.size(), 2);
        for (Map.Entry<URI, Set<Integer>> oneBatch : batches.entrySet())
        {
          Assert.assertTrue(oneBatch.getKey().toString().startsWith("http://test-host-"));
          Assert.assertTrue(keys.containsAll(oneBatch.getValue()));
View Full Code Here

                  _config.clientServicesConfig,
                  _config.d2ServicePath);

    final LoadBalancerWithFacilities loadBalancer = loadBalancerFactory.create(cfg);

    D2Client d2Client = new DynamicClient(loadBalancer, loadBalancer);

    /**
     * If we created default transport client factories, we need to shut them down when d2Client
     * is being shut down.
     */
 
View Full Code Here

      TrackerClient trackerClient = chooseTrackerClient(request, requestContext, serviceName, clusterName, cluster,
                                                        uriItem, uris, orderedStrategies, service);

      String clusterAndServiceUriString = trackerClient.getUri() + service.getPath();
      client = new RewriteClient(serviceName,
                                               URI.create(clusterAndServiceUriString),
                                               trackerClient);

      _serviceAvailableStats.inc();
    }
    else
    {
      _log.debug("service hint found, using generic client for target: " + targetService);

      TransportClient transportClient = _state.getClient(serviceName, targetService.getScheme());
      client = new RewriteClient(serviceName,targetService,transportClient);
    }
    return client;
  }
View Full Code Here

      expectedUris.add(expectedUri2);
      expectedUris.add(expectedUri3);

      for (int i = 0; i < 100; ++i)
      {
        RewriteClient client =
            (RewriteClient) loadBalancer.getClient(new URIRequest("d2://foo/52"),
                                                   new RequestContext());

        assertTrue(expectedUris.contains(client.getUri()));
        assertEquals(client.getUri().getScheme(), "http");
      }

      final CountDownLatch latch = new CountDownLatch(1);
      PropertyEventShutdownCallback callback = new PropertyEventShutdownCallback()
      {
View Full Code Here

      expectedUris.add(expectedUri3);

      for (int i = 0; i < 1000; ++i)
      {
        int ii = i % 100;
        RewriteClient client =
            (RewriteClient) loadBalancer.getClient(new URIRequest("d2://foo/id=" + ii), new RequestContext());
        String clientUri = client.getUri().toString();
        HashFunction<String[]> hashFunction = null;
        String[] str = new String[1];

        // test KeyMapper target host hint: request is always to target host regardless of what's in d2 URI and whether it's hash-based or range-based partitions
        RequestContext requestContextWithHint = new RequestContext();
        KeyMapper.TargetHostHints.setRequestContextTargetHost(requestContextWithHint, uri1);
        RewriteClient hintedClient1 = (RewriteClient)loadBalancer.getClient(new URIRequest("d2://foo/id=" + ii), requestContextWithHint);
        String hintedUri1 = hintedClient1.getUri().toString();
        Assert.assertEquals(hintedUri1, uri1.toString() + "/foo");
        RewriteClient hintedClient2 = (RewriteClient)loadBalancer.getClient(new URIRequest("d2://foo/action=purge-all"), requestContextWithHint);
        String hintedUri2 = hintedClient2.getUri().toString();
        Assert.assertEquals(hintedUri2, uri1.toString() + "/foo");
        // end test KeyMapper target host hint

        if (partitionMethod == 2)
        {
View Full Code Here

  public TrackerClient getClient(String serviceName, URI uri)
  {
    if (_partitionDescriptions.get(uri) != null)
    {
      // shorten the update interval to 20ms in order to increase the possibility of deadlock
      _trackerClients.putIfAbsent(uri, new TrackerClient(uri, _partitionDescriptions.get(uri), null, new SettableClock(), null, 20));

      return _trackerClients.get(uri);
    }
    return null;
  }
View Full Code Here

  @Override
  public TrackerClient getClient(String clusterName, URI uri)
  {
    Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
    partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1));
    return (getClient) ? new TrackerClient(uri, partitionDataMap, new TestClient()) : null;
  }
View Full Code Here

TOP

Related Classes of com.linkedin.d2.balancer.clients.RewriteClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.