title: Cassandra Integration with Apache Spark
body: <p>I am trying to run the code provided in the following link:
  <a href="http://www.datastax.com/dev/blog/accessing-cassandra-from-spark-in-java" rel="nofollow">http://www.datastax.com/dev/blog/accessing-cassandra-from-spark-in-java</a></p>
  
  <p>Code provided below:</p>
  
  <pre><code>import java.io.Serializable;
  
  import org.apache.spark.SparkConf;
  import org.apache.spark.api.java.JavaSparkContext;
  
  import com.datastax.driver.core.Session;
  import com.datastax.spark.connector.cql.CassandraConnector;
  
  public class JavaDemo implements Serializable {
      private transient SparkConf conf;
  
      private JavaDemo(SparkConf conf) {
          this.conf = conf;
      }
  
      private void run() {
          JavaSparkContext sc = new JavaSparkContext(conf);
          generateData(sc);
          compute(sc);
          showResults(sc);
          sc.stop();
      }
  
      private void generateData(JavaSparkContext sc) {
  
          CassandraConnector connector = CassandraConnector.apply(sc.getConf());
  
          try (Session session = connector.openSession()) {
              session.execute("DROP KEYSPACE IF EXISTS java_api");
              session.execute("CREATE KEYSPACE java_api WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
              session.execute("CREATE TABLE java_api.products (id INT PRIMARY KEY, name TEXT, parents LIST&lt;INT&gt;)");
              session.execute("CREATE TABLE java_api.sales (id UUID PRIMARY KEY, product INT, price DECIMAL)");
              session.execute("CREATE TABLE java_api.summaries (product INT PRIMARY KEY, summary DECIMAL)");
          }
      }
  
      private void compute(JavaSparkContext sc) {
      }
  
      private void showResults(JavaSparkContext sc) {
      }
  
      public static void main(String[] args) {
  
          SparkConf conf = new SparkConf();
          conf.setAppName("Java API demo");
          conf.setMaster("local");
          conf.set("spark.cassandra.connection.host", "XX.XX.XX.XX");
  
          JavaDemo app = new JavaDemo(conf);
          app.run();
  
      }
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Failed to open native connection to Cassandra at {&lt;Cassandra IP&gt;}:9042&lt;
      at com.datastax.spark.connector.cql.CassandraConnector$.com$datastax$spark$connector$cql$CassandraConnector$$createSession(CassandraConnector.scala:176)
      at com.datastax.spark.connector.cql.CassandraConnector$$anonfun$2.apply(CassandraConnector.scala:162)
      at com.datastax.spark.connector.cql.CassandraConnector$$anonfun$2.apply(CassandraConnector.scala:162)
      at com.datastax.spark.connector.cql.RefCountedCache.createNewValueAndKeys(RefCountedCache.scala:31)
      at com.datastax.spark.connector.cql.RefCountedCache.acquire(RefCountedCache.scala:56)
      at com.datastax.spark.connector.cql.CassandraConnector.openSession(CassandraConnector.scala:73)
      at JavaDemo.generateData(JavaDemo.java:28)
      at JavaDemo.run(JavaDemo.java:18)
      at JavaDemo.main(JavaDemo.java:52)
  Caused by: java.lang.IllegalArgumentException: Contact points contain multiple data centers:
      at com.datastax.spark.connector.cql.LocalNodeFirstLoadBalancingPolicy.init(LocalNodeFirstLoadBalancingPolicy.scala:47)
      at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1024)
      at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:270)
      at com.datastax.spark.connector.cql.CassandraConnector$.com$datastax$spark$connector$cql$CassandraConnector$$createSession(CassandraConnector.scala:169)
  </code></pre>
  
  <p>Is there something I can do about it. I have tried running Java connection with Cassandra, that seems to be working fine</p>