Search in sources :

Example 1 with GoConfigInvalidException

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."));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 2 with GoConfigInvalidException

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."));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 3 with GoConfigInvalidException

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."));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 4 with GoConfigInvalidException

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."));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 5 with GoConfigInvalidException

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);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) UpdateEnvironmentsCommand(com.thoughtworks.go.config.update.UpdateEnvironmentsCommand) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) AllConfigErrors(com.thoughtworks.go.domain.AllConfigErrors) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AgentConfig(com.thoughtworks.go.config.AgentConfig) Registration(com.thoughtworks.go.security.Registration) UpdateResourceCommand(com.thoughtworks.go.config.update.UpdateResourceCommand) AllConfigErrors(com.thoughtworks.go.domain.AllConfigErrors) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)17 Test (org.junit.Test)13 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)4 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)4 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 Packages (com.thoughtworks.go.domain.packagerepository.Packages)4 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)3 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)2 SCM (com.thoughtworks.go.domain.scm.SCM)2 SCMs (com.thoughtworks.go.domain.scm.SCMs)2 IOException (java.io.IOException)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1