Search in sources :

Example 26 with BuildDetails

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

the class WhenSchedulingJob method testParameterisedJobShouldSaveAllParameters.

@Test
public void testParameterisedJobShouldSaveAllParameters() throws Exception {
    final FreeStyleProject project = createFreeStyleProject("ParameterisedJob");
    // set parameters
    final ParameterDefinition param1 = new StringParameterDefinition("myStringParam", "myStringValue", "My String Parameter");
    final ParameterDefinition param2 = new BooleanParameterDefinition("myBooleanParam", false, "My Boolean Parameter");
    project.addProperty(new ParametersDefinitionProperty(param1, param2));
    // enable audit2db plugin
    final DbAuditPublisher plugin = getPlugin();
    project.getPublishersList().add((Publisher) plugin);
    // build now
    final Future<FreeStyleBuild> futureBuild = project.scheduleBuild2(0);
    final FreeStyleBuild build = futureBuild.get();
    Assert.assertNotNull(build);
    Assert.assertEquals("Unexpected build result", Result.SUCCESS, build.getResult());
    // check data persistence
    final BuildDetailsRepository repository = plugin.getRepository();
    final BuildDetails actual = repository.getBuildDetailsForBuild(build);
    final BuildDetails expected = new BuildDetailsImpl(build);
    Assert.assertEquals("Unexpected build details", expected, actual);
    Assert.assertNotNull("Unexpected null end date", actual.getEndDate());
    Assert.assertTrue("Unexpected duration", actual.getDuration() > 0L);
    Assert.assertEquals("Unexpected number of params", 2, actual.getParameters().size());
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) StringParameterDefinition(hudson.model.StringParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) BuildDetailsRepository(org.jenkins.plugins.audit2db.data.BuildDetailsRepository) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition) DbAuditPublisher(org.jenkins.plugins.audit2db.DbAuditPublisher) Test(org.junit.Test)

Example 27 with BuildDetails

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

the class DbAuditPublisherImpl method perform.

@Override
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener) throws InterruptedException, IOException {
    LOGGER.log(Level.FINE, String.format("perform: %s; launcher: %s", build.getDisplayName(), launcher.toString()));
    final BuildDetails details = getRepository().getBuildDetailsForBuild(build);
    details.setDuration(build.getDuration());
    details.setEndDate(new Date(details.getStartDate().getTime() + details.getDuration()));
    details.setResult(build.getResult().toString());
    boolean result = false;
    try {
        getRepository().updateBuildDetails(details);
        LOGGER.log(Level.FINE, "Updated build details with id=" + details.getId());
        result = super.perform(build, launcher, listener);
    } catch (final Throwable t) {
        LOGGER.log(Level.SEVERE, t.getMessage(), t);
    }
    return result;
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Date(java.util.Date)

Example 28 with BuildDetails

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

the class BuildDetailsHibernateRepository method getProjectNames.

/**
 * Retrieves the names of all projects on the given Jenkins master, filtered
 * by name pattern and date range. The name pattern accepts wildcards. A
 * <code>null</code> name pattern will match all names.
 */
@Override
public List<String> getProjectNames(final String masterHostName, final String pattern, final Date fromDate, final Date toDate) {
    final List<String> retval = new ArrayList<String>();
    DetachedCriteria criteria = DetachedCriteria.forClass(BuildDetails.class).add(Restrictions.and(Restrictions.ge("startDate", getInclusiveStartDate(fromDate)), Restrictions.le("endDate", getInclusiveEndDate(toDate))));
    if ((pattern != null) && !pattern.isEmpty() && !pattern.trim().equals("%")) {
        criteria = criteria.add(Restrictions.ilike("name", pattern));
    }
    criteria = criteria.createCriteria("node").add(Restrictions.ilike("masterHostName", masterHostName));
    try {
        @SuppressWarnings("unchecked") final List<BuildDetails> buildDetails = getHibernateTemplate().findByCriteria(criteria);
        if ((buildDetails != null) && !buildDetails.isEmpty()) {
            for (final BuildDetails detail : buildDetails) {
                final String projectName = detail.getName();
                if (!retval.contains(projectName)) {
                    retval.add(projectName);
                }
            }
        }
    } catch (final Throwable t) {
        LOGGER.log(Level.SEVERE, t.getMessage(), t);
    }
    return retval;
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ArrayList(java.util.ArrayList) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 29 with BuildDetails

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

the class BuildDetailsHibernateRepository method getBuildDetails.

/**
 * @see org.jenkins.plugins.audit2db.data.AuditReportsRepository#getBuildDetails(java.lang.String,
 *      java.sql.Date, java.sql.Date)
 */
@Override
public List<BuildDetails> getBuildDetails(final String masterHostName, final String projectName, final Date fromDate, final Date toDate) {
    final List<BuildDetails> retval = new ArrayList<BuildDetails>();
    // we need to specifically state >=startdate AND <=enddate
    // because the "between" semantics vary between database
    // implementations and we want to use an inclusive filter every time
    DetachedCriteria criteria = DetachedCriteria.forClass(BuildDetails.class);
    if (projectName != null) {
        criteria = criteria.add(Restrictions.ilike("name", projectName));
    }
    criteria = criteria.add(Restrictions.and(Restrictions.ge("startDate", getInclusiveStartDate(fromDate)), Restrictions.le("endDate", getInclusiveEndDate(toDate)))).addOrder(Property.forName("startDate").asc()).createAlias("node", "node").add(Restrictions.ilike("node.masterHostName", masterHostName));
    try {
        @SuppressWarnings("unchecked") final List<BuildDetails> buildDetails = getHibernateTemplate().findByCriteria(criteria);
        if ((buildDetails != null) && !buildDetails.isEmpty()) {
            retval.addAll(buildDetails);
        }
    } catch (final Throwable t) {
        LOGGER.log(Level.SEVERE, t.getMessage(), t);
    }
    return retval;
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ArrayList(java.util.ArrayList) DetachedCriteria(org.hibernate.criterion.DetachedCriteria)

Example 30 with BuildDetails

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

the class JobsByDateReportImpl method getProjectExecutions.

@Override
public Map<String, List<BuildDetails>> getProjectExecutions(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<String> projectNames = getRepository().getProjectNames(jenkinsHost, startDate, endDate);
    for (final String projectName : projectNames) {
        final List<BuildDetails> buildDetails = getRepository().getBuildDetails(jenkinsHost, projectName, startDate, endDate);
        if (!buildDetails.isEmpty()) {
            retval.put(projectName, buildDetails);
        }
    }
    return retval;
}
Also used : Jenkins(jenkins.model.Jenkins) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HashMap(java.util.HashMap) List(java.util.List) Date(java.util.Date)

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