Search in sources :

Example 81 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class DefaultBuildCoordinator method completeBuild.

public void completeBuild(BuildTask buildTask, BuildResult buildResult) {
    String buildTaskId = buildTask.getId();
    BuildCoordinationStatus coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
    try {
        if (buildResult.hasFailed()) {
            CompletionStatus operationCompletionStatus = buildResult.getCompletionStatus();
            switch(operationCompletionStatus) {
                case SYSTEM_ERROR:
                    ProcessException exception;
                    if (buildResult.getProcessException().isPresent()) {
                        exception = buildResult.getProcessException().get();
                        log.debug("[buildTaskId: {}] Storing build result with exception {}.", buildTaskId, exception.getMessage());
                    } else if (buildResult.getRepourResult().isPresent()) {
                        RepourResult repourResult = buildResult.getRepourResult().get();
                        if (repourResult.getCompletionStatus().isFailed()) {
                            exception = new ProcessException("Repour completed with system error.");
                            log.debug("[buildTaskId: {}] Storing build result with system error from repour: {}.", buildTaskId, repourResult.getLog());
                        } else {
                            exception = new ProcessException("Build completed with system error but no exception.");
                            log.error("[buildTaskId: {}] Storing build result with system_error and missing exception.", buildTaskId);
                        }
                    } else {
                        exception = new ProcessException("Build completed with system error but no exception and no Repour result.");
                        log.error("[buildTaskId: {}] Storing build result with system_error no exception and no Repour result.", buildTaskId);
                    }
                    datastoreAdapter.storeResult(buildTask, Optional.of(buildResult), exception);
                    coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
                    break;
                case CANCELLED:
                case TIMED_OUT:
                    log.debug("[buildTaskId: {}] Storing failed build result. FailedReasonStatus: {}", buildTaskId, operationCompletionStatus);
                    datastoreAdapter.storeResult(buildTask, buildResult);
                    coordinationStatus = BuildCoordinationStatus.CANCELLED;
                    break;
                case FAILED:
                    log.debug("[buildTaskId: {}] Storing failed build result. FailedReasonStatus: {}", buildTaskId, operationCompletionStatus);
                    datastoreAdapter.storeResult(buildTask, buildResult);
                    coordinationStatus = BuildCoordinationStatus.DONE_WITH_ERRORS;
                    break;
                case SUCCESS:
                    throw new BuildCoordinationException("Failed task with SUCCESS completion status ?!.");
            }
        } else {
            log.debug("[buildTaskId: {}] Storing success build result.", buildTaskId);
            BuildRecord buildRecord = datastoreAdapter.storeResult(buildTask, buildResult);
            if (buildRecord.getStatus().completedSuccessfully()) {
                coordinationStatus = BuildCoordinationStatus.DONE;
            } else {
                log.warn("[buildTaskId: {}] Something went wrong while storing the success result. The status has changed to {}.", buildTaskId, buildRecord.getStatus());
                coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
            }
        }
        updateBuildTaskStatus(buildTask, coordinationStatus);
    } catch (Throwable e) {
        log.error("[buildTaskId: " + buildTaskId + "] Cannot store results to datastore.", e);
        updateBuildTaskStatus(buildTask, BuildCoordinationStatus.SYSTEM_ERROR);
    } finally {
        // Starts when the build execution completes
        ProcessStageUtils.logProcessStageEnd("FINALIZING_BUILD", "Finalizing completed.");
    }
}
Also used : BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 82 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class DefaultBuildCoordinatorTest method shouldStoreSshCredentialsOnSshEnabled.

@Test
public void shouldStoreSshCredentialsOnSshEnabled() throws DatastoreException {
    BuildTask buildTask = mockBuildTask();
    BuildResult buildResult = mockBuildResult(true);
    SshCredentials sshCredentials = new SshCredentials();
    sshCredentials.setCommand(RandomStringUtils.randomAlphabetic(30));
    sshCredentials.setPassword(RandomStringUtils.randomAlphabetic(30));
    when(buildResult.getEnvironmentDriverResult()).thenReturn(Optional.of(new EnvironmentDriverResult(CompletionStatus.FAILED, "", Optional.of(sshCredentials))));
    when(buildResult.getRepourResult()).thenReturn(Optional.of(RepourResultMock.mock()));
    ArgumentGrabbingAnswer<BuildRecord.Builder> answer = new ArgumentGrabbingAnswer<>(BuildRecord.Builder.class);
    when(datastore.storeCompletedBuild(any(BuildRecord.Builder.class), any(), any())).thenAnswer(answer);
    coordinator.completeBuild(buildTask, buildResult);
    assertThat(answer.arguments).hasSize(1);
    BuildRecord.Builder builder = answer.arguments.iterator().next();
    BuildRecord record = builder.build();
    assertThat(record.getSshCommand()).isEqualTo(sshCredentials.getCommand());
    assertThat(record.getSshPassword()).isEqualTo(sshCredentials.getPassword());
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) SshCredentials(org.jboss.pnc.spi.SshCredentials) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 83 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildResultPushManagerTest method buildRecord.

private BuildRecord buildRecord(boolean withExecutionRootName) {
    BuildRecord record = new BuildRecord();
    record.setId(new Base32LongID(Sequence.nextId()));
    record.setStatus(BuildStatus.SUCCESS);
    record.setBuildConfigurationAudited(bca);
    record.setDependencies(Collections.emptySet());
    record.setStartTime(new Date());
    record.setEndTime(new Date());
    record.setScmRepoURL("https://example.com/foo.git");
    record.setScmRevision("abcdef012345");
    if (withExecutionRootName) {
        record.setExecutionRootName("execution:root");
    }
    buildRecordRepository.save(record);
    return record;
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord) Date(java.util.Date)

Example 84 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildResultPushManagerTest method shouldAccept.

@Test
public void shouldAccept() {
    // given
    BuildRecord record = buildRecord(true);
    record.setExecutionRootName("Foo:bar");
    record.setExecutionRootVersion("baz");
    // when
    Result result = release(record);
    // then
    assertThat(result).extracting(Result::getStatus).isEqualTo(BuildPushStatus.ACCEPTED);
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) Result(org.jboss.pnc.bpm.causeway.Result) Test(org.junit.Test)

Example 85 with BuildRecord

use of org.jboss.pnc.model.BuildRecord in project pnc by project-ncl.

the class BuildResultPushManagerTest method shouldRejectWhenSameBuildIdIsInProgress.

@Test
public void shouldRejectWhenSameBuildIdIsInProgress() {
    // given
    BuildRecord record = buildRecord(true);
    // when
    release(record);
    Result result = release(record);
    // then
    assertThat(result).extracting(Result::getStatus).isEqualTo(BuildPushStatus.REJECTED);
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) Result(org.jboss.pnc.bpm.causeway.Result) Test(org.junit.Test)

Aggregations

BuildRecord (org.jboss.pnc.model.BuildRecord)92 Test (org.junit.Test)50 Base32LongID (org.jboss.pnc.model.Base32LongID)19 Build (org.jboss.pnc.dto.Build)15 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)15 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 Artifact (org.jboss.pnc.model.Artifact)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)13 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)13 Date (java.util.Date)12 List (java.util.List)12 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)12 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)11 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 BuildStatus (org.jboss.pnc.enums.BuildStatus)10