aboutsummaryrefslogtreecommitdiffstats
path: root/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp
diff options
context:
space:
mode:
authorlj1412 <lji@research.att.com>2017-02-14 15:11:24 +0000
committerlj1412 <lji@research.att.com>2017-02-14 15:11:26 +0000
commit9a98a583855c9665c7171ca2e44e311095cdaac1 (patch)
treeb9f784669b9d235bba8d9bf9354cd313ff051171 /ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp
parent0453f7ce05dcb0affc9025c007db125128d0bf95 (diff)
Init ncomp.docker
Change-Id: Ic87bcf77cff63ef6cd3004fbff9a69f11930d684 Signed-off-by: lj1412 <lji@research.att.com>
Diffstat (limited to 'ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp')
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/docker/adaptor/tools/Generator.java70
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerAbstractClient.java191
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerAdaptorProvider.java63
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerHostProvider.java968
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClient.java196
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClientException.java31
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerInspect.java52
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRun.java102
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRunLinks.java102
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerStop.java52
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestPolling.java52
-rw-r--r--ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/gui/DockerGuiClientApiProvider.java78
12 files changed, 1957 insertions, 0 deletions
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/docker/adaptor/tools/Generator.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/docker/adaptor/tools/Generator.java
new file mode 100644
index 0000000..09f3f3f
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/docker/adaptor/tools/Generator.java
@@ -0,0 +1,70 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.docker.adaptor.tools;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+
+import org.openecomp.utils.YamlToJava;
+import org.openecomp.ncomp.sirius.manager.controllermodel.ControllerModel;
+import org.openecomp.ncomp.sirius.manager.controllermodel.ControllermodelFactory;
+import org.openecomp.ncomp.sirius.manager.generator.ControllerGenerator;
+import org.openecomp.ncomp.gwt.siriusportal.model.*;
+import org.openecomp.ncomp.sirius.manager.server.ServerPackage;
+import org.openecomp.ncomp.docker.DockerFactory;
+
+public class Generator {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ @SuppressWarnings("unused")
+ ServerPackage f = ServerPackage.eINSTANCE;
+ EObject o = DockerFactory.eINSTANCE.createDockerAdaptor();
+ EPackage p = o.eClass().getEPackage();
+ String dir = p.getNsURI().replaceAll(p.getNsPrefix() + '$', "") + "servers." + p.getNsPrefix();
+ dir = "src/main/sirius-gen/" + dir.replace('.', '/');
+ ControllerModel m = ControllermodelFactory.eINSTANCE.createControllerModel();
+ m.setTemplateDirectory("../../dcae-org.openecomp.ncomp.sirius.manager/ncomp-sirius-manager-generator/src/main/templates");
+ m.setPrefix("Docker");
+ m.setPluginName(p.getNsURI());
+ m.setName("Docker");
+ m.setTitle("Docker");
+ ControllerGenerator g = new ControllerGenerator(o, m);
+ EObject h = DockerFactory.eINSTANCE.createDockerHost();
+ g.addApi("host", h, m, false, true);
+ g.setEnableIRequestHandler(false);
+ g.setEnableISiriusPlugin(false);
+ EObject gui = ModelFactory.eINSTANCE.createGuiClientApi();
+ g.addObject("gui", gui, m);
+ g.generate(dir);
+ String pName = p.getNsURI().replaceAll(p.getNsPrefix()+'$',"") + "servers." + p.getNsPrefix() +".logging";
+// YamlToJava.convert("src/main/resources/DockerAdaptor.yaml", dir + "/logging", pName);
+ YamlToJava.convert("src/main/sirius-gen/DockerAdaptor.yaml", dir + "/logging", pName);
+ YamlToJava.convert("src/main/sirius-gen/DockerHost.yaml", dir + "/logging", pName);
+ String pName1 = p.getNsURI().replaceAll(p.getNsPrefix()+'$',"") + "servers." + p.getNsPrefix() +".gui.logging";
+ YamlToJava.convert("src/main/sirius-gen/GuiClientApi.yaml", dir + "/gui/logging", pName1);
+
+ }
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerAbstractClient.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerAbstractClient.java
new file mode 100644
index 0000000..30a5777
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerAbstractClient.java
@@ -0,0 +1,191 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import java.util.HashMap;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import org.openecomp.ncomp.utils.emf.EUtils;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+
+public abstract class DockerAbstractClient {
+ public static final Logger logger = Logger.getLogger(DockerAbstractClient.class);
+ abstract public byte[] httpBinaryTransaction(String path, String method, HashMap<String, String> headers, JSONObject body, Long timeout);
+
+ public Properties props;
+ public String language;
+ public String namespace;
+ private static HashMap<EObject, DockerAbstractClient> map1 = new HashMap<EObject, DockerAbstractClient>();
+ private static HashMap<EObject, String> map2 = new HashMap<EObject, String>();
+
+ public void add(String uri, EObject o) {
+ map1.put(o, this);
+ map2.put(o, uri);
+ }
+
+ static DockerAbstractClient findClient(EObject o) {
+ return map1.get(o);
+ }
+
+ public JSONObject operationJson(EObject o, String name, Long timeout, JSONObject json) {
+ return operationPath2(map2.get(o), name, timeout, json);
+ }
+
+ public JSONObject operationPath2(String path, String name, Long timeout, JSONObject json) {
+ HashMap<String, String> headers = new HashMap<String, String>();
+ headers.put("action", name);
+ logger.debug("operation: " + name + "\n" + json.toString(2));
+ return httpJsonTransaction(path, "PUT", headers, json, timeout);
+ }
+ public JSONObject operationOdl(String path, Long timeout, JSONObject json) {
+ JSONObject json1 = new JSONObject();
+ json1.put("input", json);
+ logger.debug("ODL operation: " + path + "\n" + json1.toString(2));
+ return httpJsonTransaction(path, "POST", null, json1, timeout);
+ }
+
+ public Object operation2(String path, EObject o, String opName, Long timeout, Object[] params) {
+ EOperation op = EUtils.name2operation(o.eClass(), opName);
+ if (op == null)
+ throw new RuntimeException("no such operation: " + opName + " on " + o);
+ JSONObject res = operationPath2(path, opName, timeout, ManagementServer.params2json(op, params));
+ return ManagementServer.json2response(op, res);
+ }
+
+ public JSONObject operation(String resourcePath, String opName, Long timeout, JSONObject json) {
+ return operationPath2(resourcePath, opName, timeout, json);
+ }
+
+ public Object operation(String path, EObject o, String opName, Long timeout, Object... params) {
+ return operation2(path, o, opName, timeout, params);
+ }
+
+ public Object operation(EObject o, String opName, Long timeout, Object... params) {
+ return operation2(map2.get(o), o, opName, timeout, params);
+ }
+
+ public Object operationPath(String resourcePath, EClass c, String opName, Long timeout, Object... params) {
+ EOperation op = EUtils.name2operation(c, opName);
+ if (op == null) {
+ throw new RuntimeException("Unknown operation " + opName + " on Eclass " + c.getName());
+ }
+ JSONObject res;
+ JSONObject json1 = ManagementServer.params2json(op, params);
+ if (language != null && language.equals("restconf")) {
+ res = operationOdl("/restconf/operations/" + namespace + ":" + opName,timeout,json1);
+ }
+ else {
+ res = operationPath2(resourcePath, op.getName(), timeout, json1 );
+ }
+ return ManagementServer.json2response(op, res);
+ }
+
+ // abstract public void sendToDataRouter(String feedname, String fileId,
+ // JSONObject metadata, InputStream is);
+
+ // public void sendToDataRouter(String feedname, String fileId, JSONObject
+ // metadata, byte[] bytes) {
+ // ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+ // sendToDataRouter(feedname, fileId, metadata, in);
+ // }
+
+ public void create(String resourcePath, String json) {
+ create(resourcePath, new JSONObject(json));
+ }
+
+ public void create(String resourcePath, JSONObject json) {
+ httpJsonTransaction(resourcePath, "POST", null, json, null);
+ }
+
+ public void update(String resourcePath, JSONObject json) {
+ httpJsonTransaction(resourcePath, "PUT", null, json, null);
+ }
+
+ public void delete(String resourcePath) {
+ httpJsonTransaction(resourcePath, "DELETE", null, new JSONObject(), null);
+ }
+
+ public JSONObject method(String resourcePath, String method, JSONObject json) {
+ return httpJsonTransaction(resourcePath, method, null, json, null);
+ }
+
+ public byte[] methodAsBinary(String resourcePath, String method, JSONObject json) {
+ return httpBinaryTransaction(resourcePath, method, null, json, null);
+ }
+
+ public String methodAsString(String resourcePath, String method, JSONObject json) {
+ return httpStringTransaction(resourcePath, method, null, json, null);
+ }
+
+ public JSONObject list(String resourcePath) {
+ if (language != null && language.equals("rest")) {
+ return httpJsonTransaction(resourcePath, "GET", null, new JSONObject(), null);
+ } else {
+ return list(resourcePath, 1);
+ }
+ }
+
+ public JSONObject listAll(String resourcePath) {
+ return httpJsonTransaction(resourcePath + "?match=regexp", "GET", null, new JSONObject(), null);
+ }
+
+ public JSONObject listReferences(String resourcePath, boolean recursive) {
+ return httpJsonTransaction(resourcePath + "?references=" + recursive, "GET", null, new JSONObject(), null);
+ }
+
+ public JSONObject list(String resourcePath, int levels) {
+ return httpJsonTransaction(resourcePath + "?levels=" + levels, "GET", null, new JSONObject(), null);
+ }
+
+ public JSONObject httpJsonTransaction(String path, String method, HashMap<String, String> headers, JSONObject body) {
+ return httpJsonTransaction(path, method, headers, body,null);
+ }
+
+ public JSONObject httpJsonTransaction(String path, String method, HashMap<String, String> headers, JSONObject body, Long timeout) {
+ String s = httpStringTransaction(path, method, headers, body, timeout);
+ if (s == null) return null;
+ if (s.startsWith("[")) {
+ JSONArray a = new JSONArray(s);
+ JSONObject json = new JSONObject();
+ json.put("$list", a);
+ return json;
+ } else {
+ logger.info("json returned <- " + "'" + s + "'");
+ JSONObject json = (!s.isEmpty()) ? new JSONObject(s) : new JSONObject();
+ return json;
+ }
+ }
+
+ public String httpStringTransaction(String path, String method, HashMap<String, String> headers, JSONObject body, Long timeout) {
+ byte[] b = httpBinaryTransaction(path, method, headers, body, timeout);
+ if (b == null) return null;
+ else return new String(b);
+ }
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerAdaptorProvider.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerAdaptorProvider.java
new file mode 100644
index 0000000..70ad116
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerAdaptorProvider.java
@@ -0,0 +1,63 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+
+package org.openecomp.ncomp.servers.docker;
+
+
+
+
+
+import java.io.InputStream;
+
+import org.openecomp.ncomp.sirius.manager.IRequestHandler;
+import org.openecomp.ncomp.sirius.manager.ISiriusPlugin;
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.function.FunctionUtils;
+
+import org.apache.log4j.Logger;
+import org.eclipse.emf.common.util.EList;
+import org.json.JSONObject;
+
+
+
+import org.openecomp.ncomp.sirius.manager.BasicAdaptorProvider;
+
+
+import org.openecomp.ncomp.docker.impl.DockerAdaptorImpl;
+import org.openecomp.ncomp.docker.DockerAdaptor;
+
+
+public class DockerDockerAdaptorProvider extends BasicAdaptorProvider {
+ private static final Logger logger = Logger.getLogger(DockerDockerAdaptorProvider.class);
+ DockerAdaptor o;
+
+ public DockerDockerAdaptorProvider(ISiriusServer controller, DockerAdaptor o) {
+ super(controller, o);
+ this.o = o;
+ }
+
+
+
+
+
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerHostProvider.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerHostProvider.java
new file mode 100644
index 0000000..d3888dc
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerDockerHostProvider.java
@@ -0,0 +1,968 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+import java.net.URLEncoder;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.io.UnsupportedEncodingException;
+
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+import org.openecomp.ncomp.sirius.manager.ManagementServerUtils;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import org.openecomp.ncomp.sirius.manager.BasicAdaptorProvider;
+import org.openecomp.ncomp.docker.ContainerOptions;
+import org.openecomp.ncomp.docker.ContainerCpuUsage;
+import org.openecomp.ncomp.docker.ContainerCpuStats;
+import org.openecomp.ncomp.docker.ContainerPortBindings;
+import org.openecomp.ncomp.docker.ContainerNetworkStats;
+import org.openecomp.ncomp.docker.ContainerMemoryStats;
+import org.openecomp.ncomp.docker.ContainerMemoryUsage;
+import org.openecomp.ncomp.docker.ContainerRestartPolicy;
+import org.openecomp.ncomp.docker.DockerContainer;
+import org.openecomp.ncomp.docker.DockerContainerStats;
+import org.openecomp.ncomp.docker.DockerFactory;
+import org.openecomp.ncomp.docker.DockerProcess;
+import org.openecomp.ncomp.docker.DockerHost;
+import org.openecomp.ncomp.docker.DockerImage;
+import org.openecomp.ncomp.docker.DockerNetwork;
+import org.openecomp.ncomp.docker.DockerPackage;
+
+import org.eclipse.emf.common.util.EList;
+
+class DockerDockerHostProvider extends BasicAdaptorProvider {
+
+ private static final Logger logger = Logger.getLogger(DockerDockerHostProvider.class);
+
+ DockerHost o;
+ DockerHttpClient client;
+ protected Date lastPoll;
+
+ //
+ // Docker endpoint types are --
+ // -> containers
+ // -> images
+ // -> networks
+ // -> misc
+ //
+ private static final String CONTAINERS = "/containers/";
+ private static final String IMAGES = "/images/";
+ private static final String NETWORKS = "/networks/";
+ private static final String MISC = "/misc/";
+
+ private static final String GET_METHOD = "GET";
+ private static final String POST_METHOD = "POST";
+ private static final String DELETE_METHOD = "DELETE";
+ private static final int PRETTY_PRINT = 4;
+ private static final int REPO = 0;
+ private static final int PORT = 1;
+ private static final int NAME = 2;
+ private static final int VER = 3;
+
+ private enum ContainerState {
+ CREATED, STOPPED, RUNNING, PAUSED, DELETED
+ }
+
+ private enum ContainerEvents {
+ CREATE, START, STOP, RESTART, PAUSE, UNPAUSE, KILL, DESTORY
+ }
+
+ private JSONObject encodeAuth(String json) {
+ String auth = Base64.encodeBase64String(json.getBytes());
+ return new JSONObject(auth);
+ }
+
+ public DockerDockerHostProvider(ISiriusServer controller, DockerHost o) {
+ super(controller, o);
+ this.o = o;
+ this.client = new DockerHttpClient("docker.properties","dockerHost");
+ }
+
+ @Override
+ public void start() {
+ if (o.isRemote()) return;
+ Thread t = new Thread("docker poller: " + o.getName()) {
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ if (lastPoll == null
+ || lastPoll.getTime() + o.getPollingFrequency() < new Date()
+ .getTime())
+ o.poll();
+ Thread.sleep(5000); // sleep 5 seconds
+ } catch (Exception e) {
+ ManagementServerUtils.printStackTrace(e);
+ logger.fatal("openstackPoller Thread DIED: " + e);
+ try {
+ Thread.sleep(30000);
+ } catch (InterruptedException e1) {
+ }
+ }
+ }
+ };
+ };
+ t.start();
+ }
+
+ protected void poll() {
+ logger.info("XXXX poll");
+ lastPoll = new Date();
+ JSONObject json = callRemoteApi("/images/json", GET_METHOD);
+ logger.info("XXXX res:" + json.toString(2));
+ updateImages(json);
+ // containers
+ // if you only want to see running containers, set "all" to false
+ // this results in only running containers being shown
+ //
+ int ALL=1;
+ json = callRemoteApi("/containers/json?all=" + ALL, GET_METHOD);
+ logger.info("XXXX res:" + json.toString(2));
+ updateContainers(json);
+ // networks
+ json = callRemoteApi("/networks", GET_METHOD);
+ logger.info("XXXX res:" + json.toString(2));
+ updateNetworks(json);
+ updateContainerStats();
+
+ logger.info("XXXX " + ManagementServer.ecore2json(o, 100, null, true).toString(2));
+ }
+
+ /*
+ * json to provide with request to create a container from an image
+ */
+ private JSONObject mkContainerJson(String image) {
+
+ StringBuilder json = new StringBuilder();
+
+ json.append("{");
+ json.append("\"Hostname\":\"\",");
+ json.append("\"User\":\"\",");
+ json.append("\"Memory\":0,");
+ json.append("\"MemorySwam\":0,");
+ json.append("\"AttachStdin\":false,");
+ json.append("\"AttachStdout\":true,");
+ json.append("\"AttachStderr\":true,");
+ json.append("\"PortSpecs\":null,");
+ json.append("\"Privleged\":false,");
+ json.append("\"Tty\":false,");
+ json.append("\"OpenStdin\":false,");
+ json.append("\"StdinOnce\":false,");
+ json.append("\"Env\":null,");
+ json.append("\"Dns\":null,");
+ json.append("\"Image\":\"<image>\",");
+ json.append("\"Volumes\":null,");
+ json.append("\"VolumesFrom\":null,");
+ json.append("\"WorkingDir\":\"\",");
+ json.append("}");
+
+
+ return new JSONObject(json.toString().replace("<image>", image));
+ }
+
+ /*
+ * this is a composite of two separate API calls. the first call creates the
+ * container. the second call starts the created container
+ */
+ public void dockerRun(String image) {
+ dockerRunWithName(image, null);
+ }
+
+ public void dockerRunWithName(String image, String name) {
+ logger.debug("image <-" + image);
+ boolean chkEnv = false;
+
+ if (chkEnv) {
+ Map<String,String> env = System.getenv();
+ for(Map.Entry<String,String> entry : env.entrySet()) {
+ if (entry.getKey().toLowerCase().contains("proxy")) {
+ logger.debug(entry.getKey() + " = " + entry.getValue());
+ }
+ }
+ }
+
+ String api = "/containers/create";
+ if (name != null) {
+ api += "?name=" + name;
+ }
+
+ JSONObject jobj = mkContainerJson(image);
+
+ logger.info("container json <- " + jobj.toString(PRETTY_PRINT));
+
+ JSONObject json = callRemoteApi(api, POST_METHOD, jobj);
+
+ // 201 - no error
+ // 404 - no such container
+ // 406 - impossible to attach (container not running)
+ // 500 - server error
+
+ if (client.getResponseCode() == 201) {
+ String shortId = json.getString("Id").substring(0,11);
+ logger.info("Starting container <- " + shortId);
+ startContainer(shortId);
+ }
+
+ }
+
+ public void dockerRunWithOptions(String image, ContainerOptions opts) {
+
+ String api = "/containers/create";
+ String name = opts.getName();
+
+ if (name != null) {
+ api += "?name=" + name;
+ }
+
+ JSONObject jobj = mkContainerJson(image);
+ JSONObject options = new JSONObject();
+ JSONArray binds = new JSONArray();
+
+ for(String binding : opts.getVolumes()) {
+ binds.put(binding);
+ }
+
+ if (binds.length() > 0) {
+ options.put("Binds",binds);
+ }
+
+ JSONObject portBindings = new JSONObject();
+ JSONObject exposedPorts = new JSONObject();
+
+ for(ContainerPortBindings portMap : opts.getPortBindings()) {
+ String tag = Integer.toString(portMap.getContainerPort()) + "/" + portMap.getProtocol();
+ String val = Integer.toString(portMap.getVmPort());
+ JSONObject pair = new JSONObject().put("HostIp", "").put("HostPort", val);
+
+ if (portBindings.has(tag)) {
+ portBindings.accumulate(tag,pair);
+ } else {
+ portBindings.put(tag, new JSONArray().put(pair));
+ }
+ exposedPorts.put(tag, new JSONObject());
+ }
+
+ if (portBindings.length() > 0) {
+ options.put("PortBindings",portBindings);
+ }
+
+ // container links
+ if (!opts.getLinks().isEmpty()) {
+ JSONArray links = new JSONArray();
+ for(String fromLink : opts.getLinks()) {
+ String linkAlias = "";
+ String link = "";
+
+ if (fromLink.contains(":")) {
+ String[] ary = fromLink.split("\\:");
+ if (ary.length > 1) {
+ link = ary[0];
+ linkAlias = ary[1];
+ }
+ } else {
+ link = fromLink;
+ }
+
+ String fqLink = link + ":" + name + "/" + linkAlias;
+ links.put(fqLink);
+ }
+ options.put("Links", links);
+ }
+
+ // default behavior
+ opts.setPublishAllPorts(true);
+
+ if (opts.isPublishAllPorts()) {
+ options.put("PublishAllPorts", true);
+ }
+
+ // restart policy defaults
+ String policy = "always";
+ int retries = 0;
+
+ if (opts.getAutoRestart() != null && opts.getAutoRestart().getNm() != null) {
+ policy = opts.getAutoRestart().getNm();
+ }
+
+ if ("on-failure".equals(policy)) {
+ retries = opts.getAutoRestart().getMaxRetryCnt();
+ }
+
+ JSONObject restartPolicy = new JSONObject()
+ .put("Name", policy)
+ .put("MaximumRetryCount", retries);
+
+ options.put("RestartPolicy", restartPolicy);
+
+ if (options.length() > 0) {
+ jobj.put("HostConfig",options);
+ }
+
+ if (exposedPorts.length() > 0) {
+ jobj.put("ExposedPorts",exposedPorts);
+ }
+
+ JSONObject config = new JSONObject();
+
+ // add any runtime environment arguments
+ if (!opts.getEnv().isEmpty()) {
+ JSONArray rekv = new JSONArray();
+ for(String kv : opts.getEnv()) {
+ logger.debug("adding runtime argument " + kv);
+ rekv.put(kv);
+ }
+ jobj.put("Env", rekv);
+ }
+
+ opts.setSetContainerName(true);
+
+ if (opts.isSetContainerName()) {
+ try {
+ jobj.put("Hostname", InetAddress.getLocalHost().getHostName());
+ } catch(UnknownHostException e) {
+ logger.error("Unable to determine local hostname", e);
+ }
+ }
+
+ logger.info("container json <- " + jobj.toString(PRETTY_PRINT));
+
+ JSONObject json = callRemoteApi(api, POST_METHOD, jobj);
+
+ // 201 - no error
+ // 404 - no such container
+ // 406 - impossible to attach (container not running)
+ // 500 - server error
+
+ if (client.getResponseCode() == 201) {
+ String shortId = json.getString("Id").substring(0,11);
+ logger.info("Starting container <- " + shortId);
+ startContainer(shortId);
+ }
+
+
+ }
+
+ private void updateContainers(JSONObject json) {
+ JSONArray a = json.getJSONArray("$list");
+ o.getContainers().clear();
+ for (int i = 0; i < a.length(); i++) {
+ JSONObject j = a.getJSONObject(i);
+ decapitalize(j);
+ fixNull(j);
+ rename(j, "created", "dockerCreated");
+ fixMap(j, "hostConfig");
+ fixMap(j, "labels");
+ DockerContainer container = (DockerContainer) controller
+ .getServer().json2ecore(
+ DockerPackage.eINSTANCE.getDockerContainer(), j);
+ if (container.getNames().size()>0)
+ container.setName(container.getNames().get(0).replace("/", ""));
+ else container.setName(container.getId().substring(0, 10));
+
+ // get container process info
+ //containerProcesses(container.getId());
+// String name = container.getId();
+// String api = CONTAINERS + name + "/top?ps_args=aux";
+// JSONObject jo = callRemoteApi(api,GET_METHOD);
+// DockerProcess[] dp = setPtbl(jo);
+ // so how do we actually update the DockerProcess processes
+ // member of the container class?
+ // EList<DockerProcess> cp = container.getProcesses();
+ // cp = (EList<DockerProcess>)Arrays.asList(dp);
+
+ System.err.println("XXXX "
+ + ManagementServer.ecore2json(container, 100, null, true)
+ .toString(2));
+ o.getContainers().add(container);
+ }
+ }
+
+ private void updateImages(JSONObject json) {
+
+
+ JSONArray a = json.getJSONArray("$list");
+ o.getImages().clear();
+ for (int i = 0; i < a.length(); i++) {
+ JSONObject j = a.getJSONObject(i);
+ decapitalize(j);
+ fixNull(j);
+ rename(j, "created", "dockerCreated");
+ if (j.has("labels")) j.remove("labels");
+ System.err.println("XXXX " + j.toString());
+ DockerImage image = (DockerImage) controller.getServer()
+ .json2ecore(DockerPackage.eINSTANCE.getDockerImage(), j);
+ // System.err.println("XXXX " + ManagementServer.ecore2json(image,
+ // 100, null, true).toString(2));
+ if (image.getRepoTags().size() > 0)
+ image.setName(image.getRepoTags().get(0));
+ image.setName(image.getName().replace("/", "_"));
+ o.getImages().add(image);
+ }
+ }
+
+
+ /*
+ * should probably break this up into discrete pieces for
+ * cpu, memory, blkio, and network. but this is good enough for now.
+ * blkio stats not modeled - since i'm not certain what is actually
+ * being reported
+ */
+ private void updateContainerStats() {
+
+ for(DockerContainer c : o.getContainers()) {
+ if (c.getStatus().equals("exited")) continue;
+ if (c.getStatus().startsWith("Exited")) continue;
+ if (c.getStatus().startsWith("Created")) continue;
+ String nm = c.getName();
+ JSONObject j = containerStats(nm,false);
+ logger.info("container stats json <- " + j.toString(4));
+
+ DockerContainerStats cstats = DockerFactory.eINSTANCE.createDockerContainerStats();
+
+ /*
+ * network stats
+ */
+ JSONObject netwks = j.getJSONObject("networks");
+ for(String net : JSONObject.getNames(netwks)) {
+ JSONObject intf = netwks.getJSONObject(net);
+ System.err.println(net + " <- " + intf.toString(4));
+ ContainerNetworkStats cnet = DockerFactory.eINSTANCE.createContainerNetworkStats();
+ cnet.setIntf(net);
+ cnet.setRx_bytes(intf.getInt("rx_bytes"));
+ cnet.setRx_dropped(intf.getInt("rx_dropped"));
+ cnet.setRx_errors(intf.getInt("rx_errors"));
+ cnet.setRx_packets(intf.getInt("rx_packets"));
+ cnet.setTx_bytes(intf.getInt("tx_bytes"));
+ cnet.setTx_dropped(intf.getInt("tx_dropped"));
+ cnet.setTx_errors(intf.getInt("tx_errors"));
+ cnet.setTx_packets(intf.getInt("tx_packets"));
+
+ cstats.getNetworks().add(cnet);
+ }
+
+ /*
+ * memory usage
+ */
+ JSONObject mem = j.getJSONObject("memory_stats");
+ ContainerMemoryUsage memusg = DockerFactory.eINSTANCE.createContainerMemoryUsage();
+
+ memusg.setUsage(mem.getInt("usage"));
+ memusg.setMax_usage(mem.getInt("max_usage"));
+ memusg.setLimit(mem.getInt("limit"));
+ memusg.setFailcnt(mem.getInt("failcnt"));
+
+ /*
+ * memory stats
+ */
+ if (mem.has("stats") && isaJSONObject(mem.get("stats"))) {
+ JSONObject mstats = mem.getJSONObject("stats");
+
+ if (mstats != null) {
+ ContainerMemoryStats memstats = DockerFactory.eINSTANCE.createContainerMemoryStats();
+ memstats.setActive_anon(mstats.getInt("active_anon"));
+ memstats.setActive_file(mstats.getInt("active_file"));
+ memstats.setCache(mstats.getInt("cache"));
+ memstats.setHierarchical_memory_limit(mstats.getInt("hierarchical_memory_limit"));
+ memstats.setInactive_anon(mstats.getInt("inactive_anon"));
+ memstats.setInactive_file(mstats.getInt("inactive_file"));
+ memstats.setMapped_file(mstats.getInt("mapped_file"));
+ memstats.setPgfault(mstats.getInt("pgfault"));
+ memstats.setPgmajfault(mstats.getInt("pgmajfault"));
+ memstats.setPgpgin(mstats.getInt("pgpgin"));
+ memstats.setPgpgout(mstats.getInt("pgpgout"));
+ memstats.setRss(mstats.getInt("rss"));
+ memstats.setRss_huge(mstats.getInt("rss_huge"));
+// memstats.setUnevictable(mstats.getInt("unevicatable"));
+ memstats.setTotal_active_anon(mstats.getInt("total_active_anon"));
+ memstats.setTotal_active_file(mstats.getInt("total_active_file"));
+ memstats.setTotal_cache(mstats.getInt("total_cache"));
+ memstats.setTotal_inactive_anon(mstats.getInt("total_inactive_anon"));
+ memstats.setTotal_inactive_file(mstats.getInt("total_inactive_file"));
+ memstats.setTotal_mapped_file(mstats.getInt("total_mapped_file"));
+ memstats.setTotal_pgfault(mstats.getInt("total_pgfault"));
+ memstats.setTotal_pgmajfault(mstats.getInt("total_pgmajfault"));
+ memstats.setTotal_pgpgin(mstats.getInt("total_pgpgin"));
+ memstats.setTotal_pgpgout(mstats.getInt("total_pgpgout"));
+ memstats.setTotal_rss(mstats.getInt("total_rss"));
+ memstats.setTotal_rss_huge(mstats.getInt("total_rss_huge"));
+ memstats.setTotal_unevictable(mstats.getInt("total_unevictable"));
+ memstats.setTotal_writeback(mstats.getInt("total_writeback"));
+
+ memusg.setMemstats(memstats);
+ }
+ }
+
+ cstats.setMemory(memusg);
+
+ /*
+ * cpu stats
+ */
+ ContainerCpuStats ccpustats = DockerFactory.eINSTANCE.createContainerCpuStats();
+ ContainerCpuUsage ccpuusage = DockerFactory.eINSTANCE.createContainerCpuUsage();
+
+ JSONObject jcpuusage = j.getJSONObject("cpu_stats").getJSONObject("cpu_usage");
+
+ ccpuusage.setTotal_usage(jcpuusage.getLong("total_usage"));
+ ccpuusage.setUsage_in_usermode(jcpuusage.getLong("usage_in_kernelmode"));
+ ccpuusage.setUser_in_kernelmode(jcpuusage.getLong("usage_in_usermode"));
+
+ JSONArray ccpupcpu = jcpuusage.getJSONArray("percpu_usage");
+
+ for(int idx = 0; idx < ccpupcpu.length(); idx++) {
+ ccpuusage.getPercpu_usage().add(ccpupcpu.getLong(idx));
+ }
+
+ ccpustats.setCpu_usage(ccpuusage);
+ cstats.setCpu(ccpustats);
+
+ c.setStats(cstats);
+ }
+
+ }
+
+ private static final boolean isaJSONObject(Object v) {
+ if (v.getClass().equals(JSONObject.class)) {
+ return true;
+ }
+ return false;
+ }
+
+ private void updateNetworks(JSONObject json) {
+ JSONArray a = json.getJSONArray("$list");
+ o.getNetworks().clear();
+ for (int i = 0; i < a.length(); i++) {
+ JSONObject j = a.getJSONObject(i);
+ decapitalize(j);
+ fixNull(j);
+ rename(j, "created", "dockerCreated");
+ fixMap(j, "containers", "id");
+ fixMap(j, "options");
+ DockerNetwork network = (DockerNetwork) controller.getServer()
+ .json2ecore(DockerPackage.eINSTANCE.getDockerNetwork(), j);
+ // System.err.println("XXXX " + ManagementServer.ecore2json(network,
+ // 100, null, true).toString(2));
+ o.getNetworks().add(network);
+ }
+ }
+
+ // change JSONObject to a JSONArray with name,value objects
+ private void fixMap(JSONObject j, String key) {
+ JSONArray a = new JSONArray();
+ if (!j.has(key)) return;
+ JSONObject jjj = j.getJSONObject(key);
+ for (Iterator<String> i = jjj.keys(); i.hasNext();) {
+ String k = i.next();
+ Object v = jjj.get(k);
+ JSONObject jj = new JSONObject();
+ jj.put("name", k);
+ jj.put("value", v);
+ a.put(jj);
+ }
+ j.put(key, a);
+ }
+
+ // change JSONObject to a JSONArray with name,value objects
+ private void fixMap(JSONObject j, String key, String nameKey) {
+ JSONArray a = new JSONArray();
+ JSONObject jjj = j.getJSONObject(key);
+ for (Iterator<String> i = jjj.keys(); i.hasNext();) {
+ String k = i.next();
+ JSONObject v = jjj.getJSONObject(k);
+ v.put(nameKey, k);
+ a.put(v);
+ }
+ j.put(key, a);
+ }
+
+ private void fixNull(JSONObject j) {
+ for (Iterator<String> i = j.keys(); i.hasNext();) {
+ String k = i.next();
+ Object v = j.get(k);
+ // System.err.println("XXXX " + v.getClass().getName());
+ if (v.getClass().getName().equals("org.json.JSONObject$Null")) {
+ j.put(k, new JSONArray());
+ System.err.println("XXXX change null to empty array " + k);
+ }
+ }
+ }
+
+ private void decapitalize(JSONObject j) {
+ ArrayList<String> l = new ArrayList<String>();
+ for (Iterator<String> i = j.keys(); i.hasNext();) {
+ l.add(i.next());
+ }
+ for (String k : l) {
+ Object v = j.get(k);
+ if (v instanceof JSONObject) {
+ JSONObject jj = (JSONObject) v;
+ decapitalize(jj);
+ }
+ if (v instanceof JSONArray) {
+ JSONArray a = (JSONArray) v;
+ for (int i = 0; i < a.length(); i++) {
+ Object v1 = a.get(i);
+ if (v1 instanceof JSONObject) {
+ JSONObject jj = (JSONObject) v1;
+ decapitalize(jj);
+ }
+ }
+ }
+ rename(j, k, k.substring(0, 1).toLowerCase() + k.substring(1));
+ }
+
+ }
+
+ private void rename(JSONObject j, String k1, String k2) {
+ if (k1.equals(k2))
+ return;
+ if (j.has(k1)) {
+ j.put(k2, j.get(k1));
+ j.remove(k1);
+ }
+ }
+
+ // run through json.get("Processes") arrays
+ // and generate a DockerProcess object
+ // "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND"
+ private DockerProcess[] setPtbl(JSONObject json) {
+
+ if (!json.has("Proccesses")) {
+ return null;
+ }
+ JSONArray processes = json.getJSONArray("Processes");
+ int sz = processes.length();
+
+ DockerProcess[] dprocs = new DockerProcess[sz];
+
+ for (int i=0; i < processes.length(); i++) {
+ JSONArray proc = processes.getJSONArray(i);
+ logger.debug("proc <- " + proc.toString(PRETTY_PRINT));
+
+ DateFormat df = new SimpleDateFormat();
+
+ DockerProcess dp = DockerFactory.eINSTANCE.createDockerProcess();
+ dp.setUser(proc.getString(0));
+ dp.setPid(proc.getLong(1));
+ dp.setCpu(proc.getDouble(2));
+ dp.setMem(proc.getDouble(3));
+ dp.setVsz(proc.getLong(4));
+ dp.setRss(proc.getLong(5));
+ dp.setTty(proc.getString(6));
+ dp.setStat(proc.getString(7));
+ dp.setCommand(proc.getString(10));
+ // 9th field is a duration indicator. FIXME
+ dp.setTimeElapsed(0);
+
+ try {
+ dp.setStart(df.parse(proc.getString(8)));
+ }
+ catch(ParseException ep) {
+ logger.warn("Could not parse " + proc.getString(8) + " into a Date");
+ dp.setStart(null);
+ }
+ catch(NullPointerException e){
+ logger.warn("Could not parse " + proc.getString(8) + " into a Date");
+ dp.setStart(null);
+ }
+
+ dprocs[i] = dp;
+ }
+
+ return dprocs;
+ }
+
+ /*
+ * many remote docker api calls do not return a json message
+ * your only indication of operational success will be in the
+ * http client response code. the json object will be null in
+ * those cases
+ */
+ private JSONObject callRemoteApi(String api, String method) {
+ return callRemoteApi(api,method,null);
+ }
+
+ private JSONObject callRemoteApi(String api, String method, JSONObject context) {
+
+ HashMap<String, String> headers = new HashMap<String, String>();
+ JSONObject json = null;
+
+ // this will be prepended to the api string passed into the method
+ String url = client.getBaseAddress();
+
+ logger.info("api <- " + method + " " + url + api);
+
+ switch(method) {
+ case GET_METHOD :
+ json = client.httpJsonTransaction(api, method, headers, null, 5000L);
+ break;
+ case POST_METHOD :
+ if (context == null) {
+ client.httpBinaryTransaction(api, method, headers, context, 5000L);
+ } else {
+ json = client.httpJsonTransaction(api,method, headers, context, 5000L);
+ }
+ break;
+ case DELETE_METHOD :
+ json = client.httpJsonTransaction(api, method, headers, null, 5000L);
+ break;
+ }
+
+ logger.info("http response <- " + client.getResponseCode());
+
+ if (json != null) {
+ logger.debug("json <- " + json.toString(PRETTY_PRINT));
+ }
+
+ return json;
+ }
+
+ private JSONArray callRemoteApiStream(String api, String method, JSONObject aContext) {
+
+ HashMap<String, String> headers = new HashMap<String, String>();
+ byte[] bytes;
+ JSONObject context = aContext;
+ String func = "callRemoteApiStream";
+
+ // this will be prepended to the api string passed into the method
+ String url = client.getBaseAddress();
+
+ logger.info("api <- " + method + " " + url + api);
+
+ bytes = client.httpBinaryTransaction(api, method, headers, context, 5000L);
+ logger.info("http response <- " + client.getResponseCode());
+
+ JSONObject json = new JSONObject(bytes.toString());
+ JSONArray a = json.getJSONArray("$list");
+
+ return a;
+ }
+
+ //
+ // GET /containers/(id)/json
+ //
+ // return low level information about a container
+ //
+ // should it be void? this is returns
+ public void inspectContainer(String name) {
+
+ int size = 0; // 1 - true, 0 - false
+ String url = CONTAINERS + name + "/json?size=" + size;
+
+ JSONObject json = callRemoteApi(url,GET_METHOD);
+ logger.info("container " + name + " <- " + json.toString(PRETTY_PRINT));
+
+ // status codes:
+ // 200 - no error
+ // 404 - no such container
+ // 500 - server error
+ // process JSON
+ }
+
+ // GET /containers/(id)/top
+ // List processes running in a container
+ public void containerProcesses(String name) {
+
+ String api = CONTAINERS + name + "/top?ps_args=aux";
+ JSONObject json = callRemoteApi(api,GET_METHOD);
+ logger.info("container " + name + " <- " + json.toString(PRETTY_PRINT));
+ setPtbl(json);
+ }
+
+ // POST /containers/(id)/kill
+ public void killContainer(String name,String sigint) {
+
+ String url = CONTAINERS + name + "/kill?signal=" + sigint;
+ JSONObject json = callRemoteApi(url,POST_METHOD);
+
+ // status codes:
+ // 204 - no error
+ // 404 - no such container
+ // 500 - server err
+ // process JSON
+ }
+
+ // POST /containers/(id)/restart?t=seconds
+ public void restartContainer(String name, int seconds) {
+
+ String url = CONTAINERS + name + "/restart?seconds=" + seconds;
+ JSONObject json = callRemoteApi(url,POST_METHOD);
+ // status codes:
+ // 204 - no error
+ // 404 - no such container
+ // 500 - server err
+ // process JSON
+ }
+
+ // remove - remove volumes, force - kill & remove
+ public void removeContainer(String name, boolean remove, boolean force) {
+
+ int rm = (force) ? 1 : 0;
+ int vol = (remove) ? 1 : 0;
+
+ String url = CONTAINERS + name + "?force=" + rm + "&v=" + vol;
+
+ JSONObject json = callRemoteApi(url,DELETE_METHOD);
+
+ // status codes:
+ // 204 - no error
+ // 400 - bad parameter
+ // 404 - no such container
+ // 500 - server error
+ // process JSON
+ }
+
+ // POST /containers/(id)/pause
+ public void pauseContainer(String name) {
+
+ String url = CONTAINERS + name + "/pause";
+ JSONObject json = callRemoteApi(url,POST_METHOD);
+
+ // status codes:
+ // 204 - no error
+ // 404 - no such container
+ // 500 - server err
+ // process JSON
+ }
+
+ // POST /containers/(id)/unpause
+ public void unpauseContainer(String name) {
+
+ String url = CONTAINERS + name + "/unpause";
+ JSONObject json = callRemoteApi(url,POST_METHOD);
+
+ // status codes:
+ // 204 - no error
+ // 404 - no such container
+ // 500 - server err
+ // process JSON
+ }
+
+ // GET /containers/(id)/stats?stream
+ // stream - true or false, if false, poll once and exit
+ public JSONObject containerStats(String name, boolean stream) {
+
+ String url = CONTAINERS + name + "/stats?stream=" + stream;
+ JSONObject json = callRemoteApi(url,GET_METHOD);
+
+ return json;
+ }
+
+ // POST /containers/(id)/start
+ public void startContainer(String name) {
+
+ String url = CONTAINERS + name + "/start";
+ JSONObject json = callRemoteApi(url,POST_METHOD);
+ // status codes:
+ // 200 - no error
+ // 304 - container already started
+ // 404 - no such container
+ // 500 - server err
+ }
+
+ // POST /containers/(id)/stop?t=seconds
+ // t = seconds to wait before killing the container
+ public void stopContainer(String name, int seconds) {
+
+ String url = CONTAINERS + name + "/stop?t=" + seconds;
+ JSONObject json = callRemoteApi(url,POST_METHOD);
+ // status codes:
+ // 204 - no error
+ // 304 - container already stopped
+ // 404 - no such container
+ // 500 - server err
+ }
+
+ private List<String> getImageNameElements(String image) {
+
+ List<String> a = new ArrayList<>();
+ for(String z : image.split("\\/")) {
+ String[] iz = z.split(":");
+ for(int i = 0; i < iz.length; i++) {
+ a.add(iz[i]);
+ }
+ }
+ return a;
+ }
+
+ /*
+ * return the latest version nbr of a package
+ */
+ private String getLatest(String image) {
+
+ List<String> vers = new ArrayList<>();
+
+ for(DockerImage im : o.getImages()) {
+ List<String> elms = getImageNameElements(im.getName());
+
+ if (image.contains(elms.get(NAME))) {
+ EList<String> tags = im.getRepoTags();
+ for(int i = 0; i < tags.size(); i++) {
+ List<String> repoElm = getImageNameElements(tags.get(i));
+ vers.add(repoElm.get(VER));
+ }
+ }
+ }
+ Collections.sort(vers);
+
+ return vers.get(vers.size()-1);
+ }
+
+ /*
+ * Tag the most current version of an image as latest
+ */
+ public void tagImage(String image, String ver, boolean force) {
+
+ int f = (force) ? 1 : 0;
+
+ if (ver.isEmpty()) {
+ ver = "latest";
+ }
+
+ List<String> elms = getImageNameElements(image);
+ String repo = elms.get(REPO);
+
+ String url = IMAGES + "/" + image + "/tag" + "?repo=" + repo + "&tag=" + ver + "&force=" + f;
+
+ JSONObject json = callRemoteApi(url,POST_METHOD);
+ // status codes:
+ // 201 - no error
+ // 400 - bad parameter
+ // 404 - no such image
+ // 500 - server err
+ }
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClient.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClient.java
new file mode 100644
index 0000000..0b9d43a
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClient.java
@@ -0,0 +1,196 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import java.io.*;
+import java.util.*;
+import java.net.*;
+
+import org.apache.log4j.Logger;
+import org.json.JSONObject;
+import org.apache.commons.codec.binary.Base64;
+
+import org.openecomp.ncomp.utils.CryptoUtils;
+import org.openecomp.ncomp.utils.PropertyUtil;
+
+public class DockerHttpClient extends DockerAbstractClient {
+
+ public static final Logger logger = Logger.getLogger(DockerHttpClient.class);
+ String authorization;
+ String baseAddress;
+ private boolean debug = true;
+ private int responseCode;
+
+ public int getResponseCode() {
+ return this.responseCode;
+ }
+
+ private static void safeClose(final OutputStream out) {
+ if (out != null) {
+ try {
+ out.close();
+ } catch(IOException e) {
+ logger.error("Failed to close stream " + e);
+ }
+ }
+ }
+
+ private static void safeClose(final InputStream in) {
+ if (in != null) {
+ try {
+ in.close();
+ } catch(IOException e) {
+ logger.error("Failed to close stream " + e);
+ }
+ }
+ }
+
+ public DockerHttpClient(String fileName, String endpoint) {
+ this.responseCode = 0;
+ try {
+ props = PropertyUtil.getPropertiesFromClasspath(fileName);
+ setBaseAddress(props.getProperty(endpoint + ".endpoint"));
+ if (getBaseAddress() == null) {
+ logger.error("unable to determine baseAddress for endpoint: " + endpoint + " in " + fileName);
+ throw new RuntimeException("unable to determine baseAddress for endpoint: " + endpoint + " in "
+ + fileName);
+ }
+ //String user = props.getProperty(endpoint + ".user");
+ //String password = decryptPassword(props.getProperty(endpoint + ".password"));
+ debug = Boolean.parseBoolean(props.getProperty(endpoint + ".debug", "false"));
+ //authorization = "Basic " + Base64.encodeBase64String((user + ":" + password).getBytes());
+ //authorization = authorization.trim();
+ } catch (Exception e) {
+ logger.error("creating client failed: " + e.getMessage());
+ }
+ }
+
+ private String decryptPassword(String s) {
+ if (s.startsWith("rsa:")) {
+ s = CryptoUtils.decryptPrivate(CryptoUtils.getKey("config/server.private"), s.substring(4));
+ }
+ return s;
+ }
+
+
+ public byte[] httpBinaryTransaction(String path, String method, HashMap<String, String> headers, JSONObject body,
+ Long timeout) {
+
+ byte[] rawbody = null;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ if ("DELETE".equals(method) || "GET".equals(method)) {
+ body = null;
+ }
+ if (body != null) {
+ rawbody = body.toString(2).getBytes();
+ if (rawbody.length == 0) {
+ rawbody = null;
+ }
+ }
+ String url = getBaseAddress() + path;
+ int tout = 60000;
+ if (timeout != null) {
+ // units? seconds or millis?
+ tout = (int) timeout.longValue();
+ }
+ try {
+ URL u = new URL(url);
+ HttpURLConnection uc = (HttpURLConnection) u.openConnection();
+ uc.setConnectTimeout(tout);
+ uc.setReadTimeout(tout);
+ if (headers == null)
+ headers = new HashMap<String, String>();
+
+ if (body != null) {
+ headers.put("Content-type", "application/json");
+ }
+ //headers.put("Authorization", authorization);
+ for (String n : headers.keySet()) {
+ uc.setRequestProperty(n, headers.get(n));
+ if (debug) {
+ System.err.println("HTTP REQUEST header: " + n + " " + headers.get(n));
+ }
+ }
+ uc.setRequestMethod(method);
+ if (debug)
+ System.err.println("HTTP REQUEST method: " + method + " " + uc.getRequestMethod());
+
+ if (rawbody != null && rawbody.length > 0) {
+ uc.setRequestProperty("Content-Length", Integer.toString(rawbody.length));
+ uc.setFixedLengthStreamingMode(rawbody.length);
+ uc.setDoOutput(true);
+ OutputStream os = uc.getOutputStream();
+ os.write(rawbody);
+ safeClose(os);
+ }
+ int rc = uc.getResponseCode();
+ this.responseCode = rc;
+ if (rc < 200 || rc >= 300) {
+ // do not throw an error - log the failure
+ //throw new DockerHttpClientException("HTTP Request Failed: URL: " + url + " code:" + rc + " msg:"
+ //+ uc.getResponseMessage());
+ logger.error("HTTP Request Failed. URL: " + url + " code: " + rc + " msg: " + uc.getResponseMessage());
+ throw new RuntimeException("Docker HTTP Request Failed. URL: " + url + " code: " + rc + " msg: " + uc.getResponseMessage());
+ }
+
+ //ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ int i;
+ InputStream is = uc.getInputStream();
+ byte[] buf = new byte[65536];
+ while ((i = is.read(buf)) > 0) {
+ baos.write(buf, 0, i);
+ }
+ safeClose(is);
+ //return baos.toByteArray();
+
+ } catch (RuntimeException re) {
+ throw re;
+ } catch (Exception e) {
+ logger.error("Exception <- " + e + " " + e.getMessage());
+ throw new RuntimeException("http error: " + e, e);
+ }
+ return baos.toByteArray();
+ }
+
+ public String getBaseAddress() {
+ return baseAddress;
+ }
+
+ public void setBaseAddress(String baseAddress) {
+ this.baseAddress = baseAddress;
+ }
+
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+ public void httpBinaryTransaction(String path, String method, HashMap<String, String> headers, InputStream i, int j) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void httpJsonTransaction(String path, String method, HashMap<String, String> headers, InputStream i, int j) {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClientException.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClientException.java
new file mode 100644
index 0000000..c9aa78e
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/DockerHttpClientException.java
@@ -0,0 +1,31 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+class DockerHttpClientException extends RuntimeException {
+ public DockerHttpClientException(String string) {
+ super(string);
+ }
+
+ private static final long serialVersionUID = 1L;
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerInspect.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerInspect.java
new file mode 100644
index 0000000..2e81d9a
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerInspect.java
@@ -0,0 +1,52 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+
+public class TestDockerInspect implements ISiriusServer {
+
+ private ManagementServer server;
+
+ public static void main(String[] args) {
+ TestDockerInspect t = new TestDockerInspect();
+ String containerId = args[0];
+ t.dockerRun(containerId);
+ }
+
+ private void dockerRun(String container) {
+ server = new ManagementServer();
+ DockerDockerHost dockerd = new DockerDockerHost(this);
+ System.out.println("inspect container <- ");
+ dockerd.inspectContainer(container);
+
+ System.out.println("container processes <- ");
+ dockerd.containerProcesses(container);
+ }
+
+ @Override
+ public ManagementServer getServer() {
+ return server;
+ }
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRun.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRun.java
new file mode 100644
index 0000000..dcbe4a9
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRun.java
@@ -0,0 +1,102 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import org.openecomp.ncomp.docker.ContainerOptions;
+import org.openecomp.ncomp.docker.ContainerPortBindings;
+import org.openecomp.ncomp.docker.ContainerRestartPolicy;
+import org.openecomp.ncomp.docker.DockerFactory;
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+
+import java.util.List;
+import java.util.ArrayList;
+
+public class TestDockerRun implements ISiriusServer {
+
+ private ManagementServer server;
+
+ public static void main(String[] args) {
+ TestDockerRun t = new TestDockerRun();
+ String dockerRegistry = "cdf-2.novalocal:7113";
+ String dockerImage = "dcae-controller-sdnlocal";
+ String dockerImageTag = "latest";
+ String image = dockerRegistry + "/" + dockerImage + ":" + dockerImageTag;
+
+ t.dockerRun(image);
+ }
+
+ private void dockerRun(String image) {
+ server = new ManagementServer();
+ DockerDockerHost dockerd = new DockerDockerHost(this);
+ boolean withOpts = true;
+
+ if (withOpts) {
+ ContainerOptions opts = DockerFactory.eINSTANCE.createContainerOptions();
+
+ // explicit port mapping
+ ContainerPortBindings portBinds = DockerFactory.eINSTANCE.createContainerPortBindings();
+ portBinds.setContainerPort(27001);
+ portBinds.setProtocol("tcp");
+ portBinds.setVmPort(27001);
+ opts.getPortBindings().add(portBinds);
+
+ // container name
+ opts.setName("kens_folly");
+
+ // vm to container volume mapping
+ opts.getVolumes().add("/var/log:/opt/app/logs");
+
+ // publish exposed ports to an ephemeral vm port
+ opts.setPublishAllPorts(true);
+
+ // set the containerName equal to the VM name
+ opts.setSetContainerName(true);;
+
+ // set restart policy
+ // if the docker engine is stopped and containers killed - this will
+ // instruct the docker engine to restart those containers when it
+ // is brought back up
+ ContainerRestartPolicy restartPolicy = DockerFactory.eINSTANCE.createContainerRestartPolicy();
+ restartPolicy.setNm("always");
+ restartPolicy.setMaxRetryCnt(0);
+ opts.setAutoRestart(restartPolicy);
+
+ // add some environment variables
+ List<String> rtEnv = new ArrayList<>();
+ rtEnv.add("FOO=bar");
+ rtEnv.add("BAR=baz");
+ rtEnv.add("BAz=foo");
+ opts.getEnv().addAll(rtEnv);
+
+ dockerd.dockerRunWithOptions(image, opts);
+ } else {
+ dockerd.dockerRunWithName(image, "kens_folly");
+ }
+ }
+
+ @Override
+ public ManagementServer getServer() {
+ return server;
+ }
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRunLinks.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRunLinks.java
new file mode 100644
index 0000000..0d92e90
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRunLinks.java
@@ -0,0 +1,102 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import org.openecomp.ncomp.docker.ContainerOptions;
+import org.openecomp.ncomp.docker.ContainerPortBindings;
+import org.openecomp.ncomp.docker.ContainerRestartPolicy;
+import org.openecomp.ncomp.docker.DockerFactory;
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+
+public class TestDockerRunLinks implements ISiriusServer {
+
+ private ManagementServer server;
+
+ public static void main(String[] args) {
+
+ TestDockerRunLinks t = new TestDockerRunLinks();
+
+ String dockerRegistry = "cdf-2.novalocal:7113";
+ String dockerImage = "dcae-mysql";
+ String dockerImageTag = "5.7";
+ String image = dockerRegistry + "/" + dockerImage + ":" + dockerImageTag;
+
+ ContainerOptions opts = DockerFactory.eINSTANCE.createContainerOptions();
+
+ String containerName = dockerImage + "_kens_test";
+
+ // container name
+ opts.setName(containerName);
+
+ // vm to container volume mapping
+ opts.getVolumes().add("/var/log:/opt/app/logs");
+
+ // publish exposed ports to an ephemeral vm port
+ opts.setPublishAllPorts(true);
+
+ // set restart policy
+ // if the docker engine is stopped and containers killed - this will
+ // instruct the docker engine to restart those containers when it
+ // is brought back up
+ ContainerRestartPolicy restartPolicy = DockerFactory.eINSTANCE.createContainerRestartPolicy();
+ restartPolicy.setNm("always");
+ restartPolicy.setMaxRetryCnt(0);
+ opts.setAutoRestart(restartPolicy);
+
+ // mysql runtime arguments
+ // not really necessary because we set these in the Dockerfile
+ /*
+ opts.getEnv().add("MYSQL_USER=nmsadm");
+ opts.getEnv().add("MYSQL_PASSWORD=nmsadm");
+ opts.getEnv().add("MYSQL_DATABASE=ucsnmp");
+ opts.getEnv().add("MYSQL_ROOT_PASSWORD=dcae");
+ */
+
+ System.err.println("Starting first container " + opts.getName() + " ...");
+ t.dockerRun(image,opts);
+
+ // create container to link to the previous one
+ ContainerOptions linkOpts = DockerFactory.eINSTANCE.createContainerOptions();
+ String linkedImage = dockerRegistry + "/" + "dcae-controller-snmptrap" + ":" + "5.7";
+ linkOpts.getLinks().add(containerName + ":" + "mysql");
+ linkOpts.setName("dcae-controller-snmptrap" + "_kens_test");
+ linkOpts.setPublishAllPorts(true);
+
+ System.err.println("Starting second container " + opts.getName() + " ...");
+ t.dockerRun(linkedImage,linkOpts);
+
+ }
+
+ private void dockerRun(String image, ContainerOptions opts) {
+ server = new ManagementServer();
+ DockerDockerHost dockerd = new DockerDockerHost(this);
+
+ dockerd.dockerRunWithOptions(image, opts);
+ }
+
+ @Override
+ public ManagementServer getServer() {
+ return server;
+ }
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerStop.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerStop.java
new file mode 100644
index 0000000..eb9e88e
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerStop.java
@@ -0,0 +1,52 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+
+public class TestDockerStop implements ISiriusServer {
+
+ private ManagementServer server;
+
+ public static void main(String[] args)
+ throws InterruptedException {
+
+ TestDockerStop t = new TestDockerStop();
+ String containerNm = "kens_folly";
+ t.dockerStop(containerNm);
+ }
+
+ private void dockerStop(String container)
+ throws InterruptedException {
+ server = new ManagementServer();
+ DockerDockerHost dockerd = new DockerDockerHost(this);
+
+ dockerd.removeContainer(container,true,true);
+ }
+
+ @Override
+ public ManagementServer getServer() {
+ return server;
+ }
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestPolling.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestPolling.java
new file mode 100644
index 0000000..450a41f
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestPolling.java
@@ -0,0 +1,52 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+package org.openecomp.ncomp.servers.docker;
+
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+
+/*
+ * the polled docker-engine is defined in docker.properties
+ * dockerHost.endpoint=https://host.domaon:port
+ *
+ */
+public class TestPolling implements ISiriusServer {
+
+ public static void main(String[] args) {
+ TestPolling t = new TestPolling();
+ t.poll();
+ }
+
+ private ManagementServer server;
+
+ private void poll() {
+ server = new ManagementServer();
+ DockerDockerHost h = new DockerDockerHost(this);
+ h.poll();
+ }
+
+ @Override
+ public ManagementServer getServer() {
+ return server;
+ }
+
+}
diff --git a/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/gui/DockerGuiClientApiProvider.java b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/gui/DockerGuiClientApiProvider.java
new file mode 100644
index 0000000..884baf3
--- /dev/null
+++ b/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/gui/DockerGuiClientApiProvider.java
@@ -0,0 +1,78 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * OPENECOMP - DCAE
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ * Licensed 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.
+ * ============LICENSE_END============================================
+ */
+
+
+package org.openecomp.ncomp.servers.docker.gui;
+
+
+
+
+
+import java.io.InputStream;
+
+import org.openecomp.ncomp.sirius.manager.IRequestHandler;
+import org.openecomp.ncomp.sirius.manager.ISiriusPlugin;
+import org.openecomp.ncomp.sirius.manager.ISiriusServer;
+import org.openecomp.ncomp.sirius.function.FunctionUtils;
+
+import org.apache.log4j.Logger;
+import org.eclipse.emf.common.util.EList;
+import org.json.JSONObject;
+
+
+
+import org.openecomp.ncomp.sirius.gui.tools.*;
+
+
+import org.openecomp.ncomp.gwt.siriusportal.model.*;
+
+
+import org.openecomp.ncomp.sirius.manager.Subject;
+
+
+import org.openecomp.ncomp.sirius.manager.ManagementServer;
+
+
+import org.openecomp.ncomp.sirius.manager.server.AbstractManagementServer;
+
+
+import org.openecomp.ncomp.sirius.manager.BasicGuiClientApiProvider;
+
+
+import org.openecomp.ncomp.gwt.siriusportal.model.impl.GuiClientApiImpl;
+import org.openecomp.ncomp.gwt.siriusportal.model.GuiClientApi;
+
+
+public class DockerGuiClientApiProvider extends BasicGuiClientApiProvider {
+ private static final Logger logger = Logger.getLogger(DockerGuiClientApiProvider.class);
+ GuiClientApi o;
+
+ public DockerGuiClientApiProvider(ISiriusServer controller, GuiClientApi o) {
+ super(controller, o);
+ this.o = o;
+ }
+
+
+
+
+
+
+}