@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 static AgentInstance agentWithConfigErrors() { ResourceConfig resourceConfig1 = new ResourceConfig("foo%"); ResourceConfig resourceConfig2 = new ResourceConfig("bar$"); AgentConfig agentConfig = new AgentConfig("uuid", "host", "IP", new ResourceConfigs(resourceConfig1, resourceConfig2)); agentConfig.validateTree(ConfigSaveValidationContext.forChain(new BasicCruiseConfig())); return AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class)); } }
@Test public void shouldValidateTree() { ResourceConfig resourceConfig = new ResourceConfig("junk%"); AgentConfig agentConfig = new AgentConfig("uuid", "junk", "junk", new ResourceConfigs(resourceConfig)); boolean isValid = agentConfig.validateTree(ConfigSaveValidationContext.forChain(agentConfig)); assertThat(agentConfig.errors().on(AgentConfig.IP_ADDRESS), is("'junk' is an invalid IP address.")); assertThat(resourceConfig.errors().on(JobConfig.RESOURCES), contains("Resource name 'junk%' is not valid.")); assertThat(isValid, is(false)); }