Search in sources :

Example 1 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method createExecResponseHandler.

private ResponseHandler<Object> createExecResponseHandler(LogOutputSpec outputSpec) throws FileNotFoundException {
    final LogCallback callback = new DefaultLogCallback(outputSpec);
    return new ResponseHandler<Object>() {

        @Override
        public Object handleResponse(HttpResponse response) throws IOException {
            try (InputStream stream = response.getEntity().getContent()) {
                LineNumberReader reader = new LineNumberReader(new InputStreamReader(stream));
                String line;
                try {
                    callback.open();
                    while ((line = reader.readLine()) != null) {
                        callback.log(1, new Timestamp(), line);
                    }
                } catch (LogCallback.DoneException e) {
                // Ok, we stop here ...
                } finally {
                    callback.close();
                }
            }
            return null;
        }
    };
}
Also used : BuildJsonResponseHandler(io.fabric8.maven.docker.access.chunked.BuildJsonResponseHandler) BodyAndStatusResponseHandler(io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.BodyAndStatusResponseHandler) ResponseHandler(org.apache.http.client.ResponseHandler) LogCallback(io.fabric8.maven.docker.access.log.LogCallback) DefaultLogCallback(io.fabric8.maven.docker.log.DefaultLogCallback) HttpResponse(org.apache.http.HttpResponse) DefaultLogCallback(io.fabric8.maven.docker.log.DefaultLogCallback)

Example 2 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class LogRequestor method callLogCallback.

private void callLogCallback(int type, String txt) throws LogCallback.DoneException {
    Matcher matcher = LOG_LINE.matcher(txt);
    if (!matcher.matches()) {
        callback.error(String.format("Invalid log format for '%s' (expected: \"<timestamp> <txt>\") [%04x %04x]", txt, (int) (txt.toCharArray())[0], (int) (txt.toCharArray())[1]));
        throw new LogCallback.DoneException();
    }
    Timestamp ts = new Timestamp(matcher.group("timestamp"));
    String logTxt = matcher.group("entry");
    callback.log(type, ts, logTxt);
}
Also used : Matcher(java.util.regex.Matcher) Timestamp(io.fabric8.maven.docker.util.Timestamp)

Example 3 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class QueryService method getLatestContainerForImage.

/**
 * Get the id of the latest container started for an image
 *
 * @param image for which its container are looked up
 * @return container or <code>null</code> if no container has been started for this image.
 * @throws DockerAccessException if the request fails
 */
public Container getLatestContainerForImage(String image) throws DockerAccessException {
    long newest = 0;
    Container result = null;
    for (Container container : getContainersForImage(image)) {
        long timestamp = container.getCreated();
        if (timestamp < newest) {
            continue;
        }
        newest = timestamp;
        result = container;
    }
    return result;
}
Also used : Container(io.fabric8.maven.docker.model.Container)

Example 4 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class DefaultLogCallbackTest method before.

@Before
public void before() throws IOException {
    file = File.createTempFile("logcallback", ".log");
    file.deleteOnExit();
    spec = new LogOutputSpec.Builder().prefix("callback-test> ").file(file.toString()).build();
    callback = new DefaultLogCallback(spec);
    callback.open();
    ts = new Timestamp("2016-12-21T15:09:00.999666333Z");
}
Also used : Timestamp(io.fabric8.maven.docker.util.Timestamp) Before(org.junit.Before)

Example 5 with Timestamp

use of io.fabric8.maven.docker.util.Timestamp in project docker-maven-plugin by fabric8io.

the class LogMatchCallbackTest method matchingPartitialLineSucceeds.

@Test(expected = LogCallback.DoneException.class)
public void matchingPartitialLineSucceeds() throws Exception {
    final String patterString = "waiting for connections";
    final LogMatchCallback logMatchCallback = new LogMatchCallback(logger, callback, patterString);
    new Expectations() {

        {
            callback.matched();
            times = 1;
        }
    };
    logMatchCallback.log(1, new Timestamp(), "2017-11-21T12:44:43.678+0000 I NETWORK  [initandlisten] waiting for connections on port 27017");
}
Also used : Expectations(mockit.Expectations) Timestamp(io.fabric8.maven.docker.util.Timestamp) Test(org.junit.Test)

Aggregations

Timestamp (io.fabric8.maven.docker.util.Timestamp)6 Test (org.junit.Test)6 Expectations (mockit.Expectations)4 QueryResult (io.fabric8.insight.metrics.model.QueryResult)3 Map (java.util.Map)3 LogResults (io.fabric8.insight.log.LogResults)2 MBeanAttrResult (io.fabric8.insight.metrics.model.MBeanAttrResult)2 MBeanAttrsResult (io.fabric8.insight.metrics.model.MBeanAttrsResult)2 MBeanOperResult (io.fabric8.insight.metrics.model.MBeanOperResult)2 MBeanOpersResult (io.fabric8.insight.metrics.model.MBeanOpersResult)2 Result (io.fabric8.insight.metrics.model.Result)2 List (java.util.List)2 Set (java.util.Set)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GitVersion (io.fabric8.api.commands.GitVersion)1 GitVersions (io.fabric8.api.commands.GitVersions)1 JMXResult (io.fabric8.api.commands.JMXResult)1 LogEvent (io.fabric8.insight.log.LogEvent)1 MBeanAttrs (io.fabric8.insight.metrics.model.MBeanAttrs)1 MBeanOpers (io.fabric8.insight.metrics.model.MBeanOpers)1