@Override public Agents getPreprocessedEntityConfig() { return updatedConfig.agents(); } }
@Override public void onConfigChange(CruiseConfig newCruiseConfig) { onEntityConfigChange(newCruiseConfig.agents()); } }
public CruiseConfig update(CruiseConfig cruiseConfig) { cruiseConfig.agents().add(agentConfig); return cruiseConfig; }
public Agents agents() { return getCurrentConfig().agents(); }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { boolean isValid = true; for (String uuid : agentsUuids) { AgentConfig agentConfig = preprocessedConfig.agents().getAgentByUuid(uuid); isValid = agentConfig.validateTree(ConfigSaveValidationContext.forChain(preprocessedConfig)) && isValid; validatedAgents.add(agentConfig); } return isValid; }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); bombIfNull(agentConfig, "Unable to set agent ipAddress; Agent [" + uuid + "] not found."); agentConfig.setIpAddress(ipAddress); return cruiseConfig; }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); bombIfNull(agentConfig, "Unable to set agent approval status; Agent [" + uuid + "] not found."); agentConfig.setDisabled(denied); return cruiseConfig; }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); if (agentConfig.isNull()) { bomb("Unable to delete agent; Agent [" + uuid + "] not found."); } cruiseConfig.getEnvironments().removeAgentFromAllEnvironments(uuid); cruiseConfig.agents().remove(agentConfig); return cruiseConfig; }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); agentConfig.getResourceConfigs().importFromCsv(resources); return cruiseConfig; } }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); bombIfNull(agentConfig, "Unable to set agent resources; Agent [" + uuid + "] not found."); agentConfig.setResourceConfigs(resourceConfigs); return cruiseConfig; } }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); bombIfNull(agentConfig, "Unable to set agent hostname; Agent [" + uuid + "] not found."); agentConfig.setHostName(hostname); return cruiseConfig; }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { agents = preprocessedConfig.agents(); AgentConfigsUpdateValidator validator = new AgentConfigsUpdateValidator(uuids); boolean isValid = validator.isValid(preprocessedConfig); if (!isValid) { result.unprocessableEntity("Validations failed for bulk update of agents. Error(s): " + agents.getAllErrors()); } return isValid; }
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); }
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; } }
@Test public void shouldSupportMultipleAgentsFromSameBox() throws Exception { CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(ConfigMigrator.migrate(WITH_MULTIPLE_LOCAL_AGENT_CONFIG)).config; assertThat(cruiseConfig.agents().size(), is(2)); assertThat(cruiseConfig.agents().get(0).getHostname(), is(cruiseConfig.agents().get(1).getHostname())); assertThat(cruiseConfig.agents().get(0).getIpAddress(), is(cruiseConfig.agents().get(1).getIpAddress())); assertThat(cruiseConfig.agents().get(0).getUuid(), is(not(cruiseConfig.agents().get(1).getUuid()))); }
@Override public boolean validateTree(ConfigSaveValidationContext validationContext, CruiseConfig preprocessedConfig) { validate(validationContext); preprocessedConfig.getEnvironments().validate(validationContext); validateContainsOnlyUuids(preprocessedConfig.agents().acceptedUuids()); boolean isValid = ErrorCollector.getAllErrors(this).isEmpty(); ValidationContext contextForChildren = validationContext.withParent(this); isValid = isValid && variables.validateTree(contextForChildren); return isValid; }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); bombIfNull(agentConfig, "Unable to set agent resources; Agent [" + uuid + "] not found."); if (action.equals(TriStateSelection.Action.add)) { agentConfig.addResourceConfig(resourceConfig); } else if (action.equals(TriStateSelection.Action.remove)) { agentConfig.removeResource(resourceConfig); } else if (action.equals(TriStateSelection.Action.nochange)) { //do nothing } else { bomb(String.format("unsupported action '%s'", action)); } return cruiseConfig; } }
@Test public void agentWithNoIpAddressShouldBeValid() throws Exception { CruiseConfig cruiseConfig = new BasicCruiseConfig(); AgentConfig agent = new AgentConfig("uuid", null, null); cruiseConfig.agents().add(agent); assertThat(cruiseConfig.validateAfterPreprocess().isEmpty(), is(true)); }
public CruiseConfig update(CruiseConfig cruiseConfig) { AgentConfig agentConfig = cruiseConfig.agents().getAgentByUuid(uuid); bombIfNull(agentConfig, "Unable to set agent resources; Agent [" + uuid + "] not found."); EnvironmentConfig environmentConfig = cruiseConfig.getEnvironments().find(new CaseInsensitiveString(environmentName)); if (environmentConfig == null) { agentConfig.addError("environments", "Environment [" + environmentName + "] does not exist."); } else { if (action.equals(TriStateSelection.Action.add)) { environmentConfig.addAgentIfNew(uuid); } else if (action.equals(TriStateSelection.Action.remove)) { environmentConfig.removeAgent(uuid); } else if (action.equals(TriStateSelection.Action.nochange)) { //do nothing } else { bomb(String.format("unsupported action '%s'", action)); } } return cruiseConfig; } }
@Test public void shouldFindAllAgentResources() { cruiseConfig.agents().add(new AgentConfig("uuid", "host1", "127.0.0.1", new ResourceConfigs("from-agent"))); assertThat(cruiseConfig.getAllResources(), hasItem(new ResourceConfig("from-agent"))); }