use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class ConfigMaterialUpdater method onMessage.
@Override
public void onMessage(MaterialUpdateCompletedMessage message) {
Material material = message.getMaterial();
// MDU is done using the checkout, it has done db update and stored latest changes
// but MUS is still waiting for material updated message on MaterialUpdateCompletedTopic
LOGGER.debug("[Config Material Update] Config material update completed for material {}. Starting parse process", material);
try {
if (message instanceof MaterialUpdateFailedMessage) {
MaterialUpdateFailedMessage failure = (MaterialUpdateFailedMessage) message;
LOGGER.warn("[Config Material Update] Cannot update configuration part because material update has failed. Reason: {}", failure.getReason());
} else {
File folder = materialRepository.folderFor(material);
MaterialRevisions latestModification = materialRepository.findLatestModification(material);
Revision revision = latestModification.firstModifiedMaterialRevision().getRevision();
MaterialRevision lastParseRevision = getMaterialRevisionAtLastParseAttempt(message);
if (lastParseRevision == null) {
// never parsed
updateConfigurationFromCheckout(folder, revision, material);
} else if (latestModification.findRevisionFor(material.config()).hasChangedSince(lastParseRevision)) {
// revision has changed. the config files might have been updated
updateConfigurationFromCheckout(folder, revision, material);
} else {
// revision is the same as last time, no need to parse again
}
}
} finally {
// always post the original message further
// this will remove material from inProgress in MUS
topic.post(message);
}
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class MaterialUpdateService method updateGitMaterial.
public boolean updateGitMaterial(String branchName, Collection<String> possibleUrls) {
final CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
Set<Material> allUniquePostCommitSchedulableMaterials = materialConfigConverter.toMaterials(cruiseConfig.getAllUniquePostCommitSchedulableMaterials());
Predicate<Material> predicate = new MaterialPredicate(branchName, possibleUrls);
Set<Material> allGitMaterials = allUniquePostCommitSchedulableMaterials.stream().filter(predicate).collect(Collectors.toSet());
allGitMaterials.forEach(new Consumer<Material>() {
@Override
public void accept(Material material) {
MaterialUpdateService.this.updateMaterial(material);
}
});
return !allGitMaterials.isEmpty();
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class PipelineService method populateRevisionsUsingUpstream.
private void populateRevisionsUsingUpstream(MaterialRevisions actualRevisions, MaterialRevisions newRevisions, DependencyMaterialRevision dmr, PipelineConfigDependencyGraph.PipelineConfigQueueEntry configQueueEntry) {
if (!configQueueEntry.containsPipelineInPath(dmr.getPipelineName())) {
return;
}
for (MaterialRevision materialRevision : actualRevisions) {
Material material = materialRevision.getMaterial();
if (currentPipelineHasMaterial(configQueueEntry, material) && !alreadyAdded(newRevisions, material)) {
List<PipelineConfig> paths = removePathHead(configQueueEntry);
if (!paths.isEmpty()) {
MaterialRevision revision = getRevisionFor(paths, dmr, material);
// revision is null when an upstream is both parent and grandparent
if (revision != null) {
materialRevision.replaceModifications(revision.getModifications());
newRevisions.addRevision(materialRevision);
}
}
}
}
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.
@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
String pipelineName = "pipeline";
ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
config.materialConfigs().clear();
config.addMaterialConfig(svnMaterial.config());
config.addMaterialConfig(dependencyMaterial.config());
lenient().when(pipelineService.getRevisionsBasedOnDependencies(any(MaterialRevisions.class), any(BasicCruiseConfig.class), any(CaseInsensitiveString.class))).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
when(pipelineScheduleQueue.mostRecentScheduled(new CaseInsensitiveString(pipelineName))).thenReturn(BuildCause.createNeverRun());
Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
when(specificMaterialRevisionFactory.create(any(String.class), anyMap())).thenReturn(MaterialRevisions.EMPTY);
MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
Materials materials = new Materials(svnMaterial, dependencyMaterial);
when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null);
ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
assertThat(serverHealthState.isSuccess(), is(true));
}
use of com.thoughtworks.go.domain.materials.Material in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldCancelAScheduledJobInCaseStageHasBeenRenamed.
@Test
public void shouldCancelAScheduledJobInCaseStageHasBeenRenamed() throws Exception {
Material hgMaterial = new HgMaterial("url", "folder");
String[] hgRevs = new String[] { "h1" };
u.checkinInOrder(hgMaterial, hgRevs);
ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("PIPELINE_WHICH_WILL_EVENTUALLY_CHANGE_CASE", u.m(hgMaterial));
BuildCause buildCause = BuildCause.createWithModifications(u.mrs(u.mr(u.m(hgMaterial).material, true, hgRevs)), "user");
Pipeline originalPipelineRun = scheduleService.schedulePipeline(p1.config.name(), buildCause);
ScheduleTestUtil.AddedPipeline renamedPipeline = u.renamePipelineAndFirstStage(p1, "pipeline_which_will_eventually_change_case", "NEW_RANDOM_STAGE_NAME" + UUID.randomUUID());
CruiseConfig cruiseConfig = configHelper.load();
// To Reload Job Plans
buildAssignmentService.onTimer();
buildAssignmentService.onConfigChange(cruiseConfig);
Stages allStages = stageDao.findAllStagesFor(originalPipelineRun.getName(), originalPipelineRun.getCounter());
assertThat(allStages.byName(CaseInsensitiveString.str(p1.config.first().name())).getState(), is(StageState.Cancelled));
u.checkinInOrder(hgMaterial, "h2");
BuildCause buildCauseForRenamedPipeline = BuildCause.createWithModifications(u.mrs(u.mr(u.m(hgMaterial).material, true, "h2")), "user");
Pipeline p1_2 = scheduleService.schedulePipeline(renamedPipeline.config.name(), buildCauseForRenamedPipeline);
Stages allStagesForRenamedPipeline = stageDao.findAllStagesFor(p1_2.getName(), p1_2.getCounter());
assertThat(allStagesForRenamedPipeline.byName(p1_2.getFirstStage().getName()).getState(), is(StageState.Building));
}
Aggregations