@RequestMapping(value = "/healthy-nodes/", summary = "List of healthy nodes", description = "List of nodes that are healthy.", returnDescription = "List of healthy nodes") public void findAllHealthyNodes(final Callback<List<String>> callback) { healthService.findHealthyNodes(callback::accept); healthService.clientProxyFlush(); }
@RequestMapping(value = "/load-nodes/", summary = "Load all health info about all nodes", description = "Load all health info about all nodes", returnDescription = "list of healthy nodes") public void loadNodes(final Callback<List<NodeHealthStat>> callback) { healthService.loadNodes(callback); healthService.clientProxyFlush(); }
/** * Read annotation. * * @param callback callback */ @RequestMapping(value = "/all-nodes/", summary = "Finds all nodes that have registered with health system", description = "Finds all service actors and endpoints that are registered with the health system." + "Each node will periodically check in with the health system." + "Nodes can mark themselves unhealthy or just fail to check in", returnDescription = "List of node names") public void findAllNodes(final Callback<List<String>> callback) { healthService.findAllNodes(callback::accept); healthService.clientProxyFlush(); }
private void check() { now = timer.now(); long duration = now - lastCheckTime; if (duration > checkInIntervalMS) { lastCheckTime = now; final boolean failing = healthManager.isFailing(); if (!failing) { healthServiceAsync.checkInOk(serviceName); } else { healthServiceAsync.checkIn(serviceName, HealthStatus.FAIL); } healthServiceAsync.clientProxyFlush(); } }
@Test public void forceTTLExpire() throws Exception { final CountDownLatch countDownLatch = new CountDownLatch(1); final AtomicBoolean result = new AtomicBoolean(); healthService.register("foo", 1, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.PASS); healthService.findAllNodes(names -> { result.set(names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch.countDown(); } ); countDownLatch.await(10, TimeUnit.SECONDS); assertTrue("foo is found", result.get()); timer.setTime(); timer.minutes(1); Sys.sleep(1000); healthService.clientProxyFlush(); final CountDownLatch countDownLatch2 = new CountDownLatch(1); result.set(false); healthService.findHealthyNodes(names -> { result.set(!names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch2.countDown(); } ); countDownLatch2.await(10, TimeUnit.SECONDS); assertTrue("foo should not be found", result.get()); }
/** * Read annotation. * * @param responseCallback responseCallback */ @RequestMapping(value = "/ok", summary = "simple health check", description = "Health check. This returns true if all nodes (service actors) are healthy", returnDescription = "true if all nodes are healthy, false if all nodes are not healthy") public void ok(final Callback<HttpTextResponse> responseCallback) { healthService.ok(callbackBuilder().withBooleanCallback(ok -> { if (ok) { responseCallback.resolve(httpResponseBuilder().setBody("true").setCode(200).buildTextResponse()); } else { responseCallback.resolve(httpResponseBuilder().setBody("false").setCode(503).buildTextResponse()); } }).build()); healthService.clientProxyFlush(); }
@Test public void testFindAllHealthyNodes() throws Exception { adminBuilder.getHealthService().checkIn("foo", HealthStatus.FAIL); adminBuilder.getHealthService().clientProxyFlush(); Sys.sleep(1000); HttpTextResponse httpResponse = httpClient.get("/__admin/all-nodes/"); assertTrue(httpResponse.code() == 200); assertEquals("[\"bar\",\"foo\",\"baz\"]", httpResponse.body()); } }
healthService.checkInOk("bar"); healthService.clientProxyFlush();
private void check() { now = timer.now(); long duration = now - lastCheckTime; if (duration > checkInIntervalMS) { lastCheckTime = now; final boolean failing = healthManager.isFailing(); if (!failing) { healthServiceAsync.checkInOk(serviceName); } else { healthServiceAsync.checkIn(serviceName, HealthStatus.FAIL); } healthServiceAsync.clientProxyFlush(); } }
private void check() { now = timer.now(); long duration = now - lastCheckTime; if (duration > checkInIntervalMS) { lastCheckTime = now; final ServiceQueue serviceQueue = ServiceContext.serviceContext().currentService(); boolean failing = serviceQueue.failing(); if (!failing) { healthServiceAsync.checkInOk(serviceName); } else { healthServiceAsync.checkIn(serviceName, HealthStatus.FAIL); } healthServiceAsync.clientProxyFlush(); } }