Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand All @@ -11,10 +12,29 @@ public class BuildResponseItem extends ResponseItem {

private static final long serialVersionUID = -1252904184236343612L;

private static final String BUILD_SUCCESS = "Successfully built";

@JsonProperty("stream")
private String stream;

public String getStream() {
return stream;
}

/**
* Returns whether the stream field indicates a successful build operation
*/
@JsonIgnore
public boolean isBuildSuccessIndicated() {
if(getStream() == null) return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put spaces after if, hard to read glued text


return getStream().contains(BUILD_SUCCESS);
}

@JsonIgnore
public String getImageId() {
if(!isBuildSuccessIndicated()) return null;

return getStream().replaceFirst(BUILD_SUCCESS, "").trim();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
Expand All @@ -10,4 +11,18 @@ public class PullResponseItem extends ResponseItem {

private static final long serialVersionUID = 6316219017613249047L;

/**
* Returns whether the status indicates a successful pull operation
*
* @returns true: status indicates that pull was successful, false: status doesn't indicate a successful pull
*/
@JsonIgnore
public boolean isPullSuccessIndicated() {
if (getStatus() == null)
return false;

return (getStatus().contains("Download complete") || getStatus().contains("Image is up to date") || getStatus()
.contains("Downloaded newer image"));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
Expand All @@ -9,4 +10,17 @@
public class PushResponseItem extends ResponseItem {

private static final long serialVersionUID = 8256977108011295857L;

/**
* Returns whether the error field indicates an error
*
* @returns true: the error field indicates an error, false: the error field doesn't indicate an error
*/
@JsonIgnore
public boolean isErrorIndicated() {
if (getError() == null)
return false;

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public String getId() {
return id;
}

public String getError() {
return error;
}

public ErrorDetail getErrorDetail() {
return errorDetail;
}

@JsonIgnoreProperties(ignoreUnknown = false)
public static class ProgressDetail implements Serializable {
private static final long serialVersionUID = -1954994695645715264L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ public abstract class ResultCallbackTemplate<RC_T extends ResultCallback<A_RES_T

private final static Logger LOGGER = LoggerFactory.getLogger(ResultCallbackTemplate.class);

private final CountDownLatch finished = new CountDownLatch(1);
private final CountDownLatch completed = new CountDownLatch(1);

private Closeable stream;

private boolean closed = false;

@Override
public void onStart(Closeable stream) {
this.stream = stream;
}

@Override
public void onNext(A_RES_T object) {
this.closed = false;
}

@Override
public void onError(Throwable throwable) {
if(closed) return;

try {
LOGGER.error("Error during callback", throwable);
throw new RuntimeException(throwable);
Expand All @@ -64,15 +65,16 @@ public void onComplete() {
public void close() throws IOException {
if (stream != null)
stream.close();
finished.countDown();
completed.countDown();
closed = true;
}

/**
* Blocks until {@link ResultCallback#onComplete()} was called
*/
@SuppressWarnings("unchecked")
public RC_T awaitCompletion() throws InterruptedException {
finished.await();
completed.await();
return (RC_T) this;
}

Expand All @@ -81,7 +83,7 @@ public RC_T awaitCompletion() throws InterruptedException {
*/
@SuppressWarnings("unchecked")
public RC_T awaitCompletion(long timeout, TimeUnit timeUnit) throws InterruptedException {
finished.await(timeout, timeUnit);
completed.await(timeout, timeUnit);
return (RC_T) this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.AsyncDockerCmd;
import com.github.dockerjava.api.command.DockerCmdAsyncExec;

public abstract class AbstrAsyncDockerCmd<CMD_T extends AsyncDockerCmd<CMD_T, A_RES_T>, A_RES_T> implements
AsyncDockerCmd<CMD_T, A_RES_T> {

private final static Logger LOGGER = LoggerFactory.getLogger(AbstrAsyncDockerCmd.class);

protected DockerCmdAsyncExec<CMD_T, A_RES_T> execution;

public AbstrAsyncDockerCmd(DockerCmdAsyncExec<CMD_T, A_RES_T> execution) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Created on 21.07.2015
*/
package com.github.dockerjava.core.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.core.async.ResultCallbackTemplate;

/**
*
* @author marcus
*
*/
public class AttachContainerResultCallback extends ResultCallbackTemplate<AttachContainerResultCallback, Frame> {

private final static Logger LOGGER = LoggerFactory.getLogger(AttachContainerResultCallback.class);

@Override
public void onNext(Frame item) {
LOGGER.debug(item.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Created on 21.07.2015
*/
package com.github.dockerjava.core.command;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.DockerClientException;
import com.github.dockerjava.api.model.BuildResponseItem;
import com.github.dockerjava.core.async.ResultCallbackTemplate;

/**
*
* @author marcus
*
*/
public class BuildImageResultCallback extends ResultCallbackTemplate<BuildImageResultCallback, BuildResponseItem> {

private final static Logger LOGGER = LoggerFactory.getLogger(BuildImageResultCallback.class);

private BuildResponseItem latestItem = null;

@Override
public void onNext(BuildResponseItem item) {
this.latestItem = item;
LOGGER.debug(item.toString());
}

/**
* Awaits the image id from the response stream.
*
* @throws DockerClientException
* if the build fails.
*/
public String awaitImageId() {
try {
awaitCompletion();
} catch (InterruptedException e) {
throw new DockerClientException("", e);
}

return getImageId();
}

/**
* Awaits the image id from the response stream.
*
* @throws DockerClientException
* if the build fails or the timeout occurs.
*/
public String awaitImageId(long timeout, TimeUnit timeUnit) {
try {
awaitCompletion(timeout, timeUnit);
} catch (InterruptedException e) {
throw new DockerClientException("", e);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set some exception description

}

return getImageId();
}

private String getImageId() {
if (latestItem == null || !latestItem.isBuildSuccessIndicated()) {
throw new DockerClientException("Could not build image: " + latestItem.getError());
} else {
return latestItem.getImageId();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Created on 21.07.2015
*/
package com.github.dockerjava.core.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.model.Event;
import com.github.dockerjava.core.async.ResultCallbackTemplate;

/**
*
* @author marcus
*
*/
public class EventsResultCallback extends ResultCallbackTemplate<EventsResultCallback, Event> {

private final static Logger LOGGER = LoggerFactory.getLogger(EventsResultCallback.class);

@Override
public void onNext(Event item) {
LOGGER.debug(item.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Created on 21.07.2015
*/
package com.github.dockerjava.core.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.core.async.ResultCallbackTemplate;

/**
*
* @author marcus
*
*/
public class LogContainerResultCallback extends ResultCallbackTemplate<LogContainerResultCallback, Frame> {

private final static Logger LOGGER = LoggerFactory.getLogger(LogContainerResultCallback.class);

@Override
public void onNext(Frame item) {
LOGGER.debug(item.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Created on 21.07.2015
*/
package com.github.dockerjava.core.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.DockerClientException;
import com.github.dockerjava.api.model.PullResponseItem;
import com.github.dockerjava.core.async.ResultCallbackTemplate;

/**
*
* @author marcus
*
*/
public class PullImageResultCallback extends ResultCallbackTemplate<PullImageResultCallback, PullResponseItem> {

private final static Logger LOGGER = LoggerFactory.getLogger(PullImageResultCallback.class);

private PullResponseItem latestItem = null;

@Override
public void onNext(PullResponseItem item) {
this.latestItem = item;
LOGGER.debug(item.toString());
}

/**
* Awaits the image to be pulled successful.
*
* @throws DockerClientException
* if the pull fails.
*/
public void awaitSuccess() {
try {
awaitCompletion();
} catch (InterruptedException e) {
throw new DockerClientException("", e);
}

if (latestItem == null || !latestItem.isPullSuccessIndicated()) {
throw new DockerClientException("Could not pull image: " + latestItem.getError());
}
}
}
Loading