Search in sources :

Example 1 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class ProjectBuilder method buildProject.

BuildTask buildProject(BuildConfiguration buildConfiguration, BuildCoordinator buildCoordinator, Consumer<BuildStatusChangedEvent> onStatusUpdate, BuildOptions buildOptions) throws BuildConflictException, InterruptedException, CoreException {
    log.debug("Building project {}", buildConfiguration.getName());
    List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
    Consumer<BuildStatusChangedEvent> onStatusUpdateInternal = (statusUpdate) -> {
        receivedStatuses.add(statusUpdate);
        onStatusUpdate.accept(statusUpdate);
    };
    // Defines a number of callbacks, which are executed after buildStatus update
    final Semaphore semaphore = registerReleaseListenersAndAcquireSemaphore(onStatusUpdateInternal, N_STATUS_UPDATES_PER_TASK);
    BuildSetTask taskSet = buildCoordinator.build(buildConfiguration, MockUser.newTestUser(1), buildOptions);
    Set<BuildTask> buildTasks = taskSet.getBuildTasks();
    assertThat(buildTasks).hasSize(1);
    BuildTask buildTask = buildTasks.iterator().next();
    log.info("Started build task {}", buildTask);
    assertBuildStartedSuccessfully(buildTask);
    waitForStatusUpdates(N_STATUS_UPDATES_PER_TASK, semaphore, "");
    return buildTask;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) Inject(javax.inject.Inject) TestCDIBuildSetStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildSetStatusChangedReceiver) Assert.fail(org.junit.Assert.fail) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Before(org.junit.Before) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) TestCDIBuildStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildStatusChangedReceiver) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) MockUser(org.jboss.pnc.mock.model.MockUser) CoreException(org.jboss.pnc.spi.exception.CoreException) Dependent(javax.enterprise.context.Dependent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArtifactBuilder(org.jboss.pnc.mock.model.builders.ArtifactBuilder) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Semaphore(java.util.concurrent.Semaphore) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class DefaultBuildExecutor method retrieveBuildDriverResults.

private Void retrieveBuildDriverResults(BuildExecutionSession buildExecutionSession, CompletedBuild completedBuild) {
    if (completedBuild == null) {
        userLog.warn("Unable to retrieve build driver results. Most likely due to cancelled operation.");
        return null;
    }
    try {
        buildExecutionSession.setStatus(BuildExecutionStatus.COLLECTING_RESULTS_FROM_BUILD_DRIVER);
        BuildDriverResult buildResult = completedBuild.getBuildResult();
        BuildStatus buildStatus = buildResult.getBuildStatus();
        buildExecutionSession.setBuildDriverResult(buildResult);
        if (buildStatus.completedSuccessfully()) {
            userLog.info("Build successfully completed.");
            buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_COMPLETED_SUCCESS);
        } else if (buildStatus.equals(BuildStatus.CANCELLED)) {
            userLog.info("Build has been canceled.");
            buildExecutionSession.setStatus(BuildExecutionStatus.CANCELLED);
        } else {
            userLog.warn("Build completed with errors.");
            buildExecutionSession.setStatus(BuildExecutionStatus.BUILD_COMPLETED_WITH_ERROR);
        }
        return null;
    } catch (Throwable e) {
        throw new BuildProcessException(e, completedBuild.getRunningEnvironment());
    }
}
Also used : BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) BuildStatus(org.jboss.pnc.enums.BuildStatus) BuildProcessException(org.jboss.pnc.executor.exceptions.BuildProcessException)

Example 3 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class DatastoreAdapterTest method shouldStoreRepositoryManagerError.

@Test
public void shouldStoreRepositoryManagerError() throws DatastoreException {
    // given
    DatastoreMock datastore = new DatastoreMock();
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastore);
    BuildStatus buildStatus = BuildStatus.SUCCESS;
    CompletionStatus completionStatus = CompletionStatus.FAILED;
    // when
    storeResult(datastoreAdapter, buildStatus, completionStatus);
    // then
    List<BuildRecord> buildRecords = datastore.getBuildRecords();
    Assert.assertEquals(1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertEquals(BuildStatus.FAILED, buildRecord.getStatus());
    Assert.assertTrue(buildRecord.getBuildLog().contains(BUILD_LOG));
    Assert.assertTrue(buildRecord.getBuildLog().contains(REPOSITORY_MANAGER_LOG));
}
Also used : CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildStatus(org.jboss.pnc.enums.BuildStatus) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 4 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class BuildExecutorMock method startBuilding.

// @Deprecated //CDI workaround
// public BuildExecutorMock() {
// }
// 
// @Inject
// public BuildExecutorMock(RepositoryManagerFactory repositoryManagerFactory, BuildDriverFactory
// buildDriverFactory, EnvironmentDriverFactory environmentDriverFactory, Configuration configuration) {
// 
// }
@Override
public BuildExecutionSession startBuilding(BuildExecutionConfiguration buildExecutionConfiguration, Consumer<BuildExecutionStatusChangedEvent> onBuildExecutionStatusChangedEvent, String accessToken) throws ExecutorException {
    log.info("Starting mock build execution for buildExecutionConfiguration.id {}", buildExecutionConfiguration.getId());
    BuildExecutionSession buildExecutionSession = new BuildExecutionSessionMock(buildExecutionConfiguration, onBuildExecutionStatusChangedEvent);
    buildExecutionSession.setStatus(BuildExecutionStatus.NEW);
    runningExecutions.put(buildExecutionConfiguration.getId(), buildExecutionSession);
    Consumer<BuildExecutionStatus> onCompleteInternal = (buildStatus) -> {
        log.debug("Removing buildExecutionConfiguration.id [" + buildExecutionConfiguration.getId() + "] form list of running tasks.");
        runningExecutions.remove(buildExecutionConfiguration.getId());
        buildExecutionSession.setStatus(buildStatus);
    };
    CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> mockBuild(buildExecutionSession), executor).handleAsync((buildPassed, e) -> complete(buildPassed, e, onCompleteInternal), executor);
    runningFutures.put(buildExecutionConfiguration.getId(), future);
    return buildExecutionSession;
}
Also used : BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) Logger(org.slf4j.Logger) RepositoryManagerResultMock(org.jboss.pnc.mock.repositorymanager.RepositoryManagerResultMock) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) BuildStatus(org.jboss.pnc.enums.BuildStatus) BuildDriverResultMock(org.jboss.pnc.mock.builddriver.BuildDriverResultMock) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) Consumer(java.util.function.Consumer) MDCExecutors(org.jboss.pnc.common.concurrent.MDCExecutors) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) Map(java.util.Map) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) NamedThreadFactory(org.jboss.pnc.common.concurrent.NamedThreadFactory) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) ExecutorService(java.util.concurrent.ExecutorService) BuildExecutionStatus(org.jboss.pnc.enums.BuildExecutionStatus)

Example 5 with BuildStatus

use of org.jboss.pnc.enums.BuildStatus in project pnc by project-ncl.

the class TermdBuildDriver method collectResults.

private CompletedBuild collectResults(RunningEnvironment runningEnvironment, RemoteInvocationCompletion remoteInvocationCompletion, FileTransfer transfer) {
    logger.info("Collecting results ...");
    try {
        StringBuffer stringBuffer = new StringBuffer();
        String logsDirectory = runningEnvironment.getWorkingDirectory().toString();
        transfer.downloadFileToStringBuilder(stringBuffer, logsDirectory + "/console.log");
        String prependMessage = "";
        BuildStatus buildStatus = getBuildStatus(remoteInvocationCompletion.getStatus());
        if (!transfer.isFullyDownloaded()) {
            prependMessage = "----- build log was cut -----\n";
            if (buildStatus.completedSuccessfully()) {
                prependMessage = "----- build has completed successfully but it is marked as failed due to log overflow. Max log size is " + MAX_LOG_SIZE + " -----\n";
                buildStatus = BuildStatus.FAILED;
            }
        }
        return new DefaultCompletedBuild(runningEnvironment, buildStatus, remoteInvocationCompletion.getOutputChecksum(), prependMessage + stringBuffer.toString());
    } catch (Throwable e) {
        throw new RuntimeException("Cannot collect results.", e);
    }
}
Also used : BuildStatus(org.jboss.pnc.enums.BuildStatus)

Aggregations

BuildStatus (org.jboss.pnc.enums.BuildStatus)20 Test (org.junit.Test)14 GroupBuild (org.jboss.pnc.dto.GroupBuild)10 ContainerTest (org.jboss.pnc.test.category.ContainerTest)10 Build (org.jboss.pnc.dto.Build)9 BuildConfiguration (org.jboss.pnc.dto.BuildConfiguration)7 Instant (java.time.Instant)4 GroupConfiguration (org.jboss.pnc.dto.GroupConfiguration)3 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)3 GroupBuildParameters (org.jboss.pnc.rest.api.parameters.GroupBuildParameters)3 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)3 Consumer (java.util.function.Consumer)2 DatastoreAdapter (org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter)2 BuildCoordinationStatus (org.jboss.pnc.enums.BuildCoordinationStatus)2 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ArrayList (java.util.ArrayList)1