Search in sources :

Example 11 with BuildDriverResult

use of org.jboss.pnc.spi.builddriver.BuildDriverResult in project pnc by project-ncl.

the class BuildDriverMock method complete.

protected void complete(BuildExecutionSession buildExecutionSession, final RunningEnvironment runningEnvironment, Consumer<CompletedBuild> onComplete) throws InterruptedException {
    Thread.sleep(RandomUtils.randInt(100, 300));
    setBuildStatus(buildExecutionSession.getBuildExecutionConfiguration().getBuildScript());
    onComplete.accept(new CompletedBuild() {

        @Override
        public BuildDriverResult getBuildResult() throws BuildDriverException {
            return getBuildResultMock(runningEnvironment);
        }

        @Override
        public RunningEnvironment getRunningEnvironment() {
            return runningEnvironment;
        }
    });
}
Also used : CompletedBuild(org.jboss.pnc.spi.builddriver.CompletedBuild) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) BuildDriverException(org.jboss.pnc.spi.builddriver.exception.BuildDriverException) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment)

Example 12 with BuildDriverResult

use of org.jboss.pnc.spi.builddriver.BuildDriverResult 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 13 with BuildDriverResult

use of org.jboss.pnc.spi.builddriver.BuildDriverResult 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 14 with BuildDriverResult

use of org.jboss.pnc.spi.builddriver.BuildDriverResult in project pnc by project-ncl.

the class BuildTaskEndpointTest method shouldAcceptCompletionResultAsSingleJson.

@Test
public void shouldAcceptCompletionResultAsSingleJson() throws RemoteResourceException {
    // given
    BuildDriverResult buildDriverResult = new DefaultBuildDriverResult("The log!", BuildStatus.SYSTEM_ERROR, java.util.Optional.of("12345"));
    BuildDriverResultRest buildDriverResultRest = new BuildDriverResultRest(buildDriverResult);
    BuildResultRest buildResultRest = new BuildResultRest();
    buildResultRest.setBuildDriverResult(buildDriverResultRest);
    // when
    HttpPost request = new HttpPost(url + BASE_REST_PATH + "/build-tasks/42/completed");
    request.addHeader(Credentials.USER.createAuthHeader(BasicHeader::new));
    request.addHeader("Content-type", MediaType.APPLICATION_JSON);
    String jsonBody = JsonOutputConverterMapper.apply(buildResultRest);
    log.debug("Json body: {}.", jsonBody);
    request.setEntity(new StringEntity(jsonBody, ContentType.APPLICATION_JSON));
    // then
    int statusCode = -1;
    try (CloseableHttpClient httpClient = HttpUtils.getPermissiveHttpClient()) {
        try (CloseableHttpResponse response = httpClient.execute(request)) {
            statusCode = response.getStatusLine().getStatusCode();
            Assert.assertEquals("Received error response code. Response: " + printEntity(response), // validation failure is expected; 500 when deserialization fails
            400, statusCode);
        }
    } catch (IOException e) {
        Assertions.fail("Cannot invoke remote endpoint.", e);
    }
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) DefaultBuildDriverResult(org.jboss.pnc.termdbuilddriver.DefaultBuildDriverResult) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) DefaultBuildDriverResult(org.jboss.pnc.termdbuilddriver.DefaultBuildDriverResult) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) BuildDriverResultRest(org.jboss.pnc.bpm.model.BuildDriverResultRest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 15 with BuildDriverResult

use of org.jboss.pnc.spi.builddriver.BuildDriverResult 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)

Aggregations

BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)15 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)7 BuildResult (org.jboss.pnc.spi.BuildResult)6 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)4 BuildStatus (org.jboss.pnc.enums.BuildStatus)3 BuildDriverException (org.jboss.pnc.spi.builddriver.exception.BuildDriverException)3 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 BuildDriverResultRest (org.jboss.pnc.bpm.model.BuildDriverResultRest)2 BuildResultRest (org.jboss.pnc.bpm.model.BuildResultRest)2 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)2 BuildExecutionStatus (org.jboss.pnc.enums.BuildExecutionStatus)2 Artifact (org.jboss.pnc.model.Artifact)2 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)2 CompletedBuild (org.jboss.pnc.spi.builddriver.CompletedBuild)2 ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)2 EnvironmentDriverResult (org.jboss.pnc.spi.environment.EnvironmentDriverResult)2 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)2 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)2