Package com.netflix.astyanax.AstyanaxContext

Examples of com.netflix.astyanax.AstyanaxContext.Builder


    if(builderObj == null || !(builderObj instanceof Builder))
      throw new IllegalArgumentException("The property Bootstrap.CASSANDRA_BUILDER was not in the Map or was in Map but was not of type Builder and must be supplied when using Cassandra plugin");

    callback = (CreateCfCallback) properties.get(SpiConstants.CASSANDRA_CF_CREATE_CALLBACK);
   
    Builder builder = (Builder) builderObj;
    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    keyspaceName = clusterContext.getKeyspaceName();
    if(keyspaceName == null)
      throw new IllegalArgumentException("You did not call Builder.forKeyspace on the astyanax Builder api.  We need to know the keyspace to continue");
   
    clusterContext.start();
   
    cluster = clusterContext.getClient();
    List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
    List<String> keyspaceNames = new ArrayList<String>();
    boolean exists = false;
    for(KeyspaceDefinition kDef : keyspaces) {
      keyspaceNames.add(kDef.getName());
      if(keyspaceName.equalsIgnoreCase(kDef.getName())) {
        exists = true;
        break;
      }
    }

    log.info("your keyspace="+keyspaceName+" keyspaces="+keyspaceNames+" exists="+exists);
    if(!exists) {
      KeyspaceDefinition def = cluster.makeKeyspaceDefinition();
      def.setName(keyspaceName);
      def.setStrategyClass("org.apache.cassandra.locator.SimpleStrategy");
      Map<String, String> map = new HashMap<String, String>();
      map.put("replication_factor", "3");
      def.setStrategyOptions(map);
      if(callback != null)
        def = (KeyspaceDefinition) callback.configureKeySpace(keyspaceName, def);
      cluster.addKeyspace(def);
      log.info("added keyspace="+keyspaceName+" so it now exists");
    }
   
    context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
   
    keyspace = context.getClient();

    //for some reason, the keyspace is not always created fast enough so sleep 3 seconds and try again
View Full Code Here


    return impl;
  }
  @Override
  protected void createBestCassandraConfig(Map<String, Object> properties,
      String clusterName, String keyspace2, String seeds2) {
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
      )
      .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
          .setMaxConnsPerHost(20)
          .setInitConnsPerHost(2)
          .setSeeds(seeds2)
          .setConnectTimeout(10000)
      )
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
   
   
  if(seeds2.contains(",")) {
    //for a multi-node cluster, we want the test suite using quorum on writes and
    //reads so we have no issues...
    AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
    config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    builder = builder.withAstyanaxConfiguration(config);
  }
  properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

//    else if(clusterNameObj == null || !(clusterNameObj instanceof String))
//      throw new IllegalArgumentException("The property Bootstrap.CLUSTER_NAME was not in the Map or was in the Map but not as a String");
    if(builderObj == null || !(builderObj instanceof Builder))
      throw new IllegalArgumentException("The property Bootstrap.CASSANDRA_BUILDER was not in the Map or was in Map but was not of type Builder and must be supplied when using Cassandra plugin");

    Builder builder = (Builder) builderObj;
    AstyanaxContext<Cluster> clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    keyspaceName = clusterContext.getKeyspaceName();
    if(keyspaceName == null)
      throw new IllegalArgumentException("You did not call Builder.forKeyspace on the astyanax Builder api.  We need to know the keyspace to continue");
   
    clusterContext.start();
   
    cluster = clusterContext.getEntity();
    List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
    boolean exists = false;
    for(KeyspaceDefinition kDef : keyspaces) {
      if(keyspaceName.equalsIgnoreCase(kDef.getName())) {
        exists = true;
        break;
      }
    }

    if(!exists) {
      KeyspaceDefinition def = cluster.makeKeyspaceDefinition();
      def.setName(keyspaceName);
      def.setStrategyClass("org.apache.cassandra.locator.SimpleStrategy");
      Map<String, String> map = new HashMap<String, String>();
      map.put("replication_factor", "3");
      def.setStrategyOptions(map);
      cluster.addKeyspace(def);
    }
   
    AstyanaxContext<Keyspace> context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
   
    keyspace = context.getEntity();

    KeyspaceDefinition keySpaceMeta = keyspace.describeKeyspace();
View Full Code Here

    return impl;
  }
  @Override
  protected void createBestCassandraConfig(Map<String, Object> properties,
      String clusterName, String keyspace2, String seeds2) {
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
      )
      .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
          .setMaxConnsPerHost(2)
          .setInitConnsPerHost(2)
          .setSeeds(seeds2)
      )
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
   
   
    if(!"localhost:9160".equals(seeds2)) {
      if(!seeds2.contains(","))
        throw new IllegalArgumentException("You must specify a comma delimited list of seeds OR 'localhost:9160' as the seed");
      //for a multi-node cluster, we want the test suite using quorum on writes and
      //reads so we have no issues...
      AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
      config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
      builder = builder.withAstyanaxConfiguration(config);
    }   
    properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

    if(builderObj == null || !(builderObj instanceof Builder))
      throw new IllegalArgumentException("The property Bootstrap.CASSANDRA_BUILDER was not in the Map or was in Map but was not of type Builder and must be supplied when using Cassandra plugin");

    callback = (CreateCfCallback) properties.get(SpiConstants.CASSANDRA_CF_CREATE_CALLBACK);
   
    Builder builder = (Builder) builderObj;
    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    keyspaceName = clusterContext.getKeyspaceName();
    if(keyspaceName == null)
      throw new IllegalArgumentException("You did not call Builder.forKeyspace on the astyanax Builder api.  We need to know the keyspace to continue");
   
    clusterContext.start();
   
    cluster = clusterContext.getEntity();
    List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
    boolean exists = false;
    for(KeyspaceDefinition kDef : keyspaces) {
      if(keyspaceName.equalsIgnoreCase(kDef.getName())) {
        exists = true;
        break;
      }
    }

    if(!exists) {
      KeyspaceDefinition def = cluster.makeKeyspaceDefinition();
      def.setName(keyspaceName);
      def.setStrategyClass("org.apache.cassandra.locator.SimpleStrategy");
      Map<String, String> map = new HashMap<String, String>();
      map.put("replication_factor", "3");
      def.setStrategyOptions(map);
      cluster.addKeyspace(def);
    }
   
    context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
   
    keyspace = context.getEntity();

    KeyspaceDefinition keySpaceMeta = keyspace.describeKeyspace();
View Full Code Here

  }
 
  @Override
  protected void createBestCassandraConfig(Map<String, Object> properties,
      String clusterName, String keyspace2, String seeds2) {
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
          .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    .setClock(new MicrosecondsAsyncClock())
      )
      .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
          .setMaxConnsPerHost(20)
          .setInitConnsPerHost(2)
          .setSeeds(seeds2)
          .setConnectTimeout(10000)
    .setRetryBackoffStrategy(new FixedRetryBackoffStrategy(5000, 30000))
      )
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
   
   
  if(seeds2.contains(",")) {
    //for a multi-node cluster, we want the test suite using quorum on writes and
    //reads so we have no issues...
    AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
    config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    builder = builder.withAstyanaxConfiguration(config);
  }
  properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

//    else if(clusterNameObj == null || !(clusterNameObj instanceof String))
//      throw new IllegalArgumentException("The property Bootstrap.CLUSTER_NAME was not in the Map or was in the Map but not as a String");
    if(builderObj == null || !(builderObj instanceof Builder))
      throw new IllegalArgumentException("The property Bootstrap.CASSANDRA_BUILDER was not in the Map or was in Map but was not of type Builder and must be supplied when using Cassandra plugin");

    Builder builder = (Builder) builderObj;
    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    keyspaceName = clusterContext.getKeyspaceName();
    if(keyspaceName == null)
      throw new IllegalArgumentException("You did not call Builder.forKeyspace on the astyanax Builder api.  We need to know the keyspace to continue");
   
    clusterContext.start();
   
    cluster = clusterContext.getEntity();
    List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
    boolean exists = false;
    for(KeyspaceDefinition kDef : keyspaces) {
      if(keyspaceName.equalsIgnoreCase(kDef.getName())) {
        exists = true;
        break;
      }
    }

    if(!exists) {
      KeyspaceDefinition def = cluster.makeKeyspaceDefinition();
      def.setName(keyspaceName);
      def.setStrategyClass("org.apache.cassandra.locator.SimpleStrategy");
      Map<String, String> map = new HashMap<String, String>();
      map.put("replication_factor", "3");
      def.setStrategyOptions(map);
      cluster.addKeyspace(def);
    }
   
    context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
   
    keyspace = context.getEntity();

    KeyspaceDefinition keySpaceMeta = keyspace.describeKeyspace();
View Full Code Here

  }
 
  @Override
  protected void createBestCassandraConfig(Map<String, Object> properties,
      String clusterName, String keyspace2, String seeds2) {
    Builder builder = new AstyanaxContext.Builder()
      .forCluster(clusterName)
      .forKeyspace(keyspace2)
      .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()     
          .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
          .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
      )
      .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
          .setMaxConnsPerHost(20)
          .setInitConnsPerHost(2)
          .setSeeds(seeds2)
          .setConnectTimeout(10000)
      )
      .withConnectionPoolMonitor(new CountingConnectionPoolMonitor());
   
   
  if(seeds2.contains(",")) {
    //for a multi-node cluster, we want the test suite using quorum on writes and
    //reads so we have no issues...
    AstyanaxConfigurationImpl config = new AstyanaxConfigurationImpl();
    config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    config.setDefaultReadConsistencyLevel(ConsistencyLevel.CL_QUORUM);
    builder = builder.withAstyanaxConfiguration(config);
  }
  properties.put(Bootstrap.CASSANDRA_BUILDER, builder);
  }
View Full Code Here

//    else if(clusterNameObj == null || !(clusterNameObj instanceof String))
//      throw new IllegalArgumentException("The property Bootstrap.CLUSTER_NAME was not in the Map or was in the Map but not as a String");
    if(builderObj == null || !(builderObj instanceof Builder))
      throw new IllegalArgumentException("The property Bootstrap.CASSANDRA_BUILDER was not in the Map or was in Map but was not of type Builder and must be supplied when using Cassandra plugin");

    Builder builder = (Builder) builderObj;
    clusterContext = builder.buildCluster(ThriftFamilyFactory.getInstance());
    keyspaceName = clusterContext.getKeyspaceName();
    if(keyspaceName == null)
      throw new IllegalArgumentException("You did not call Builder.forKeyspace on the astyanax Builder api.  We need to know the keyspace to continue");
   
    clusterContext.start();
   
    cluster = clusterContext.getEntity();
    List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
    boolean exists = false;
    for(KeyspaceDefinition kDef : keyspaces) {
      if(keyspaceName.equalsIgnoreCase(kDef.getName())) {
        exists = true;
        break;
      }
    }

    if(!exists) {
      KeyspaceDefinition def = cluster.makeKeyspaceDefinition();
      def.setName(keyspaceName);
      def.setStrategyClass("org.apache.cassandra.locator.SimpleStrategy");
      Map<String, String> map = new HashMap<String, String>();
      map.put("replication_factor", "3");
      def.setStrategyOptions(map);
      cluster.addKeyspace(def);
    }
   
    context = builder.buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
   
    keyspace = context.getEntity();

    KeyspaceDefinition keySpaceMeta = keyspace.describeKeyspace();
View Full Code Here

TOP

Related Classes of com.netflix.astyanax.AstyanaxContext.Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.