Search in sources :

Example 21 with RepositoryManagerResult

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

the class UploadOneManagedSvcThenDownloadAndVerifyArtifactHasBuildCategoryTest 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();
    Map<String, String> genericParams = new HashMap<>(1);
    genericParams.put(BuildConfigurationParameterKeys.BUILD_CATEGORY.name(), BuildCategory.SERVICE.name());
    RepositorySession rc = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, genericParams, false);
    assertThat(rc, notNullValue());
    String baseUrl = rc.getConnectionInfo().getDeployUrl();
    String path = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.pom";
    String content = "This is a test";
    CloseableHttpClient client = HttpClientBuilder.create().build();
    // upload a couple files related to a single GAV using the repo session deployment url
    // this simulates a build deploying one jar and its associated POM
    final String url = UrlUtils.buildUrl(baseUrl, path);
    assertThat("Failed to upload: " + url, ArtifactUploadUtils.put(client, url, content), equalTo(true));
    // 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, path)), equalTo(content));
    ProjectVersionRef pvr = new SimpleProjectVersionRef("org.commonjava.indy", "indy-core", "0.17.0");
    String artifactRef = new SimpleArtifactRef(pvr, "pom", null).toString();
    // extract the "builtArtifacts" artifacts we uploaded above.
    RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
    // check that both files are present in extracted result
    List<Artifact> builtArtifacts = repositoryManagerResult.getBuiltArtifacts();
    log.info("Built artifacts: " + builtArtifacts.toString());
    assertThat(builtArtifacts, notNullValue());
    assertThat(builtArtifacts.size(), equalTo(1));
    Artifact builtArtifact = builtArtifacts.get(0);
    assertThat(builtArtifact + " doesn't match pom ref: " + artifactRef, builtArtifact.getIdentifier(), equalTo(artifactRef));
    assertThat(builtArtifact + " doesn't have correct build category: " + BuildCategory.SERVICE, builtArtifact.getBuildCategory(), equalTo(BuildCategory.SERVICE));
    client.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) HashMap(java.util.HashMap) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) 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) Artifact(org.jboss.pnc.model.Artifact) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 22 with RepositoryManagerResult

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

the class UploadOneThenDownloadAndVerifyArtifactHasOriginUrlTest 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 path = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.pom";
    String content = "This is a test";
    CloseableHttpClient client = HttpClientBuilder.create().build();
    // upload a couple files related to a single GAV using the repo session deployment url
    // this simulates a build deploying one jar and its associated POM
    final String url = UrlUtils.buildUrl(baseUrl, path);
    assertThat("Failed to upload: " + url, ArtifactUploadUtils.put(client, url, content), equalTo(true));
    // 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, path)), equalTo(content));
    ProjectVersionRef pvr = new SimpleProjectVersionRef("org.commonjava.indy", "indy-core", "0.17.0");
    String artifactRef = new SimpleArtifactRef(pvr, "pom", null).toString();
    // extract the "builtArtifacts" artifacts we uploaded above.
    RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
    // check that both files are present in extracted result
    List<Artifact> builtArtifacts = repositoryManagerResult.getBuiltArtifacts();
    log.info("Built artifacts: " + builtArtifacts.toString());
    assertThat(builtArtifacts, notNullValue());
    assertThat(builtArtifacts.size(), equalTo(1));
    Artifact builtArtifact = builtArtifacts.get(0);
    assertThat(builtArtifact + " doesn't match pom ref: " + artifactRef, builtArtifact.getIdentifier(), equalTo(artifactRef));
    assertThat(builtArtifact + " doesn't have correct build category: " + BuildCategory.STANDARD, builtArtifact.getBuildCategory(), equalTo(BuildCategory.STANDARD));
    client.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) 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) Artifact(org.jboss.pnc.model.Artifact) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 23 with RepositoryManagerResult

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

the class DatastoreAdapter method storeResult.

public BuildRecord storeResult(BuildTask buildTask, BuildResult buildResult) throws DatastoreException {
    try {
        BuildStatus buildRecordStatus = NEW;
        BuildRecord.Builder buildRecordBuilder = initBuildRecordBuilder(buildTask);
        buildRecordBuilder.buildContentId(buildTask.getContentId());
        if (buildResult.getRepourResult().isPresent()) {
            RepourResult repourResult = buildResult.getRepourResult().get();
            buildRecordBuilder.repourLog(repourResult.getLog());
            buildRecordBuilder.executionRootName(repourResult.getExecutionRootName());
            buildRecordBuilder.executionRootVersion(repourResult.getExecutionRootVersion());
            CompletionStatus repourCompletionStatus = repourResult.getCompletionStatus();
            if (repourCompletionStatus != null) {
                switch(repourCompletionStatus) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordBuilder.appendLog("\nBuild failed during the alignment phase, please check the 'Alignment Log' tab for more information.\n");
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordBuilder.appendLog("\nBuild cancelled during alignment phase.\n");
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                        buildRecordBuilder.appendLog("\nBuild timed-out during alignment phase.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    case SYSTEM_ERROR:
                        buildRecordBuilder.appendLog("\nBuild failed with SYSTEM_ERROR during the alignment phase, " + "please check the 'Alignment Log' tab for more information.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the alignment phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
        } else {
            userLog.warn("Missing Repour Result!");
            log.warn("[BuildTask:" + buildTask.getId() + "] Missing RepourResult.");
        }
        if (buildResult.getBuildDriverResult().isPresent()) {
            BuildDriverResult buildDriverResult = buildResult.getBuildDriverResult().get();
            buildRecordBuilder.appendLog(buildDriverResult.getBuildLog());
            buildDriverResult.getOutputChecksum().ifPresent(buildRecordBuilder::buildOutputChecksum);
            // TODO buildRecord should use CompletionStatus
            buildRecordStatus = buildDriverResult.getBuildStatus();
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildDriverResult."));
        }
        if (buildResult.getEnvironmentDriverResult().isPresent()) {
            EnvironmentDriverResult environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
            buildRecordBuilder.appendLog(environmentDriverResult.getLog());
            environmentDriverResult.getSshCredentials().ifPresent(c -> {
                buildRecordBuilder.sshCommand(c.getCommand());
                buildRecordBuilder.sshPassword(c.getPassword());
            });
            if (environmentDriverResult.getCompletionStatus() != null) {
                switch(environmentDriverResult.getCompletionStatus()) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                    case SYSTEM_ERROR:
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the environment setup phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
        }
        List<Artifact> builtArtifacts = Collections.emptyList();
        List<Artifact> dependencies = Collections.emptyList();
        if (buildResult.getRepositoryManagerResult().isPresent()) {
            RepositoryManagerResult repositoryManagerResult = buildResult.getRepositoryManagerResult().get();
            buildRecordBuilder.appendLog(repositoryManagerResult.getLog());
            if (repositoryManagerResult.getCompletionStatus() != null) {
                switch(// TODO, do not mix statuses
                repositoryManagerResult.getCompletionStatus()) {
                    case SUCCESS:
                    case NO_REBUILD_REQUIRED:
                        break;
                    case FAILED:
                        buildRecordStatus = FAILED;
                        break;
                    case CANCELLED:
                        buildRecordStatus = CANCELLED;
                        break;
                    case TIMED_OUT:
                    case SYSTEM_ERROR:
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                    default:
                        buildRecordBuilder.appendLog("\nInvalid status during the promotion phase, failing with SYSTEM_ERROR.\n");
                        buildRecordStatus = SYSTEM_ERROR;
                        break;
                }
            }
            builtArtifacts = repositoryManagerResult.getBuiltArtifacts();
            Map<Artifact, String> builtConflicts = datastore.checkForBuiltArtifacts(builtArtifacts);
            if (builtConflicts.size() > 0) {
                return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with invalid repository manager result. Conflicting artifact data found: " + builtConflicts.toString()));
            }
            dependencies = repositoryManagerResult.getDependencies();
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing RepositoryManagerResult."));
        }
        if (NEW.equals(buildRecordStatus)) {
            switch(buildResult.getCompletionStatus()) {
                case SUCCESS:
                case NO_REBUILD_REQUIRED:
                case FAILED:
                case SYSTEM_ERROR:
                    break;
                case CANCELLED:
                    buildRecordStatus = CANCELLED;
                    break;
                case TIMED_OUT:
                    buildRecordStatus = SYSTEM_ERROR;
                    buildRecordBuilder.appendLog("-- Operation TIMED-OUT --");
                    userLog.warn("Operation TIMED-OUT.");
                    break;
                default:
                    buildRecordBuilder.appendLog("\nInvalid status detected in the final completion status, failing with SYSTEM_ERROR.\n");
                    break;
            }
        }
        log.debug("Setting status " + buildRecordStatus.toString() + " to buildRecord.");
        buildRecordBuilder.status(buildRecordStatus);
        if (buildResult.getBuildExecutionConfiguration().isPresent()) {
            BuildExecutionConfiguration buildExecutionConfig = buildResult.getBuildExecutionConfiguration().get();
            buildRecordBuilder.scmRepoURL(buildExecutionConfig.getScmRepoURL());
            buildRecordBuilder.scmRevision(buildExecutionConfig.getScmRevision());
            buildRecordBuilder.scmTag(buildExecutionConfig.getScmTag());
        } else if (!buildResult.hasFailed()) {
            return storeResult(buildTask, Optional.of(buildResult), new BuildCoordinationException("Trying to store success build with incomplete result. Missing BuildExecutionConfiguration."));
        }
        log.debug("Storing results of buildTask [{}] to datastore.", buildTask.getId());
        userLog.info("Successfully completed.");
        return datastore.storeCompletedBuild(buildRecordBuilder, builtArtifacts, dependencies);
    } catch (Exception e) {
        return storeResult(buildTask, Optional.of(buildResult), e);
    }
}
Also used : BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildStatus(org.jboss.pnc.enums.BuildStatus) RepourResult(org.jboss.pnc.spi.repour.RepourResult)

Example 24 with RepositoryManagerResult

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

the class AbstractDependentBuildTest method repoManagerResult.

private static RepositoryManagerResult repoManagerResult() {
    RepositoryManagerResult mock = mock(RepositoryManagerResult.class);
    when(mock.getCompletionStatus()).thenReturn(CompletionStatus.SUCCESS);
    return mock;
}
Also used : RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)

Example 25 with RepositoryManagerResult

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

the class RepositoryManagerResultSerializationTest method serializeAndDeserializeRepositoryManagerResult.

@Test
public void serializeAndDeserializeRepositoryManagerResult() throws IOException {
    RepositoryManagerResult repoMngrResult = RepositoryManagerResultMock.mockResult();
    RepositoryManagerResultRest repoMngrResultRest = repositoryManagerResultMapper.toDTO(repoMngrResult);
    String repoMngrResultJson = JsonOutputConverterMapper.apply(repoMngrResultRest);
    log.debug("RepoManagerResultJson : {}", repoMngrResultJson);
    RepositoryManagerResultRest deserializedRepoManResultRest = JsonOutputConverterMapper.readValue(repoMngrResultJson, RepositoryManagerResultRest.class);
    RepositoryManagerResult deserializedRepoMngrResult = repositoryManagerResultMapper.toEntity(deserializedRepoManResultRest);
    String message = "Deserialized object does not match the original.";
    Assert.assertEquals(message, repoMngrResult.getBuildContentId(), deserializedRepoMngrResult.getBuildContentId());
    Assert.assertEquals(message, repoMngrResult.getBuiltArtifacts().get(0), deserializedRepoMngrResult.getBuiltArtifacts().get(0));
    Assert.assertEquals(message, repoMngrResult.getBuiltArtifacts().get(0).getSha256(), deserializedRepoMngrResult.getBuiltArtifacts().get(0).getSha256());
    Assert.assertEquals(message, repoMngrResult.getBuiltArtifacts().get(0).isBuilt(), deserializedRepoMngrResult.getBuiltArtifacts().get(0).isBuilt());
    Assert.assertEquals(message, repoMngrResult.getDependencies().get(0), deserializedRepoMngrResult.getDependencies().get(0));
    Assert.assertEquals(message, repoMngrResult.getDependencies().get(0).getDeployPath(), deserializedRepoMngrResult.getDependencies().get(0).getDeployPath());
    Assert.assertEquals(message, repoMngrResult.getDependencies().get(0).isImported(), deserializedRepoMngrResult.getDependencies().get(0).isImported());
}
Also used : RepositoryManagerResultRest(org.jboss.pnc.bpm.model.RepositoryManagerResultRest) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) 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