Examples of ClusterProperties


Examples of com.linkedin.d2.balancer.properties.ClusterProperties

                                                            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(),
                                                            null,
                                                            null,
                                                            schemes,
                                                            null));

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

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

    assertNotNull(strategy);
    assertTrue(strategy instanceof DegraderLoadBalancerStrategyV3);
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

    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,
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

                                                            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(),
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

    // one for service onInit
    ++expectedVersion;

    assertEquals(_state.getVersion(), expectedVersion);

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

    // one for cluster onAdd
    ++expectedVersion;

    assertEquals(_state.getVersion(), expectedVersion);
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

    assertEquals(d2Conf.runDiscovery(_zkHosts), 0);

    verifyPartitionProperties("partitioned-cluster", partitionProperties);

    final ClusterProperties clusterprops = getClusterProperties(_zkclient, "partitioned-cluster" );
    final PartitionAccessor accessor = PartitionAccessorFactory.getPartitionAccessor(clusterprops.getPartitionProperties());
    try
    {
      accessor.getPartitionId(-1 + "");
      fail("Exception expected");
    }
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

    assertEquals(d2Conf.runDiscovery(_zkHosts), 0);

    verifyPartitionProperties("partitioned-cluster", partitionProperties);

    final ClusterProperties clusterprops = getClusterProperties(_zkclient, "partitioned-cluster" );
    final PartitionAccessor accessor = PartitionAccessorFactory.getPartitionAccessor(clusterprops.getPartitionProperties());

    assertEquals(0, accessor.getPartitionId(0 + ""));
    assertEquals(9, accessor.getPartitionId(99 + ""));
    assertEquals(6, accessor.getPartitionId(176 + ""));
    assertEquals(3, accessor.getPartitionId(833 + ""));
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

    return zkUriRegistry.get(cluster);
  }

  public static void verifyClusterProperties(String cluster) throws IOException, URISyntaxException, PropertyStoreException
  {
    ClusterProperties clusterprops = getClusterProperties(_zkclient, cluster);

    assertEquals(clusterprops.getClusterName(), cluster);
    assertEquals(clusterprops.getPrioritizedSchemes(), Arrays.asList(new String[] {"http"}));
    assertEquals(clusterprops.getProperties().get("requestTimeout"), String.valueOf(10000));
    assertEquals(clusterprops.getBanned(), new TreeSet<URI>());
  }
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

      }
      else
      {
        ServiceProperties serviceProperties =
            _expectedServiceProperties.get(possibleService);
        ClusterProperties clusterProperties =
            _expectedClusterProperties.get(serviceProperties.getClusterName());
        UriProperties uriProperties =
            _expectedUriProperties.get(serviceProperties.getClusterName());

        assertEquals(_state.getServiceProperties(possibleService).getProperty(),
                     serviceProperties);

        // verify round robin'ing of the hosts for this service
        for (int i = 0; i < 100; ++i)
        {
          try
          {
            // this call will queue up messages if we're not listening to the service, but
            // it's ok, because all of the messengers have been stopped.
            final TransportClient client =
                _loadBalancer.getClient(new URIRequest("d2://" + possibleService +
                    random(_possiblePaths)), new RequestContext());

            // if we didn't receive service unavailable, we should
            // get a client back
            assertNotNull(client);
          }
          catch (ServiceUnavailableException e)
          {
            if (uriProperties != null && clusterProperties != null)
            {
              // only way to get here is if the prioritized
              // schemes could find no available uris in the
              // cluster. let's see if we can find a URI that
              // matches a prioritized scheme in the cluster.
              Set<String> schemes = new HashSet<String>();

              for (URI uri : uriProperties.Uris())
              {
                schemes.add(uri.getScheme());
              }

              for (String scheme : clusterProperties.getPrioritizedSchemes())
              {
                // if we got null, then we must not have a
                // matching scheme, or we must be missing a
                // client factory

                // TODO if you're not using round robin
                // strategy, it's possible that the strategy
                // could return null (even though a factory is
                // available), but i am not checking for this at
                // the moment. See SimpleLoadBalancer.java to trace
                // the code.
                if (schemes.contains(scheme) && _clientFactories.containsKey(scheme))
                {
                  break;
                }

                assertFalse(schemes.contains(scheme)
                                && _clientFactories.containsKey(scheme),
                            "why couldn't a client be found for schemes "
                                + clusterProperties.getPrioritizedSchemes()
                                + " with URIs: " + uriProperties.Uris());
              }
            }
          }
        }
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

  // cluster simulation
  public void addCluster(String clusterName,
                         List<String> prioritizedSchemes,
                         List<URI> uris)
  {
    ClusterProperties clusterProperties =
        new ClusterProperties(clusterName, prioritizedSchemes);

    // weight the uris randomly between 1 and 2
    Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<URI, Map<Integer, PartitionData>>();

    for (URI uri : uris)
View Full Code Here

Examples of com.linkedin.d2.balancer.properties.ClusterProperties

    {
      List<String> schemes = new ArrayList<String>();

      schemes.add("http");

      putCluster(new ClusterProperties(servers.getKey(), schemes));

      for (final LoadBalancerEchoServer server : servers.getValue())
      {
        for (int i = 1; i <= 3; ++i)
        {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.