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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations