use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class TriStateSelectionTest method shouldHaveActionAddIfAllAgentsHaveThatResource.
@Test
public void shouldHaveActionAddIfAllAgentsHaveThatResource() {
resourceConfigs.add(new ResourceConfig("all"));
agents.add(new Agent("uuid1", "host1", "127.0.0.1", singletonList("all")));
agents.add(new Agent("uuid2", "host2", "127.0.0.2", singletonList("all")));
List<TriStateSelection> selections = TriStateSelection.forAgentsResources(resourceConfigs, agents);
assertThat(selections, hasItem(new TriStateSelection("all", TriStateSelection.Action.add)));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class JobAssignmentIntegrationTest method setupRemoteAgent.
private AgentInstance setupRemoteAgent() {
Agent agent = AgentMother.remoteAgent();
agentService.saveOrUpdate(agent);
AgentInstance instance = AgentInstance.createFromAgent(agent, systemEnvironment, agentStatusChangeListener());
instance.enable();
return instance;
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationController method agentRequest.
@RequestMapping(value = "/admin/agent", method = RequestMethod.POST)
public ResponseEntity agentRequest(@RequestParam("hostname") String hostname, @RequestParam("uuid") String uuid, @RequestParam("location") String location, @RequestParam("usablespace") String usableSpaceStr, @RequestParam("operatingSystem") String os, @RequestParam("agentAutoRegisterKey") String agentAutoRegisterKey, @RequestParam("agentAutoRegisterResources") String agentAutoRegisterResources, @RequestParam("agentAutoRegisterEnvironments") String agentAutoRegisterEnvs, @RequestParam("agentAutoRegisterHostname") String agentAutoRegisterHostname, @RequestParam("elasticAgentId") String elasticAgentId, @RequestParam("elasticPluginId") String elasticPluginId, @RequestParam("token") String token, HttpServletRequest request) {
final String ipAddress = request.getRemoteAddr();
LOG.debug("Processing registration request from agent [{}/{}]", hostname, ipAddress);
boolean keyEntry;
String preferredHostname = hostname;
boolean isElasticAgent = elasticAgentAutoregistrationInfoPresent(elasticAgentId, elasticPluginId);
try {
if (!encodeBase64String(hmac().doFinal(uuid.getBytes())).equals(token)) {
String message = "Not a valid token.";
LOG.error("Rejecting request for registration. Error: HttpCode=[{}] Message=[{}] UUID=[{}] Hostname=[{}]" + "ElasticAgentID=[{}] PluginID=[{}]", FORBIDDEN, message, uuid, hostname, elasticAgentId, elasticPluginId);
return new ResponseEntity<>(message, FORBIDDEN);
}
boolean shouldAutoRegister = shouldAutoRegister(agentAutoRegisterKey, isElasticAgent);
if (shouldAutoRegister) {
preferredHostname = getPreferredHostname(agentAutoRegisterHostname, hostname);
} else {
if (elasticAgentAutoregistrationInfoPresent(elasticAgentId, elasticPluginId)) {
String message = String.format("Elastic agent registration requires an auto-register agent key to be" + " setup on the server. The agentAutoRegisterKey: [%s] is either not provided or expired. Agent-id: [%s], Plugin-id: [%s]", agentAutoRegisterKey, elasticAgentId, elasticPluginId);
LOG.error("Rejecting request for registration. Error: HttpCode=[{}] Message=[{}] UUID=[{}] Hostname=[{}]" + "ElasticAgentID=[{}] PluginID=[{}]", UNPROCESSABLE_ENTITY, message, uuid, hostname, elasticAgentId, elasticPluginId);
return new ResponseEntity<>(message, UNPROCESSABLE_ENTITY);
}
}
Agent agent = createAgentFromRequest(uuid, preferredHostname, ipAddress, elasticAgentId, elasticPluginId);
agent.validate();
if (agent.hasErrors()) {
List<ConfigErrors> errors = agent.errorsAsList();
throw new GoConfigInvalidException(null, new AllConfigErrors(errors));
}
if (partialElasticAgentAutoregistrationInfo(elasticAgentId, elasticPluginId)) {
String message = "Elastic agents must submit both elasticAgentId and elasticPluginId.";
LOG.error("Rejecting request for registration. Error: HttpCode=[{}] Message=[{}] UUID=[{}] Hostname=[{}]" + "ElasticAgentID=[{}] PluginID=[{}]", UNPROCESSABLE_ENTITY, message, uuid, hostname, elasticAgentId, elasticPluginId);
return new ResponseEntity<>(message, UNPROCESSABLE_ENTITY);
}
if (elasticAgentIdAlreadyRegistered(elasticAgentId, elasticPluginId)) {
String message = "Duplicate Elastic agent Id used to register elastic agent.";
LOG.error("Rejecting request for registration. Error: HttpCode=[{}] Message=[{}] UUID=[{}] Hostname=[{}]" + "ElasticAgentID=[{}] PluginID=[{}]", UNPROCESSABLE_ENTITY, message, uuid, hostname, elasticAgentId, elasticPluginId);
return new ResponseEntity<>(message, UNPROCESSABLE_ENTITY);
}
if (shouldAutoRegister && !agentService.isRegistered(uuid)) {
LOG.info("[Agent Auto Registration] Auto registering agent with uuid {} ", uuid);
agent.setEnvironments(agentAutoRegisterEnvs);
agent.setResources(agentAutoRegisterResources);
agentService.register(agent);
if (agent.hasErrors()) {
throw new GoConfigInvalidException(null, new AllConfigErrors(agent.errorsAsList()).asString());
}
}
boolean registeredAlready = agentService.isRegistered(uuid);
long usableSpace = Long.parseLong(usableSpaceStr);
AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(agent, registeredAlready, location, usableSpace, os);
if (elasticAgentAutoregistrationInfoPresent(elasticAgentId, elasticPluginId)) {
agentRuntimeInfo = ElasticAgentRuntimeInfo.fromServer(agentRuntimeInfo, elasticAgentId, elasticPluginId);
}
keyEntry = agentService.requestRegistration(agentRuntimeInfo);
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return new ResponseEntity<>("", httpHeaders, keyEntry ? OK : ACCEPTED);
} catch (Exception e) {
LOG.error("Error occurred during agent registration process. Error: HttpCode=[{}] Message=[{}] UUID=[{}] " + "Hostname=[{}] ElasticAgentID=[{}] PluginID=[{}]", UNPROCESSABLE_ENTITY, getErrorMessage(e), uuid, hostname, elasticAgentId, elasticPluginId, e);
return new ResponseEntity<>(String.format("Error occurred during agent registration process: %s", getErrorMessage(e)), UNPROCESSABLE_ENTITY);
}
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationController method createAgentFromRequest.
private Agent createAgentFromRequest(String uuid, String hostname, String ip, String elasticAgentId, String elasticPluginId) {
Agent agent = new Agent(uuid, hostname, ip);
if (elasticAgentAutoregistrationInfoPresent(elasticAgentId, elasticPluginId)) {
agent.setElasticAgentId(elasticAgentId);
agent.setElasticPluginId(elasticPluginId);
}
return agent;
}
use of com.thoughtworks.go.config.Agent 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());
Agent agent = agentService.getAgentByUUID(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();
Stage stage = stageService.getStageByBuild(current);
return new JobDetailPresentationModel(current, recent25, agent, pipelineWithOneBuild, customizedTabs, trackingTool, artifactService, stage);
}
Aggregations