Search in sources :

Example 81 with AgentConfig

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

the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsRescheduled.

@Test
public void shouldSendCancelMessageIfJobIsRescheduled() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    configHelper.addAgent(agentConfig);
    fixture.createPipelineWithFirstStageScheduled();
    AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
    info.setCookie("cookie");
    agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    buildAssignmentService.onTimer();
    assertThat(agent.messages.size(), is(1));
    assertThat(MessageEncoding.decodeWork(agent.messages.get(0).getData()), instanceOf(BuildWork.class));
    BuildWork work = (BuildWork) MessageEncoding.decodeWork(agent.messages.get(0).getData());
    BuildAssignment assignment = work.getAssignment();
    final JobInstance instance = jobInstanceService.buildByIdWithTransitions(assignment.getJobIdentifier().getBuildId());
    scheduleService.rescheduleJob(instance);
    assertThat(agent.messages.size(), is(2));
    assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) JobInstance(com.thoughtworks.go.domain.JobInstance) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) BuildWork(com.thoughtworks.go.remote.work.BuildWork)

Example 82 with AgentConfig

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

the class JobAssignmentTest method setupLocalAgent.

private AgentInstance setupLocalAgent() throws UnknownHostException {
    AgentConfig agentConfig = AgentMother.localAgent();
    configHelper.addAgent(agentConfig);
    return AgentInstance.createFromConfig(agentConfig, systemEnvironment, agentStatusChangeListener());
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig)

Example 83 with AgentConfig

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

the class JobControllerIntegrationTest method jobDetailModel_shouldNotHaveTheElasticProfilePluginIdAndElasticAgentIdWhenAgentIsNotElasticAgent.

@Test
public void jobDetailModel_shouldNotHaveTheElasticProfilePluginIdAndElasticAgentIdWhenAgentIsNotElasticAgent() throws Exception {
    Pipeline pipeline = fixture.createPipelineWithFirstStageAssigned();
    Stage stage = pipeline.getFirstStage();
    JobInstance job = stage.getFirstJob();
    final AgentConfig agentConfig = new AgentConfig(job.getAgentUuid());
    goConfigService.agents().add(agentConfig);
    ModelAndView modelAndView = controller.jobDetail(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(stage.getCounter()), job.getName());
    assertNull(modelAndView.getModel().get("elasticAgentPluginId"));
    assertNull(modelAndView.getModel().get("elasticAgentId"));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) Test(org.junit.Test)

Example 84 with AgentConfig

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

the class JobControllerIntegrationTest method jobDetailModel_shouldHaveTheElasticPluginIdAndElasticAgentIdWhenAgentIsAssigned.

@Test
public void jobDetailModel_shouldHaveTheElasticPluginIdAndElasticAgentIdWhenAgentIsAssigned() throws Exception {
    Pipeline pipeline = fixture.createPipelineWithFirstStageAssigned();
    Stage stage = pipeline.getFirstStage();
    JobInstance job = stage.getFirstJob();
    GoPluginDescriptor.About about = new GoPluginDescriptor.About("name", "0.1", "17.3.0", "desc", null, null);
    GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin_id", null, about, null, null, false);
    ElasticAgentMetadataStore.instance().setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, new Capabilities(false, true)));
    fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), new ElasticProfile("profile_id", "plugin_id", Collections.EMPTY_LIST)));
    final AgentConfig agentConfig = new AgentConfig(job.getAgentUuid());
    agentConfig.setElasticAgentId("elastic_agent_id");
    agentConfig.setElasticPluginId("plugin_id");
    goConfigService.agents().add(agentConfig);
    ModelAndView modelAndView = controller.jobDetail(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(stage.getCounter()), job.getName());
    assertThat(modelAndView.getModel().get("elasticAgentPluginId"), is("plugin_id"));
    assertThat(modelAndView.getModel().get("elasticAgentId"), is("elastic_agent_id"));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) Capabilities(com.thoughtworks.go.plugin.domain.elastic.Capabilities) ModelAndView(org.springframework.web.servlet.ModelAndView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 85 with AgentConfig

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

the class AgentRegistrationControllerIntegrationTest method shouldReIssueCertificateIfRegisteredAgentAsksForRegistration.

@Test
public void shouldReIssueCertificateIfRegisteredAgentAsksForRegistration() throws Exception {
    String uuid = UUID.randomUUID().toString();
    agentConfigService.addAgent(new AgentConfig(uuid, "hostname", "127.0.01"), Username.ANONYMOUS);
    assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
    MockHttpServletRequest request = new MockHttpServletRequest();
    final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, null, null, null, null, null, null, false, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
    AgentInstance agentInstance = agentService.findAgent(uuid);
    assertTrue(agentInstance.isIdle());
    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
    assertTrue(RegistrationJSONizer.fromJson(responseEntity.getBody().toString()).isValid());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

AgentConfig (com.thoughtworks.go.config.AgentConfig)90 Test (org.junit.Test)68 AgentInstance (com.thoughtworks.go.domain.AgentInstance)20 Agents (com.thoughtworks.go.config.Agents)13 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)11 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)10 Username (com.thoughtworks.go.server.domain.Username)7 ResponseEntity (org.springframework.http.ResponseEntity)7 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)6 ResourceConfigs (com.thoughtworks.go.config.ResourceConfigs)5 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)4 ServerConfig (com.thoughtworks.go.config.ServerConfig)4 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)4 EnvironmentVariablesConfig (com.thoughtworks.go.config.EnvironmentVariablesConfig)3 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)3 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)3 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 StageConfig (com.thoughtworks.go.config.StageConfig)2