Search in sources :

Example 1 with ArtifactQuality

use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.

the class IndyRepositorySession method collectUploads.

/**
 * Return list of output artifacts for promotion.
 *
 * @param report The tracking report that contains info about artifacts uploaded (output) from the build
 * @return List of output artifacts meta data
 * @throws RepositoryManagerException In case of a client API transport error or an error during promotion of
 *         artifacts
 */
private Uploads collectUploads(TrackedContentDTO report) throws RepositoryManagerException {
    List<Artifact> data;
    List<String> promotion;
    logger.info("BEGIN: Process artifacts uploaded from build");
    userLog.info("Processing built artifacts");
    StopWatch stopWatch = StopWatch.createStarted();
    Set<TrackedContentEntryDTO> uploads = report.getUploads();
    if (CollectionUtils.isEmpty(uploads)) {
        data = Collections.emptyList();
        promotion = Collections.emptyList();
    } else {
        data = new ArrayList<>();
        Set<String> promotionSet = new HashSet<>();
        IndyContentClientModule content;
        try {
            content = indy.content();
        } catch (IndyClientException e) {
            throw new RepositoryManagerException("Failed to retrieve Indy content module. Reason: %s", e, e.getMessage());
        }
        for (TrackedContentEntryDTO upload : uploads) {
            String path = upload.getPath();
            StoreKey storeKey = upload.getStoreKey();
            if (artifactFilter.acceptsForData(upload)) {
                String identifier = computeIdentifier(upload);
                String purl = computePurl(upload);
                logger.info("Recording upload: {}", identifier);
                RepositoryType repoType = toRepoType(storeKey.getPackageType());
                TargetRepository targetRepository = getUploadsTargetRepository(repoType, content);
                ArtifactQuality artifactQuality = getArtifactQuality(isTempBuild);
                Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(upload.getMd5()).sha1(upload.getSha1()).sha256(upload.getSha256()).size(upload.getSize()).deployPath(upload.getPath()).filename(new File(path).getName()).identifier(identifier).purl(purl).targetRepository(targetRepository).artifactQuality(artifactQuality).buildCategory(buildCategory);
                Artifact artifact = validateArtifact(artifactBuilder.build());
                data.add(artifact);
            }
            if (artifactFilter.acceptsForPromotion(upload, false)) {
                promotionSet.add(path);
                if (MAVEN_PKG_KEY.equals(storeKey.getPackageType()) && !isChecksum(path)) {
                    // add the standard checksums to ensure, they are promoted (Maven usually uses only one, so
                    // the other would be missing) but avoid adding checksums of checksums.
                    promotionSet.add(path + ".md5");
                    promotionSet.add(path + ".sha1");
                }
            }
        }
        promotion = new ArrayList<>(promotionSet);
    }
    logger.info("END: Process artifacts uploaded from build, took {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
    return new Uploads(data, promotion);
}
Also used : RepositoryType(org.jboss.pnc.enums.RepositoryType) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) StopWatch(org.apache.commons.lang3.time.StopWatch) TargetRepository(org.jboss.pnc.model.TargetRepository) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyContentClientModule(org.commonjava.indy.client.core.module.IndyContentClientModule) IndyClientException(org.commonjava.indy.client.core.IndyClientException) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with ArtifactQuality

use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.

the class TemporaryBuildsCleanerTest method shouldReturnOnlyTopLevelTemporaryBuilds.

@Test
public void shouldReturnOnlyTopLevelTemporaryBuilds() throws Exception {
    // with
    // top level BR1
    BuildRecord br1 = initBuildRecordBuilder().temporaryBuild(true).build();
    br1 = buildRecordRepository.save(br1);
    Artifact art1br1 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br1).build();
    Artifact art2br1 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br1).build();
    artifactRepository.save(art1br1);
    artifactRepository.save(art2br1);
    Set<Artifact> depArtBr2 = new HashSet<>();
    // independent BR2
    BuildRecord br2 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr2).build();
    br2 = buildRecordRepository.save(br2);
    Artifact art1br2 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br2).build();
    Artifact art2br2 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br2).build();
    artifactRepository.save(art1br2);
    artifactRepository.save(art2br2);
    Set<Artifact> depArtBr3 = new HashSet<>();
    depArtBr3.add(art1br1);
    depArtBr3.add(art1br2);
    // create implicitly dependent BR3 (BR3 is dependent on BR1)
    BuildRecord br3 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr3).build();
    br3 = buildRecordRepository.save(br3);
    Artifact art1br3 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br3).build();
    Artifact art2br3 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br3).build();
    artifactRepository.save(art1br3);
    artifactRepository.save(art2br3);
    Set<Artifact> depArtBr4 = new HashSet<>();
    depArtBr4.add(art2br2);
    depArtBr4.add(art1br3);
    // create implicitly dependent BR4 (BR4 is dependent on BR2 and BR3)
    BuildRecord br4 = initBuildRecordBuilder().temporaryBuild(true).dependencies(depArtBr4).build();
    br4 = buildRecordRepository.save(br4);
    Artifact art1br4 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br4).build();
    Artifact art2br4 = initArtifactBuilder().artifactQuality(ArtifactQuality.TEMPORARY).buildRecord(br4).build();
    artifactRepository.save(art1br4);
    artifactRepository.save(art2br4);
    BuildRecord finalBr1 = br1;
    Condition<Build> hasBr1 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr1.getId()))), "Is Br1 with id " + BuildMapper.idMapper.toDto(finalBr1.getId()));
    BuildRecord finalBr2 = br2;
    Condition<Build> hasBr2 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr2.getId()))), "Is Br2 with id " + BuildMapper.idMapper.toDto(finalBr2.getId()));
    BuildRecord finalBr3 = br3;
    Condition<Build> hasBr3 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr3.getId()))), "Is Br3 with id " + BuildMapper.idMapper.toDto(finalBr3.getId()));
    BuildRecord finalBr4 = br4;
    Condition<Build> hasBr4 = new Condition<>((build -> build.getId().equals(BuildMapper.idMapper.toDto(finalBr4.getId()))), "Is Br4 with id " + BuildMapper.idMapper.toDto(finalBr4.getId()));
    // when #1
    Page<Build> builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
    // then #1
    assertThat(builds.getContent()).doNotHave(hasBr1).doNotHave(hasBr2).doNotHave(hasBr3).haveExactly(1, hasBr4);
    // when #2
    temporaryBuildsCleaner.deleteTemporaryBuild(br4.getId(), "");
    builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
    // then #2
    assertThat(builds.getContent()).doNotHave(hasBr1).doNotHave(hasBr2).haveExactly(1, hasBr3).doNotHave(hasBr4);
    // when #3
    temporaryBuildsCleaner.deleteTemporaryBuild(br3.getId(), "");
    builds = buildProvider.getAllIndependentTemporaryOlderThanTimestamp(0, 50, null, null, new Date().getTime());
    // then #3
    assertThat(builds.getContent()).haveExactly(1, hasBr1).haveExactly(1, hasBr2).doNotHave(hasBr3).doNotHave(hasBr4);
}
Also used : Condition(org.assertj.core.api.Condition) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arquillian(org.jboss.arquillian.junit.Arquillian) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BuildConfigurationSetRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationSetRepository) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) ArtifactRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) Assert.fail(org.junit.Assert.fail) Deployments.addBuildExecutorMock(org.jboss.pnc.integration.setup.Deployments.addBuildExecutorMock) Deployments(org.jboss.pnc.integration.setup.Deployments) BuildConfigurationRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationRepository) TargetRepository(org.jboss.pnc.model.TargetRepository) User(org.jboss.pnc.model.User) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) Artifact(org.jboss.pnc.model.Artifact) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) MethodHandles(java.lang.invoke.MethodHandles) BuildProvider(org.jboss.pnc.facade.providers.api.BuildProvider) Datastore(org.jboss.pnc.spi.datastore.Datastore) Set(java.util.Set) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) UserRepository(org.jboss.pnc.spi.datastore.repositories.UserRepository) List(java.util.List) RemoteBuildsCleanerMock(org.jboss.pnc.integration.mock.RemoteBuildsCleanerMock) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) PersistenceException(javax.persistence.PersistenceException) HeuristicMixedException(javax.transaction.HeuristicMixedException) TargetRepositoryRepository(org.jboss.pnc.spi.datastore.repositories.TargetRepositoryRepository) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) RunWith(org.junit.runner.RunWith) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Inject(javax.inject.Inject) HashSet(java.util.HashSet) RollbackException(javax.transaction.RollbackException) ProductVersionRepository(org.jboss.pnc.spi.datastore.repositories.ProductVersionRepository) TemporaryBuildsCleaner(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleaner) Before(org.junit.Before) ValidationException(org.jboss.pnc.spi.exception.ValidationException) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTransaction(javax.transaction.UserTransaction) Test(org.junit.Test) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Page(org.jboss.pnc.dto.response.Page) NotSupportedException(javax.transaction.NotSupportedException) Build(org.jboss.pnc.dto.Build) ChronoUnit(java.time.temporal.ChronoUnit) Assert.assertNull(org.junit.Assert.assertNull) Deployment(org.jboss.arquillian.container.test.api.Deployment) SystemException(javax.transaction.SystemException) Condition(org.assertj.core.api.Condition) Sequence(org.jboss.pnc.common.concurrent.Sequence) Assert.assertEquals(org.junit.Assert.assertEquals) Build(org.jboss.pnc.dto.Build) BuildRecord(org.jboss.pnc.model.BuildRecord) Artifact(org.jboss.pnc.model.Artifact) Date(java.util.Date) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 3 with ArtifactQuality

use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.

the class ArtifactProviderTest method testStore.

@Test
public void testStore() {
    TargetRepository repo = TargetRepository.refBuilder().identifier("repo-id").repositoryPath("/repo/path").repositoryType(RepositoryType.MAVEN).build();
    final String identifier = "foo:bar:0.0.1";
    Artifact artifact = Artifact.builder().identifier(identifier).artifactQuality(ArtifactQuality.NEW).buildCategory(BuildCategory.STANDARD).build();
    Artifact stored = provider.store(artifact);
    assertThat(stored.getIdentifier()).isEqualTo(identifier);
    assertThat(stored.getId()).isNotNull();
    Mockito.verify(repository).save(ArgumentMatchers.argThat(a -> identifier.equals(a.getIdentifier())));
}
Also used : TargetRepository(org.jboss.pnc.dto.TargetRepository) TargetRepository(org.jboss.pnc.dto.TargetRepository) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers(org.mockito.ArgumentMatchers) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) ArtifactRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactRepository) Repository(org.jboss.pnc.spi.datastore.repositories.api.Repository) ArrayList(java.util.ArrayList) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) RepositoryType(org.jboss.pnc.enums.RepositoryType) UserService(org.jboss.pnc.facade.util.UserService) DTOValidationException(org.jboss.pnc.facade.validation.DTOValidationException) Spy(org.mockito.Spy) Assert.fail(org.junit.Assert.fail) User(org.jboss.pnc.model.User) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited) Iterator(java.util.Iterator) ArtifactAuditedRepository(org.jboss.pnc.spi.datastore.repositories.ArtifactAuditedRepository) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Artifact(org.jboss.pnc.dto.Artifact) Page(org.jboss.pnc.dto.response.Page) IdRev(org.jboss.pnc.model.IdRev) Mockito(org.mockito.Mockito) List(java.util.List) Condition(org.assertj.core.api.Condition) BuildCategory(org.jboss.pnc.enums.BuildCategory) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) TargetRepositoryRepository(org.jboss.pnc.spi.datastore.repositories.TargetRepositoryRepository) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Artifact(org.jboss.pnc.dto.Artifact) Test(org.junit.Test)

Example 4 with ArtifactQuality

use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.

the class ArtifactProviderImpl method validateProvidedArtifactQuality.

private ArtifactQuality validateProvidedArtifactQuality(String quality, boolean isLoggedInUserSystemUser) {
    ArtifactQuality newQuality;
    try {
        newQuality = ArtifactQuality.valueOf(quality.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new InvalidEntityException("Artifact quality: " + quality + " does not exist.");
    }
    // User can specify NEW, TESTED, VERIFIED, DEPRECATED quality levels; admins can also specify DELETED and
    // BLACKLISTED
    EnumSet<ArtifactQuality> allowedQualities = isLoggedInUserSystemUser ? ADMIN_ALLOWED_ARTIFACT_QUALITIES : USER_ALLOWED_ARTIFACT_QUALITIES;
    if (!allowedQualities.contains(newQuality)) {
        throw new InvalidEntityException("Artifact quality level can be changed only to " + allowedQualities);
    }
    return newQuality;
}
Also used : ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException)

Example 5 with ArtifactQuality

use of org.jboss.pnc.enums.ArtifactQuality in project pnc by project-ncl.

the class ArtifactProviderImpl method createQualityLevelRevision.

@Override
public ArtifactRevision createQualityLevelRevision(String id, String quality, String reason) throws DTOValidationException {
    boolean isLoggedInUserSystemUser = userService.hasLoggedInUserRole(SYSTEM_USER);
    ArtifactQuality newQuality = validateProvidedArtifactQuality(quality, isLoggedInUserSystemUser);
    org.jboss.pnc.dto.Artifact artifact = getSpecific(id);
    if (artifact == null) {
        throw new InvalidEntityException("Artifact with id: " + id + " does not exist.");
    }
    validateIfArtifactQualityIsModifiable(artifact, newQuality);
    update(id, artifact.toBuilder().artifactQuality(newQuality).qualityLevelReason(reason).build());
    ArtifactAudited latestRevision = artifactAuditedRepository.findLatestById(Integer.parseInt(id));
    if (latestRevision == null) {
        throw new RepositoryViolationException("Entity should exist in the DB");
    }
    if (DA_SYNCRONIZED_ARTIFACT_QUALITIES.contains(newQuality)) {
        String jsonPayload = createBlacklistJSONPayload(artifact);
        blacklistAsyncInvoker.notifyBlacklistToDA(jsonPayload);
    }
    return artifactRevisionMapper.toDTO(latestRevision);
}
Also used : RepositoryViolationException(org.jboss.pnc.facade.validation.RepositoryViolationException) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) InvalidEntityException(org.jboss.pnc.facade.validation.InvalidEntityException) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited)

Aggregations

ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)7 Artifact (org.jboss.pnc.model.Artifact)3 TargetRepository (org.jboss.pnc.model.TargetRepository)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Condition (org.assertj.core.api.Condition)2 Page (org.jboss.pnc.dto.response.Page)2 RepositoryType (org.jboss.pnc.enums.RepositoryType)2 InvalidEntityException (org.jboss.pnc.facade.validation.InvalidEntityException)2 ArtifactAudited (org.jboss.pnc.model.ArtifactAudited)2 User (org.jboss.pnc.model.User)2 ArtifactRepository (org.jboss.pnc.spi.datastore.repositories.ArtifactRepository)2 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)2 TargetRepositoryRepository (org.jboss.pnc.spi.datastore.repositories.TargetRepositoryRepository)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.fail (org.junit.Assert.fail)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2