Search in sources :

Example 6 with GroupBuild

use of org.jboss.pnc.dto.GroupBuild in project pnc by project-ncl.

the class GroupBuildProviderTest method testGetSpecific.

@Test
public void testGetSpecific() {
    GroupBuild groupBuild = provider.getSpecific(bcsr.getId().toString());
    assertThat(groupBuild).isNotNull();
    assertThat(groupBuild.getId()).isEqualTo(bcsr.getId().toString());
    assertThat(groupBuild.getGroupConfig().getId()).isEqualTo(bcsr.getBuildConfigurationSet().getId().toString());
}
Also used : GroupBuild(org.jboss.pnc.dto.GroupBuild) Test(org.junit.Test)

Example 7 with GroupBuild

use of org.jboss.pnc.dto.GroupBuild in project bacon by project-ncl.

the class PncBuilderTest method getCountOfBuildConfigsForGroupBuild.

@Test
void getCountOfBuildConfigsForGroupBuild() throws Exception {
    Map<String, BuildConfigurationRef> buildConfigurations = new HashMap<>();
    BuildConfigurationRef bc1 = easyRandom.nextObject(BuildConfigurationRef.class);
    BuildConfigurationRef bc2 = easyRandom.nextObject(BuildConfigurationRef.class);
    BuildConfigurationRef bc3 = easyRandom.nextObject(BuildConfigurationRef.class);
    buildConfigurations.put(bc1.getName(), bc1);
    buildConfigurations.put(bc2.getName(), bc2);
    buildConfigurations.put(bc3.getName(), bc3);
    String groupConfigurationId = "5";
    String groupBuildId = "1";
    GroupConfiguration gc = GroupConfiguration.builder().id(groupConfigurationId).buildConfigs(buildConfigurations).build();
    GroupBuild gb = GroupBuild.builder().id(groupBuildId).groupConfig(gc).build();
    when(groupBuildClient.getSpecific(groupBuildId)).thenReturn(gb);
    when(groupConfigurationClient.getBuildConfigs(groupConfigurationId)).thenReturn(new RemoteCollection<BuildConfiguration>() {

        @Override
        public int size() {
            return buildConfigurations.size();
        }

        @Override
        public Collection<BuildConfiguration> getAll() {
            return null;
        }

        @Override
        public Iterator<BuildConfiguration> iterator() {
            return null;
        }
    });
    try (PncBuilder builder = new PncBuilder(groupBuildClient, groupConfigurationClient)) {
        assertEquals(buildConfigurations.size(), builder.getCountOfBuildConfigsForGroupBuild(groupBuildId));
    }
}
Also used : BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) HashMap(java.util.HashMap) GroupBuild(org.jboss.pnc.dto.GroupBuild) Iterator(java.util.Iterator) Collection(java.util.Collection) RemoteCollection(org.jboss.pnc.client.RemoteCollection) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Test(org.junit.jupiter.api.Test)

Example 8 with GroupBuild

use of org.jboss.pnc.dto.GroupBuild in project bacon by project-ncl.

the class PigFacade method build.

public static GroupBuildInfo build(boolean tempBuild, boolean tempBuildTS, RebuildMode rebuildMode, boolean wait, boolean dryRun) {
    ImportResult importResult = context().getPncImportResult();
    if (importResult == null) {
        importResult = readPncEntities();
    }
    if (tempBuild) {
        log.info("Temporary build");
    }
    try (PncBuilder pncBuilder = new PncBuilder()) {
        GroupBuild groupBuild = pncBuilder.build(importResult.getBuildGroup(), tempBuild, tempBuildTS, rebuildMode, wait, dryRun);
        if (wait) {
            try (BuildInfoCollector buildInfoCollector = new BuildInfoCollector()) {
                return buildInfoCollector.getBuildsFromGroupBuild(groupBuild);
            }
        }
        log.info("Not waiting for build to finish.");
        return null;
    }
}
Also used : ImportResult(org.jboss.pnc.bacon.pig.impl.pnc.ImportResult) BuildInfoCollector(org.jboss.pnc.bacon.pig.impl.pnc.BuildInfoCollector) GroupBuild(org.jboss.pnc.dto.GroupBuild) PncBuilder(org.jboss.pnc.bacon.pig.impl.pnc.PncBuilder)

Example 9 with GroupBuild

use of org.jboss.pnc.dto.GroupBuild in project bacon by project-ncl.

the class BuildInfoCollector method getBuildsFromGroupBuild.

/**
 * Get all the builds done in a build group. If the build finished with 'NO_REBUILD_REQUIRED', get the 'original'
 * successful build and return it instead If the build was successful, we don't grab the logs since they can be
 * quite long.
 *
 * @param groupBuild the group build to get the builds
 * @return The information on the group build and the builds performed
 */
public GroupBuildInfo getBuildsFromGroupBuild(GroupBuild groupBuild) {
    Map<String, PncBuild> result = new HashMap<>();
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setLatest(false);
    filter.setRunning(false);
    try {
        Collection<Build> builds = groupBuildClient.getBuilds(groupBuild.getId(), filter).getAll();
        for (Build build : builds) {
            PncBuild pncBuild;
            if (build.getStatus() == BuildStatus.NO_REBUILD_REQUIRED) {
                BuildRef buildRef = build.getNoRebuildCause();
                Build realBuild = buildClient.getSpecific(buildRef.getId());
                pncBuild = new PncBuild(realBuild);
            } else {
                pncBuild = new PncBuild(build);
            }
            pncBuild.addBuiltArtifacts(toList(buildClient.getBuiltArtifacts(pncBuild.getId())));
            result.put(pncBuild.getName(), pncBuild);
        }
        return new GroupBuildInfo(groupBuild, result);
    } catch (RemoteResourceException e) {
        throw new RuntimeException("Failed to get group build info for " + groupBuild.getId(), e);
    }
}
Also used : BuildRef(org.jboss.pnc.dto.BuildRef) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) GroupBuildInfo(org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Example 10 with GroupBuild

use of org.jboss.pnc.dto.GroupBuild in project bacon by project-ncl.

the class PncBuilder method cancelRunningGroupBuild.

public String cancelRunningGroupBuild(String groupConfigurationId) {
    try {
        Collection<GroupBuild> groupBuilds = groupConfigClient.getAllGroupBuilds(groupConfigurationId, of("=desc=startTime"), query("status==%s", BuildStatus.BUILDING)).getAll();
        if (groupBuilds.size() > 1) {
            return ("Can't cancel, there are multiple GroupBuilds running for single GroupConfiguration name and we can't decide correct one to cancel from build-config.yaml information. Found:" + groupBuilds);
        }
        if (groupBuilds.isEmpty()) {
            return "No build is running for this group.";
        }
        GroupBuild running = groupBuilds.iterator().next();
        groupBuildClient.cancel(running.getId());
        return "Group build " + running.getId() + " canceled.";
    } catch (RemoteResourceException e) {
        throw new RuntimeException("Failed to get group build info to cancel running build.", e);
    }
}
Also used : RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) GroupBuild(org.jboss.pnc.dto.GroupBuild)

Aggregations

GroupBuild (org.jboss.pnc.dto.GroupBuild)14 Test (org.junit.Test)7 ContainerTest (org.jboss.pnc.test.category.ContainerTest)6 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)5 GroupBuildParameters (org.jboss.pnc.rest.api.parameters.GroupBuildParameters)4 ClientException (org.jboss.pnc.client.ClientException)3 BuildStatus (org.jboss.pnc.enums.BuildStatus)3 HashMap (java.util.HashMap)2 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)2 RemoteResourceNotFoundException (org.jboss.pnc.client.RemoteResourceNotFoundException)2 Undertow (io.undertow.Undertow)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 InSequence (org.jboss.arquillian.junit.InSequence)1 GroupBuildInfo (org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo)1 BuildInfoCollector (org.jboss.pnc.bacon.pig.impl.pnc.BuildInfoCollector)1 ImportResult (org.jboss.pnc.bacon.pig.impl.pnc.ImportResult)1 PncBuilder (org.jboss.pnc.bacon.pig.impl.pnc.PncBuilder)1