Search in sources :

Example 16 with Agent

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

the class DefaultSchedulingContext method permittedAgent.

@Override
public SchedulingContext permittedAgent(String permittedAgentUuid) {
    Agents permitted = new Agents();
    for (Agent agent : agents) {
        if (agent.getUuid().equals(permittedAgentUuid)) {
            permitted.add(agent);
        }
    }
    DefaultSchedulingContext context = new DefaultSchedulingContext(approvedBy, permitted, profiles, clusterProfiles);
    context.variables = variables.overrideWith(new EnvironmentVariablesConfig());
    context.rerun = rerun;
    return context;
}
Also used : Agent(com.thoughtworks.go.config.Agent) Agents(com.thoughtworks.go.config.Agents) EnvironmentVariablesConfig(com.thoughtworks.go.config.EnvironmentVariablesConfig)

Example 17 with Agent

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

the class PluginNotificationServiceTest method shouldConstructDataForElasticAgentNotification.

@Test
public void shouldConstructDataForElasticAgentNotification() {
    when(notificationPluginRegistry.getPluginsInterestedIn(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION)).thenReturn(new LinkedHashSet<>(asList(PLUGIN_ID_1)));
    when(systemEnvironment.get(NOTIFICATION_PLUGIN_MESSAGES_TTL)).thenReturn(1000L);
    ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
    Agent agent = new Agent("some-uuid");
    agent.setElasticAgentId("42");
    agent.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
    agent.setIpaddress("127.0.0.1");
    AgentInstance agentInstance = AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    agentInstance.update(agentRuntimeInfo);
    pluginNotificationService.notifyAgentStatus(agentInstance);
    ArgumentCaptor<PluginNotificationMessage> captor = ArgumentCaptor.forClass(PluginNotificationMessage.class);
    verify(pluginNotificationsQueueHandler).post(captor.capture(), eq(1000L));
    PluginNotificationMessage message = captor.getValue();
    assertThat(message.pluginId(), is(PLUGIN_ID_1));
    assertThat(message.getRequestName(), is(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION));
    assertThat(message.getData() instanceof AgentNotificationData, is(true));
    AgentNotificationData data = (AgentNotificationData) message.getData();
    assertTrue(data.isElastic());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Agent(com.thoughtworks.go.config.Agent) AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) ElasticAgentRuntimeInfo(com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.jupiter.api.Test)

Example 18 with Agent

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

the class AgentStatusChangeNotifierTest method shouldNotifyIfAgentIsElastic.

@Test
public void shouldNotifyIfAgentIsElastic() {
    ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
    Agent agent = new Agent("some-uuid");
    agent.setElasticAgentId("42");
    agent.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
    agent.setIpaddress("127.0.0.1");
    AgentInstance agentInstance = AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    agentInstance.update(agentRuntimeInfo);
    when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
    agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
    verify(pluginNotificationService).notifyAgentStatus(agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Agent(com.thoughtworks.go.config.Agent) ElasticAgentRuntimeInfo(com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.jupiter.api.Test)

Example 19 with Agent

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

the class JobControllerIntegrationTest method jobDetailModel_shouldNotHaveElasticPluginIdAndElasticAgentIdForACompletedJob.

@Test
public void jobDetailModel_shouldNotHaveElasticPluginIdAndElasticAgentIdForACompletedJob() throws Exception {
    Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
    Stage stage = pipeline.getFirstStage();
    JobInstance job = stage.getFirstJob();
    final Agent agent = new Agent(job.getAgentUuid(), "localhost", "127.0.0.1", uuidGenerator.randomUuid());
    agent.setElasticAgentId("elastic_agent_id");
    agent.setElasticPluginId("plugin_id");
    agentService.saveOrUpdate(agent);
    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 : Agent(com.thoughtworks.go.config.Agent) JobInstance(com.thoughtworks.go.domain.JobInstance) ModelAndView(org.springframework.web.servlet.ModelAndView) Stage(com.thoughtworks.go.domain.Stage) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.jupiter.api.Test)

Example 20 with Agent

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

the class AgentRegistrationControllerIntegrationTest method shouldNotRegisterElasticAgentWithDuplicateElasticAgentID.

@Test
public void shouldNotRegisterElasticAgentWithDuplicateElasticAgentID() {
    String uuid = UUID.randomUUID().toString();
    String elasticAgentId = UUID.randomUUID().toString();
    MockHttpServletRequest request = new MockHttpServletRequest();
    controller.agentRequest("elastic-agent-hostname", uuid, "sandbox", "100", "Alpine Linux v3.5", ephemeralAutoRegisterKeyService.autoRegisterKey(), "", "", "hostname", elasticAgentId, "elastic-plugin-id", token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
    Agent agent = agentService.getAgentByUUID(uuid);
    assertTrue(agent.isElastic());
    final ResponseEntity responseEntity = controller.agentRequest("elastic-agent-hostname", uuid, "sandbox", "100", "Alpine Linux v3.5", ephemeralAutoRegisterKeyService.autoRegisterKey(), "", "", "hostname", elasticAgentId, "elastic-plugin-id", token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
    assertThat(responseEntity.getStatusCode(), is(UNPROCESSABLE_ENTITY));
    assertThat(responseEntity.getBody(), is("Duplicate Elastic agent Id used to register elastic agent."));
}
Also used : Agent(com.thoughtworks.go.config.Agent) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Agent (com.thoughtworks.go.config.Agent)100 Test (org.junit.jupiter.api.Test)52 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)36 AgentInstance (com.thoughtworks.go.domain.AgentInstance)20 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)19 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)16 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)13 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)11 JobInstance (com.thoughtworks.go.domain.JobInstance)8 ResponseEntity (org.springframework.http.ResponseEntity)8 ServerConfig (com.thoughtworks.go.config.ServerConfig)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)6 Username (com.thoughtworks.go.server.domain.Username)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)4 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)4 Query (org.hibernate.Query)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4 Gson (com.google.gson.Gson)3 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)3