aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject aries-containers git commit: Support for health checks in the Marathon binding.
Date Thu, 15 Jun 2017 15:18:37 GMT
Repository: aries-containers
Updated Branches:
  refs/heads/master 182343a7f -> 80bacd1cc


Support for health checks in the Marathon binding.


Project: http://git-wip-us.apache.org/repos/asf/aries-containers/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-containers/commit/80bacd1c
Tree: http://git-wip-us.apache.org/repos/asf/aries-containers/tree/80bacd1c
Diff: http://git-wip-us.apache.org/repos/asf/aries-containers/diff/80bacd1c

Branch: refs/heads/master
Commit: 80bacd1ccc1a6b5bf81b5b34b1b209659ec3aa40
Parents: 182343a
Author: David Bosschaert <davidb@apache.org>
Authored: Thu Jun 15 16:18:20 2017 +0100
Committer: David Bosschaert <davidb@apache.org>
Committed: Thu Jun 15 16:18:20 2017 +0100

----------------------------------------------------------------------
 .../marathon/impl/MarathonServiceManager.java   | 39 ++++++++++++++++++--
 .../impl/MarathonServiceManagerTest.java        | 36 +++++++++++++++++-
 2 files changed, 70 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-containers/blob/80bacd1c/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
----------------------------------------------------------------------
diff --git a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
index d2e0e55..7735af0 100644
--- a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
+++ b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
@@ -25,6 +25,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.naming.OperationNotSupportedException;
+
 import org.apache.aries.containers.Service;
 import org.apache.aries.containers.ServiceConfig;
 import org.apache.aries.containers.ServiceManager;
@@ -34,9 +36,11 @@ import mesosphere.dcos.client.model.DCOSAuthCredentials;
 import mesosphere.marathon.client.Marathon;
 import mesosphere.marathon.client.MarathonClient;
 import mesosphere.marathon.client.model.v2.App;
+import mesosphere.marathon.client.model.v2.Command;
 import mesosphere.marathon.client.model.v2.Container;
 import mesosphere.marathon.client.model.v2.Docker;
 import mesosphere.marathon.client.model.v2.GetAppsResponse;
+import mesosphere.marathon.client.model.v2.HealthCheck;
 import mesosphere.marathon.client.model.v2.Port;
 
 public class MarathonServiceManager implements ServiceManager {
@@ -89,6 +93,7 @@ public class MarathonServiceManager implements ServiceManager {
         app.setMem(config.getRequestedMemory());
         app.setInstances(config.getRequestedInstances());
         app.setEnv(Collections.unmodifiableMap(config.getEnvVars()));
+        app.addLabel(SERVICE_NAME, config.getServiceName());
 
         StringBuilder cmd = new StringBuilder();
         if (config.getEntryPoint() != null) {
@@ -112,7 +117,7 @@ public class MarathonServiceManager implements ServiceManager {
 
         Docker docker = new Docker();
         docker.setImage(config.getContainerImage());
-        docker.setNetwork("BRIDGE"); // TODO is this correct?
+        docker.setNetwork("BRIDGE");
         List<Port> ports = new ArrayList<>();
         for (int p : config.getContainerPorts()) {
             Port port = new Port();
@@ -124,12 +129,38 @@ public class MarathonServiceManager implements ServiceManager {
         Container container = new Container();
         container.setType("DOCKER");
         container.setDocker(docker);
-
         app.setContainer(container);
-        app.addLabel(SERVICE_NAME, config.getServiceName());
 
-        App res = marathonClient.createApp(app);
+        List<HealthCheck> healthChecks = new ArrayList<>();
+        for (org.apache.aries.containers.HealthCheck hc : config.getHealthChecks()) {
+            HealthCheck healthCheck = new HealthCheck();
+            healthCheck.setProtocol(hc.getType().toString());
+            healthCheck.setGracePeriodSeconds(hc.getGracePeriod());
+            healthCheck.setIntervalSeconds(hc.getInterval());
+            healthCheck.setMaxConsecutiveFailures(hc.getMaxFailures());
+            healthCheck.setTimeoutSeconds(hc.getTimeout());
+
+            switch (hc.getType()) {
+            case HTTP:
+                healthCheck.setPath(hc.getParameters());
+                // Fallthrough as the other params are the same as TCP
+            case TCP:
+                healthCheck.setPort(hc.getPort());
+                healthCheck.setPortIndex(hc.getPortIndex());
+                break;
+            case COMMAND:
+                Command command = new Command();
+                command.setValue(hc.getParameters());
+                healthCheck.setCommand(command);
+                break;
+            default:
+                throw new OperationNotSupportedException(hc.getType() + " health checks are
not yet supported");
+            }
+            healthChecks.add(healthCheck);
+        }
+        app.setHealthChecks(healthChecks);
 
+        App res = marathonClient.createApp(app);
         return createServiceFromApp(res, config);
     }
 

http://git-wip-us.apache.org/repos/asf/aries-containers/blob/80bacd1c/containers-marathon/src/test/java/org/apache/aries/containers/marathon/impl/MarathonServiceManagerTest.java
----------------------------------------------------------------------
diff --git a/containers-marathon/src/test/java/org/apache/aries/containers/marathon/impl/MarathonServiceManagerTest.java
b/containers-marathon/src/test/java/org/apache/aries/containers/marathon/impl/MarathonServiceManagerTest.java
index 0baf722..c0152e9 100644
--- a/containers-marathon/src/test/java/org/apache/aries/containers/marathon/impl/MarathonServiceManagerTest.java
+++ b/containers-marathon/src/test/java/org/apache/aries/containers/marathon/impl/MarathonServiceManagerTest.java
@@ -26,6 +26,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.aries.containers.HealthCheck;
 import org.apache.aries.containers.Service;
 import org.apache.aries.containers.ServiceConfig;
 import org.junit.Test;
@@ -103,7 +104,7 @@ public class MarathonServiceManagerTest {
     }
 
     @Test
-    public void testGetService2() throws Exception {
+    public void testGetServiceWithHealthCheck() throws Exception {
         GetAppsResponse nar = Mockito.mock(GetAppsResponse.class);
 
         List<App> appsCreated = new ArrayList<>();
@@ -121,9 +122,18 @@ public class MarathonServiceManagerTest {
 
         MarathonServiceManager msm = new MarathonServiceManager(mc);
 
+        HealthCheck hc1 = HealthCheck.builder(HealthCheck.Type.HTTP).parameters("/").portIndex(0).
+                build();
+        HealthCheck hc2 = HealthCheck.builder(HealthCheck.Type.TCP).port(8080).
+                build();
+        HealthCheck hc3 = HealthCheck.builder(HealthCheck.Type.COMMAND).parameters("ping
test.com").
+                build();
         ServiceConfig cfg = ServiceConfig.builder("my-other-service", "animage").
                 entryPoint("/bin/sh").
                 commandLine("-c", "ls -la").
+                healthCheck(hc1).
+                healthCheck(hc2).
+                healthCheck(hc3).
                 build();
 
         assertEquals("Precondition", 0, appsCreated.size());
@@ -132,6 +142,30 @@ public class MarathonServiceManagerTest {
 
         App app = appsCreated.iterator().next();
         assertEquals("/bin/sh -c 'ls -la'", app.getCmd());
+
+        List<mesosphere.marathon.client.model.v2.HealthCheck> checks = app.getHealthChecks();
+        assertEquals(3, checks.size());
+
+        Set<String> foundTypes = new HashSet<>();
+        for (mesosphere.marathon.client.model.v2.HealthCheck check : checks) {
+            foundTypes.add(check.getProtocol());
+
+            switch (check.getProtocol()) {
+            case "HTTP":
+                assertEquals("/", check.getPath());
+                assertEquals((Integer) 0, check.getPortIndex());
+                assertNull(check.getPort());
+                break;
+            case "TCP":
+                assertEquals(8080, (int) check.getPort());
+                assertNull(check.getPortIndex());
+                break;
+            case "COMMAND":
+                assertEquals("ping test.com", check.getCommand().getValue());
+                break;
+            }
+        }
+
         assertSame(cfg, svc.getConfiguration());
     }
 


Mime
View raw message