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