Esempio n. 1
0
        public async Task <bool> Deploy(TestJob testJob)
        {
            Messenger.Default.Send($"{DateTime.Now.ToString("T")} - Deploy {testJob.BatchJobId}", "RunningLog");

            BatchSharedKeyCredentials credentials = new BatchSharedKeyCredentials(BatchServiceUrl, BatchAccountName, BatchAccountKey);

            using (BatchClient batchClient = await BatchClient.OpenAsync(credentials))
            {
                batchClient.CustomBehaviors.Add(RetryPolicyProvider.LinearRetryProvider(TimeSpan.FromSeconds(10), 3));

                try
                {
                    Messenger.Default.Send($"{DateTime.Now.ToString("T")} - Create Pool ({testJob.NumofVm} core)", "RunningLog");
                    await CreatePoolIfNotExistAsync(batchClient, StorageAccount, testJob);

                    Messenger.Default.Send(
                        new DeployStatusUpdateMessage()
                    {
                        Phase  = DeployPhase.PoolCreated,
                        Status = PhaseStatus.Succeeded
                    }, "DeployStatus");
                }
                catch (Exception ex)
                {
                    Messenger.Default.Send($"{DateTime.Now.ToString("T")} - delete test due to {ex.Message}", "RunningLog");
                    Messenger.Default.Send(
                        new DeployStatusUpdateMessage()
                    {
                        Phase  = DeployPhase.PoolCreated,
                        Status = PhaseStatus.Failed
                    }, "DeployStatus");
                    await batchClient.DeleteTest(testJob);
                }
                try
                {
                    Messenger.Default.Send($"{DateTime.Now.ToString("T")} - Submit job", "RunningLog");
                    await SubmitJobIfNotExistAsync(batchClient, StorageAccount, testJob);

                    Messenger.Default.Send(
                        new DeployStatusUpdateMessage()
                    {
                        Phase  = DeployPhase.JobCreated,
                        Status = PhaseStatus.Succeeded
                    }, "DeployStatus");
                }
                catch (Exception ex)
                {
                    Messenger.Default.Send($"{DateTime.Now.ToString("T")} - delete test due to {ex.Message}", "RunningLog");
                    Messenger.Default.Send(
                        new DeployStatusUpdateMessage()
                    {
                        Phase  = DeployPhase.JobCreated,
                        Status = PhaseStatus.Failed
                    }, "DeployStatus");
                    await batchClient.DeleteTest(testJob);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public async Task <bool> DeleteTest(TestJob testJob)
        {
            BatchSharedKeyCredentials credentials = new BatchSharedKeyCredentials(BatchServiceUrl, BatchAccountName, BatchAccountKey);

            using (BatchClient batchClient = await BatchClient.OpenAsync(credentials))
            {
                return(await batchClient.DeleteTest(testJob));
            }
        }