diff options
author | Carsten Lund <lund@research.att.com> | 2017-05-02 02:12:12 +0000 |
---|---|---|
committer | Carsten Lund <lund@research.att.com> | 2017-05-02 02:12:12 +0000 |
commit | 3c1f68ba21fa40fdc508e770015e888123772afc (patch) | |
tree | a127aa12dcba8c4c91ffa30b3fe2f54bc662f929 | |
parent | ad9a84ca5fa65171088a9708dce197da3e324349 (diff) |
[DCAE-15] Changes related to version 1.1 (2)
Change-Id: I2805362fb66130180bb178ba1bd2775a16ed090a
Signed-off-by: Carsten Lund <lund@research.att.com>
3 files changed, 45 insertions, 49 deletions
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 index 2fc41a8..a5f2331 100644 --- 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 @@ -176,7 +176,6 @@ public abstract class DockerAbstractClient { json.put("$list", a); return json; } else { - logger.info("json returned <- " + "'" + s + "'"); JSONObject json = (!s.isEmpty()) ? new JSONObject(s) : new JSONObject(); return json; } 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 index 8ea1ba9..8c83df5 100644 --- 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 @@ -72,6 +72,8 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { DockerHost o; DockerHttpClient client; protected Date lastPoll; + + private Long timeout; // // Docker endpoint types are -- @@ -106,6 +108,8 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { super(controller, o); this.o = o; this.client = new DockerHttpClient("docker.properties","dockerHost"); + if (client != null && client.props != null) + timeout = Long.parseLong(client.props.getProperty("dockerHost.timeout", "60000")); } @Override @@ -229,7 +233,6 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { if (client.getResponseCode() == 201) { String shortId = json.getString("Id").substring(0,11); - logger.info("Starting container <- " + shortId); startContainer(shortId); } @@ -363,11 +366,10 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { // 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); - } + if (client.getResponseCode() == 201) { + String shortId = json.getString("Id").substring(0, 11); + startContainer(shortId); + } } @@ -418,13 +420,13 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { fixNull(j); rename(j, "created", "dockerCreated"); if (j.has("labels")) j.remove("labels"); -// System.err.println("XXXX " + j.toString()); +// System.err.println("XXXX " + j.toString(2)); 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)); + else + image.setName(image.getRepoDigests().get(0)); image.setName(image.getName().replace("/", "_")); o.getImages().add(image); } @@ -723,21 +725,19 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { // 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); + json = client.httpJsonTransaction(api, method, headers, null, timeout); break; case POST_METHOD : if (context == null) { - client.httpBinaryTransaction(api, method, headers, context, 5000L); + client.httpBinaryTransaction(api, method, headers, context, timeout); } else { - json = client.httpJsonTransaction(api,method, headers, context, 5000L); + json = client.httpJsonTransaction(api,method, headers, context, timeout); } break; case DELETE_METHOD : - json = client.httpJsonTransaction(api, method, headers, null, 5000L); + json = client.httpJsonTransaction(api, method, headers, null, timeout); break; } @@ -762,7 +762,7 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { logger.info("api <- " + method + " " + url + api); - bytes = client.httpBinaryTransaction(api, method, headers, context, 5000L); + bytes = client.httpBinaryTransaction(api, method, headers, context, timeout); logger.info("http response <- " + client.getResponseCode()); JSONObject json = new JSONObject(bytes.toString()); @@ -863,6 +863,7 @@ class DockerDockerHostProvider extends BasicAdaptorProvider { String url = CONTAINERS + name + "/unpause"; JSONObject json = callRemoteApi(url,POST_METHOD); + logger.debug("unpauseContainer: " + (json != null ? json.toString(2) : "NULL")); // status codes: // 204 - no error 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 index 0b9d43a..42b373c 100644 --- 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 @@ -21,14 +21,16 @@ package org.openecomp.ncomp.servers.docker; -import java.io.*; -import java.util.*; -import java.net.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.HashMap; 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; @@ -84,20 +86,12 @@ public class DockerHttpClient extends DockerAbstractClient { } } - 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; } @@ -113,6 +107,8 @@ public class DockerHttpClient extends DockerAbstractClient { // units? seconds or millis? tout = (int) timeout.longValue(); } + InputStream is = null; + OutputStream os = null; try { URL u = new URL(url); HttpURLConnection uc = (HttpURLConnection) u.openConnection(); @@ -120,11 +116,11 @@ public class DockerHttpClient extends DockerAbstractClient { uc.setReadTimeout(tout); if (headers == null) headers = new HashMap<String, String>(); - + if (body != null) { - headers.put("Content-type", "application/json"); + headers.put("Content-type", "application/json"); } - //headers.put("Authorization", authorization); + // headers.put("Authorization", authorization); for (String n : headers.keySet()) { uc.setRequestProperty(n, headers.get(n)); if (debug) { @@ -132,42 +128,42 @@ public class DockerHttpClient extends DockerAbstractClient { } } uc.setRequestMethod(method); - if (debug) + 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 = 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()); + // throw new DockerHttpClientException("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(); + + // ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i; - InputStream is = uc.getInputStream(); + 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); + } finally { + safeClose(os); + safeClose(is); } return baos.toByteArray(); } |