Exemplo n.º 1
0
        /// <summary>
        /// Download a package from blob storage and unzip it
        /// </summary>
        /// <param name="containerName">The Blob storage container name</param>
        /// <param name="packageName">The name of the zip file package</param>
        /// <param name="workingDirectory">Where to extract the files</param>
        private static void InstallPackage(string containerName, string packageName, string workingDirectory)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(DATA_CONNECTION_STRING));

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            blobClient.RetryPolicy = RetryPolicies.Retry(100, TimeSpan.FromSeconds(1));
            blobClient.Timeout     = TimeSpan.FromSeconds(600);

            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlockBlob     blob      = container.GetBlockBlobReference(packageName);

            Console.WriteLine(string.Format("Downloading {0} to {1}", blob.Uri, workingDirectory), "Information");

            if (blob.Uri.PathAndQuery.EndsWith(".zip", true, Thread.CurrentThread.CurrentCulture))
            {
                // if this is a zip file, unzip it
                // the temp dirtectory is limited to 100 MB
                var filename = @"c:\" + Guid.NewGuid();
                blob.DownloadToFile(filename);

                Console.WriteLine(string.Format("Extracting {0}", packageName), "Information");

                UnZip(Directory.GetCurrentDirectory(), filename, workingDirectory);

                // delete the temp file
                File.Delete(filename);
            }
            else
            {
                blob.DownloadToFile(@"c:\Applications\" + blob.Uri.Segments.Last());
            }

            Console.WriteLine("Extraction finished", "Information");
        }
Exemplo n.º 2
0
        // Constructor - get settings from a hosted service configuration or .NET configuration file.

        public BlobHelper(string configurationSettingName, bool hostedService)
        {
            if (hostedService)
            {
                CloudStorageAccount.SetConfigurationSettingPublisher(
                    (configName, configSettingPublisher) =>
                {
                    var connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
                    configSettingPublisher(connectionString);
                }
                    );
            }
            else
            {
                CloudStorageAccount.SetConfigurationSettingPublisher(
                    (configName, configSettingPublisher) =>
                {
                    var connectionString = ConfigurationManager.ConnectionStrings[configName].ConnectionString;
                    configSettingPublisher(connectionString);
                }
                    );
            }

            Account = CloudStorageAccount.FromConfigurationSetting(configurationSettingName);

            BlobClient             = Account.CreateCloudBlobClient();
            BlobClient.RetryPolicy = RetryPolicies.Retry(4, TimeSpan.Zero);
        }
        public WindowsAzureStorageHelper(string accountName, string accountKey, bool isLocal, string blobEndpointURI, string queueEndpointURI, string tableEndpointURI)
        {
            ContainerName = CONTAINER_NAME;

            StorageAccountInfo = new StorageAccountInfo(new Uri(blobEndpointURI), isLocal, accountName, accountKey);

            BlobStorageType             = BlobStorage.Create(StorageAccountInfo);
            BlobStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100));
            Container = BlobStorageType.GetBlobContainer(ContainerName);

            //Create the container if it does not exist.
            Container.CreateContainer(ContainerMetaData, ContainerAccessControl.Private);

            // Open queue storage.

            //StorageAccountInfo qaccount = StorageAccountInfo.GetDefaultQueueStorageAccountFromConfiguration();

            StorageAccountInfo qaccount = new StorageAccountInfo(new Uri(queueEndpointURI), isLocal, accountName, accountKey);

            QueueStorageType             = QueueStorage.Create(qaccount);
            QueueStorageType             = QueueStorage.Create(qaccount);
            QueueStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100));

            // Open table storage.

            //StorageAccountInfo taccount = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();
            StorageAccountInfo taccount = new StorageAccountInfo(new Uri(tableEndpointURI), isLocal, accountName, accountKey);

            TableStorageType             = TableStorage.Create(taccount);
            TableStorageType             = TableStorage.Create(taccount);
            TableStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100));
        }
Exemplo n.º 4
0
 public DatasetInfoDataSource()
 {
     _context = new DatasetInfoDataContext(StorageAccount.TableEndpoint.AbsoluteUri, StorageAccount.Credentials)
     {
         RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1))
     };
 }
Exemplo n.º 5
0
        public void InitializeCloudStorageAccess(string containerName)
        {
            if (containerName == null)
            {
                throw new ArgumentNullException("containerName");
            }
            if (containerName == "")
            {
                throw new ArgumentException("Invalid container name", "containerName");
            }
            if (initializedContainerName != null)
            {
                if (containerName == initializedContainerName)
                {
                    return;
                }
                if (containerName != initializedContainerName)
                {
                    throw new NotSupportedException("InitializeCloudStorageAccess already initialized with container name: "
                                                    + initializedContainerName + " (tried to initialize with: "
                                                    + containerName + ")");
                }
            }
            CloudBlobClient blobClient = StorageSupport.CurrStorageAccount.CreateCloudBlobClient();

            blobClient.RetryPolicy = RetryPolicies.Retry(10, TimeSpan.FromMilliseconds(300));
            CurrBlobClient         = blobClient;

            var activeContainer = blobClient.GetContainerReference(containerName.ToLower());

            activeContainer.CreateIfNotExist();
            CurrActiveContainer      = activeContainer;
            initializedContainerName = containerName;
        }
Exemplo n.º 6
0
        public static List <string> GetTableColumnsMetadata(string entitySet, string ogdiAlias)
        {
            var accountName =
                AppSettings.EnabledStorageAccounts[ogdiAlias].storageaccountname;
            var accountKey =
                AppSettings.EnabledStorageAccounts[ogdiAlias].storageaccountkey;
            var connString          = "DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}";
            var cloudStorageAccount = CloudStorageAccount.Parse(string.Format(connString, accountName, accountKey));
            var context             = new TableColumnsMetadataDataServiceContext(cloudStorageAccount.TableEndpoint.ToString(), cloudStorageAccount.Credentials)
            {
                RetryPolicy =
                    RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount,
                                                   RetryPolicies.DefaultClientBackoff)
            };

            List <string> namespaces = new List <string>();

            var query = from entity in context.TableColumnsMetadataTable
                        where entity.PartitionKey == entitySet
                        select entity;

            string namespaceAdded;

            foreach (TableColumnsMetadataEntity c in query)
            {
                namespaceAdded = string.Empty;
                namespaceAdded = namespaces.Find(item => item.Split('=')[0] == c.columnnamespace.Split('=')[0]);
                if (namespaceAdded == string.Empty || namespaceAdded == null)
                {
                    namespaces.Add(c.columnnamespace);
                }
            }
            return(namespaces);
        }
        public static void ParallelUpload(this CloudBlockBlob blobRef, string filename, BlobRequestOptions options)
        {
            if (null == options)
            {
                options = new BlobRequestOptions()
                {
                    Timeout     = blobRef.ServiceClient.Timeout,
                    RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff)
                };
            }

            // get upload history if any
            UploadInfo uploadInfo = UploadInfo.LoadByUploadFilename(filename);

            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                blobRef.ParallelUpload(fs, uploadInfo, options);
            }

            // upload completed no history needed - delete it
            if (File.Exists(uploadInfo.LogFilename))
            {
                File.Delete(uploadInfo.LogFilename);
            }

            Console.WriteLine("\nUpload completed.");
        }
Exemplo n.º 8
0
        private static bool StoreEntity(string entitySetName, Entity entity, string parKey, string rowKey)
        {
            TableContext context = new TableContext(account.TableEndpoint.ToString(), account.Credentials)
            {
                RetryPolicy = RetryPolicies.RetryExponential(5, new TimeSpan(0, 0, 1))
            };

            TableEntity tableEntity = new TableEntity(entity, parKey, rowKey);

            context.AddObject(entitySetName, tableEntity);

            try
            {
                context.SaveChanges();
                return(true);
            }
            catch (StorageClientException e)
            {
                WriteInFile(filename, "ERROR " + entitySetName + " entity was not created " + e.Message);
                return(false);
            }
            catch (Exception e)
            {
                WriteInFile(filename, "ERROR " + entitySetName + " entity was not created " + e.Message);
                return(false);
            }
        }
        private void Init(string configurationSettingName)
        {
            if (RoleEnvironment.IsAvailable)
            {
                CloudStorageAccount.SetConfigurationSettingPublisher(
                    (configName, configSettingPublisher) =>
                {
                    var connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
                    configSettingPublisher(connectionString);
                }
                    );
            }
            else
            {
                CloudStorageAccount.SetConfigurationSettingPublisher(
                    (configName, configSettingPublisher) =>
                {
                    var connectionString = ConfigurationManager.ConnectionStrings[configName].ConnectionString;
                    configSettingPublisher(connectionString);
                }
                    );
            }

            Account = CloudStorageAccount.FromConfigurationSetting(configurationSettingName);

            TableClient             = Account.CreateCloudTableClient();
            TableClient.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromMilliseconds(100));
        }
Exemplo n.º 10
0
        public string AlmacenarCfdiFramework4(Stream cfdi, string Xml, string uuid)
        {
            var sharedAccessSignature = new StorageCredentialsSharedAccessSignature(ConfigurationManager.AppSettings["SharedAccesSignature"].Replace('|', '&'));
            var blobClient            = new CloudBlobClient(ConfigurationManager.AppSettings["BlobStorageEndpoint"],
                                                            sharedAccessSignature);

            blobClient.RetryPolicy = RetryPolicies.RetryExponential(15, TimeSpan.FromSeconds(25));

            blobClient.Timeout = TimeSpan.FromMinutes(1);
            var blobContainer = blobClient
                                .GetContainerReference(ConfigurationManager.AppSettings["ContainerName"]);
            var blob = blobContainer.GetBlobReference(uuid);

            if (cfdi.Length <= MaximumBlobSizeBeforeTransmittingAsBlocks)
            {
                XElement xdoc    = XElement.Parse(Xml);
                string   version = xdoc.Attribute("Version") == null ? "" : xdoc.Attribute("Version").Value;
                if (version != "")
                {
                    blob.UploadFromStream(cfdi);
                    blob.Metadata["versionCFDI"] = version;
                    blob.SetMetadata();
                }
            }
            else
            {
                var blockBlob = blobContainer.GetBlockBlobReference(blob.Uri.AbsoluteUri);
                blockBlob.UploadFromStream(cfdi);
            }

            return(blob.Uri.AbsoluteUri);
        }
Exemplo n.º 11
0
        private List <string> GetTableColumnsMetadata()
        {
            TableColumnsMetadataDataServiceContext context = new TableColumnsMetadataDataServiceContext(_Account.TableEndpoint.ToString(), _Account.Credentials)
            {
                RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff)
            };

            List <string> namespaces = new List <string>();

            var query = from entity in context.TableColumnsMetadataTable
                        where entity.PartitionKey == EntitySet
                        select entity;

            string namespaceAdded;

            foreach (var c in query)
            {
                namespaceAdded = string.Empty;
                namespaceAdded = namespaces.Find(item => item.Split('=')[0] == c.columnnamespace.Split('=')[0]);
                if (namespaceAdded == string.Empty || namespaceAdded == null)
                {
                    namespaces.Add(c.columnnamespace);
                }
            }

            return(namespaces);
        }
Exemplo n.º 12
0
        protected internal static RetryPolicy CreateRetryPolicy(Configuration conf, string
                                                                maxWaitTimeStr, long defMaxWaitTime, string connectRetryIntervalStr, long defRetryInterval
                                                                )
        {
            long maxWaitTime     = conf.GetLong(maxWaitTimeStr, defMaxWaitTime);
            long retryIntervalMS = conf.GetLong(connectRetryIntervalStr, defRetryInterval);

            if (maxWaitTime == -1)
            {
                // wait forever.
                return(RetryPolicies.RetryForever);
            }
            Preconditions.CheckArgument(maxWaitTime > 0, "Invalid Configuration. " + maxWaitTimeStr
                                        + " should be a positive value.");
            Preconditions.CheckArgument(retryIntervalMS > 0, "Invalid Configuration. " + connectRetryIntervalStr
                                        + "should be a positive value.");
            RetryPolicy retryPolicy = RetryPolicies.RetryUpToMaximumTimeWithFixedSleep(maxWaitTime
                                                                                       , retryIntervalMS, TimeUnit.Milliseconds);
            IDictionary <Type, RetryPolicy> exceptionToPolicyMap = new Dictionary <Type, RetryPolicy
                                                                                   >();

            exceptionToPolicyMap[typeof(EOFException)]           = retryPolicy;
            exceptionToPolicyMap[typeof(ConnectException)]       = retryPolicy;
            exceptionToPolicyMap[typeof(NoRouteToHostException)] = retryPolicy;
            exceptionToPolicyMap[typeof(UnknownHostException)]   = retryPolicy;
            exceptionToPolicyMap[typeof(RetriableException)]     = retryPolicy;
            exceptionToPolicyMap[typeof(SocketException)]        = retryPolicy;
            exceptionToPolicyMap[typeof(NMNotYetReadyException)] = retryPolicy;
            return(RetryPolicies.RetryByException(RetryPolicies.TryOnceThenFail, exceptionToPolicyMap
                                                  ));
        }
Exemplo n.º 13
0
        private static void CheckAndUpdateMetadataLastUpdateDate(string metadataSet, string entitySet, string entityKind,
                                                                 DateTime lastUpdateDate, DataLoaderParams Params)
        {
            var context = new TableContext(s_account.TableEndpoint.ToString(), s_account.Credentials, Params)
            {
                RetryPolicy =
                    RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount,
                                                   RetryPolicies.DefaultClientBackoff)
            };

            string             query   = string.Format(s_metadataEntityQueryTemplate, metadataSet, entitySet, entityKind);
            List <TableEntity> results = context.Execute <TableEntity>(new Uri(query, UriKind.Relative)).ToList();

            if (results.Count == 1)
            {
                DateTime oldLastUpdateDate = new TableMetadataEntity(results[0]).LastUpdateDate;
                if (oldLastUpdateDate > lastUpdateDate)
                {
                    throw new MetadataOutdatedException(oldLastUpdateDate, lastUpdateDate);
                }

                results[0].UpdateProperty(DataLoaderConstants.PropNameLastUpdateDate, lastUpdateDate);
                context.UpdateObject(results[0]);
                context.SaveChanges();
            }
            else if (results.Count > 1)
            {
                throw new DuplicateEntityException(query);
            }
        }
Exemplo n.º 14
0
        private static void CheckMetadataChanges(string metadataSet, string entitySet, string entityKind, Entity entity,
                                                 DataLoaderParams Params, MetadataKind metadataKind)
        {
            var context = new TableContext(s_account.TableEndpoint.ToString(), s_account.Credentials, Params)
            {
                RetryPolicy =
                    RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount,
                                                   RetryPolicies.DefaultClientBackoff)
            };

            string             query   = string.Format(s_metadataEntityQueryTemplate, metadataSet, entitySet, entityKind);
            List <TableEntity> results = context.Execute <TableEntity>(new Uri(query, UriKind.Relative)).ToList();

            if (results.Count == 1)
            {
                var exceprionColumns = new[]
                {
                    DataLoaderConstants.PropNameEntityId,
                    DataLoaderConstants.PropNameLastUpdateDate
                };
                string differences = results[0].FindDifferences(entity, exceprionColumns);
                if (differences != null)
                {
                    throw new MetadataChangedException(entitySet, differences);
                }
            }
            else if (results.Count > 1)
            {
                throw new DuplicateEntityException(query);
            }
            else if (results.Count == 0)
            {
                throw new MetadataNotFoundException(entitySet, metadataKind);
            }
        }
Exemplo n.º 15
0
        public void Test()
        {
            var client = Play_all_for_BlobStreaming.GetCustom();

            client.RetryPolicy = RetryPolicies.NoRetry();

            var root = new BlobStreamingRoot(client);
            var cont = root.GetContainer("tests").Create();

            var storageItem = cont.GetItem("test");


            storageItem.Write(w => w.WriteByte(1), options: StreamingWriteOptions.CompressIfPossible);
            storageItem.ReadInto((props, stream) => stream.CopyTo(new MemoryStream(), 10));

            var format = storageItem.GetInfo();

            string ctx;

            if (!format.Value.Properties.TryGetValue("ContentMD5", out ctx))
            {
                ctx = "None";
            }

            Console.WriteLine("MD5: {0}", ctx);

            //storageItem.ReadText();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the value of an input field.
        /// </summary>
        /// <param name="driver">this</param>
        /// <param name="inputFieldSelector">The selector for the input field to populate.</param>
        /// <param name="inputFieldType">The InputFieldType of the input field.</param>
        /// <param name="value">The value with which to populate the specified input field.</param>
        public static void SetInputFieldValue(this IWebDriver driver, By inputFieldSelector, InputFieldType inputFieldType, string value)
        {
            driver.ScrollIntoView(inputFieldSelector);
            var inputField = RetryPolicies.HandleDriverException().Execute(() => driver.FindElement(inputFieldSelector));

            switch (inputFieldType)
            {
            case InputFieldType.Text:
            case InputFieldType.Password:
                inputField.Clear();
                inputField.SendKeys(value);
                break;

            case InputFieldType.Dropdown:
            case InputFieldType.MultiSelectBox:
                var selectElement = new SelectElement(inputField);
                selectElement.SelectByText(value);
                break;

            case InputFieldType.Checkbox:
            case InputFieldType.RadioButton:
                var currentValue = inputField.Selected ? "true" : "false";
                if (!currentValue.Equals(value, StringComparison.InvariantCultureIgnoreCase))
                {
                    inputField.Click();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException($"{inputFieldType} is not a valid input field type.");
            }
        }
        private void Connect()
        {
            connected = false;

            int trycount = 0;

            while (trycount++ < 3)
            {
                try
                {
                    string connectionString = RoleEnvironment.GetConfigurationSettingValue(connectionStringName);
                    _storageAccount          = CloudStorageAccount.Parse(connectionString);
                    _tableClient             = new CloudTableClient(_storageAccount.TableEndpoint.AbsoluteUri, _storageAccount.Credentials);
                    _tableClient.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));
                    if (!_tableClient.DoesTableExist(tableName))
                    {
                        _tableClient.CreateTableIfNotExist(tableName);
                    }

                    connected = true;
                    break;
                }
                catch
                {
                }
            }

            if (!connected)
            {
                throw new Exception("Could not connect to table service");
            }
        }
Exemplo n.º 18
0
        public AzureMessageLogWriter(CloudStorageAccount account, string tableName)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentException("tableName");
            }

            this.account                 = account;
            this.tableName               = tableName;
            this.tableClient             = account.CreateCloudTableClient();
            this.tableClient.RetryPolicy = RetryPolicies.NoRetry();

            var retryStrategy = new ExponentialBackoff(10, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(1));

            this.retryPolicy = new RetryPolicy <StorageTransientErrorDetectionStrategy>(retryStrategy);

            this.retryPolicy.ExecuteAction(() => tableClient.CreateTableIfNotExist(tableName));
        }
Exemplo n.º 19
0
 static AzureQueueDefaultPolicies()
 {
     MaxQueueOperationRetries          = 5;
     PauseBetweenQueueOperationRetries = TimeSpan.FromMilliseconds(100);
     QueueOperationRetryPolicy         = RetryPolicies.Retry(MaxQueueOperationRetries, PauseBetweenQueueOperationRetries); // 5 x 100ms
     QueueOperationTimeout             = PauseBetweenQueueOperationRetries.Multiply(MaxQueueOperationRetries).Multiply(6); // 3 sec
 }
Exemplo n.º 20
0
        private void Connect()
        {
            connected = false;

            int trycount = 0;

            while (trycount++ < 3)
            {
                try
                {
                    //comment added just for test
                    string connectionString = "DefaultEndpointsProtocol=https; AccountName=careerthesaurus; AccountKey=52D4zWvYaIL6gfl4FUt6y8cc9Ar8UV8EWNmBttpraVkMJjcy+cOlDhiZYTnmGZLdpKV1nwlNNlGQJiqZh9rlxQ==";
                    _storageAccount          = CloudStorageAccount.Parse(connectionString);
                    _tableClient             = new CloudTableClient(_storageAccount.TableEndpoint.AbsoluteUri, _storageAccount.Credentials);
                    _tableClient.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));
                    if (!_tableClient.DoesTableExist(tableName))
                    {
                        _tableClient.CreateTableIfNotExist(tableName);
                    }

                    connected = true;
                    break;
                }
                catch
                {
                }
            }

            if (!connected)
            {
                throw new Exception("Could not connect to table service");
            }
        }
Exemplo n.º 21
0
 public GuestBookDataSource()
 {
     context = new GuestBookDataContext(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials)
     {
         RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1))
     };
 }
Exemplo n.º 22
0
        /// <summary>Creates the namenode proxy with the passed protocol.</summary>
        /// <remarks>
        /// Creates the namenode proxy with the passed protocol. This will handle
        /// creation of either HA- or non-HA-enabled proxy objects, depending upon
        /// if the provided URI is a configured logical URI.
        /// </remarks>
        /// <param name="conf">
        /// the configuration containing the required IPC
        /// properties, client failover configurations, etc.
        /// </param>
        /// <param name="nameNodeUri">
        /// the URI pointing either to a specific NameNode
        /// or to a logical nameservice.
        /// </param>
        /// <param name="xface">the IPC interface which should be created</param>
        /// <param name="fallbackToSimpleAuth">
        /// set to true or false during calls to indicate if
        /// a secure client falls back to simple auth
        /// </param>
        /// <returns>
        /// an object containing both the proxy and the associated
        /// delegation token service it corresponds to
        /// </returns>
        /// <exception cref="System.IO.IOException">if there is an error creating the proxy</exception>
        public static NameNodeProxies.ProxyAndInfo <T> CreateProxy <T>(Configuration conf,
                                                                       URI nameNodeUri, AtomicBoolean fallbackToSimpleAuth)
        {
            System.Type xface = typeof(T);
            AbstractNNFailoverProxyProvider <T> failoverProxyProvider = CreateFailoverProxyProvider
                                                                            (conf, nameNodeUri, xface, true, fallbackToSimpleAuth);

            if (failoverProxyProvider == null)
            {
                // Non-HA case
                return(CreateNonHAProxy(conf, NameNode.GetAddress(nameNodeUri), xface, UserGroupInformation
                                        .GetCurrentUser(), true, fallbackToSimpleAuth));
            }
            else
            {
                // HA case
                DFSClient.Conf config = new DFSClient.Conf(conf);
                T proxy = (T)RetryProxy.Create(xface, failoverProxyProvider, RetryPolicies.FailoverOnNetworkException
                                                   (RetryPolicies.TryOnceThenFail, config.maxFailoverAttempts, config.maxRetryAttempts
                                                   , config.failoverSleepBaseMillis, config.failoverSleepMaxMillis));
                Text dtService;
                if (failoverProxyProvider.UseLogicalURI())
                {
                    dtService = HAUtil.BuildTokenServiceForLogicalUri(nameNodeUri, HdfsConstants.HdfsUriScheme
                                                                      );
                }
                else
                {
                    dtService = SecurityUtil.BuildTokenService(NameNode.GetAddress(nameNodeUri));
                }
                return(new NameNodeProxies.ProxyAndInfo <T>(proxy, dtService, NameNode.GetAddress(
                                                                nameNodeUri)));
            }
        }
Exemplo n.º 23
0
        static CloudBlobClient CreateCloudBlobClient()
        {
            var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();

            client.RetryPolicy = RetryPolicies.NoRetry();
            return(client);
        }
Exemplo n.º 24
0
        private CloudBlobContainer GetBlobContainer(string containerName)
        {
            var client = this.StorageAccount.CreateCloudBlobClient();

            client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5));
            return(client.GetContainerReference(containerName));
        }
Exemplo n.º 25
0
        static AzureTableDefaultPolicies()
        {
            MaxTableCreationRetries          = 60;
            PauseBetweenTableCreationRetries = TimeSpan.FromSeconds(1);

            MaxTableOperationRetries          = 5;
            PauseBetweenTableOperationRetries = TimeSpan.FromMilliseconds(100);

            MaxBusyRetries          = 120;
            PauseBetweenBusyRetries = TimeSpan.FromMilliseconds(500);
#if DEBUG
            if (Debugger.IsAttached)
            {
                PauseBetweenTableCreationRetries  = PauseBetweenTableCreationRetries.Multiply(100);
                PauseBetweenTableOperationRetries = PauseBetweenTableOperationRetries.Multiply(100);
                PauseBetweenBusyRetries           = PauseBetweenBusyRetries.Multiply(10);
            }
#endif
            TableCreationRetryPolicy = RetryPolicies.Retry(MaxTableCreationRetries, PauseBetweenTableCreationRetries);    // 60 x 1s
            TableCreationTimeout     = PauseBetweenTableCreationRetries.Multiply(MaxTableCreationRetries).Multiply(3);    // 3 min

            TableOperationRetryPolicy = RetryPolicies.Retry(MaxTableOperationRetries, PauseBetweenTableOperationRetries); // 5 x 100ms
            TableOperationTimeout     = PauseBetweenTableOperationRetries.Multiply(MaxTableOperationRetries).Multiply(6); // 3 sec

            BusyRetriesTimeout = PauseBetweenBusyRetries.Multiply(MaxBusyRetries);                                        // 1 minute
        }
        public AzureFilesBlobContainer()
        {
            _log   = ClassLogger.Create(GetType());
            _dblog = DebugOnlyLogger.Create(_log);

            var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);

            _containerName = config[BlobContainerLocalConfig.ContainerName];
            EntityAccess access = (EntityAccess)Enum.Parse(typeof(EntityAccess),
                                                           config.Get(BlobContainerLocalConfig.OptionalAccess,
                                                                      EntityAccess.Private.ToString()));

            _contentType = config.Get(BlobContainerLocalConfig.OptionalContentType, "application/raw");

            _account = Client.FromConfig();
            _client  = _account.CreateCloudBlobClient();

            _client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5));

            var blobContainerPermissions = new BlobContainerPermissions
            {
                PublicAccess = AzureEntityAccessTranslator.Translate(access)
            };

            _blobContainerPermissions = blobContainerPermissions;
            _container = _client.GetContainerReference(_containerName.ToLowerInvariant());

            if (_container.CreateIfNotExist())
            {
                _container.SetPermissions(_blobContainerPermissions);
            }
        }
Exemplo n.º 27
0
        // Constructor - pass in a storage connection string.

        public BlobHelper(string connectionString)
        {
            Account = CloudStorageAccount.Parse(connectionString);

            BlobClient             = Account.CreateCloudBlobClient();
            BlobClient.RetryPolicy = RetryPolicies.Retry(4, TimeSpan.Zero);
        }
Exemplo n.º 28
0
        public static void Initialize()
        {
            CloudStorageAccount account = CloudConfiguration.GetStorageAccount(AzureConnectionStrings.DataConnection);

            // Tables
            var cloudTableClient = new CloudTableClient(account.TableEndpoint.ToString(), account.Credentials);

            cloudTableClient.CreateTableIfNotExist <ExpenseExpenseItemEntity>(AzureStorageNames.ExpenseTable);
            cloudTableClient.CreateTableIfNotExist <ExpenseExportEntity>(AzureStorageNames.ExpenseExportTable);

            // Blobs
            CloudBlobClient client = account.CreateCloudBlobClient();

            client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5));
            var container = client.GetContainerReference(AzureStorageNames.ReceiptContainerName);

            container.CreateIfNotExist();
            container = client.GetContainerReference(AzureStorageNames.ExpenseExportContainerName);
            container.CreateIfNotExist();

            // Queues
            CloudQueueClient queueClient = account.CreateCloudQueueClient();

            queueClient.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5));
            CloudQueue queueReference = queueClient.GetQueueReference(AzureStorageNames.ApprovedExpenseMessage);

            queueReference.CreateIfNotExist();
            queueReference = queueClient.GetQueueReference(AzureStorageNames.PoisonApprovedExpenseMessage);
            queueReference.CreateIfNotExist();
            queueReference = queueClient.GetQueueReference(AzureStorageNames.NewReceiptMessage);
            queueReference.CreateIfNotExist();
            queueReference = queueClient.GetQueueReference(AzureStorageNames.PoisonNewReceiptMessage);
            queueReference.CreateIfNotExist();
        }
        public WindowsAzureStorageHelper()
        {
            ContainerName = CONTAINER_NAME;
            // Open blob storage.

            StorageAccountInfo          = StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration();
            BlobStorageType             = BlobStorage.Create(StorageAccountInfo);
            BlobStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100));

            // Open queue storage.

            StorageAccountInfo queueAccount = StorageAccountInfo.GetDefaultQueueStorageAccountFromConfiguration();

            QueueStorageType             = QueueStorage.Create(queueAccount);
            QueueStorageType             = QueueStorage.Create(queueAccount);
            QueueStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100));

            // Open table storage.

            StorageAccountInfo tableAccount = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();

            TableStorageType             = TableStorage.Create(tableAccount);
            TableStorageType             = TableStorage.Create(tableAccount);
            TableStorageType.RetryPolicy = RetryPolicies.RetryN(2, TimeSpan.FromMilliseconds(100));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Checks a package in Blob Storage against any previous package receipt
        /// to determine whether to reinstall it
        /// </summary>
        private static bool IsNewPackage(string containerName, string packageName, string packageReceiptFile)
        {
            var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(DATA_CONNECTION_STRING));

            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            blobClient.RetryPolicy = RetryPolicies.Retry(100, TimeSpan.FromSeconds(1));
            blobClient.Timeout     = TimeSpan.FromSeconds(600);

            CloudBlobContainer container = blobClient.GetContainerReference(containerName);
            CloudBlockBlob     blob      = container.GetBlockBlobReference(packageName);

            blob.FetchAttributes();
            DateTime blobTimeStamp = blob.Attributes.Properties.LastModifiedUtc;

            DateTime fileTimeStamp = File.GetCreationTimeUtc(packageReceiptFile);

            if (fileTimeStamp.CompareTo(blobTimeStamp) < 0)
            {
                Console.WriteLine(string.Format("{0} is new or not yet installed.", packageName), "Information");
                return(true);
            }
            else
            {
                Console.WriteLine(string.Format("{0} has previously been installed, skipping download.", packageName), "Information");
                return(false);
            }
        }