Skip to content

Instantly share code, notes, and snippets.

View ArturSkowronski's full-sized avatar

Artur Skowronski ArturSkowronski

View GitHub Profile
package main
import (
"bufio"
"fmt"
"os"
)
func algorithm1(lines []string) int {
class FinalizingStep implements AsyncStep<Void>, Callable<Void> {
public Void call() throws ExecutionException {
// Unwrap the wrapped dependencies.
List<ListenableFuture<?>> unwrappedDependencies = new ArrayList<>();
for (AsyncStep<? extends ImmutableList<? extends AsyncStep<?>>> wrappedDependency :
futureDependencyLists) {
for (AsyncStep<?> unwrappedDependency : NonBlockingSteps.get(wrappedDependency)) {
unwrappedDependencies.add(unwrappedDependency.getFuture());
}
}
class PushContainerConfigurationStep
/*(...)*/
@Override
public AsyncStep<PushBlobStep> call() throws ExecutionException {
ListenableFuture<PushBlobStep> pushBlobStepFuture =
Futures.whenAllSucceed(
authenticatePushStep.getFuture(), NonBlockingSteps.get(buildImageStep).getFuture())
.call(this::afterBuildConfigurationFutureFuture, listeningExecutorService);
return () -> pushBlobStepFuture;
}
class BuildImageStep
implements AsyncStep<AsyncStep<Image<CachedLayer>>>, Callable<AsyncStep<Image<CachedLayer>>> {
/*(...)*/
private Image<CachedLayer> afterCachedLayersSteps()
throws ExecutionException, LayerPropertyNotFoundException {
try (Timer ignored = new Timer(buildConfiguration.getBuildLogger(), DESCRIPTION)) {
// Constructs the image.
Image.Builder<CachedLayer> imageBuilder = Image.builder();
for (PullAndCacheBaseImageLayerStep pullAndCacheBaseImageLayerStep :
NonBlockingSteps.get(pullAndCacheBaseImageLayersStep)) {
class BuildImageStep
implements AsyncStep<AsyncStep<Image<CachedLayer>>>, Callable<AsyncStep<Image<CachedLayer>>> {
/*(...)*/
public AsyncStep<Image<CachedLayer>> call() throws ExecutionException {
List<ListenableFuture<?>> dependencies = new ArrayList<>();
for (PullAndCacheBaseImageLayerStep pullAndCacheBaseImageLayerStep :
NonBlockingSteps.get(pullAndCacheBaseImageLayersStep)) {
dependencies.add(pullAndCacheBaseImageLayerStep.getFuture());
}
public class CacheWriter {
/*(...)*/
public CachedLayerWithMetadata writeLayer(ReproducibleLayerBuilder reproducibleLayerBuilder)
throws IOException {
UnwrittenLayer unwrittenLayer = reproducibleLayerBuilder.build();
Path tempLayerFile = Files.createTempFile(cache.getCacheDirectory(), null, null);
tempLayerFile.toFile().deleteOnExit();
try (CountingDigestOutputStream compressedDigestOutputStream =
class BuildAndCacheApplicationLayerStep
implements AsyncStep<CachedLayerWithMetadata>, Callable<CachedLayerWithMetadata> {
/*(...)*/
@Override
public CachedLayerWithMetadata call() throws IOException, CacheMetadataCorruptedException {
/*(...)*/
CachedLayerWithMetadata cachedLayer =
new CacheReader(cache)
.getUpToDateLayerByLayerEntries(layerConfiguration.getLayerEntries());
class BuildAndCacheApplicationLayerStep
implements AsyncStep<CachedLayerWithMetadata>, Callable<CachedLayerWithMetadata> {
/*(...)*/
static ImmutableList<BuildAndCacheApplicationLayerStep> makeList(
ListeningExecutorService listeningExecutorService,
BuildConfiguration buildConfiguration,
SourceFilesConfiguration sourceFilesConfiguration,
Cache cache) {
/*(...)*/
class PushBlobStep implements AsyncStep<BlobDescriptor>, Callable<BlobDescriptor> {
/*(...)*/
public BlobDescriptor call() throws IOException, RegistryException, ExecutionException {
/*(...)*/
RegistryClient registryClient =/*(...)*/
if (registryClient.checkBlob(blobDescriptor.getDigest()) != null) {
/*(...)*/
return blobDescriptor;
}
class PushLayersStep
implements AsyncStep<ImmutableList<AsyncStep<PushBlobStep>>>,
Callable<ImmutableList<AsyncStep<PushBlobStep>>> {
/*(...)*/
private PushBlobStep makePushBlobStep(AsyncStep<? extends CachedLayer> cachedLayerStep)
throws ExecutionException {
CachedLayer cachedLayer = NonBlockingSteps.get(cachedLayerStep);
return new PushBlobStep(
listeningExecutorService,
buildConfiguration,