Search in sources :

Example 1 with BuildConfiguration

use of org.jboss.pnc.model.BuildConfiguration in project pnc by project-ncl.

the class AbstractDependentBuildTest method buildConfig.

protected BuildConfiguration buildConfig(String name, BuildConfiguration... dependencies) {
    int id = configIdSequence.getAndIncrement();
    Project project = Project.Builder.newBuilder().id(1).name("Mock project").build();
    BuildConfiguration config = BuildConfiguration.Builder.newBuilder().id(id).name(name).project(project).repositoryConfiguration(RepositoryConfigurationMock.newTestRepository()).buildEnvironment(BuildEnvironmentMock.newTest()).build();
    Stream.of(dependencies).forEach(config::addDependency);
    return config;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Project(org.jboss.pnc.model.Project)

Example 2 with BuildConfiguration

use of org.jboss.pnc.model.BuildConfiguration 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 3 with BuildConfiguration

use of org.jboss.pnc.model.BuildConfiguration in project pnc by project-ncl.

the class DefaultBuildCoordinatorTest method mockBuildTask.

private BuildTask mockBuildTask() {
    BuildConfiguration buildConfiguration = new BuildConfiguration();
    buildConfiguration.setId(12);
    buildConfiguration.setProject(new Project());
    buildConfiguration.setRepositoryConfiguration(RepositoryConfigurationMock.newTestRepository());
    buildConfiguration.setBuildEnvironment(BuildEnvironmentMock.newTest());
    BuildOptions buildOptions = new BuildOptions(false, true, false, false, RebuildMode.IMPLICIT_DEPENDENCY_CHECK, AlignmentPreference.PREFER_PERSISTENT);
    BuildTask buildTask = BuildTask.build(BuildConfigurationAudited.fromBuildConfiguration(buildConfiguration, 13), buildOptions, MockUser.newTestUser(1), "1", null, new Date(), null, "context-id", Optional.empty());
    buildTask.setStatus(BuildCoordinationStatus.DONE);
    return buildTask;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Project(org.jboss.pnc.model.Project) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildOptions(org.jboss.pnc.spi.BuildOptions) Date(java.util.Date)

Example 4 with BuildConfiguration

use of org.jboss.pnc.model.BuildConfiguration in project pnc by project-ncl.

the class DefaultBuildCoordinatorTest method shouldCreateNoRebuildRequiredRecords.

@Test
public void shouldCreateNoRebuildRequiredRecords() throws CoreException, TimeoutException, InterruptedException {
    when(datastore.requiresRebuild(any(BuildConfigurationAudited.class), any(Boolean.class), any(Boolean.class), nullable(AlignmentPreference.class), anySet())).thenReturn(false);
    BuildConfigurationAudited bca1 = new BuildConfigurationAudited();
    IdRev idRev1 = new IdRev(BC_1.getId(), BC_1.getId() * 1000 + 1);
    bca1.setIdRev(idRev1);
    bca1.setId(idRev1.getId());
    bca1.setRev(idRev1.getRev());
    bca1.setProject(PROJECT);
    when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_1.getId())).thenReturn(bca1);
    BuildConfigurationAudited bca3 = new BuildConfigurationAudited();
    IdRev idRev3 = new IdRev(BC_3.getId(), BC_3.getId() * 1000 + 1);
    bca3.setIdRev(idRev3);
    bca3.setId(idRev3.getId());
    bca3.setRev(idRev3.getRev());
    bca3.setProject(PROJECT);
    when(datastore.getLatestBuildConfigurationAuditedLoadBCDependencies(BC_3.getId())).thenReturn(bca3);
    Set<BuildConfiguration> buildConfigs = new HashSet<>();
    buildConfigs.add(BC_1);
    buildConfigs.add(BC_3);
    when(datastore.getBuildConfigurations(any())).thenReturn(buildConfigs);
    Set<BuildRecord> storedRecords = new HashSet<>();
    when(datastore.storeRecordForNoRebuild(any())).thenAnswer(new SaveRecordForNoRebuildAnswer(storedRecords));
    BuildSetTask bsTask = coordinator.build(BCS, USER, BUILD_OPTIONS);
    coordinator.start();
    assertThat(bsTask.getBuildConfigSetRecord().get().getStatus()).isEqualTo(BuildStatus.NO_REBUILD_REQUIRED);
    Wait.forCondition(() -> storedRecords.size() == 2, 3, ChronoUnit.SECONDS);
    assertThat(storedRecords.size()).isEqualTo(2);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) IdRev(org.jboss.pnc.model.IdRev) BuildRecord(org.jboss.pnc.model.BuildRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with BuildConfiguration

use of org.jboss.pnc.model.BuildConfiguration in project pnc by project-ncl.

the class BuildEnvironmentTest method shouldReportErrorInCaseOfPodCreationFailure.

@Test
public void shouldReportErrorInCaseOfPodCreationFailure() throws ExecutorException, InterruptedException, TimeoutException {
    BuildConfiguration buildConfiguration = configurationBuilder.build(123, "Pod creation failure");
    Set<BuildExecutionStatusChangedEvent> statusChangedEvents = new HashSet<>();
    ObjectWrapper<BuildResult> buildExecutionResultWrapper = new ObjectWrapper<>();
    runBuild(buildConfiguration, statusChangedEvents, buildExecutionResultWrapper, true);
    checkBuildStatuses(statusChangedEvents, Arrays.asList(BUILD_ENV_SETTING_UP, BUILD_ENV_WAITING, BUILD_ENV_SETUP_COMPLETE_WITH_ERROR, // supported yet
    DONE_WITH_ERRORS));
    assertNoState(statusChangedEvents, BUILD_ENV_SETUP_COMPLETE_SUCCESS);
    assertNoState(statusChangedEvents, BUILD_SETTING_UP);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildResult(org.jboss.pnc.spi.BuildResult) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) BuildExecutionStatusChangedEvent(org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)65 Test (org.junit.Test)23 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)11 HashSet (java.util.HashSet)10 BuildRecord (org.jboss.pnc.model.BuildRecord)9 Project (org.jboss.pnc.model.Project)9 BuildOptions (org.jboss.pnc.spi.BuildOptions)9 BuildResult (org.jboss.pnc.spi.BuildResult)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 List (java.util.List)8 Set (java.util.Set)8 Inject (javax.inject.Inject)8 ObjectWrapper (org.jboss.pnc.common.util.ObjectWrapper)8 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)8 BuildExecutionStatusChangedEvent (org.jboss.pnc.spi.events.BuildExecutionStatusChangedEvent)8 IdRev (org.jboss.pnc.model.IdRev)7 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)7 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)7 Collectors (java.util.stream.Collectors)5