public void enableAgents(Username username, OperationResult operationResult, List<String> uuids) { if (!hasOperatePermission(username, operationResult)) { return; } List<AgentInstance> agents = new ArrayList<>(); if (!populateAgentInstancesForUUIDs(operationResult, uuids, agents)) { return; } try { agentConfigService.enableAgents(username, agents.toArray((new AgentInstance[0]))); operationResult.ok(String.format("Enabled %s agent(s)", uuids.size())); } catch (Exception e) { operationResult.internalServerError("Enabling agents failed:" + e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL)); } }
public void disableAgents(Username username, OperationResult operationResult, List<String> uuids) { if (!hasOperatePermission(username, operationResult)) { return; } List<AgentInstance> agents = new ArrayList<>(); if (!populateAgentInstancesForUUIDs(operationResult, uuids, agents)) { return; } try { agentConfigService.disableAgents(username, agents.toArray(new AgentInstance[0])); operationResult.ok(String.format("Disabled %s agent(s)", uuids.size())); } catch (Exception e) { operationResult.internalServerError("Disabling agents failed:" + e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL)); } }
public void modifyResources(Username username, HttpOperationResult operationResult, List<String> uuids, List<TriStateSelection> selections) { if (!hasOperatePermission(username, operationResult)) { return; } List<AgentInstance> agents = new ArrayList<>(); if (!populateAgentInstancesForUUIDs(operationResult, uuids, agents)) { return; } try { agentConfigService.modifyResources(agents.toArray(new AgentInstance[0]), selections, username); operationResult.ok(String.format("Resource(s) modified on %s agent(s)", uuids.size())); } catch (Exception e) { operationResult.notAcceptable("Could not modify resources:" + e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL)); } }
public void modifyEnvironments(Username username, HttpOperationResult operationResult, List<String> uuids, List<TriStateSelection> selections) { if (!hasOperatePermission(username, operationResult)) { return; } List<AgentInstance> agents = new ArrayList<>(); if (!populateAgentInstancesForUUIDs(operationResult, uuids, agents)) { return; } try { environmentConfigService.modifyEnvironments(agents, selections); operationResult.ok(String.format("Environment(s) modified on %s agent(s)", uuids.size())); } catch (Exception e) { operationResult.notAcceptable("Could not modify environments:" + e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL)); } }
public void deleteAgents(Username username, HttpOperationResult operationResult, List<String> uuids) { if (!hasOperatePermission(username, operationResult)) { return; } List<AgentInstance> agents = new ArrayList<>(); if (!populateAgentInstancesForUUIDs(operationResult, uuids, agents)) { return; } for (AgentInstance agentInstance : agents) { if (!agentInstance.canBeDeleted()) { operationResult.notAcceptable(String.format("Failed to delete %s agent(s), as agent(s) might not be disabled or are still building.", agents.size()), HealthStateType.general(HealthStateScope.GLOBAL)); return; } } try { agentConfigService.deleteAgents(username, agents.toArray(new AgentInstance[0])); operationResult.ok(String.format("Deleted %s agent(s).", agents.size())); } catch (Exception e) { operationResult.internalServerError("Deleting agents failed:" + e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL)); } }
public AgentInstance updateAgentAttributes(Username username, HttpOperationResult result, String uuid, String newHostname, String resources, String environments, TriState enable) { if (!hasOperatePermission(username, result)) { return null; } AgentInstance agentInstance = findAgent(uuid); if (isUnknownAgent(agentInstance, result)) { return null; } AgentConfig agentConfig = agentConfigService.updateAgentAttributes(uuid, username, newHostname, resources, environments, enable, agentInstances, result); if (agentConfig != null) { return AgentInstance.createFromConfig(agentConfig, systemEnvironment, agentStatusChangeNotifier); } return null; }