Search in sources :

Example 31 with Build

use of org.jboss.pnc.dto.Build 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 32 with Build

use of org.jboss.pnc.dto.Build 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 33 with Build

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

the class BuildConfigurationEndpointTest method testGetBuilds.

@Test
public void testGetBuilds() throws ClientException {
    BuildConfigurationClient client = new BuildConfigurationClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Build> all = client.getBuilds(configurationId, null);
    assertThat(all).hasSize(2).allMatch(b -> configurationId.equals(b.getBuildConfigRevision().getId()));
}
Also used : Build(org.jboss.pnc.dto.Build) BuildConfigurationWithLatestBuild(org.jboss.pnc.dto.BuildConfigurationWithLatestBuild) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 34 with Build

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

the class BuildEndpointTest method shouldModifyBuiltArtifactQualityLevels.

@Test
public void shouldModifyBuiltArtifactQualityLevels() throws RemoteResourceException {
    BuildClient client = new BuildClient(RestClientConfiguration.asSystem());
    String buildRecordId = build3Id;
    String REASON = "This artifact has become old enough";
    ArtifactClient artifactClient = new ArtifactClient(RestClientConfiguration.asSystem());
    Artifact newArtifact = artifactClient.create(Artifact.builder().artifactQuality(ArtifactQuality.NEW).buildCategory(BuildCategory.STANDARD).filename("builtArtifactInsertNew.jar").identifier("integration-test:built-artifact-new:jar:1.0").targetRepository(artifactClient.getSpecific("100").getTargetRepository()).md5("insert-md5-22").sha1("insert-22").sha256("insert-22").size(10L).build());
    client.setBuiltArtifacts(build3Id, Collections.singletonList(newArtifact.getId()));
    client.createBuiltArtifactsQualityLevelRevisions(buildRecordId, "BLACKListed", REASON);
    RemoteCollection<Artifact> artifacts = client.getBuiltArtifacts(buildRecordId);
    for (Artifact artifact : artifacts) {
        assertThat(artifact.getArtifactQuality()).isEqualTo(ArtifactQuality.BLACKLISTED);
        assertThat(artifact.getQualityLevelReason()).isEqualTo(REASON);
        assertThat(artifact.getModificationUser().getUsername()).isEqualTo("system");
    }
    Build withAttribute = client.getSpecific(buildRecordId);
    assertThat(withAttribute.getAttributes()).contains(entry(Attributes.BLACKLIST_REASON, REASON));
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) ArtifactClient(org.jboss.pnc.client.ArtifactClient) Artifact(org.jboss.pnc.dto.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 35 with Build

use of org.jboss.pnc.dto.Build 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

Build (org.jboss.pnc.dto.Build)71 Test (org.junit.Test)52 ContainerTest (org.jboss.pnc.test.category.ContainerTest)35 BuildClient (org.jboss.pnc.client.BuildClient)20 BuildRecord (org.jboss.pnc.model.BuildRecord)18 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)16 BuildStatus (org.jboss.pnc.enums.BuildStatus)15 GroupBuild (org.jboss.pnc.dto.GroupBuild)14 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)14 ArrayList (java.util.ArrayList)12 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)11 HashSet (java.util.HashSet)10 List (java.util.List)10 Set (java.util.Set)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Date (java.util.Date)9 Page (org.jboss.pnc.dto.response.Page)9 BuildMapper (org.jboss.pnc.mapper.api.BuildMapper)9 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)9