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;
}
};
}
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);
}
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;
}
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");
}
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");
}
Aggregations