com.netflix.astyanax.Keyspace Java Examples

The following examples show how to use com.netflix.astyanax.Keyspace. 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: ShardedEdgeSerializationImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Inject
public ShardedEdgeSerializationImpl( final Keyspace keyspace, final CassandraConfig cassandraConfig,
                                     final GraphFig graphFig, final EdgeShardStrategy writeEdgeShardStrategy,
                                     final TimeService timeService,
                                     final EdgeShardSerialization edgeShardSerialization ) {


    checkNotNull( "keyspace required", keyspace );
    checkNotNull( "cassandraConfig required", cassandraConfig );
    checkNotNull( "consistencyFig required", graphFig );
    checkNotNull( "writeEdgeShardStrategy required", writeEdgeShardStrategy );
    checkNotNull( "timeService required", timeService );
    checkNotNull( "edgeShardSerialization required", edgeShardSerialization );



    this.keyspace = keyspace;
    this.cassandraConfig = cassandraConfig;
    this.graphFig = graphFig;
    this.writeEdgeShardStrategy = writeEdgeShardStrategy;
    this.timeService = timeService;
    this.edgeShardSerialization = edgeShardSerialization;
}
 
Example #2
Source File: MarkCommit.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Inject
public MarkCommit( final MvccLogEntrySerializationStrategy logStrat,
                   final MvccEntitySerializationStrategy entityStrat,
                   final UniqueValueSerializationStrategy uniqueValueStrat,
                   final SerializationFig serializationFig,
                   final ActorSystemFig actorSystemFig,
                   final UniqueValuesFig uniqueValuesFig,
                   final UniqueValuesService uniqueValuesService,
                   final Keyspace keyspace ) {


    Preconditions.checkNotNull( logStrat, "logEntrySerializationStrategy is required" );
    Preconditions.checkNotNull( entityStrat, "entitySerializationStrategy is required" );

    this.logStrat = logStrat;
    this.entityStrat = entityStrat;
    this.serializationFig = serializationFig;
    this.uniqueValueStrat = uniqueValueStrat;
    this.actorSystemFig = actorSystemFig;
    this.uniqueValuesFig = uniqueValuesFig;
    this.uniqueValuesService = uniqueValuesService;
    this.keyspace = keyspace;
}
 
Example #3
Source File: CassandraTableResourceFactory.java    From staash with Apache License 2.0 6 votes vote down vote up
@Override
public TableDataResource getTableDataResource(TableEntity table) throws NotFoundException {
    //Log.info(table.toString());
    
    String clusterName      = table.getOption("cassandra.cluster");
    String keyspaceName     = table.getOption("cassandra.keyspace");
    String columnFamilyName = table.getOption("cassandra.columnfamily");
    String discoveryType    = table.getOption("discovery");
    if (discoveryType == null)
        discoveryType = "eureka";
    
    Preconditions.checkNotNull(clusterName,      "Must specify cluster name for table "       + table.getTableName());
    Preconditions.checkNotNull(keyspaceName,     "Must specify keyspace name for table "      + table.getTableName());
    Preconditions.checkNotNull(columnFamilyName, "Must specify column family name for table " + table.getTableName());
    Preconditions.checkNotNull(discoveryType,    "Must specify discovery type for table "     + table.getTableName());
    
    Keyspace keyspace = clientProvider.acquireKeyspace(new KeyspaceKey(new ClusterKey(clusterName, discoveryType), keyspaceName));
    
    return new AstyanaxThriftDataTableResource(keyspace, columnFamilyName);
}
 
Example #4
Source File: TestChunking.java    From staash with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
			.forCluster("Test Cluster")
			.forKeyspace(KS)
			.withAstyanaxConfiguration(
					new AstyanaxConfigurationImpl()
							.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE))
			.withConnectionPoolConfiguration(
					new ConnectionPoolConfigurationImpl("MyConnectionPool")
							.setPort(9160).setMaxConnsPerHost(1)
							.setSeeds("127.0.0.1:9160"))
			.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
			.buildKeyspace(ThriftFamilyFactory.getInstance());

	context.start();
	keyspace = context.getClient();
}
 
Example #5
Source File: InstanceDataDAOCassandra.java    From Raigad with Apache License 2.0 6 votes vote down vote up
private AstyanaxContext<Keyspace> initWithThriftDriverWithExternalHostsSupplier() {
    logger.info("Boot cluster (BOOT_CLUSTER) is {}, keyspace name (KS_NAME) is {}", BOOT_CLUSTER, KS_NAME);

    return new AstyanaxContext.Builder()
            .forCluster(BOOT_CLUSTER)
            .forKeyspace(KS_NAME)
            .withAstyanaxConfiguration(
                    new AstyanaxConfigurationImpl()
                            .setDiscoveryType(
                                    NodeDiscoveryType.DISCOVERY_SERVICE)
                            .setConnectionPoolType(
                                    ConnectionPoolType.ROUND_ROBIN))
            .withConnectionPoolConfiguration(
                    new ConnectionPoolConfigurationImpl(
                            "MyConnectionPool")
                            .setMaxConnsPerHost(3)
                            .setPort(thriftPortForAstyanax))
            .withHostSupplier(getSupplier())
            .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
            .buildKeyspace(ThriftFamilyFactory.getInstance());

}
 
Example #6
Source File: MarkCommitTest.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateStage( final CollectionIoEvent<MvccEntity> event ) {
    /**
     * Write up mock mutations so we don't npe on the our operations, but rather on the input
     */
    final MvccLogEntrySerializationStrategy logStrategy = mock( MvccLogEntrySerializationStrategy.class );
    final MutationBatch logMutation = mock( MutationBatch.class );
    final MvccEntitySerializationStrategy mvccEntityStrategy = mock( MvccEntitySerializationStrategy.class );
    final MutationBatch entityMutation = mock( MutationBatch.class );
    final SerializationFig serializationFig = mock(SerializationFig.class);
    final UniqueValueSerializationStrategy uniqueValueSerializationStrategy = mock(UniqueValueSerializationStrategy.class);
    final Keyspace keyspace = mock( Keyspace.class );

    when(keyspace.prepareMutationBatch()).thenReturn( entityMutation );

    when( logStrategy.write( any( ApplicationScope.class ), any( MvccLogEntry.class ) ) ).thenReturn( logMutation );
    when( mvccEntityStrategy.write( any( ApplicationScope.class ), any( MvccEntity.class ) ) )
            .thenReturn( entityMutation );


    new MarkCommit( logStrategy, mvccEntityStrategy, uniqueValueSerializationStrategy, serializationFig,
        null, null, null, keyspace ).call( event );

    //TODO: This doesn't assert anything, this needs fixed (should be a fail technically)
}
 
Example #7
Source File: EdgeMetadataSerializationV2Impl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Inject
public EdgeMetadataSerializationV2Impl( final Keyspace keyspace, final CassandraConfig cassandraConfig,
                                        final GraphFig graphFig ) {

    Preconditions.checkNotNull( "cassandraConfig is required", cassandraConfig );
    Preconditions.checkNotNull( "consistencyFig is required", graphFig );
    Preconditions.checkNotNull( "keyspace is required", keyspace );

    this.keyspace = keyspace;
    this.cassandraConfig = cassandraConfig;
    this.graphFig = graphFig;

    //set up the shard locator instances
    idExpandingShardLocator = new ExpandingShardLocator<>( ID_FUNNEL, cassandraConfig.getShardSettings() );

    edgeTypeExpandingShardLocator =
            new ExpandingShardLocator<>( EDGE_TYPE_FUNNEL, cassandraConfig.getShardSettings() );
}
 
Example #8
Source File: AstyanaxSupport.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
public AstyanaxContext<Keyspace> newAstyanaxContextForKeyspace(String keyspace) {
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
            .forCluster(clusterName)
            .forKeyspace(keyspace)
            .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                    .setDiscoveryType(NodeDiscoveryType.NONE))
            .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("BrooklynPool")
                    .setPort(thriftPort)
                    .setMaxConnsPerHost(1)
                    .setConnectTimeout(5000) // 10s
                    .setSeeds(String.format("%s:%d", hostname, thriftPort)))
            .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
            .buildKeyspace(ThriftFamilyFactory.getInstance());

    context.start();
    return context;
}
 
Example #9
Source File: MultiRowShardColumnIterator.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public MultiRowShardColumnIterator( final Keyspace keyspace, final ColumnFamily<R, C> cf,
                                    final ConsistencyLevel consistencyLevel, final ColumnParser<C, T> columnParser,
                                    final ColumnSearch<T> columnSearch, final Comparator<T> comparator,
                                    final int pageSize, final List<SmartShard> rowKeysWithShardEnd,
                                    final boolean ascending, final Optional<Long> lastTimestamp) {
    this.cf = cf;
    this.pageSize = pageSize;
    this.columnParser = columnParser;
    this.columnSearch = columnSearch;
    this.comparator = comparator;
    this.keyspace = keyspace;
    this.consistencyLevel = consistencyLevel;
    this.moreToReturn = true;
    this.rowKeysWithShardEnd = rowKeysWithShardEnd;
    this.resultsTracking = new ArrayList<>();
    this.ascending = ascending;
    this.lastTimestamp = lastTimestamp;


}
 
Example #10
Source File: WriteUniqueVerify.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Inject
public WriteUniqueVerify(final UniqueValueSerializationStrategy uniqueValueSerializiationStrategy,
                         final SerializationFig serializationFig,
                         final Keyspace keyspace,
                         final CassandraConfig cassandraFig,
                         final ActorSystemFig actorSystemFig,
                         final UniqueValuesFig uniqueValuesFig,
                         final UniqueValuesService akkaUvService,
                         final Session session ) {

    this.keyspace = keyspace;
    this.cassandraFig = cassandraFig;
    this.actorSystemFig = actorSystemFig;
    this.uniqueValuesFig = uniqueValuesFig;
    this.akkaUvService = akkaUvService;
    this.session = session;

    Preconditions.checkNotNull( uniqueValueSerializiationStrategy, "uniqueValueSerializationStrategy is required" );
    Preconditions.checkNotNull( serializationFig, "serializationFig is required" );

    this.uniqueValueStrat = uniqueValueSerializiationStrategy;
    this.serializationFig = serializationFig;

    uniqueVerifyPoolSize = this.serializationFig.getUniqueVerifyPoolSize();
}
 
Example #11
Source File: MultiRowColumnIterator.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * Create the iterator
 */
public MultiRowColumnIterator( final Keyspace keyspace, final ColumnFamily<R, C> cf,
                               final ConsistencyLevel consistencyLevel, final ColumnParser<C, T> columnParser,
                               final ColumnSearch<T> columnSearch, final Comparator<T> comparator,
                               final Collection<R> rowKeys, final int pageSize ) {
    this.cf = cf;
    this.pageSize = pageSize;
    this.columnParser = columnParser;
    this.columnSearch = columnSearch;
    this.comparator = comparator;
    this.rowKeys = rowKeys;
    this.keyspace = keyspace;
    this.consistencyLevel = consistencyLevel;
    this.moreToReturn = true;

    //        seenResults = new HashMap<>( pageSize * 10 );
}
 
Example #12
Source File: CassandraMutagenImpl.java    From mutagen-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 *
 *
 */
@Override
public Plan.Result<Integer> mutate(Keyspace keyspace) {
	// Do this in a VM-wide critical section. External cluster-wide 
	// synchronization is going to have to happen in the coordinator.
	synchronized (System.class) {
		CassandraCoordinator coordinator=new CassandraCoordinator(keyspace);
		CassandraSubject subject=new CassandraSubject(keyspace);

		Planner<Integer> planner=
			new CassandraPlanner(keyspace,getResources());
		Plan<Integer> plan=planner.getPlan(subject,coordinator);

		// Execute the plan
		Plan.Result<Integer> result=plan.execute();
		return result;
	}
}
 
Example #13
Source File: MetaDaoImpl.java    From staash with Apache License 2.0 6 votes vote down vote up
@Override
public void writeMetaEntity(Entity entity) {
    // TODO Auto-generated method stub
    Keyspace ks = kscp.acquireKeyspace("meta");
    ks.prepareMutationBatch();
    MutationBatch m;
    OperationResult<Void> result;
    m = ks.prepareMutationBatch();
    m.withRow(dbcf, entity.getRowKey()).putColumn(entity.getName(), entity.getPayLoad(), null);
    try {
        result = m.execute();
        if (entity instanceof PaasTableEntity) {
            String schemaName = ((PaasTableEntity)entity).getSchemaName();
            Keyspace schemaks = kscp.acquireKeyspace(schemaName);
            ColumnFamily<String, String> cf = ColumnFamily.newColumnFamily(entity.getName(), StringSerializer.get(), StringSerializer.get());
            schemaks.createColumnFamily(cf, null);
        }
        int i = 0;
    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
Example #14
Source File: Migration.java    From blueflood with Apache License 2.0 6 votes vote down vote up
private static AstyanaxContext<Keyspace> connect(String host, int port, String keyspace, int threads, NodeDiscoveryType discovery) {
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
                    .forKeyspace(keyspace)
            .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
                .setDiscoveryType(discovery)
                .setRetryPolicy(new RetryNTimes(10)))
                
            .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl(host + ":" + keyspace)
                    .setMaxConns(threads * 2)
                    .setSeeds(host)
                    .setPort(port)
                    .setRetryBackoffStrategy(new FixedRetryBackoffStrategy(1000, 1000)))
            .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
            .buildKeyspace(ThriftFamilyFactory.getInstance());
    context.start();
    return context;
}
 
Example #15
Source File: EdgeMetaRepairImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Inject
public EdgeMetaRepairImpl( final EdgeMetadataSerialization edgeMetadataSerialization, final Keyspace keyspace,
                           final GraphFig graphFig, final EdgeSerialization storageEdgeSerialization ) {


    Preconditions.checkNotNull( "edgeMetadataSerialization is required", edgeMetadataSerialization );
    Preconditions.checkNotNull( "storageEdgeSerialization is required", storageEdgeSerialization );
    Preconditions.checkNotNull( "consistencyFig is required", graphFig );
    Preconditions.checkNotNull( "cassandraConfig is required", graphFig );
    Preconditions.checkNotNull( "keyspace is required", keyspace );

    this.edgeMetadataSerialization = edgeMetadataSerialization;
    this.keyspace = keyspace;
    this.graphFig = graphFig;
    this.storageEdgeSerialization = storageEdgeSerialization;
}
 
Example #16
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 6 votes vote down vote up
private List<CfSplit> getCfSplits(Table tbl, int desiredRecordsPerSplit, @Nullable String fromKey) {
    checkNotNull(tbl, "table");

    AstyanaxTable table = (AstyanaxTable) tbl;
    AstyanaxStorage storage = table.getReadStorage();
    DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
    Keyspace keyspace = placement.getKeyspace().getAstyanaxKeyspace();
    ColumnFamily<ByteBuffer, DeltaKey> cf = placement.getBlockedDeltaColumnFamily();

    // Create at least one split per shard, perhaps more if a shard is large.
    List<CfSplit> splits = Lists.newArrayList();
    Iterator<ByteBufferRange> it = storage.scanIterator(fromKey);
    Collection<TokenRange> allTokenRanges = describeCassandraTopology(keyspace).values();
    while (it.hasNext()) {
        ByteBufferRange keyRange = it.next();

        String start = toTokenString(keyRange.getStart());
        String end = toTokenString(keyRange.getEnd());

        splits.addAll(getCfSplits(keyspace, cf, start, end, desiredRecordsPerSplit, allTokenRanges));
    }
    return splits;
}
 
Example #17
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the topology for a Cassandra keyspace as a Multimap, where the keys identify a rack (or availability zone
 * in Amazon) and the values are the token ranges for each host in that rack.  For example, for a well distributed
 * ring of 12 hosts and a replication factor of 3 this method would return a Multimap with 3 keys and each key would
 * contain 4 token ranges.
 */
private Multimap<String, TokenRange> describeCassandraTopology(final Keyspace keyspace) {
    try {
        @SuppressWarnings ("unchecked")
        ConnectionPool<Cassandra.Client> connectionPool = (ConnectionPool<Cassandra.Client>) keyspace.getConnectionPool();

        return connectionPool.executeWithFailover(
                new AbstractKeyspaceOperationImpl<Multimap<String, TokenRange>>(EmptyKeyspaceTracerFactory.getInstance().newTracer(CassandraOperationType.DESCRIBE_RING), keyspace.getKeyspaceName()) {
                    @Override
                    protected Multimap<String, TokenRange> internalExecute(Cassandra.Client client, ConnectionContext state)
                            throws Exception {
                        Multimap<String, TokenRange> racks = ArrayListMultimap.create();
                        for (org.apache.cassandra.thrift.TokenRange tokenRange : client.describe_local_ring(getKeyspace())) {
                            // The final local endpoint "owns" the token range, the rest are for replication
                            EndpointDetails endpointDetails = Iterables.getLast(tokenRange.getEndpoint_details());
                            racks.put(endpointDetails.getRack(),
                                    new TokenRangeImpl(tokenRange.getStart_token(), tokenRange.getEnd_token(), tokenRange.getEndpoints()));
                        }
                        return Multimaps.unmodifiableMultimap(racks);
                    }
                },
                keyspace.getConfig().getRetryPolicy().duplicate()).getResult();
    } catch (ConnectionException e) {
        throw Throwables.propagate(e);
    }
}
 
Example #18
Source File: MigrationManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Inject
public MigrationManagerImpl( final CassandraFig cassandraFig, final Keyspace keyspace,
                             final Set<Migration> migrations, final DataStaxCluster dataStaxCluster) {

    this.cassandraFig = cassandraFig;
    this.keyspace = keyspace;
    this.migrations = migrations;
    this.dataStaxCluster = dataStaxCluster;
}
 
Example #19
Source File: ShardsColumnIterator.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public ShardsColumnIterator(final EdgeSearcher<R, C, T> searcher,
                            final MultiTenantColumnFamily<ScopedRowKey<R>, C> cf, final Keyspace keyspace,
                            final ConsistencyLevel consistencyLevel, final int pageSize,
                            final boolean smartShardSeekEnabled) {
    this.searcher = searcher;
    this.cf = cf;
    this.keyspace = keyspace;
    this.pageSize = pageSize;
    this.consistencyLevel = consistencyLevel;
    this.smartShardSeekEnabled = smartShardSeekEnabled;
}
 
Example #20
Source File: AstyanaxDao.java    From staash with Apache License 2.0 5 votes vote down vote up
public AstyanaxDao(Keyspace keyspace, Class<T> entityType, String columnFamilyName) {
    this.keyspace     = keyspace;
    this.entityName   = entityNameFromClass(entityType);
    this.columnFamily = new ColumnFamily<String, String>(columnFamilyName, StringSerializer.get(), StringSerializer.get());
    this.prefix       = this.entityName + ":";
    
    manager = new DefaultEntityManager.Builder<T, String>()
            .withKeyspace(keyspace)
            .withColumnFamily(columnFamily)
            .withEntityType(entityType)
            .build();
}
 
Example #21
Source File: AstyanaxDaoSchemaProvider.java    From staash with Apache License 2.0 5 votes vote down vote up
public AstyanaxDaoSchema(String schemaName, Keyspace keyspace) {
    this.keyspace = keyspace;
    this.schemaName = schemaName;
    
    Configuration config = configuration.subset(String.format(CONFIG_PREFIX_FORMAT, schemaName.toLowerCase()));
    if (config.getBoolean("autocreate", false)) {
        try {
            createSchema();
        }
        catch (Exception e) {
            LOG.error("Error creating column keyspace", e);
        }
    }
}
 
Example #22
Source File: EdgeDataMigrationImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Inject
public EdgeDataMigrationImpl( final Keyspace keyspace, final GraphManagerFactory graphManagerFactory,
                              final EdgesObservable edgesFromSourceObservable,
                              final VersionedMigrationSet<EdgeMetadataSerialization> allVersions,
                              final EdgeMetadataSerializationV2Impl edgeMetadataSerializationV2,
                              final MigrationDataProvider<GraphNode> migrationDataProvider ) {

    this.keyspace = keyspace;
    this.graphManagerFactory = graphManagerFactory;
    this.edgesFromSourceObservable = edgesFromSourceObservable;
    this.allVersions = allVersions;
    this.edgeMetadataSerializationV2 = edgeMetadataSerializationV2;
    this.migrationDataProvider = migrationDataProvider;
}
 
Example #23
Source File: AstyanaxDaoSchemaProvider.java    From staash with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized DaoSchema getSchema(String schemaName) throws NotFoundException {
    AstyanaxDaoSchema schema = (AstyanaxDaoSchema)schemas.get(schemaName);
    if (schema == null) {
        LOG.info("Creating schema '{}'", new Object[]{schemaName});
        Keyspace keyspace = keyspaceProvider.acquireKeyspace(schemaName);
        schema = new AstyanaxDaoSchema(schemaName, keyspace);
        schemas.put(schemaName, schema);
    }
    return schema;
}
 
Example #24
Source File: MvccLogEntrySerializationProxyImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Inject
public MvccLogEntrySerializationProxyImpl( final Keyspace keyspace,
                                           final VersionedMigrationSet<MvccLogEntrySerializationStrategy>
                                               allVersions,
                                           final MigrationInfoCache migrationInfoCache ) {

    this.keyspace = keyspace;
    this.migrationInfoCache = migrationInfoCache;
    this.versions = allVersions;
}
 
Example #25
Source File: MvccEntitySerializationStrategyProxyImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Inject
public MvccEntitySerializationStrategyProxyImpl( final Keyspace keyspace,
                                                 final VersionedMigrationSet<MvccEntitySerializationStrategy> allVersions,
                                                 final MigrationInfoCache migrationInfoCache ) {

    this.keyspace = keyspace;
    this.migrationInfoCache = migrationInfoCache;
    this.versions = allVersions;
}
 
Example #26
Source File: DefaultKeyspaceClientProvider.java    From staash with Apache License 2.0 5 votes vote down vote up
@Override
public Keyspace acquireKeyspace(KeyspaceKey key) {
    String schemaName = key.getSchemaName().toLowerCase();
    
    Preconditions.checkNotNull(schemaName, "Invalid schema name 'null'");
    
    KeyspaceContextHolder holder = contextMap.get(schemaName);
    if (holder == null) {
        Preconditions.checkNotNull(key.getClusterName(),   "Missing cluster name for schema " + schemaName);
        Preconditions.checkNotNull(key.getKeyspaceName(),  "Missing cluster name for schema " + schemaName);
        Preconditions.checkNotNull(key.getDiscoveryType(), "Missing cluster name for schema " + schemaName);
        
        HostSupplierProvider hostSupplierProvider = hostSupplierProviders.get(key.getDiscoveryType());
        Preconditions.checkNotNull(hostSupplierProvider, "Unknown host supplier provider " + key.getDiscoveryType());
        
        AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
            .forCluster(key.getClusterName())
            .forKeyspace(key.getKeyspaceName())
            .withAstyanaxConfiguration(configurationProvider.get(schemaName))
            .withConnectionPoolConfiguration(cpProvider.get(schemaName))
            .withConnectionPoolMonitor(monitorProvider.get(schemaName))
            .withHostSupplier(hostSupplierProvider.getSupplier(key.getClusterName()))
            .buildKeyspace(ThriftFamilyFactory.getInstance());
        
        holder = new KeyspaceContextHolder(context);
        contextMap.put(schemaName, holder);
        holder.start();
    }
    holder.addRef();
    
    return holder.getKeyspace();
}
 
Example #27
Source File: MvccEntitySerializationStrategyV3Impl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Inject
public MvccEntitySerializationStrategyV3Impl( final Keyspace keyspace, final SerializationFig serializationFig,
                                              final CassandraFig cassandraFig, final MetricsFactory metricsFactory ) {
    this.keyspace = keyspace;
    this.serializationFig = serializationFig;
    this.cassandraFig = cassandraFig;
    this.entitySerializer = new EntitySerializer( serializationFig, metricsFactory );
}
 
Example #28
Source File: AstyanaxThriftTest.java    From staash with Apache License 2.0 5 votes vote down vote up
@Test
    @Ignore
    public void testReadData() throws Exception {
        
        KeyspaceClientProvider clientProvider = injector.getInstance(KeyspaceClientProvider.class);
        Keyspace keyspace = clientProvider.acquireKeyspace(new KeyspaceKey(new ClusterKey(LOCAL_DISCOVERY_TYPE, CLUSTER_NAME), KEYSPACE_NAME));
//        
//        // Create the keyspace and column family
//        keyspace.createKeyspace(new Properties());
//        Properties props = new Properties();
//        props.setProperty("name",                   CF_NAME);
//        props.setProperty("comparator_type",        "LongType");
//        props.setProperty("key_validation_class",   "LongType");
//        keyspace.createColumnFamily(props);
//        
//        // Add some data
        TableDataResource thriftDataTableResource = new AstyanaxThriftDataTableResource(keyspace, CF_NAME);

        String rowKey = "100";
        
        SchemalessRows.Builder builder = SchemalessRows.builder();
        builder.addRow(rowKey, ImmutableMap.<String, String>builder().put("1", "11").put("2", "22").build());
        RowData dr = new RowData();
        dr.setSrows(builder.build());
        
//        thriftDataTableResource.updateRow(rowKey, dr);
        
        QueryResult result;
        
        result = thriftDataTableResource.readRow(rowKey,  1, null, null, false);
//        Assert.assertEquals(1,  Iterables.getFirst(result.getSrows().getRows(), null).getColumns().size());
        LOG.info(result.toString());
        
        result = thriftDataTableResource.readRow(rowKey, 10, null, null, false);
//        Assert.assertEquals(2,  Iterables.getFirst(result.getRows(), null).getColumns().size());
        
        LOG.info(result.toString());
    }
 
Example #29
Source File: EdgeDeleteRepairImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Inject
public EdgeDeleteRepairImpl( final EdgeSerialization storageSerialization,
                             final GraphFig graphFig, final Keyspace keyspace ) {

    Preconditions.checkNotNull( "storageSerialization is required", storageSerialization );
    Preconditions.checkNotNull( "consistencyFig is required", graphFig );
    Preconditions.checkNotNull( "keyspace is required", keyspace );


    this.storageSerialization = storageSerialization;
    this.graphFig = graphFig;
    this.keyspace = keyspace;
}
 
Example #30
Source File: BasicCassandraRepositoryConfig.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/** Construct the config with defaults if necessary */
public CassandraArchiveRepositoryConfig build() throws IOException {
    Keyspace keyspace = cassandraGateway.getKeyspace();
    String columnFamilyName = cassandraGateway.getColumnFamily();
    String buildRepositoryId = repositoryId;
    if (buildRepositoryId == null) {
        buildRepositoryId = keyspace.getKeyspaceName() + "-" + columnFamilyName;
    }
    Path buildArchiveDir = archiveOutputDirectory;
    if (buildArchiveDir == null) {
        buildArchiveDir = Files.createTempDirectory("ScriptArchiveOutputDir");
    }
    return new BasicCassandraRepositoryConfig(buildRepositoryId, cassandraGateway, shardCount, fetchBatchSize, buildArchiveDir, specSerializer);
}