コード例 #1
0
ファイル: RegistryClient.cs プロジェクト: tiaotiao97/jib
        /**
         * Pushes the BLOB. If the {@code sourceRepository} is provided then the remote registry may skip
         * if the BLOB already exists on the registry.
         *
         * @param blobDigest the digest of the BLOB, used for existence-check
         * @param blob the BLOB to push
         * @param sourceRepository if pushing to the same registry then the source image, or {@code null}
         *     otherwise; used to optimize the BLOB push
         * @param writtenByteCountListener listens on byte count written to the registry during the push
         * @return {@code true} if the BLOB already exists on the registry and pushing was skipped; false
         *     if the BLOB was pushed
         * @throws IOException if communicating with the endpoint fails
         * @throws RegistryException if communicating with the endpoint fails
         */
        public async Task <bool> PushBlobAsync(
            DescriptorDigest blobDigest,
            IBlob blob,
            string sourceRepository,
            Action <long> writtenByteCountListener)
        {
            BlobPusher blobPusher =
                new BlobPusher(registryEndpointRequestProperties, blobDigest, blob, sourceRepository);

            using (TimerEventDispatcher timerEventDispatcher =
                       new TimerEventDispatcher(eventHandlers, "pushBlob"))
            {
                timerEventDispatcher.Lap("pushBlob POST " + blobDigest);

                // POST /v2/<name>/blobs/uploads/ OR
                // POST /v2/<name>/blobs/uploads/?mount={blob.digest}&from={sourceRepository}
                Uri patchLocation = await CallRegistryEndpointAsync(blobPusher.CreateInitializer()).ConfigureAwait(false);

                if (patchLocation == null)
                {
                    // The BLOB exists already.
                    return(true);
                }
                timerEventDispatcher.Lap("pushBlob PATCH " + blobDigest);

                // PATCH <Location> with BLOB
                Uri putLocation =
                    await CallRegistryEndpointAsync(blobPusher.CreateWriter(patchLocation, writtenByteCountListener)).ConfigureAwait(false);

                Preconditions.CheckNotNull(putLocation);
                timerEventDispatcher.Lap("pushBlob PUT " + blobDigest);

                // PUT <Location>?digest={blob.digest}
                await CallRegistryEndpointAsync(blobPusher.CreateCommitter(putLocation)).ConfigureAwait(false);

                return(false);
            }
        }
コード例 #2
0
 public Initializer(BlobPusher parent)
 {
     this.parent = parent;
 }
コード例 #3
0
 public Committer(Uri location, BlobPusher parent)
 {
     this.location = location;
     this.parent   = parent;
 }
コード例 #4
0
 public Writer(Uri location, Action <long> writtenByteCountListener, BlobPusher parent)
 {
     this.location = location;
     this.writtenByteCountListener = writtenByteCountListener;
     this.parent = parent;
 }