All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.driver.core.ConfigAntiPatternsFinder Maven / Gradle / Ivy

Go to download

A driver for DataStax Enterprise (DSE) and Apache Cassandra 1.2+ clusters that works exclusively with the Cassandra Query Language version 3 (CQL3) and Cassandra's binary protocol, supporting DSE-specific features such as geospatial types, DSE Graph and DSE authentication.

There is a newer version: 2.4.0
Show newest version
/*
 * Copyright DataStax, Inc.
 *
 * This software can be used solely with DataStax Enterprise. Please consult the license at
 * http://www.datastax.com/terms/datastax-dse-driver-license-terms
 */
package com.datastax.driver.core;

import com.datastax.driver.core.policies.ChainableLoadBalancingPolicy;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.RetryPolicy;
import com.google.common.annotations.VisibleForTesting;
import java.util.HashMap;
import java.util.Map;

class ConfigAntiPatternsFinder {
  Map findAntiPatterns(Cluster cluster) {
    Map antiPatterns = new HashMap();
    findLoadBalancingPolicyAntiPatterns(
        antiPatterns, cluster.getConfiguration().getPolicies().getLoadBalancingPolicy());
    findRetryPolicyAntiPatterns(
        antiPatterns, cluster.getConfiguration().getPolicies().getRetryPolicy());
    return antiPatterns;
  }

  @SuppressWarnings("deprecation")
  private void findRetryPolicyAntiPatterns(
      Map antiPatterns, RetryPolicy retryPolicy) {
    if (retryPolicy
        instanceof com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy) {
      antiPatterns.put("downgradingConsistency", "Downgrading consistency retry policy in use");
    }
  }

  @VisibleForTesting
  void findLoadBalancingPolicyAntiPatterns(
      Map antiPatterns, LoadBalancingPolicy loadBalancingPolicy) {
    if (loadBalancingPolicy instanceof ChainableLoadBalancingPolicy) {
      findLoadBalancingPolicyAntiPatterns(
          antiPatterns, ((ChainableLoadBalancingPolicy) loadBalancingPolicy).getChildPolicy());
    }
    if (loadBalancingPolicy instanceof DCAwareRoundRobinPolicy) {
      DCAwareRoundRobinPolicy dcAwareRoundRobinPolicy =
          (DCAwareRoundRobinPolicy) loadBalancingPolicy;
      if (dcAwareRoundRobinPolicy.isContactPointsMultipleDCs()) {
        antiPatterns.put(
            "contactPointsMultipleDCs", "Contact points contain hosts from multiple data centers");
      }

      if (dcAwareRoundRobinPolicy.isUseRemoteHostsForFailover()) {
        antiPatterns.put("useRemoteHosts", "Using remote hosts for failover");
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy