me.prettyprint.cassandra.service.ThriftKsDef Java Examples

The following examples show how to use me.prettyprint.cassandra.service.ThriftKsDef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraService.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/** Create the keyspace */
private void createKeySpace( String keyspace ) {
    logger.info( "Creating keyspace: {}", keyspace );

    String strategy_class =
            getString( properties, "cassandra.keyspace.strategy", "org.apache.cassandra.locator.SimpleStrategy" );
    logger.info( "Using strategy: {}", strategy_class );

    int replication_factor = getIntValue( properties, "cassandra.keyspace.replication", 1 );
    logger.info( "Using replication (may be overriden by strategy options): {}", replication_factor );

    // try {
    ThriftKsDef ks_def = ( ThriftKsDef ) HFactory
            .createKeyspaceDefinition( keyspace, strategy_class, replication_factor,
                    new ArrayList<ColumnFamilyDefinition>() );

    @SuppressWarnings({ "unchecked", "rawtypes" }) Map<String, String> strategy_options =
            filter( ( Map ) properties, "cassandra.keyspace.strategy.options.", true );
    if ( strategy_options.size() > 0 ) {
        logger.info( "Strategy options: {}", mapToFormattedJsonString( strategy_options ) );
        ks_def.setStrategyOptions( strategy_options );
    }

    cluster.addKeyspace( ks_def );

    waitForCreation( keyspace );

    logger.info( "Created keyspace {}", keyspace );
}
 
Example #2
Source File: SchemaBuilder.java    From oneops with Apache License 2.0 4 votes vote down vote up
private static void createFreshSchema(Cluster cluster, String keyspaceName) {
	ColumnFamilyDefinition cfThresholdsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			THRESHOLDS_CF, 
               ComparatorType.BYTESTYPE);
	cfThresholdsDef.setColumnType(ColumnType.SUPER);
	cfThresholdsDef.setSubComparatorType(ComparatorType.BYTESTYPE);
	
	ColumnFamilyDefinition cfManifestMapDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			MANIFESTMAP_CF, 
               ComparatorType.BYTESTYPE);

	ColumnFamilyDefinition cfRealizedAsMapDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			REALIZED_AS_CF, 
               ComparatorType.LONGTYPE);
	
	ColumnFamilyDefinition cfOpsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			OPS_EVENTS_CF, 
               ComparatorType.LONGTYPE);

	ColumnFamilyDefinition cfCiStateHistDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			CI_STATE_HIST_CF, 
               ComparatorType.LONGTYPE);

	ColumnFamilyDefinition cfCiOpenEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			CI_OPEN_EVENTS_CF, 
               ComparatorType.BYTESTYPE);
	cfCiOpenEventsDef.setColumnType(ColumnType.SUPER);
	cfCiOpenEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE);

	ColumnFamilyDefinition cfComponentStateDef = HFactory.createColumnFamilyDefinition(keyspaceName,                              
			COMPONENT_STATE_CF, 
               ComparatorType.BYTESTYPE);
	cfComponentStateDef.setColumnType(ColumnType.STANDARD);
	cfComponentStateDef.setDefaultValidationClass(ComparatorType.COUNTERTYPE.getClassName());
	cfComponentStateDef.setKeyValidationClass(ComparatorType.LONGTYPE.getClassName());
	
	ColumnFamilyDefinition cfOrphanEventsDef = HFactory.createColumnFamilyDefinition(keyspaceName,
			ORPHAN_CLOSE_EVENTS_CF, 
			ComparatorType.LONGTYPE);
	cfOrphanEventsDef.setColumnType(ColumnType.SUPER);
	cfOrphanEventsDef.setSubComparatorType(ComparatorType.BYTESTYPE);

	KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition(keyspaceName,                 
	              ThriftKsDef.DEF_STRATEGY_CLASS,  
	              1,
	              Arrays.asList(cfThresholdsDef,cfManifestMapDef, cfRealizedAsMapDef, cfOpsDef, cfCiStateHistDef, cfCiOpenEventsDef, cfComponentStateDef));
	//Add the schema to the cluster.
	//"true" as the second param means that Hector will block until all nodes see the change.
	cluster.addKeyspace(newKeyspace, true);
	logger.info("Added keyspace " + keyspaceName);
}