Search in sources :

Example 31 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails in project selenium_java by sergueik.

the class JobsByParamReportImpl method getProjectExecutions.

/**
 * @see org.jenkins.plugins.audit2db.reports.JobsByParamReport#getProjectExecutions(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public Map<String, List<BuildDetails>> getProjectExecutions(final String paramName, final String paramValue, final String startDateString, final String endDateString) {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins != null) {
        // unit tests won't have a Jenkins instance
        jenkins.checkPermission(DbAuditPlugin.RUN);
    }
    final Map<String, List<BuildDetails>> retval = new HashMap<String, List<BuildDetails>>();
    final Date startDate = DbAuditReportUtils.stringToDate(startDateString);
    final Date endDate = DbAuditReportUtils.stringToDate(endDateString);
    final String jenkinsHost = getJenkinsHostname();
    final List<BuildDetails> buildDetails = getRepository().getBuildDetailsByParams(jenkinsHost, paramName, paramValue, startDate, endDate);
    for (final BuildDetails details : buildDetails) {
        final String projectName = details.getName();
        if (!retval.containsKey(projectName)) {
            retval.put(projectName, new ArrayList<BuildDetails>());
        }
        retval.get(projectName).add(details);
    }
    return retval;
}
Also used : Jenkins(jenkins.model.Jenkins) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date)

Example 32 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails in project selenium_java by sergueik.

the class Audit2DbExecution method run.

@Override
protected Void run() throws Exception {
    StepContext context = getContext();
    Run<?, ?> run = context.get(Run.class);
    LOGGER.fine("StepContext.Run: " + run);
    Properties props = HibernateUtil.getExtraProperties(step.getJdbcDriver(), step.getJdbcUrl(), step.getJdbcUsername(), step.getJdbcPassword());
    if (StringUtils.isNotBlank(step.getHibernateDialect())) {
        props.put("hibernate.dialect", step.getHibernateDialect());
    }
    LOGGER.fine("props: " + props);
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory(props);
    LOGGER.fine("sessionFactory: " + sessionFactory);
    BuildDetailsRepository repository = new BuildDetailsHibernateRepository(sessionFactory);
    BuildDetails details = BuildDetailsResolver.resolveBuildDetails(run, context.get(Computer.class));
    Audit2DbGraphListener listener = new Audit2DbGraphListener(repository, details);
    context.get(FlowExecution.class).addListener(listener);
    return null;
}
Also used : SessionFactory(org.hibernate.SessionFactory) StepContext(org.jenkinsci.plugins.workflow.steps.StepContext) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BuildDetailsRepository(org.jenkins.plugins.audit2db.data.BuildDetailsRepository) Computer(hudson.model.Computer) Properties(java.util.Properties) BuildDetailsHibernateRepository(org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository)

Example 33 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails in project selenium_java by sergueik.

the class BuildDetailsHibernateRepositoryTests method retrievalForMasterAndProjectByMatchingDateRangeShouldReturnNonEmptyList.

@Test
public void retrievalForMasterAndProjectByMatchingDateRangeShouldReturnNonEmptyList() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final List<BuildDetails> builds = repository.getBuildDetails(build.getNode().getMasterHostName(), build.getName(), new Date(0), build.getEndDate());
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertFalse("Unexpected empty list of builds", builds.isEmpty());
    Assert.assertEquals("Unexpected number of builds", 1, builds.size());
    Assert.assertEquals("Mismatching build details found", build, builds.get(0));
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Date(java.util.Date) Test(org.junit.Test)

Example 34 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails in project selenium_java by sergueik.

the class BuildDetailsHibernateRepositoryTests method retrievalByNonMatchingDateRangeShouldReturnEmptyList.

@Test
public void retrievalByNonMatchingDateRangeShouldReturnEmptyList() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final Calendar start = Calendar.getInstance();
    start.set(1914, 6, 28, 9, 0, 0);
    final Calendar end = Calendar.getInstance();
    end.set(1918, 10, 11, 11, 0, 0);
    final List<BuildDetails> builds = repository.getBuildDetailsByDateRange(start.getTime(), end.getTime());
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertTrue("Unexpected non-empty list of builds", builds.isEmpty());
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 35 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails in project selenium_java by sergueik.

the class BuildDetailsHibernateRepositoryTests method retrievalForMasterByMatchingDateRangeShouldReturnNonEmptyList.

@Test
public void retrievalForMasterByMatchingDateRangeShouldReturnNonEmptyList() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final List<BuildDetails> builds = repository.getBuildDetails(build.getNode().getMasterHostName(), new Date(0), build.getEndDate());
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertFalse("Unexpected empty list of builds", builds.isEmpty());
    Assert.assertEquals("Unexpected number of builds", 1, builds.size());
    Assert.assertEquals("Mismatching build details found", build, builds.get(0));
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Date(java.util.Date) Test(org.junit.Test)

Aggregations

BuildDetails (org.jenkins.plugins.audit2db.model.BuildDetails)62 Test (org.junit.Test)50 List (java.util.List)25 Calendar (java.util.Calendar)11 BuildParameter (org.jenkins.plugins.audit2db.model.BuildParameter)11 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 TransactionStatus (org.springframework.transaction.TransactionStatus)8 BuildDetailsHibernateRepository (org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository)5 BuildDetailsImpl (org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl)5 JobsByParamReportImpl (org.jenkins.plugins.audit2db.internal.reports.JobsByParamReportImpl)5 JobHistoryReport (org.jenkins.plugins.audit2db.reports.JobHistoryReport)5 JobsByParamReport (org.jenkins.plugins.audit2db.reports.JobsByParamReport)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 BuildNode (org.jenkins.plugins.audit2db.model.BuildNode)4 JobsByDateReport (org.jenkins.plugins.audit2db.reports.JobsByDateReport)4 HashMap (java.util.HashMap)3 Jenkins (jenkins.model.Jenkins)3 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)3 BuildDetailsRepository (org.jenkins.plugins.audit2db.data.BuildDetailsRepository)3