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);
}
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);
}
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' " + "}");
}
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")));
}
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));
}
Aggregations