Skip to content

Instantly share code, notes, and snippets.

View jsanda's full-sized avatar

John Sanda jsanda

View GitHub Profile
public class StateListenerTest {
private static final Log logger = LogFactory.getLog(StateListenerTest.class);
@Test
public void listenForStateChanges() throws Exception {
Cluster cluster = new ClusterBuilder()
.addContactPoints("127.0.0.1")
.withCredentials("rhqadmin", "rhqadmin")
.build();
Observable<Lease> leaseObservable = leaseService.find(timeSlice)
.filter(lease -> lease.getOwner() == null)
.map(lease -> lease.setOwner(owner));
Observable<Boolean> acquiredObservable = leaseObservable.flatMap(leaseService::acquire)
.filter(acquired -> acquired);
Observable.zip(leaseObservable, acquiredObservable, ((lease, acquired) -> lease))
.flatMap(lease -> findTasks(lease, taskType))
.map(executeTasksSegment)
.flatMap(this::rescheduleTask)
.flatMap(taskContainer -> rxSession.execute(queries.deleteTasks.bind(
@Path("/")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public class AsyncHandler {
private static final ListeningExecutorService threadPool = MoreExecutors.listeningDecorator(
Executors.newFixedThreadPool(4));
@POST
@Path("/{tenantId}/metrics/numeric/{id}/data")
@jsanda
jsanda / gist:702b82b06222ded41aad
Created April 2, 2015 14:58
add data end point
public void addDataForMetric(
@Suspended final AsyncResponse asyncResponse,
@PathParam("tenantId") final String tenantId, @PathParam("id") String id,
@ApiParam(value = "List of datapoints containing timestamp and value", required = true)
List<NumericData> data
) {
Callable<Response> callable = () -> {
// long sleep = random.nextLong() % SLEEP;
// if (sleep > 0) {
// try {
class TestScriptBase {
@Override
Object run() {
return null
}
def execute() {
BigDecimal.metaClass.equals = { return true }
script()
}
BigDecimal.metaClass.equals = { return compareTo(it); }
@jsanda
jsanda / gist:7b9257602f25b84f74c3
Created January 22, 2015 14:52
liveoak/events data model discusion
mstruk: jsanda: sure, let's discuss it
08:02 jsanda: which means we also need to consider queries
08:02 mstruk: jsanda: yeah, in this case I hide something akin to stored procs behind /rhq-metrics/event-log endpoint
08:03 mstruk: jsanda: well … hardcoded in java ...
08:03 mstruk: jsanda: this needs to be made more generic
08:03 jsanda: yeah, i figured that, but it looks like a great start from what i saw
08:04 jsanda: not sure if it is a good starting point, but i'm looking at https://github.com/mstruk/rhq-metrics/blob/liveoak/core-api/src/main/java/org/rhq/metrics/core/LogEvent.java
08:04 jsanda: here's my first question
08:04 jsanda: what fields minimally describe an event?
08:05 mstruk: jsanda: for my purposes I have two types of events actually
Tracing session: 0fc8fc00-6ff8-11e4-bd7b-33b208512135
activity | timestamp | source | source_elapsed
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------+-----------+----------------
execute_cql3_query | 09:26:33,539 | 127.0.0.1 | 0
Parsing select * from metrics where bucket = 'raw' and metric_id = 'snert.local.bytes_in' and time >= '2014-11-01' and time < '2014-11-12 14:21:00-0500' LIMIT 10000; | 09:26:33,541 | 127.0.0.1 | 2296
CREATE TABLE data (
metric text,
time timeuuid,
attributes map<text, text> static,
value double,
PRIMARY KEY (metric, time)
);
CREATE TABLE grouped_data (
group text,
# Defines the number of tokens randomly assigned to a node on the ring. The more tokens,
# relative to other nodes, the larger the proportion of data that this node will store. You
# probably want all nodes to have the same number of tokens assuming they have equal
# hardware capability. Tokens are randomly generated with the expectation of an even
# distribution. With that said, there can be some variation. Either increasing this value
# or increasing the number of nodes in the cluster will help even out the distribution.
rhq.storage.num-tokens=256
# A comma-delimited list of IP addresses/host names that are deemed contact points.
# Cassandra nodes use this list of hosts to find each other and learn the