Skip to content

Instantly share code, notes, and snippets.

View jsanda's full-sized avatar

John Sanda jsanda

View GitHub Profile
// how we did async in the dark ages
Futures.addCallback(session.executeAsync(boundStatement), new FutureCallback<ResultSet>() {
@Override
public void onSuccess(ResultSet rows) {
rows.forEach(row -> mappings.put(row.getString(0), row.getString(1)));
}
@Override
public void onFailure(Throwable throwable) {
// handle failure
private Map<String,String> getMappingTable() {
// You only want to prepare the query once. Best to do it when you initialize the session.
PreparedStatement findMappings = session.prepare(
"SELECT project_id, project_name " +
"FROM openshift_metrics.metrics_mappings " +
"WHERE token(project_id) > ? AND token(project_id) <= ?");
Map<String,String> mappings = new HashMap<>();
if (hasMappingTable()) {
for (TokenRange tokenRange : getTokenRanges()) {
@Override
public void start() throws Exception {
ObjectMapper mapper = createMapper();
Router router = Router.router(vertx);
router.route(HttpMethod.POST, BASE_URL + "gauges/raw").handler(context ->
RxHelper.toObservable(context.request())
.map(buffer -> {
try {
TypeReference<List<Metric<Double>>> typeRef = new TypeReference<List<Metric<Double>>>() {};
Observable<Row> findEntityByCanonicalPath(String cp) {
// return session.executeAndFetch(findEntityByCanonicalPath.bind(cp));
return session.execute(findEntityByCanonicalPath.bind(cp)).flatMap(Observable::from);
}
Observable<Row> findRelationshipByCanonicalPath(String cp) {
// return session.executeAndFetch(findRelationshipByCanonicalPath.bind(cp));
return session.execute(findRelationshipByCanonicalPath.bind(cp)).flatMap(Observable::from);
}
// I put this class in the rest-tests-jaxrs module.
class NullStringITest extends RESTTest {
@Test
void nullStrings() {
String tenantId = nextTenantId()
def response = hawkularMetrics.post(
path: 'strings',
body: [
id: 'NULL-STRING',
<cache-container name="hawkular-metrics"
default-cache="locks"
module="org.wildfly.clustering.server"
statistics-enabled="true">
<transport lock-timeout="60000"/>
<replicated-cache name="locks" mode="SYNC">
<transaction mode="NON_XA" locking="PESSIMISTIC"/>
</replicated-cache>
</cache-container
private void initSchema() {
doWithLock("cassalog", () -> {
SchemaService schemaService = new SchemaService();
schemaService.run(session, keyspace, Boolean.parseBoolean(resetDb));
session.execute("USE " + keyspace);
});
}
private void doWithLock(String key, Runnable runnable) {
AdvancedCache<String, String> cache = locksCache.getAdvancedCache();
@Listener
public class DistributedLock {
private static Logger log = Logger.getLogger(DistributedLock.class);
private static final String KEY = "cassalog";
private AdvancedCache<String, String> locksCache;
public DistributedLock(AdvancedCache<String, String> locksCache) {
private void initSchema() {
doWithLock("cassalog", () -> {
SchemaService schemaService = new SchemaService();
schemaService.run(session, keyspace, Boolean.parseBoolean(resetDb));
session.execute("USE " + keyspace);
});
}
private void doWithLock(String key, Runnable runnable) {
AdvancedCache<String, String> cache = locksCache.getAdvancedCache();
TransactionManager transactionManager = cache.getTransactionManager();
public boolean enableAll(MetricRegistry registry)
{
boolean enabled = false;
if (console != null)
{
if (enableConsole(registry))
{
enabled = true;
}
}