@Override public void update(CruiseConfig preprocessedConfig) { preprocessedConfig.addEnvironment((BasicEnvironmentConfig) environmentConfig); }
public EnvironmentConfig addEnvironmentConfig(CruiseConfig config, String envName, String... pipelineNames) { BasicEnvironmentConfig env = EnvironmentConfigMother.environment(envName, pipelineNames); config.addEnvironment(env); return env; }
@Test public void shouldNotWriteWhenEnvironmentNameIsNotSet() throws Exception { String xml = ConfigFileFixture.CONFIG_WITH_NANT_AND_EXEC_BUILDER; CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(xml).config; cruiseConfig.addEnvironment(new BasicEnvironmentConfig()); try { xmlWriter.write(cruiseConfig, output, false); fail("Should not be able to save config when the environment name is not set"); } catch (Exception e) { assertThat(e.getMessage(), containsString("\"Name\" is required for Environment")); } }
@Test public void shouldNotLockAPipelineWhenItIsAddedToAnEnvironment() throws Exception { CruiseConfig config = GoConfigMother.configWithPipelines("pipeline-1"); EnvironmentConfig env = config.addEnvironment("environment"); env.addPipeline(new CaseInsensitiveString("pipeline-1")); assertThat(config.isPipelineLockable("pipeline-1"), is(false)); }
@Override public CruiseConfig update(CruiseConfig cruiseConfig) { if (partial != null && fingerprint != null) { PartialConfig config = resolver.findPartialByFingerprint(cruiseConfig, fingerprint); if (null != config) { cruiseConfig.getPartials().remove(config); } cruiseConfig.getPartials().add(CLONER.deepClone(partial)); for (PartialConfig partial : cruiseConfig.getPartials()) { for (EnvironmentConfig environmentConfig : partial.getEnvironments()) { if (!cruiseConfig.getEnvironments().hasEnvironmentNamed(environmentConfig.name())) { cruiseConfig.addEnvironment(new BasicEnvironmentConfig(environmentConfig.name())); } } for (PipelineConfigs pipelineConfigs : partial.getGroups()) { if (!cruiseConfig.getGroups().hasGroup(pipelineConfigs.getGroup())) { cruiseConfig.getGroups().add(new BasicPipelineConfigs(pipelineConfigs.getGroup(), new Authorization())); } } } } return cruiseConfig; } }
@Test public void shouldCollectOriginErrorsFromEnvironments_InMergedConfig() { pipelines = new BasicPipelineConfigs("group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1")); BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines); PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipe2", "g2"); partialConfig.getGroups().get(0).get(0).setOrigin(new RepoConfigOrigin()); cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig); BasicEnvironmentConfig uat = new BasicEnvironmentConfig(new CaseInsensitiveString("UAT")); uat.addPipeline(new CaseInsensitiveString("pipe2")); cruiseConfig.addEnvironment(uat); List<ConfigErrors> allErrors = cruiseConfig.validateAfterPreprocess(); assertThat(allErrors.size(), is(1)); assertNotNull(allErrors.get(0).on("origin")); }