Search in sources :

Example 51 with DependencyMaterialConfig

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.

the class PipelineConfigValidationTest method shouldDetectCyclicDependencies.

@Test
public void shouldDetectCyclicDependencies() {
    String pipelineName = "p1";
    BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines(pipelineName, "p2", "p3");
    PipelineConfig p2 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p2"));
    p2.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString("stage")));
    PipelineConfig p3 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString("p3"));
    p3.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p2"), new CaseInsensitiveString("stage")));
    PipelineConfig p1 = cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName));
    // Do not remove cloning else it changes the underlying cache object defeating the purpose of the test.
    p1 = new Cloner().deepClone(p1);
    p1.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("p3"), new CaseInsensitiveString("stage")));
    p1.validateTree(PipelineConfigSaveValidationContext.forChain(true, cruiseConfig.getGroups().first().getGroup(), cruiseConfig, p1));
    assertThat(p1.materialConfigs().errors().isEmpty(), is(false));
    assertThat(p1.materialConfigs().errors().on("base"), is("Circular dependency: p1 <- p2 <- p3 <- p1"));
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Cloner(com.rits.cloning.Cloner) Test(org.junit.Test)

Example 52 with DependencyMaterialConfig

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.

the class DependencyMaterialUpdateNotifier method dependencyMaterials.

private HashMap<String, Material> dependencyMaterials() {
    HashMap<String, Material> map = new HashMap<>();
    for (DependencyMaterialConfig materialConfig : goConfigService.getSchedulableDependencyMaterials()) {
        String stageIdentifier = stageIdentifier(materialConfig.getPipelineName().toString(), materialConfig.getStageName().toString());
        map.put(stageIdentifier, materialConfigConverter.toMaterial(materialConfig));
    }
    return map;
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)

Example 53 with DependencyMaterialConfig

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.

the class FetchArtifactViewHelper method addMaterialsToQueue.

private static void addMaterialsToQueue(Queue<JobHierarchyQueueEntry> bfsQueue, PipelineConfig pipelineConfig, String pathFromThisPipeline) {
    for (MaterialConfig mat : pipelineConfig.materialConfigs()) {
        if (mat instanceof DependencyMaterialConfig) {
            DependencyMaterialConfig depMat = (DependencyMaterialConfig) mat;
            bfsQueue.add(new JobHierarchyQueueEntry(pathFromThisPipeline, depMat.getPipelineName(), depMat.getStageName()));
        }
    }
}
Also used : DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)

Example 54 with DependencyMaterialConfig

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldMigrateDependsOnTagToBeADependencyMaterial.

@Test
public void shouldMigrateDependsOnTagToBeADependencyMaterial() throws Exception {
    String content = FileUtils.readFileToString(new File("../common/src/test/resources/data/config/version4/cruise-config-dependency-migration.xml"), UTF_8);
    CruiseConfig cruiseConfig = loadConfigFileWithContent(content);
    MaterialConfig actual = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("depends")).materialConfigs().first();
    assertThat(actual, instanceOf(DependencyMaterialConfig.class));
    DependencyMaterialConfig depends = (DependencyMaterialConfig) actual;
    assertThat(depends.getPipelineName(), is(new CaseInsensitiveString("multiple")));
    assertThat(depends.getStageName(), is(new CaseInsensitiveString("helloworld-part2")));
}
Also used : GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 55 with DependencyMaterialConfig

use of com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig in project gocd by gocd.

the class GoPartialConfigIntegrationTest method shouldMarkAnInvalidKnownPartialAsValidWhenLoadingAnotherPartialMakesThisOneValid_InterConfigRepoDependency.

@Test
public void shouldMarkAnInvalidKnownPartialAsValidWhenLoadingAnotherPartialMakesThisOneValid_InterConfigRepoDependency() {
    ConfigRepoConfig repoConfig3 = new ConfigRepoConfig(new GitMaterialConfig("url3"), "plugin");
    configHelper.addConfigRepo(repoConfig3);
    PartialConfig repo1 = PartialConfigMother.withPipeline("p1_repo1", new RepoConfigOrigin(repoConfig1, "1"));
    PartialConfig repo2 = PartialConfigMother.withPipeline("p2_repo2", new RepoConfigOrigin(repoConfig2, "1"));
    PartialConfig repo3 = PartialConfigMother.withPipeline("p3_repo3", new RepoConfigOrigin(repoConfig3, "1"));
    PipelineConfig p1 = repo1.getGroups().first().getPipelines().get(0);
    PipelineConfig p2 = repo2.getGroups().first().getPipelines().get(0);
    PipelineConfig p3 = repo3.getGroups().first().getPipelines().get(0);
    p2.addMaterialConfig(new DependencyMaterialConfig(p1.name(), p1.first().name()));
    p2.addMaterialConfig(new DependencyMaterialConfig(p3.name(), p3.first().name()));
    p1.addMaterialConfig(new DependencyMaterialConfig(p3.name(), p3.first().name()));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, repo2);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(false));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).isEmpty(), is(false));
    ServerHealthState healthStateForInvalidConfigMerge = serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig2)).get(0);
    assertThat(healthStateForInvalidConfigMerge.getMessage(), is("Invalid Merged Configuration"));
    assertThat(healthStateForInvalidConfigMerge.getDescription(), is("3+ errors :: Pipeline &quot;p1_repo1&quot; does not exist. It is used from pipeline &quot;p2_repo2&quot;.;; Pipeline with name 'p1_repo1' does not exist, it is defined as a dependency for pipeline 'p2_repo2' (url2 at 1);; Pipeline with name 'p3_repo3' does not exist, it is defined as a dependency for pipeline 'p2_repo2' (url2 at 1);;  -  Config-Repo: url2 at 1"));
    assertThat(healthStateForInvalidConfigMerge.getLogLevel(), is(HealthStateLevel.ERROR));
    assertThat(cachedGoPartials.lastValidPartials().isEmpty(), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(1));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo1), is(false));
    goPartialConfig.onSuccessPartialConfig(repoConfig3, repo3);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p3.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(false));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p1.name()), is(false));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig3)).isEmpty(), is(true));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(1));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo2), is(false));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo3), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(2));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo3), is(true));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, repo1);
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p1.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p2.name()), is(true));
    assertThat(goConfigDao.loadConfigHolder().config.getAllPipelineNames().contains(p3.name()), is(true));
    assertThat(serverHealthService.filterByScope(HealthStateScope.forPartialConfigRepo(repoConfig1)).isEmpty(), is(true));
    assertThat(cachedGoPartials.lastValidPartials().size(), is(3));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo1), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastValidPartials(), repo3), is(true));
    assertThat(cachedGoPartials.lastKnownPartials().size(), is(3));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo2), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo1), is(true));
    assertThat(cacheContainsPartial(cachedGoPartials.lastKnownPartials(), repo3), is(true));
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Aggregations

DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)135 Test (org.junit.Test)106 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)22 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)22 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)21 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)15 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)14 PipelineConfigDependencyGraph (com.thoughtworks.go.server.domain.PipelineConfigDependencyGraph)11 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)10 Date (java.util.Date)10 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)9 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)8 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)8 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)8 Pipeline (com.thoughtworks.go.domain.Pipeline)8 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)8 ScmMaterialConfig (com.thoughtworks.go.config.materials.ScmMaterialConfig)7 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)7 ModificationsMother.changedDependencyMaterialRevision (com.thoughtworks.go.helper.ModificationsMother.changedDependencyMaterialRevision)7