Search in sources :

Example 1 with Node

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")))));
}
Also used : Node(com.thoughtworks.go.util.Node) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.Test)

Example 2 with Node

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;
}
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 Node

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);
                    }
                }
            }
        }
    }
}
Also used : Node(com.thoughtworks.go.util.Node) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)

Example 4 with Node

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));
}
Also used : PipelineGroups(com.thoughtworks.go.domain.PipelineGroups) TemplatesConfig(com.thoughtworks.go.config.TemplatesConfig) Node(com.thoughtworks.go.util.Node) PipelineStructureViewModel(com.thoughtworks.go.apiv1.internalpipelinestructure.models.PipelineStructureViewModel) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentsConfig(com.thoughtworks.go.config.EnvironmentsConfig)

Example 5 with Node

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")))));
}
Also used : Node(com.thoughtworks.go.util.Node) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) Test(org.junit.jupiter.api.Test)

Aggregations

Node (com.thoughtworks.go.util.Node)6 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)4 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)2 PipelineStructureViewModel (com.thoughtworks.go.apiv1.internalpipelinestructure.models.PipelineStructureViewModel)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 EnvironmentsConfig (com.thoughtworks.go.config.EnvironmentsConfig)1 TemplatesConfig (com.thoughtworks.go.config.TemplatesConfig)1 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)1 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)1 ConfigOrigin (com.thoughtworks.go.config.remote.ConfigOrigin)1 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)1 CanDeleteResult (com.thoughtworks.go.server.presentation.CanDeleteResult)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1