Search in sources :

Example 6 with BuildsFilterParameters

use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project bacon by project-ncl.

the class BuildInfoCollector method getLatestBuild.

public PncBuild getLatestBuild(String configId, BuildSearchType searchType) {
    try {
        BuildsFilterParameters filter = new BuildsFilterParameters();
        Optional<String> queryParam;
        switch(searchType) {
            case ANY:
                queryParam = query("status==%s", BuildStatus.SUCCESS);
                break;
            case PERMANENT:
                queryParam = query("status==%s;temporaryBuild==%s", BuildStatus.SUCCESS, false);
                break;
            case TEMPORARY:
                // NCL-5943 Cannot ignore permanent(regular) builds because they cause NO_REBUILD_REQUIRED even for
                // temporary builds. That means "latest build" for a temporary build can be permanent(regular).
                queryParam = query("status==%s", BuildStatus.SUCCESS);
                break;
            default:
                queryParam = Optional.empty();
        }
        // Note: sort by id not allowed
        Iterator<Build> buildIterator = buildConfigClient.getBuilds(configId, filter, of("=desc=submitTime"), queryParam).iterator();
        if (!buildIterator.hasNext()) {
            throw new NoSuccessfulBuildException(configId);
        }
        Build build = buildIterator.next();
        PncBuild result = new PncBuild(build);
        result.addBuiltArtifacts(toList(buildClient.getBuiltArtifacts(build.getId())));
        return result;
    } catch (ClientException e) {
        throw new RuntimeException("Failed to get latest successful build for " + configId, e);
    }
}
Also used : GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) ClientException(org.jboss.pnc.client.ClientException) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Example 7 with BuildsFilterParameters

use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters 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 8 with BuildsFilterParameters

use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project bacon by project-ncl.

the class PncBuilder method verifyAllBuildsInGroupBuildInFinalStateWithProperCount.

/**
 * This check makes sure that even when a group build is marked as done, we also need to make sure all its builds
 * are also done (NCL-6044). We also make sure that the number of builds done is the same as the number of build
 * configs in the group build's group config (NCL-6041)
 *
 * This is done to handle a weird timing error which happens when a group build finishes, the group build status is
 * updated before the last individual build status is updated to their final state. This may cause inconsistency in
 * the last build data.
 *
 * This is especially true when the Group build status is NO_REBUILD_REQUIRED, where it is also essential that all
 * the individual builds are also in their final state (and logically NO_REBUILD_REQUIRED status) so that we can get
 * the no rebuild cause.
 *
 * @param groupBuildId the group build id
 * @return whether all the builds have a final status or not
 */
boolean verifyAllBuildsInGroupBuildInFinalStateWithProperCount(String groupBuildId) {
    // log set to info for CPaaS to detect infinite loop
    log.info("Checking if all builds in group build {} are in final state with proper count of builds ( {} )", groupBuildId, UrlGenerator.generateGroupBuildUrl(groupBuildId));
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setLatest(false);
    filter.setRunning(false);
    try {
        Collection<Build> builds = groupBuildClient.getBuilds(groupBuildId, filter).getAll();
        boolean allFinal = builds.stream().allMatch(b -> b.getStatus().isFinal());
        return allFinal && getCountOfBuildConfigsForGroupBuild(groupBuildId) == builds.size();
    } catch (ClientException e) {
        log.warn("Failed to check if all builds in group build {} have a final status. Assuming it is not finished", groupBuildId, e);
        return false;
    }
}
Also used : Build(org.jboss.pnc.dto.Build) GroupBuild(org.jboss.pnc.dto.GroupBuild) ClientException(org.jboss.pnc.client.ClientException) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Example 9 with BuildsFilterParameters

use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project pnc by project-ncl.

the class AdvancedBuildConfigurationClient method fallbackSupplier.

/**
 * Used to retrieve build through through REST when WS Client loses connection and reconnects
 *
 * @param bcId Id of the BuildConfig where the build was run
 * @return
 * @throws RemoteResourceException
 */
private Build fallbackSupplier(String bcId) throws RemoteResourceException {
    BuildsFilterParameters parameters = new BuildsFilterParameters();
    parameters.setLatest(true);
    Build build = null;
    try (BuildConfigurationClient client = new BuildConfigurationClient(configuration)) {
        build = client.getBuilds(bcId, parameters).iterator().next();
    }
    return build;
}
Also used : Build(org.jboss.pnc.dto.Build) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Example 10 with BuildsFilterParameters

use of org.jboss.pnc.rest.api.parameters.BuildsFilterParameters in project pnc by project-ncl.

the class BuildEndpointTest method shouldFilterByBuildConfigurationNameAndInvalidUserId.

@Test
public void shouldFilterByBuildConfigurationNameAndInvalidUserId() throws Exception {
    BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
    String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
    String username = "random-user-name";
    String rsql = "user.username==" + username;
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setBuildConfigName(buildConfigName);
    List<Build> builds = new ArrayList<>(client.getAll(filter, null, Optional.empty(), Optional.of(rsql)).getAll());
    assertThat(builds).isEmpty();
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) ArrayList(java.util.ArrayList) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

BuildsFilterParameters (org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)14 Build (org.jboss.pnc.dto.Build)13 ContainerTest (org.jboss.pnc.test.category.ContainerTest)9 Test (org.junit.Test)9 BuildClient (org.jboss.pnc.client.BuildClient)7 ArrayList (java.util.ArrayList)3 ClientException (org.jboss.pnc.client.ClientException)3 GroupBuild (org.jboss.pnc.dto.GroupBuild)3 InSequence (org.jboss.arquillian.junit.InSequence)2 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)2 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)2 BuildStatus (org.jboss.pnc.enums.BuildStatus)2 RestAssured.given (io.restassured.RestAssured.given)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 Instant (java.time.Instant)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1