Пример #1
0
        public async Task CheckListApplicationSummariesIsReturningAValidList()
        {
            const string applicationId = "blender.exe";
            const string displayName   = "blender";

            IList <string> versions = new[] { "1.0", "1.5" };

            BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential();

            using (BatchClient client = await BatchClient.OpenAsync(credentials))
            {
                Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(baseRequest =>
                {
                    var request = (Protocol.BatchRequest <Models.ApplicationListOptions, AzureOperationResponse <IPage <Models.ApplicationSummary>, Models.ApplicationListHeaders> >)baseRequest;

                    request.ServiceRequestFunc = (token) =>
                    {
                        var response = new AzureOperationResponse <IPage <Models.ApplicationSummary>, Models.ApplicationListHeaders>
                        {
                            Body = new FakePage <Models.ApplicationSummary>(new[]
                            {
                                new Models.ApplicationSummary
                                {
                                    Id          = applicationId,
                                    DisplayName = displayName,
                                    Versions    = versions
                                },
                            })
                        };

                        return(Task.FromResult(response));
                    };
                });

                IPagedEnumerable <Microsoft.Azure.Batch.ApplicationSummary> applicationSummaries = client.ApplicationOperations.ListApplicationSummaries(additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });

                Assert.Equal(1, applicationSummaries.Count());

                var applicationSummary = applicationSummaries.First();
                Assert.Equal(applicationId, applicationSummary.Id);
                Assert.Equal(displayName, applicationSummary.DisplayName);
                Assert.Equal(versions.First(), applicationSummary.Versions.First());
                Assert.Equal(versions.Count, applicationSummary.Versions.ToList().Count);
            }
        }
        public void ListRows()
        {
            string projectId = _fixture.ProjectId;
            string datasetId = _fixture.GameDatasetId;
            string tableId   = _fixture.HistoryTableId;

            // Snippet: ListRows
            BigqueryClient client = BigqueryClient.Create(projectId);
            BigqueryTable  table  = client.GetTable(datasetId, tableId);
            IPagedEnumerable <TableDataList, BigqueryRow> result = table.ListRows();

            foreach (BigqueryRow row in result)
            {
                DateTime timestamp = (DateTime)row["game_started"];
                long     level     = (long)row["level"];
                long     score     = (long)row["score"];
                string   player    = (string)row["player"];
                Console.WriteLine($"{player}: {level}/{score} ({timestamp:yyyy-MM-dd HH:mm:ss})");
            }
            // End snippet

            // We set up 7 results in the fixture. Other tests may add more.
            Assert.True(result.Count() >= 7);
        }
Пример #3
0
        /// <summary>
        /// Gets the list of jobs submitted to Azure.
        /// </summary>
        /// <returns>List of Jobs. Null if the thread is asked to cancel, or if unable to update the progress bar.</returns>
        private List <JobDetails> ListJobs()
        {
            try
            {
                view.ShowLoadingProgressBar();
                view.JobLoadProgress = 0;
            } catch (NullReferenceException)
            {
                return(null);
            } catch (Exception e)
            {
                ShowError(e.ToString());
            }

            List <JobDetails> jobs = new List <JobDetails>();
            var pools          = batchClient.PoolOperations.ListPools();
            var jobDetailLevel = new ODATADetailLevel {
                SelectClause = "id,displayName,state,executionInfo,stats", ExpandClause = "stats"
            };

            IPagedEnumerable <CloudJob> cloudJobs = null;

            // Attempt to download raw job list. If this fails more than 3 times, return.
            int numTries = 0;

            while (numTries < 4 && cloudJobs == null)
            {
                try
                {
                    cloudJobs = batchClient.JobOperations.ListJobs(jobDetailLevel);
                }
                catch (Exception e)
                {
                    if (numTries >= 3)
                    {
                        ShowError("Unable to retrieve job list: " + e.ToString());
                        return(new List <JobDetails>());
                    }
                } finally
                {
                    numTries++;
                }
            }

            // Parse jobs into a list of JobDetails objects.

            var length = cloudJobs.Count();
            int i      = 0;

            foreach (var cloudJob in cloudJobs)
            {
                if (FetchJobs.CancellationPending)
                {
                    return(null);
                }
                try
                {
                    view.JobLoadProgress = 100.0 * i / length;
                } catch (NullReferenceException)
                {
                    return(null);
                } catch (Exception e)
                {
                    ShowError(e.ToString());
                }

                string owner = GetAzureMetaData("job-" + cloudJob.Id, "Owner");

                long   numTasks    = 1;
                double jobProgress = 0;
                try
                {
                    TaskCounts tasks = batchClient.JobOperations.GetJobTaskCounts(cloudJob.Id);
                    numTasks = tasks.Active + tasks.Running + tasks.Completed;
                    // if there are no tasks, set progress to 100%
                    jobProgress = numTasks == 0 ? 100 : 100.0 * tasks.Completed / numTasks;
                } catch (Exception e)
                {
                    // sometimes an exception is thrown when retrieving the task counts
                    // could be due to the job not being submitted correctly
                    ShowError(e.ToString());

                    numTasks    = -1;
                    jobProgress = 100;
                }

                // if cpu time is unavailable, set this field to 0
                TimeSpan cpu = cloudJob.Statistics == null ? TimeSpan.Zero : cloudJob.Statistics.KernelCpuTime + cloudJob.Statistics.UserCpuTime;
                var      job = new JobDetails
                {
                    Id          = cloudJob.Id,
                    DisplayName = cloudJob.DisplayName,
                    State       = cloudJob.State.ToString(),
                    Owner       = owner,
                    NumSims     = numTasks - 1, // subtract one because one of these is the job manager
                    Progress    = jobProgress,
                    CpuTime     = cpu
                };

                if (cloudJob.ExecutionInformation != null)
                {
                    job.StartTime = cloudJob.ExecutionInformation.StartTime;
                    job.EndTime   = cloudJob.ExecutionInformation.EndTime;
                }
                jobs.Add(job);
                i++;
            }
            view.HideLoadingProgressBar();
            if (jobs == null)
            {
                return(new List <JobDetails>());
            }
            return(jobs);
        }