Permalink
Fetching contributors…
Cannot retrieve contributors at this time
203 lines (139 sloc) 5.4 KB

Pre Talk

Start OpenShift

cd ~/1/streaming-data-kubernetes
./start-openshift.sh

Verify OpenShift is running

oc project

Live coding

Create Infinispan data grid

Open https://127.0.0.1:8443/ in Chrome

Log in as usr/pwd developer/developer

Click `Infinispan Ephemeral`

Explain differences between Ephemeral and Persistent

Change app name to `datagrid`

Change management usr/pwd to developer/developer

Change number of instances to 3

Click Next

Do not create binding and click Create

Start Visualizer

While data grid loads, start visualizer:

cd visual
oc project myproject
oc new-build --binary --name=visual
oc start-build visual --from-dir=. --follow
oc new-app visual
oc expose service visual

Verify visualizer is working: http://visual-myproject.127.0.0.1.nip.io/infinispan-visualizer/

Test Infinispan data grid

Create a Main verticle in app project

@Override
public void start(Future<Void> startFuture) throws Exception {
  Router router = Router.router(vertx);
  router.get("/test").handler(this::test);

  vertx.createHttpServer()
    .requestHandler(router::accept)
    .listen(8080, ar -> {
      if (ar.succeeded())
        log.info("Server started");

      startFuture.handle(ar.mapEmpty());
    });
}

private void test(RoutingContext ctx) {
  RemoteCacheManager client = new RemoteCacheManager(
    new ConfigurationBuilder().addServer()
      .host("datagrid-hotrod")
      .port(11222)
      .build());

  RemoteCache<Object, Object> cache = client.getCache("repl");
  cache.put("hello", "world");
  Object v = cache.get("hello");

  Set<SocketAddress> topology =
    cache.getCacheTopologyInfo().getSegmentsPerServer().keySet();

  JsonObject json = new JsonObject()
    .put("get", v.toString())
    .put("topology", topology.toString());

  ctx.response()
    .putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8")
    .end(json.encodePrettily());

  client.stop();
}

Build and deploy app project

oc project myproject
oc new-build --binary --name=app
mvn clean package
oc start-build app --from-dir=. --follow
oc new-app app
oc expose service app

Switch visualizer to `repl` cache Switch to terminal and make sure visualizer is in background From terminal, execute:

curl http://app-myproject.127.0.0.1.nip.io/test

Integrate data injector

Add a route for /inject and start the Injector verticle

router.get("/inject").handler(this::inject);

private void inject(RoutingContext ctx) {
  vertx.deployVerticle(Injector.class.getName(), new DeploymentOptions());
  ctx.response().end("Injector started");
}

Redeploy the app

mvn clean package
oc start-build app --from-dir=. --follow

Switch visualizer to default cache

Switch to terminal and make sure visualizer is in background

From terminal, start the injector invoking:

curl http://app-myproject.127.0.0.1.nip.io/inject

Add Continuous Query Listener

Implement continuous query listener

private void addContinuousQuery(RemoteCache<String, Stop> stopsCache) {
  QueryFactory qf = Search.getQueryFactory(stopsCache);

  Query query = qf.from(Stop.class)
    .having("delayMin").gt(0)
    .build();

  ContinuousQueryListener<String, Stop> listener =
      new ContinuousQueryListener<String, Stop>() {
    @Override
    public void resultJoining(String key, Stop value) {
      vertx.runOnContext(x -> {
        vertx.eventBus().publish("delayed-trains", toJson(value));
      });
    }
  };

  continuousQuery = Search.getContinuousQuery(stopsCache);
  continuousQuery.addContinuousQueryListener(query, listener);
}

Add evenbus route for sending events back to dashboard

router.get("/eventbus/*").handler(AppUtils.sockJSHandler(vertx));

Make /inject route deploy the continuous query listener

vertx.deployVerticle(Listener.class.getName(), new DeploymentOptions());

Redeploy the app

mvn clean package
oc start-build app --from-dir=. --follow

Switch to terminal and make sure visualizer is in background

From terminal, start the injector invoking:

curl http://app-myproject.127.0.0.1.nip.io/inject

Run Dashboard from IDE and check that delayed trains are received

Extras

Increase number of replicas and show visualizer dealing with it