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));
}
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;
}
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)));
}
}
}
}
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);
}
}
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");
}
Aggregations