use of com.rits.cloning.Cloner in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldCancelBuildsForDeletedStagesWhenPipelineConfigChanges.
@Test
public void shouldCancelBuildsForDeletedStagesWhenPipelineConfigChanges() throws Exception {
buildAssignmentService.initialize();
fixture.createPipelineWithFirstStageScheduled();
buildAssignmentService.onTimer();
PipelineConfig pipelineConfig = new Cloner().deepClone(configHelper.getCachedGoConfig().currentConfig().getPipelineConfigByName(new CaseInsensitiveString(fixture.pipelineName)));
String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
String md5 = CachedDigestUtils.md5Hex(xml);
StageConfig devStage = pipelineConfig.findBy(new CaseInsensitiveString(fixture.devStage));
pipelineConfig.remove(devStage);
pipelineConfigService.updatePipelineConfig(loserUser, pipelineConfig, md5, new HttpLocalizedOperationResult());
Pipeline pipeline = pipelineDao.mostRecentPipeline(fixture.pipelineName);
JobInstance job = pipeline.getFirstStage().getJobInstances().first();
assertThat(job.getState(), is(JobState.Completed));
assertThat(job.getResult(), is(JobResult.Cancelled));
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class MergeCruiseConfigTest method shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned.
@Test
public void shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned() {
//we need this case because cloning has proven to be problematic with complex object graph in merged config
BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipeline-1", "g2");
partialConfig.setOrigin(new RepoConfigOrigin());
CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
Cloner CLONER = new Cloner();
CruiseConfig cloned = CLONER.deepClone(config);
List<ConfigErrors> allErrors = cloned.validateAfterPreprocess();
assertThat(allErrors.size(), is(2));
assertThat(allErrors.get(0).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
assertThat(allErrors.get(1).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class GoConfigParallelGraphWalkerTest method shouldAddErrorsToRawCruiseConfigWhenTemplateHasErrors.
@Test
public void shouldAddErrorsToRawCruiseConfigWhenTemplateHasErrors() {
CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
cruiseConfig.getTemplates().add(new PipelineTemplateConfig(new CaseInsensitiveString("invalid template name"), new StageConfig(new CaseInsensitiveString("stage-1"), new JobConfigs(new JobConfig("job-1")))));
PipelineConfig pipelineWithTemplate = new PipelineConfig(new CaseInsensitiveString("pipeline-with-template"), MaterialConfigsMother.defaultMaterialConfigs());
pipelineWithTemplate.setTemplateName(new CaseInsensitiveString("invalid template name"));
cruiseConfig.getGroups().get(0).add(pipelineWithTemplate);
CruiseConfig rawCruiseConfig = new Cloner().deepClone(cruiseConfig);
MagicalGoConfigXmlLoader.validate(cruiseConfig);
cruiseConfig.copyErrorsTo(rawCruiseConfig);
ConfigErrors templateErrors = rawCruiseConfig.getTemplateByName(new CaseInsensitiveString("invalid template name")).errors();
assertThat(templateErrors.getAll().size(), is(1));
assertThat(templateErrors.getAll().get(0), is("Invalid template name 'invalid template name'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class GoConfigServiceIntegrationTest method shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict.
@Test
public void shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict() {
configHelper.addPipeline("pipeline", "stage");
String md5 = goConfigService.getConfigForEditing().getMd5();
goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("secondStage"), md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("thirdStage"), md5, Username.ANONYMOUS, result);
assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
CruiseConfig expectedConfig = goConfigService.getConfigForEditing();
CruiseConfig modifiedConfig = new Cloner().deepClone(expectedConfig);
ReflectionUtil.setField(modifiedConfig, "md5", expectedConfig.getMd5());
PipelineConfig expected = modifiedConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline"));
expected.addStageWithoutValidityAssertion(StageConfigMother.custom("thirdStage", "job"));
PipelineConfig actual = (PipelineConfig) response.getNode();
assertThat(response.configAfterUpdate(), is(expectedConfig));
assertThat(response.getCruiseConfig(), is(modifiedConfig));
assertThat(actual, is(expected));
assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
}
use of com.rits.cloning.Cloner in project gocd by gocd.
the class PipelineConfigTreeValidator method validateDependencyMaterialsForDownstreams.
private void validateDependencyMaterialsForDownstreams(PipelineConfigSaveValidationContext validationContext, CaseInsensitiveString selected, PipelineConfig downstreamPipeline) {
Node dependenciesOfSelectedPipeline = validationContext.getDependencyMaterialsFor(selected);
for (Node.DependencyNode dependencyNode : dependenciesOfSelectedPipeline.getDependencies()) {
if (dependencyNode.getPipelineName().equals(pipelineConfig.name())) {
for (MaterialConfig materialConfig : downstreamPipeline.materialConfigs()) {
if (materialConfig instanceof DependencyMaterialConfig) {
DependencyMaterialConfig dependencyMaterialConfig = new Cloner().deepClone((DependencyMaterialConfig) materialConfig);
dependencyMaterialConfig.validate(validationContext.withParent(downstreamPipeline));
List<String> allErrors = dependencyMaterialConfig.errors().getAll();
for (String error : allErrors) {
pipelineConfig.errors().add("base", error);
}
}
}
}
}
}
Aggregations