Search in sources :

Example 6 with BuildNode

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) Computer(hudson.model.Computer) InetAddress(java.net.InetAddress) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode)

Example 7 with BuildNode

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());
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode) Test(org.junit.Test)

Example 8 with BuildNode

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);
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode) Test(org.junit.Test)

Example 9 with BuildNode

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;
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) BuildNodeImpl(org.jenkins.plugins.audit2db.internal.model.BuildNodeImpl) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ArrayList(java.util.ArrayList) BuildParameterImpl(org.jenkins.plugins.audit2db.internal.model.BuildParameterImpl) Date(java.util.Date) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode)

Example 10 with BuildNode

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);
}
Also used : Jenkins(jenkins.model.Jenkins) BuildNodeImpl(org.jenkins.plugins.audit2db.internal.model.BuildNodeImpl) Node(hudson.model.Node) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode) URL(java.net.URL) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode)

Aggregations

BuildNode (org.jenkins.plugins.audit2db.model.BuildNode)10 Test (org.junit.Test)5 BuildNodeImpl (org.jenkins.plugins.audit2db.internal.model.BuildNodeImpl)4 BuildDetails (org.jenkins.plugins.audit2db.model.BuildDetails)4 Computer (hudson.model.Computer)1 Node (hudson.model.Node)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Jenkins (jenkins.model.Jenkins)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1 BuildDetailsImpl (org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl)1 BuildParameterImpl (org.jenkins.plugins.audit2db.internal.model.BuildParameterImpl)1 BuildParameter (org.jenkins.plugins.audit2db.model.BuildParameter)1 HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate)1