Skip to content

Instantly share code, notes, and snippets.

View RichardHightower's full-sized avatar

Richard Hightower RichardHightower

View GitHub Profile
@RichardHightower
RichardHightower / UsingGuavaFutures.md
Created April 8, 2016 17:35
Simple Example using Guava Futures

Simplest example.

    public static void main(String... args) throws Exception{


        ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));

        Callable<String> asyncTask = () -> {
            Thread.sleep(1000);
@RichardHightower
RichardHightower / qbit_reakt_cassandra.md
Created April 9, 2016 01:21
Example of using QBit circuit breaker logic with Cassandra using Reakt

This class uses an async supplier to connect to cassandra.

Example of circuit breaker for Cassandra.

import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.ResultSetFuture;
@RichardHightower
RichardHightower / setup_for_logback_logstash.md
Created April 20, 2016 02:15
Logstash Logback setup for Mesosphere for debugging distributed microservices

Logstash and Logback setup for running in Mesosphere.

.../salt/logstash/files/conf.d/input-json.conf

input {
  udp {
    port => 5000
    codec => "json"
  }
interface Config {
    String getString(String path);
    int getInt(String path);
    float getFloat(String path);
    double getDouble(String path);
    long getLong(String path);
    Map<String, Object> getMap(String path);
  T getObject(String path, Class type);
@RichardHightower
RichardHightower / TwoAsyncCalls.java
Last active July 7, 2016 19:20
Make two async calls and not returning until both come back or fail
override fun removeArtistFromSystem(artistId: Long): Promise<Boolean> {
return Promises.invokablePromise { promise ->
val saveSystemDataPromise = Promises.promiseBoolean()
.catchError { e -> logger.info("removeArtistFromSystem:: unable to save system data for $artistId", e) }
val removeArtistFromSystemPromise = Promises.promiseBoolean()
.catchError { e -> logger.info("removeArtistFromSystem:: unable to remove $artistId from repo", e) }
Promises.all(saveSystemDataPromise, removeArtistFromSystemPromise)

/etc/logstash/conf.d

The key is that it is ok to have many logstash processes running with different input and output filters. And we need json in and json out for UDP. The non UDP/JSON versions do not seem to work with extra fields/MDC. The output encoder moving from logstash and into kibana was wrong so it would black hole all of our logs from logback.

# cat 50-udp.conf 

input {
    udp {
        port => 5001
@RichardHightower
RichardHightower / foo.md
Created August 15, 2016 23:11
Installing exhibitor....
$ dcos package install exhibitor
We recommend a minimum of three nodes with 3GB of RAM available.
Continue installing? [yes/no] yes
Installing Marathon app for package [exhibitor] version [1.0.0]
Object is not valid
got 1.0, expected 0.5 or less
got 1.0, expected 0.0
must be false
@RichardHightower
RichardHightower / consul.md
Last active July 19, 2017 05:49
consul setup on mesos / coreos

We are having troubles talking to Mesos DNS if our Marathon application / service has two ports.

We could use mesos consul https://hub.docker.com/r/ciscocloud/mesos-consul/ but that would require a consul cluster.

The following are instructions to install consul on dcos/mesos/coreos. This may not be the best way. Coreos does have a package manager (but we don't know how to use it). At a minimum we should script this with ansible. (We are not ansible experts either).

So far, I have been unable to get mesos-consul to work but consul is running on the mesos-masters and mesos-slaves in a special snowflake fashion.

@RichardHightower
RichardHightower / install_docker.sh
Created August 21, 2016 00:37
Installing lab env
## Setup docker repo
sudo apt-get install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo touch /etc/apt/sources.list.d/docker.list
sudo echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" > /etc/apt/sources.list.d/docker.list
## Install Docker
sudo apt-get update
sudo apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
@RichardHightower
RichardHightower / logback.xml
Last active August 24, 2016 17:55
Java setup for Mesos/Gradle/QBit zip that uses logback/sl4j and virtual hosting
<configuration>
<appender name="STASH-UDP" class="net.logstash.logback.appender.LogstashSocketAppender">
<host>${LOGSTASH_HOST:-192.168.99.100}</host>
<port>${LOGSTASH_PORT:-5001}</port>
<customFields>{"serviceName":"sample-dcos-qbit","serviceHost":"${HOST}","servicePort":"${PORT0}","serviceId":"sample-dcos-qbit-${HOST}-${PORT0}","serviceAdminPort":"${PORT1}"}</customFields>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">