Package com.linkedin.d2.balancer.properties

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


        "/test", "random", null,
        Collections.<String, Object>emptyMap(),
        null, null, schemes, null));

    // first we announce uri with empty partition data map
    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));

    TrackerClient client = _state.getClient("service-1", uri);

    assertNotNull(client);
    assertEquals(client.getUri(), uri);
    // tracker client should see empty partition data map
    assertTrue(client.getParttitionDataMap().isEmpty());

    // then we update this uri to have a non-empty partition data map
    partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
    _uriRegistry.put("cluster-1", new UriProperties("cluster-1", uriData));

    TrackerClient updatedClient = _state.getClient("service-1", uri);

    assertNotNull(updatedClient);
    // should have got a different tracker client
View Full Code Here


      Map<Integer, PartitionData> partitionData = new HashMap<Integer, PartitionData>(1);
      partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1.0d));
      uriData.put(TEST_SERVER_URI1, partitionData);
      uriData.put(TEST_SERVER_URI2, partitionData);

      UriProperties uriProps = new UriProperties(TEST_CLUSTER_NAME, uriData);

      callback = new FutureCallback<None>();
      uriStore.start(callback);
      callback.get(30, TimeUnit.SECONDS);
View Full Code Here

    assertNull(store.get("cluster-2"));

    // bring up uri1
    markUp(server, cluster, uri1, 0.5d);

    UriProperties properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.getPartitionDataMap(uri1).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), 0.5d);
    assertEquals(properties.Uris().size(), 1);

    // test mark up when already up call
    markUp(server, cluster, uri1, 2d);

    properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.getPartitionDataMap(uri1).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), 2d);
    assertEquals(properties.Uris().size(), 1);

    // bring up uri 2
    markUp(server, cluster, uri2, 1.5d);

    properties = store.get(cluster);
    assertEquals(properties.getPartitionDataMap(uri1).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), 2d);
    assertEquals(properties.getPartitionDataMap(uri2).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), 1.5d);
    assertEquals(properties.Uris().size(), 2);

    // bring down uri 1
    markDown(server, cluster, uri1);

    properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.getPartitionDataMap(uri2).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), 1.5d);
    assertEquals(properties.Uris().size(), 1);

    // test bring down when already down
    markDown(server, cluster, uri1);

    properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.getPartitionDataMap(uri2).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), 1.5d);
    assertEquals(properties.Uris().size(), 1);

    // bring down uri 2
    markDown(server, cluster, uri2);

    properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.Uris().size(), 0);

    // test bad cluster doesn't exist
    markDown(server, "BAD CLUSTER", uri1);

    properties = store.get("BAD CLUSTER");
    assertNull(properties);

    // bring up uri1

    Map<Integer, PartitionData> partitionWeight = new HashMap<Integer, PartitionData>();
    partitionWeight.put(5, new PartitionData(0.3d));
    partitionWeight.put(15, new PartitionData(0.7d));
    markUp(server, cluster, uri1, partitionWeight, null);
    properties = store.get(cluster);
    assertNotNull(properties);

    assertEquals(properties.getPartitionDataMap(uri1), partitionWeight);

    Map<String, Object> uri2SpecificProperties = new HashMap<String, Object>();
    uri2SpecificProperties.put("foo", "fooValue");
    uri2SpecificProperties.put("bar", 1);

    partitionWeight.put(10, new PartitionData(1d));

    // bring up uri2 with uri specific properties

    markUp(server, cluster, uri2, partitionWeight, uri2SpecificProperties);

    properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.Uris().size(), 2);
    assertEquals(properties.getPartitionDataMap(uri2), partitionWeight);

    assertNotNull(properties.getUriSpecificProperties());
    assertEquals(properties.getUriSpecificProperties().size(), 1);
    assertEquals(properties.getUriSpecificProperties().get(uri2), uri2SpecificProperties);

    // bring down uri1 and bring it back up again with properties

    markDown(server, cluster, uri1);

    Map<String, Object> uri1SpecificProperties = new HashMap<String, Object>();
    uri1SpecificProperties.put("baz", "bazValue");

    // use new partition data so that we can test the mapping later on

    Map<Integer, PartitionData> newUri1PartitionWeights = new HashMap<Integer, PartitionData>(partitionWeight);
    newUri1PartitionWeights.remove(10);
    markUp(server, cluster, uri1, newUri1PartitionWeights, uri1SpecificProperties);

    properties = store.get(cluster);
    assertNotNull(properties);
    assertEquals(properties.Uris().size(), 2);
    assertEquals(properties.getPartitionDataMap(uri1), newUri1PartitionWeights);
    assertEquals(properties.getPartitionDataMap(uri2), partitionWeight);

    assertNotNull(properties.getUriSpecificProperties());
    assertEquals(properties.getUriSpecificProperties().size(), 2);
    assertEquals(properties.getUriSpecificProperties().get(uri1), uri1SpecificProperties);
    assertEquals(properties.getUriSpecificProperties().get(uri2), uri2SpecificProperties);

    Set<URI> uriSet = new HashSet<URI>();
    uriSet.add(uri1);
    uriSet.add(uri2);

    assertEquals(properties.getUriBySchemeAndPartition("http", 5), uriSet);

    uriSet.remove(uri1);

    assertEquals(properties.getUriBySchemeAndPartition("http", 10), uriSet);
  }
View Full Code Here

      {
        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

      Map<Integer, PartitionData> partitionData = new HashMap<Integer, PartitionData>(1);
      partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d + _random.nextDouble()));
      uriData.put(uri, partitionData);
    }

    UriProperties uriProperties = new UriProperties(clusterName, uriData);

    _expectedClusterProperties.put(clusterName, clusterProperties);
    _expectedUriProperties.put(clusterName, uriProperties);
    _clusterRegistry.put(clusterName, clusterProperties);
    _uriRegistry.put(clusterName, uriProperties);
View Full Code Here

                                                                   uristoreString,
                                                                   new UriPropertiesJsonSerializer(),
                                                                   new UriPropertiesMerger());

    String clusterName = zkServiceRegistry.get(serviceName).getClusterName();
    UriProperties uripros = zkUriRegistry.get(clusterName);
    uriprops.add( uripros);
    return uriprops;
  }
View Full Code Here

    for (String service : currentservices)
    {
      if (service.equals(serviceName))
      {
        String clusterName = zkServiceRegistry.get(serviceName).getClusterName();
        UriProperties uripros = zkUriRegistry.get(clusterName);
        map.put( clusterName, uripros);
      }
    }

    return map;
View Full Code Here

  }

  public static void verifyUriProperties(String cluster, Map<URI, Double> urisWeights)
      throws IOException, URISyntaxException, PropertyStoreException
  {
    UriProperties     uriprops     = getUriProperties(_zkclient,cluster);

    assertEquals(uriprops.getClusterName(), cluster);

    for (URI uri : urisWeights.keySet())
    {
      assertEquals(uriprops.getPartitionDataMap(uri).get(DefaultPartitionAccessor.DEFAULT_PARTITION_ID).getWeight(), urisWeights.get(uri));
    }
  }
View Full Code Here

  }

  public static void verifyPartitionedUriProperties(String cluster, Map<URI, Map<Integer, Double>> partitionWeights)
      throws IOException, URISyntaxException, PropertyStoreException
  {
    UriProperties     uriprops     = getUriProperties(_zkclient,cluster);
    assertEquals(uriprops.getClusterName(), cluster);

    if (partitionWeights != null)
    {
      Map<Integer, Set<URI>> partitionUris = new HashMap<Integer, Set<URI>>();
      for (final URI uri : partitionWeights.keySet())
      {
        for(final int partitionId : partitionWeights.get(uri).keySet())
        {
          Set<URI> uriSet = partitionUris.get(partitionId);
          if (uriSet == null)
          {
            uriSet = new HashSet<URI>();
            partitionUris.put(partitionId, uriSet);
          }
          uriSet.add(uri);
        }
      }

      for (final int partitionId : partitionUris.keySet())
      {
        assertEquals(uriprops.getUriBySchemeAndPartition("http", partitionId), partitionUris.get(partitionId));
      }

      for (URI uri : partitionWeights.keySet())
      {
        Map<Integer, Double> weights = partitionWeights.get(uri);
        for (int partitionId : weights.keySet())
        {
          assertEquals(weights.get(partitionId), uriprops.getPartitionDataMap(uri).get(partitionId).getWeight());
        }
      }
    }
  }
View Full Code Here

            sb.append("]");
          }
          sb.append("}");
          info(_log, sb);
        }
        _store.put(clusterName, new UriProperties(clusterName, partitionDesc, myUriSpecificProperties), callback);

      }

      @Override
      public void onError(Throwable e)
View Full Code Here

TOP

Related Classes of com.linkedin.d2.balancer.properties.UriProperties

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.