Search in sources :

Example 36 with BuildRecord

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

the class BuildProviderImpl method update.

@RolesAllowed(SYSTEM_USER)
@Override
public Build update(String buildId, Build restEntity) {
    Base32LongID id = parseId(buildId);
    validateBeforeUpdating(id, restEntity);
    logger.debug("Updating build: " + restEntity.toString());
    BuildRecord entityInDB = repository.queryById(id);
    entityInDB.setStatus(restEntity.getStatus());
    return mapper.toDTO(entityInDB);
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 37 with BuildRecord

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

the class BuildProviderImpl method getByAttribute.

public Page<Build> getByAttribute(BuildPageInfo buildPageInfo, Map<String, String> attributeConstraints) {
    Set<Predicate<BuildRecord>> predicates = new HashSet<>();
    for (Map.Entry<String, String> entry : attributeConstraints.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (key.startsWith("!")) {
            predicates.add(withoutAttribute(key.substring(1)));
        } else {
            predicates.add(withAttribute(key, value));
        }
    }
    Predicate<BuildRecord> queryPredicate = rsqlPredicateProducer.getCriteriaPredicate(BuildRecord.class, buildPageInfo.getQ());
    predicates.add(queryPredicate);
    Predicate<BuildRecord>[] predicatesArray = predicates.toArray(new Predicate[predicates.size()]);
    PageInfo pageInfo = toPageInfo(buildPageInfo);
    SortInfo sortInfo = rsqlPredicateProducer.getSortInfo(type, buildPageInfo.getSort());
    List<BuildRecord> resultList = ((BuildRecordRepository) BuildProviderImpl.this.repository).queryWithPredicatesUsingCursor(pageInfo, sortInfo, predicatesArray);
    int hits = repository.count(predicatesArray);
    return new Page<>(buildPageInfo.getPageIndex(), buildPageInfo.getPageSize(), hits, resultList.stream().map(b -> mapper.toDTO(b)).collect(Collectors.toList()));
}
Also used : Page(org.jboss.pnc.dto.response.Page) BuildRecord(org.jboss.pnc.model.BuildRecord) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) Map(java.util.Map) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) HashSet(java.util.HashSet)

Example 38 with BuildRecord

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

the class BuildProviderImpl method getSshCredentials.

@Override
public SSHCredentials getSshCredentials(String buildId) {
    BuildRecord buildRecord = getBuildRecord(buildId);
    User user = null;
    try {
        user = userService.currentUser();
    } catch (IllegalStateException e) {
    // leaves user null
    }
    if (!buildRecord.getUser().equals(user)) {
        throw new EJBAccessException("Only user who executed the build is allowed to get the SSH credentials");
    }
    return SSHCredentials.builder().command(buildRecord.getSshCommand()).password(buildRecord.getSshPassword()).build();
}
Also used : User(org.jboss.pnc.model.User) BuildRecord(org.jboss.pnc.model.BuildRecord) EJBAccessException(javax.ejb.EJBAccessException)

Example 39 with BuildRecord

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

the class BuildConfigurationProviderImpl method populateBuildConfigWithLatestBuild.

private BuildConfigurationWithLatestBuild populateBuildConfigWithLatestBuild(BuildConfiguration buildConfig, List<BuildRecord> latestBuilds, List<BuildTask> runningBuilds) {
    Integer bcId = mapper.getIdMapper().toEntity(buildConfig.getId());
    Optional<BuildTask> latestBuildTask = runningBuilds.stream().filter(Objects::nonNull).filter(bt -> bt.getBuildConfigurationAudited().getId().equals(bcId)).max(Comparator.comparing(BuildTask::getSubmitTime));
    Optional<BuildRecord> latestBuildRecord = latestBuilds.stream().filter(br -> br.getBuildConfigurationId().equals(bcId)).findFirst();
    BuildRef latestBuild = latestBuildTask.map((bt -> (BuildRef) buildMapper.fromBuildTask(bt))).orElse(latestBuildRecord.map(buildMapper::toRef).orElse(null));
    String latestBuildUsername = latestBuildTask.map(bt -> bt.getUser().getUsername()).orElse(latestBuildRecord.map(br -> br.getUser().getUsername()).orElse(null));
    return BuildConfigurationWithLatestBuild.builderWithLatestBuild().buildConfig(buildConfig).latestBuild(latestBuild).latestBuildUsername(latestBuildUsername).build();
}
Also used : BuildConfigurationPredicates.withDependencyConfiguration(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withDependencyConfiguration) Notifier(org.jboss.pnc.spi.notifications.Notifier) Date(java.util.Date) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationPredicates.withScmRepositoryId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withScmRepositoryId) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildConfigurationMapper(org.jboss.pnc.mapper.api.BuildConfigurationMapper) BuildEnvironment(org.jboss.pnc.model.BuildEnvironment) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) RepositoryCreationResponse(org.jboss.pnc.dto.response.RepositoryCreationResponse) User(org.jboss.pnc.dto.User) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) BuildConfigurationRevisionMapper(org.jboss.pnc.mapper.api.BuildConfigurationRevisionMapper) SCMRepositoryProvider(org.jboss.pnc.facade.providers.api.SCMRepositoryProvider) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) WhenCreatingNew(org.jboss.pnc.dto.validation.groups.WhenCreatingNew) BuildRef(org.jboss.pnc.dto.BuildRef) Stateless(javax.ejb.Stateless) PermitAll(javax.annotation.security.PermitAll) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildProvider(org.jboss.pnc.facade.providers.api.BuildProvider) ValidationBuilder(org.jboss.pnc.facade.validation.ValidationBuilder) Set(java.util.Set) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) Collectors(java.util.stream.Collectors) BuildConfigCreationResponse(org.jboss.pnc.dto.response.BuildConfigCreationResponse) IdRev(org.jboss.pnc.model.IdRev) BuildConfigurationPredicates.withDependantConfiguration(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withDependantConfiguration) Objects(java.util.Objects) SequenceHandlerRepository(org.jboss.pnc.spi.datastore.repositories.SequenceHandlerRepository) List(java.util.List) ConflictedEntryValidator(org.jboss.pnc.facade.validation.ConflictedEntryValidator) RepositoryConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.RepositoryConfigurationRepository) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) BuildConfigurationPredicates.isNotArchived(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.isNotArchived) Optional(java.util.Optional) BuildConfigurationPredicates.withProductVersionId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProductVersionId) BuildConfigWithSCMRequest(org.jboss.pnc.dto.requests.BuildConfigWithSCMRequest) ProjectRepository(org.jboss.pnc.spi.datastore.repositories.ProjectRepository) BuildConfigurationCreation(org.jboss.pnc.dto.notification.BuildConfigurationCreation) JobNotificationType(org.jboss.pnc.enums.JobNotificationType) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildEnvironmentRepository(org.jboss.pnc.spi.datastore.repositories.BuildEnvironmentRepository) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) BuildConfigurationRef(org.jboss.pnc.dto.BuildConfigurationRef) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) HashSet(java.util.HashSet) UserMapper(org.jboss.pnc.mapper.api.UserMapper) SCMRepositoryMapper(org.jboss.pnc.mapper.api.SCMRepositoryMapper) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) BuildConfigurationProvider(org.jboss.pnc.facade.providers.api.BuildConfigurationProvider) ProductVersionRepository(org.jboss.pnc.spi.datastore.repositories.ProductVersionRepository) WhenUpdating(org.jboss.pnc.dto.validation.groups.WhenUpdating) Logger(org.slf4j.Logger) RepositoryConfiguration(org.jboss.pnc.model.RepositoryConfiguration) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigurationPredicates.withProjectId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProjectId) Page(org.jboss.pnc.dto.response.Page) Build(org.jboss.pnc.dto.Build) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildConfigurationWithLatestBuild(org.jboss.pnc.dto.BuildConfigurationWithLatestBuild) SCMRepository(org.jboss.pnc.dto.SCMRepository) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) MDCWrappers(org.jboss.pnc.common.concurrent.MDCWrappers) Comparator(java.util.Comparator) BuildConfigurationPredicates.withName(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withName) Collections(java.util.Collections) BuildConfigurationPredicates.withBuildConfigurationSetId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withBuildConfigurationSetId) BuildRef(org.jboss.pnc.dto.BuildRef) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Objects(java.util.Objects) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 40 with BuildRecord

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

the class BrewPusherImpl method doPushBuild.

private BuildPushResult doPushBuild(Base32LongID buildId, BuildPushParameters buildPushParameters, Long buildPushResultId) throws ProcessException {
    // TODO START timing event
    userLog.info("Push started.");
    // collect and validate input data
    BuildRecord buildRecord = getLatestSuccessfullyExecutedBuildRecord(buildId);
    if (buildRecord.getExecutionRootName() == null && !buildRecord.getBuildConfigurationAudited().getGenericParameters().containsKey(BREW_BUILD_NAME.name())) {
        throw new InvalidEntityException("Build " + buildId + " cannot be pushed to brew, because it is missing " + Attributes.BUILD_BREW_NAME + " attribute with brew name.");
    }
    List<Artifact> artifacts = artifactRepository.queryWithPredicates(ArtifactPredicates.withBuildRecordId(buildRecord.getId()));
    if (hasBadArtifactQuality(artifacts)) {
        String message = "Build contains artifacts of insufficient quality: BLACKLISTED/DELETED.";
        log.debug(message);
        BuildPushResult pushResult = BuildPushResult.builder().buildId(BuildMapper.idMapper.toDto(buildId)).status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).logContext(buildPushResultId.toString()).message(message).build();
        throw new OperationNotAllowedException(message, pushResult);
    }
    log.debug("Pushing Build.id {}.", buildRecord.getId());
    BuildPushOperation buildPushOperation = new BuildPushOperation(buildRecord, buildPushResultId, buildPushParameters.getTagPrefix(), buildPushParameters.isReimport(), getCompleteCallbackUrlTemplate());
    Result pushResult = buildResultPushManager.push(buildPushOperation, userService.currentUserToken());
    log.info("Push Result {}.", pushResult);
    BuildPushResult result = BuildPushResult.builder().id(pushResult.getId()).buildId(pushResult.getBuildId()).status(pushResult.getStatus()).logContext(pushResult.getId()).message(pushResult.getMessage()).build();
    // verify operation status
    switch(pushResult.getStatus()) {
        case ACCEPTED:
            userLog.info("Push ACCEPTED.");
            return result;
        case REJECTED:
            userLog.warn("Push REJECTED.");
            throw new AlreadyRunningException(pushResult.getMessage(), result);
        case SYSTEM_ERROR:
            userLog.error("Brew push failed: " + pushResult.getMessage());
            throw new ProcessException(pushResult.getMessage());
        default:
            userLog.error("Invalid push result status.");
            throw new ProcessException("Invalid push result status.");
    }
}
Also used : AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildPushOperation(org.jboss.pnc.bpm.causeway.BuildPushOperation) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) Artifact(org.jboss.pnc.model.Artifact) Result(org.jboss.pnc.bpm.causeway.Result) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult)

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