use of com.thoughtworks.go.validation.AgentConfigsUpdateValidator in project gocd by gocd.
the class AgentConfigService method modifyResources.
public void modifyResources(AgentInstance[] agentInstances, List<TriStateSelection> selections, Username currentUser) {
GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
ArrayList<String> uuids = new ArrayList<>();
for (AgentInstance agentInstance : agentInstances) {
String uuid = agentInstance.getUuid();
uuids.add(uuid);
if (goConfigService.hasAgent(uuid)) {
for (TriStateSelection selection : selections) {
command.addCommand(new ModifyResourcesCommand(uuid, new ResourceConfig(selection.getValue()), selection.getAction()));
}
}
}
AgentConfigsUpdateValidator validator = new AgentConfigsUpdateValidator(uuids);
updateAgents(command, validator, currentUser);
}
use of com.thoughtworks.go.validation.AgentConfigsUpdateValidator in project gocd by gocd.
the class AgentsEntityConfigUpdateCommand method isValid.
@Override
public boolean isValid(CruiseConfig preprocessedConfig) {
agents = preprocessedConfig.agents();
AgentConfigsUpdateValidator validator = new AgentConfigsUpdateValidator(uuids);
boolean isValid = validator.isValid(preprocessedConfig);
if (!isValid) {
result.unprocessableEntity(LocalizedMessage.string("BULK_AGENT_UPDATE_FAILED", agents.getAllErrors()));
}
return isValid;
}
use of com.thoughtworks.go.validation.AgentConfigsUpdateValidator in project gocd by gocd.
the class AgentConfigService method updateAgent.
public AgentConfig updateAgent(UpdateConfigCommand command, String uuid, HttpOperationResult result, Username currentUser) {
AgentConfigsUpdateValidator validator = new AgentConfigsUpdateValidator(asList(uuid));
try {
updateAgents(command, validator, currentUser);
result.ok(String.format("Updated agent with uuid %s.", uuid));
} catch (Exception e) {
if (e instanceof GoConfigInvalidException) {
result.unprocessibleEntity("Updating agent failed:", e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL));
GoConfigInvalidException goConfigInvalidException = (GoConfigInvalidException) e;
return goConfigInvalidException.getCruiseConfig().agents().getAgentByUuid(uuid);
} else {
result.internalServerError("Updating agent failed: " + e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL));
return null;
}
}
return goConfigService.agents().getAgentByUuid(uuid);
}
Aggregations