Commit 1c9d0457 authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

#refs 1683 Added a health check for nesstar server availability

parent d607d425
package com.nesstar.rest;
import com.nesstar.rest.common.ServerHandler;
import com.nesstar.rest.healthchecks.NesstarHealthCheck;
import com.nesstar.rest.resources.*;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Bootstrap;
......@@ -43,6 +44,8 @@ public class NesstarDropService extends Service<NesstarDropConfiguration> {
environment.addResource(new QueryResource(serverHandler));
environment.addResource(new DownloadResource(serverHandler));
environment.addHealthCheck(new NesstarHealthCheck(serverHandler));
FilterBuilder filterConfig = environment.addFilter(CrossOriginFilter.class, "*");
filterConfig.setInitParam(CrossOriginFilter.PREFLIGHT_MAX_AGE_PARAM, String.valueOf(60 * 60 * 24)); // 1 day
filterConfig.setInitParam(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
......
package com.nesstar.rest.healthchecks;
import com.nesstar.api.NotAuthorizedException;
import com.nesstar.api.Server;
import com.nesstar.api.User;
import com.nesstar.rest.common.ServerHandler;
import com.yammer.metrics.core.HealthCheck;
import java.io.IOException;
import static com.yammer.metrics.core.HealthCheck.Result.healthy;
import static com.yammer.metrics.core.HealthCheck.Result.unhealthy;
public class NesstarHealthCheck extends HealthCheck {
private ServerHandler serverHandler;
public NesstarHealthCheck(ServerHandler serverHandler) {
super("nesstarserver");
this.serverHandler = serverHandler;
}
@Override
protected Result check() throws Exception {
Server server = serverHandler.getServer();
String userID = serverHandler.getUserId();
String password = serverHandler.getPassword();
User currentUser = null;
try {
currentUser = server.getCurrentUser();
} catch (NotAuthorizedException e) {
// ignore, see bug #1686 in Nesstar API
} catch (IOException e) {
return server.login(userID, password) ? healthy() : unhealthy("couldn't login to nesstar server");
}
if (currentUser == null) {
}
return healthy();
}
}
Markdown is supported
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