public static ContextConfigurations getContextConfigurations( final String resourceShardStr, final String readConsistencyStr, final String writeConsistencyStr) { Duration resourceShard = Duration.seconds(Long.parseLong(resourceShardStr)); ConsistencyLevel readConsistency = ConsistencyLevel.valueOf(readConsistencyStr); ConsistencyLevel writeConsistency = ConsistencyLevel.valueOf(writeConsistencyStr); ContextConfigurations contexts = new ContextConfigurations(); contexts.addContextConfig(Context.DEFAULT_CONTEXT, resourceShard, readConsistency, writeConsistency); return contexts; } }
public Collection<String> getMetricNames(Context context, String resourceId) { try { ConsistencyLevel readConsistency = m_contextConfigurations.getReadConsistency(context); return getMetricNamesFromResults(fetchMetricNames(context, resourceId, readConsistency)); } catch (ExecutionException|InterruptedException e) { throw Throwables.propagate(e); } }
@Override public void delete(final Context context, final Resource resource) { final Timer.Context ctx = m_deleteTimer.time(); final ConsistencyLevel writeConsistency = m_contextConfigurations.getWriteConsistency(context); final List<RegularStatement> statements = Lists.newArrayList(); definitelyUnindexResource(statements, context, resource, writeConsistency); definitelyUnindexResourceAttributes(statements, context, resource, writeConsistency); definitelyRemoveMetricName(statements, context, resource, writeConsistency); try { if (!statements.isEmpty()) { m_session.execute(batch(statements.toArray(new RegularStatement[statements.size()]))); } m_cache.delete(context, resource); } finally { ctx.stop(); } }
public ContextConfigurations(Collection<ContextConfiguration> contextConfigs) { for (ContextConfiguration contextConfig : contextConfigs) { addContextConfig(contextConfig); } }
SelectDispatcher(SelectConfig config) { super(config); m_config = config; CassandraSession session = new CassandraSessionImpl( config.getCassandraKeyspace(), config.getCassandraHost(), config.getCassandraPort(), config.getCassandraCompression(), config.getCassandraUsername(), config.getCassandraPassword(), config.getCassandraSsl()); m_repository = new CassandraSampleRepository( session, Config.CASSANDRA_TTL, m_metricRegistry, new DefaultSampleProcessorService(1), new ContextConfigurations()); m_queryQueue = Queues.newArrayBlockingQueue(config.getThreads() * 10); }
private Iterator<com.datastax.driver.core.Row> cassandraSelect(Context context, Resource resource, Timestamp start, Timestamp end) { List<Future<ResultSet>> futures = Lists.newArrayList(); Duration resourceShard = m_contextConfigurations.getResourceShard(context); Timestamp lower = start.stepFloor(resourceShard); Timestamp upper = end.stepFloor(resourceShard); for (Timestamp partition : new IntervalGenerator(lower, upper, resourceShard)) { BoundStatement bindStatement = m_selectStatement.bind(); bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId()); bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds()); bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId()); bindStatement.setTimestamp("start", start.asDate()); bindStatement.setTimestamp("end", end.asDate()); // Use the context specific consistency level bindStatement.setConsistencyLevel(m_contextConfigurations.getReadConsistency(context)); futures.add(m_session.executeAsync(bindStatement)); } return new ConcurrentResultWrapper(futures); }
Duration resourceShard = m_contextConfigurations.getResourceShard(m.getContext()); insert.setConsistencyLevel(m_contextConfigurations.getWriteConsistency(m.getContext()));
final Timestamp end = Timestamp.now(); final Duration resourceShard = m_contextConfigurations.getResourceShard(context); final Duration resourceShard = m_contextConfigurations.getResourceShard(context);
private List<Statement> toStatements(Set<StatementGenerator> generators) { List<Statement> statementsToExecute = Lists.newArrayList(); Map<String, List<Statement>> statementsByKey = Maps.newHashMap(); for (StatementGenerator generator : generators) { Statement statement = generator.toStatement() .setConsistencyLevel(m_contextConfigurations.getWriteConsistency(generator.getContext())); String key = generator.getKey(); if (key == null) { // Don't try batching these statementsToExecute.add(statement); continue; } // Group these by key List<Statement> statementsForKey = statementsByKey.get(key); if (statementsForKey == null) { statementsForKey = Lists.newArrayList(); statementsByKey.put(key, statementsForKey); } statementsForKey.add(statement); } // Consolidate the grouped statements into batches for (List<Statement> statementsForKey: statementsByKey.values()) { for (List<Statement> partition : Lists.partition(statementsForKey, m_options.getMaxBatchSize())) { statementsToExecute.add(unloggedBatch(partition.toArray(new RegularStatement[partition.size()]))); } } return statementsToExecute; }
public ContextConfigurations(Collection<ContextConfiguration> contextConfigs) { for (ContextConfiguration contextConfig : contextConfigs) { addContextConfig(contextConfig); } }
config.getCassandraSsl()); ContextConfigurations contexts = new ContextConfigurations(); Set<SampleProcessor> processors = Sets.newHashSet();
public static ContextConfigurations getContextConfigurations( final String resourceShardStr, final String readConsistencyStr, final String writeConsistencyStr) { Duration resourceShard = Duration.seconds(Long.parseLong(resourceShardStr)); ConsistencyLevel readConsistency = ConsistencyLevel.valueOf(readConsistencyStr); ConsistencyLevel writeConsistency = ConsistencyLevel.valueOf(writeConsistencyStr); ContextConfigurations contexts = new ContextConfigurations(); contexts.addContextConfig(Context.DEFAULT_CONTEXT, resourceShard, readConsistency, writeConsistency); return contexts; } }
public Map<String, String> getResourceAttributes(Context context, String resourceId) { try { ConsistencyLevel readConsistency = m_contextConfigurations.getReadConsistency(context); return getResourceAttributesFromResults(fetchResourceAttributes(context, resourceId, readConsistency)); } catch (ExecutionException|InterruptedException e) { throw Throwables.propagate(e); } }
@Override public void delete(final Context context, final Resource resource) { final Timer.Context ctx = m_deleteTimer.time(); final ConsistencyLevel writeConsistency = m_contextConfigurations.getWriteConsistency(context); final List<RegularStatement> statements = Lists.newArrayList(); definitelyUnindexResource(statements, context, resource, writeConsistency); definitelyUnindexResourceAttributes(statements, context, resource, writeConsistency); definitelyRemoveMetricName(statements, context, resource, writeConsistency); try { if (!statements.isEmpty()) { m_session.execute(batch(statements.toArray(new RegularStatement[statements.size()]))); } m_cache.delete(context, resource); } finally { ctx.stop(); } }
ContextConfigurations contextConfigurations = new ContextConfigurations(); for (ContextConfig contextConfig : m_newtsConf.getContextConfigs().values()) { contextConfigurations.addContextConfig(contextConfig.getContext(), contextConfig.getResourceShard(), contextConfig.getReadConsistency(), contextConfig.getWriteConsistency());
public Collection<String> getMetricNames(Context context, String resourceId) { try { ConsistencyLevel readConsistency = m_contextConfigurations.getReadConsistency(context); return getMetricNamesFromResults(fetchMetricNames(context, resourceId, readConsistency)); } catch (ExecutionException|InterruptedException e) { throw Throwables.propagate(e); } }
private List<Statement> toStatements(Set<StatementGenerator> generators) { List<Statement> statementsToExecute = Lists.newArrayList(); Map<String, List<Statement>> statementsByKey = Maps.newHashMap(); for (StatementGenerator generator : generators) { Statement statement = generator.toStatement() .setConsistencyLevel(m_contextConfigurations.getWriteConsistency(generator.getContext())); String key = generator.getKey(); if (key == null) { // Don't try batching these statementsToExecute.add(statement); continue; } // Group these by key List<Statement> statementsForKey = statementsByKey.get(key); if (statementsForKey == null) { statementsForKey = Lists.newArrayList(); statementsByKey.put(key, statementsForKey); } statementsForKey.add(statement); } // Consolidate the grouped statements into batches for (List<Statement> statementsForKey: statementsByKey.values()) { for (List<Statement> partition : Lists.partition(statementsForKey, m_options.getMaxBatchSize())) { statementsToExecute.add(unloggedBatch(partition.toArray(new RegularStatement[partition.size()]))); } } return statementsToExecute; }
ContextConfigurations contextConfigurations = new ContextConfigurations(); for (ContextConfig contextConfig : m_newtsConf.getContextConfigs().values()) { contextConfigurations.addContextConfig(contextConfig.getContext(), contextConfig.getResourceShard(), contextConfig.getReadConsistency(), contextConfig.getWriteConsistency());
public Map<String, String> getResourceAttributes(Context context, String resourceId) { try { ConsistencyLevel readConsistency = m_contextConfigurations.getReadConsistency(context); return getResourceAttributesFromResults(fetchResourceAttributes(context, resourceId, readConsistency)); } catch (ExecutionException|InterruptedException e) { throw Throwables.propagate(e); } }
for (StatementGenerator generator : generators) { Statement statement = generator.toStatement() .setConsistencyLevel(contextConfigurations.getWriteConsistency(generator.getContext())); String key = generator.getKey(); if (key == null) {