Search in sources :

Example 1 with AgentConfigsUpdateValidator

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);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) ArrayList(java.util.ArrayList) AgentConfigsUpdateValidator(com.thoughtworks.go.validation.AgentConfigsUpdateValidator) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection)

Example 2 with AgentConfigsUpdateValidator

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;
}
Also used : AgentConfigsUpdateValidator(com.thoughtworks.go.validation.AgentConfigsUpdateValidator)

Example 3 with AgentConfigsUpdateValidator

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);
}
Also used : AgentConfigsUpdateValidator(com.thoughtworks.go.validation.AgentConfigsUpdateValidator) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException)

Aggregations

AgentConfigsUpdateValidator (com.thoughtworks.go.validation.AgentConfigsUpdateValidator)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)1 ArrayList (java.util.ArrayList)1