use of com.datastax.driver.core.BoundStatement in project newts by OpenNMS.
the class CassandraSearcher method fetchMetricNames.
private ResultSetFuture fetchMetricNames(Context context, String resourceId, ConsistencyLevel readConsistency) {
BoundStatement bindStatement = m_selectMetricNamesStatement.bind();
bindStatement.setString(Schema.C_METRICS_CONTEXT, context.getId());
bindStatement.setString(Schema.C_METRICS_RESOURCE, resourceId);
bindStatement.setConsistencyLevel(readConsistency);
return m_session.executeAsync(bindStatement);
}
use of com.datastax.driver.core.BoundStatement in project newts by OpenNMS.
the class CassandraIndexerTest method insertStatementsAreDeduplicatedWhenIndexingManySamples.
@Test
public void insertStatementsAreDeduplicatedWhenIndexingManySamples() {
CassandraSession session = mock(CassandraSession.class);
ArgumentCaptor<Statement> statementCaptor = ArgumentCaptor.forClass(Statement.class);
when(session.executeAsync(statementCaptor.capture())).thenReturn(mock(ResultSetFuture.class));
PreparedStatement statement = mock(PreparedStatement.class);
BoundStatement boundStatement = mock(BoundStatement.class);
when(session.prepare(any(RegularStatement.class))).thenReturn(statement);
when(statement.bind()).thenReturn(boundStatement);
when(boundStatement.setString(any(String.class), any(String.class))).thenReturn(boundStatement);
CassandraIndexingOptions options = new CassandraIndexingOptions.Builder().withHierarchicalIndexing(true).withMaxBatchSize(1).build();
MetricRegistry registry = new MetricRegistry();
GuavaResourceMetadataCache cache = new GuavaResourceMetadataCache(2048, registry);
CassandraIndexer indexer = new CassandraIndexer(session, 0, cache, registry, options, new EscapableResourceIdSplitter(), new ContextConfigurations());
Resource r = new Resource("snmp:1589:vmware5Cpu:2:vmware5Cpu");
List<Sample> samples = Lists.newArrayList();
samples.add(new Sample(Timestamp.now(), r, "CpuCostopSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuIdleSum", MetricType.GAUGE, new Gauge(19299.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuMaxLdSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuOverlapSum", MetricType.GAUGE, new Gauge(5.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuRdySum", MetricType.GAUGE, new Gauge(41.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuRunSum", MetricType.GAUGE, new Gauge(619.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuSpwaitSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuSystemSum", MetricType.GAUGE, new Gauge(0)));
samples.add(new Sample(Timestamp.now(), r, "CpuUsagemhzAvg", MetricType.GAUGE, new Gauge(32.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuUsedSum", MetricType.GAUGE, new Gauge(299.0)));
samples.add(new Sample(Timestamp.now(), r, "CpuWaitSum", MetricType.GAUGE, new Gauge(19343)));
// Index the collection of samples
indexer.update(samples);
// Verify the number of exectuteAsync calls
verify(session, times(20)).executeAsync(any(Statement.class));
}
use of com.datastax.driver.core.BoundStatement in project zipkin by openzipkin.
the class TracedSession method handleInvocation.
@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
// Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null && method.getName().equals("executeAsync") && args[0] instanceof BoundStatement) {
BoundStatement statement = (BoundStatement) args[0];
// via an internal class z.s.cassandra3.NamedBoundStatement, toString() is a nice name
SpanId spanId = brave.clientTracer().startNewSpan(statement.toString());
// o.a.c.tracing.Tracing.newSession must use the same format for the key zipkin
if (version.compareTo(ProtocolVersion.V4) >= 0) {
statement.enableTracing();
statement.setOutgoingPayload(singletonMap("zipkin", ByteBuffer.wrap(spanId.bytes())));
}
// start the span and store it
brave.clientTracer().setClientSent();
brave.clientTracer().submitBinaryAnnotation("cql.query", statement.preparedStatement().getQueryString());
cache.put(statement, brave.clientSpanThreadBinder().getCurrentClientSpan());
// let go of the client span as it is only used for the RPC (will have no local children)
brave.clientSpanThreadBinder().setCurrentSpan(null);
return new BraveResultSetFuture(target.executeAsync(statement), brave);
}
try {
return method.invoke(target, args);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException)
throw e.getCause();
throw e;
}
}
use of com.datastax.driver.core.BoundStatement in project cassandra-driver-mapping by valchkou.
the class MappingSession method updateValues.
/**
* Update values with options.
*
* @param id Primary Key
* @param class Entity.class
* @param propertyNames Array of properties to update
* @param value array of values to update
*/
public void updateValues(Object id, Class<?> clazz, String[] propertyNames, Object[] values, WriteOptions options) {
maybeSync(clazz);
BoundStatement bs = MappingBuilder.prepareUpdateValues(id, clazz, propertyNames, values, options, keyspace, session);
execute(bs);
}
use of com.datastax.driver.core.BoundStatement in project cassandra-driver-mapping by valchkou.
the class MappingSession method get.
/**
* Get Entity by Id(Primary Key)
*
* @param class Entity.class
* @param id primary key
* @param options ReadOptions
* @return Entity instance or null
*/
public <T> T get(Class<T> clazz, Object id, ReadOptions options) {
maybeSync(clazz);
BoundStatement bs = MappingBuilder.prepareSelect(clazz, id, options, keyspace, session);
if (bs != null) {
ResultSet rs = session.execute(bs);
List<T> all = getFromResultSet(clazz, rs);
if (all.size() > 0) {
return all.get(0);
}
}
return null;
}
Aggregations