Search in sources :

Example 11 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class PipelineConfigTreeValidator method validate.

public boolean validate(PipelineConfigSaveValidationContext validationContext) {
    pipelineConfig.validate(validationContext);
    pipelineCreationSpecificValidations(validationContext);
    validateDependencies(validationContext);
    boolean isValid = pipelineConfig.errors().isEmpty();
    PipelineConfigSaveValidationContext contextForChildren = validationContext.withParent(pipelineConfig);
    for (StageConfig stageConfig : pipelineConfig.getStages()) {
        isValid = stageConfig.validateTree(contextForChildren) && isValid;
        if (pipelineConfig.hasTemplateApplied()) {
            final List<ConfigErrors> allErrors = new ArrayList<>();
            new GoConfigGraphWalker(stageConfig).walk(new ErrorCollectingHandler(allErrors) {

                @Override
                public void handleValidation(Validatable validatable, ValidationContext context) {
                }
            });
            for (ConfigErrors error : allErrors) {
                pipelineConfig.errors().add("template", ListUtil.join(error.getAll()));
            }
        }
    }
    validateCyclicDependencies(validationContext);
    isValid = pipelineConfig.materialConfigs().validateTree(contextForChildren) && isValid;
    isValid = pipelineConfig.getParams().validateTree(contextForChildren) && isValid;
    isValid = pipelineConfig.getVariables().validateTree(contextForChildren) && isValid;
    if (pipelineConfig.getTrackingTool() != null)
        isValid = pipelineConfig.getTrackingTool().validateTree(contextForChildren) && isValid;
    if (pipelineConfig.getMingleConfig() != null)
        isValid = pipelineConfig.getMingleConfig().validateTree(contextForChildren) && isValid;
    if (pipelineConfig.getTimer() != null)
        isValid = pipelineConfig.getTimer().validateTree(contextForChildren) && isValid;
    return isValid;
}
Also used : ArrayList(java.util.ArrayList) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 12 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class GoConfigInvalidMergeException method allErrorsToString.

private static String allErrorsToString(List<ConfigErrors> allErrors, String summary) {
    if (allErrors == null || allErrors.size() == 0)
        // should never be
        return "Error list empty";
    StringBuilder b = new StringBuilder();
    b.append(allErrors.size()).append("+ errors :: ");
    for (ConfigErrors e : allErrors) {
        b.append(e.firstError()).append(";; ");
    }
    return b.toString();
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 13 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class EnvironmentAgentValidator method validate.

public void validate(CruiseConfig cruiseConfig) throws Exception {
    List<ConfigErrors> errors = validateConfig(cruiseConfig);
    List<String> errorMessages = new ArrayList<>();
    for (ConfigErrors error : errors) {
        errorMessages.addAll(error.getAll());
    }
    if (!errors.isEmpty())
        throw new RuntimeException(ListUtil.join(errorMessages));
}
Also used : ArrayList(java.util.ArrayList) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 14 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class AdminRoleTest method shouldAddValidationErrorIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext.

@Test
public void shouldAddValidationErrorIfRoleNameInPipelinesAuthorizationDoesNotExist_PipelineConfigSaveValidationContext() throws Exception {
    AdminRole role = new AdminRole(new CaseInsensitiveString("role2"));
    PipelineConfig pipelineConfig = new PipelineConfig();
    PipelineConfigs pipelinesConfig = new BasicPipelineConfigs(new Authorization(new ViewConfig(role)), pipelineConfig);
    CruiseConfig config = new BasicCruiseConfig(pipelinesConfig);
    role.validate(PipelineConfigSaveValidationContext.forChain(true, "group", config, pipelineConfig));
    ConfigErrors errors = role.errors();
    assertThat(errors.isEmpty(), is(false));
    assertThat(errors.on(AdminRole.NAME), is("Role \"role2\" does not exist."));
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 15 with ConfigErrors

use of com.thoughtworks.go.domain.ConfigErrors in project gocd by gocd.

the class AdminRoleTest method shouldThrowExceptionIfRoleNameInPipelinesAuthorizationDoesNotExist_ConfigSaveValidationContext.

@Test
public void shouldThrowExceptionIfRoleNameInPipelinesAuthorizationDoesNotExist_ConfigSaveValidationContext() throws Exception {
    AdminRole role = new AdminRole(new CaseInsensitiveString("role2"));
    PipelineConfigs pipelinesConfig = new BasicPipelineConfigs(new Authorization(new ViewConfig(role)));
    CruiseConfig config = new BasicCruiseConfig(pipelinesConfig);
    role.validate(ConfigSaveValidationContext.forChain(config));
    ConfigErrors errors = role.errors();
    assertThat(errors.isEmpty(), is(false));
    assertThat(errors.on(AdminRole.NAME), is("Role \"role2\" does not exist."));
}
Also used : ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Aggregations

ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)23 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 Cloner (com.rits.cloning.Cloner)2 IOException (java.io.IOException)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 EnvironmentAgentConfig (com.thoughtworks.go.config.EnvironmentAgentConfig)1 EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)1 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)1 IgnoreTraversal (com.thoughtworks.go.config.IgnoreTraversal)1 Validatable (com.thoughtworks.go.config.Validatable)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 UpdateEnvironmentsCommand (com.thoughtworks.go.config.update.UpdateEnvironmentsCommand)1 UpdateResourceCommand (com.thoughtworks.go.config.update.UpdateResourceCommand)1