Search in sources :

Example 26 with BuildRecord

use of org.jboss.pnc.model.BuildRecord 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 27 with BuildRecord

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

the class TemporaryBuildsCleanerTest method shouldNotDeleteNonTemporaryBuildTest.

@Test(expected = ValidationException.class)
public void shouldNotDeleteNonTemporaryBuildTest() throws ValidationException {
    // given
    BuildRecord nonTempBr = initBuildRecordBuilder().temporaryBuild(false).build();
    buildRecordRepository.save(nonTempBr);
    // when - then
    temporaryBuildsCleaner.deleteTemporaryBuild(nonTempBr.getId(), "");
    fail("Deletion of non-temporary build should be prohibited");
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 28 with BuildRecord

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

the class TemporaryBuildsCleanerTest method shouldNotDeleteNonTemporaryArtifacts.

@Test
public void shouldNotDeleteNonTemporaryArtifacts() {
    // given
    Artifact artifact = initArtifactBuilder().artifactQuality(ArtifactQuality.NEW).build();
    artifactRepository.save(artifact);
    Set<Artifact> builtArtifacts = new HashSet<>();
    builtArtifacts.add(artifact);
    BuildRecord tempBr = initBuildRecordBuilder().temporaryBuild(true).build();
    BuildRecord savedTempBr = buildRecordRepository.save(tempBr);
    artifact.setBuildRecord(savedTempBr);
    artifactRepository.save(artifact);
    // when - then
    try {
        temporaryBuildsCleaner.deleteTemporaryBuild(tempBr.getId(), "");
    } catch (Exception ex) {
        logger.info("Received exception:", ex);
        if (ex.getCause().getClass().equals(PersistenceException.class)) {
            return;
        }
    }
    fail("Deletion of non-temporary artifacts should be prohibited");
}
Also used : PersistenceException(javax.persistence.PersistenceException) Artifact(org.jboss.pnc.model.Artifact) BuildRecord(org.jboss.pnc.model.BuildRecord) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) PersistenceException(javax.persistence.PersistenceException) HeuristicMixedException(javax.transaction.HeuristicMixedException) RollbackException(javax.transaction.RollbackException) ValidationException(org.jboss.pnc.spi.exception.ValidationException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 29 with BuildRecord

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

the class VerifyManualDeletionOfBuildRepoTest method manuallyPromoteBuildRepoToChainGroup.

@Test
public void manuallyPromoteBuildRepoToChainGroup() throws Exception {
    String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
    String content = "This is a test " + System.currentTimeMillis();
    String buildId = "build";
    // create a dummy non-chained build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution(buildId);
    RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    String pkgType = MAVEN_PKG_KEY;
    // simulate a build deploying a file.
    StoreKey hostedKey = new StoreKey(pkgType, StoreType.hosted, buildId);
    indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
    // now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
    RepositoryManagerResult result = session.extractBuildArtifacts(true);
    // do some sanity checks while we're here
    List<Artifact> deps = result.getBuiltArtifacts();
    assertThat(deps.size(), equalTo(1));
    Artifact a = deps.get(0);
    assertThat(a.getFilename(), equalTo(new File(path).getName()));
    // construct a dummy BuildRecord for use below
    BuildRecord record = new BuildRecord();
    record.setBuildContentId(buildId);
    // unset the readonly flag on the hosted repo to allow its deletion
    IndyStoresClientModule indyStoreAdmin = indy.stores();
    StoreKey key = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, record.getBuildContentId());
    HostedRepository store = indyStoreAdmin.load(key, HostedRepository.class);
    store.setReadonly(false);
    indyStoreAdmin.update(store, "Unsetting readonly-flag to allow deletion");
    // manually delete the build to the public group (since it's convenient)
    RunningRepositoryDeletion deletion = driver.deleteBuild(record, pkgType, accessToken);
    deletion.monitor(completed -> assertThat("Manual deletion failed.", completed.isSuccessful(), equalTo(true)), error -> {
        error.printStackTrace();
        fail("Failed to manually delete: " + error.getMessage());
    });
    // end result: the build hosted repo should no longer exist.
    assertThat(indyStoreAdmin.exists(hostedKey), equalTo(false));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) IndyStoresClientModule(org.commonjava.indy.client.core.module.IndyStoresClientModule) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) BuildRecord(org.jboss.pnc.model.BuildRecord) RunningRepositoryDeletion(org.jboss.pnc.spi.repositorymanager.model.RunningRepositoryDeletion) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) HostedRepository(org.commonjava.indy.model.core.HostedRepository) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 30 with BuildRecord

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

the class VerifyManualPromotionOfBuildRepoTest method manuallyPromoteBuildRepoToChainGroup.

@Test
public void manuallyPromoteBuildRepoToChainGroup() throws Exception {
    String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
    String content = "This is a test " + System.currentTimeMillis();
    // String chainId = "chain";
    String buildId = "build";
    // create a dummy non-chained build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution(buildId);
    RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    String pkgType = MAVEN_PKG_KEY;
    // simulate a build deploying a file.
    StoreKey hostedKey = new StoreKey(pkgType, StoreType.hosted, buildId);
    indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
    // now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
    RepositoryManagerResult result = session.extractBuildArtifacts(true);
    // do some sanity checks while we're here
    List<Artifact> deps = result.getBuiltArtifacts();
    assertThat(deps.size(), equalTo(1));
    Artifact a = deps.get(0);
    assertThat(a.getFilename(), equalTo(new File(path).getName()));
    // construct a dummy BuildRecord for use below
    BuildRecord record = new BuildRecord();
    record.setBuildContentId(buildId);
    // manually promote the build to the public group (since it's convenient)
    RunningRepositoryPromotion promotion = driver.promoteBuild(record, pkgType, PUBLIC, accessToken);
    promotion.monitor(completed -> assertThat("Manual promotion failed.", completed.isSuccessful(), equalTo(true)), error -> {
        error.printStackTrace();
        fail("Failed to manually promote: " + error.getMessage());
    });
    // end result: the chain group should contain the build hosted repo.
    StoreKey publicKey = new StoreKey(pkgType, StoreType.group, PUBLIC);
    Group publicGroup = indy.stores().load(publicKey, Group.class);
    System.out.println("public group constituents: " + publicGroup.getConstituents());
    assertThat(publicGroup.getConstituents().contains(hostedKey), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) RunningRepositoryPromotion(org.jboss.pnc.spi.repositorymanager.model.RunningRepositoryPromotion) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) BuildRecord(org.jboss.pnc.model.BuildRecord) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

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