public void StatusShallRunThrough()
        {
            var mockClient = new Mock <IJobsClient>();
            var mockLogger = new Mock <ILogger <ClaraJobsApi> >();

            var jobId   = Guid.NewGuid().ToString("N");
            var jobDate = DateTime.UtcNow;

            JobId.TryParse(jobId, out JobId jobIdObj);

            mockClient.Setup(p => p.GetStatus(It.IsAny <JobId>()))
            .ReturnsAsync(new JobDetails
            {
                JobId       = jobIdObj,
                JobState    = JobState.Pending,
                JobStatus   = Nvidia.Clara.Platform.JobStatus.Healthy,
                DateCreated = jobDate,
                DateStarted = jobDate,
                DateStopped = jobDate,
                JobPriority = JobPriority.Higher,
                Name        = "name"
            });

            var service = new ClaraJobsApi(
                mockClient.Object, mockLogger.Object);

            service.Status(jobId).Wait();

            mockClient.Verify(
                p => p.GetStatus(It.IsAny <JobId>()),
                Times.Exactly(1));

            mockLogger.VerifyLogging(LogLevel.Error, Times.Never());
            mockLogger.VerifyLogging(LogLevel.Information, Times.Once());
        }
Exemplo n.º 2
0
 public void Single()
 {
     RunAll(EqualityUnit
            .Create(new JobId("test"))
            .WithEqualValues(new JobId("test"), JobId.ParseName("test"))
            .WithNotEqualValues(new JobId("test2"), JobId.Root));
 }
Exemplo n.º 3
0
            /// <exception cref="System.IO.IOException"/>
            private Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job VerifyAndGetJob(JobId jobID, bool
                                                                               exceptionThrow)
            {
                UserGroupInformation loginUgi = null;

                Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = null;
                try
                {
                    loginUgi = UserGroupInformation.GetLoginUser();
                    job      = loginUgi.DoAs(new _PrivilegedExceptionAction_205(this, jobID));
                }
                catch (Exception e)
                {
                    throw new IOException(e);
                }
                if (job == null && exceptionThrow)
                {
                    throw new IOException("Unknown Job " + jobID);
                }
                if (job != null)
                {
                    JobACL operation = JobACL.ViewJob;
                    this.CheckAccess(job, operation);
                }
                return(job);
            }
        public void AddMetadata_ShallRunThrough()
        {
            var mockClient = new Mock <IJobsClient>();
            var mockLogger = new Mock <ILogger <ClaraJobsApi> >();

            var jobId   = Guid.NewGuid().ToString("N");
            var jobDate = DateTime.UtcNow;

            JobId.TryParse(jobId, out JobId jobIdObj);

            mockClient.Setup(p => p.AddMetadata(It.IsAny <JobId>(), It.IsAny <Dictionary <string, string> >()));

            var service = new ClaraJobsApi(
                mockClient.Object, mockLogger.Object);

            var job = new Job
            {
                JobId     = Guid.NewGuid().ToString("N"),
                PayloadId = Guid.NewGuid().ToString("N")
            };

            service.AddMetadata(job, new Dictionary <string, string>()).Wait();

            mockClient.Verify(
                p => p.AddMetadata(It.IsAny <JobId>(), It.IsAny <Dictionary <string, string> >()),
                Times.Exactly(1));

            mockLogger.VerifyLogging(LogLevel.Error, Times.Never());
            mockLogger.VerifyLogging(LogLevel.Information, Times.Once());
        }
Exemplo n.º 5
0
        public bool IsValidCustomFieldIdList(JobId jobId, IList <CustomFieldTypeId> customFieldTypeIds)
        {
            var job             = jobRep.GetById(jobId);
            var customFieldList = customFieldRep.Find(customFieldTypeIds);

            return(job.IsValidCustomFields(customFieldList));
        }
Exemplo n.º 6
0
        private static async Task Test()
        {
            var account     = GetStorageAccount();
            var tableClient = account.CreateCloudTableClient();
            var table       = tableClient.GetTableReference(AzureConstants.TableNames.BuildResultDate);
            var query       = new TableQuery <DynamicTableEntity>()
                              .Where(FilterUtil.SinceDate(ColumnNames.PartitionKey, DateTimeOffset.UtcNow - TimeSpan.FromDays(2)))
                              .Select(new[] { "JobName" });
            var nameSet = new HashSet <string>();
            var kindSet = new HashSet <string>();

            foreach (var entity in table.ExecuteQuery(query))
            {
                var name = entity["JobName"].StringValue;
                if (nameSet.Add(name))
                {
                    var id = JobId.ParseName(name);
                    try
                    {
                        var client = CreateClient(id);
                        var kind   = await client.GetJobKindAsync(id);

                        if (kindSet.Add(kind))
                        {
                            Console.WriteLine(kind);
                        }
                    }
                    catch
                    {
                        // Ignore
                    }
                }
            }
        }
Exemplo n.º 7
0
 public Job AddJob(string jobName, string dictionaryName, List <CustomFieldTypeId> customFieldTypeIdList, Guid transferId)
 {
     try
     {
         using (var scope = new TransactionScope())
         {
             JobId jobId = jobRep.GetNextId();
             var   job   = new Job(jobId, jobName, dictionaryName);
             job.TransferId = transferId;
             assignJobCustomField(job, customFieldTypeIdList);
             jobRep.AddJob(job);
             scope.Complete();
             return(job);
         }
     }
     catch (Exception exp)
     {
         var res = jobRep.TryConvertException(exp);
         if (res == null)
         {
             throw;
         }
         throw res;
     }
 }
Exemplo n.º 8
0
 public void Nested()
 {
     RunAll(EqualityUnit
            .Create(new JobId("test", new JobId("op")))
            .WithEqualValues(new JobId("test", new JobId("op")), JobId.ParseName("op/test"))
            .WithNotEqualValues(new JobId("test"), JobId.Root, new JobId("op")));
 }
Exemplo n.º 9
0
        private List <JobQueueSummary> GetJobSummaryList(JobId jobId, int count)
        {
            var list   = new List <JobQueueSummary>();
            var client = ControllerUtil.CreateJenkinsClient();

            foreach (var id in client.GetBuildIds(jobId).Take(count))
            {
                var state = client.GetBuildInfo(id).State;
                if (state == BuildState.Running)
                {
                    continue;
                }

                var time = client.GetTimeInQueue(id);
                if (time.HasValue)
                {
                    var summary = new JobQueueSummary()
                    {
                        Name      = jobId.Name,
                        Id        = id.Number,
                        QueueTime = time.Value
                    };
                    list.Add(summary);
                }
            }

            return(list.OrderBy(x => x.Id).ToList());
        }
Exemplo n.º 10
0
        public static string JobToString(JobId id)
        {
            string result;
            if (!sIdToJobs.TryGetValue(id, out result)) return null;

            return result;
        }
Exemplo n.º 11
0
        public void CreateTextJob()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    content = Content.TEXT;
                    api     = ReviewAPI.JOB_CREATE;
                    HttpMockServer.Initialize("ReviewAPIs", "CreateTextJob");
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetReviewResponse(client, api, content, MIMETypes.JSON.GetDescription(), teamName, "Public", Workflow.TEXT_WORKFLOW.GetDescription(), content.GetDescription() + " Review");

                    var job = results.CreateJob;
                    Assert.NotNull(job);
                    Assert.Equal(HttpStatusCode.OK, job.Response.StatusCode);
                    Job = job.Body;
                    Assert.NotNull(Job);
                    Assert.NotNull(Job.JobIdProperty);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 12
0
            private void TestAll(JobId id, string name)
            {
                var other = JobId.ParseName(name);

                Assert.Equal(id, other);
                Assert.Equal(id.Name, name);
            }
        public async Task Ack_ValidInformation_StampsAcknowledgmentReturnsPositiveResult()
        {
            var exampleQueueName = QueueId.Parse("ExampleQueue");

            var readyJobId = JobId.Generate();

            var existingJobs = new[]
            {
                new Job
                {
                    Id      = readyJobId,
                    QueueId = exampleQueueName
                }
            };

            var exampleAck = new JobAcknowledgment
            {
                { "RunnerId", Guid.NewGuid().ToString("N") }
            };

            await RunInMongoLand(async database =>
            {
                var jobs = database.GetJobCollection();
                await jobs.InsertManyAsync(existingJobs).ConfigureAwait(false);

                var sut    = new MongoJobAcknowledgmentService(database);
                var result = await sut.Ack(exampleQueueName, readyJobId, exampleAck).ConfigureAwait(false);

                var jobWeExpectToHaveBeenAcknowledged = await jobs.Find(Builders <Job> .Filter.Eq(x => x.Id, readyJobId)).FirstAsync().ConfigureAwait(false);

                Assert.That(result?.Success, Is.True);
                Assert.That(jobWeExpectToHaveBeenAcknowledged.Acknowledgment, Is.EqualTo(exampleAck));
                Assert.That(jobWeExpectToHaveBeenAcknowledged.Acknowledgment["RunnerId"], Is.EqualTo(exampleAck["RunnerId"]));
            }).ConfigureAwait(false);
        }
        /// <summary>
        /// Trivial test case that verifies basic functionality of
        /// <see cref="JobIdHistoryFileInfoMap"/>
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestWithSingleElement()
        {
            HistoryFileManager.JobIdHistoryFileInfoMap mapWithSize = new HistoryFileManager.JobIdHistoryFileInfoMap
                                                                         ();
            JobId jobId = MRBuilderUtils.NewJobId(1, 1, 1);

            HistoryFileManager.HistoryFileInfo fileInfo1 = Org.Mockito.Mockito.Mock <HistoryFileManager.HistoryFileInfo
                                                                                     >();
            Org.Mockito.Mockito.When(fileInfo1.GetJobId()).ThenReturn(jobId);
            // add it twice
            NUnit.Framework.Assert.AreEqual("Incorrect return on putIfAbsent()", null, mapWithSize
                                            .PutIfAbsent(jobId, fileInfo1));
            NUnit.Framework.Assert.AreEqual("Incorrect return on putIfAbsent()", fileInfo1, mapWithSize
                                            .PutIfAbsent(jobId, fileInfo1));
            // check get()
            NUnit.Framework.Assert.AreEqual("Incorrect get()", fileInfo1, mapWithSize.Get(jobId
                                                                                          ));
            NUnit.Framework.Assert.IsTrue("Incorrect size()", CheckSize(mapWithSize, 1));
            // check navigableKeySet()
            NavigableSet <JobId> set = mapWithSize.NavigableKeySet();

            NUnit.Framework.Assert.AreEqual("Incorrect navigableKeySet()", 1, set.Count);
            NUnit.Framework.Assert.IsTrue("Incorrect navigableKeySet()", set.Contains(jobId));
            // check values()
            ICollection <HistoryFileManager.HistoryFileInfo> values = mapWithSize.Values();

            NUnit.Framework.Assert.AreEqual("Incorrect values()", 1, values.Count);
            NUnit.Framework.Assert.IsTrue("Incorrect values()", values.Contains(fileInfo1));
        }
Exemplo n.º 15
0
        public void ViewNameOther()
        {
            var buildId = new BuildId(42, JobId.ParseName("house/test"));
            var entity  = new BuildResultEntity(buildId, DateTimeOffset.UtcNow, TimeSpan.FromSeconds(1), "kind", "test", BuildResultClassification.Succeeded, null);

            Assert.Equal("house", entity.ViewName);
        }
Exemplo n.º 16
0
        private void AddDestination(int jobId)
        {
            DateTime lastUpdateDate = DateTime.Parse(Request.QueryString["LastUpdateDate"]);

            Facade.IJob facJob = new Facade.Job();

            // Define the trunk instruction.
            DateTime bookedDateTime = new DateTime(rdiArrivalDate.SelectedDate.Value.Year, rdiArrivalDate.SelectedDate.Value.Month, rdiArrivalDate.SelectedDate.Value.Day, rdiArrivalTime.SelectedDate.Value.Hour, rdiArrivalTime.SelectedDate.Value.Minute, 0);
            TimeSpan travellingTime = bookedDateTime.Subtract(CurrentJob.Instructions[CurrentJob.Instructions.Count - 1].PlannedDepartureDateTime);

            Entities.CustomPrincipal user   = (Entities.CustomPrincipal)Page.User;
            Entities.FacadeResult    result = facJob.AttachDestination(CurrentJob, ucPoint.PointID, chkDriver.Checked, chkVehicle.Checked, chkTrailer.Checked, travellingTime, true, user.IdentityId, user.UserName);

            if (result.Success)
            {
                Cache.Remove(jobEntityForJobId + JobId.ToString());
                this.ReturnValue = "refresh";
                this.Close();
            }
            else
            {
                infrigementDisplay.Infringements = result.Infringements;
                infrigementDisplay.DisplayInfringments();
            }
        }
Exemplo n.º 17
0
 /// <exception cref="System.IO.IOException"/>
 private static MockHistoryJobs.JobsPair Split(IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job
                                                            > mocked)
 {
     MockHistoryJobs.JobsPair ret = new MockHistoryJobs.JobsPair();
     ret.full    = Maps.NewHashMap();
     ret.partial = Maps.NewHashMap();
     foreach (KeyValuePair <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> entry in
              mocked)
     {
         JobId id = entry.Key;
         Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job j       = entry.Value;
         MockHistoryJobs.MockCompletedJob           mockJob = new MockHistoryJobs.MockCompletedJob(j
                                                                                                   );
         // use MockCompletedJob to set everything below to make sure
         // consistent with what history server would do
         ret.full[id] = mockJob;
         JobReport    report = mockJob.GetReport();
         JobIndexInfo info   = new JobIndexInfo(report.GetStartTime(), report.GetFinishTime(
                                                    ), mockJob.GetUserName(), mockJob.GetName(), id, mockJob.GetCompletedMaps(), mockJob
                                                .GetCompletedReduces(), mockJob.GetState().ToString());
         info.SetJobStartTime(report.GetStartTime());
         info.SetQueueName(mockJob.GetQueueName());
         ret.partial[id] = new PartialJob(info, id);
     }
     return(ret);
 }
Exemplo n.º 18
0
        public async Task Complete_ValidResult_Persists()
        {
            var exampleQueueId = QueueId.Parse(Guid.NewGuid().ToString("N"));
            var exampleJobId   = JobId.Generate();
            var exampleResult  = new JobResult {
                { "Datacenter", "PEN" }
            };

            Assert.That(exampleResult, Is.Not.Null);

            await RunInMongoLand(async database =>
            {
                var collection = database.GetJobCollection();
                collection.InsertOne(new Job {
                    QueueId = exampleQueueId, Id = exampleJobId
                });
                var sut = new MongoJobCompletionService(database);
                await sut.Complete(exampleQueueId, exampleJobId, exampleResult).ConfigureAwait(false);

                var result = await collection.Find(Builders <Job> .Filter.Empty).SingleAsync().ConfigureAwait(false);

                Assert.That(result.Result, Is.Not.Null);
                Assert.That(result.Result["Datacenter"], Is.EqualTo("PEN"));
            }).ConfigureAwait(false);
        }
Exemplo n.º 19
0
 /// <summary>
 /// Creates new instance
 /// </summary>
 /// <param name="jobId"></param>
 public Job(JobId jobId)
 {
     this.Id          = jobId;
     this.Circle      = Circle.First;
     this.SkillPoints = 0;
     this.Data        = ChannelServer.Instance.Data.JobDb.Find(jobId) ?? throw new ArgumentException($"Unknown job '{jobId}'.");
 }
Exemplo n.º 20
0
        public virtual void Update(Period period, Job job, Unit unit, JobPosition parent)
        {
            if (period == null || period.Id == null)
            {
                throw new ArgumentNullException("period");
            }
            period.CheckModifyingJobPosition();

            if (job == null || job.Id == null)
            {
                throw new ArgumentNullException("job");
            }
            if (unit == null || unit.Id == null)
            {
                throw new ArgumentNullException("unit");
            }


            if (!period.Id.Equals(job.Id.PeriodId))
            {
                throw new JobPositionCompareException("JobPosition", "Job", "Period");
            }

            if (!period.Id.Equals(unit.Id.PeriodId))
            {
                throw new JobPositionCompareException("JobPosition", "Unit", "Period");
            }

            this.parent = parent;
            unitId      = unit.Id;
            jobId       = job.Id;
        }
Exemplo n.º 21
0
        private JobSummary GetJobDaySummary(JobId jobId)
        {
            var client = ControllerUtil.CreateJenkinsClient();
            var all    = client.GetBuildInfoList(jobId).Where(x => x.State != BuildState.Running);
            var list   = new List <JobDaySummary>();

            foreach (var group in all.GroupBy(x => x.Date.Date))
            {
                var succeeded       = group.Count(x => x.State == BuildState.Succeeded);
                var failed          = group.Count(x => x.State == BuildState.Failed);
                var aborted         = group.Count(x => x.State == BuildState.Aborted);
                var averageDuration = TimeSpan.FromMilliseconds(group.Average(x => x.Duration.TotalMilliseconds));
                list.Add(new JobDaySummary()
                {
                    Name            = jobId.Name,
                    Date            = group.Key,
                    Succeeded       = succeeded,
                    Failed          = failed,
                    Aborted         = aborted,
                    AverageDuration = averageDuration
                });
            }

            return(new JobSummary()
            {
                Name = jobId.Name,
                AverageDuration = TimeSpan.FromMilliseconds(all.Average(x => x.Duration.TotalMilliseconds)),
                JobDaySummaryList = list
            });
        }
Exemplo n.º 22
0
        public override int GetHashCode()
        {
            int hash = 0;

            if (!string.IsNullOrWhiteSpace(AccessId))
            {
                hash ^= AccessId.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(DataSourceName))
            {
                hash ^= DataSourceName.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(EntityTypeName))
            {
                hash ^= EntityTypeName.GetHashCode();
            }

            if (!string.IsNullOrWhiteSpace(JobId))
            {
                hash ^= JobId.GetHashCode();
            }

            hash ^= IsActive.GetHashCode();
            hash ^= IsPublic.GetHashCode();
            hash ^= IsStaging.GetHashCode();

            return(hash);
        }
Exemplo n.º 23
0
        public static Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job NewJob(ApplicationId appID
                                                                        , int i, int n, int m, Path confFile, bool hasFailedTasks)
        {
            JobId     id     = NewJobID(appID, i);
            string    name   = NewJobName();
            JobReport report = NewJobReport(id);
            IDictionary <TaskId, Task> tasks = NewTasks(id, n, m, hasFailedTasks);

            MockJobs.TaskCount taskCount = GetTaskCount(tasks.Values);
            Counters           counters  = GetCounters(tasks.Values);
            Path configFile = confFile;
            IDictionary <JobACL, AccessControlList> tmpJobACLs = new Dictionary <JobACL, AccessControlList
                                                                                 >();
            Configuration conf = new Configuration();

            conf.Set(JobACL.ViewJob.GetAclName(), "testuser");
            conf.SetBoolean(MRConfig.MrAclsEnabled, true);
            JobACLsManager aclsManager = new JobACLsManager(conf);

            tmpJobACLs = aclsManager.ConstructJobACLs(conf);
            IDictionary <JobACL, AccessControlList> jobACLs = tmpJobACLs;

            return(new _Job_503(id, name, report, counters, tasks, taskCount, configFile, jobACLs
                                , conf));
        }
Exemplo n.º 24
0
        public void StartShallRunThrough()
        {
            var mockClient = new Mock <IJobsClient>();
            var mockLogger = new Mock <ILogger <ClaraJobsApi> >();
            var job        = new Job
            {
                JobId     = Guid.NewGuid().ToString("N"),
                PayloadId = Guid.NewGuid().ToString("N")
            };

            JobId.TryParse(job.JobId, out JobId jobId);

            mockClient.Setup(p => p.StartJob(It.IsAny <JobId>(), It.IsAny <List <KeyValuePair <string, string> > >()))
            .ReturnsAsync(new JobToken
            {
                JobId     = jobId,
                JobState  = JobState.Pending,
                JobStatus = Nvidia.Clara.Platform.JobStatus.Healthy
            });

            var service = new ClaraJobsApi(
                mockClient.Object, mockLogger.Object);

            service.Start(job).Wait();

            mockClient.Verify(
                p => p.StartJob(It.IsAny <JobId>(), It.IsAny <List <KeyValuePair <string, string> > >()),
                Times.Exactly(1));

            mockLogger.VerifyLogging(LogLevel.Error, Times.Never());
            mockLogger.VerifyLogging(LogLevel.Information, Times.Once());
        }
Exemplo n.º 25
0
        public async Task TaoFailure()
        {
            var buildId = new BuildId(4, JobId.ParseName("test"));

            _restClient.AddJson(
                buildId: buildId,
                buildResultJson: TestResources.Tao1BuildResult,
                buildInfoJson: TestResources.Tao1BuildInfo,
                failureInfoJson: TestResources.Tao1FailureInfo,
                testReportJson: TestResources.Tao1TestResult);

            var entity = await _populator.PopulateBuild(buildId);

            var filter = FilterUtil
                         .Column(nameof(BuildFailureEntity.JobName), buildId.JobName)
                         .Filter;
            var list = AzureUtil.Query <BuildFailureEntity>(_buildFailureExactTable, filter).ToList();

            Assert.Equal(2, list.Count);
            foreach (var item in list)
            {
                Assert.Equal(BuildFailureKind.TestCase, item.BuildFailureKind);
                Assert.Equal(buildId, item.BuildId);
            }
        }
Exemplo n.º 26
0
 public void Root()
 {
     RunAll(EqualityUnit
            .Create(JobId.Root)
            .WithEqualValues(JobId.Root, JobId.ParseName(""))
            .WithNotEqualValues(new JobId("test")));
 }
Exemplo n.º 27
0
        /// <summary>Ensure that a JOB_ID was passed into the page.</summary>
        public virtual void RequireJob()
        {
            if ($(JobId).IsEmpty())
            {
                BadRequest("missing job ID");
                throw new RuntimeException("Bad Request: Missing job ID");
            }
            JobId jobID = MRApps.ToJobID($(JobId));

            app.SetJob(app.context.GetJob(jobID));
            if (app.GetJob() == null)
            {
                NotFound($(JobId));
                throw new RuntimeException("Not Found: " + $(JobId));
            }
            /* check for acl access */
            Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = app.context.GetJob(jobID);
            if (!CheckAccess(job))
            {
                AccessDenied("User " + Request().GetRemoteUser() + " does not have " + " permission to view job "
                             + $(JobId));
                throw new RuntimeException("Access denied: User " + Request().GetRemoteUser() + " does not have permission to view job "
                                           + $(JobId));
            }
        }
Exemplo n.º 28
0
 public Job UppdateJob(JobId jobId, string name, string dictionaryName, IList <CustomFieldTypeId> customFieldTypeIdList)
 {
     try
     {
         using (var scope = new TransactionScope())
         {
             var job             = jobRep.GetById(jobId);
             var jobCustomFields = customFieldRep.GetAll(EntityTypeEnum.Job)
                                   .Where(c => customFieldTypeIdList.Contains(c.Id)).ToList();
             job.Update(name, dictionaryName, jobCustomFields);
             jobRep.UpdateJob(job);
             scope.Complete();
             return(job);
         }
     }
     catch (Exception exp)
     {
         var res = jobRep.TryConvertException(exp);
         if (res == null)
         {
             throw;
         }
         throw res;
     }
 }
Exemplo n.º 29
0
            /// <exception cref="System.IO.IOException"/>
            public virtual GetTaskReportsResponse GetTaskReports(GetTaskReportsRequest request
                                                                 )
            {
                JobId    jobId    = request.GetJobId();
                TaskType taskType = request.GetTaskType();
                GetTaskReportsResponse response = this.recordFactory.NewRecordInstance <GetTaskReportsResponse
                                                                                        >();

                Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = this.VerifyAndGetJob(jobId, JobACL
                                                                                      .ViewJob, true);
                ICollection <Task> tasks = job.GetTasks(taskType).Values;

                MRClientService.Log.Info("Getting task report for " + taskType + "   " + jobId +
                                         ". Report-size will be " + tasks.Count);
                // Take lock to allow only one call, otherwise heap will blow up because
                // of counters in the report when there are multiple callers.
                lock (this.getTaskReportsLock)
                {
                    foreach (Task task in tasks)
                    {
                        response.AddTaskReport(task.GetReport());
                    }
                }
                return(response);
            }
Exemplo n.º 30
0
        public async Task Create_ShallReturnAJob()
        {
            var mockClient = new Mock <IJobsClient>();
            var mockLogger = new Mock <ILogger <ClaraJobsApi> >();

            JobId.TryParse(Guid.NewGuid().ToString("N"), out JobId jobId);
            PayloadId.TryParse(Guid.NewGuid().ToString("N"), out PayloadId payloadId);
            PipelineId.TryParse(Guid.NewGuid().ToString("N"), out PipelineId pipelineId);

            mockClient.Setup(p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>(), It.IsAny <JobPriority>(), It.IsAny <Dictionary <string, string> >()))
            .ReturnsAsync(new JobInfo
            {
                Name       = "bla bla job",
                JobId      = jobId,
                PayloadId  = payloadId,
                PipelineId = pipelineId
            });

            var service = new ClaraJobsApi(mockClient.Object, mockLogger.Object);

            var metadata = new JobMetadataBuilder();

            metadata.AddSourceName("TestSource");
            var job = await service.Create(pipelineId.ToString(), "bla bla", JobPriority.Higher, metadata);

            Assert.Equal(jobId.ToString(), job.JobId);
            Assert.Equal(payloadId.ToString(), job.PayloadId);

            mockClient.Verify(
                p => p.CreateJob(It.IsAny <PipelineId>(), It.IsAny <string>(), JobPriority.Higher, metadata),
                Times.Exactly(1));

            mockLogger.VerifyLogging(LogLevel.Information, Times.Once());
            mockLogger.VerifyLogging(LogLevel.Error, Times.Never());
        }
Exemplo n.º 31
0
 public TaskManagerJobMetricGroup(
     IMetricRegistry registry,
     TaskManagerMetricGroup parent,
     JobId jobId, string jobName)
     : base(registry, parent, jobId, jobName, null)
 {
 }
Exemplo n.º 32
0
        protected static string JobToString(JobId job)
        {
            if (!sCareerJobToString.Valid)
            {
                return null;
            }

            return sCareerJobToString.Invoke<string>(new object[] { job });
        }
Exemplo n.º 33
0
 internal static BuildInfo ParseBuildInfo(Uri host, JobId jobId, JObject build)
 {
     var id = build.Value<int>("id");
     var duration = TimeSpan.FromMilliseconds(build.Value<int>("duration"));
     var state = ParseBuildInfoState(build);
     var date = JenkinsUtil.ConvertTimestampToDateTimeOffset(build.Value<long>("timestamp"));
     var buildId = new BoundBuildId(host, id, jobId);
     var machineName = build.Value<string>("builtOn");
     return new BuildInfo(buildId, state, date, duration, machineName);
 }
Exemplo n.º 34
0
        public JobInfo(JobId id, string jobKind, List<BuildId> builds = null, List<JobId> jobs = null)
        {
            Debug.Assert(jobs.All(x => x.Parent.Name == id.Name));
            builds = builds ?? new List<BuildId>(capacity: 0);
            jobs = jobs ?? new List<JobId>(capacity: 0);

            Id = id;
            Builds = builds;
            Jobs = jobs;
            JobKind = jobKind;
        }
Exemplo n.º 35
0
        internal static List<BuildInfo> ParseBuildInfoList(Uri host, JobId jobId, JObject data)
        {
            var list = new List<BuildInfo>();
            var builds = (JArray)data["builds"];
            foreach (JObject build in builds)
            {
                list.Add(ParseBuildInfo(host, jobId, build));
            }

            return list;
        }
Exemplo n.º 36
0
        public static bool IsAuthNeededHeuristic(JobId jobId)
        {
            var name = jobId.Name;
            if (name.Contains("Private") ||
                name.Contains("perf_win10"))
            {
                return true;
            }

            return false;
        }
Exemplo n.º 37
0
        internal static List<BuildId> ParseBuilds(JobId id, JArray builds)
        {
            Debug.Assert(builds != null);
            var list = new List<BuildId>();
            foreach (var cur in builds)
            {
                var build = cur.ToObject<Json.Build>();
                list.Add(new BuildId(build.Number, id));
            }

            return list;
        }
Exemplo n.º 38
0
        public static string GetJobPath(JobId id)
        {
            if (id.IsRoot)
            {
                return "";
            }

            if (id.Parent.IsRoot)
            {
                return $"job/{id.ShortName}";
            }

            return $"{GetJobPath(id.Parent)}/job/{id.ShortName}";
        }
Exemplo n.º 39
0
        internal static List<JobId> ParseJobs(JobId parent, JArray jobs)
        {
            if (jobs == null)
            {
                return new List<JobId>(capacity: 0);
            }

            var list = new List<JobId>();
            foreach (var cur in jobs)
            {
                var name = cur.Value<string>("name");
                var id = new JobId(name, parent);
                list.Add(id);
            }

            return list;
        }
Exemplo n.º 40
0
 public static Uri GetJobUri(Uri baseUrl, JobId jobId)
 {
     var path = GetJobPath(jobId);
     return GetUri(baseUrl, path);
 }
Exemplo n.º 41
0
 public static string ConvertJobIdToPath(JobId jobId)
 {
     var builder = new StringBuilder();
     ConvertJobIdToPathCore(builder, jobId);
     return builder.ToString();
 }
Exemplo n.º 42
0
 public bool TryRemove(JobId jobId)
 {
     var tick = FindTick(jobId);
     if (!tick.HasValue) return false;
     var result = _jobs[tick.Value].RemoveIf(job => job.Id == jobId);
     Debug.Assert(result);
     return true;
 }
Exemplo n.º 43
0
        private static void ConvertJobIdToPathCore(StringBuilder builder, JobId jobId)
        {
            if (jobId.IsRoot)
            {
                return;
            }

            ConvertJobIdToPathCore(builder, jobId.Parent);

            if (builder.Length != 0)
            {
                builder.Append('/');
            }

            builder.Append($"job/{jobId.ShortName}");
        }
Exemplo n.º 44
0
        private JobSummary GetJobDaySummary(JobId jobId)
        {
            var client = ControllerUtil.CreateJenkinsClient();
            var all = client.GetBuildInfoList(jobId).Where(x => x.State != BuildState.Running);
            var list = new List<JobDaySummary>();
            foreach (var group in all.GroupBy(x => x.Date.Date))
            {
                var succeeded = group.Count(x => x.State == BuildState.Succeeded);
                var failed = group.Count(x => x.State == BuildState.Failed);
                var aborted = group.Count(x => x.State == BuildState.Aborted);
                var averageDuration = TimeSpan.FromMilliseconds(group.Average(x => x.Duration.TotalMilliseconds));
                list.Add(new JobDaySummary()
                {
                    Name = jobId.Name,
                    Date = group.Key,
                    Succeeded = succeeded,
                    Failed = failed,
                    Aborted = aborted,
                    AverageDuration = averageDuration
                });
            }

            return new JobSummary()
            {
                Name = jobId.Name,
                AverageDuration = TimeSpan.FromMilliseconds(all.Average(x => x.Duration.TotalMilliseconds)),
                JobDaySummaryList = list
            };
        }
Exemplo n.º 45
0
 public void SetAsDone()
 {
     _jobId = default(JobId);
 }
Exemplo n.º 46
0
 private static BoundBuildId Create(string host, int number, JobId id) => new BoundBuildId(new Uri($"http://{host}"), number, id);
Exemplo n.º 47
0
        private List<JobQueueSummary> GetJobSummaryList(JobId jobId, int count)
        {
            var list = new List<JobQueueSummary>();
            var client = ControllerUtil.CreateJenkinsClient();

            foreach (var id in client.GetBuildIds(jobId).Take(count))
            {
                var state = client.GetBuildInfo(id).State;
                if (state == BuildState.Running)
                {
                    continue;
                }

                var time = client.GetTimeInQueue(id);
                if (time.HasValue)
                {
                    var summary = new JobQueueSummary()
                    {
                        Name = jobId.Name,
                        Id = id.Number,
                        QueueTime = time.Value
                    };
                    list.Add(summary);
                }
            }

            return list.OrderBy(x => x.Id).ToList();
        }
Exemplo n.º 48
0
 public JobCreationFailed(JobId jobId, string errorMessage, Exception exception = null)
     : base(errorMessage, exception)
 {
     JobId = jobId;
 }
Exemplo n.º 49
0
 public static string GetJobDeletePath(JobId jobId)
 {
     return $"{GetJobPath(jobId)}/doDelete";
 }
Exemplo n.º 50
0
 public CreateJob(JobId jobId)
 {
     JobId = jobId;
 }
Exemplo n.º 51
0
 public static string GetJobEnablePath(JobId jobId)
 {
     return $"{GetJobPath(jobId)}/enable";
 }
Exemplo n.º 52
0
 public static string GetJobDisablePath(JobId jobId)
 {
     return $"{GetJobPath(jobId)}/disable";
 }
Exemplo n.º 53
0
 // Externalized to MasterController and Traveler
 public static string JobToString (JobId job)
 {
     try
     {
         return JobsBooter.JobToString(job);
     }
     catch (Exception e)
     {
         Common.Exception("JobToString", e);
         return null;
     }
 }
Exemplo n.º 54
0
 public Job(Schedule schedule, Tick delay, Action callback)
 {
     _schedule = schedule;
     _jobId = _schedule.AddRelative(delay, callback);
 }
Exemplo n.º 55
0
        private ActionResult GetQueueJob(JobId jobId, int count)
        {
            var list = GetJobSummaryList(jobId, count);

            // TODO: this is expensive to compute.  Should cache.
            var average = TimeSpan.FromMilliseconds(list.Average(x => x.QueueTime.TotalMilliseconds));
            var median = TimeSpan.FromMilliseconds(list.Select(x => x.QueueTime.TotalMilliseconds).OrderBy(x => x).Skip(list.Count / 2).First());
            var max = TimeSpan.FromMilliseconds(list.Max(x => x.QueueTime.TotalMilliseconds));
            var min = TimeSpan.FromMilliseconds(list.Min(x => x.QueueTime.TotalMilliseconds));
            var model = new JobQueueModel()
            {
                JobName = jobId.Name,
                JobCount = list.Count,
                AverageTime = average,
                MedianTime = median,
                MaxTime = max,
                Mintime = min,
                Jobs = list
            };

            return View(viewName: "QueueJobData", model: model);
        }
Exemplo n.º 56
0
        private Tick? FindTick(JobId jobId)
        {
            if (_jobToTick.Empty())
                return null;

            if (_jobToTick.First().Key > jobId)
                return null;

            Tick tick;
            if (!_jobToTick.TryGetAndRemove(jobId, out tick))
                return null;

            return tick;
        }
Exemplo n.º 57
0
 private ActionResult GetJob(JobId id)
 {
     var model = GetJobDaySummary(id);
     return View(viewName: "JobData", model: model);
 }
Exemplo n.º 58
0
 public bool Remove(JobId jobId)
 {
     var ret = TryRemove(jobId);
     if (!ret) Debug.LogError("job " + jobId + " not found.");
     return ret;
 }
Exemplo n.º 59
0
 /// <summary>
 /// Ensure the view name for the given job is present in the <see cref="AzureConstants.TableNames.ViewNameDate"/> table.
 /// </summary>
 private async Task PopulateViewName(JobId jobId, DateTimeOffset buildDate)
 {
     try
     {
         var entity = new ViewNameEntity(buildDate, AzureUtil.GetViewName(jobId));
         var op = TableOperation.Insert(entity);
         await _viewNameDateTable.ExecuteAsync(op);
     }
     catch (StorageException ex) when (ex.RequestInformation.HttpStatusCode == 409)
     {
         // It's expected to get errors here because we're inserting duplicate data.  All that matters is the
         // data is present in the table.  
     }
 }
 public RecipientsInitializationFailed(JobId jobId, string errorMessage, Exception exception = null)
     : base(errorMessage, exception)
 {
     JobId = jobId;
 }