Search in sources :

Example 36 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class BuildProviderImplTest method mockBuildTask.

private BuildTask mockBuildTask(String buildConfigName) {
    BuildConfigurationAudited bca = mock(BuildConfigurationAudited.class);
    when(bca.getName()).thenReturn(buildConfigName);
    BuildTask bt = mock(BuildTask.class);
    when(bt.getId()).thenReturn(getNextId().getId());
    when(bt.getSubmitTime()).thenReturn(new Date());
    when(bt.getBuildConfigurationAudited()).thenReturn(bca);
    try {
        // make sure there are no two builds with the same start date
        Thread.sleep(1L);
    } catch (InterruptedException e) {
        logger.error("I can get no sleep.", e);
    }
    runningBuilds.add(bt);
    return bt;
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Date(java.util.Date)

Example 37 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class BuildProviderImplTest method testGetLatestRunningBuild.

@Test
public void testGetLatestRunningBuild() {
    // Prepare
    mockBuildTask();
    mockBuildTask();
    mockBuildRecord();
    BuildTask latestRunning = mockBuildTask();
    mockBuildRecord();
    // When
    BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", true, true, "");
    Page<Build> builds = provider.getBuilds(pageInfo);
    // Verify
    assertEquals(1, builds.getTotalHits());
    assertEquals(latestRunning.getId(), builds.getContent().iterator().next().getId());
}
Also used : BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Build(org.jboss.pnc.dto.Build) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) Test(org.junit.Test)

Example 38 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class DatastoreAdapter method initBuildRecordBuilder.

/**
 * Initialize a new BuildRecord.Builder based on the data contained in the BuildTask. Note, this must be done inside
 * a transaction because it fetches the BuildRecordSet entities from the database.
 *
 * @return The initialized build record builder
 */
private BuildRecord.Builder initBuildRecordBuilder(BuildTask buildTask) {
    BuildOptions buildOptions = buildTask.getBuildOptions();
    BuildRecord.Builder builder = BuildRecord.Builder.newBuilder().id(buildTask.getId()).buildConfigurationAudited(buildTask.getBuildConfigurationAudited()).user(buildTask.getUser()).submitTime(buildTask.getSubmitTime()).startTime(buildTask.getStartTime()).productMilestone(buildTask.getProductMilestone()).temporaryBuild(buildOptions.isTemporaryBuild()).alignmentPreference(buildOptions.getAlignmentPreference()).noRebuildCause(buildTask.getNoRebuildCause());
    if (buildTask.getEndTime() == null) {
        buildTask.setEndTime(Date.from(Instant.now()));
    }
    builder.endTime(buildTask.getEndTime());
    if (buildTask.getBuildConfigSetRecordId() != null) {
        BuildConfigSetRecord buildConfigSetRecord = datastore.getBuildConfigSetRecordById(buildTask.getBuildConfigSetRecordId());
        builder.buildConfigSetRecord(buildConfigSetRecord);
    }
    List<Base32LongID> dependencies = buildTask.getDependencies().stream().map(BuildTask::getId).map(Base32LongID::new).collect(Collectors.toList());
    builder.dependencyBuildRecordIds(dependencies.toArray(new Base32LongID[dependencies.size()]));
    List<Base32LongID> dependants = buildTask.getDependants().stream().map(BuildTask::getId).map(Base32LongID::new).collect(Collectors.toList());
    builder.dependentBuildRecordIds(dependants.toArray(new Base32LongID[dependants.size()]));
    return builder;
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 39 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class DefaultBuildCoordinator method cancelSet.

@Override
public boolean cancelSet(int buildSetTaskId) {
    BuildConfigSetRecord record = datastoreAdapter.getBuildCongigSetRecordById(buildSetTaskId);
    if (record == null) {
        log.error("Could not find buildConfigSetRecord with id : {}", buildSetTaskId);
        return false;
    }
    log.debug("Cancelling Build Configuration Set: {}", buildSetTaskId);
    getSubmittedBuildTasks().stream().filter(Objects::nonNull).filter(t -> t.getBuildSetTask() != null && t.getBuildSetTask().getId().equals(buildSetTaskId)).forEach(buildTask -> {
        try {
            MDCUtils.addBuildContext(getMDCMeta(buildTask));
            log.debug("Received cancel request for buildTaskId: {}.", buildTask.getId());
            cancel(buildTask.getId());
        } catch (CoreException e) {
            log.error("Unable to cancel the build [" + buildTask.getId() + "].", e);
        } finally {
            MDCUtils.removeBuildContext();
        }
    });
    record.setStatus(BuildStatus.CANCELLED);
    record.setEndTime(Date.from(Instant.now()));
    try {
        datastoreAdapter.saveBuildConfigSetRecord(record);
    } catch (DatastoreException e) {
        log.error("Failed to update BuildConfigSetRecord (id: {} ) with status CANCELLED", record.getId(), e);
    }
    return true;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) ScheduledFuture(java.util.concurrent.ScheduledFuture) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) GroupBuildMapper(org.jboss.pnc.mapper.api.GroupBuildMapper) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) Map(java.util.Map) CollectionUtils.hasCycle(org.jboss.pnc.common.util.CollectionUtils.hasCycle) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) EnumMap(java.util.EnumMap) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) Objects(java.util.Objects) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) MDCExecutors(org.jboss.pnc.common.concurrent.MDCExecutors) PostConstruct(javax.annotation.PostConstruct) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) NamedThreadFactory(org.jboss.pnc.common.concurrent.NamedThreadFactory) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) RepourResult(org.jboss.pnc.spi.repour.RepourResult) Quicksort(org.jboss.pnc.common.util.Quicksort) ExecutorService(java.util.concurrent.ExecutorService) Event(javax.enterprise.event.Event) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) Logger(org.slf4j.Logger) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildRecord(org.jboss.pnc.model.BuildRecord) ProcessStageUtils(org.jboss.pnc.common.util.ProcessStageUtils) PollingMonitor(org.jboss.pnc.common.monitor.PollingMonitor) TimeUnit(java.util.concurrent.TimeUnit) Build(org.jboss.pnc.dto.Build) Sequence(org.jboss.pnc.common.concurrent.Sequence) CoreException(org.jboss.pnc.spi.exception.CoreException) Objects(java.util.Objects) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 40 with BuildTask

use of org.jboss.pnc.spi.coordinator.BuildTask in project pnc by project-ncl.

the class DefaultBuildCoordinatorTest method shouldStoreSshCredentialsOnSshEnabled.

@Test
public void shouldStoreSshCredentialsOnSshEnabled() throws DatastoreException {
    BuildTask buildTask = mockBuildTask();
    BuildResult buildResult = mockBuildResult(true);
    SshCredentials sshCredentials = new SshCredentials();
    sshCredentials.setCommand(RandomStringUtils.randomAlphabetic(30));
    sshCredentials.setPassword(RandomStringUtils.randomAlphabetic(30));
    when(buildResult.getEnvironmentDriverResult()).thenReturn(Optional.of(new EnvironmentDriverResult(CompletionStatus.FAILED, "", Optional.of(sshCredentials))));
    when(buildResult.getRepourResult()).thenReturn(Optional.of(RepourResultMock.mock()));
    ArgumentGrabbingAnswer<BuildRecord.Builder> answer = new ArgumentGrabbingAnswer<>(BuildRecord.Builder.class);
    when(datastore.storeCompletedBuild(any(BuildRecord.Builder.class), any(), any())).thenAnswer(answer);
    coordinator.completeBuild(buildTask, buildResult);
    assertThat(answer.arguments).hasSize(1);
    BuildRecord.Builder builder = answer.arguments.iterator().next();
    BuildRecord record = builder.build();
    assertThat(record.getSshCommand()).isEqualTo(sshCredentials.getCommand());
    assertThat(record.getSshPassword()).isEqualTo(sshCredentials.getPassword());
}
Also used : BuildResult(org.jboss.pnc.spi.BuildResult) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) SshCredentials(org.jboss.pnc.spi.SshCredentials) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Aggregations

BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)43 Test (org.junit.Test)23 BuildRecord (org.jboss.pnc.model.BuildRecord)15 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)15 Build (org.jboss.pnc.dto.Build)13 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)13 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 BuildOptions (org.jboss.pnc.spi.BuildOptions)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Inject (javax.inject.Inject)11 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)11 CoreException (org.jboss.pnc.spi.exception.CoreException)11 User (org.jboss.pnc.model.User)10 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)10 Date (java.util.Date)9 Set (java.util.Set)9 HashSet (java.util.HashSet)8 List (java.util.List)8