Search in sources :

Example 21 with Build

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

the class BuildProviderImplTest method testGetBuilds.

@Test
public void testGetBuilds() {
    // Prepare
    // hit
    mockBuildRecord();
    // hit
    mockBuildTask();
    // hit
    mockBuildRecord();
    // hit
    mockBuildTask();
    // hit
    mockBuildRecord();
    // hit
    mockBuildTask();
    // hit
    BuildRecord build2 = mockBuildRecord();
    // hit
    BuildTask build1 = mockBuildTask();
    // When
    BuildPageInfo pageInfo = new BuildPageInfo(0, 2, "", "", false, false, "");
    Page<Build> builds = provider.getBuilds(pageInfo);
    // Verify
    assertEquals(8, builds.getTotalHits());
    assertEquals(2, builds.getContent().size());
    Iterator<Build> it = builds.getContent().iterator();
    assertEquals(build1.getId(), it.next().getId());
    assertEquals(BuildMapper.idMapper.toDto(build2.getId()), it.next().getId());
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 22 with Build

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

the class BuildProviderImpl method getDependencyGraph.

@Override
public Graph<Build> getDependencyGraph(String buildId) {
    Build specific = getSpecific(buildId);
    if (specific == null) {
        throw new EmptyEntityException("there is no record for given buildId.");
    }
    org.jboss.util.graph.Graph<BuildWithDependencies> buildGraph = createBuildDependencyGraph(buildId);
    GraphDtoBuilder<BuildWithDependencies, Build> graphBuilder = new GraphDtoBuilder();
    return graphBuilder.from(buildGraph, Build.class, vertex -> vertex.getData().getBuild());
}
Also used : EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) GraphDtoBuilder(org.jboss.pnc.facade.util.GraphDtoBuilder) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build)

Example 23 with Build

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

the class BuildProviderImpl method setBuiltArtifacts.

@RolesAllowed(SYSTEM_USER)
@Override
public void setBuiltArtifacts(String buildId, List<String> artifactIds) {
    Set<Integer> ids = artifactIds.stream().map(Integer::valueOf).collect(Collectors.toSet());
    List<Artifact> artifacts = artifactRepository.queryWithPredicates(withIds(ids));
    if (ids.size() != artifacts.size()) {
        artifacts.stream().map(Artifact::getId).forEach(ids::remove);
        throw new InvalidEntityException("Artifacts not found, missing ids: " + ids);
    }
    final Base32LongID id = parseId(buildId);
    BuildRecord buildRecord = repository.queryById(id);
    for (Artifact artifact : artifacts) {
        if (artifact.getBuildRecord() != null && !id.equals(artifact.getBuildRecord().getId())) {
            throw new ConflictedEntryException("Artifact " + artifact.getId() + " is already marked as built by different build.", BuildRecord.class, BuildMapper.idMapper.toDto(artifact.getBuildRecord().getId()));
        }
        artifact.setBuildRecord(buildRecord);
    }
    HashSet<Artifact> oldBuiltArtifacts = new HashSet<>(buildRecord.getBuiltArtifacts());
    oldBuiltArtifacts.stream().filter(a -> !ids.contains(a.getId())).forEach(a -> a.setBuildRecord(null));
}
Also used : BigInteger(java.math.BigInteger) PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Vertex(org.jboss.util.graph.Vertex) Arrays(java.util.Arrays) RolesAllowed(javax.annotation.security.RolesAllowed) ArtifactRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactRepository) SYSTEM_USER(org.jboss.pnc.facade.providers.api.UserRoles.SYSTEM_USER) StringUtils(org.jboss.pnc.common.util.StringUtils) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) Map(java.util.Map) RunningBuildCount(org.jboss.pnc.dto.response.RunningBuildCount) BigInteger(java.math.BigInteger) EJBAccessException(javax.ejb.EJBAccessException) BuildConfigurationRevision(org.jboss.pnc.dto.BuildConfigurationRevision) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) User(org.jboss.pnc.model.User) BuildRef(org.jboss.pnc.dto.BuildRef) SortInfoProducer(org.jboss.pnc.spi.datastore.repositories.SortInfoProducer) Gerrit(org.jboss.pnc.common.gerrit.Gerrit) BuildProvider(org.jboss.pnc.facade.providers.api.BuildProvider) Set(java.util.Set) BuildRecordPredicates.withArtifactProduced(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withArtifactProduced) IdRev(org.jboss.pnc.model.IdRev) BuildRecordPredicates.withPerformedInMilestone(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withPerformedInMilestone) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecordPredicates.withBuildConfigurationId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigurationId) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) HttpUtils(org.jboss.pnc.common.util.HttpUtils) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildRecordPredicates.withoutImplicitDependants(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withoutImplicitDependants) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) StreamSupport(java.util.stream.StreamSupport) CorruptedDataException(org.jboss.pnc.facade.validation.CorruptedDataException) ResultMapper(org.jboss.pnc.mapper.api.ResultMapper) ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildRecordPredicates.withoutLinkedNRRRecordOlderThanTimestamp(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withoutLinkedNRRRecordOlderThanTimestamp) BuildRecord(org.jboss.pnc.model.BuildRecord) TemporaryBuildsCleanerAsyncInvoker(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleanerAsyncInvoker) Page(org.jboss.pnc.dto.response.Page) BuildRecordPredicates(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates) BuildRecordPredicates.withBuildConfigSetId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigSetId) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) BuildRecordPredicates.buildFinishedBefore(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.buildFinishedBefore) LongBase32IdConverter(org.jboss.pnc.common.pnc.LongBase32IdConverter) Date(java.util.Date) Spliterators(java.util.Spliterators) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) GraphUtils(org.jboss.pnc.common.graph.GraphUtils) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) DefaultPageInfo(org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo) UserService(org.jboss.pnc.facade.util.UserService) Graph(org.jboss.pnc.dto.response.Graph) BuildRecordPredicates.withUserId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withUserId) BuildConfigurationRevisionMapper(org.jboss.pnc.mapper.api.BuildConfigurationRevisionMapper) URI(java.net.URI) Stateless(javax.ejb.Stateless) PermitAll(javax.annotation.security.PermitAll) Collection(java.util.Collection) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Result(org.jboss.pnc.spi.coordinator.Result) BuildRecordInsights(org.jboss.pnc.dto.insights.BuildRecordInsights) RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) Math.min(java.lang.Math.min) Collectors(java.util.stream.Collectors) BuildStatus(org.jboss.pnc.enums.BuildStatus) Objects(java.util.Objects) BuildRecordPredicates.withBuildConfigSetRecordId(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigSetRecordId) List(java.util.List) GerritException(org.jboss.pnc.common.gerrit.GerritException) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) Optional(java.util.Optional) BuildRecordPredicates.withAttribute(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withAttribute) Spliterator(java.util.Spliterator) BuildRecordPredicates.withoutAttribute(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withoutAttribute) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Getter(lombok.Getter) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Function(java.util.function.Function) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) HashSet(java.util.HashSet) Inject(javax.inject.Inject) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) GraphBuilder(org.jboss.pnc.common.graph.GraphBuilder) Attributes(org.jboss.pnc.constants.Attributes) MergeIterator(org.jboss.pnc.facade.util.MergeIterator) NoSuchElementException(java.util.NoSuchElementException) SSHCredentials(org.jboss.pnc.dto.response.SSHCredentials) ArtifactPredicates.withIds(org.jboss.pnc.spi.datastore.predicates.ArtifactPredicates.withIds) TimeUtils(org.jboss.pnc.common.util.TimeUtils) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BuildRecordPredicates.withArtifactDependency(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withArtifactDependency) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BuildConfigurationPredicates.withProjectId(org.jboss.pnc.spi.datastore.predicates.BuildConfigurationPredicates.withProjectId) Consumer(java.util.function.Consumer) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) GraphDtoBuilder(org.jboss.pnc.facade.util.GraphDtoBuilder) Build(org.jboss.pnc.dto.Build) BuildRecordPredicates.withBuildConfigurationIds(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.withBuildConfigurationIds) Comparator(java.util.Comparator) Collections(java.util.Collections) Base32LongID(org.jboss.pnc.model.Base32LongID) ConflictedEntryException(org.jboss.pnc.facade.validation.ConflictedEntryException) Artifact(org.jboss.pnc.model.Artifact) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) BuildRecord(org.jboss.pnc.model.BuildRecord) HashSet(java.util.HashSet) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 24 with Build

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

the class BuildProviderImpl method getBuildGraphForGroupBuild.

@Override
public Graph<Build> getBuildGraphForGroupBuild(String groupBuildId) {
    BuildConfigSetRecord buildConfigSetRecord = buildConfigSetRecordRepository.queryById(Integer.valueOf(groupBuildId));
    if (buildConfigSetRecord == null) {
        throw new EmptyEntityException("Build group " + groupBuildId + " does not exists.");
    }
    List<String> runningAndStoredIds = getBuildIdsInTheGroup(buildConfigSetRecord);
    org.jboss.util.graph.Graph<BuildWithDependencies> buildGraph = new org.jboss.util.graph.Graph<>();
    for (String buildId : runningAndStoredIds) {
        org.jboss.util.graph.Graph<BuildWithDependencies> dependencyGraph = createBuildDependencyGraph(buildId);
        GraphUtils.merge(buildGraph, dependencyGraph);
        logger.trace("Merged graph from buildRecordId {} to BuildConfigSetRecordGraph {}; Edges {},", buildId, buildGraph, buildGraph.getEdges());
    }
    GraphDtoBuilder<BuildWithDependencies, Build> graphBuilder = new GraphDtoBuilder();
    Graph<Build> graphDto = graphBuilder.from(buildGraph, Build.class, vertex -> vertex.getData().getBuild());
    return graphDto;
}
Also used : GraphDtoBuilder(org.jboss.pnc.facade.util.GraphDtoBuilder) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) Graph(org.jboss.pnc.dto.response.Graph) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 25 with Build

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

the class BuildProviderImpl method getBuilds.

/**
 * Returns the page of builds (running or finished) filtered by given BuildPageInfo and predicate.
 */
private Page<Build> getBuilds(BuildPageInfo pageInfo, java.util.function.Predicate<BuildTask> predicate, Predicate<BuildRecord> dbPredicate) {
    List<Build> runningBuilds = readRunningBuilds(pageInfo, predicate);
    int firstPossibleDBIndex = pageInfo.getPageIndex() * pageInfo.getPageSize() - runningBuilds.size();
    int lastPossibleDBIndex = (pageInfo.getPageIndex() + 1) * pageInfo.getPageSize() - 1;
    int toSkip = min(runningBuilds.size(), pageInfo.getPageIndex() * pageInfo.getPageSize());
    Predicate<BuildRecord>[] predicates = preparePredicates(dbPredicate, pageInfo.getQ(), pageInfo.getBuildConfigName());
    Comparator<Build> comparing = Comparator.comparing(Build::getSubmitTime).reversed();
    if (!StringUtils.isEmpty(pageInfo.getSort())) {
        comparing = rsqlPredicateProducer.getComparator(pageInfo.getSort());
    }
    SortInfo sortInfo = rsqlPredicateProducer.getSortInfo(type, pageInfo.getSort());
    MergeIterator<Build> builds = new MergeIterator(runningBuilds.iterator(), new BuildIterator(firstPossibleDBIndex, lastPossibleDBIndex, pageInfo.getPageSize(), sortInfo, predicates), comparing);
    List<Build> resultList = StreamSupport.stream(Spliterators.spliteratorUnknownSize(builds, Spliterator.ORDERED | Spliterator.SORTED), false).skip(toSkip).limit(pageInfo.getPageSize()).collect(Collectors.toList());
    int hits = repository.count(predicates) + runningBuilds.size();
    return new Page<>(pageInfo.getPageIndex(), pageInfo.getPageSize(), (int) Math.ceil((double) hits / pageInfo.getPageSize()), hits, resultList);
}
Also used : BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build) Page(org.jboss.pnc.dto.response.Page) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) MergeIterator(org.jboss.pnc.facade.util.MergeIterator)

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