whiteList.add(new InetSocketAddress(point, config.getNativeProtocolPort())); loadPolicy = new WhiteListPolicy(loadPolicy, whiteList);
/** * Creates a new policy that wraps the provided child policy but only "allows" hosts from the * provided white list. * * @param childPolicy the wrapped policy. * @param whiteList the white listed hosts. Only hosts from this list may get connected to * (whether they will get connected to or not depends on the child policy). */ public WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) { super(childPolicy, buildPredicate(whiteList)); }
/** * Creates a new policy with the given host names. * * <p>See {@link #ofHosts(LoadBalancingPolicy, Iterable)} for more details. */ public static WhiteListPolicy ofHosts(LoadBalancingPolicy childPolicy, String... hostnames) { return ofHosts(childPolicy, Arrays.asList(hostnames)); }
return new WhiteListPolicy( childPolicy, new Predicate<Host>() {
/** * Creates a new policy that wraps the provided child policy but only "allows" hosts * from the provided while list. * * @param childPolicy the wrapped policy. * @param whiteList the white listed hosts. Only hosts from this list may get connected * to (whether they will get connected to or not depends on the child policy). */ public WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) { super(childPolicy, buildPredicate(whiteList)); }
/** * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws an {@link * IllegalArgumentException} if a name could not be resolved. * * @test_category load_balancing:white_list */ @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_throw_IAE_if_name_could_not_be_resolved() { WhiteListPolicy.ofHosts(new RoundRobinPolicy(), "a.b.c.d.e.f.UNRESOLVEABLE"); }
loadBalancingPolicy = new WhiteListPolicy(loadBalancingPolicy, whiteListCollection);
/** * Creates a new policy that wraps the provided child policy but only "allows" hosts * from the provided while list. * * @param childPolicy the wrapped policy. * @param whiteList the white listed hosts. Only hosts from this list may get connected * to (whether they will get connected to or not depends on the child policy). */ public WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) { super(childPolicy, buildPredicate(whiteList)); }
/** * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws a {@link * NullPointerException} if a name provided is null. * * @test_category load_balancing:white_list */ @Test(groups = "unit", expectedExceptions = NullPointerException.class) public void should_throw_NPE_if_null_provided() { WhiteListPolicy.ofHosts(new RoundRobinPolicy(), null, null); }
@Override public Cluster.Builder createClusterBuilder() { // Only connect to node 1, which makes it easier to query system tables in // should_expose_tokens_per_host() LoadBalancingPolicy lbp = new WhiteListPolicy(new RoundRobinPolicy(), Collections.singleton(ccm().addressOfNode(1))); return Cluster.builder() .addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .withLoadBalancingPolicy(lbp); }
/** * Creates a new policy that wraps the provided child policy but only "allows" hosts * from the provided while list. * * @param childPolicy the wrapped policy. * @param whiteList the white listed hosts. Only hosts from this list may get connected * to (whether they will get connected to or not depends on the child policy). */ public WhiteListPolicy(LoadBalancingPolicy childPolicy, Collection<InetSocketAddress> whiteList) { super(childPolicy, buildPredicate(whiteList)); }
WhiteListPolicy.ofHosts( new RoundRobinPolicy(), sCluster.address(1).getHostName(),
/** * @return a {@link Cluster} instance that connects only to the control host of the given cluster. */ public static Cluster buildControlCluster(Cluster cluster, CCMAccess ccm) { Host controlHost = cluster.manager.controlConnection.connectedHost(); List<InetSocketAddress> singleAddress = Collections.singletonList(controlHost.getSocketAddress()); return Cluster.builder() .addContactPoints(controlHost.getSocketAddress().getAddress()) .withPort(ccm.getBinaryPort()) .withLoadBalancingPolicy(new WhiteListPolicy(new RoundRobinPolicy(), singleAddress)) .build(); }
/** * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws an {@link * IllegalArgumentException} if a name could not be resolved. * * @test_category load_balancing:white_list */ @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) public void should_throw_IAE_if_name_could_not_be_resolved() { WhiteListPolicy.ofHosts(new RoundRobinPolicy(), "a.b.c.d.e.f.UNRESOLVEABLE"); }
private void deleteNode2RpcAddressFromNode1() throws Exception { InetSocketAddress firstHost = ccm().addressOfNode(1); Cluster cluster = register( Cluster.builder() .addContactPoints(firstHost.getAddress()) .withPort(ccm().getBinaryPort()) // ensure we will only connect to node1 .withLoadBalancingPolicy( new WhiteListPolicy( Policies.defaultLoadBalancingPolicy(), Lists.newArrayList(firstHost))) .build()); Session session = cluster.connect(); String deleteStmt = String.format( "DELETE rpc_address FROM system.peers WHERE peer = '%s'", ccm().addressOfNode(2).getHostName()); session.execute(deleteStmt); session.close(); cluster.close(); } }
/** * Ensures that {@link WhiteListPolicy#ofHosts(LoadBalancingPolicy, String...)} throws a {@link * NullPointerException} if a name provided is null. * * @test_category load_balancing:white_list */ @Test(groups = "unit", expectedExceptions = NullPointerException.class) public void should_throw_NPE_if_null_provided() { WhiteListPolicy.ofHosts(new RoundRobinPolicy(), null, null); }
@Test(groups = "short") public void should_rethrow_unavailable_in_no_host_available_exception() { LoadBalancingPolicy firstHostOnlyPolicy = new WhiteListPolicy( Policies.defaultLoadBalancingPolicy(), Collections.singletonList(host1.getSocketAddress()));
WhiteListPolicy.ofHosts( new RoundRobinPolicy(), sCluster.address(1).getHostName(),
@Override public LoadBalancingPolicy build() { return new WhiteListPolicy(subPolicy.build(), whiteList); } }
@Override public LoadBalancingPolicy build() { return new WhiteListPolicy(subPolicy.build(), whiteList); } }