summaryrefslogtreecommitdiff
path: root/src/main/java/com/p4square/grow/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/p4square/grow/frontend')
-rw-r--r--src/main/java/com/p4square/grow/frontend/GrowFrontend.java1
-rw-r--r--src/main/java/com/p4square/grow/frontend/HealthCheckPage.java82
-rw-r--r--src/main/java/com/p4square/grow/frontend/IntegrationDriver.java10
3 files changed, 93 insertions, 0 deletions
diff --git a/src/main/java/com/p4square/grow/frontend/GrowFrontend.java b/src/main/java/com/p4square/grow/frontend/GrowFrontend.java
index ebaa8df..29f7e14 100644
--- a/src/main/java/com/p4square/grow/frontend/GrowFrontend.java
+++ b/src/main/java/com/p4square/grow/frontend/GrowFrontend.java
@@ -118,6 +118,7 @@ public class GrowFrontend extends FMFacade {
router.attach("/login.html", LoginPageResource.class);
router.attach("/newaccount.html", NewAccountResource.class);
router.attach("/newbeliever", NewBelieverResource.class);
+ router.attach("/ping", HealthCheckPage.class);
final Router accountRouter = new MetricRouter(getContext(), mMetricRegistry);
accountRouter.attach("/authenticate", AuthenticatedResource.class);
diff --git a/src/main/java/com/p4square/grow/frontend/HealthCheckPage.java b/src/main/java/com/p4square/grow/frontend/HealthCheckPage.java
new file mode 100644
index 0000000..7469b09
--- /dev/null
+++ b/src/main/java/com/p4square/grow/frontend/HealthCheckPage.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2018 Jesse Morgan
+ */
+
+package com.p4square.grow.frontend;
+
+import org.restlet.Request;
+import org.restlet.Response;
+import org.restlet.data.Method;
+import org.restlet.data.Status;
+import org.restlet.representation.Representation;
+import org.restlet.representation.StringRepresentation;
+
+import org.apache.log4j.Logger;
+
+import com.p4square.grow.config.Config;
+import org.restlet.resource.ServerResource;
+
+/**
+ * This page verifies all of the dependencies are working.
+ * If so, it returns a 200, otherwise a 500.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class HealthCheckPage extends ServerResource {
+ private static final Logger LOG = Logger.getLogger(HealthCheckPage.class);
+
+ private GrowFrontend mGrowFrontend;
+ private Config mConfig;
+
+ @Override
+ public void doInit() {
+ super.doInit();
+
+ mGrowFrontend = (GrowFrontend) getApplication();
+ mConfig = mGrowFrontend.getConfig();
+ }
+
+ /**
+ * Health check
+ */
+ @Override
+ protected Representation get() {
+ try {
+ // Check the backend
+ boolean backendOk = checkBackend();
+
+ // Check the Third-Party Integration driver
+ boolean integrationOk = mGrowFrontend.getThirdPartyIntegrationFactory().doHealthCheck();
+
+ if (backendOk && integrationOk) {
+ return new StringRepresentation("SUCCESS");
+ }
+
+ } catch (Exception e) {
+ LOG.fatal("Health check exception: " + e.getMessage(), e);
+ }
+
+ // Something went wrong...
+ setStatus(Status.SERVER_ERROR_INTERNAL);
+ return new StringRepresentation("FAIL");
+ }
+
+ private boolean checkBackend() {
+ final Request request = new Request(Method.GET, getBackendEndpoint() + "/ping");
+ final Response response = getContext().getClientDispatcher().handle(request);
+
+ if (response.getStatus().isSuccess()) {
+ return true;
+ } else {
+ LOG.warn("Backend health check failed. Got " + response.getStatus().toString());
+ return false;
+ }
+ }
+
+ /**
+ * @return The backend endpoint URI
+ */
+ private String getBackendEndpoint() {
+ return mConfig.getString("backendUri", "riap://component/backend");
+ }
+}
diff --git a/src/main/java/com/p4square/grow/frontend/IntegrationDriver.java b/src/main/java/com/p4square/grow/frontend/IntegrationDriver.java
index b9c3508..8ea2600 100644
--- a/src/main/java/com/p4square/grow/frontend/IntegrationDriver.java
+++ b/src/main/java/com/p4square/grow/frontend/IntegrationDriver.java
@@ -23,4 +23,14 @@ public interface IntegrationDriver {
* @return The ProgressReporter.
*/
ProgressReporter getProgressReporter();
+
+ /**
+ * Check if the IntegrationDriver is configured correctly and working.
+ *
+ * This method should try to contact the CMS to ensure endpoints,
+ * credentials, etc. are working correctly.
+ *
+ * @return true for success.
+ */
+ boolean doHealthCheck();
}