Search in sources :

Example 1 with CoreException

use of org.jboss.pnc.spi.exception.CoreException 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 CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class CancelledBuildTest method cancelBuildingConfigSetTestCase.

@Test(timeout = 5_000)
public void cancelBuildingConfigSetTestCase() throws Exception {
    // given
    DatastoreMock datastoreMock = new DatastoreMock();
    TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
    BuildCoordinator coordinator = buildCoordinatorFactory.createBuildCoordinator(datastoreMock).coordinator;
    BuildConfigurationSet configurationSet = configurationBuilder.buildConfigurationSetForCancel(1);
    List<BuildStatusChangedEvent> receivedStatuses = new ArrayList<>();
    Consumer<BuildStatusChangedEvent> onStatusUpdate = (event) -> {
        receivedStatuses.add(event);
        if (event.getBuild().getBuildConfigRevision().getId().equals("2") && event.getNewStatus().equals(BuildStatus.BUILDING)) {
            CompletableFuture.runAsync(() -> {
                try {
                    // wait a bit for build execution to start
                    Thread.sleep(250);
                    // we need to get buildConfigSet id to cancel BuildGroup, it is not provided by event class
                    // directly, so we need to dit it up from buildTaskId that event provides
                    log.info("Cancelling ...");
                    coordinator.cancelSet(getBuildConfigSetId(coordinator, event.getBuild().getId()));
                } catch (CoreException | InterruptedException e) {
                    log.error("Unable to cancel the build.", e);
                    Assert.fail("Unable to cancel the build.");
                }
            });
        }
    };
    // when
    BuildSetTask buildSetTask = buildProjects(configurationSet, coordinator, onStatusUpdate, 2);
    // expect
    List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
    Assert.assertEquals("Incorrect number of build records in datastore: " + buildRecords, 3, buildRecords.size());
    for (BuildRecord buildRecord : buildRecords) {
        Assert.assertNotNull(buildRecord.getSubmitTime());
        switch(buildRecord.getBuildConfigurationId()) {
            case 1:
                Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
                continue;
            case 2:
                Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
                break;
            case 3:
                Assert.assertEquals(BuildStatus.SUCCESS, buildRecord.getStatus());
                break;
            default:
                Assert.fail("Invalid build configuration ID");
                break;
        }
        Assert.assertNotNull(buildRecord.getStartTime());
        Assert.assertNotNull(buildRecord.getEndTime());
    }
    // 3 is independent, 2 is dependent on 3, 1 is dependent on 2
    for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
        String buildTaskId = buildTask.getId();
        switch(buildTask.getBuildConfigurationAudited().getId()) {
            case 1:
                // Building status is skipped (cancelled before it can start building)
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
                break;
            case 2:
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.WAITING_FOR_DEPENDENCIES, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.CANCELLED, buildTaskId);
                break;
            case 3:
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.ENQUEUED, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.BUILDING, buildTaskId);
                assertStatusUpdateReceived(receivedStatuses, BuildStatus.SUCCESS, buildTaskId);
                break;
            default:
                break;
        }
    }
}
Also used : BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Logger(org.slf4j.Logger) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Assert(org.junit.Assert) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArrayList(java.util.ArrayList) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test)

Example 3 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class StatusUpdatesTest method buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState.

@Test
@InSequence(10)
public void buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState() throws DatastoreException, InterruptedException, CoreException {
    ObjectWrapper<BuildSetStatusChangedEvent> receivedBuildSetStatusChangedEvent = new ObjectWrapper<>();
    Consumer<BuildSetStatusChangedEvent> statusUpdateListener = receivedBuildSetStatusChangedEvent::set;
    testCDIBuildSetStatusChangedReceiver.addBuildSetStatusChangedEventListener(statusUpdateListener);
    User user = User.Builder.newBuilder().id(1).username("test-user-1").build();
    Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> {
    }).getBuildTasks();
    buildTasks.forEach((bt) -> {
        buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE);
        buildCoordinator.completeBuild(bt, createBuildResult());
    });
    this.waitForConditionWithTimeout(() -> buildTasks.stream().allMatch(task -> task.getStatus().isCompleted()), 4);
    Assert.assertNotNull("Did not receive build set status update.", receivedBuildSetStatusChangedEvent.get());
    Assert.assertEquals(BuildSetStatus.DONE, receivedBuildSetStatusChangedEvent.get().getNewStatus());
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) LoggerFactory(org.slf4j.LoggerFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) CoreException(org.jboss.pnc.spi.exception.CoreException) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) IndyRepositoryManagerResult(org.jboss.pnc.indyrepositorymanager.IndyRepositoryManagerResult) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) RunWith(org.junit.runner.RunWith) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) BuildCallBack(org.jboss.pnc.coordinator.notifications.buildTask.BuildCallBack) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BuildCoordinatorDeployments(org.jboss.pnc.coordinator.test.BuildCoordinatorDeployments) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildTasksInitializer(org.jboss.pnc.coordinator.builder.BuildTasksInitializer) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) Assert(org.junit.Assert) Sequence(org.jboss.pnc.common.concurrent.Sequence) Collections(java.util.Collections) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 4 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class BuildTasksInitializer method initBuildSetTask.

private BuildSetTask initBuildSetTask(BuildConfigurationSet buildConfigurationSet, User user, BuildOptions buildOptions) throws CoreException {
    BuildConfigSetRecord buildConfigSetRecord = BuildConfigSetRecord.Builder.newBuilder().buildConfigurationSet(buildConfigurationSet).user(user).startTime(new Date()).status(org.jboss.pnc.enums.BuildStatus.BUILDING).temporaryBuild(buildOptions.isTemporaryBuild()).alignmentPreference(buildOptions.getAlignmentPreference()).build();
    final BuildConfigSetRecord configSetRecord;
    try {
        configSetRecord = saveBuildConfigSetRecord(buildConfigSetRecord);
    } catch (DatastoreException e) {
        log.error("Failed to store build config set record: " + e);
        throw new CoreException(e);
    }
    return BuildSetTask.Builder.newBuilder().buildConfigSetRecord(configSetRecord).buildOptions(buildOptions).build();
}
Also used : CoreException(org.jboss.pnc.spi.exception.CoreException) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Date(java.util.Date) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 5 with CoreException

use of org.jboss.pnc.spi.exception.CoreException in project pnc by project-ncl.

the class DefaultBuildCoordinator method processBuildTask.

private void processBuildTask(BuildTask task) {
    try {
        // process only tasks with status ENQUEUED
        synchronized (task) {
            if (task.getStatus() != BuildCoordinationStatus.ENQUEUED) {
                log.debug("Skipping the execution of build task {} as it has been processed already. Status: {}.", task.getId(), task.getStatus());
                return;
            }
            if (!task.getBuildOptions().isForceRebuild() && !datastoreAdapter.requiresRebuild(task, new HashSet<>())) {
                completeNoBuild(task, CompletionStatus.NO_REBUILD_REQUIRED);
                return;
            }
            task.setStartTime(new Date());
            updateBuildTaskStatus(task, BuildCoordinationStatus.BUILDING);
        }
        buildScheduler.startBuilding(task);
    } catch (CoreException | ExecutorException e) {
        log.debug(" Build coordination task failed. Setting it as SYSTEM_ERROR.", e);
        updateBuildTaskStatus(task, BuildCoordinationStatus.SYSTEM_ERROR, e.getMessage());
        try {
            datastoreAdapter.storeResult(task, Optional.empty(), e);
        } catch (DatastoreException e1) {
            log.error("Unable to store error [" + e.getMessage() + "] of build coordination task [" + task.getId() + "].", e1);
        }
    } catch (Error error) {
        log.error("Build coordination task failed with error! Setting it as SYSTEM_ERROR.", error);
        log.error("The system probably is in an invalid state!");
        updateBuildTaskStatus(task, BuildCoordinationStatus.SYSTEM_ERROR, error.getMessage());
        try {
            datastoreAdapter.storeResult(task, Optional.empty(), error);
        } catch (DatastoreException e1) {
            log.error("Unable to store error [" + error.getMessage() + "] of build coordination task [" + task.getId() + "].", e1);
        }
        throw error;
    } finally {
        ProcessStageUtils.logProcessStageEnd(BuildCoordinationStatus.ENQUEUED.toString());
    }
}
Also used : ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) CoreException(org.jboss.pnc.spi.exception.CoreException) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Date(java.util.Date) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate)

Aggregations

CoreException (org.jboss.pnc.spi.exception.CoreException)21 Inject (javax.inject.Inject)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Consumer (java.util.function.Consumer)9 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)9 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)8 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)8 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)8 BuildStatus (org.jboss.pnc.enums.BuildStatus)7 BuildOptions (org.jboss.pnc.spi.BuildOptions)7 DatastoreException (org.jboss.pnc.spi.datastore.DatastoreException)7 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)7 List (java.util.List)6 TestProjectConfigurationBuilder (org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder)6 Optional (java.util.Optional)5 Set (java.util.Set)5 BuildCoordinationStatus (org.jboss.pnc.enums.BuildCoordinationStatus)5 BuildSetStatus (org.jboss.pnc.spi.BuildSetStatus)5 BuildSetStatusChangedEvent (org.jboss.pnc.spi.events.BuildSetStatusChangedEvent)5