com.spotify.docker.client.messages.ProgressMessage Java Examples
The following examples show how to use
com.spotify.docker.client.messages.ProgressMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerService.java From selenium-jupiter with Apache License 2.0 | 6 votes |
public void pullImage(String imageId) throws DockerException, InterruptedException { if (!preferences.checkKeyInPreferences(imageId) || !getConfig().isUsePreferences() || !localDaemon) { log.info("Pulling Docker image {}", imageId); dockerClient.pull(imageId, new ProgressHandler() { @Override public void progress(ProgressMessage message) throws DockerException { log.trace("Pulling Docker image {} ... {}", imageId, message); } }); log.trace("Docker image {} downloaded", imageId); if (getConfig().isUsePreferences() && localDaemon) { preferences.putValueInPreferencesIfEmpty(imageId, "pulled"); } } }
Example #2
Source File: AnsiProgressHandler.java From docker-client with Apache License 2.0 | 6 votes |
@Override public void progress(ProgressMessage message) throws DockerException { if (message.error() != null) { throw new DockerException(message.error()); } if (message.progressDetail() != null) { printProgress(message); return; } String value = message.stream(); if (value != null) { // trim trailing new lines which are present in streams value = value.replaceFirst("\n$", ""); } else { value = message.status(); } // if value is null it's an unknown message type so just print the whole thing out if (value == null) { value = message.toString(); } out.println(value); }
Example #3
Source File: DockerProgressHandler.java From docker-registry-artifact-plugin with Apache License 2.0 | 6 votes |
@Override public void progress(ProgressMessage message) { if (StringUtils.isNotBlank(message.error())) { consoleLogger.error(message.error()); LOG.error(format("Failure: %s", message.error())); throw new RuntimeException(message.error()); } if (StringUtils.isNotBlank(message.progress())) { consoleLogger.info(message.progress()); } if (StringUtils.isNotBlank(message.digest())) { digest = message.digest(); } }
Example #4
Source File: LoggingPullHandler.java From docker-client with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { 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()); } } log.info("pull {}: {}", image, message); }
Example #5
Source File: BuildMojoTest.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
public void testDigestWrittenOnBuildWithPushAndExplicitTag() throws Exception { final File pom = getPom("/pom-build-push-with-tag.xml"); final BuildMojo mojo = setupMojo(pom); final DockerClient docker = mock(DockerClient.class); final String digest = "sha256:ebd39c3e3962f804787f6b0520f8f1e35fbd5a01ab778ac14c8d6c37978e8445"; final ProgressMessage digestProgressMessage = ProgressMessage.builder().status( "Digest: " + digest ).build(); doAnswer(new Answer() { @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { final ProgressHandler handler = (ProgressHandler) invocationOnMock.getArguments()[1]; handler.progress(digestProgressMessage); return null; } }).when(docker).push(anyString(), any(ProgressHandler.class)); mojo.execute(docker); verify(docker).build(eq(Paths.get("target/docker")), eq("busybox:sometag"), any(AnsiProgressHandler.class)); verify(docker).push(eq("busybox:sometag"), any(AnsiProgressHandler.class)); assertFileExists(mojo.tagInfoFile); final ObjectMapper objectMapper = new ObjectMapper(); final JsonNode node = objectMapper.readTree(new File(mojo.tagInfoFile)); assertEquals("busybox@" + digest, node.get("digest").asText()); }
Example #6
Source File: BuildMojoTest.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
public void testDigestWrittenOnBuildWithPush() throws Exception { final File pom = getPom("/pom-build-push.xml"); final BuildMojo mojo = setupMojo(pom); final DockerClient docker = mock(DockerClient.class); final String digest = "sha256:ebd39c3e3962f804787f6b0520f8f1e35fbd5a01ab778ac14c8d6c37978e8445"; final ProgressMessage digestProgressMessage = ProgressMessage.builder().status( "Digest: " + digest ).build(); doAnswer(new Answer() { @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { final ProgressHandler handler = (ProgressHandler) invocationOnMock.getArguments()[1]; handler.progress(digestProgressMessage); return null; } }).when(docker).push(anyString(), any(ProgressHandler.class)); mojo.execute(docker); verify(docker).build(eq(Paths.get("target/docker")), eq("busybox"), any(AnsiProgressHandler.class)); verify(docker).push(eq("busybox"), any(AnsiProgressHandler.class)); assertFileExists(mojo.tagInfoFile); final ObjectMapper objectMapper = new ObjectMapper(); final JsonNode node = objectMapper.readTree(new File(mojo.tagInfoFile)); assertEquals("busybox@" + digest, node.get("digest").asText()); }
Example #7
Source File: Utils.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
@Override public void progress(final ProgressMessage message) throws DockerException { if (message.digest() != null) { digest = message.digest(); } delegate.progress(message); }
Example #8
Source File: DefaultDockerClient.java From docker-client with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { delegate.progress(message); final String id = message.buildImageId(); if (id != null) { imageId = id; } }
Example #9
Source File: DefaultDockerClient.java From docker-client with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { delegate.progress(message); final String stream = message.stream(); if (stream != null) { Matcher streamMatcher = IMAGE_STREAM_PATTERN.matcher(stream); if (streamMatcher.matches()) { imageNames.add(streamMatcher.group("image")); } } }
Example #10
Source File: DefaultDockerClient.java From docker-client with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { delegate.progress(message); final String status = message.status(); if (status != null && (status.length() == EXPECTED_CHARACTER_NUM1 || status.length() == EXPECTED_CHARACTER_NUM2)) { imageId = message.status(); } }
Example #11
Source File: LoggingPushHandler.java From docker-client with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { if (message.error() != null) { throw new ImagePushFailedException(image, message.toString()); } log.info("push {}: {}", image, message); }
Example #12
Source File: LoggingBuildHandler.java From docker-client with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { if (message.error() != null) { throw new DockerException(message.toString()); } log.info("build: {}", message); }
Example #13
Source File: AnsiProgressHandler.java From docker-client with Apache License 2.0 | 5 votes |
/** * Displays the upload/download status of multiple image layers the same way the docker CLI does. * The current status of each layer is show on its own line. As the status updated, we move the * cursor to the correct line, and overwrite the old status with the new one. * * @param message the ProgressMessage to parse */ private void printProgress(final ProgressMessage message) { final String id = message.id(); Integer line = idsToLines.get(id); int diff = 0; if (line == null) { line = idsToLines.size(); idsToLines.put(id, line); } else { diff = idsToLines.size() - line; } if (diff > 0) { // move cursor up to the line for this image layer out.printf("%c[%dA", ESC_CODE, diff); // delete entire line out.printf("%c[2K\r", ESC_CODE); } // The progress bar graphic is in the 'progress' element. Some messages like "Pulling // dependent layers" don't have a progress bar, in which case set to empty string. String progress = message.progress(); if (progress == null) { progress = ""; } // this will print something like "90b15849fc7e: Downloading [==>] 5.812 MB/117.4 MB 4m12s" out.printf("%s: %s %s%n", id, message.status(), progress); if (diff > 0) { // move cursor back down to bottom out.printf("%c[%dB", ESC_CODE, diff - 1); } }
Example #14
Source File: LoggingLoadHandler.java From docker-client with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { if (message.error() != null) { throw new DockerException(message.toString()); } log.info("load: {}", message); }
Example #15
Source File: LoggingProgressHandler.java From dockerfile-maven with Apache License 2.0 | 5 votes |
@Override public void progress(ProgressMessage message) throws DockerException { if (message.error() != null) { handleError(message.error()); } else if (message.progressDetail() != null) { handleProgress(message.id(), message.status(), message.progress()); } else if ((message.status() != null) || (message.stream() != null)) { handleGeneric(message.stream(), message.status()); } String imageId = message.buildImageId(); if (imageId != null) { builtImageId = imageId; } }
Example #16
Source File: DockerProgressHandlerTest.java From docker-registry-artifact-plugin with Apache License 2.0 | 5 votes |
@Test public void shouldLogErrorToConsoleLogger() { try { progressHandler.progress(ProgressMessage.builder().error("some-error").build()); fail("Should throw runtime exception with error message"); } catch (RuntimeException e) { verify(consoleLogger, times(1)).error("some-error"); assertThat(e.getMessage()).isEqualTo("some-error"); } }
Example #17
Source File: ProgressStream.java From docker-client with Apache License 2.0 | 4 votes |
ProgressStream(final InputStream stream) throws IOException { this.stream = stream; final JsonParser parser = objectMapper().getFactory().createParser(stream); iterator = objectMapper().readValues(parser, ProgressMessage.class); }
Example #18
Source File: DockerProgressHandlerTest.java From docker-registry-artifact-plugin with Apache License 2.0 | 4 votes |
@Test public void shouldLogProgressToConsoleLogger() { progressHandler.progress(ProgressMessage.builder().progress("docker-push-pull-progress").build()); verify(consoleLogger, times(1)).info("docker-push-pull-progress"); }
Example #19
Source File: ProgressHandler.java From docker-client with Apache License 2.0 | 2 votes |
/** * This method will be called for each progress message received from Docker. * * @param message the message to process * @throws DockerException if a server error occurred (500) */ void progress(ProgressMessage message) throws DockerException;