Search in sources :

Example 76 with BuildRecord

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

the class RSQLPredicateProducerTest method testCriteriaPredicateUnknownQuery.

@Test
public void testCriteriaPredicateUnknownQuery() {
    org.jboss.pnc.spi.datastore.repositories.api.Predicate<BuildRecord> criteriaPredicate = producer.getCriteriaPredicate(BuildRecord.class, "fieldThatDoesNotExists==\"FooBar\"");
    CriteriaBuilder cb = mock(CriteriaBuilder.class);
    Root<BuildRecord> root = mock(Root.class);
    try {
        criteriaPredicate.apply(root, null, cb);
        fail("Exception expected");
    } catch (RuntimeException ex) {
    // ok
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 77 with BuildRecord

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

the class RSQLPredicateProducerTest method testCriteriaPredicate.

@Test
public void testCriteriaPredicate() {
    Base32LongID id = new Base32LongID(4L);
    org.jboss.pnc.spi.datastore.repositories.api.Predicate<BuildRecord> criteriaPredicate = producer.getCriteriaPredicate(BuildRecord.class, "id==" + id.getId());
    CriteriaBuilder cb = mock(CriteriaBuilder.class);
    Root<BuildRecord> root = mock(Root.class);
    SingularAttributePath<Base32LongID> idPath = mock(SingularAttributePath.class);
    when(root.get(BuildRecord_.id)).thenReturn(idPath);
    Mockito.doReturn(Base32LongID.class).when(idPath).getJavaType();
    SingularAttribute pathAttribute = mock(SingularAttribute.class);
    java.lang.reflect.Member javaMember = mock(java.lang.reflect.Member.class);
    Mockito.doReturn(BuildRecord.class).when(javaMember).getDeclaringClass();
    Mockito.doReturn(javaMember).when(pathAttribute).getJavaMember();
    Mockito.doReturn("id").when(pathAttribute).getName();
    Mockito.doReturn(pathAttribute).when(idPath).getAttribute();
    criteriaPredicate.apply(root, null, cb);
    Mockito.verify(cb).equal(idPath, id);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Test(org.junit.Test)

Example 78 with BuildRecord

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

the class DatastoreAdapter method storeRecordForNoRebuild.

public BuildRecord storeRecordForNoRebuild(BuildTask buildTask) throws DatastoreException {
    try {
        log.debug("Storing record for non required rebuild of buildTask [{}] to datastore.", buildTask.getId());
        BuildRecord buildRecord = initBuildRecordBuilder(buildTask).status(BuildStatus.NO_REBUILD_REQUIRED).appendLog("No rebuild was required.").buildContentId(buildTask.getContentId()).build();
        BuildRecord storedRecord = datastore.storeRecordForNoRebuild(buildRecord);
        userLog.info("Successfully completed.");
        return storedRecord;
    } catch (Exception e) {
        return storeResult(buildTask, Optional.empty(), e);
    }
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException)

Example 79 with BuildRecord

use of org.jboss.pnc.model.BuildRecord 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 80 with BuildRecord

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

the class TemporaryBuildsCleaner method deleteTemporaryBuild.

private Result deleteTemporaryBuild(BuildRecord buildRecord, String authToken) throws ValidationException {
    if (!buildRecord.isTemporaryBuild()) {
        throw new ValidationException("Only deletion of the temporary builds is allowed");
    }
    // first delete BRs where this build is noRebuildCause
    List<BuildRecord> noRebuildBRs = buildRecordRepository.getBuildByCausingRecord(buildRecord.getId());
    for (BuildRecord noRebuildBR : noRebuildBRs) {
        log.info("Deleting build " + noRebuildBR.getId() + " which has noRebuildCause " + buildRecord.getId() + ".");
        deleteTemporaryBuild(noRebuildBR.getId(), authToken);
    }
    // delete the build itself
    log.info("Starting deletion of a temporary build " + buildRecord + "; Built artifacts: " + buildRecord.getBuiltArtifacts() + "; Dependencies: " + buildRecord.getDependencies());
    String externalBuildId = BuildMapper.idMapper.toDto(buildRecord.getId());
    Result result = remoteBuildsCleaner.deleteRemoteBuilds(buildRecord, authToken);
    if (!result.isSuccess()) {
        log.error("Failed to delete remote temporary builds for BR.id:{}.", buildRecord.getId());
        return new Result(externalBuildId, ResultStatus.FAILED, "Failed to delete remote temporary builds.");
    }
    removeBuiltArtifacts(buildRecord);
    buildRecordRepository.delete(buildRecord.getId());
    log.info("Deletion of the temporary build {} finished successfully.", buildRecord);
    return new Result(externalBuildId, ResultStatus.SUCCESS);
}
Also used : ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildRecord(org.jboss.pnc.model.BuildRecord) Result(org.jboss.pnc.spi.coordinator.Result)

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