Package com.linkedin.d2.balancer.clients

Examples of com.linkedin.d2.balancer.clients.TrackerClient$PartitionState


    assertNull(_state.getStrategy("service-1", "http"));

    // Put degrader into the strategyList, it it not one of the supported strategies in
    // this strategyFactory, so we should not get a strategy back for http.
    strategyList.add("degrader");
    _serviceRegistry.put("service-1", new ServiceProperties("service-1",
                                                            "cluster-1",
                                                            "/test",
                                                            "unusedInThisConstructor",
                                                            strategyList,
                                                            Collections.<String, Object>emptyMap(),
                                                            null,
                                                            null,
                                                            schemes,
                                                            null));
    _clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));
    assertNull(_state.getStrategy("service-1", "http"));

    // put the random strategy into the Strategy list, it is one of the supported strategies in the
    // strategyFactory for this unit test
    strategyList.clear();
    strategyList.add("random");
    _serviceRegistry.put("service-1", new ServiceProperties("service-1",
                                                            "cluster-1",
                                                            "/test",
                                                            "unusedInThisConstructor",
                                                            strategyList,
                                                            Collections.<String, Object>emptyMap(),
                                                            null,
                                                            null,
                                                            schemes,
                                                            null));

    _clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));

    LoadBalancerStrategy strategy = _state.getStrategy("service-1", "http");

    assertNotNull(strategy);
    assertTrue(strategy instanceof RandomLoadBalancerStrategy);

    // now add the degraderV3 strategy into the Strategy list
    strategyList.addFirst("degraderV3");
    _serviceRegistry.put("service-1", new ServiceProperties("service-1",
                                                            "cluster-1",
                                                            "/test",
                                                            "unusedInThisConstructor",
                                                            strategyList,
                                                            Collections.<String, Object>emptyMap(),
View Full Code Here


    assertNull(_state.getStrategy("service-1", "http"));

    // Use the _clusterRegistry.put to populate the _state.clusterProperties, used by
    // _state.refreshServiceStrategies
    _clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));
    _serviceRegistry.put("service-1", new ServiceProperties("service-1",
                                                              "cluster-1",
                                                              "/test",
                                                              "unusedInThisConstructor",
                                                              strategyList,
                                                              Collections.<String, Object>emptyMap(),
                                                              Collections.<String, Object>emptyMap(),
                                                              Collections.<String, String>emptyMap(),
                                                              schemes,
                                                              Collections.<URI>emptySet()));

    LoadBalancerStrategy strategy = _state.getStrategy("service-1", "http");
    assertNotNull(strategy, "got null strategy in setup");

    // test serial to make sure things are working before concurrent test
    TransportClient resultTC = _state.getClient("service-1", "http");
    assertNotNull(resultTC, "got null tracker client in non-concurrent env");

    ExecutorService myExecutor = Executors.newCachedThreadPool();
    ArrayList<TcCallable> cArray = new ArrayList<TcCallable>();

    List<TrackerClient> clients = new ArrayList<TrackerClient>();
    Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
    partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
    clients.add(new TrackerClient(uri, partitionDataMap, new DegraderLoadBalancerTest.TestLoadBalancerClient(uri),
                                  SystemClock.instance(), null));

    for (int i = 0; i < 20; i++)
    {
      cArray.add(i, new TcCallable(clients, _state));
    }

    Runnable refreshTask = new Runnable()
    {
      @Override
      public void run()
      {
        while(true)
        {
          List<String> myStrategyList = new LinkedList<String>();
          myStrategyList.add("degraderV3");
          _state.refreshServiceStrategies(new ServiceProperties("service-1",
                                                                "cluster-1",
                                                                "/test",
                                                                "unusedInThisConstructor",
                                                                myStrategyList,
                                                                Collections.<String, Object>emptyMap(),
View Full Code Here

    // set up state
    _state.listenToService("service-1", new NullStateListenerCallback());
    _state.listenToCluster("cluster-1", new NullStateListenerCallback());
    _state.setDelayedExecution(0);
    _serviceRegistry.put("service-1", new ServiceProperties("service-1",
                                                            "cluster-1",
                                                            "/test",
                                                            "random",
                                                            null,
                                                            Collections.<String, Object>emptyMap(),
                                                            Collections.<String, Object>emptyMap(),
                                                            Collections.<String, String>emptyMap(),
                                                            schemes,
                                                            Collections.<URI>emptySet()));

    _clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));


    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));

    URI uri1 = URI.create("http://partition-cluster-1/test1");
    URI uri2 = URI.create("http://partition-cluster-1/test2");

    _state.listenToCluster("partition-cluster-1", new NullStateListenerCallback());
    _clusterRegistry.put("partition-cluster-1", new ClusterProperties("partition-cluster-1", null,
        new HashMap<String, String>(), new HashSet<URI>(), new RangeBasedPartitionProperties("id=(\\d+)", 0, 100, 2)));

    _state.listenToService("partition-service-1", new NullStateListenerCallback());
    _serviceRegistry.put("partition-service-1",
        new ServiceProperties("partition-service-1",
            "partition-cluster-1", "/partition-test", "degraderV3", null, Collections.<String, Object>emptyMap(),
                                                                        Collections.<String, Object>emptyMap(),
                                                                        Collections.<String, String>emptyMap(),
                                                                        schemes,
                                                                        Collections.<URI>emptySet()));

    Map<Integer, PartitionData> partitionWeight = new HashMap<Integer, PartitionData>();
    partitionWeight.put(0, new PartitionData(1d));
    partitionWeight.put(1, new PartitionData(2d));

    Map<URI, Map<Integer, PartitionData>> partitionDesc =
        new HashMap<URI, Map<Integer, PartitionData>>();
    partitionDesc.put(uri1, partitionWeight);

    partitionWeight.remove(0);
    partitionWeight.put(2, new PartitionData(1d));
    partitionDesc.put(uri2, partitionWeight);


    _uriRegistry.put("partition-cluster-1", new UriProperties("partition-cluster-1", partitionDesc));
    TrackerClient client1 = _state.getClient("partition-service-1", uri1);
    TrackerClient client2 = _state.getClient("partition-service-1", uri2);
    assertEquals(client2.getPartitionWeight(1), 2d);
    assertEquals(client2.getPartitionWeight(2), 1d);
    assertEquals(client1.getPartitionWeight(1), 2d);


    // Get client, then refresh cluster
    TrackerClient client = _state.getClient("service-1", uri);
    client.restRequest(new RestRequestBuilder(URI.create("d2://service-1/foo")).build(),
                       new RequestContext(),
                       Collections.<String, String>emptyMap(),
                       new TransportCallbackAdapter<RestResponse>(Callbacks.<RestResponse>empty()));

    // now force a refresh by adding cluster
    _clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));

    // Get client, then refresh service
    client = _state.getClient("service-1", uri);
    client.restRequest(new RestRequestBuilder(URI.create("d2://service-1/foo")).build(),
                       new RequestContext(),
                       Collections.<String, String>emptyMap(),
                       new TransportCallbackAdapter<RestResponse>(Callbacks.<RestResponse>empty()));

    // refresh by adding service
    _serviceRegistry.put("service-1", new ServiceProperties("service-1",
                                                            "cluster-1",
                                                            "/test",
                                                            "random",
                                                            Collections.<String>emptyList(),
                                                            Collections.<String, Object>emptyMap(),
View Full Code Here

      writeConfig(ZKFSUtil.clusterPath(_basePath), new ClusterPropertiesJsonSerializer(),
                  new ClusterPropertiesJsonSerializer(), clusters, _clusterDefaults);
      _log.info("Wrote cluster configuration");

      _log.info("Service configuration:\n" + services);
      writeConfig(ZKFSUtil.servicePath(_basePath), new ServicePropertiesJsonSerializer(),
                  new ServicePropertiesJsonSerializer(), services, _serviceDefaults);
      _log.info("Wrote service configuration");

      if (!serviceVariants.isEmpty())
      {
        for (Map.Entry<String,Map<String,Map<String,Object>>> entry : serviceVariants.entrySet())
        {
          if (_log.isDebugEnabled())
          {
            _log.info("serviceVariant: "+ entry + "\n");
          }
          else
          {
            _log.info("serviceVariant: "+ entry.getKey() + "\n");
          }
          writeConfig(ZKFSUtil.servicePath(_basePath,entry.getKey()), new ServicePropertiesJsonSerializer(),
                      new ServicePropertiesJsonSerializer(), entry.getValue(), _serviceDefaults);
        }
        _log.info("Wrote service variant configurations");
      }

      _log.info("Configuration complete");
View Full Code Here

  {
    _log.info("Using d2ServicePath: " + _d2ServicePath);
    ZooKeeperPermanentStore<ClusterProperties> zkClusterRegistry = createPermanentStore(
            zkConnection, ZKFSUtil.clusterPath(_baseZKPath), new ClusterPropertiesJsonSerializer());
    ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = createPermanentStore(
            zkConnection, ZKFSUtil.servicePath(_baseZKPath, _d2ServicePath), new ServicePropertiesJsonSerializer());
    ZooKeeperEphemeralStore<UriProperties> zkUriRegistry =  createEphemeralStore(
            zkConnection, ZKFSUtil.uriPath(_baseZKPath), new UriPropertiesJsonSerializer(), new UriPropertiesMerger());

    FileStore<ClusterProperties> fsClusterStore = createFileStore("clusters", new ClusterPropertiesJsonSerializer());
    FileStore<ServiceProperties> fsServiceStore = createFileStore(_d2ServicePath, new ServicePropertiesJsonSerializer());
    FileStore<UriProperties> fsUriStore = createFileStore("uris", new UriPropertiesJsonSerializer());

    PropertyEventBus<ClusterProperties> clusterBus = new PropertyEventBusImpl<ClusterProperties>(executorService);
    PropertyEventBus<ServiceProperties> serviceBus = new PropertyEventBusImpl<ServiceProperties>(executorService);
    PropertyEventBus<UriProperties> uriBus = new PropertyEventBusImpl<UriProperties>(executorService);
View Full Code Here

  @Override
  public LoadBalancerStateItem<UriProperties> getUriProperties(String clusterName)
  {
    //this is used to get partitionId -> host uris
    UriProperties uriProperties = new UriProperties(_cluster, _partitionDescriptions);
    return new LoadBalancerStateItem<UriProperties>(uriProperties, 1, 1);
  }
View Full Code Here

      Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<URI, Map<Integer, PartitionData>>(3);
      uriData.put(uri1, partitionData);
      uriData.put(uri2, partitionData);
      uriData.put(uri3, partitionData);
      return (getUriProperties)
          ? new LoadBalancerStateItem<UriProperties>(new UriProperties("cluster-1", uriData),
                                                     0,
                                                     0) : null;
    }
    catch (Exception e)
    {
View Full Code Here

    _announcer.setWeight(1d);

    return new ZooKeeperConnectionManager(_zkHostname + ":" + _zkPort,
                                          _sessionTimeoutInMs,
                                          _basePath,
                                          new ZKUriStoreFactory(),
                                          _announcer);
  }
View Full Code Here

  public ZooKeeperConnectionManager build()
  {
    _announcer.setWeight(1d);

    return new ZooKeeperConnectionManager(_zkHostname + ":" + _zkPort,
                                          _sessionTimeoutInMs,
                                          _basePath,
                                          new ZKUriStoreFactory(),
                                          _announcer);
  }
View Full Code Here

    // write D2-related configuration to ZooKeeper
    // all the configuration here are permanent, no need to re-write as long as ZooKeeper still has the data
    // therefore in real case, do this "discovery" step separately

    final HttpServer server = RestLiExampleBasicServer.createServer();
    final ZooKeeperConnectionManager zkConn = createZkConn();

    startServer(server, zkConn);

    System.out.println("Example server with D2 is running with URL " + RestLiExampleBasicServer.getServerUrl() + ". Press any key to stop server.");
    System.in.read();
View Full Code Here

TOP

Related Classes of com.linkedin.d2.balancer.clients.TrackerClient$PartitionState

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.