Search in sources :

Example 16 with RepositoryManagerResult

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

the class BuildResultMock method mock.

public static BuildResult mock(BuildStatus status) {
    BuildExecutionConfiguration buildExecutionConfig = BuildExecutionConfigurationMock.mockConfig();
    BuildDriverResult buildDriverResult = BuildDriverResultMock.mockResult(status);
    RepositoryManagerResult repositoryManagerResult = RepositoryManagerResultMock.mockResult();
    ExecutorException exception = buildException();
    CompletionStatus completionStatus;
    if (status.completedSuccessfully()) {
        completionStatus = CompletionStatus.SUCCESS;
    } else {
        completionStatus = CompletionStatus.FAILED;
    }
    return new BuildResult(completionStatus, Optional.of(new ProcessException("Test Exception.")), "", Optional.ofNullable(buildExecutionConfig), Optional.ofNullable(buildDriverResult), Optional.ofNullable(repositoryManagerResult), Optional.of(EnvironmentDriverResultMock.mock()), Optional.of(RepourResultMock.mock()));
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus)

Example 17 with RepositoryManagerResult

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

the class BuildExecutorMock method mockBuild.

private Boolean mockBuild(BuildExecutionSession buildExecutionSession) {
    log.debug("Building {}.", buildExecutionSession.getId());
    BuildDriverResult driverResult;
    Boolean buildPassed;
    if (TestProjectConfigurationBuilder.FAIL.equals(buildExecutionSession.getBuildExecutionConfiguration().getBuildScript())) {
        log.debug("Marking build {} as Failed.", buildExecutionSession.getId());
        driverResult = BuildDriverResultMock.mockResult(BuildStatus.FAILED);
        buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_COMPLETED_WITH_ERROR);
        buildPassed = false;
    } else if (TestProjectConfigurationBuilder.FAIL_WITH_DELAY.equals(buildExecutionSession.getBuildExecutionConfiguration().getBuildScript())) {
        log.debug("Waiting for a while for a build {}.", buildExecutionSession.getId());
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            log.warn("Build mock has been interrupted.", e);
        }
        log.debug("Marking build {} as Failed.", buildExecutionSession.getId());
        driverResult = BuildDriverResultMock.mockResult(BuildStatus.FAILED);
        buildPassed = false;
    } else if (TestProjectConfigurationBuilder.CANCEL.equals(buildExecutionSession.getBuildExecutionConfiguration().getBuildScript())) {
        log.debug("Waiting for a while for a build {} to be canceled.", buildExecutionSession.getId());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.warn("Build mock has been interrupted.", e);
        }
        driverResult = BuildDriverResultMock.mockResult(BuildStatus.CANCELLED);
        buildPassed = false;
    } else {
        log.debug("Marking build {} as Success.", buildExecutionSession.getId());
        driverResult = BuildDriverResultMock.mockResult(BuildStatus.SUCCESS);
        RepositoryManagerResult repositoryManagerResult = RepositoryManagerResultMock.mockResult();
        buildExecutionSession.setRepositoryManagerResult(repositoryManagerResult);
        buildPassed = true;
    }
    buildExecutionSession.setBuildDriverResult(driverResult);
    return buildPassed;
}
Also used : BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)

Example 18 with RepositoryManagerResult

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

the class BuildMaintenanceEndpointImpl method collectRepoManagerResult.

@Override
public Response collectRepoManagerResult(String id) {
    logger.info("Getting repository manager result for build record id {}.", id);
    RepositoryManagerResult result;
    try {
        result = repositoryManager.collectRepoManagerResult(id);
    } catch (RepositoryManagerException ex) {
        logger.error("Error when collecting repository manager result for build record " + id, ex);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.toString()).build();
    }
    if (result == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    return Response.ok(result).build();
}
Also used : RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException)

Example 19 with RepositoryManagerResult

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

the class ExcludeInternalRepoByNameTest method extractBuildArtifacts_ContainsTwoDownloads.

@Test
public void extractBuildArtifacts_ContainsTwoDownloads() throws Exception {
    // create a remote repo pointing at our server fixture's 'repo/test' directory.
    indy.stores().create(new RemoteRepository(MAVEN_PKG_KEY, INTERNAL, server.formatUrl(INTERNAL)), "Creating internal test remote repo", RemoteRepository.class);
    indy.stores().create(new RemoteRepository(MAVEN_PKG_KEY, EXTERNAL, server.formatUrl(EXTERNAL)), "Creating external test remote repo", RemoteRepository.class);
    Group publicGroup = indy.stores().load(new StoreKey(MAVEN_PKG_KEY, StoreType.group, PUBLIC_GROUP_ID), Group.class);
    if (publicGroup == null) {
        publicGroup = new Group(MAVEN_PKG_KEY, PUBLIC_GROUP_ID, new StoreKey(MAVEN_PKG_KEY, StoreType.remote, INTERNAL), new StoreKey(MAVEN_PKG_KEY, StoreType.remote, EXTERNAL));
        indy.stores().create(publicGroup, "creating public group", Group.class);
    } else {
        publicGroup.setConstituents(Arrays.asList(new StoreKey(MAVEN_PKG_KEY, StoreType.remote, INTERNAL), new StoreKey(MAVEN_PKG_KEY, StoreType.remote, EXTERNAL)));
        indy.stores().update(publicGroup, "adding test remotes to public group");
    }
    String internalPath = "org/foo/internal/1.0/internal-1.0.pom";
    String externalPath = "org/foo/external/1.1/external-1.1.pom";
    String content = "This is a test " + System.currentTimeMillis();
    // setup the expectation that the remote repo pointing at this server will request this file...and define its
    // content.
    server.expect(server.formatUrl(INTERNAL, internalPath), 200, content);
    server.expect(server.formatUrl(EXTERNAL, externalPath), 200, content);
    // 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().getDependencyUrl();
    // download the two files via the repo session's dependency URL, which will proxy the test http server
    // using the expectations above
    assertThat(download(UrlUtils.buildUrl(baseUrl, internalPath)), equalTo(content));
    assertThat(download(UrlUtils.buildUrl(baseUrl, externalPath)), equalTo(content));
    // extract the build artifacts, which should contain the two imported deps.
    // This will also trigger promoting imported artifacts into the shared-imports hosted repo
    RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
    List<Artifact> deps = repositoryManagerResult.getDependencies();
    System.out.println(deps);
    assertThat(deps, notNullValue());
    assertThat(deps.size(), equalTo(2));
    Indy indy = driver.getIndy(accessToken);
    StoreKey sharedImportsKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, SHARED_IMPORTS_ID);
    // check that the imports from external locations are available from shared-imports
    InputStream stream = indy.content().get(sharedImportsKey, externalPath);
    String downloaded = IOUtils.toString(stream, (String) null);
    assertThat(downloaded, equalTo(content));
    stream.close();
    // check that the imports from internal/trusted locations are NOT available from shared-imports
    stream = indy.content().get(sharedImportsKey, internalPath);
    assertThat(stream, nullValue());
}
Also used : Group(org.commonjava.indy.model.core.Group) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) InputStream(java.io.InputStream) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) Indy(org.commonjava.indy.client.core.Indy) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) Artifact(org.jboss.pnc.model.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 20 with RepositoryManagerResult

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

the class IndyPromotionValidationTest method testIndyPromotionValidation.

@Test
public /**
 * Test whose purpose is to provide a means for more or less easy debugging of indy validation errors. For it to
 * work it needs a standalone Indy server, with a rule-set definition such as this: { "storeKeyPattern":
 * "group:builds-untested", "ruleNames": [ "no-snapshots.groovy", "parsable-pom.groovy" ], "validationParameters":
 * {} } Provide the base URL to this Indy server as a System parameter such as e.g.
 * -DbaseUrl="http://127.0.0.1:8090"
 */
void testIndyPromotionValidation() {
    String baseUrl = System.getProperty("baseUrl");
    if (StringUtils.isBlank(baseUrl)) {
        fail("No base URL has been specified");
    }
    RepositoryManager driver = null;
    try {
        driver = new RepositoryManagerDriver(new TestConfiguration(baseUrl), new BuildRecordRepositoryMock());
        RepositorySession repositorySession = driver.createBuildRepository(new TestBuildExecution("test"), null, null, RepositoryType.MAVEN, Collections.emptyMap(), false);
        CloseableHttpClient client = HttpClientBuilder.create().build();
        String deployUrl = repositorySession.getConnectionInfo().getDeployUrl();
        // Deploy several 'wrong' artifacts to get a composed error message back
        String pathPom1 = "org/foo/invalid/1/invalid-1.pom";
        String snapshotPom = "<?xml version=\"1.0\"?>\n<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId>" + "<artifactId>invalid</artifactId><version>1</version><dependencies>" + "<dependency><groupId>org.bar</groupId><artifactId>dep</artifactId>" + "<version>1.0-SNAPSHOT</version></dependency></dependencies></project>";
        String url = UrlUtils.buildUrl(deployUrl, pathPom1);
        put(client, url, snapshotPom);
        String pathPom2 = "org/foo/invalid2/1/invalid2-1.pom";
        String snapshotPom2 = "<?xml version=\"1.0\"?>\n<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId>" + "<artifactId>invalid2</artifactId><version>1</version><dependencies>" + "<dependency><groupId>org.bar</groupId><artifactId>dep</artifactId>" + "<version>1.0-SNAPSHOT</version></dependency></dependencies></project>";
        url = UrlUtils.buildUrl(deployUrl, pathPom2);
        put(client, url, snapshotPom2);
        String pathPom3 = "org/foo/nonparseable/1/nonparseable.pom";
        String nonparseablePom = "<?xml version=\"1.0\"?>\n<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId>" + "<artifactId>nonparseable</artifactId><version>1</version><dependencies>" + "<dependency><groupId>org.bar</groupId><artifactId>dep</artifactId>" + "<version>1.0</version></dependency></dependencies></project>";
        url = UrlUtils.buildUrl(deployUrl, pathPom3);
        put(client, url, nonparseablePom);
        RepositoryManagerResult repositoryManagerResult = repositorySession.extractBuildArtifacts(true);
        // Just a dummy check, the point is really to be able to debug this
        assertSame(CompletionStatus.FAILED, repositoryManagerResult.getCompletionStatus());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BuildRecordRepositoryMock(org.jboss.pnc.mock.repository.BuildRecordRepositoryMock) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) RepositoryManager(org.jboss.pnc.spi.repositorymanager.RepositoryManager) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) IOException(java.io.IOException) DebugTest(org.jboss.pnc.test.category.DebugTest) Test(org.junit.Test)

Aggregations

RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)27 Artifact (org.jboss.pnc.model.Artifact)14 RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)14 Test (org.junit.Test)14 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)12 BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)11 ContainerTest (org.jboss.pnc.test.category.ContainerTest)11 StoreKey (org.commonjava.indy.model.core.StoreKey)9 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)7 File (java.io.File)6 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)6 SimpleArtifactRef (org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef)5 BuildResult (org.jboss.pnc.spi.BuildResult)5 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 HashSet (java.util.HashSet)4 ProjectVersionRef (org.commonjava.atlas.maven.ident.ref.ProjectVersionRef)4 SimpleProjectVersionRef (org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef)4 Indy (org.commonjava.indy.client.core.Indy)4 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)4