示例#1
0
        async Task DeployAndStartStressLoad(IConfigurationProvider provider)
        {
            try
            {
                var     devicePerVm = int.Parse(provider.GetConfigValue("DevicePerVm"));
                var     numofVM     = int.Parse(provider.GetConfigValue("NumofVm"));
                TestJob job         = new TestJob
                {
                    JobId                = DateTime.UtcNow.Ticks,
                    ConfigureProvider    = provider,
                    DevicePerVm          = devicePerVm,
                    Message              = provider.GetConfigValue("Message"),
                    Transport            = provider.GetConfigValue("Transport"),
                    MessagePerMin        = int.Parse(provider.GetConfigValue("MessagePerMin")),
                    NumofVm              = numofVM,
                    SizeOfVM             = (VmSize)Enum.Parse(typeof(VmSize), provider.GetConfigValue("SizeOfVM")),
                    DeviceClientEndpoint = provider.GetConfigValue("DeviceClientEndpoint"),
                    DurationInMin        = int.Parse(provider.GetConfigValue("DurationInMin"))
                };
                var batch = new BatchConnector(provider);
                BatchHelper.Connector = batch;
                await job.Deploy();

                //StartRead();
                await job.DeleteTest();
            }
            catch (Exception e)
            {
                Messenger.Default.Send($"Terminated Due to error '{e.Message}', please check all your inputs are correct.", "RunningLog");
            }
        }
示例#2
0
        public BatchConnector(IConfigurationProvider provider = null)
        {
            configurationProvider = provider == null ? new InternalProvider() : provider;

            BatchServiceUrl = configurationProvider.GetConfigValue("BatchServiceUrl");

            var builder = new UriBuilder(BatchServiceUrl);

            BatchAccountName = builder.Host.Split('.').First();
            BatchAccountKey  = configurationProvider.GetConfigValue("BatchAccountKey");

            StorageConnectionString = configurationProvider.GetConfigValue("StorageConnectionString");
            StorageAccount          = CloudStorageAccount.Parse(StorageConnectionString);

            BatchOsSize = configurationProvider.GetConfigValue("SizeOfVM");
        }
        public static string GetBatchJobId(long jobId, IConfigurationProvider provider = null)
        {
            provider = provider ?? new ConfigurationProvider();
            var jobid = string.Format(provider.GetConfigValue("DeviceIdPrefix") + jobId.ToString());

            Messenger.Default.Send(jobid, "BatchJobId");
            return(jobid);
        }
示例#4
0
        /// <summary>
        /// Creates a job and adds a task to it. The task is a
        /// custom executable which has a resource file associated with it.
        /// </summary>
        /// <param name="batchClient">The BatchClient to use when interacting with the Batch service.</param>
        /// <param name="cloudStorageAccount">The storage account to upload the files to.</param>
        /// <param name="jobId">The ID of the job.</param>
        /// <returns>The set of container names containing the jobs input files.</returns>
        private async Task <bool> SubmitJobIfNotExistAsync(BatchClient batchClient, CloudStorageAccount cloudStorageAccount, TestJob testJob)
        {
            CloudJob batchJob = batchClient.JobOperations.CreateJob();

            batchJob.Id = testJob.BatchJobId;
            batchJob.PoolInformation = new PoolInformation()
            {
                PoolId = TestJob.BatchPoolId
            };

            bool jobExists = false;

            try
            {
                await batchJob.CommitAsync();
            }
            catch (BatchException e)
            {
                if (e.RequestInformation != null &&
                    e.RequestInformation.BatchError != null &&
                    e.RequestInformation.BatchError.Code == BatchErrorCodeStrings.JobExists)
                {
                    jobExists = true;
                }
                else
                {
                    throw;
                }
            }

            if (jobExists)
            {
                // check whether task are there
                var job = await batchClient.JobOperations.GetJobAsync(testJob.BatchJobId);

                if (job != null && job.ListTasks().Count() > 0)
                {
                    return(true);
                }
            }

            var tasksToRun = new List <CloudTask>();

            Messenger.Default.Send($"{DateTime.Now.ToString("T")} - Upload assemblies for batch", "RunningLog");

            Console.WriteLine($"{DateTime.Now.ToString("T")} - Upload assemblies for batch");
            var resourceFiles = await UploadFilesToContainerAsync(cloudStorageAccount);

            Messenger.Default.Send(
                new DeployStatusUpdateMessage()
            {
                Phase  = DeployPhase.AssemblyUploaded,
                Status = PhaseStatus.Succeeded
            },
                "DeployStatus"
                );
            var jobsPerVm = 4 * (int)Math.Pow(2, (int)testJob.SizeOfVM);

            for (int i = 0; i < jobsPerVm * testJob.NumofVm; i++)
            {
                if (string.IsNullOrEmpty(testJob.Message))
                {
                    testJob.Message = string.Empty;
                }

                var command = string.Format("DeviceLoad.exe {0} {1} {2} {3} {4} {5} {6}-{7} \"{8}\" {9}",
                                            StorageConnectionString,
                                            testJob.DeviceClientEndpoint,
                                            testJob.DevicePerVm / jobsPerVm,
                                            testJob.MessagePerMin,
                                            testJob.DurationInMin,
                                            testJob.BatchJobId,
                                            configurationProvider.GetConfigValue("DeviceIdPrefix"),
                                            i.ToString().PadLeft(4, '0'),
                                            testJob.Message.Replace("\"", "\\\""),
                                            testJob.Transport);

                CloudTask taskWithFiles = new CloudTask("deviceTest" + i, command);
                taskWithFiles.ResourceFiles = resourceFiles;
                await batchClient.JobOperations.AddTaskAsync(testJob.BatchJobId, taskWithFiles);
            }

            return(true);
        }