Rename ContainerFactory to ServiceManager and add some Javadoc.
diff --git a/containers-api/src/main/java/org/apache/aries/containers/ContainerFactory.java b/containers-api/src/main/java/org/apache/aries/containers/ContainerFactory.java
deleted file mode 100644
index d6f988b..0000000
--- a/containers-api/src/main/java/org/apache/aries/containers/ContainerFactory.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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;
-
-import java.util.Set;
-
-import org.osgi.annotation.versioning.ProviderType;
-
-@ProviderType
-public interface ContainerFactory {
- public static final String BINDING = "container.factory.binding";
-
- Service getService(ServiceConfig config) throws Exception;
-
- Set<String> listServices() throws Exception;
-}
diff --git a/containers-api/src/main/java/org/apache/aries/containers/ServiceManager.java b/containers-api/src/main/java/org/apache/aries/containers/ServiceManager.java
new file mode 100644
index 0000000..8c86370
--- /dev/null
+++ b/containers-api/src/main/java/org/apache/aries/containers/ServiceManager.java
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import java.util.Set;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+/** The service manager creates services and otherwise manages service.
+ * Multiple implementations of this inteface can co-exist binding to
+ * various back-end service containers. <p>
+ *
+ * To find a service manager for a specific binding select this service
+ * on the {@code container.factory.binding} service property.
+ */
+@ProviderType
+public interface ServiceManager {
+ /**
+ * Services should register this property to declare the back-end that
+ * they bind to. For example {@code marathon} or {@code docker.local}.
+ */
+ public static final String BINDING = "container.factory.binding";
+
+ /**
+ * Obtain a service for the specified configuration. If the service
+ * already exists it should be returned. Also if the service was created
+ * during previous runs of the manager it should be discovered and used.
+ * <p>
+ * Otherwise a new service should be created for the specified
+ * configuration. <p>
+ * Services can outlive the life cycle of the Service Manager.
+ *
+ * @param config The service configuration for the service.
+ * @return A {@link Service} instance representing this service.
+ * @throws Exception
+ */
+ Service getService(ServiceConfig config) throws Exception;
+
+ /**
+ * List available services by name.
+ * @return A set with the service names. If no services are found an empty
+ * set is returned.
+ * @throws Exception
+ */
+ Set<String> listServices() throws Exception;
+}
diff --git a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/Activator.java b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/Activator.java
index a43c5a5..3b54050 100644
--- a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/Activator.java
+++ b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/Activator.java
@@ -21,7 +21,7 @@
import java.util.Dictionary;
import java.util.Hashtable;
-import org.apache.aries.containers.ContainerFactory;
+import org.apache.aries.containers.ServiceManager;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -29,9 +29,9 @@
@Override
public void start(BundleContext context) throws Exception {
Dictionary<String, Object> props = new Hashtable<>();
- props.put(ContainerFactory.BINDING, "docker.local");
- context.registerService(ContainerFactory.class,
- new LocalDockerContainerFactory(), props);
+ props.put(ServiceManager.BINDING, "docker.local");
+ context.registerService(ServiceManager.class,
+ new LocalDockerServiceManager(), props);
}
@Override
diff --git a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ContainerImpl.java b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ContainerImpl.java
index 6584ab6..2909f37 100644
--- a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ContainerImpl.java
+++ b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ContainerImpl.java
@@ -42,7 +42,7 @@
try {
service.killContainer(this);
} catch (Exception e) {
- LocalDockerContainerFactory.LOG.warn("Problem killing container {}", this, e);
+ LocalDockerServiceManager.LOG.warn("Problem killing container {}", this, e);
}
}
diff --git a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerController.java b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerController.java
index 6b0e8c7..cf3ede1 100644
--- a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerController.java
+++ b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerController.java
@@ -44,7 +44,7 @@
execCmd.addAll(command);
String id = runCommandExpectSingleID(execCmd.toArray(new String [] {}));
- return new DockerContainerInfo(id, LocalDockerContainerFactory.getContainerHost());
+ return new DockerContainerInfo(id, LocalDockerServiceManager.getContainerHost());
}
public List<String> ps(String labelFilter) {
diff --git a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerContainerFactory.java b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
similarity index 96%
rename from containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerContainerFactory.java
rename to containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
index 673f664..4639e25 100644
--- a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerContainerFactory.java
+++ b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/LocalDockerServiceManager.java
@@ -37,15 +37,15 @@
import java.util.stream.Stream;
import org.apache.aries.containers.Container;
-import org.apache.aries.containers.ContainerFactory;
+import org.apache.aries.containers.ServiceManager;
import org.apache.aries.containers.Service;
import org.apache.aries.containers.ServiceConfig;
import org.apache.felix.utils.json.JSONParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class LocalDockerContainerFactory implements ContainerFactory {
- static final Logger LOG = LoggerFactory.getLogger(LocalDockerContainerFactory.class);
+public class LocalDockerServiceManager implements ServiceManager {
+ static final Logger LOG = LoggerFactory.getLogger(LocalDockerServiceManager.class);
private static final String SERVICE_NAME = "org.apache.aries.containers.service.name";
private static final String DOCKER_MACHINE_VM_NAME = System.getenv("DOCKER_MACHINE_NAME");
@@ -64,7 +64,7 @@
private final ConcurrentMap<String, Service> services =
new ConcurrentHashMap<>();
- public LocalDockerContainerFactory() {
+ public LocalDockerServiceManager() {
if (docker == null)
docker = new LocalDockerController();
}
@@ -195,7 +195,7 @@
}
}
// TODO check that the settings match!
- res.add(new ContainerImpl(m.get("Id").toString(), LocalDockerContainerFactory.getContainerHost(), ports));
+ res.add(new ContainerImpl(m.get("Id").toString(), LocalDockerServiceManager.getContainerHost(), ports));
}
return res;
}
diff --git a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ServiceImpl.java b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ServiceImpl.java
index 2c594a5..94aba89 100644
--- a/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ServiceImpl.java
+++ b/containers-docker-local/src/main/java/org/apache/aries/containers/docker/local/impl/ServiceImpl.java
@@ -29,10 +29,10 @@
class ServiceImpl implements Service {
private final ServiceConfig config;
private final List<ContainerImpl> containers;
- private final LocalDockerContainerFactory factory;
+ private final LocalDockerServiceManager factory;
public ServiceImpl(ServiceConfig config,
- LocalDockerContainerFactory factory,
+ LocalDockerServiceManager factory,
List<ContainerImpl> containers) {
this.config = config;
this.factory = factory;
@@ -71,7 +71,7 @@
}
}
} catch (Exception e) {
- LocalDockerContainerFactory.LOG.error("Problem changing instance count of service {} to {}",
+ LocalDockerServiceManager.LOG.error("Problem changing instance count of service {} to {}",
config.getServiceName(), count, e);
}
}
diff --git a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonConfigManagedService.java b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonConfigManagedService.java
index 87c1baf..d4b8746 100644
--- a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonConfigManagedService.java
+++ b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonConfigManagedService.java
@@ -21,7 +21,7 @@
import java.util.Dictionary;
import java.util.Hashtable;
-import org.apache.aries.containers.ContainerFactory;
+import org.apache.aries.containers.ServiceManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
@@ -34,7 +34,7 @@
private final BundleContext bundleContext;
volatile String marathonURL;
- volatile ServiceRegistration<ContainerFactory> reg;
+ volatile ServiceRegistration<ServiceManager> reg;
MarathonConfigManagedService(BundleContext bc) {
bundleContext = bc;
@@ -60,10 +60,10 @@
reg.unregister();
marathonURL = marURL;
- ContainerFactory cf = new MarathonContainerFactory(marathonURL);
+ ServiceManager cf = new MarathonServiceManager(marathonURL);
Dictionary<String, Object> props = new Hashtable<>();
- props.put(ContainerFactory.BINDING, "marathon");
- reg = bundleContext.registerService(ContainerFactory.class, cf, props);
+ props.put(ServiceManager.BINDING, "marathon");
+ reg = bundleContext.registerService(ServiceManager.class, cf, props);
}
}
diff --git a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonContainerFactory.java b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
similarity index 94%
rename from containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonContainerFactory.java
rename to containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
index e5c6b16..f39ef61 100644
--- a/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonContainerFactory.java
+++ b/containers-marathon/src/main/java/org/apache/aries/containers/marathon/impl/MarathonServiceManager.java
@@ -25,7 +25,7 @@
import java.util.Map;
import java.util.Set;
-import org.apache.aries.containers.ContainerFactory;
+import org.apache.aries.containers.ServiceManager;
import org.apache.aries.containers.Service;
import org.apache.aries.containers.ServiceConfig;
@@ -39,16 +39,16 @@
import mesosphere.marathon.client.model.v2.GetAppsResponse;
import mesosphere.marathon.client.model.v2.Port;
-public class MarathonContainerFactory implements ContainerFactory {
+public class MarathonServiceManager implements ServiceManager {
private static final String SERVICE_NAME = "org.apache.aries.containers.service.name";
private final Marathon marathonClient;
- public MarathonContainerFactory(String marathonURL) {
+ public MarathonServiceManager(String marathonURL) {
marathonClient = MarathonClient.getInstance(marathonURL);
}
- public MarathonContainerFactory(String marathonURL, String dcosUser, String passToken, boolean serviceAcct) {
+ public MarathonServiceManager(String marathonURL, String dcosUser, String passToken, boolean serviceAcct) {
DCOSAuthCredentials authCredentials;
if (serviceAcct) {
authCredentials = DCOSAuthCredentials.forServiceAccount(dcosUser, passToken);