use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.
the class DeletePipelineConfigCommand method isValid.
@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
for (PipelineConfig pipeline : preprocessedConfig.getAllPipelineConfigs()) {
if (pipeline.materialConfigs().hasDependencyMaterial(pipelineConfig)) {
Localizable.CurryableLocalizable message = LocalizedMessage.string("CANNOT_DELETE_PIPELINE_USED_AS_MATERIALS", pipelineConfig.name(), String.format("%s (%s)", pipeline.name(), pipeline.getOriginDisplayName()));
this.result.unprocessableEntity(message);
return false;
}
}
for (EnvironmentConfig environment : preprocessedConfig.getEnvironments()) {
if (environment.getPipelineNames().contains(pipelineConfig.name())) {
Localizable.CurryableLocalizable message = LocalizedMessage.string("CANNOT_DELETE_PIPELINE_IN_ENVIRONMENT", pipelineConfig.name(), environment.name());
this.result.unprocessableEntity(message);
return false;
}
}
return true;
}
use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.
the class EnvironmentCommand method isValid.
@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
EnvironmentConfig config = preprocessedConfig.getEnvironments().find(this.environmentConfig.name());
boolean isValid = config.validateTree(ConfigSaveValidationContext.forChain(preprocessedConfig), preprocessedConfig);
if (!isValid) {
String allErrors = new AllConfigErrors(preprocessedConfig.getAllErrors()).asString();
result.unprocessableEntity(LocalizedMessage.composite(actionFailed, allErrors));
}
return isValid;
}
use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.
the class UpdateEnvironmentCommand method isRequestFresh.
private boolean isRequestFresh(CruiseConfig cruiseConfig) {
EnvironmentConfig config = cruiseConfig.getEnvironments().find(new CaseInsensitiveString(oldEnvironmentConfigName));
if (config instanceof MergeEnvironmentConfig) {
config = ((MergeEnvironmentConfig) config).getFirstEditablePart();
}
boolean freshRequest = hashingService.hashForEntity(config).equals(digest);
if (!freshRequest) {
result.stale(EntityType.Environment.staleConfig(oldEnvironmentConfigName));
}
return freshRequest;
}
use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.
the class UpdateEnvironmentCommand method update.
@Override
public void update(CruiseConfig preprocessedConfig) {
EnvironmentsConfig environments = preprocessedConfig.getEnvironments();
EnvironmentConfig envToRemove = environments.find(new CaseInsensitiveString(oldEnvironmentConfigName));
int index = environments.indexOf(envToRemove);
environments.remove(index);
environments.add(index, environmentConfig);
}
use of com.thoughtworks.go.config.EnvironmentConfig in project gocd by gocd.
the class InternalEnvironmentsControllerV1 method updateAgentAssociation.
String updateAgentAssociation(Request request, Response response) {
String envName = request.params("env_name");
EnvironmentConfig envConfig = environmentConfigService.getEnvironmentConfig(envName);
JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
JsonReader agents = jsonReader.readJsonObject("agents");
List<String> uuidsToAssociate = agents.readStringArrayIfPresent("add").orElse(Collections.emptyList());
List<String> uuidsToRemove = agents.readStringArrayIfPresent("remove").orElse(Collections.emptyList());
if (!uuidsToAssociate.isEmpty() || !uuidsToRemove.isEmpty()) {
agentService.updateAgentsAssociationOfEnvironment(envConfig, uuidsToAssociate, uuidsToRemove);
}
return renderMessage(response, 200, EntityType.Environment.updateSuccessful(envName));
}
Aggregations