private UpdateConfigCommand pipelineAdder(final PipelineConfig pipelineConfig, final String groupName) { return cruiseConfig -> { cruiseConfig.addPipeline(groupName, pipelineConfig); return cruiseConfig; }; }
@Test public void shouldNotWriteDuplicatedPipelines() throws Exception { String xml = ConfigFileFixture.TWO_PIPELINES; CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(xml).config; cruiseConfig.addPipeline("someGroup", PipelineConfigMother.pipelineConfig("pipeline1")); try { xmlWriter.write(cruiseConfig, output, false); fail("Should not be able to save config when there are 2 pipelines with same name"); } catch (Exception e) { assertThat(e.getMessage(), containsString("You have defined multiple pipelines named 'pipeline1'. Pipeline names must be unique. Source(s): [cruise-config.xml]")); } }
public static CruiseConfig simpleDiamond() { CruiseConfig cruiseConfig = new BasicCruiseConfig(); PipelineConfig pipeline1 = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(MaterialConfigsMother.gitMaterialConfig("g1"))); PipelineConfig pipeline2 = PipelineConfigMother.pipelineConfig("p2", new MaterialConfigs(MaterialConfigsMother.gitMaterialConfig("g1"))); PipelineConfig pipeline3 = PipelineConfigMother.pipelineConfig("p3", new MaterialConfigs(MaterialConfigsMother.dependencyMaterialConfig("p1", "stage-1-1"), MaterialConfigsMother.dependencyMaterialConfig("p2", "stage-1-1"))); cruiseConfig.addPipeline("group-1", pipeline1); cruiseConfig.addPipeline("group-1", pipeline2); cruiseConfig.addPipeline("group-1", pipeline3); return cruiseConfig; }
@Test public void shouldReturnSelectedGroupNameIfGroupNameIsSpecified() { CruiseConfig cfg = createCruiseConfig(); cfg.addPipeline("grp1", PipelineConfigMother.pipelineConfig("foo")); assertThat(cfg.sanitizedGroupName("gr1"), is("gr1")); }
@Test public void globalStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.invalidConfig())); assertTrue((serverHealthService.logs().get(0)).getPipelineNames(config).isEmpty()); }
@Test public void shouldAllowCleanupOfNonExistentStages() { CruiseConfig cruiseConfig = createCruiseConfig(); assertThat(cruiseConfig.isArtifactCleanupProhibited("foo", "bar"), is(false)); PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("foo-pipeline", "bar-stage", "baz-job"); cruiseConfig.addPipeline("defaultGrp", pipelineConfig); assertThat(cruiseConfig.isArtifactCleanupProhibited("foo-pipeline", "baz-stage"), is(false)); assertThat(cruiseConfig.isArtifactCleanupProhibited("foo-pipeline", "bar-stage"), is(false)); ReflectionUtil.setField(pipelineConfig.getFirstStageConfig(), "artifactCleanupProhibited", true); assertThat(cruiseConfig.isArtifactCleanupProhibited("foo-pipeline", "bar-stage"), is(true)); assertThat(cruiseConfig.isArtifactCleanupProhibited("fOO-pipeLINE", "BaR-StagE"), is(true)); }
@Test public void faninErrorStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(HealthStateScope.forFanin("pipeline2")))); Set<String> pipelines = (serverHealthService.logs().get(0)).getPipelineNames(config); assertEquals(Sets.newHashSet("pipeline2"), pipelines); } }
@Test public void materialStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forMaterial(hgMaterial)))); Set<String> pipelines = (serverHealthService.logs().get(0)).getPipelineNames(config); assertEquals(Sets.newHashSet("pipeline", "pipeline2"), pipelines); }
@Test public void materialUpdateStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forMaterialUpdate(hgMaterial)))); Set<String> pipelines = (serverHealthService.logs().get(0)).getPipelineNames(config); assertEquals(Sets.newHashSet("pipeline", "pipeline2"), pipelines); }
@Test public void noPipelineMatchMaterialStateRelatedPipelineNames() { HgMaterial hgMaterial = MaterialsMother.hgMaterial(); CruiseConfig config = new BasicCruiseConfig(); config.addPipeline("group", PipelineConfigMother.pipelineConfig(PIPELINE_NAME, new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(hgMaterial.config()))); config.addPipeline("group", PipelineConfigMother.pipelineConfig("pipeline3")); serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(forMaterial(MaterialsMother.p4Material())))); assertTrue((serverHealthService.logs().get(0)).getPipelineNames(config).isEmpty()); }
public PipelineConfig addPipelineWithGroupAndTimer(CruiseConfig cruiseConfig, String groupName, String pipelineName, MaterialConfigs materialConfigs, String stageName, TimerConfig timer, String... buildNames) { String cronSpec = timer == null ? null : timer.getTimerSpec(); boolean shouldTriggerOnlyOnMaterialChanges = timer != null && timer.shouldTriggerOnlyOnChanges(); StageConfig stageConfig = StageConfigMother.custom(stageName, defaultBuildPlans(buildNames)); PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString(pipelineName), PipelineLabel.COUNT_TEMPLATE, cronSpec, shouldTriggerOnlyOnMaterialChanges, materialConfigs, asList(stageConfig)); pipelineConfig.setOrigin(new FileConfigOrigin()); cruiseConfig.addPipeline(groupName, pipelineConfig); return pipelineConfig; }
@Test public void shouldReturnAllMaterialsMatchingTheFingerprint() { CruiseConfig cruiseConfig = new BasicCruiseConfig(); HgMaterialConfig hg = new HgMaterialConfig("url", null); for (int i = 0; i < 10; i++) { PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("pipeline" + i, new MaterialConfigs(hg)); cruiseConfig.addPipeline("defaultGroup", pipelineConfig); } ValidationContext context = ConfigSaveValidationContext.forChain(cruiseConfig); assertThat(context.getAllMaterialsByFingerPrint(hg.getFingerprint()).size(), is(10)); }
@Test public void shouldAddValidationErrorWhenAssociatedTemplateDoesNotExist() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("wunderbar"), new MaterialConfigs()); config.addPipeline("group", pipelineConfig); pipelineConfig.setTemplateName(new CaseInsensitiveString("does-not-exist")); pipelineConfig.validateTemplate(null); assertThat(pipelineConfig.errors().on("pipeline"), is("Pipeline 'wunderbar' refers to non-existent template 'does-not-exist'.")); }
@Test public void validate_shouldEnsureThatTemplateFollowsTheNameType() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("name"), new MaterialConfigs()); pipelineConfig.setTemplateName(new CaseInsensitiveString(".Name")); config.addPipeline("group", pipelineConfig); pipelineConfig.validateTemplate(new PipelineTemplateConfig()); assertThat(pipelineConfig.errors().isEmpty(), is(false)); assertThat(pipelineConfig.errors().on(PipelineConfig.TEMPLATE_NAME), is("Invalid template name '.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.")); }
@Test public void addPipeline_shouldAddPipelineToMain() { pipelines = new BasicPipelineConfigs("group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1")); pipelines.setOrigin(new FileConfigOrigin()); BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2")); cruiseConfig.addPipeline("group_main", PipelineConfigMother.pipelineConfig("pipe3")); assertThat(mainCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true)); assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true)); }
@Test public void shouldNotAddValidationErrorWhenAssociatedTemplateExists() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("wunderbar"), new MaterialConfigs()); config.addPipeline("group", pipelineConfig); config.addTemplate(new PipelineTemplateConfig(new CaseInsensitiveString("t1"))); pipelineConfig.setTemplateName(new CaseInsensitiveString("t1")); pipelineConfig.validateTree(PipelineConfigSaveValidationContext.forChain(true, "group", config, pipelineConfig)); assertThat(pipelineConfig.errors().getAllOn("template"), is(nullValue())); }
@Test public void shouldAllowResourcesWithParamsForJobs() throws Exception { CruiseConfig cruiseConfig = new BasicCruiseConfig(); cruiseConfig.addTemplate(new PipelineTemplateConfig(new CaseInsensitiveString("template"), stageWithJobResource("#{PLATFORM}"))); PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs()); pipelineConfig.setTemplateName(new CaseInsensitiveString("template")); pipelineConfig.addParam(new ParamConfig("PLATFORM", "windows")); cruiseConfig.addPipeline("group", pipelineConfig); List<ConfigErrors> errorses = MagicalGoConfigXmlLoader.validate(cruiseConfig); assertThat(errorses.isEmpty(), is(true)); }
@Test public void shouldValidateThatPipelineAssociatedToATemplateDoesNotHaveStagesDefinedLocally() { PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("wunderbar"), new MaterialConfigs()); config.addPipeline("g", pipelineConfig); pipelineConfig.setTemplateName(new CaseInsensitiveString("template-name")); pipelineConfig.addStageWithoutValidityAssertion(new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs())); pipelineConfig.validateTemplate(null); assertThat(pipelineConfig.errors().on("stages"), is("Cannot add stages to pipeline 'wunderbar' which already references template 'template-name'")); assertThat(pipelineConfig.errors().on("template"), is("Cannot set template 'template-name' on pipeline 'wunderbar' because it already has stages defined")); }
@Test public void shouldAllowRoleWithParamsForStageInTemplate() throws Exception { CruiseConfig cruiseConfig = new BasicCruiseConfig(); cruiseConfig.server().security().addRole(new RoleConfig(new CaseInsensitiveString("role"))); cruiseConfig.addTemplate(new PipelineTemplateConfig(new CaseInsensitiveString("template"), stageWithAuth("#{ROLE}"))); PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), new MaterialConfigs()); pipelineConfig.setTemplateName(new CaseInsensitiveString("template")); pipelineConfig.addParam(new ParamConfig("ROLE", "role")); cruiseConfig.addPipeline("group", pipelineConfig); List<ConfigErrors> errorses = MagicalGoConfigXmlLoader.validate(cruiseConfig); assertThat(errorses.isEmpty(), is(true)); }
@Test public void shouldRemoveErrorLogWhenCorrespondingMaterialIsMissing() throws Exception { serverHealthService.update(ServerHealthState.error("hg-message", "description", HealthStateType.general(forMaterial(MaterialsMother.hgMaterial())))); SvnMaterialConfig svnMaterialConfig = MaterialConfigsMother.svnMaterialConfig(); serverHealthService.update(ServerHealthState.error("svn-message", "description", HealthStateType.general(forMaterialConfig(svnMaterialConfig)))); CruiseConfig cruiseConfig = new BasicCruiseConfig(); cruiseConfig.addPipeline("defaultGroup", new PipelineConfig(new CaseInsensitiveString("dev"), new MaterialConfigs(svnMaterialConfig), new StageConfig(new CaseInsensitiveString("first"), new JobConfigs()))); serverHealthService.purgeStaleHealthMessages(cruiseConfig); assertThat(serverHealthService.logs().size(), is(1)); }