Amazon.EC2.Import.DiskImageImporter.DetermineRemainingUploads C# (CSharp) Метод

DetermineRemainingUploads() приватный Метод

Analyzes the parts list of the manifest to determine which object parts exist in S3. Used when instantiating an importer from an existing manifest of a failed uploaded (RetainArtifactsOnUploadError set true to keep the partially uploaded content allowing uploads to be resumed part-way through).
Since the manifest contains a set of presigned urls to each part we can make use of those to determine whether a part has been uploaded or not.
private DetermineRemainingUploads ( ) : void
Результат void
        void DetermineRemainingUploads()
        {
            foreach (var part in ImportManifest.ImportData.PartsList.PartInstances)
            {
                try
                {
                    var request = WebRequest.Create(part.HeadUrl);
                    request.Method = "HEAD";
                    var response = request.GetResponse();
                    response.Close();
                    // if the HEAD request worked, log that the part can be skipped during resumption
                    part.UploadCompleted = true;
                }
                catch
                {
                    // always clear the state on exception so we'll retry parts we failed to HEAD 
                    // even if we thought we'd completed them successfully
                    part.UploadCompleted = false;
                }                
            }
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Constructs an importer instance for a previously uploaded manifest. The manifest is downloaded using 
        /// a new Amazon S3 client constructed for the specified region and deserialized, ready for use in 
        /// constructing the appropriate ImportInstance or ImportVolume request to Amazon EC2.
        /// </summary>
        /// <param name="credentials">
        /// The AWS credentials for the account that owns or has access to the bucket containing the manifest file.
        /// </param>
        /// <param name="region">The region in which the Amazon S3 client used for download will be constructed.</param>
        /// <param name="bucketName">The name of the bucket containing the manifest file.</param>
        /// <param name="manifestFileKey">The S3 object key of the manifest file.</param>
        /// <param name="resumingUpload">
        /// Set this to true if a previous upload failed part-way through processing and RetainArtifactsOnUploadError
        /// was set to true so the partially uploaded content was retained. The existing manifest will
        /// be inspected and uploads can then resume to process the retaining content.
        /// </param>
        /// <returns>Initialized importer instance containing a deserialized manifest</returns>
        public static DiskImageImporter FromManifest(AWSCredentials credentials, 
                                                     RegionEndpoint region, 
                                                     string bucketName, 
                                                     string manifestFileKey,
                                                     bool resumingUpload)
        {
            try
            {
                var importer = new DiskImageImporter(credentials, region, bucketName)
                {
                    ManifestFileKey = manifestFileKey
                };
                importer.DeserializeManifestFromS3();

                if (resumingUpload)
                    importer.DetermineRemainingUploads();

                return importer;
            }
            catch (AmazonS3Exception e)
            {
                var msg = string.Format(CultureInfo.InvariantCulture,
                                        "Failed to download the specified manifest from bucket {0} with key {1}",
                                        bucketName, 
                                        manifestFileKey);
                throw new DiskImageImporterException(DiskImportErrorStage.ManifestInspection, msg, e);
            }
            catch (XmlException e)
            {
                throw new DiskImageImporterException(DiskImportErrorStage.ManifestInspection, 
                                                     "Failed to deserialize the downloaded manifest", 
                                                     e);
            }
        }