com.spotify.docker.client.exceptions.DockerTimeoutException Java Examples

The following examples show how to use com.spotify.docker.client.exceptions.DockerTimeoutException. 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: DefaultDockerClient.java    From docker-client with Apache License 2.0 5 votes vote down vote up
private RuntimeException propagate(final String method, final WebTarget resource,
                                   final Exception ex)
    throws DockerException, InterruptedException {
  Throwable cause = ex.getCause();

  // Sometimes e is a org.glassfish.hk2.api.MultiException
  // which contains the cause we're actually interested in.
  // So we unpack it here.
  if (ex instanceof MultiException) {
    cause = cause.getCause();
  }

  Response response = null;
  if (cause instanceof ResponseProcessingException) {
    response = ((ResponseProcessingException) cause).getResponse();
  } else if (cause instanceof WebApplicationException) {
    response = ((WebApplicationException) cause).getResponse();
  } else if ((cause instanceof ProcessingException) && (cause.getCause() != null)) {
    // For a ProcessingException, The exception message or nested Throwable cause SHOULD contain
    // additional information about the reason of the processing failure.
    cause = cause.getCause();
  }

  if (response != null) {
    throw new DockerRequestException(method, resource.getUri(), response.getStatus(),
                                     message(response), cause);
  } else if ((cause instanceof SocketTimeoutException)
             || (cause instanceof ConnectTimeoutException)) {
    throw new DockerTimeoutException(method, resource.getUri(), ex);
  } else if ((cause instanceof InterruptedIOException)
             || (cause instanceof InterruptedException)) {
    throw new InterruptedException("Interrupted: " + method + " " + resource);
  } else {
    throw new DockerException(ex);
  }
}
 
Example #2
Source File: TaskRunnerTest.java    From helios with Apache License 2.0 5 votes vote down vote up
@Test
public void testPullTimeoutVariation() throws Throwable {
  doThrow(new DockerTimeoutException("x", new URI("http://example.com"), null))
      .when(mockDocker).pull(IMAGE);

  doThrow(new ImageNotFoundException("not found"))
      .when(mockDocker).inspectImage(IMAGE);

  final TaskRunner tr = TaskRunner.builder()
      .delayMillis(0)
      .config(TaskConfig.builder()
          .namespace("test")
          .host(HOST)
          .job(JOB)
          .containerDecorators(ImmutableList.of(containerDecorator))
          .build())
      .docker(mockDocker)
      .listener(new TaskRunner.NopListener())
      .build();

  tr.run();

  try {
    tr.resultFuture().get();
    fail("this should throw");
  } catch (Exception t) {
    assertTrue(t instanceof ExecutionException);
    assertEquals(ImagePullFailedException.class, t.getCause().getClass());
  }
}
 
Example #3
Source File: GlobalExceptionHandler.java    From paas with Apache License 2.0 4 votes vote down vote up
@ExceptionHandler(value = DockerTimeoutException.class)
public ResultVO customException(DockerTimeoutException e) {
    return ResultVOUtils.error(ResultEnum.DOCKER_TIMEOUT);
}