Search in sources :

Example 6 with AgentConfig

use of com.thoughtworks.go.config.AgentConfig 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)

Example 7 with AgentConfig

use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.

the class JobController method presenter.

private JobDetailPresentationModel presenter(JobInstance current) {
    String pipelineName = current.getIdentifier().getPipelineName();
    String stageName = current.getIdentifier().getStageName();
    JobInstances recent25 = jobInstanceService.latestCompletedJobs(pipelineName, stageName, current.getName());
    AgentConfig agentConfig = goConfigService.agentByUuid(current.getAgentUuid());
    Pipeline pipelineWithOneBuild = pipelineService.wrapBuildDetails(current);
    Tabs customizedTabs = goConfigService.getCustomizedTabs(pipelineWithOneBuild.getName(), pipelineWithOneBuild.getFirstStage().getName(), current.getName());
    TrackingTool trackingTool = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineWithOneBuild.getName())).trackingTool();
    Properties properties = propertiesService.getPropertiesForJob(current.getId());
    Stage stage = stageService.getStageByBuild(current);
    return new JobDetailPresentationModel(current, recent25, agentConfig, pipelineWithOneBuild, customizedTabs, trackingTool, artifactService, properties, stage);
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Tabs(com.thoughtworks.go.config.Tabs) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) JobDetailPresentationModel(com.thoughtworks.go.server.presentation.models.JobDetailPresentationModel) Properties(com.thoughtworks.go.domain.Properties) TrackingTool(com.thoughtworks.go.config.TrackingTool) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 8 with AgentConfig

use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.

the class JobStatusJsonPresentationModelTest method shouldShowBuildStatus.

@Test
public void shouldShowBuildStatus() throws Exception {
    JobInstance instance = JobInstanceMother.assigned("test");
    instance.setId(12);
    instance.setAgentUuid("1234");
    final Agents agents = new Agents(new AgentConfig("1234", "localhost", "1234"));
    JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, agents.getAgentByUuid(instance.getAgentUuid()));
    Map json = presenter.toJsonHash();
    new JsonTester(json).shouldContain("{ 'name' : 'test'," + " 'id' : '12', " + " 'agent' : 'localhost', " + " 'current_status' : 'assigned' " + "}");
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) JsonTester(com.thoughtworks.go.util.JsonTester) JobInstance(com.thoughtworks.go.domain.JobInstance) Agents(com.thoughtworks.go.config.Agents) Map(java.util.Map) Test(org.junit.Test)

Example 9 with AgentConfig

use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.

the class AgentInstancesTest method shouldRemoveAgentWhenAgentIsRemovedFromConfigFile.

@Test
public void shouldRemoveAgentWhenAgentIsRemovedFromConfigFile() throws Exception {
    AgentInstances agentInstances = new AgentInstances(null, systemEnvironment, idle, building);
    Agents oneAgentIsRemoved = new Agents(new AgentConfig("uuid2", "CCeDev01", "10.18.5.1"));
    agentInstances.sync(oneAgentIsRemoved);
    assertThat(agentInstances.size(), is(1));
    assertThat(agentInstances.findAgentAndRefreshStatus("uuid2"), is(idle));
    assertThat(agentInstances.findAgentAndRefreshStatus("uuid1"), is(new NullAgentInstance("uuid1")));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Agents(com.thoughtworks.go.config.Agents) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) Test(org.junit.Test)

Example 10 with AgentConfig

use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.

the class AgentInstancesTest method shouldUnderstandFilteringAgentListBasedOnUuid.

@Test
public void shouldUnderstandFilteringAgentListBasedOnUuid() {
    AgentInstances instances = new AgentInstances(null);
    AgentRuntimeInfo agent1 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-1", "host-1", "192.168.1.2"), true, "/foo/bar", 100l, "linux", false);
    AgentRuntimeInfo agent2 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-2", "host-2", "192.168.1.3"), true, "/bar/baz", 200l, "linux", false);
    AgentRuntimeInfo agent3 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-3", "host-3", "192.168.1.4"), true, "/baz/quux", 300l, "linux", false);
    AgentInstance instance1 = AgentInstance.createFromLiveAgent(agent1, systemEnvironment);
    instances.add(instance1);
    instances.add(AgentInstance.createFromLiveAgent(agent2, systemEnvironment));
    AgentInstance instance3 = AgentInstance.createFromLiveAgent(agent3, systemEnvironment);
    instances.add(instance3);
    List<AgentInstance> agents = instances.filter(Arrays.asList("uuid-1", "uuid-3"));
    assertThat(agents, hasItems(instance1, instance3));
    assertThat(agents.size(), is(2));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentConfig(com.thoughtworks.go.config.AgentConfig) Test(org.junit.Test)

Aggregations

AgentConfig (com.thoughtworks.go.config.AgentConfig)65 Test (org.junit.Test)45 AgentInstance (com.thoughtworks.go.domain.AgentInstance)15 Agents (com.thoughtworks.go.config.Agents)13 Username (com.thoughtworks.go.server.domain.Username)7 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)6 Resource (com.thoughtworks.go.config.Resource)5 Resources (com.thoughtworks.go.config.Resources)5 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)4 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)4 ServerConfig (com.thoughtworks.go.config.ServerConfig)4 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)4 JobInstance (com.thoughtworks.go.domain.JobInstance)4 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)3 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 StageConfig (com.thoughtworks.go.config.StageConfig)2