예제 #1
0
        /// <summary>
        /// Initialises the uploader and batch client. Asks user for an Azure licence file and saves the credentials
        /// if the credentials have not previously been set.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetCredentials(object sender, EventArgs e)
        {
            if (AzureCredentialsSetup.CredentialsExist())
            {
                // store credentials
                storageAuth = StorageCredentials.FromConfiguration();
                batchAuth   = BatchCredentials.FromConfiguration();

                storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAuth.Account, storageAuth.Key), true);
                uploader       = new FileUploader(storageAccount);
                var sharedCredentials = new Microsoft.Azure.Batch.Auth.BatchSharedKeyCredentials(batchAuth.Url, batchAuth.Account, batchAuth.Key);
                try
                {
                    batchCli = BatchClient.Open(sharedCredentials);
                }
                catch (UriFormatException)
                {
                    ShowErrorMessage("Error opening Azure Batch client: credentials are invalid.");
                    AzureCredentialsSetup cred = new AzureCredentialsSetup();
                    cred.Finished += GetCredentials;
                }
                catch (Exception ex)
                {
                    ShowError(ex);
                }
            }
            else
            {
                // ask user for a credentials file
                AzureCredentialsSetup cred = new AzureCredentialsSetup();
                cred.Finished += GetCredentials;
            }
        }
        /// <summary>
        /// Initialises the Azure credentials, batch client and blob client. Asks user for an Azure
        /// licence file and saves the credentials if the credentials have not previously been set.
        /// Once credentials are saved, it starts the job load worker.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void GetCredentials()
        {
            if (AzureCredentialsSetup.CredentialsExist())
            {
                // store credentials
                storageAuth = StorageCredentials.FromConfiguration();
                batchAuth   = BatchCredentials.FromConfiguration();

                storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAuth.Account, storageAuth.Key), true);
                var sharedCredentials = new Microsoft.Azure.Batch.Auth.BatchSharedKeyCredentials(batchAuth.Url, batchAuth.Account, batchAuth.Key);
                batchCli = BatchClient.Open(sharedCredentials);

                blobCli = storageAccount.CreateCloudBlobClient();
                blobCli.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(3), 10);

                if (!fetchJobs.IsBusy)
                {
                    fetchJobs.RunWorkerAsync();
                }
            }
            else
            {
                // ask user for a credentials file
                AzureCredentialsSetup cred = new AzureCredentialsSetup();
                cred.Finished += (sender, e) => GetCredentials();
            }
        }
예제 #3
0
        public BatchService(BatchSharedKeyCredential credentials)
        {
            this.Client      = BatchClient.Open(credentials);
            this.Credentials = credentials;
            this.retryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(5), 3);

            this.Client.CustomBehaviors.Add(new RetryPolicyProvider(this.retryPolicy));
        }
예제 #4
0
        public BatchService(BatchSharedKeyCredential credentials)
        {
            this.Client = BatchClient.Open(credentials);
            this.Credentials = credentials;
            this.retryPolicy = new LinearRetry(TimeSpan.FromSeconds(10), 5);

            this.Client.CustomBehaviors.Add(new RetryPolicyProvider(this.retryPolicy));
        }
예제 #5
0
 public RetryPolicyUnitTests(ITestOutputHelper testOutputHelper)
 {
     this.testOutputHelper = testOutputHelper;
     this.credentials      = new Microsoft.Azure.Batch.Auth.BatchSharedKeyCredentials(
         ClientUnitTestCommon.DummyBaseUrl,
         ClientUnitTestCommon.DummyAccountName,
         ClientUnitTestCommon.DummyAccountKey);
 }
예제 #6
0
        public AzureBatchService(
            [Parameter(typeof(AzureBatchAccountUri))] string azureBatchAccountUri,
            [Parameter(typeof(AzureBatchAccountName))] string azureBatchAccountName,
            [Parameter(typeof(AzureBatchAccountKey))] string azureBatchAccountKey,
            [Parameter(typeof(AzureBatchPoolId))] string azureBatchPoolId)
        {
            BatchSharedKeyCredential credentials = new BatchSharedKeyCredential(azureBatchAccountUri, azureBatchAccountName, azureBatchAccountKey);

            this.Client      = BatchClient.Open(credentials);
            this.Credentials = credentials;
            this.PoolId      = azureBatchPoolId;
            this.Client.CustomBehaviors.Add(new RetryPolicyProvider(new ExponentialRetry(RetryDeltaBackOff, MaxRetries)));
        }
예제 #7
0
        public AzureBatchService(
            ContainerRegistryProvider containerRegistryProvider,
            ICommandBuilder commandBuilder,
            [Parameter(typeof(AzureBatchAccountUri))] string azureBatchAccountUri,
            [Parameter(typeof(AzureBatchAccountName))] string azureBatchAccountName,
            [Parameter(typeof(AzureBatchAccountKey))] string azureBatchAccountKey,
            [Parameter(typeof(AzureBatchPoolId))] string azureBatchPoolId,
            [Parameter(typeof(AzureBatchPoolDriverPortsList))] IList <string> ports)
        {
            BatchSharedKeyCredential credentials =
                new BatchSharedKeyCredential(azureBatchAccountUri, azureBatchAccountName, azureBatchAccountKey);

            Ports       = ports;
            Client      = BatchClient.Open(credentials);
            Credentials = credentials;
            PoolId      = azureBatchPoolId;
            ContainerRegistryProvider = containerRegistryProvider;
            Client.CustomBehaviors.Add(new RetryPolicyProvider(new ExponentialRetry(RetryDeltaBackOff, MaxRetries)));
            CommandBuilder = commandBuilder;
        }
예제 #8
0
        /// <summary>
        /// Constructor. Requires Azure credentials to already be set in ApsimNG.Properties.Settings.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="jobName"></param>
        /// <param name="path"></param>
        /// <param name="explorer"></param>
        /// <param name="export"></param>
        /// <param name="includeDebugFiles"></param>
        /// <param name="keepOutputFiles"></param>
        public AzureResultsDownloader(Guid id, string jobName, string path, AzureJobDisplayPresenter explorer, bool getResults, bool export, bool includeDebugFiles, bool keepOutputFiles, bool unzipResultFiles)
        {
            numBlobsComplete   = 0;
            jobId              = id;
            downloadResults    = getResults;
            exportToCsv        = export;
            saveDebugFiles     = includeDebugFiles;
            saveRawOutputFiles = keepOutputFiles;
            outputPath         = path;
            rawResultsPath     = outputPath + "\\" + jobName.ToString() + "_Results";
            tempPath           = Path.GetTempPath() + "\\" + jobId;
            progressMutex      = new object();
            dbMutex            = new object();
            presenter          = explorer;
            unzipResults       = unzipResultFiles;
            try
            {
                // if we need to save files, create a directory under the output directory
                if ((saveDebugFiles || saveRawOutputFiles || exportToCsv) && !Directory.Exists(rawResultsPath))
                {
                    Directory.CreateDirectory(rawResultsPath);
                }
            }
            catch (Exception err)
            {
                presenter.ShowError(err);
                return;
            }

            name = jobName;
            StorageCredentials storageCredentials = StorageCredentials.FromConfiguration();
            BatchCredentials   batchCredentials   = BatchCredentials.FromConfiguration();

            storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageCredentials.Account, storageCredentials.Key), true);
            var sharedCredentials = new Microsoft.Azure.Batch.Auth.BatchSharedKeyCredentials(batchCredentials.Url, batchCredentials.Account, batchCredentials.Key);

            batchClient = BatchClient.Open(sharedCredentials);
            blobClient  = storageAccount.CreateCloudBlobClient();
            blobClient.DefaultRequestOptions.RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(3), 10);
        }
 public RetryPolicyUnitTests(ITestOutputHelper testOutputHelper)
 {
     this.testOutputHelper = testOutputHelper;
     this.credentials      = ClientUnitTestCommon.CreateDummySharedKeyCredential();
 }