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: Add container info to Marathon service.
Date Fri, 26 May 2017 14:15:15 GMT
Repository: aries-containers
Updated Branches:
  refs/heads/master 129ef689c -> 49c288937


Add container info to Marathon service.


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

Branch: refs/heads/master
Commit: 49c288937098205a357e94f57224af3b33ccd3d9
Parents: 129ef68
Author: David Bosschaert <davidb@apache.org>
Authored: Fri May 26 15:14:52 2017 +0100
Committer: David Bosschaert <davidb@apache.org>
Committed: Fri May 26 15:14:52 2017 +0100

----------------------------------------------------------------------
 .../containers/marathon/impl/ContainerImpl.java | 93 ++++++++++++++++++++
 .../containers/marathon/impl/ServiceImpl.java   | 15 +++-
 2 files changed, 105 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-containers/blob/49c28893/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ContainerImpl.java
----------------------------------------------------------------------
diff --git a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ContainerImpl.java
b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ContainerImpl.java
new file mode 100644
index 0000000..88264d2
--- /dev/null
+++ b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ContainerImpl.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.containers.marathon.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.containers.Container;
+import org.apache.aries.containers.Service;
+
+import mesosphere.marathon.client.Marathon;
+
+public class ContainerImpl implements Container {
+    private final String appID;
+    private final String taskID;
+    private final String host;
+    private final Marathon marathonClient;
+    private final Map<Integer, Integer> ports;
+    private final Service service;
+
+    public ContainerImpl(Marathon marathon, String appID, String taskID, String host,
+            Collection<Integer> ports, Service service) {
+        this.marathonClient = marathon;
+        this.appID = appID;
+        this.taskID = taskID;
+        this.host = host;
+        this.service = service;
+
+        // Marathon only reports the external ports which are in the same order as the
+        // port definitions, so we need to associate them
+        Map<Integer, Integer> pm = new HashMap<>();
+        List<Integer> hostPorts = new ArrayList<>(ports);
+        List<Integer> containerPorts = service.getConfiguration().getContainerPorts();
+        for (int i=0; i < hostPorts.size() && i < containerPorts.size(); i++)
{
+            pm.put(containerPorts.get(i), hostPorts.get(i));
+        }
+        this.ports = Collections.unmodifiableMap(pm);
+    }
+
+    @Override
+    public void destroy() {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public String getID() {
+        return taskID;
+    }
+
+    @Override
+    public String getIPAddress() {
+        return host;
+    }
+
+    @Override
+    public Map<Integer, Integer> getExposedPorts() {
+        return ports;
+    }
+
+    @Override
+    public Service getService() {
+        return service;
+    }
+
+    @Override
+    public String toString() {
+        return "ContainerImpl [appID=" + appID + ", taskID=" + taskID + ", host=" + host
+
+                ", ports=" + ports + ", service=" + service.getConfiguration().getServiceName()
+ "]";
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/aries-containers/blob/49c28893/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ServiceImpl.java
----------------------------------------------------------------------
diff --git a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ServiceImpl.java
b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ServiceImpl.java
index 8896271..cc6d100 100644
--- a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ServiceImpl.java
+++ b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/ServiceImpl.java
@@ -18,7 +18,7 @@
  */
 package org.apache.aries.containers.marathon.impl;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.aries.containers.Container;
@@ -27,6 +27,7 @@ import org.apache.aries.containers.ServiceConfig;
 
 import mesosphere.marathon.client.Marathon;
 import mesosphere.marathon.client.model.v2.App;
+import mesosphere.marathon.client.model.v2.Task;
 
 class ServiceImpl implements Service {
     private final ServiceConfig configuration;
@@ -56,8 +57,16 @@ class ServiceImpl implements Service {
 
     @Override
     public List<Container> listContainers() {
-        // TODO Auto-generated method stub
-        return Collections.emptyList();
+        App app = marathonClient.getApp(marathonAppID).getApp();
+
+        List<Container> res = new ArrayList<>();
+        for (Task t : app.getTasks()) {
+            Container c = new ContainerImpl(marathonClient, app.getId(), t.getId(),
+                    t.getHost(), t.getPorts(), this);
+
+            res.add(c);
+        }
+        return res;
     }
 
     @Override


Mime
View raw message