Search in sources :

Example 11 with BuildExecution

use of org.jboss.pnc.spi.repositorymanager.BuildExecution in project pnc by project-ncl.

the class UploadTwoThenVerifyExtractedArtifactsContainThemTest method extractBuildArtifacts_ContainsTwoUploads.

@Test
public void extractBuildArtifacts_ContainsTwoUploads() throws Exception {
    // create a dummy non-chained build execution and repo session based on it
    BuildExecution execution = new TestBuildExecution();
    RepositorySession rc = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    assertThat(rc, notNullValue());
    String baseUrl = rc.getConnectionInfo().getDeployUrl();
    String pomPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.pom";
    String jarPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.jar";
    CloseableHttpClient client = HttpClientBuilder.create().build();
    // this simulates a build deploying one jar and its associated POM
    for (String path : new String[] { pomPath, jarPath }) {
        final String url = UrlUtils.buildUrl(baseUrl, path);
        assertThat("Failed to upload: " + url, ArtifactUploadUtils.put(client, url, "This is a test"), equalTo(true));
    }
    // extract the "built" artifacts we uploaded above.
    RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
    // check that both files are present in extracted result
    List<Artifact> artifacts = repositoryManagerResult.getBuiltArtifacts();
    System.out.println(artifacts);
    assertThat(artifacts, notNullValue());
    assertThat(artifacts.size(), equalTo(2));
    ProjectVersionRef pvr = new SimpleProjectVersionRef("org.commonjava.indy", "indy-core", "0.17.0");
    Set<String> refs = new HashSet<>();
    refs.add(new SimpleArtifactRef(pvr, "pom", null).toString());
    refs.add(new SimpleArtifactRef(pvr, "jar", null).toString());
    // check that the artifact getIdentifier() stores GAVT[C] information in the standard Maven rendering
    for (Artifact artifact : artifacts) {
        assertThat(artifact + " is not in the expected list of built artifacts: " + refs, refs.contains(artifact.getIdentifier()), equalTo(true));
    }
    // check that we can download the two files from the build repository
    for (String path : new String[] { pomPath, jarPath }) {
        StoreKey hostedKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, rc.getBuildRepositoryId());
        final String url = indy.content().contentUrl(hostedKey, path);
        boolean downloaded = client.execute(new HttpGet(url), response -> {
            try {
                return response.getStatusLine().getStatusCode() == 200;
            } finally {
                if (response instanceof CloseableHttpResponse) {
                    IOUtils.closeQuietly((CloseableHttpResponse) response);
                }
            }
        });
        assertThat("Failed to download: " + url, downloaded, equalTo(true));
    }
    client.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) HttpGet(org.apache.http.client.methods.HttpGet) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 12 with BuildExecution

use of org.jboss.pnc.spi.repositorymanager.BuildExecution in project pnc by project-ncl.

the class VerifyBuildGroupRemovedAfterArtifactExtractionTest method extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup.

@Test
public void extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup() 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 composed (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);
    // simulate a build deploying a file.
    indy.module(IndyFoloContentClientModule.class).store(buildId, new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, buildId), 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()));
    // end result: the build aggregation group should have been garbage collected
    StoreKey groupKey = new StoreKey(MAVEN_PKG_KEY, StoreType.group, buildId);
    boolean buildGroupExists = indy.stores().exists(groupKey);
    assertThat(buildGroupExists, equalTo(false));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) File(java.io.File) Artifact(org.jboss.pnc.model.Artifact) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 13 with BuildExecution

use of org.jboss.pnc.spi.repositorymanager.BuildExecution in project pnc by project-ncl.

the class VerifyBuildRepoPromotionToUntestedBuildsGroupTest method extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup.

@Test
public void extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup() 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 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);
    StoreKey hostedKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, buildId);
    // simulate a build deploying a file.
    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 pnc-builds
    // group.
    RepositoryManagerResult result = session.extractBuildArtifacts(true);
    assertThat(result.getCompletionStatus(), equalTo(CompletionStatus.SUCCESS));
    // 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()));
    // end result: the pnc-builds group should contain the build hosted repo.
    StoreKey pncBuildsKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, PNC_BUILDS);
    assertThat(indy.content().exists(pncBuildsKey, path), equalTo(true));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) File(java.io.File) Artifact(org.jboss.pnc.model.Artifact) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 14 with BuildExecution

use of org.jboss.pnc.spi.repositorymanager.BuildExecution 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 15 with BuildExecution

use of org.jboss.pnc.spi.repositorymanager.BuildExecution 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

BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)20 RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)20 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)19 ContainerTest (org.jboss.pnc.test.category.ContainerTest)18 Test (org.junit.Test)18 StoreKey (org.commonjava.indy.model.core.StoreKey)12 Artifact (org.jboss.pnc.model.Artifact)11 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)11 Indy (org.commonjava.indy.client.core.Indy)8 Group (org.commonjava.indy.model.core.Group)7 File (java.io.File)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ProjectVersionRef (org.commonjava.atlas.maven.ident.ref.ProjectVersionRef)4 SimpleArtifactRef (org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef)4 SimpleProjectVersionRef (org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef)4 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)4 RepositoryConnectionInfo (org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2