public void UploadContent(string tag, string sourceSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag, bool acquireSourceReaderLock) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); sourceSoftLink = this.GetLocalPath(sourceSoftLink); if ((!FabricFile.Exists(sourceSoftLink)) && (!FabricDirectory.Exists(sourceSoftLink))) { throw new IOException( string.Format( CultureInfo.CurrentCulture, StringResources.ImageStoreError_DoesNotExistError, sourceSoftLink)); } try { using (XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { tag = XStoreCommon.FormatXStoreUri(tag); if (copyFlag == CopyFlag.AtomicCopy) { this.DeleteContent(tag, helper == null ? timeout : helper.GetRemainingTime()); } if (FabricFile.Exists(sourceSoftLink)) { // This is a file copy xstoreFileOperation.CopyFile( sourceSoftLink, tag, XStoreFileOperationType.CopyFromSMBToXStore, helper); } else { // this is a folder copy xstoreFileOperation.CopyFolder( sourceSoftLink, tag, XStoreFileOperationType.CopyFromSMBToXStore, copyFlag, null, null, helper); } } } catch (Exception ex) { this.HandleException(ex); throw; } }
private static string ConvertBlobReferenceToBlobReference(string blobReference, string srcRootUri, string dstRootUri) { char[] trims = { '/', ' ' }; blobReference = XStoreCommon.FormatXStoreUri(blobReference); if (blobReference.StartsWith(srcRootUri, StringComparison.OrdinalIgnoreCase)) { blobReference = blobReference.Substring(srcRootUri.Length).Trim(trims); } return(string.Format("{0}/{1}", dstRootUri, blobReference)); }
/// <summary> /// Find the corresponding smb path based on the blob uri /// SMB path is \\XXX\YYY; XStore path is XXX/YYY /// </summary> /// <returns>The SMB path corresponding to the XStore Path.</returns> /// <param name="blobReference">The reference to blob.</param> /// <param name="srcRootUri">The root uri of the source.</param> /// <param name="dstRootUri">The root uri of the destination.</param> private static string ConvertBlobReferenceToSMBPath(string blobReference, string srcRootUri, string dstRootUri) { char[] trims = { '/', ' ' }; blobReference = XStoreCommon.FormatXStoreUri(blobReference); if (blobReference.StartsWith(srcRootUri, StringComparison.OrdinalIgnoreCase)) { blobReference = blobReference.Substring(srcRootUri.Length).Trim(trims); } return(Path.Combine(dstRootUri, blobReference.Replace('/', '\\'))); }
/// <summary> /// Copies content from a path in the XStore to the destination path in the XStore /// </summary> /// <param name="remoteSource"> Location relative to RootUri where the content to be copied will be found. </param> /// <param name="remoteDestination"> Location relative to RootUri where the content needs to be copied. </param> /// <param name="timeout">The timeout for performing the copying operation.</param> /// <param name="skipFiles">The list of the blobs to be skipped for copying </param> /// <param name="copyFlag">The copying control information to specify how blob can be overwritten.</param> /// <param name="checkMarkFile">Indicats whether to check mark file during copying.</param> public void CopyContent(string remoteSource, string remoteDestination, TimeSpan timeout, string[] skipFiles, CopyFlag copyFlag, bool checkMarkFile) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); try { using ( XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { remoteSource = XStoreCommon.FormatXStoreUri(remoteSource); remoteDestination = XStoreCommon.FormatXStoreUri(remoteDestination); bool xstoreFileExist = xstoreFileOperation.XStoreFileExists(remoteSource, helper); bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(remoteSource, checkMarkFile, helper); if ((!xstoreFileExist) && (!xstoreFolderExist)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, remoteSource)); } if (copyFlag == CopyFlag.AtomicCopy) { this.DeleteContent(remoteDestination, helper == null ? timeout : helper.GetRemainingTime()); } if (xstoreFileExist) { // this is a single blob copy from xstore to xstore xstoreFileOperation.CopyFile( remoteSource, remoteDestination, XStoreFileOperationType.CopyFromXStoreToXStore, helper); } else { xstoreFileOperation.CopyFolder( remoteSource, remoteDestination, XStoreFileOperationType.CopyFromXStoreToXStore, copyFlag, null, skipFiles, helper); } } } catch (Exception ex) { this.HandleException(ex); throw; } }
/// <summary> /// Downloads content from the XStore to local destination. /// </summary> /// <param name="tag">Location (relative to RootUri) from where to download the content.</param> /// <param name="destinationSoftLink">Physical location where to download the content.</param> /// <param name="handler">Defines the behavior to process progress information from the downloading operation.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string tag, string destinationSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); destinationSoftLink = this.GetLocalPath(destinationSoftLink); try { using (XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { tag = XStoreCommon.FormatXStoreUri(tag); bool xstoreFileExist = xstoreFileOperation.XStoreFileExists(tag, helper); bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(tag, true, helper); if ((!xstoreFileExist) && (!xstoreFolderExist)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, tag)); } if (xstoreFileExist) { // this is a single blob copy from xstore to smb xstoreFileOperation.CopyFile( tag, destinationSoftLink, XStoreFileOperationType.CopyFromXStoreToSMB, helper); } else { // this is a multiple blob (folder) copy from xstore to smb xstoreFileOperation.CopyFolder( tag, destinationSoftLink, XStoreFileOperationType.CopyFromXStoreToSMB, copyFlag, null, null, helper); } } } catch (Exception ex) { this.HandleException(ex); throw; } }
/// <summary> /// List all blobs under the the given relative blob path/sub blob path /// </summary> /// <param name="tag">Location (relative to RootUri)</param> /// <param name="isRecursive">flag list subhierarchy</param> /// <param name="timeout">The timeout for performing the listing operation</param> /// <returns>All blobs within the input blob path/sub blob path</returns> public ImageStoreContent ListContentWithDetails(string tag, bool isRecursive, TimeSpan timeout) { ImageStoreContent content = null; TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); try { using (XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { content = xstoreFileOperation.ListXStoreFile(XStoreCommon.FormatXStoreUri(tag), isRecursive, helper); } } catch (Exception ex) { this.HandleException(ex); throw; } return(content); }
/// <summary> /// Remove tag from store, clear data assosciate with tag. /// </summary> /// <param name="tag">Location (relative to RootUri) from where to delete the content.</param> ///<param name="timeout">The timeout for performing the deleting operation</param> public void DeleteContent(string tag, TimeSpan timeout) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); try { using ( XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { tag = XStoreCommon.FormatXStoreUri(tag); if (!xstoreFileOperation.XStoreContainerExists(helper)) { return; } if (string.IsNullOrEmpty(tag)) { // remove the container in this case xstoreFileOperation.RemoveContainer(helper); } else if (xstoreFileOperation.XStoreFileExists(tag, helper)) { xstoreFileOperation.RemoveXStoreFile(tag, helper); } else { xstoreFileOperation.RemoveXStoreFolder(tag, helper); } } } catch (Exception ex) { this.HandleException(ex); throw; } }
/// <summary> /// Check if content is present in the store. /// </summary> /// <param name="tag"> Location (relative to RootUri) where to check the presence of the content. </param> /// <param name="timeout">The timeout for performing the checking existence operation</param> /// <returns> True if the content exists, false otherwise. </returns> public bool DoesContentExist(string tag, TimeSpan timeout) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); bool isExist = false; try { using ( XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { tag = XStoreCommon.FormatXStoreUri(tag); isExist = xstoreFileOperation.XStoreFileExists(tag, helper) || xstoreFileOperation.XStoreFolderExists(tag, true, helper); } } catch (Exception ex) { this.HandleException(ex); throw; } return(isExist); }
/// <summary> /// Downloads content from the XStore to local destination. /// </summary> /// <param name="tag">Location (relative to RootUri) from where to download the content.</param> /// <param name="destinationSoftLink">Physical location where to download the content.</param> /// <param name="handler">Defines the behavior to process progress information from the downloading operation.</param> /// <param name="timeout">The timeout for performing the downloading operation.</param> /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param> public void DownloadContent(string tag, string destinationSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag) { TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout); destinationSoftLink = this.GetLocalPath(destinationSoftLink); try { using (XStoreFileOperations xstoreFileOperation = new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName))) { tag = XStoreCommon.FormatXStoreUri(tag); bool xstoreFileExist = xstoreFileOperation.XStoreFileExists(tag, helper); bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(tag, true, helper); if ((!xstoreFileExist) && (!xstoreFolderExist)) { throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, tag)); } if (xstoreFileExist) { // this is a single blob copy from xstore to smb xstoreFileOperation.CopyFile( tag, destinationSoftLink, XStoreFileOperationType.CopyFromXStoreToSMB, helper); } else { var operationId = Guid.NewGuid(); // this is a multiple blob (folder) copy from xstore to smb xstoreFileOperation.CopyFolder( tag, destinationSoftLink, XStoreFileOperationType.CopyFromXStoreToSMB, copyFlag, null, null, helper, operationId); var blobContentEntries = XStoreCommon.GetDownloadContentEntries(operationId); if (blobContentEntries == null) { return; } var missingFiles = blobContentEntries.Where(entry => !File.Exists(entry.Item2)); if (missingFiles.Count() > 0) { //The missing file count will be traced out and there will be no retrying without remaining time. //The following step to do will return proper error code after sync up with hosting and image builder. if (helper != null && helper.GetRemainingTime() == TimeSpan.Zero) { this.traceSource.WriteWarning( ClassName, "{0} files missing after downloading, OperationID: {1}", missingFiles.Count(), operationId); return; } this.traceSource.WriteWarning( ClassName, "Retry to download the {0} missing files, operationID: {1}", missingFiles.Count(), operationId); foreach (var file in missingFiles) { xstoreFileOperation.CopyFile( file.Item1, file.Item2, XStoreFileOperationType.CopyFromXStoreToSMB, helper); } } } } } catch (Exception ex) { this.HandleException(ex); throw; } }