use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.
the class BuildCauseProducerServiceTest method manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials.
@Test
public void manualTrigger_shouldNotUpdatePipelineConfigWhenConfigRepoIsNotInMaterials() {
HgMaterial material1 = new HgMaterial("url", null);
HgMaterialConfig materialConfig1 = new HgMaterialConfig("url", null);
HgMaterialConfig materialConfig2 = new HgMaterialConfig("url2", null);
pipelineConfig.addMaterialConfig(materialConfig1);
pipelineConfig.setOrigin(new RepoConfigOrigin(new ConfigRepoConfig(materialConfig2, "plug"), "revision1"));
when(materialConfigConverter.toMaterial(materialConfig1)).thenReturn(material1);
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), new HashMap<>(), new HashMap<>()), new ServerHealthStateOperationResult());
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
MaterialUpdateStatusListener statusListener = extractMaterialListenerInstanceFromRegisterCall();
statusListener.onMaterialUpdate(new MaterialUpdateSuccessfulMessage(material1, 0));
verify(mockMaterialUpdateStatusNotifier).removeListenerFor(pipelineConfig);
verify(goConfigService, times(1)).pipelineConfigNamed(pipelineConfig.name());
}
use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.
the class ScheduleService method lockAndRerunStage.
private Stage lockAndRerunStage(String pipelineName, String counterOrLabel, String stageName, StageInstanceCreator creator, final ErrorConditionHandler errorHandler) {
synchronized (mutexForPipeline(pipelineName)) {
OperationResult result = new ServerHealthStateOperationResult();
if (!schedulingChecker.canSchedule(result)) {
errorHandler.cantSchedule(result.getServerHealthState().getDescription(), pipelineName, stageName);
}
String username = CaseInsensitiveString.str(UserHelper.getUserName().getUsername());
if (!securityService.hasOperatePermissionForStage(pipelineName, stageName, username)) {
errorHandler.noOperatePermission(pipelineName, stageName);
}
Pipeline pipeline = pipelineService.fullPipelineByCounterOrLabel(pipelineName, counterOrLabel);
if (pipeline == null) {
errorHandler.nullPipeline(pipelineName, counterOrLabel, stageName);
}
if (!pipeline.hasStageBeenRun(stageName)) {
if (goConfigService.hasPreviousStage(pipelineName, stageName)) {
CaseInsensitiveString previousStageName = goConfigService.previousStage(pipelineName, stageName).name();
if (!pipeline.hasStageBeenRun(CaseInsensitiveString.str(previousStageName))) {
errorHandler.previousStageNotRun(pipeline.getName(), stageName);
}
}
}
Stage stage = internalRerun(pipeline, stageName, username, creator, errorHandler);
if (stage == null) {
errorHandler.nullStage();
}
return stage;
}
}
use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.
the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered.
@Test
public void shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered() throws Exception {
GitTestRepo otherGitRepo = new GitTestRepo(temporaryFolder);
pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
pipelineConfig.materialConfigs().clear();
materialConfig = hgRepo.createMaterialConfig("dest1");
materialConfig.setAutoUpdate(true);
pipelineConfig.materialConfigs().add(materialConfig);
// new material is added
GitMaterial gitMaterial = otherGitRepo.createMaterial("dest2");
gitMaterial.setAutoUpdate(true);
MaterialConfig otherMaterialConfig = gitMaterial.config();
otherMaterialConfig.setAutoUpdate(true);
pipelineConfig.materialConfigs().add(otherMaterialConfig);
List<Modification> mod = configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
final HashMap<String, String> revisions = new HashMap<>();
final HashMap<String, String> environmentVariables = new HashMap<>();
buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
cachedGoConfig.throwExceptionIfExists();
Map<String, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(20);
assertThat(afterLoad.keySet(), hasItem(PIPELINE_NAME));
BuildCause cause = afterLoad.get(PIPELINE_NAME);
assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
String lastPushedRevision = mod.get(0).getRevision();
assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
assertThat(pipelineConfig.materialConfigs(), hasItem(otherMaterialConfig));
assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPushedRevision));
// update of commited material happened during manual trigger
MaterialRevisions modificationsInDb = materialRepository.findLatestModification(gitMaterial);
assertThat(modificationsInDb.latestRevision(), is(otherGitRepo.latestModification().get(0).getRevision()));
}
use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldScheduleAfterAllMaterialsAreUpdated.
@Test
public void shouldScheduleAfterAllMaterialsAreUpdated() throws Exception {
HgMaterial hgMaterial = new HgMaterial("url", null);
HgMaterialConfig hgMaterialConfig = hg("url", null);
SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
SvnMaterialConfig svnMaterialConfig = svn("url", null, null, false);
pipelineConfig.addMaterialConfig(hgMaterialConfig);
pipelineConfig.addMaterialConfig(svnMaterialConfig);
GoConfigService service = mock(GoConfigService.class);
when(service.pipelineConfigNamed(pipelineConfig.name())).thenReturn(pipelineConfig);
when(materialConfigConverter.toMaterial(hgMaterialConfig)).thenReturn(hgMaterial);
when(materialConfigConverter.toMaterial(svnMaterialConfig)).thenReturn(svnMaterial);
MaterialUpdateStatusNotifier notifier = new MaterialUpdateStatusNotifier(mock(MaterialUpdateCompletedTopic.class));
buildCauseProducerService = spy(createBuildCauseProducerService(notifier));
buildCauseProducerService.manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(), new ServerHealthStateOperationResult());
final HashMap<String, String> stringStringHashMap = new HashMap<>();
doReturn(ServerHealthState.success(healthStateType)).when(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), new ScheduleOptions(eq(EMPTY_REVISIONS), stringStringHashMap, new HashMap<>()), any(ServerHealthStateOperationResult.class), eq(12345L));
assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
notifier.onMessage(new MaterialUpdateSuccessfulMessage(hgMaterial, 1111L));
assertThat(notifier.hasListenerFor(pipelineConfig), is(true));
notifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 2222L));
assertThat(notifier.hasListenerFor(pipelineConfig), is(false));
verify(buildCauseProducerService).newProduceBuildCause(eq(pipelineConfig), any(ManualBuild.class), eq(new ScheduleOptions()), any(ServerHealthStateOperationResult.class), eq(2222L));
}
use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult 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));
}
Aggregations