/** * {@inheritDoc} */ @Override public synchronized Session connect() throws NoHostAvailableException { if (isDisconnected()) { LOG.info("Connected to cluster: {}", cluster.getClusterName()); for (Host host : getAllHosts()) LOG.info("Datacenter: {}; Host: {}; Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack()); LOG.info("Connect to cluster using keyspace %s", keyspace); session = cluster.connect(keyspace); } else { LOG.warn("{} - Already connected to cluster: {}", getExecutorName(), cluster.getClusterName()); } if (session.isClosed()) { LOG.warn("Session has been closed - create new one!"); this.session = cluster.newSession(); } return session; }
@Override public Cluster get() { String host = configuration.getHostAddress(); int port = configuration.getPort(); LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port); Cluster cluster = Cluster.builder() .addContactPoint(host) .withPort(port) .build(); Metadata metadata = cluster.getMetadata(); LOGGER.info("Connected to cluster: {}", metadata.getClusterName()); metadata.getAllHosts().forEach(h -> { LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack()); }); return cluster; } }
logger.info("Datacenter: {}; Host: {}; Rack: {}\n", discoveredHost.getDatacenter(), discoveredHost.getAddress(), discoveredHost.getRack());
private Map<String, Set<String>> getRacksInDcs(Iterable<Host> hosts) { Map<String, Set<String>> result = new HashMap<String, Set<String>>(); for (Host host : hosts) { Set<String> racks = result.get(host.getDatacenter()); if (racks == null) { racks = new HashSet<String>(); result.put(host.getDatacenter(), racks); } racks.add(host.getRack()); } return result; }
if (rf == null || dcReplicas.size() >= rf) continue; String rack = h.getRack();
private static void updateLocationInfo( Host host, String datacenter, String rack, boolean isInitialConnection, Cluster.Manager cluster) { if (MoreObjects.equal(host.getDatacenter(), datacenter) && MoreObjects.equal(host.getRack(), rack)) return; // If the dc/rack information changes for an existing node, we need to update the load balancing // policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. if (!isInitialConnection) cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); if (!isInitialConnection) cluster.loadBalancingPolicy().onAdd(host); }
private Map<String, Set<String>> getRacksInDcs(Iterable<Host> hosts) { Map<String, Set<String>> result = new HashMap<String, Set<String>>(); for (Host host : hosts) { Set<String> racks = result.get(host.getDatacenter()); if (racks == null) { racks = new HashSet<String>(); result.put(host.getDatacenter(), racks); } racks.add(host.getRack()); } return result; }
private Map<String, Set<String>> getRacksInDcs(Iterable<Host> hosts) { Map<String, Set<String>> result = new HashMap<String, Set<String>>(); for (Host host : hosts) { Set<String> racks = result.get(host.getDatacenter()); if (racks == null) { racks = new HashSet<String>(); result.put(host.getDatacenter(), racks); } racks.add(host.getRack()); } return result; }
private Map<String, Set<String>> getRacksInDcs(Iterable<Host> hosts) { Map<String, Set<String>> result = new HashMap<String, Set<String>>(); for (Host host : hosts) { Set<String> racks = result.get(host.getDatacenter()); if (racks == null) { racks = new HashSet<String>(); result.put(host.getDatacenter(), racks); } racks.add(host.getRack()); } return result; }
private RingMember(Host host) { Assert.notNull(host, "Host must not be null"); this.hostName = host.getAddress().getHostName(); this.address = host.getAddress().getHostAddress(); this.dc = host.getDatacenter(); this.rack = host.getRack(); }
public RingMember(Host h) { this.hostName = h.getAddress().getHostName(); this.address = h.getAddress().getHostAddress(); this.DC = h.getDatacenter(); this.rack = h.getRack(); }
host.getDatacenter(), host.getAddress(), host.getRack());
private void displayClusterInfo() { Metadata metadata = m_cluster.getMetadata(); m_logger.info("Connected to cluster with topography:"); RoundRobinPolicy policy = new RoundRobinPolicy(); for (Host host : metadata.getAllHosts()) { m_logger.info(" Host {}: datacenter: {}, rack: {}, distance: {}", new Object[]{host.getAddress(), host.getDatacenter(), host.getRack(), policy.distance(host)}); } m_logger.info("Database contains {} keyspaces", metadata.getKeyspaces().size()); } // displayClusterInfo
private void displayClusterInfo() { Metadata metadata = m_cluster.getMetadata(); m_logger.info("Connected to cluster with topography:"); RoundRobinPolicy policy = new RoundRobinPolicy(); for (Host host : metadata.getAllHosts()) { m_logger.info(" Host {}: datacenter: {}, rack: {}, distance: {}", new Object[]{host.getAddress(), host.getDatacenter(), host.getRack(), policy.distance(host)}); } m_logger.info("Database contains {} keyspaces", metadata.getKeyspaces().size()); } // displayClusterInfo
private static void updateLocationInfo(Host host, String datacenter, String rack, Cluster.Manager cluster) { if (Objects.equal(host.getDatacenter(), datacenter) && Objects.equal(host.getRack(), rack)) return; // If the dc/rack information changes, we need to update the load balancing policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); cluster.loadBalancingPolicy().onAdd(host); }
private Host parseHostInfo(ResultSet rs) { if (rs == null) { return null; } com.datastax.driver.core.Host fromHost = rs.getExecutionInfo().getQueriedHost(); InetAddress add = fromHost.getAddress(); Host toHost = new Host(add.getHostAddress(), -1); toHost.setRack(fromHost.getRack()); return toHost; }
public void connect(String node) { cluster = Cluster.builder().addContactPoint(node).build(); Metadata metadata = cluster.getMetadata(); System.out.printf("Connected to cluster: %s\n", metadata.getClusterName()); for (Host host : metadata.getAllHosts()) { System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack()); } session = cluster.connect("karaf_demo"); }
private static void updateLocationInfo(Host host, String datacenter, String rack, boolean isInitialConnection, Cluster.Manager cluster) { if (Objects.equal(host.getDatacenter(), datacenter) && Objects.equal(host.getRack(), rack)) return; // If the dc/rack information changes for an existing node, we need to update the load balancing policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. if (!isInitialConnection) cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); if (!isInitialConnection) cluster.loadBalancingPolicy().onAdd(host); }
private static void updateLocationInfo(Host host, String datacenter, String rack, boolean isInitialConnection, Cluster.Manager cluster) { if (MoreObjects.equal(host.getDatacenter(), datacenter) && MoreObjects.equal(host.getRack(), rack)) return; // If the dc/rack information changes for an existing node, we need to update the load balancing policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. if (!isInitialConnection) cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); if (!isInitialConnection) cluster.loadBalancingPolicy().onAdd(host); }
private static void updateLocationInfo(Host host, String datacenter, String rack, boolean isInitialConnection, Cluster.Manager cluster) { if (Objects.equal(host.getDatacenter(), datacenter) && Objects.equal(host.getRack(), rack)) return; // If the dc/rack information changes for an existing node, we need to update the load balancing policy. // For that, we remove and re-add the node against the policy. Not the most elegant, and assumes // that the policy will update correctly, but in practice this should work. if (!isInitialConnection) cluster.loadBalancingPolicy().onDown(host); host.setLocationInfo(datacenter, rack); if (!isInitialConnection) cluster.loadBalancingPolicy().onAdd(host); }