@Override public List<PipelineConfig> getAllLocalPipelineConfigs(boolean excludeMembersOfRemoteEnvironments) { return getAllPipelineConfigs(); }
public Map<CaseInsensitiveString, PipelineConfig> pipelineConfigsAsMap() { return getAllPipelineConfigs().stream().collect(toMap(PipelineConfig::name, Function.identity())); }
@Override public List<CaseInsensitiveString> getAllPipelineNames() { List<CaseInsensitiveString> names = new ArrayList<>(); for (PipelineConfig config : getAllPipelineConfigs()) { names.add(config.name()); } return names; }
private Hashtable<CaseInsensitiveString, Node> getDependencies() { if (dependencies == null) { dependencies = new Hashtable<>(); for (PipelineConfig pipeline : cruiseConfig.getAllPipelineConfigs()) { dependencies.put(pipeline.name(), pipeline.getDependenciesAsNode()); } } return dependencies; }
@Override public ArrayList<PipelineConfig> pipelineConfigsAssociatedWithTemplate(CaseInsensitiveString templateName) { ArrayList<PipelineConfig> pipelines = new ArrayList<>(); if (templateName != null) { for (PipelineConfig pipelineConfig : getAllPipelineConfigs()) { if (pipelineConfig.hasTemplate() && pipelineConfig.getTemplateName().equals(templateName)) { pipelines.add(pipelineConfig); } } } return pipelines; }
@Override public Map<CaseInsensitiveString, List<PipelineConfig>> generatePipelineVsDownstreamMap() { List<PipelineConfig> pipelineConfigs = getAllPipelineConfigs(); Map<CaseInsensitiveString, List<PipelineConfig>> result = new HashMap<>(); for (PipelineConfig currentPipeline : pipelineConfigs) { CaseInsensitiveString currentPipelineName = currentPipeline.name(); if (!result.containsKey(currentPipelineName)) { result.put(currentPipelineName, new ArrayList<>()); } for (MaterialConfig materialConfig : currentPipeline.materialConfigs()) { if (materialConfig instanceof DependencyMaterialConfig) { CaseInsensitiveString pipelineWhichTriggersMe = ((DependencyMaterialConfig) materialConfig).getPipelineName(); if (!result.containsKey(pipelineWhichTriggersMe)) { result.put(pipelineWhichTriggersMe, new ArrayList<>()); } result.get(pipelineWhichTriggersMe).add(currentPipeline); } } } return result; }
@Override public ArrayList<CaseInsensitiveString> pipelinesAssociatedWithTemplate(CaseInsensitiveString templateName) { ArrayList<CaseInsensitiveString> pipelines = new ArrayList<>(); if (templateName != null) { for (PipelineConfig pipelineConfig : getAllPipelineConfigs()) { if (pipelineConfig.hasTemplate() && pipelineConfig.getTemplateName().equals(templateName)) { pipelines.add(pipelineConfig.getName()); } } } return pipelines; }
@Override public PipelineConfig findPipelineUsingThisPipelineAsADependency(String pipelineName) { List<PipelineConfig> configs = getAllPipelineConfigs(); for (PipelineConfig config : configs) { DependencyMaterialConfig materialConfig = config.materialConfigs().findDependencyMaterial(new CaseInsensitiveString(pipelineName)); if (materialConfig != null) { return config; } } return null; }
@Override public void encryptSecureProperties(CruiseConfig preprocessed) { for (PipelineConfig pipelineConfig : getAllPipelineConfigs()) { pipelineConfig.encryptSecureProperties(preprocessed, preprocessed.pipelineConfigByName(pipelineConfig.name())); } }
private void areThereCyclicDependencies() { final DFSCycleDetector dfsCycleDetector = new DFSCycleDetector(); final Hashtable<CaseInsensitiveString, Node> dependencyTable = getDependencyTable(); List<PipelineConfig> pipelineConfigs = this.getAllPipelineConfigs(); DependencyTable pipelineDependencyState = new DependencyTable(dependencyTable); for (PipelineConfig pipelineConfig : pipelineConfigs) { try { dfsCycleDetector.topoSort(pipelineConfig.name(), pipelineDependencyState); } catch (Exception e) { addToErrorsBaseOnMaterialsIfDoesNotExist(e.getMessage(), pipelineConfig.materialConfigs(), pipelineConfigs); } } }
@Test public void shouldNotCloneAllPipelineConfigs() { BasicCruiseConfig config = GoConfigMother.configWithPipelines("p1", "p2"); //to prime cache config.getAllPipelineConfigs(); //change state config.findGroup("defaultGroup").remove(0); BasicCruiseConfig cloned = new GoConfigCloner().deepClone(config); assertThat(ReflectionUtil.getField(config, "allPipelineConfigs"), is(not((nullValue())))); assertThat(ReflectionUtil.getField(cloned, "allPipelineConfigs"), is(nullValue())); assertThat(cloned.getAllPipelineConfigs().size(), is(1)); }
@Test public void shouldGetFilesToLoadMatchingPattern() throws Exception { GoConfigMother mother = new GoConfigMother(); PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0); File file1 = helper.addFileWithPipeline("pipe1.gocd.xml", pipe1); File file2 = helper.addFileWithPipeline("pipe1.gcd.xml", pipe1); File file3 = helper.addFileWithPipeline("subdir/pipe1.gocd.xml", pipe1); File file4 = helper.addFileWithPipeline("subdir/sub/pipe1.gocd.xml", pipe1); File[] matchingFiles = xmlPartialProvider.getFiles(tmpFolder, mock(PartialConfigLoadContext.class)); File[] expected = new File[] {file1, file3, file4}; assertArrayEquals("Matched files are: " + Arrays.asList(matchingFiles).toString(), expected, matchingFiles); }
@Test public void shouldFailToLoadDirectoryWithDuplicatedPipeline() throws Exception { GoConfigMother mother = new GoConfigMother(); PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0); helper.addFileWithPipeline("pipe1.gocd.xml", pipe1); helper.addFileWithPipeline("pipedup.gocd.xml", pipe1); try { PartialConfig part = xmlPartialProvider.load(tmpFolder, mock(PartialConfigLoadContext.class)); } catch (Exception ex) { assertThat(ex.getMessage(),is("You have defined multiple pipelines called 'pipeline1'. Pipeline names must be unique.")); return; } fail("should have thrown"); }
@Test public void shouldLoadDirectoryWithOnePipeline() throws Exception { GoConfigMother mother = new GoConfigMother(); PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0); helper.addFileWithPipeline("pipe1.gocd.xml", pipe1); PartialConfig part = xmlPartialProvider.load(tmpFolder,mock(PartialConfigLoadContext.class)); PipelineConfig pipeRead = part.getGroups().get(0).get(0); assertThat(pipeRead,is(pipe1)); }
@Test public void shouldParseFileWithOnePipeline() throws Exception { GoConfigMother mother = new GoConfigMother(); PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0); File file = helper.addFileWithPipeline("pipe1.gocd.xml", pipe1); PartialConfig part = xmlPartialProvider.parseFile(file); PipelineConfig pipeRead = part.getGroups().get(0).get(0); assertThat(pipeRead,is(pipe1)); }
@Test public void shouldUseExplicitPatternWhenProvided() throws Exception { GoConfigMother mother = new GoConfigMother(); PipelineConfig pipe1 = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0); File file1 = helper.addFileWithPipeline("pipe1.myextension", pipe1); File file2 = helper.addFileWithPipeline("pipe1.gcd.xml", pipe1); File file3 = helper.addFileWithPipeline("subdir/pipe1.gocd.xml", pipe1); File file4 = helper.addFileWithPipeline("subdir/sub/pipe1.gocd.xml", pipe1); PartialConfigLoadContext context = mock(PartialConfigLoadContext.class); Configuration configs = new Configuration(); configs.addNewConfigurationWithValue("pattern","*.myextension",false); when(context.configuration()).thenReturn(configs); File[] matchingFiles = xmlPartialProvider.getFiles(tmpFolder, context); File[] expected = new File[1]; expected[0] = file1; assertArrayEquals(expected,matchingFiles); }