Search in sources :

Example 16 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class BuildTest method dontRebuildTemporaryBuildWhenThereIsNewerPersistentOnSameRev.

// NCL-5192
// Replicates NCL-5192 through explicit dependency instead of implicit
@Test
public void dontRebuildTemporaryBuildWhenThereIsNewerPersistentOnSameRev() throws ClientException {
    BuildConfiguration parent = buildConfigurationClient.getAll(Optional.empty(), Optional.of("name==pnc-build-agent-0.4")).iterator().next();
    BuildConfiguration dependency = buildConfigurationClient.getAll(Optional.empty(), Optional.of("name==termd")).iterator().next();
    Instant oldLastModDateParent = parent.getModificationTime();
    BuildConfiguration updatedParent = parent.toBuilder().description("Random Description to be able to trigger build again so that temporary build will be first on this revision").buildScript("mvn" + "  clean deploy -DskipTests=true").build();
    buildConfigurationClient.update(updatedParent.getId(), updatedParent);
    updatedParent = buildConfigurationClient.getSpecific(updatedParent.getId());
    assertThat(oldLastModDateParent).isNotEqualTo(updatedParent.getModificationTime());
    Instant oldLastModDateDependency = parent.getModificationTime();
    BuildConfiguration updatedDependency = dependency.toBuilder().description("Random Description so it rebuilds").buildScript("mvn" + "   clean deploy -DskipTests=true").build();
    buildConfigurationClient.update(updatedDependency.getId(), updatedDependency);
    assertThat(oldLastModDateDependency).isNotEqualTo(updatedDependency.getModificationTime());
    EnumSet<BuildStatus> isIn = EnumSet.of(BuildStatus.SUCCESS);
    EnumSet<BuildStatus> isNotIn = EnumSet.of(BuildStatus.REJECTED, BuildStatus.NO_REBUILD_REQUIRED);
    // Build temporary builds (parent and dependency) on new revision
    Build temporaryBuild = buildConfigurationClient.trigger(parent.getId(), getTemporaryParameters());
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(temporaryBuild.getId(), isIn, isNotIn), 15, TimeUnit.SECONDS);
    // Build persistent build of dependency on the same revision
    Build dependencyPersistentBuild = buildConfigurationClient.trigger(dependency.getId(), getPersistentParameters());
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(dependencyPersistentBuild.getId(), isIn, isNotIn), 15, TimeUnit.SECONDS);
    // Build temporary build of parent and check it gets REJECTED even if it's dependency has newer record
    // (in this case temp build should ignore persistent one)
    Build finalRecord = buildConfigurationClient.trigger(parent.getId(), getTemporaryParameters());
    ResponseUtils.waitSynchronouslyFor(() -> buildToFinish(finalRecord.getId(), EnumSet.of(BuildStatus.NO_REBUILD_REQUIRED), null), 15, TimeUnit.SECONDS);
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 17 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class BuildStatusChangedTest method shouldSerializeObject.

@Test
public void shouldSerializeObject() throws IOException {
    // given
    Build build = getBuild();
    BuildStatus oldStatus = BuildStatus.NEW;
    BuildStatusChanged buildStatusChanged = BuildStatusChanged.builder().oldStatus(oldStatus.toString()).build(build).buildMe();
    // when
    String serialized = buildStatusChanged.toJson();
    logger.info("Serialized: {}", serialized);
    BuildStatusChanged deserialized = JsonOutputConverterMapper.readValue(serialized, BuildStatusChanged.class);
    // then
    Assertions.assertThat(deserialized).isEqualToComparingFieldByField(buildStatusChanged);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildStatus(org.jboss.pnc.enums.BuildStatus) Test(org.junit.Test)

Example 18 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class DatastoreAdapter method storeResult.

public BuildRecord storeResult(BuildTask buildTask, BuildResult buildResult) throws DatastoreException {
    try {
        BuildStatus buildRecordStatus = NEW;
        BuildRecord.Builder buildRecordBuilder = initBuildRecordBuilder(buildTask);
        buildRecordBuilder.buildContentId(buildTask.getContentId());
        if (buildResult.getRepourResult().isPresent()) {
            RepourResult repourResult = buildResult.getRepourResult().get();
            buildRecordBuilder.repourLog(repourResult.getLog());
            buildRecordBuilder.executionRootName(repourResult.getExecutionRootName());
            buildRecordBuilder.executionRootVersion(repourResult.getExecutionRootVersion());
            CompletionStatus repourCompletionStatus = repourResult.getCompletionStatus();
            if (repourCompletionStatus != null) {
                switch(repourCompletionStatus) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordBuilder.appendLog("\nBuild failed during the alignment phase, please check the 'Alignment Log' tab for more information.\n");
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordBuilder.appendLog("\nBuild cancelled during alignment phase.\n");
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                        buildRecordBuilder.appendLog("\nBuild timed-out during alignment phase.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    case SYSTEM_ERROR:
                        buildRecordBuilder.appendLog("\nBuild failed with SYSTEM_ERROR during the alignment phase, " + "please check the 'Alignment Log' tab for more information.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the alignment phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
        } else {
            userLog.warn("Missing Repour Result!");
            log.warn("[BuildTask:" + buildTask.getId() + "] Missing RepourResult.");
        }
        if (buildResult.getBuildDriverResult().isPresent()) {
            BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
            buildRecordBuilder.appendLog(buildDriverResult.getBuildLog());
            buildDriverResult.getOutputChecksum().ifPresent(buildRecordBuilder::buildOutputChecksum);
            // TODO buildRecord should use CompletionStatus
            buildRecordStatus = buildDriverResult.getBuildStatus();
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildDriverResult."));
        }
        if (buildResult.getEnvironmentDriverResult().isPresent()) {
            EnvironmentDriverResult environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
            buildRecordBuilder.appendLog(environmentDriverResult.getLog());
            environmentDriverResult.getSshCredentials().ifPresent(c -> {
                buildRecordBuilder.sshCommand(c.getCommand());
                buildRecordBuilder.sshPassword(c.getPassword());
            });
            if (environmentDriverResult.getCompletionStatus() != null) {
                switch(environmentDriverResult.getCompletionStatus()) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                    case SYSTEM_ERROR:
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the environment setup phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
        }
        List<Artifact> builtArtifacts = Collections.emptyList();
        List<Artifact> dependencies = Collections.emptyList();
        if (buildResult.getRepositoryManagerResult().isPresent()) {
            RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
            buildRecordBuilder.appendLog(repositoryManagerResult.getLog());
            if (repositoryManagerResult.getCompletionStatus() != null) {
                switch(// TODO, do not mix statuses
                repositoryManagerResult.getCompletionStatus()) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                    case SYSTEM_ERROR:
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the promotion phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
            builtArtifacts = repositoryManagerResult.getBuiltArtifacts();
            Map<Artifact, String> builtConflicts = datastore.checkForBuiltArtifacts(builtArtifacts);
            if (builtConflicts.size() > 0) {
                return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with invalid repository manager result. Conflicting artifact data found: " + builtConflicts.toString()));
            }
            dependencies = repositoryManagerResult.getDependencies();
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing RepositoryManagerResult."));
        }
        if (NEW.equals(buildRecordStatus)) {
            switch(buildResult.getCompletionStatus()) {
                case SUCCESS:
                case NO_REBUILD_REQUIRED:
                case FAILED:
                case SYSTEM_ERROR:
                    break;
                case CANCELLED:
                    buildRecordStatus = CANCELLED;
                    break;
                case TIMED_OUT:
                    buildRecordStatus = SYSTEM_ERROR;
                    buildRecordBuilder.appendLog("-- Operation TIMED-OUT --");
                    userLog.warn("Operation TIMED-OUT.");
                    break;
                default:
                    buildRecordBuilder.appendLog("\nInvalid status detected in the final completion status, failing with SYSTEM_ERROR.\n");
                    break;
            }
        }
        log.debug("Setting status " + buildRecordStatus.toString() + " to buildRecord.");
        buildRecordBuilder.status(buildRecordStatus);
        if (buildResult.getBuildExecutionConfiguration().isPresent()) {
            BuildExecutionConfiguration buildExecutionConfig = buildResult.getBuildExecutionConfiguration().get();
            buildRecordBuilder.scmRepoURL(buildExecutionConfig.getScmRepoURL());
            buildRecordBuilder.scmRevision(buildExecutionConfig.getScmRevision());
            buildRecordBuilder.scmTag(buildExecutionConfig.getScmTag());
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildExecutionConfiguration."));
        }
        log.debug("Storing results of buildTask [{}] to datastore.", buildTask.getId());
        userLog.info("Successfully completed.");
        return datastore.storeCompletedBuild(buildRecordBuilder, builtArtifacts, dependencies);
    } catch (Exception e) {
        return storeResult(buildTask, Optional.of(buildResult), e);
    }
}
Also used : BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildStatus(org.jboss.pnc.enums.BuildStatus) RepourResult(org.jboss.pnc.spi.repour.RepourResult)

Example 19 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class BuildCoordinationTest method buildConfigSetRecordShouldBeMarkedFailedOnFailure.

@Test
public void buildConfigSetRecordShouldBeMarkedFailedOnFailure() throws CoreException, TimeoutException, InterruptedException {
    BuildConfigurationSet buildConfigurationSet = TestEntitiesFactory.newBuildConfigurationSet();
    testProjectConfigurationBuilder.buildConfigurationWithDependenciesThatFail(buildConfigurationSet);
    ObjectWrapper<BuildSetStatus> lastBuildSetStatus = registerCallback(buildConfigurationSet);
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setRebuildMode(RebuildMode.FORCE);
    BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, TestEntitiesFactory.newUser(), buildOptions);
    Wait.forCondition(lastBuildSetStatus::isSet, 5, ChronoUnit.SECONDS);
    // check the result
    Assert.assertEquals(BuildSetStatus.DONE, lastBuildSetStatus.get());
    datastoreMock.getBuildConfigSetRecordById(buildConfigurationSet.getId());
    Optional<BuildConfigSetRecord> maybeSetRecord = buildSetTask.getBuildConfigSetRecord();
    assertThat(maybeSetRecord.isPresent()).isTrue();
    Assert.assertEquals(BuildStatus.FAILED, maybeSetRecord.get().getStatus());
    Collection<BuildStatus> statuses = getBuildStatuses();
    // dependent build failed with
    Assert.assertTrue(statuses.contains(BuildStatus.REJECTED_FAILED_DEPENDENCIES));
    // system error
    Assert.assertFalse(statuses.contains(BuildStatus.SYSTEM_ERROR));
    assertEmptyQueue();
}
Also used : BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildStatus(org.jboss.pnc.enums.BuildStatus) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Test(org.junit.Test)

Example 20 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class DefaultBuildCoordinator method updateBuildTaskStatus.

private void updateBuildTaskStatus(BuildTask task, BuildCoordinationStatus status, String statusDescription) {
    BuildCoordinationStatus oldStatus = task.getStatus();
    // REJECTED_ALREADY_BUILT -> DONE
    if (status.isCompleted() && !oldStatus.isCompleted()) {
        markFinished(task, status, statusDescription);
    } else {
        task.setStatus(status);
        task.setStatusDescription(statusDescription);
    }
    Build build = buildMapper.fromBuildTask(task);
    BuildStatusChangedEvent buildStatusChanged = new DefaultBuildStatusChangedEvent(build, BuildStatus.fromBuildCoordinationStatus(oldStatus), BuildStatus.fromBuildCoordinationStatus(status));
    log.debug("Updated build task {} status to {}; old coord status: {}, new coord status: {}", task.getId(), buildStatusChanged, oldStatus, status);
    userLog.info("Build status updated to {}; previous: {}", status, oldStatus);
    BuildStatus oldBuildStatus = BuildStatus.fromBuildCoordinationStatus(oldStatus);
    BuildStatus newBuildStatus = BuildStatus.fromBuildCoordinationStatus(status);
    if ((oldBuildStatus != newBuildStatus) && !(oldBuildStatus.isFinal() && newBuildStatus.isFinal())) {
        // only fire notification when BuildStatus changes
        // and avoid firing the notification when old and new statuses are final (NCL-5885)
        buildStatusChangedEventNotifier.fire(buildStatusChanged);
        log.debug("Fired buildStatusChangedEventNotifier after task {} status update to {}.", task.getId(), status);
    }
}
Also used : BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Build(org.jboss.pnc.dto.Build) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) BuildStatus(org.jboss.pnc.enums.BuildStatus)

Aggregations

BuildStatus (org.jboss.pnc.enums.BuildStatus)20 Test (org.junit.Test)14 GroupBuild (org.jboss.pnc.dto.GroupBuild)10 ContainerTest (org.jboss.pnc.test.category.ContainerTest)10 Build (org.jboss.pnc.dto.Build)9 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)7 Instant (java.time.Instant)4 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)3 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)3 GroupBuildParameters (org.jboss.pnc.rest.api.parameters.GroupBuildParameters)3 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)3 Consumer (java.util.function.Consumer)2 DatastoreAdapter (org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter)2 BuildCoordinationStatus (org.jboss.pnc.enums.BuildCoordinationStatus)2 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ArrayList (java.util.ArrayList)1