Skip to content

Commit

Permalink
Fix root progress construction (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored Jun 20, 2019
1 parent 8cb7179 commit a5ea74a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void dispatchProgress(long progressUnits) {
private long decrementRemainingAllocationUnits(long units) {
Preconditions.checkState(!closed);

if (remainingAllocationUnits > units) {
if (remainingAllocationUnits >= units) {
remainingAllocationUnits -= units;
return units;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -102,10 +101,7 @@ public static StepsRunner begin(BuildConfiguration buildConfiguration) {
private final List<Runnable> stepsToRun = new ArrayList<>();

@Nullable private String rootProgressDescription;
private Supplier<ProgressEventDispatcher.Factory> childProgressDispatcherFactorySupplier =
() -> {
throw new IllegalStateException("root progress dispatcher uninstantiated");
};
@Nullable private ProgressEventDispatcher rootProgressDispatcher;

private StepsRunner(
ListeningExecutorService executorService, BuildConfiguration buildConfiguration) {
Expand All @@ -114,98 +110,127 @@ private StepsRunner(
}

private void retrieveTargetRegistryCredentials() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.targetRegistryCredentials =
executorService.submit(
RetrieveRegistryCredentialsStep.forTargetImage(
buildConfiguration, childProgressDispatcherFactorySupplier.get()));
buildConfiguration, childProgressDispatcherFactory));
}

private void authenticatePush() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.pushAuthorization =
executorService.submit(
() ->
new AuthenticatePushStep(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
results.targetRegistryCredentials.get())
.call());
}

private void pullBaseImage() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.baseImageAndAuth =
executorService.submit(
new PullBaseImageStep(
buildConfiguration, childProgressDispatcherFactorySupplier.get()));
new PullBaseImageStep(buildConfiguration, childProgressDispatcherFactory));
}

private void pullAndCacheBaseImageLayers() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.baseImageLayers =
executorService.submit(
() ->
scheduleCallables(
PullAndCacheBaseImageLayersStep.makeList(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
results.baseImageAndAuth.get())));
}

private void pushBaseImageLayers() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.baseImageLayerPushResults =
executorService.submit(
() ->
scheduleCallables(
PushLayerStep.makeList(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
results.pushAuthorization.get(),
results.baseImageLayers.get())));
}

private void buildAndCacheApplicationLayers() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.applicationLayers =
scheduleCallables(
BuildAndCacheApplicationLayerStep.makeList(
buildConfiguration, childProgressDispatcherFactorySupplier.get()));
buildConfiguration, childProgressDispatcherFactory));
}

private void buildImage() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.builtImage =
executorService.submit(
() ->
new BuildImageStep(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
results.baseImageAndAuth.get().getImage(),
realizeFutures(results.baseImageLayers.get()),
realizeFutures(Verify.verifyNotNull(results.applicationLayers)))
.call());
}

private void pushContainerConfiguration() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.containerConfigurationPushResult =
executorService.submit(
() ->
new PushContainerConfigurationStep(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
results.pushAuthorization.get(),
results.builtImage.get())
.call());
}

private void pushApplicationLayers() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.applicationLayerPushResults =
executorService.submit(
() ->
scheduleCallables(
PushLayerStep.makeList(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
results.pushAuthorization.get(),
Verify.verifyNotNull(results.applicationLayers))));
}

private void pushImage() {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.buildResult =
executorService.submit(
() -> {
Expand All @@ -215,7 +240,7 @@ private void pushImage() {
return new PushImageStep(
executorService,
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
results.pushAuthorization.get(),
results.containerConfigurationPushResult.get(),
results.builtImage.get())
Expand All @@ -224,24 +249,30 @@ private void pushImage() {
}

private void loadDocker(DockerClient dockerClient) {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.buildResult =
executorService.submit(
() ->
new LoadDockerStep(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
dockerClient,
results.builtImage.get())
.call());
}

private void writeTarFile(Path outputPath) {
ProgressEventDispatcher.Factory childProgressDispatcherFactory =
Verify.verifyNotNull(rootProgressDispatcher).newChildProducer();

results.buildResult =
executorService.submit(
() ->
new WriteTarFileStep(
buildConfiguration,
childProgressDispatcherFactorySupplier.get(),
childProgressDispatcherFactory,
outputPath,
results.builtImage.get())
.call());
Expand All @@ -253,7 +284,8 @@ public BuildResult run() throws ExecutionException, InterruptedException {
try (ProgressEventDispatcher progressEventDispatcher =
ProgressEventDispatcher.newRoot(
buildConfiguration.getEventHandlers(), rootProgressDescription, stepsToRun.size())) {
childProgressDispatcherFactorySupplier = progressEventDispatcher::newChildProducer;
rootProgressDispatcher = progressEventDispatcher;

stepsToRun.forEach(Runnable::run);
return results.buildResult.get();

Expand Down

0 comments on commit a5ea74a

Please sign in to comment.