-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an adapted LoggingPullHandler that should generate less logging…
… messages - especially in a local deployment.
- Loading branch information
1 parent
7456b37
commit 1513d6e
Showing
3 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
platform-controller/src/main/java/org/hobbit/controller/docker/LoggingPullHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.hobbit.controller.docker; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.spotify.docker.client.ProgressHandler; | ||
import com.spotify.docker.client.exceptions.DockerException; | ||
import com.spotify.docker.client.exceptions.ImageNotFoundException; | ||
import com.spotify.docker.client.exceptions.ImagePullFailedException; | ||
import com.spotify.docker.client.messages.ProgressMessage; | ||
|
||
/** | ||
* This class handles the logging of the progress while pulling a Docker image. | ||
* It is mainly a copy of {@link com.spotify.docker.client.LoggingPullHandler} | ||
* but produces much less logging messages. | ||
* | ||
* @author Michael Röder (roeder@informatik.uni-leipzig.de) | ||
* | ||
*/ | ||
public class LoggingPullHandler implements ProgressHandler { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingPullHandler.class); | ||
|
||
private static final String SWARM_PULLING_STARTED_STATUS = "Pulling "; | ||
private static final String SWARM_PULLING_STOPPED_STATUS = ": downloaded"; | ||
private static final String SINGLE_DOWNLOADING_STATUS = "Downloading"; | ||
private static final String SINGLE_IMAGE_UP_TO_DATE_STATUS = "Status: Image is up to date"; | ||
private static final String SINGLE_PULLING_COMPLETE_STATUS = "Status: Downloaded newer image"; | ||
|
||
private final String image; | ||
private boolean pullingStartedLogged = false; | ||
private int pullStartCount = 0; | ||
private int pullEndCount = 0; | ||
|
||
public LoggingPullHandler(String image) { | ||
this.image = image; | ||
} | ||
|
||
@Override | ||
public void progress(ProgressMessage message) throws DockerException { | ||
// Error handling (taken from | ||
// com.spotify.docker.client.LoggingPullHandler) | ||
if (message.error() != null) { | ||
if (message.error().contains("404") || message.error().contains("not found")) { | ||
throw new ImageNotFoundException(image, message.toString()); | ||
} else { | ||
throw new ImagePullFailedException(image, message.toString()); | ||
} | ||
} | ||
|
||
processProgress(message); | ||
} | ||
|
||
protected synchronized void processProgress(ProgressMessage message) { | ||
if (message.status().startsWith(SWARM_PULLING_STARTED_STATUS)) { | ||
++pullStartCount; | ||
if (pullStartCount == 2) { | ||
LOGGER.info("Pulling image {}", image); | ||
pullingStartedLogged = true; | ||
} | ||
return; | ||
} | ||
|
||
if (!pullingStartedLogged) { | ||
if (message.status().startsWith(SINGLE_IMAGE_UP_TO_DATE_STATUS)) { | ||
LOGGER.info("Image {} is up to date und does not have to be pulled.", image); | ||
} else if (message.status().startsWith(SINGLE_DOWNLOADING_STATUS)) { | ||
LOGGER.info("Image {} is being pulled...", image); | ||
pullingStartedLogged = true; | ||
} | ||
} else { | ||
if (message.status().startsWith(SINGLE_PULLING_COMPLETE_STATUS)) { | ||
LOGGER.info("Pulled image {}.", image); | ||
} else if ((pullStartCount > 0) && (message.status().endsWith(SWARM_PULLING_STOPPED_STATUS))) { | ||
++pullEndCount; | ||
if (pullStartCount == pullEndCount) { | ||
LOGGER.info("Pulled image {}", image); | ||
} | ||
} | ||
} | ||
} | ||
} |