use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotAllowMultipleRepositoriesWithSameName.
@Test
public void shouldNotAllowMultipleRepositoriesWithSameName() throws Exception {
Configuration packageConfiguration = new Configuration(getConfigurationProperty("name", false, "go-agent"));
Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id1", "name", repositoryConfiguration, new Packages(new PackageDefinition("id1", "name1", packageConfiguration)));
PackageRepository anotherPackageRepository = createPackageRepository("plugin-id", "version", "id2", "name", repositoryConfiguration, new Packages(new PackageDefinition("id2", "name2", packageConfiguration)));
configToSave.setPackageRepositories(new PackageRepositories(packageRepository, anotherPackageRepository));
try {
xmlWriter.write(configToSave, output, false);
fail("should not have allowed two repositories with same id");
} catch (GoConfigInvalidException e) {
assertThat(e.getMessage(), is("You have defined multiple repositories called 'name'. Repository names are case-insensitive and must be unique."));
}
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotAllowPackagesWithInvalidName.
@Test
public void shouldNotAllowPackagesWithInvalidName() throws Exception {
Configuration packageConfiguration = new Configuration(getConfigurationProperty("name", false, "go-agent"));
Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", repositoryConfiguration, new Packages(new PackageDefinition("id", "name with space", packageConfiguration)));
configToSave.setPackageRepositories(new PackageRepositories(packageRepository));
try {
xmlWriter.write(configToSave, output, false);
fail("should not have allowed two repositories with same id");
} catch (GoConfigInvalidException e) {
assertThat(e.getMessage(), is("Invalid Package name 'name with space'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
}
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotAllowPackagesRepositoryWithInvalidName.
@Test
public void shouldNotAllowPackagesRepositoryWithInvalidName() throws Exception {
Configuration packageConfiguration = new Configuration(getConfigurationProperty("name", false, "go-agent"));
Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name with space", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
configToSave.setPackageRepositories(new PackageRepositories(packageRepository));
try {
xmlWriter.write(configToSave, output, false);
fail("should not have allowed two repositories with same id");
} catch (GoConfigInvalidException e) {
assertThat(e.getMessage(), is("Invalid PackageRepository name 'name with space'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
}
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotAllowMultiplePackagesWithSameNameWithinARepo.
@Test
public void shouldNotAllowMultiplePackagesWithSameNameWithinARepo() throws Exception {
Configuration packageConfiguration1 = new Configuration(getConfigurationProperty("name", false, "go-agent"));
Configuration packageConfiguration2 = new Configuration(getConfigurationProperty("name2", false, "go-server"));
Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", repositoryConfiguration, new Packages(new PackageDefinition("id1", "name", packageConfiguration1), new PackageDefinition("id2", "name", packageConfiguration2)));
configToSave.setPackageRepositories(new PackageRepositories(packageRepository));
try {
xmlWriter.write(configToSave, output, false);
fail("should not have allowed two repositories with same id");
} catch (GoConfigInvalidException e) {
assertThat(e.getMessage(), is("You have defined multiple packages called 'name'. Package names are case-insensitive and must be unique within a repository."));
}
}
use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.
the class AgentRegistrationController method agentRequest.
@RequestMapping(value = "/admin/agent", method = RequestMethod.POST)
public ModelAndView agentRequest(@RequestParam("hostname") String hostname, @RequestParam("uuid") String uuid, @RequestParam("location") String location, @RequestParam("usablespace") String usablespaceAsString, @RequestParam("operatingSystem") String operatingSystem, @RequestParam("agentAutoRegisterKey") String agentAutoRegisterKey, @RequestParam("agentAutoRegisterResources") String agentAutoRegisterResources, @RequestParam("agentAutoRegisterEnvironments") String agentAutoRegisterEnvironments, @RequestParam("agentAutoRegisterHostname") String agentAutoRegisterHostname, @RequestParam("elasticAgentId") String elasticAgentId, @RequestParam("elasticPluginId") String elasticPluginId, @RequestParam(value = "supportsBuildCommandProtocol", required = false, defaultValue = "false") boolean supportsBuildCommandProtocol, HttpServletRequest request) throws IOException {
final String ipAddress = request.getRemoteAddr();
if (LOG.isDebugEnabled()) {
LOG.debug("Processing registration request from agent [{}/{}]", hostname, ipAddress);
}
Registration keyEntry;
String preferredHostname = hostname;
try {
if (goConfigService.serverConfig().shouldAutoRegisterAgentWith(agentAutoRegisterKey)) {
preferredHostname = getPreferredHostname(agentAutoRegisterHostname, hostname);
LOG.info("[Agent Auto Registration] Auto registering agent with uuid {} ", uuid);
} else {
if (elasticAgentAutoregistrationInfoPresent(elasticAgentId, elasticPluginId)) {
throw new RuntimeException(String.format("Elastic agent registration requires an auto-register agent key to be setup on the server. Agent-id: [%s], Plugin-id: [%s]", elasticAgentId, elasticPluginId));
}
}
AgentConfig agentConfig = new AgentConfig(uuid, preferredHostname, ipAddress);
if (partialElasticAgentAutoregistrationInfo(elasticAgentId, elasticPluginId)) {
throw new RuntimeException("Elastic agents must submit both elasticAgentId and elasticPluginId");
}
if (elasticAgentAutoregistrationInfoPresent(elasticAgentId, elasticPluginId)) {
agentConfig.setElasticAgentId(elasticAgentId);
agentConfig.setElasticPluginId(elasticPluginId);
}
if (goConfigService.serverConfig().shouldAutoRegisterAgentWith(agentAutoRegisterKey)) {
LOG.info(String.format("[Agent Auto Registration] Auto registering agent with uuid %s ", uuid));
GoConfigDao.CompositeConfigCommand compositeConfigCommand = new GoConfigDao.CompositeConfigCommand(new AgentConfigService.AddAgentCommand(agentConfig), new UpdateResourceCommand(uuid, agentAutoRegisterResources), new UpdateEnvironmentsCommand(uuid, agentAutoRegisterEnvironments));
HttpOperationResult result = new HttpOperationResult();
agentConfig = agentConfigService.updateAgent(compositeConfigCommand, uuid, result, agentService.agentUsername(uuid, ipAddress, preferredHostname));
if (!result.isSuccess()) {
List<ConfigErrors> errors = com.thoughtworks.go.config.ErrorCollector.getAllErrors(agentConfig);
throw new GoConfigInvalidException(null, new AllConfigErrors(errors).asString());
}
}
boolean registeredAlready = goConfigService.hasAgent(uuid);
long usablespace = Long.parseLong(usablespaceAsString);
AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, registeredAlready, location, usablespace, operatingSystem, supportsBuildCommandProtocol);
if (elasticAgentAutoregistrationInfoPresent(elasticAgentId, elasticPluginId)) {
agentRuntimeInfo = ElasticAgentRuntimeInfo.fromServer(agentRuntimeInfo, elasticAgentId, elasticPluginId);
}
keyEntry = agentService.requestRegistration(agentService.agentUsername(uuid, ipAddress, preferredHostname), agentRuntimeInfo);
} catch (Exception e) {
keyEntry = Registration.createNullPrivateKeyEntry();
LOG.error("Error occured during agent registration process: ", e);
}
return render(keyEntry);
}
Aggregations