Search in sources :

Example 16 with BuildConfigurationAudited

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

the class BuildConfigProviderTest method testRestoreRevision.

@Test
public void testRestoreRevision() {
    // With
    final Integer revision = 1;
    final String restoredName = "Old guy";
    BuildConfigurationAudited bca = BuildConfigurationAudited.fromBuildConfiguration(bc, revision);
    bca.setName(restoredName);
    when(buildConfigurationAuditedRepository.queryById(new IdRev(bc.getId(), revision))).thenReturn(bca);
    // When
    provider.restoreRevision(bc.getId().toString(), revision);
    // Then
    org.jboss.pnc.dto.BuildConfiguration restored = provider.getSpecific(bc.getId().toString());
    assertThat(restored).isNotNull();
    assertThat(restored.getName()).isEqualTo(restoredName);
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) IdRev(org.jboss.pnc.model.IdRev) Test(org.junit.Test)

Example 17 with BuildConfigurationAudited

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

the class BuildProviderImpl method getSpecific.

@Override
public Build getSpecific(String buildId) {
    List<BuildTask> runningBuilds = buildCoordinator.getSubmittedBuildTasks();
    Build build = runningBuilds.stream().filter(buildTask -> buildId.equals(buildTask.getId())).findAny().map(buildMapper::fromBuildTask).orElse(null);
    // if build not in runningBuilds, check the database
    if (build == null) {
        // use findByIdFetchProperties instead of super.getSpecific to get 'BuildConfigurationAudited' object
        build = mapper.toDTO(buildRecordRepository.findByIdFetchProperties(parseId(buildId)));
    }
    return build;
}
Also used : 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) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build)

Example 18 with BuildConfigurationAudited

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

the class BuildConfigurationProviderImpl method restoreRevision.

@Override
public Optional<BuildConfiguration> restoreRevision(String id, int rev) {
    IdRev idRev = new IdRev(Integer.valueOf(id), rev);
    BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedRepository.queryById(idRev);
    org.jboss.pnc.model.BuildConfiguration originalBC = repository.queryById(Integer.valueOf(id));
    org.jboss.pnc.model.User user = userService.currentUser();
    if (buildConfigurationAudited == null || originalBC == null) {
        return Optional.empty();
    }
    originalBC.setName(buildConfigurationAudited.getName());
    originalBC.setBuildScript(buildConfigurationAudited.getBuildScript());
    originalBC.setRepositoryConfiguration(buildConfigurationAudited.getRepositoryConfiguration());
    originalBC.setScmRevision(buildConfigurationAudited.getScmRevision());
    originalBC.setBuildType(buildConfigurationAudited.getBuildType());
    originalBC.setBuildEnvironment(buildConfigurationAudited.getBuildEnvironment());
    originalBC.setGenericParameters(buildConfigurationAudited.getGenericParameters());
    originalBC.setLastModificationUser(user);
    org.jboss.pnc.model.BuildConfiguration newBc = repository.save(originalBC);
    newBc.getBuildConfigurationSets().forEach(BuildConfigurationSet::getId);
    newBc.getDependencies().forEach(org.jboss.pnc.model.BuildConfiguration::getId);
    repository.flushAndRefresh(newBc);
    return Optional.of(mapper.toDTO(newBc));
}
Also used : BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) IdRev(org.jboss.pnc.model.IdRev)

Example 19 with BuildConfigurationAudited

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

the class BuildTriggererImpl method loadAuditedsFromDB.

private Map<Integer, BuildConfigurationAudited> loadAuditedsFromDB(BuildConfigurationSet buildConfigurationSet, List<BuildConfigurationRevisionRef> buildConfigurationAuditedRests) throws InvalidEntityException {
    Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap = new HashMap<>();
    Set<IdRev> buildConfigurationAuditedRevs = nullableStreamOf(buildConfigurationAuditedRests).map(bcrRef -> new IdRev(Integer.valueOf(bcrRef.getId()), bcrRef.getRev())).collect(Collectors.toSet());
    if (!buildConfigurationAuditedRevs.isEmpty()) {
        Map<IdRev, BuildConfigurationAudited> buildConfigurationsAuditedMap = buildConfigurationAuditedRepository.queryById(buildConfigurationAuditedRevs);
        for (BuildConfigurationRevisionRef bc : buildConfigurationAuditedRests) {
            BuildConfigurationAudited buildConfigurationAudited = buildConfigurationsAuditedMap.get(new IdRev(Integer.valueOf(bc.getId()), bc.getRev()));
            Preconditions.checkArgument(buildConfigurationAudited != null, "Can't find Build Configuration with id=" + bc.getId() + ", rev=" + bc.getRev());
            buildConfigurationAudited = hibernateLazyInitializer.initializeBuildConfigurationAuditedBeforeTriggeringIt(buildConfigurationAudited);
            if (!buildConfigurationSet.getBuildConfigurations().contains(buildConfigurationAudited.getBuildConfiguration())) {
                throw new InvalidEntityException("BuildConfigurationSet " + buildConfigurationSet + " doesn't contain this BuildConfigurationAudited entity " + buildConfigurationAudited);
            }
            buildConfigurationAuditedsMap.put(buildConfigurationAudited.getId(), buildConfigurationAudited);
        }
    }
    return buildConfigurationAuditedsMap;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) HibernateLazyInitializer(org.jboss.pnc.facade.util.HibernateLazyInitializer) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) HashMap(java.util.HashMap) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) OptionalInt(java.util.OptionalInt) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) Inject(javax.inject.Inject) UserService(org.jboss.pnc.facade.util.UserService) Map(java.util.Map) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildTriggerer(org.jboss.pnc.facade.BuildTriggerer) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) GenericSettingProvider(org.jboss.pnc.facade.providers.GenericSettingProvider) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) CoreException(org.jboss.pnc.spi.exception.CoreException) StreamHelper.nullableStreamOf(org.jboss.pnc.common.util.StreamHelper.nullableStreamOf) GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) HashMap(java.util.HashMap) BuildConfigurationRevisionRef(org.jboss.pnc.dto.BuildConfigurationRevisionRef) IdRev(org.jboss.pnc.model.IdRev) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 20 with BuildConfigurationAudited

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

the class DatastoreAdapterTest method shouldStoreRepourResult.

@Test
public void shouldStoreRepourResult() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    RepourResult repourResult = RepourResultMock.mock();
    // when
    BuildConfiguration buildConfiguration = BuildConfiguration.Builder.newBuilder().name("Configuration.").build();
    BuildConfigurationAudited buildConfigurationAudited = BuildConfigurationAudited.Builder.newBuilder().buildConfiguration(buildConfiguration).build();
    BuildTask buildTask = mockBuildTask();
    BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
    BuildResult buildResult = new BuildResult(CompletionStatus.SUCCESS, Optional.empty(), "", Optional.of(buildExecutionConfiguration), Optional.of(BuildDriverResultMock.mockResult(BuildStatus.SUCCESS)), Optional.of(RepositoryManagerResultMock.mockResult()), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(repourResult));
    datastoreAdapter.storeResult(buildTask, buildResult);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(buildRecord.getStatus(), BuildStatus.SUCCESS);
    Assert.assertEquals(repourResult.getExecutionRootName(), buildRecord.getExecutionRootName());
    Assert.assertEquals(repourResult.getExecutionRootVersion(), buildRecord.getExecutionRootVersion());
    Assert.assertEquals(repourResult.getLog(), buildRecord.getRepourLog());
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Aggregations

BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)35 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 IdRev (org.jboss.pnc.model.IdRev)12 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)10 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)10 Test (org.junit.Test)8 HashSet (java.util.HashSet)7 BuildRecord (org.jboss.pnc.model.BuildRecord)6 Date (java.util.Date)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Map (java.util.Map)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 Base32LongID (org.jboss.pnc.model.Base32LongID)4 Collections (java.util.Collections)3 List (java.util.List)3 Optional (java.util.Optional)3 Stateless (javax.ejb.Stateless)3