From 9f05a6a83d43dbacdf7a49bcca7dddb0bcf81374 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sat, 13 Nov 2021 22:37:45 +0100 Subject: [PATCH 1/2] Allow custom callbacks at imageCreate() --- .../docker/remote/api/client/ImageApi.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt b/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt index a5740c3f..3bc06d2b 100644 --- a/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt +++ b/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt @@ -18,6 +18,7 @@ import de.gesellix.docker.engine.RequestMethod.POST import de.gesellix.docker.remote.api.BuildInfo import de.gesellix.docker.remote.api.BuildPruneResponse import de.gesellix.docker.remote.api.ContainerConfig +import de.gesellix.docker.remote.api.CreateImageInfo import de.gesellix.docker.remote.api.HistoryResponseItem import de.gesellix.docker.remote.api.IdResponse import de.gesellix.docker.remote.api.Image @@ -571,6 +572,7 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro * @throws ServerException If the API returns a server error response */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) + @JvmOverloads fun imageCreate( fromImage: String?, fromSrc: String?, @@ -580,7 +582,8 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro xRegistryAuth: String?, changes: List?, platform: String?, - inputImage: InputStream? + inputImage: InputStream?, + callback: StreamCallback? = null, timeoutMillis: Long? = null /*= 24.hours.toLongMilliseconds()*/ ) { val localVariableConfig = imageCreateRequestConfig( @@ -595,21 +598,25 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro inputImage = inputImage ) - val localVarResponse = requestStream( + val localVarResponse = requestStream( localVariableConfig ) - val timeout = Duration.of(1, ChronoUnit.MINUTES) - val callback = LoggingCallback() + val timeout = if (timeoutMillis == null) { + Duration.of(10, ChronoUnit.MINUTES) + } else { + Duration.of(timeoutMillis, ChronoUnit.MILLIS) + } + val actualCallback = callback ?: LoggingCallback() return when (localVarResponse.responseType) { ResponseType.Success -> { runBlocking { launch { withTimeout(timeout.toMillis()) { - callback.onStarting(this@launch::cancel) - (localVarResponse as SuccessStream<*>).data.collect { callback.onNext(it) } - callback.onFinished() + actualCallback.onStarting(this@launch::cancel) + ((localVarResponse as SuccessStream<*>).data as Flow).collect { actualCallback.onNext(it) } + actualCallback.onFinished() } } } From 84bc0874e4ed2088540603fbcd857e5ec34bfafa Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sat, 13 Nov 2021 22:38:42 +0100 Subject: [PATCH 2/2] Allow custom callbacks at imageLoad() --- .../docker/remote/api/client/ImageApi.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt b/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt index 3bc06d2b..d47a28a1 100644 --- a/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt +++ b/api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ImageApi.kt @@ -1023,24 +1023,32 @@ class ImageApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, pro * @throws ServerException If the API returns a server error response */ @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) - fun imageLoad(quiet: Boolean?, imagesTarball: java.io.File?) { + @JvmOverloads + fun imageLoad( + quiet: Boolean?, imagesTarball: java.io.File?, + callback: StreamCallback? = null, timeoutMillis: Long? = null /*= 24.hours.toLongMilliseconds()*/ + ) { val localVariableConfig = imageLoadRequestConfig(quiet = quiet, imagesTarball = imagesTarball) - val localVarResponse = requestStream( + val localVarResponse = requestStream( localVariableConfig ) - val timeout = Duration.of(1, ChronoUnit.MINUTES) - val callback = LoggingCallback() + val timeout = if (timeoutMillis == null) { + Duration.of(10, ChronoUnit.MINUTES) + } else { + Duration.of(timeoutMillis, ChronoUnit.MILLIS) + } + val actualCallback = callback ?: LoggingCallback() return when (localVarResponse.responseType) { ResponseType.Success -> { runBlocking { launch { withTimeout(timeout.toMillis()) { - callback.onStarting(this@launch::cancel) - (localVarResponse as SuccessStream<*>).data.collect { callback.onNext(it) } - callback.onFinished() + actualCallback.onStarting(this@launch::cancel) + ((localVarResponse as SuccessStream<*>).data as Flow).collect { actualCallback.onNext(it) } + actualCallback.onFinished() } } }