use of org.jenkins.plugins.audit2db.model.BuildNode in project selenium_java by sergueik.
the class BuildDetailsImpl method resolveBuildNode.
private BuildNode resolveBuildNode(final Node node) {
String address = "UNKNOWN";
String hostname = "UNKNOWN";
try {
final InetAddress iaddr = InetAddress.getLocalHost();
address = iaddr.getHostAddress();
hostname = iaddr.getHostName();
} catch (final UnknownHostException e) {
LOGGER.log(Level.SEVERE, "An error occurred while trying to resolve the master's network name and address: " + e.getMessage(), e);
}
final Computer computer = node.toComputer();
final BuildNode retval = new BuildNodeImpl(address, hostname, computer.getDisplayName(), String.format("%s/%s", hostname, computer.getUrl()), node.getNodeName(), node.getNodeDescription(), node.getLabelString());
return retval;
}
use of org.jenkins.plugins.audit2db.model.BuildNode in project selenium_java by sergueik.
the class BuildDetailsHibernateRepositoryTests method createBuildsWithSameNodeShouldReuseNodeEntity.
@Test
public void createBuildsWithSameNodeShouldReuseNodeEntity() {
final BuildDetails build1 = TestUtils.createRandomBuildDetails();
build1.setId("BUILD_1");
final BuildDetails build2 = TestUtils.createRandomBuildDetails();
build2.setId("BUILD_2");
repository.saveBuildDetails(build1);
repository.saveBuildDetails(build2);
final HibernateTemplate hibernate = new HibernateTemplate();
hibernate.setSessionFactory(((AbstractHibernateRepository) repository).getSessionFactory());
final List<BuildNode> nodes = hibernate.loadAll(BuildNode.class);
Assert.assertEquals("Unexpected number of node entities", 1, nodes.size());
}
use of org.jenkins.plugins.audit2db.model.BuildNode in project selenium_java by sergueik.
the class BuildDetailsHibernateRepositoryTests method retrievingBuildNodeByNonExistingUrlShouldReturnNull.
@Test
public void retrievingBuildNodeByNonExistingUrlShouldReturnNull() {
final BuildDetails build = TestUtils.createRandomBuildDetails();
final Object buildId = repository.saveBuildDetails(build);
Assert.assertNotNull("Unexpected null build id", buildId);
final BuildNode actual = repository.getBuildNodeByUrl("NON_EXISTING_URL");
Assert.assertNull("Unexppected non-null build node", actual);
}
use of org.jenkins.plugins.audit2db.model.BuildNode in project selenium_java by sergueik.
the class TestUtils method createRandomBuildDetails.
public static BuildDetails createRandomBuildDetails(final boolean withParams) {
final long salt = System.nanoTime();
final BuildDetails build = new BuildDetailsImpl();
build.setDuration(Long.valueOf(60 + (long) (Math.random() * 60)));
build.setEndDate(new Date(build.getStartDate().getTime() + (build.getDuration() * 1000)));
build.setFullName("BUILD FULL NAME " + salt);
build.setId("BUILD ID " + salt);
build.setName("BUILD NAME " + salt);
build.setUserId("BUILD USER ID " + salt);
build.setUserName("BUILD USER NAME " + salt);
if (withParams) {
final List<BuildParameter> params = new ArrayList<BuildParameter>();
params.add(new BuildParameterImpl("PARAM_ID 1 " + salt, "PARAM NAME 1 " + salt, "PARAM VALUE 1 " + salt, build));
params.add(new BuildParameterImpl("PARAM_ID 2 " + salt, "PARAM NAME 2 " + salt, "PARAM VALUE 2 " + salt, build));
build.setParameters(params);
}
final BuildNode node = new BuildNodeImpl("NODE ADDRESS", "NODE HOSTNAME", "NODE DISPLAYNAME", "NODE URL", "NODE NAME", "NODE DESCRIPTION", "NODE LABEL");
build.setNode(node);
return build;
}
use of org.jenkins.plugins.audit2db.model.BuildNode in project selenium_java by sergueik.
the class BuildDetailsResolver method addBuildNodeFromContext.
private static void addBuildNodeFromContext(BuildDetailsImpl details, Run<?, ?> run, Computer computer) throws IOException, InterruptedException {
LOGGER.finer("resolving build node");
Jenkins jenkins = Jenkins.getInstance();
LOGGER.finer("jenkins: " + jenkins);
LOGGER.finer("computer: " + computer);
Node node = computer.getNode();
LOGGER.finer("node: " + node);
String rootUrl = jenkins != null ? jenkins.getRootUrl() : "http://unconfigured-jenkins-server/";
LOGGER.finer("rootUrl: " + rootUrl);
URL url = new URL(rootUrl);
String masterHostname = url.getHost();
String urlString = String.format("%s/%s", rootUrl, computer.getUrl()).replaceAll("(\\w)(\\/{2,})(\\w)", "$1/$3");
BuildNode buildNode = new BuildNodeImpl(resolveMasterIpAddress(computer), masterHostname, computer.getDisplayName(), // url
urlString, node.getNodeName(), node.getNodeDescription(), node.getLabelString());
LOGGER.finer("buildNode: " + buildNode);
details.setNode(buildNode);
}
Aggregations