Search in sources :

Example 1 with BuildRef

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

the class BuildEndpointTest method shouldSortResults.

@Test
public void shouldSortResults() throws Exception {
    BuildClient bc = new BuildClient(RestClientConfiguration.asAnonymous());
    String sort = "=asc=submitTime";
    List<Long> notSorted = bc.getAll(null, null).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
    List<Long> sorted = bc.getAll(null, null, Optional.of(sort), Optional.empty()).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
    assertThat(notSorted).isNotEqualTo(sorted);
    assertThat(sorted).isSorted();
}
Also used : BuildRef(org.jboss.pnc.dto.BuildRef) BuildClient(org.jboss.pnc.client.BuildClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 2 with BuildRef

use of org.jboss.pnc.dto.BuildRef 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 3 with BuildRef

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

the class BuildInfoCollector method getBuildsFromGroupBuild.

/**
 * Get all the builds done in a build group. If the build finished with 'NO_REBUILD_REQUIRED', get the 'original'
 * successful build and return it instead If the build was successful, we don't grab the logs since they can be
 * quite long.
 *
 * @param groupBuild the group build to get the builds
 * @return The information on the group build and the builds performed
 */
public GroupBuildInfo getBuildsFromGroupBuild(GroupBuild groupBuild) {
    Map<String, PncBuild> result = new HashMap<>();
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setLatest(false);
    filter.setRunning(false);
    try {
        Collection<Build> builds = groupBuildClient.getBuilds(groupBuild.getId(), filter).getAll();
        for (Build build : builds) {
            PncBuild pncBuild;
            if (build.getStatus() == BuildStatus.NO_REBUILD_REQUIRED) {
                BuildRef buildRef = build.getNoRebuildCause();
                Build realBuild = buildClient.getSpecific(buildRef.getId());
                pncBuild = new PncBuild(realBuild);
            } else {
                pncBuild = new PncBuild(build);
            }
            pncBuild.addBuiltArtifacts(toList(buildClient.getBuiltArtifacts(pncBuild.getId())));
            result.put(pncBuild.getName(), pncBuild);
        }
        return new GroupBuildInfo(groupBuild, result);
    } catch (RemoteResourceException e) {
        throw new RuntimeException("Failed to get group build info for " + groupBuild.getId(), e);
    }
}
Also used : BuildRef(org.jboss.pnc.dto.BuildRef) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) HashMap(java.util.HashMap) GroupBuild(org.jboss.pnc.dto.GroupBuild) Build(org.jboss.pnc.dto.Build) GroupBuildInfo(org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)

Aggregations

BuildRef (org.jboss.pnc.dto.BuildRef)3 Build (org.jboss.pnc.dto.Build)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 PermitAll (javax.annotation.security.PermitAll)1 Stateless (javax.ejb.Stateless)1 Inject (javax.inject.Inject)1 GroupBuildInfo (org.jboss.pnc.bacon.pig.impl.config.GroupBuildInfo)1 BuildClient (org.jboss.pnc.client.BuildClient)1 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)1