use of com.thoughtworks.go.util.Node in project gocd by gocd.
the class PipelineConfigTest method shouldGetDependenciesAsNode.
@Test
public void shouldGetDependenciesAsNode() throws Exception {
PipelineConfig pipelineConfig = new PipelineConfig();
pipelineConfig.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("framework"), new CaseInsensitiveString("dev")));
pipelineConfig.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("middleware"), new CaseInsensitiveString("dev")));
assertThat(pipelineConfig.getDependenciesAsNode(), is(new Node(new Node.DependencyNode(new CaseInsensitiveString("framework"), new CaseInsensitiveString("dev")), new Node.DependencyNode(new CaseInsensitiveString("middleware"), new CaseInsensitiveString("dev")))));
}
use of com.thoughtworks.go.util.Node 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.util.Node in project gocd by gocd.
the class PipelineConfigTreeValidator method validateDependencyMaterialsForDownstreams.
private void validateDependencyMaterialsForDownstreams(PipelineConfigSaveValidationContext validationContext, CaseInsensitiveString selected, PipelineConfig downstreamPipeline) {
Node dependenciesOfSelectedPipeline = validationContext.getDependencyMaterialsFor(selected);
for (Node.DependencyNode dependencyNode : dependenciesOfSelectedPipeline.getDependencies()) {
if (dependencyNode.getPipelineName().equals(pipelineConfig.name())) {
for (MaterialConfig materialConfig : downstreamPipeline.materialConfigs()) {
if (materialConfig instanceof DependencyMaterialConfig) {
DependencyMaterialConfig dependencyMaterialConfig = ClonerFactory.instance().deepClone((DependencyMaterialConfig) materialConfig);
dependencyMaterialConfig.validate(validationContext.withParent(downstreamPipeline));
List<String> allErrors = dependencyMaterialConfig.errors().getAll();
for (String error : allErrors) {
pipelineConfig.errors().add("base", error);
}
}
}
}
}
}
use of com.thoughtworks.go.util.Node in project gocd by gocd.
the class InternalPipelineStructureControllerV1 method index.
public String index(Request request, Response response) throws IOException {
String pipelineGroupAuthorizationType = request.queryParamOrDefault("pipeline_group_authorization", "view");
String templateAuthorizationType = request.queryParamOrDefault("template_authorization", "view");
Supplier<PipelineGroups> pipelineGroupsSupplier = pipelineGroupAuthorizationRegistry.get(pipelineGroupAuthorizationType);
Supplier<TemplatesConfig> templatesConfigSupplier = templateAuthorizationRegistry.get(templateAuthorizationType);
if (pipelineGroupsSupplier == null || templatesConfigSupplier == null) {
HaltApiResponses.haltBecauseOfReason("Bad query parameter.");
}
EnvironmentsConfig environments = new EnvironmentsConfig();
environments.addAll(environmentConfigService.getEnvironments());
Hashtable<CaseInsensitiveString, Node> dependencyTable = goConfigService.getCurrentConfig().getDependencyTable();
PipelineStructureViewModel pipelineStructureViewModel = new PipelineStructureViewModel().setPipelineGroups(pipelineGroupsSupplier.get()).setTemplatesConfig(templatesConfigSupplier.get()).setEnvironmentsConfig(environments).setPipelineDependencyTable(dependencyTable);
boolean withAdditionalInfo = parseBoolean(request.queryParams("with_additional_info"));
if (!withAdditionalInfo) {
return writerForTopLevelObject(request, response, outputWriter -> InternalPipelineStructuresRepresenter.toJSON(outputWriter, pipelineStructureViewModel));
}
Collection<String> users = userService.allUsernames();
Collection<String> roles = userService.allRoleNames();
return writerForTopLevelObject(request, response, outputWriter -> InternalPipelineStructuresRepresenter.toJSON(outputWriter, pipelineStructureViewModel, users, roles));
}
use of com.thoughtworks.go.util.Node in project gocd by gocd.
the class PipelineConfigTest method shouldGetDependenciesAsNode.
@Test
public void shouldGetDependenciesAsNode() throws Exception {
PipelineConfig pipelineConfig = new PipelineConfig();
pipelineConfig.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("framework"), new CaseInsensitiveString("dev")));
pipelineConfig.addMaterialConfig(new DependencyMaterialConfig(new CaseInsensitiveString("middleware"), new CaseInsensitiveString("dev")));
assertThat(pipelineConfig.getDependenciesAsNode(), is(new Node(new Node.DependencyNode(new CaseInsensitiveString("framework"), new CaseInsensitiveString("dev")), new Node.DependencyNode(new CaseInsensitiveString("middleware"), new CaseInsensitiveString("dev")))));
}
Aggregations