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;
}
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());
}
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;
}
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;
}
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());
}
Aggregations