コード例 #1
0
 public void GivenIHaveTheStorageAbstraction(string account)
 {
     account = Constants.WabsProtocolSchemeName + account;
     var factory = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>();
     // NOTE: when run against production we should pull the key out of the valid creds file.
     var creds = new WindowsAzureStorageAccountCredentials() { Name = account, Key = string.Empty };
     abstraction = factory.Create(creds);
 }
コード例 #2
0
 public WabStorageAbstractionSimulator(WindowsAzureStorageAccountCredentials credentials)
 {
     this.credentials = credentials;
     this.RootPath = this.credentials.Name;
     this.ChosenProtocol = Constants.WabsProtocol;
     this.ChosenProtocolScheme = Constants.WabsProtocolSchemeName;
     this.Root = new StorageSimulatorItem(this.Account, string.Empty);
 }
コード例 #3
0
 public IStorageAbstraction Create(WindowsAzureStorageAccountCredentials credentials)
 {
     WabStorageAbstractionSimulator simulator;
     if (!this.simulators.TryGetValue(credentials.Name, out simulator))
     {
         simulator = new WabStorageAbstractionSimulator(credentials);
         this.simulators.Add(credentials.Name, simulator);
     }
     return simulator;
 }
コード例 #4
0
        public void CanGetStorageAccountName_Production()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Name = "demostorage"
            };

            var wabsStorageClient = new WabStorageAbstraction(storageCreds);
            Assert.AreEqual(wabsStorageClient.StorageAccountName, "demostorage");
            Assert.AreEqual(wabsStorageClient.StorageAccountRoot, "http://demostorage.blob.core.windows.net/");
        }
コード例 #5
0
        public void CanConvertWabsPathToHttpPath()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Name = "demostorage.blob.core.windows-int.net"
            };

            var asvPath = Constants.WabsProtocolSchemeName + "[email protected]/path1/path2";
            var httpPath = WabStorageAbstraction.ConvertToHttpPath(new Uri(asvPath));
            Assert.AreEqual("http://demostorage.blob.core.windows-int.net/container/path1/path2", httpPath.AbsoluteUri);
        }
コード例 #6
0
        public void CanGetStorageAccountName_Internal()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Name = Constants.WabsProtocolSchemeName + "demostorage.blob.core.windows-int.net"
            };

            var wabsStorageClient = new WabStorageAbstraction(storageCreds);
            Assert.AreEqual("demostorage", wabsStorageClient.StorageAccountName);
            Assert.AreEqual("http://demostorage.blob.core.windows-int.net", wabsStorageClient.StorageAccountRoot);
        }
コード例 #7
0
 public async Task CreateContainerIfNotExists(string fullAccount, string key, string container)
 {
     try
     {
         var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials() { Key = key, Name = fullAccount };
         var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageAbstractionCreds);
         await storageAbstraction.CreateContainerIfNotExists(container);
     }
     catch (Exception e)
     {
         throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture,
                                                              "Validating container '{0}' (storage '{1}') failed. Inner exception:{2}",
                                                              container,
                                                              fullAccount,
                                                              e.Message),
                                                e);
     }
 }
コード例 #8
0
 public async Task ValidateAccount(string fullAccount, string key)
 {
     try
     {
         var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials() { Key = key, Name = fullAccount };
         var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageAbstractionCreds);
         var listContainersUri = new Uri(string.Format("{0}://{1}/", Constants.WabsProtocol, fullAccount));
         await storageAbstraction.List(listContainersUri, false);
     }
     catch (Exception e)
     {
         throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture,
                                                              "Validating connection to '{0}' failed. Inner exception:{1}",
                                                              fullAccount,
                                                              e.Message),
                                                e);
     }
 }
コード例 #9
0
        public async Task ICanPerformA_PositiveCreateContainer_WithNonExistantContainer()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Key = IntegrationTestBase.TestCredentials.Environments[0].DefaultStorageAccount.Key,
                Name = IntegrationTestBase.TestCredentials.Environments[0].DefaultStorageAccount.Name
            };

            var nonExistantContainer = Guid.NewGuid().ToString("N").ToLowerInvariant();
            var client = ServiceLocator.Instance.Locate<IAsvValidatorClientFactory>().Create();
            await client.CreateContainerIfNotExists(storageCreds.Name, storageCreds.Key, nonExistantContainer);

            var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageCreds);
            var listContainerPath = new Uri(Constants.WabsProtocolSchemeName + nonExistantContainer + "@" + storageCreds.Name);
            var containers = await storageAbstraction.List(listContainerPath, false);
            var containerExists = containers.Any(path => path.UserInfo == nonExistantContainer);
            Assert.IsTrue(containerExists);
        }
 private void WriteJobResultFile(string statusDirectory, string content, string fileName)
 {
     if (!string.IsNullOrEmpty(statusDirectory))
     {
         var storageCreds = new WindowsAzureStorageAccountCredentials()
         {
             Name = Constants.WabsProtocolSchemeName + this.cluster.Cluster.DefaultStorageAccount.Name,
             Key = this.cluster.Cluster.DefaultStorageAccount.Key
         };
         var storageHandler = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageCreds);
         storageHandler.Write(this.GetStatusPath(statusDirectory, fileName), this.GetStream(content));
     }
 }
コード例 #11
0
        public static async Task ValidateAndResolveWasbScriptActionEndpointUri(Uri uri, WabStorageAccountConfiguration storage)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            // Try to check the existence of the script in the URI specified.
            var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials()
            {
                Key = storage.Key,
                Name = GetFullyQualifiedStorageAccountName(storage.Name),
            };

            var storageAbstraction = new WabStorageAbstraction(storageAbstractionCreds);

            bool exists = false;

            try
            {
                // Firstly converts the URI to wasb style and then test it against wasb storage for existence.
                exists = await storageAbstraction.Exists(ConvertToWasbUriIfNeeded(uri));
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Script action URI: {0} cannot be retrieved correctly. Inner exception: {1}", uri.AbsoluteUri, e.Message), e);
            }

            if (!exists)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Script action URI: {0} cannot be retrieved correctly because it does not exist", uri.AbsoluteUri));
            }
        }
コード例 #12
0
        public async Task NegativeTest_InvalidAsvContainer_Using_PocoClient_AgainstAzure()
        {
            this.ApplyIndividualTestMockingOnly();
            var cluster = GetRandomCluster();
            IHDInsightCertificateCredential credentials = IntegrationTestBase.GetValidCredentials();
            await ServiceLocator.Instance.Locate<IHDInsightManagementPocoClientFactory>().Create(credentials, GetAbstractionContext(), false).CreateContainer(cluster);

            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Key = cluster.DefaultStorageAccountKey,
                Name = cluster.DefaultStorageAccountName
            };
            var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageCreds);
            var listContainerPath = new Uri(Constants.WabsProtocolSchemeName + storageCreds.Name);
            var containers = await storageAbstraction.List(listContainerPath, false);
            var containerExists = containers.Any(path => path.UserInfo == cluster.DefaultStorageContainer);
            Assert.IsTrue(containerExists);
        }
コード例 #13
0
 public async Task CreateContainerIfNotExists(string fullAccount, string key, string container)
 {
     var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials() { Key = key, Name = fullAccount };
     var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageAbstractionCreds);
     await storageAbstraction.CreateContainerIfNotExists(container);
     }