/// <inheritdoc/> public override void ExecuteCmdlet() { this.ConfirmAction( this.Force.IsPresent, string.Format(Resources.ConfirmCreateStorageTarget, this.Name), string.Format(Resources.CreateStorageTarget, this.Name), this.Name, () => { this.storageTarget = this.CLFS.IsPresent ? this.CreateClfsStorageTargetParameters() : this.CreateNfsStorageTargetParameters(); if (this.IsParameterBound(c => c.Junction)) { this.storageTarget.Junctions = new List <NamespaceJunction>(); foreach (var junction in this.Junction) { var nameSpaceJunction = HashtableToDictionary <string, string>(junction); this.storageTarget.Junctions.Add( new NamespaceJunction( nameSpaceJunction.GetOrNull("namespacePath"), nameSpaceJunction.GetOrNull("targetPath"), nameSpaceJunction.GetOrNull("nfsExport"))); } } this.DoesStorageTargetExists(); var results = new List <PSHpcStorageTarget>() { this.CreateStorageTargetModel() }; this.WriteObject(results, enumerateCollection: true); }); }
private PSHpcStorageTarget CreateStorageTargetModel() { try { StorageTarget storageTarget = this.HpcCacheClient.StorageTargets.CreateOrUpdate( this.ResourceGroupName, this.CacheName, this.Name, this.storageTarget); } catch (CloudErrorException ex) { // Fix for update storage target, until Swagger is updated with correct response code. if (ex.Response.StatusCode == HttpStatusCode.Accepted) { try { this.storageTarget = Rest.Serialization.SafeJsonConvert.DeserializeObject <StorageTarget>(ex.Response.Content, this.HpcCacheClient.DeserializationSettings); } catch (JsonException jsonEx) { throw new SerializationException("Unable to deserialize the response.", ex.Response.Content, jsonEx); } } else { throw; } } return(new PSHpcStorageTarget(this.storageTarget)); }
public void TestStorageTargetInvalidTargetType() { this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode."); using (StorageCacheTestContext context = new StorageCacheTestContext(this)) { var client = context.GetClient <StorageCacheManagementClient>(); client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion; this.fixture.CacheHelper.StoragecacheManagementClient = client; StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters( "storageAccount", "blobContainer", "junction"); storageTargetParameters.TargetType = "invalid"; CloudErrorException ex = Assert.Throws <CloudErrorException>( () => this.fixture.CacheHelper.CreateStorageTarget( this.fixture.Cache.Name, "invalidst", storageTargetParameters, this.testOutputHelper, maxRequestTries: 0)); this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}"); this.testOutputHelper.WriteLine($"{ex.Body.Error.Code}"); this.testOutputHelper.WriteLine($"{ex.Body.Error.Target}"); Assert.Contains("InvalidParameter", ex.Body.Error.Code); Assert.Equal("storageTarget.targetType", ex.Body.Error.Target); } }
/// <summary> /// Create CLFS storage target. /// </summary> /// <param name="cacheName">Storage cache name.</param> /// <param name="storageTargetName">Storage target name.</param> /// <param name="storageTargetParameters">Object representing a Storage target parameters.</param> /// <param name="testOutputHelper">Object representing a ITestOutputHelper.</param> /// <param name="waitForStorageTarget">Wait for storage target to deploy.</param> /// <param name="maxRequestTries">Max retries.</param> /// <param name="delayBetweenTries">Delay between each retries in seconds.</param> /// <returns>CLFS storage target.</returns> public StorageTarget CreateStorageTarget( string cacheName, string storageTargetName, StorageTarget storageTargetParameters, ITestOutputHelper testOutputHelper = null, bool waitForStorageTarget = true, int maxRequestTries = 25, int delayBetweenTries = 90) { StorageTarget storageTarget; storageTarget = this.Retry( () => this.StoragecacheManagementClient.StorageTargets.CreateOrUpdate( this.resourceGroup.Name, cacheName, storageTargetName, storageTargetParameters), maxRequestTries, delayBetweenTries, "hasn't sufficient permissions", testOutputHelper); if (waitForStorageTarget) { this.WaitForStoragteTargetState(cacheName, storageTargetName, "Succeeded", testOutputHelper).GetAwaiter().GetResult(); } return(storageTarget); }
public void TestClfsTargetInvalidNameSpace() { this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode."); this.testOutputHelper.WriteLine("TestClfsTargetInvalidNamespace 2"); using (StorageCacheTestContext context = new StorageCacheTestContext(this)) { var client = context.GetClient <StorageCacheManagementClient>(); client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion; this.fixture.CacheHelper.StoragecacheManagementClient = client; var storageAccount = this.storageAccountsFixture.AddStorageAccount(context, this.fixture.ResourceGroup, testOutputHelper: this.testOutputHelper); var blobContainer = this.storageAccountsFixture.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount, testOutputHelper: this.testOutputHelper); StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters( storageAccount.Name, blobContainer.Name, "Invalid#$%1"); var exceptionTarget = string.Empty; CloudErrorException ex; ex = Assert.Throws <CloudErrorException>( () => this.fixture.CacheHelper.CreateInvalidStorageTarget( this.fixture.Cache.Name, "invalidst", storageTargetParameters, this.testOutputHelper)); exceptionTarget = ex.Message; testOutputHelper.WriteLine($"Exception Message: {ex.Body.Error.Message}"); testOutputHelper.WriteLine($"Exception Data: {ex.Body.Error.Code}"); testOutputHelper.WriteLine($"Exception Target: {ex.Body.Error.Target}"); Assert.Contains("InvalidParameter", ex.Body.Error.Code); Assert.Equal("storageTarget.junctions.namespacePath", ex.Body.Error.Target); //Assert.Equal("storageTarget.clfs.target", ex.Body.Error.Target); } }
public void TestClfsTargetInvalidResourceGroup() { this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode."); using (StorageCacheTestContext context = new StorageCacheTestContext(this)) { var client = context.GetClient <StorageCacheManagementClient>(); client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion; this.fixture.CacheHelper.StoragecacheManagementClient = client; var storageAccount = this.storageAccountsFixture.AddStorageAccount(context, this.fixture.ResourceGroup, testOutputHelper: this.testOutputHelper); var blobContainer = this.storageAccountsFixture.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount); StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters( storageAccount.Name, blobContainer.Name, "/junction", resourceGroupName: "invalidrs"); CloudErrorException ex = Assert.Throws <CloudErrorException>( () => this.fixture.CacheHelper.CreateStorageTarget( this.fixture.Cache.Name, "invalidst", storageTargetParameters, this.testOutputHelper, maxRequestTries: 0)); this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}"); this.testOutputHelper.WriteLine($"{ex.Body.Error.Code}"); this.testOutputHelper.WriteLine($"{ex.Body.Error.Target}"); Assert.Contains("InvalidParameter", ex.Body.Error.Code); Assert.Equal("storageTarget.clfs.target", ex.Body.Error.Target); } }
/// <summary> /// Creates storage account, blob container and adds BlobNfs storage account to cache. /// </summary> /// <param name="context">StorageCacheTestContext.</param> /// <param name="suffix">suffix.</param> /// <param name="waitForStorageTarget">Whether to wait for storage target to deploy.</param> /// <param name="addPermissions">Whether to add storage account contributor roles.</param> /// <param name="testOutputHelper">testOutputHelper.</param> /// <param name="sleep">Sleep time for permissions to get propagated.</param> /// <param name="waitForPermissions">Whether to wait for permissions to be propagated.</param> /// <param name="maxRequestTries">Max retries.</param> /// <returns>StorageTarget.</returns> public StorageTarget AddBlobNfsStorageAccount( StorageCacheTestContext context, string suffix = null, bool waitForStorageTarget = true, bool addPermissions = true, ITestOutputHelper testOutputHelper = null, int sleep = 300, bool waitForPermissions = true, int maxRequestTries = 25, string usageModel = "WRITE_WORKLOAD_15") { if (testOutputHelper != null) { testOutputHelper.WriteLine($"SAF Add blob nfs Storage Account"); } string storageTargetName = string.IsNullOrEmpty(suffix) ? this.fixture.ResourceGroup.Name : this.fixture.ResourceGroup.Name + suffix; string junction = "/junction" + suffix; var storageAccount = this.AddStorageAccount( context, this.fixture.ResourceGroup, suffix, addPermissions, testOutputHelper, sleep: sleep, waitForPermissions: waitForPermissions, blobNfs: true); var blobContainer = this.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount, suffix, testOutputHelper); testOutputHelper.WriteLine($"Add Storage Target Usage Model {usageModel}"); StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateBlobNfsStorageTargetParameters( storageAccount.Name, blobContainer.Name, junction, usageModel: usageModel, testOutputHelper: testOutputHelper); testOutputHelper.WriteLine($"Storage Target Parameters BlobNfs {storageTargetParameters.BlobNfs.UsageModel}"); testOutputHelper.WriteLine($"Storage Target Parameters BlobNfs {storageTargetParameters.BlobNfs.Target}"); StorageTarget storageTarget = this.fixture.CacheHelper.CreateStorageTarget( this.fixture.Cache.Name, storageTargetName, storageTargetParameters, testOutputHelper, waitForStorageTarget, maxRequestTries); if (testOutputHelper != null) { testOutputHelper.WriteLine($"Storage target Name {storageTarget.Name}"); testOutputHelper.WriteLine($"Storage target NamespacePath {storageTarget.Junctions[0].NamespacePath}"); testOutputHelper.WriteLine($"Storage target TargetPath {storageTarget.Junctions[0].TargetPath}"); testOutputHelper.WriteLine($"Storage target Id {storageTarget.Id}"); testOutputHelper.WriteLine($"Storage target Target {storageTarget.BlobNfs.Target}"); testOutputHelper.WriteLine($"Storage target UsageModel {storageTarget.BlobNfs.UsageModel}"); } return(storageTarget); }
/// <summary> /// Creates storage account, blob container and adds CLFS storage account to cache. /// </summary> /// <param name="context">HpcCacheTestContext.</param> /// <param name="suffix">suffix.</param> /// <param name="waitForStorageTarget">Whether to wait for storage target to deploy.</param> /// <param name="addPermissions">Whether to add storage account contributor roles.</param> /// <param name="testOutputHelper">testOutputHelper.</param> /// <param name="sleep">Sleep time for permissions to get propagated.</param> /// <param name="waitForPermissions">Whether to wait for permissions to be propagated.</param> /// <param name="maxRequestTries">Max retries.</param> /// <returns>StorageTarget.</returns> public StorageTarget AddClfsStorageTarget( HpcCacheTestContext context, string storageTargetName = "msazure", string storageAccountName = "cmdletsa", string containerName = "cmdletcontnr", string suffix = null, bool waitForStorageTarget = true, bool addPermissions = true, ITestOutputHelper testOutputHelper = null, int sleep = 300, bool waitForPermissions = true, int maxRequestTries = 25) { StorageTarget storageTarget; if (string.IsNullOrEmpty(HpcCacheTestEnvironmentUtilities.StorageTargetName)) { storageTargetName = string.IsNullOrEmpty(suffix) ? storageTargetName : storageTargetName + suffix; } else { storageTargetName = HpcCacheTestEnvironmentUtilities.StorageTargetName; } var client = context.GetClient <StorageCacheManagementClient>(); client.ApiVersion = Constants.DefaultAPIVersion; this.fixture.CacheHelper.StoragecacheManagementClient = client; storageTarget = this.fixture.CacheHelper.GetStorageTarget(this.fixture.Cache.Name, storageTargetName); if (storageTarget == null) { string junction = "/junction" + suffix; var storageAccount = this.AddStorageAccount( context, this.fixture.ResourceGroup, storageAccountName, suffix, addPermissions, testOutputHelper, sleep: sleep, waitForPermissions: waitForPermissions); var blobContainer = this.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount, containerName, suffix, testOutputHelper); StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters( storageAccount.Name, blobContainer.Name, junction); storageTarget = this.fixture.CacheHelper.CreateStorageTarget( this.fixture.Cache.Name, storageTargetName, storageTargetParameters, testOutputHelper, waitForStorageTarget, maxRequestTries); } return(storageTarget); }
private void FileExplorerOnDismiss(StorageTarget target, object file) { Select.IsChecked = false; var sample = file as IStorageFileEx; if (sample != null) { ViewModel.SelectSampleAsync(sample); } }
/// <inheritdoc/> public override void ExecuteCmdlet() { if (string.IsNullOrWhiteSpace(this.ResourceGroupName)) { throw new PSArgumentNullException("ResourceGroupName"); } if (string.IsNullOrWhiteSpace(this.CacheName)) { throw new PSArgumentNullException("CacheName"); } if (string.IsNullOrWhiteSpace(this.Name)) { throw new PSArgumentNullException("StorageTargetName"); } this.ConfirmAction( this.Force.IsPresent, string.Format(Resources.ConfirmUpdateStorageTarget, this.Name), string.Format(Resources.UpdateStorageTarget, this.Name), this.Name, () => { var storageT = this.DoesStorageTargetExists(); if (storageT == null) { throw new CloudException(string.Format("Storage target {0} does not exists.", this.Name)); } this.storageTarget = this.CLFS.IsPresent ? this.CreateClfsStorageTargetParameters(storageT) : this.CreateNfsStorageTargetParameters(storageT); if (this.IsParameterBound(c => c.Junction)) { this.storageTarget.Junctions = new List <NamespaceJunction>(); foreach (var junction in this.Junction) { var nameSpaceJunction = HashtableToDictionary <string, string>(junction); this.storageTarget.Junctions.Add( new NamespaceJunction( nameSpaceJunction.GetOrNull("namespacePath"), nameSpaceJunction.GetOrNull("targetPath"), nameSpaceJunction.GetOrNull("nfsExport"))); } } var results = new List <PSHpcStorageTarget>() { this.CreateStorageTargetModel() }; this.WriteObject(results, enumerateCollection: true); }); }
/// <summary> /// Creates storage account, blob container and adds CLFS storage account to cache. /// </summary> /// <param name="context">StorageCacheTestContext.</param> /// <param name="suffix">suffix.</param> /// <param name="waitForStorageTarget">Whether to wait for storage target to deploy.</param> /// <param name="addPermissions">Whether to add storage account contributor roles.</param> /// <param name="testOutputHelper">testOutputHelper.</param> /// <param name="sleep">Sleep time for permissions to get propagated.</param> /// <param name="waitForPermissions">Whether to wait for permissions to be propagated.</param> /// <param name="maxRequestTries">Max retries.</param> /// <returns>StorageTarget.</returns> public StorageTarget AddClfsStorageAccount( StorageCacheTestContext context, string suffix = null, bool waitForStorageTarget = true, bool addPermissions = true, ITestOutputHelper testOutputHelper = null, int sleep = 300, bool waitForPermissions = true, int maxRequestTries = 25) { if (testOutputHelper != null) { testOutputHelper.WriteLine($"SAF Add clfs Storage Account with wait for ST {waitForStorageTarget}, add Permissions {addPermissions}, waitForPermissions {waitForPermissions}"); } string storageTargetName = string.IsNullOrEmpty(suffix) ? this.fixture.ResourceGroup.Name : this.fixture.ResourceGroup.Name + suffix; string junction = "/junction" + suffix; var storageAccount = this.AddStorageAccount( context, this.fixture.ResourceGroup, suffix, addPermissions, testOutputHelper, sleep: sleep, waitForPermissions: waitForPermissions); var blobContainer = this.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount, suffix, testOutputHelper); StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters( storageAccount.Name, blobContainer.Name, junction); StorageTarget storageTarget = this.fixture.CacheHelper.CreateStorageTarget( this.fixture.Cache.Name, storageTargetName, storageTargetParameters, testOutputHelper, waitForStorageTarget, maxRequestTries); if (testOutputHelper != null) { testOutputHelper.WriteLine($"Storage target Name {storageTarget.Name}"); testOutputHelper.WriteLine($"Storage target NamespacePath {storageTarget.Junctions[0].NamespacePath}"); testOutputHelper.WriteLine($"Storage target TargetPath {storageTarget.Junctions[0].TargetPath}"); testOutputHelper.WriteLine($"Storage target Id {storageTarget.Id}"); testOutputHelper.WriteLine($"Storage target Target {storageTarget.Clfs.Target}"); } return(storageTarget); }
/// <summary> /// Update CLFS storage target parameters. /// </summary> /// <returns>CLFS storage target parameters.</returns> private StorageTarget CreateClfsStorageTargetParameters(StorageTarget storageT) { ClfsTarget clfsTarget = new ClfsTarget() { Target = storageT.Clfs.Target, }; StorageTarget storageTargetParameters = new StorageTarget { TargetType = "clfs", Clfs = clfsTarget, }; return(storageTargetParameters); }
/// <summary> /// Create CLFS storage target parameters. /// </summary> /// <returns>CLFS storage target parameters.</returns> private StorageTarget CreateClfsStorageTargetParameters() { ClfsTarget clfsTarget = new ClfsTarget() { Target = this.StorageContainerID, }; StorageTarget storageTargetParameters = new StorageTarget { TargetType = "clfs", Clfs = clfsTarget, }; return(storageTargetParameters); }
/// <summary> /// Update CLFS storage target parameters. /// </summary> /// <returns>CLFS storage target parameters.</returns> private StorageTarget CreateNfsStorageTargetParameters(StorageTarget storageT) { Nfs3Target nfs3Target = new Nfs3Target() { Target = storageT.Nfs3.Target, UsageModel = storageT.Nfs3.UsageModel, }; StorageTarget storageTargetParameters = new StorageTarget { TargetType = "nfs3", Nfs3 = nfs3Target, }; return(storageTargetParameters); }
/// <summary> /// Create NFS storage target parameters. /// </summary> /// <returns>NFS storage target parameters.</returns> private StorageTarget CreateNfsStorageTargetParameters() { Nfs3Target nfs3Target = new Nfs3Target() { Target = this.HostName, UsageModel = this.UsageModel, }; StorageTarget storageTargetParameters = new StorageTarget { TargetType = "nfs3", Nfs3 = nfs3Target, }; return(storageTargetParameters); }
public void TestClfsTargetEmptyNameSpace() { this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode."); using (StorageCacheTestContext context = new StorageCacheTestContext(this)) { var client = context.GetClient <StorageCacheManagementClient>(); client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion; this.fixture.CacheHelper.StoragecacheManagementClient = client; var storageAccount = this.storageAccountsFixture.AddStorageAccount(context, this.fixture.ResourceGroup, testOutputHelper: this.testOutputHelper); var blobContainer = this.storageAccountsFixture.AddBlobContainer(context, this.fixture.ResourceGroup, storageAccount, testOutputHelper: this.testOutputHelper); StorageTarget storageTargetParameters = this.fixture.CacheHelper.CreateClfsStorageTargetParameters( storageAccount.Name, blobContainer.Name, string.Empty); storageTargetParameters.Junctions = new List <NamespaceJunction>() { }; var exceptionTarget = string.Empty; CloudErrorException ex; DateTimeOffset startTime = DateTimeOffset.Now; do { ex = Assert.Throws <CloudErrorException>( () => this.fixture.CacheHelper.CreateStorageTarget( this.fixture.Cache.Name, "invalidst", storageTargetParameters, this.testOutputHelper, maxRequestTries: 0)); exceptionTarget = ex.Body.Error.Target; if (DateTimeOffset.Now.Subtract(startTime).TotalSeconds > 600) { throw new TimeoutException(); } }while (exceptionTarget != "storageTarget.junctions"); this.testOutputHelper.WriteLine($"{ex.Body.Error.Message}"); this.testOutputHelper.WriteLine($"{ex.Body.Error.Code}"); this.testOutputHelper.WriteLine($"{ex.Body.Error.Target}"); Assert.Contains("InvalidParameter", ex.Body.Error.Code); Assert.Equal("storageTarget.junctions", ex.Body.Error.Target); } }
/// <summary> /// Initializes a new instance of the <see cref="PSHpcStorageTarget"/> class. /// </summary> /// <param name="storageTargetObj">storage target object.</param> public PSHpcStorageTarget(StorageCacheModels.StorageTarget storageTargetObj) { this.storageTarget = storageTargetObj ?? throw new ArgumentNullException("storageTargetObj"); this.Name = storageTargetObj.Name; this.Id = storageTargetObj.Id; this.TargetType = storageTargetObj.TargetType; if (storageTargetObj.Nfs3 != null) { this.Nfs3 = new PSHpcNfs3Target(storageTargetObj.Nfs3); } if (storageTargetObj.Clfs != null) { this.Clfs = new PSHpcClfsTarget(storageTargetObj.Clfs); } this.ProvisioningState = storageTargetObj.ProvisioningState; this.Junctions = new List <PSNamespaceJunction>(); this.Junctions = storageTargetObj.Junctions.Select(j => new PSNamespaceJunction(j.NamespacePath, j.NfsExport, j.TargetPath)).ToList(); }
/// <summary> /// Create CLFS storage target parameters. /// </summary> /// <param name="storageAccountName">Storage account name.</param> /// <param name="containerName"> Storage container name.</param> /// <param name="namespacePath"> namepace path.</param> /// <param name="subscriptionId">Subscription id.</param> /// <param name="resourceGroupName">Resource group name.</param> /// <returns>CLFS storage target parameters.</returns> public StorageTarget CreateClfsStorageTargetParameters( string storageAccountName, string containerName, string namespacePath, string subscriptionId = null, string resourceGroupName = null) { var subscriptionID = string.IsNullOrEmpty(subscriptionId) ? this.subscriptionId : subscriptionId; var resourceGroup = string.IsNullOrEmpty(resourceGroupName) ? this.resourceGroup.Name : resourceGroupName; ClfsTarget clfsTarget = new ClfsTarget() { Target = $"/subscriptions/{subscriptionID}/" + $"resourceGroups/{resourceGroup}/" + $"providers/Microsoft.Storage/storageAccounts/{storageAccountName}/" + $"blobServices/default/containers/{containerName}", }; NamespaceJunction namespaceJunction = new NamespaceJunction() { NamespacePath = namespacePath, TargetPath = "/", }; StorageTarget storageTargetParameters = new StorageTarget { TargetType = "clfs", Clfs = clfsTarget, Junctions = new List <NamespaceJunction>() { namespaceJunction }, }; return(storageTargetParameters); }
public SettingStorageAttribute(string pathIn, string fieldNameIn, StorageTarget targetIn) { m_path = pathIn; m_fieldName = fieldNameIn; m_target = targetIn; }
/// <summary> /// Create or update a Storage Target. This operation is allowed at any time, /// but if the Cache is down or unhealthy, the actual creation/modification of /// the Storage Target may be delayed until the Cache is healthy again. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Target resource group. /// </param> /// <param name='cacheName'> /// Name of Cache. Length of name must be not greater than 80 and chars must be /// in list of [-0-9a-zA-Z_] char class. /// </param> /// <param name='storageTargetName'> /// Name of the Storage Target. Length of name must be not greater than 80 and /// chars must be in list of [-0-9a-zA-Z_] char class. /// </param> /// <param name='storagetarget'> /// Object containing the definition of a Storage Target. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <StorageTarget> CreateOrUpdateAsync(this IStorageTargets operations, string resourceGroupName, string cacheName, string storageTargetName, StorageTarget storagetarget = default(StorageTarget), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, cacheName, storageTargetName, storagetarget, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Create or update a Storage Target. This operation is allowed at any time, /// but if the Cache is down or unhealthy, the actual creation/modification of /// the Storage Target may be delayed until the Cache is healthy again. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Target resource group. /// </param> /// <param name='cacheName'> /// Name of Cache. Length of name must be not greater than 80 and chars must be /// in list of [-0-9a-zA-Z_] char class. /// </param> /// <param name='storageTargetName'> /// Name of the Storage Target. Length of name must be not greater than 80 and /// chars must be in list of [-0-9a-zA-Z_] char class. /// </param> /// <param name='storagetarget'> /// Object containing the definition of a Storage Target. /// </param> public static StorageTarget CreateOrUpdate(this IStorageTargets operations, string resourceGroupName, string cacheName, string storageTargetName, StorageTarget storagetarget = default(StorageTarget)) { return(operations.CreateOrUpdateAsync(resourceGroupName, cacheName, storageTargetName, storagetarget).GetAwaiter().GetResult()); }
public FileTarget(StorageTarget storageTarget, int linkDepth, bool constrainToSite) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="PSHpcStorageTarget"/> class. /// </summary> public PSHpcStorageTarget() { this.storageTarget = new StorageCacheModels.StorageTarget(); }
public void TestCreateClfsStorageTarget() { testOutputHelper.WriteLine(storageAccountsFixture.notes.ToString()); this.testOutputHelper.WriteLine($"Running in {HttpMockServer.GetCurrentMode()} mode."); using (StorageCacheTestContext context = new StorageCacheTestContext(this)) { var client = context.GetClient <StorageCacheManagementClient>(); client.ApiVersion = StorageCacheTestEnvironmentUtilities.APIVersion; this.fixture.CacheHelper.StoragecacheManagementClient = client; StorageTarget storageTarget; var suffix = "cre"; storageTarget = this.storageAccountsFixture.AddClfsStorageAccount(context, suffix: suffix, waitForPermissions: false, testOutputHelper: this.testOutputHelper); string id = $"/subscriptions/{this.fixture.SubscriptionID}" + $"/resourceGroups/{this.fixture.ResourceGroup.Name}" + $"/providers/Microsoft.StorageCache/caches/{this.fixture.Cache.Name}" + $"/storageTargets/{this.fixture.ResourceGroup.Name + suffix}"; string clfsTarget = $"/subscriptions/{this.fixture.SubscriptionID}" + $"/resourceGroups/{this.fixture.ResourceGroup.Name}" + $"/providers/Microsoft.Storage/storageAccounts/{this.fixture.ResourceGroup.Name + suffix}" + $"/blobServices/default/containers/{this.fixture.ResourceGroup.Name + suffix}"; Assert.Equal(this.fixture.ResourceGroup.Name + suffix, storageTarget.Name); Assert.Equal(id, storageTarget.Id, ignoreCase: true); Assert.Equal("clfs", storageTarget.TargetType); Assert.Equal(clfsTarget, storageTarget.Clfs.Target); Assert.Equal("/junction" + suffix, storageTarget.Junctions[0].NamespacePath); Assert.Equal("/", storageTarget.Junctions[0].TargetPath); // Call an invalid DNSRefresh case. Models.SystemData systemData = new Models.SystemData("SDK", "Application", DateTime.UtcNow, "SDK", "Application", DateTime.UtcNow); StorageTarget st = new StorageTarget("clfs", "clfsStorageTarget", null, "StorageTarget", systemData: systemData); Models.SystemData sd = storageTarget.SystemData; testOutputHelper.WriteLine($"ST values createdBy {sd.CreatedBy}, createdByType {sd.CreatedByType}, createdAt {sd.CreatedAt}"); testOutputHelper.WriteLine($"ST values modifiedBy {sd.LastModifiedBy}, modifiedByType {sd.LastModifiedByType}, modifiedAt {sd.LastModifiedAt}"); CloudErrorException ex = new CloudErrorException(); ex = Assert.Throws <CloudErrorException>( () => client.StorageTargets.DnsRefresh(fixture.ResourceGroup.Name, fixture.Cache.Name, storageTarget.Name)); testOutputHelper.WriteLine($"Exception Message: {ex.Body.Error.Message}"); testOutputHelper.WriteLine($"Request: {ex.Request}"); testOutputHelper.WriteLine($"Response: {ex.Response}"); Assert.Contains("BadRequest", ex.Body.Error.Code); Microsoft.Rest.ValidationException rex = Assert.Throws <Microsoft.Rest.ValidationException>( () => client.StorageTargets.DnsRefresh(null, fixture.Cache.Name, storageTarget.Name)); testOutputHelper.WriteLine($"Exception Message: {rex.Message}"); Assert.Contains("'resourceGroupName' cannot be null", rex.Message); rex = Assert.Throws <Microsoft.Rest.ValidationException>( () => client.StorageTargets.DnsRefresh(fixture.ResourceGroup.Name, null, storageTarget.Name)); testOutputHelper.WriteLine($"Exception Message: {rex.Message}"); Assert.Contains("'cacheName' cannot be null", rex.Message); rex = Assert.Throws <Microsoft.Rest.ValidationException>( () => client.StorageTargets.DnsRefresh(fixture.ResourceGroup.Name, ".badcachename.", storageTarget.Name)); testOutputHelper.WriteLine($"Exception Message: {rex.Message}"); Assert.Contains("'cacheName' does not match expected pattern '^[-0-9a-zA-Z_]{1,80}$'", rex.Message); } }
/// <summary> /// Create or update a Storage Target. This operation is allowed at any time, /// but if the Cache is down or unhealthy, the actual creation/modification of /// the Storage Target may be delayed until the Cache is healthy again. /// </summary> /// <param name='resourceGroupName'> /// Target resource group. /// </param> /// <param name='cacheName'> /// Name of Cache. Length of name must be not greater than 80 and chars must be /// in list of [-0-9a-zA-Z_] char class. /// </param> /// <param name='storageTargetName'> /// Name of the Storage Target. Length of name must be not greater than 80 and /// chars must be in list of [-0-9a-zA-Z_] char class. /// </param> /// <param name='storagetarget'> /// Object containing the definition of a Storage Target. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="CloudErrorException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse <StorageTarget> > CreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string cacheName, string storageTargetName, StorageTarget storagetarget = default(StorageTarget), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (cacheName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "cacheName"); } if (cacheName != null) { if (!System.Text.RegularExpressions.Regex.IsMatch(cacheName, "^[-0-9a-zA-Z_]{1,80}$")) { throw new ValidationException(ValidationRules.Pattern, "cacheName", "^[-0-9a-zA-Z_]{1,80}$"); } } if (storageTargetName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "storageTargetName"); } if (storageTargetName != null) { if (!System.Text.RegularExpressions.Regex.IsMatch(storageTargetName, "^[-0-9a-zA-Z_]{1,80}$")) { throw new ValidationException(ValidationRules.Pattern, "storageTargetName", "^[-0-9a-zA-Z_]{1,80}$"); } } if (storagetarget != null) { storagetarget.Validate(); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("cacheName", cacheName); tracingParameters.Add("storageTargetName", storageTargetName); tracingParameters.Add("storagetarget", storagetarget); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "CreateOrUpdate", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.StorageCache/caches/{cacheName}/storageTargets/{storageTargetName}").ToString(); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{cacheName}", System.Uri.EscapeDataString(cacheName)); _url = _url.Replace("{storageTargetName}", System.Uri.EscapeDataString(storageTargetName)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += "?" + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (storagetarget != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(storagetarget, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 201) { var ex = new CloudErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <CloudError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse <StorageTarget>(); _result.Request = _httpRequest; _result.Response = _httpResponse; // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <StorageTarget>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } // Deserialize Response if ((int)_statusCode == 201) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <StorageTarget>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public static bool IsSettingStorageAttributeSet(System.Reflection.MemberInfo prop, StorageTarget targetIn) { SettingStorageAttribute[] attr = (SettingStorageAttribute[])prop.GetCustomAttributes(typeof(SettingStorageAttribute), false); if (attr != null) { if (attr.Length > 0) { return(attr[0].Target == targetIn); } } return(false); }