Search in sources :

Example 1 with ConfigOrigin

use of com.thoughtworks.go.config.remote.ConfigOrigin in project gocd by gocd.

the class MergePipelineConfigsTest method shouldReturnOriginAsASumOfAllOrigins.

@Test
public void shouldReturnOriginAsASumOfAllOrigins() {
    BasicPipelineConfigs fileConfigs = new BasicPipelineConfigs(PipelineConfigMother.pipelineConfig("pipeline1"));
    fileConfigs.setOrigin(new FileConfigOrigin());
    BasicPipelineConfigs remoteConfigs = new BasicPipelineConfigs(PipelineConfigMother.pipelineConfig("pipeline2"));
    remoteConfigs.setOrigin(new RepoConfigOrigin());
    PipelineConfigs group = new MergePipelineConfigs(fileConfigs, remoteConfigs);
    ConfigOrigin allOrigins = group.getOrigin();
    assertThat(allOrigins instanceof MergeConfigOrigin, is(true));
    MergeConfigOrigin mergeConfigOrigin = (MergeConfigOrigin) allOrigins;
    assertThat(mergeConfigOrigin.size(), is(2));
    assertThat(mergeConfigOrigin.contains(new FileConfigOrigin()), is(true));
    assertThat(mergeConfigOrigin.contains(new RepoConfigOrigin()), is(true));
}
Also used : FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) ConfigOrigin(com.thoughtworks.go.config.remote.ConfigOrigin) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigOrigin

use of com.thoughtworks.go.config.remote.ConfigOrigin in project gocd by gocd.

the class PipelineConfigService method canDeletePipelines.

public Map<CaseInsensitiveString, CanDeleteResult> canDeletePipelines() {
    CruiseConfig cruiseConfig = goConfigService.getCurrentConfig();
    Map<CaseInsensitiveString, CanDeleteResult> nameToCanDeleteIt = new HashMap<>();
    Hashtable<CaseInsensitiveString, Node> hashtable = cruiseConfig.getDependencyTable();
    List<CaseInsensitiveString> pipelineNames = cruiseConfig.getAllPipelineNames();
    for (CaseInsensitiveString pipelineName : pipelineNames) {
        ConfigOrigin origin = pipelineConfigOrigin(cruiseConfig, pipelineName);
        if (origin != null && !origin.isLocal()) {
            nameToCanDeleteIt.put(pipelineName, new CanDeleteResult(false, "Cannot delete pipeline '" + pipelineName + "' defined in configuration repository '" + origin.displayName() + "'."));
        } else {
            CaseInsensitiveString envName = environmentUsedIn(cruiseConfig, pipelineName);
            if (envName != null) {
                nameToCanDeleteIt.put(pipelineName, new CanDeleteResult(false, "Cannot delete pipeline '" + pipelineName + "' as it is present in environment '" + envName + "'."));
            } else {
                CaseInsensitiveString downStream = downstreamOf(hashtable, pipelineName);
                if (downStream != null) {
                    nameToCanDeleteIt.put(pipelineName, new CanDeleteResult(false, "Cannot delete pipeline '" + pipelineName + "' as pipeline '" + downStream + "' depends on it."));
                } else {
                    nameToCanDeleteIt.put(pipelineName, new CanDeleteResult(true, "Delete this pipeline."));
                }
            }
        }
    }
    return nameToCanDeleteIt;
}
Also used : CanDeleteResult(com.thoughtworks.go.server.presentation.CanDeleteResult) ConfigOrigin(com.thoughtworks.go.config.remote.ConfigOrigin) Node(com.thoughtworks.go.util.Node)

Example 3 with ConfigOrigin

use of com.thoughtworks.go.config.remote.ConfigOrigin in project gocd by gocd.

the class MaterialConfigs method validateOrigins.

private void validateOrigins(PipelineConfig currentPipeline, ValidationContext validationContext) {
    for (DependencyMaterialConfig material : filterDependencyMaterials()) {
        PipelineConfig upstream = validationContext.getPipelineConfigByName(material.getPipelineName());
        if (upstream == null)
            // other rule validates existence of upstream
            continue;
        ConfigOrigin myOrigin = currentPipeline.getOrigin();
        ConfigOrigin upstreamOrigin = upstream.getOrigin();
        if (validationContext.shouldCheckConfigRepo()) {
            if (!validationContext.getConfigRepos().isReferenceAllowed(myOrigin, upstreamOrigin)) {
                material.addError(DependencyMaterialConfig.ORIGIN, String.format("Dependency from pipeline defined in %s to pipeline defined in %s is not allowed", displayNameFor(myOrigin), displayNameFor(upstreamOrigin)));
            }
        }
    }
}
Also used : ConfigOrigin(com.thoughtworks.go.config.remote.ConfigOrigin) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)

Example 4 with ConfigOrigin

use of com.thoughtworks.go.config.remote.ConfigOrigin in project gocd by gocd.

the class EnvironmentsRepresenter method origin.

private static void origin(OutputWriter writer, EnvironmentConfig environment, String agentUuid) {
    if (environment.containsAgentRemotely(agentUuid)) {
        ConfigOrigin originForAgent = environment.originForAgent(agentUuid).orElseThrow(() -> bomb(String.format("Did not expect config origin to be null for Environment: %s, Agent: %s", environment.name(), agentUuid)));
        writeConfigRepoOrigin(writer, (RepoConfigOrigin) originForAgent);
    } else {
        writeConfigXmlOrigin(writer);
    }
}
Also used : ConfigOrigin(com.thoughtworks.go.config.remote.ConfigOrigin) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin)

Example 5 with ConfigOrigin

use of com.thoughtworks.go.config.remote.ConfigOrigin in project gocd by gocd.

the class BasicEnvironmentConfigTest method shouldReturnOriginIfEnvContainsTheAgent.

@Test
void shouldReturnOriginIfEnvContainsTheAgent() {
    String uuid = "uuid";
    this.environmentConfig.addAgent(uuid);
    this.environmentConfig.setOrigins(new FileConfigOrigin());
    Optional<ConfigOrigin> originForAgent = this.environmentConfig.originForAgent(uuid);
    assertThat(originForAgent.isPresent()).isTrue();
    assertThat(originForAgent.get().displayName()).isEqualTo("cruise-config.xml");
}
Also used : FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) ConfigOrigin(com.thoughtworks.go.config.remote.ConfigOrigin) UIConfigOrigin(com.thoughtworks.go.config.remote.UIConfigOrigin) FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigOrigin (com.thoughtworks.go.config.remote.ConfigOrigin)11 FileConfigOrigin (com.thoughtworks.go.config.remote.FileConfigOrigin)6 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)4 Test (org.junit.jupiter.api.Test)3 UIConfigOrigin (com.thoughtworks.go.config.remote.UIConfigOrigin)2 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 CanDeleteResult (com.thoughtworks.go.server.presentation.CanDeleteResult)1 Node (com.thoughtworks.go.util.Node)1