Tabnine Logo
Host.getDatacenter
Code IndexAdd Tabnine to your IDE (free)

How to use
getDatacenter
method
in
com.datastax.driver.core.Host

Best Java code snippets using com.datastax.driver.core.Host.getDatacenter (Showing top 20 results out of 351)

origin: apache/storm

/**
 * {@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;
}
origin: Netflix/conductor

  @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;
  }
}
origin: brianfrankcooper/YCSB

discoveredHost.getDatacenter(), discoveredHost.getAddress(),
discoveredHost.getRack());
origin: com.datastax.cassandra/cassandra-driver-core

private String dc(Host host) {
 String dc = host.getDatacenter();
 return dc == null ? localDc : dc;
}
origin: com.datastax.cassandra/cassandra-driver-core

 @Override
 public boolean apply(Host host) {
  String hdc = host.getDatacenter();
  return (hdc == null) ? includeNullDC : _dcs.contains(hdc);
 }
};
origin: com.datastax.cassandra/cassandra-driver-core

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;
}
origin: com.datastax.cassandra/cassandra-driver-core

public HostAssert isInDatacenter(String datacenter) {
 assertThat(actual.getDatacenter()).isEqualTo(datacenter);
 return this;
}
origin: com.datastax.cassandra/cassandra-driver-core

String dc = host.getDatacenter();
if (dcHostCount.get(dc) == null) {
 dcHostCount.put(dc, 0);
for (int j = 0; j < ring.size() && !allDone(allDcReplicas, dcHostCount); j++) {
 Host h = tokenToPrimary.get(getTokenWrapping(i + j, ring));
 String dc = h.getDatacenter();
 if (dc == null || !allDcReplicas.containsKey(dc)) continue;
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_ignore_DCs_in_black_list() {
 when(host1.getDatacenter()).thenReturn("dc1");
 when(host2.getDatacenter()).thenReturn("dc2");
 when(host3.getDatacenter()).thenReturn(null);
 HostFilterPolicy policy =
   HostFilterPolicy.fromDCBlackList(wrappedPolicy, Lists.newArrayList("dc2"));
 assertThat(policy.distance(host1)).isSameAs(HostDistance.LOCAL);
 assertThat(policy.distance(host2)).isSameAs(HostDistance.IGNORED);
 assertThat(policy.distance(host3)).isSameAs(HostDistance.LOCAL);
}
origin: com.datastax.cassandra/cassandra-driver-core

 @Test(groups = "unit")
 public void should_ignore_DCs_not_in_white_list_and_not_null() {
  when(host1.getDatacenter()).thenReturn("dc1");
  when(host2.getDatacenter()).thenReturn("dc2");
  when(host3.getDatacenter()).thenReturn(null);

  HostFilterPolicy policy =
    HostFilterPolicy.fromDCWhiteList(wrappedPolicy, Lists.newArrayList("dc1"));

  assertThat(policy.distance(host1)).isSameAs(HostDistance.LOCAL);
  assertThat(policy.distance(host2)).isSameAs(HostDistance.IGNORED);
  assertThat(policy.distance(host3)).isSameAs(HostDistance.LOCAL);
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

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);
}
origin: io.prestosql.cassandra/cassandra-driver

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;
}
origin: com.datastax.cassandra/cassandra-driver-core

assertThat(initHostsCaptor.getValue()).containsExactly(host1);
assertThat(policy.localDc).isEqualTo(host1.getDatacenter());
origin: com.datastax.cassandra/cassandra-driver-core

assertThat(initHostsCaptor.getValue()).containsOnly(host1);
assertThat(policy.localDc).isEqualTo(host1.getDatacenter());
origin: org.springframework.data/spring-data-cassandra

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();
}
origin: intuit/wasabi

for (Host host : metadata.getAllHosts()) {
  LOGGER.info("Datatacenter: {}; Host: {}; Rack: {}\n",
      host.getDatacenter(),
      host.getAddress(),
      host.getRack());
origin: com.stratio.cassandra/cassandra-driver-core

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);
}
origin: com.datastax.dse/dse-java-driver-core

 @Test(groups = "unit")
 public void should_ignore_DCs_not_in_white_list_and_not_null() {
  when(host1.getDatacenter()).thenReturn("dc1");
  when(host2.getDatacenter()).thenReturn("dc2");
  when(host3.getDatacenter()).thenReturn(null);

  HostFilterPolicy policy =
    HostFilterPolicy.fromDCWhiteList(wrappedPolicy, Lists.newArrayList("dc1"));

  assertThat(policy.distance(host1)).isSameAs(HostDistance.LOCAL);
  assertThat(policy.distance(host2)).isSameAs(HostDistance.IGNORED);
  assertThat(policy.distance(host3)).isSameAs(HostDistance.LOCAL);
 }
}
origin: io.prestosql.cassandra/cassandra-driver

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);
}
origin: com.yugabyte/cassandra-driver-core

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);
}
com.datastax.driver.coreHostgetDatacenter

Javadoc

Returns the name of the datacenter this host is part of.

The returned datacenter name is the one as known by Cassandra. It is also possible for this information to be unavailable. In that case this method returns null, and the caller should always be aware of this possibility.

Popular methods of Host

  • getAddress
    Returns the address that the driver will use to connect to the node. This is a shortcut for getSocke
  • getRack
    Returns the name of the rack this host is part of. The returned rack name is the one as known by Cas
  • getCassandraVersion
    The Cassandra version the host is running. It is also possible for this information to be unavailabl
  • isUp
    Returns whether the host is considered up by the driver. Please note that this is only the view of t
  • getSocketAddress
    Returns the address and port that the driver will use to connect to the node. This is the node's br
  • toString
  • equals
  • <init>
  • getBroadcastAddress
    Returns the node broadcast address (that is, the IP by which it should be contacted by other peers i
  • setDown
  • setLocationInfo
  • setUp
  • setLocationInfo,
  • setUp,
  • wasJustAdded,
  • setDseGraphEnabled,
  • setDseVersion,
  • setDseWorkload,
  • setTokens,
  • setVersion,
  • getBroadcastSocketAddress

Popular in Java

  • Parsing JSON documents to java classes using gson
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • setRequestProperty (URLConnection)
  • requestLocationUpdates (LocationManager)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • BoxLayout (javax.swing)
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now