Search in sources :

Example 1 with BuildConflictException

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

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

the class SkippingBuiltConfigsTest method shouldTriggerTheSameBuildConfigurationWithNewRevision.

@Test
public void shouldTriggerTheSameBuildConfigurationWithNewRevision() throws Exception {
    coordinator.start();
    buildRecordRepository.clear();
    // given
    BuildConfiguration testConfiguration = config("shouldRejectBCWithNewRevision");
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setBuildDependencies(false);
    // when
    coordinator.build(testConfiguration, user, buildOptions);
    BuildConfiguration updatedConfiguration = updateConfiguration(testConfiguration);
    BuildSetTask buildSetTask;
    boolean rejected = false;
    try {
        buildSetTask = coordinator.build(updatedConfiguration, user, buildOptions);
    } catch (BuildConflictException e) {
        rejected = true;
    }
    // then
    Assert.assertFalse("The task was rejected.", rejected);
    waitForEmptyBuildQueue();
    assertThat(getNonRejectedBuildRecords().size()).isEqualTo(2);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Test(org.junit.Test)

Example 3 with BuildConflictException

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

the class GroupConfigurationEndpointImpl method triggerBuild.

private GroupBuild triggerBuild(String groupConfigId, Optional<GroupBuildRequest> buildConfigRevisions, GroupBuildParameters buildParams) {
    try {
        BuildOptions buildOptions = toBuildOptions(buildParams);
        int groupBuildId = buildTriggerer.triggerGroupBuild(Integer.parseInt(groupConfigId), buildConfigRevisions, buildOptions);
        return groupBuildProvider.getSpecific(Integer.toString(groupBuildId));
    } catch (BuildConflictException ex) {
        throw new AlreadyRunningException(ex, ex.getBuildTaskId());
    } catch (CoreException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) GroupConfigurationEndpoint(org.jboss.pnc.rest.api.endpoints.GroupConfigurationEndpoint)

Aggregations

BuildOptions (org.jboss.pnc.spi.BuildOptions)3 BuildConflictException (org.jboss.pnc.spi.exception.BuildConflictException)3 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)2 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)2 CoreException (org.jboss.pnc.spi.exception.CoreException)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Semaphore (java.util.concurrent.Semaphore)1 TimeUnit (java.util.concurrent.TimeUnit)1 Consumer (java.util.function.Consumer)1 Dependent (javax.enterprise.context.Dependent)1 Inject (javax.inject.Inject)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 TestCDIBuildSetStatusChangedReceiver (org.jboss.pnc.coordinator.test.event.TestCDIBuildSetStatusChangedReceiver)1 TestCDIBuildStatusChangedReceiver (org.jboss.pnc.coordinator.test.event.TestCDIBuildStatusChangedReceiver)1 BuildCoordinationStatus (org.jboss.pnc.enums.BuildCoordinationStatus)1 BuildStatus (org.jboss.pnc.enums.BuildStatus)1