Skip to content
Snippets Groups Projects
Commit ab9c6018 authored by Ludovic Claude's avatar Ludovic Claude
Browse files

Add active ping to Woken to health checks

parent 62ff0fa1
No related branches found
No related tags found
No related merge requests found
......@@ -46,8 +46,10 @@ public class StartupTasks implements ApplicationListener<ApplicationReadyEvent>
LOGGER.info("Prefill variable repository with datasets...");
for (int i = 0; i < 5; i++) {
try {
StringBuilder fetchedDatasets = new StringBuilder();
for (Dataset dataset : datasetsApi.fetchDatasets()) {
final String code = dataset.id().code();
fetchedDatasets.append(code).append(' ');
Variable v = variableRepository.findOne(code);
if (v == null) {
LOGGER.info("Store additional variable {}", code);
......@@ -55,7 +57,7 @@ public class StartupTasks implements ApplicationListener<ApplicationReadyEvent>
variableRepository.save(v);
}
}
LOGGER.info("Datasets fetched from Woken");
LOGGER.info("Datasets fetched from Woken: " + fetchedDatasets.toString());
variablesRepositoryOk = true;
break;
} catch (Exception e) {
......@@ -80,7 +82,7 @@ public class StartupTasks implements ApplicationListener<ApplicationReadyEvent>
}
*/
LOGGER.info("MIP Portal backend is ready!");
LOGGER.info("[OK] MIP Portal backend is ready!");
}
}
package eu.hbp.mip.akka;
import akka.cluster.Cluster;
import ch.chuv.lren.woken.messages.Ping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
import scala.Option;
@Component
public class AkkaClusterHealthCheck implements HealthIndicator {
public class AkkaClusterHealthCheck extends WokenClientController implements HealthIndicator {
@Autowired
private Cluster wokenCluster;
......@@ -20,7 +22,12 @@ public class AkkaClusterHealthCheck implements HealthIndicator {
} else if (!wokenCluster.state().allRoles().contains("woken")) {
return Health.down().withDetail("Error", "Woken server cannot be seen in the cluster").build();
}
return Health.up().build();
try {
askWoken(new Ping(Option.apply("woken")), 5);
return Health.up().build();
} catch (Exception e) {
return Health.down().withDetail("Error", "Cannot reach Woken: " + e.toString()).build();
}
}
}
......@@ -6,6 +6,7 @@ import akka.cluster.pubsub.DistributedPubSub;
import akka.cluster.pubsub.DistributedPubSubMediator;
import akka.pattern.Patterns;
import akka.util.Timeout;
import ch.chuv.lren.woken.messages.RemoteMessage;
import ch.chuv.lren.woken.messages.query.Query;
import ch.chuv.lren.woken.messages.query.QueryResult;
import org.slf4j.Logger;
......@@ -36,18 +37,20 @@ public abstract class WokenClientController {
private String wokenPath;
@SuppressWarnings("unchecked")
protected <A, B> B askWoken(A message, int waitInSeconds) throws Exception {
LOGGER.info("Akka is trying to reach remote " + wokenPath);
protected <A extends RemoteMessage, B> B askWoken(A message, int waitInSeconds) throws Exception {
LOGGER.info("Trying to reach remote Akka actor " + wokenPath + "...");
DistributedPubSubMediator.Send queryMessage = new DistributedPubSubMediator.Send(wokenPath, message, false);
Timeout timeout = new Timeout(Duration.create(waitInSeconds, "seconds"));
Future<Object> future = Patterns.ask(wokenMediator(), queryMessage, timeout);
return (B) Await.result(future, timeout.duration());
B result = (B) Await.result(future, timeout.duration());
LOGGER.info("Akka actor returned a result for message of class " + message.getClass());
return result;
}
protected <A, B> ResponseEntity requestWoken(A message, int waitInSeconds, Function<B, ResponseEntity> handleResponse) {
protected <A extends RemoteMessage, B> ResponseEntity requestWoken(A message, int waitInSeconds, Function<B, ResponseEntity> handleResponse) {
try {
B result = askWoken(message, waitInSeconds);
return handleResponse.apply(result);
......
......@@ -8,8 +8,6 @@ package eu.hbp.mip.controllers;
import ch.chuv.lren.woken.messages.datasets.Dataset;
import ch.chuv.lren.woken.messages.datasets.DatasetsQuery;
import ch.chuv.lren.woken.messages.datasets.DatasetsResponse;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import eu.hbp.mip.akka.WokenClientController;
import eu.hbp.mip.model.DatasetDescription;
import io.swagger.annotations.*;
......@@ -25,7 +23,6 @@ import scala.Option;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment