Search in sources :

Example 6 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class EnvironmentAgentValidator method validateConfig.

public List<ConfigErrors> validateConfig(CruiseConfig cruiseConfig) {
    List<ConfigErrors> errors = new ArrayList<>();
    Set<String> uuids = cruiseConfig.agents().acceptedUuids();
    if (!cruiseConfig.getEnvironments().validateContainOnlyUuids(uuids)) {
        for (EnvironmentConfig environmentConfig : cruiseConfig.getEnvironments()) {
            for (EnvironmentAgentConfig environmentAgentConfig : environmentConfig.getAgents()) {
                if (!environmentAgentConfig.errors().isEmpty()) {
                    errors.add(environmentAgentConfig.errors());
                }
            }
        }
    }
    return errors;
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) ArrayList(java.util.ArrayList) EnvironmentAgentConfig(com.thoughtworks.go.config.EnvironmentAgentConfig) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors)

Example 7 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class EnvironmentsRepresenter method toJSON.

public static void toJSON(OutputListWriter writer, Collection<EnvironmentConfig> environments, AgentInstance agentInstance) {
    EnvironmentsConfig envConfigs = new EnvironmentsConfig();
    envConfigs.addAll(environments);
    Set<String> agentEnvAssociationFromDB = new HashSet<>(agentInstance.getAgent().getEnvironmentsAsList());
    Set<String> agentEnvAssociationFromConfigRepo = envConfigs.stream().filter(environmentConfig -> !environmentConfig.isLocal()).map(environmentConfig -> environmentConfig.name().toString()).collect(Collectors.toSet());
    Set<String> allAgentEnvAssociations = Sets.union(agentEnvAssociationFromDB, agentEnvAssociationFromConfigRepo);
    List<String> sortedEnvNames = allAgentEnvAssociations.stream().sorted().collect(toList());
    for (String envName : sortedEnvNames) {
        EnvironmentConfig envConfig = envConfigs.find(new CaseInsensitiveString(envName));
        if (envConfig != null) {
            writer.addChild((childWriter) -> {
                childWriter.add("name", envName);
                childWriter.addChild("origin", (originWriter) -> origin(originWriter, envConfig, agentInstance.getUuid()));
            });
        } else {
            writer.addChild((childWriter) -> {
                childWriter.add("name", envName);
                childWriter.addChild("origin", (originWriter) -> originWriter.add("type", "unknown"));
            });
        }
    }
}
Also used : OutputListWriter(com.thoughtworks.go.api.base.OutputListWriter) java.util(java.util) AgentInstance(com.thoughtworks.go.domain.AgentInstance) ConfigOrigin(com.thoughtworks.go.config.remote.ConfigOrigin) ExceptionUtils.bomb(com.thoughtworks.go.util.ExceptionUtils.bomb) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) OutputWriter(com.thoughtworks.go.api.base.OutputWriter) Collectors.toList(java.util.stream.Collectors.toList) EnvironmentsConfig(com.thoughtworks.go.config.EnvironmentsConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Routes(com.thoughtworks.go.spark.Routes) CurrentGoCDVersion.apiDocsUrl(com.thoughtworks.go.CurrentGoCDVersion.apiDocsUrl) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentsConfig(com.thoughtworks.go.config.EnvironmentsConfig)

Example 8 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class PatchEnvironmentCommand method validateRemovalOfInvalidEnvironmentVariable.

private boolean validateRemovalOfInvalidEnvironmentVariable() {
    EnvironmentConfig environmentConfig = this.environmentConfig;
    for (String variableName : envVarsToRemove) {
        if (!environmentConfig.getVariables().hasVariable(variableName)) {
            String message = String.format("Environment variable with name '%s' does not exist in environment '%s'", variableName, environmentConfig.name());
            result.unprocessableEntity(LocalizedMessage.composite(actionFailed, message));
            return false;
        }
    }
    return true;
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 9 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class PatchEnvironmentCommand method validateRemovalOfInvalidPipelines.

private boolean validateRemovalOfInvalidPipelines() {
    EnvironmentConfig environmentConfig = this.environmentConfig;
    for (String pipelineToRemove : pipelinesToRemove) {
        if (!environmentConfig.containsPipeline(new CaseInsensitiveString(pipelineToRemove))) {
            String message = String.format("Pipeline '%s' does not exist in environment '%s'", pipelineToRemove, environmentConfig.name());
            result.unprocessableEntity(LocalizedMessage.composite(actionFailed, message));
            return false;
        }
    }
    return true;
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 10 with EnvironmentConfig

use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.

the class PatchEnvironmentCommand method isValid.

@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
    EnvironmentConfig preprocessedEnvironmentConfig = preprocessedConfig.getEnvironments().find(environmentConfig.name());
    boolean isValid = validateRemovalOfInvalidEntities();
    if (preprocessedEnvironmentConfig instanceof MergeEnvironmentConfig) {
        isValid = validateRemovalOfRemoteEntities(preprocessedEnvironmentConfig);
    }
    return isValid && super.isValid(preprocessedConfig);
}
Also used : EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig)

Aggregations

EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 MergeEnvironmentConfig (com.thoughtworks.go.config.merge.MergeEnvironmentConfig)5 EnvironmentsConfig (com.thoughtworks.go.config.EnvironmentsConfig)2 Sets (com.google.common.collect.Sets)1 CurrentGoCDVersion.apiDocsUrl (com.thoughtworks.go.CurrentGoCDVersion.apiDocsUrl)1 OutputListWriter (com.thoughtworks.go.api.base.OutputListWriter)1 OutputWriter (com.thoughtworks.go.api.base.OutputWriter)1 JsonReader (com.thoughtworks.go.api.representers.JsonReader)1 EnvironmentAgentConfig (com.thoughtworks.go.config.EnvironmentAgentConfig)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 ConfigOrigin (com.thoughtworks.go.config.remote.ConfigOrigin)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 AllConfigErrors (com.thoughtworks.go.domain.AllConfigErrors)1 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)1 Localizable (com.thoughtworks.go.i18n.Localizable)1 Routes (com.thoughtworks.go.spark.Routes)1 ExceptionUtils.bomb (com.thoughtworks.go.util.ExceptionUtils.bomb)1 java.util (java.util)1