Search in sources :

Example 71 with Agent

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

the class AgentInstanceMother method missing.

public static AgentInstance missing() {
    Agent agent = new Agent("1234", "localhost", "192.168.0.1");
    AgentInstance instance = AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.initialState(agent);
    newRuntimeInfo.setStatus(AgentStatus.Missing);
    instance.update(newRuntimeInfo);
    return instance;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

Example 72 with Agent

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

the class AgentTest method shouldCopyAllFieldsFromAnotherAgentObjectUsingCopyConstructor.

@Test
void shouldCopyAllFieldsFromAnotherAgentObjectUsingCopyConstructor() {
    Agent origAgent = new Agent("uuid", "host", "127.0.0.1", "cookie");
    origAgent.addResources(asList("Resource1", "Resource2"));
    origAgent.addEnvironments(asList("dev", "test"));
    Agent copiedAgent = new Agent(origAgent);
    assertEquals(origAgent, copiedAgent);
}
Also used : Agent(com.thoughtworks.go.config.Agent) Test(org.junit.jupiter.api.Test)

Example 73 with Agent

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

the class JobPresentationService method jobInstanceModelFor.

public List<JobInstanceModel> jobInstanceModelFor(JobInstances jobInstances) {
    ArrayList<JobInstanceModel> models = new ArrayList<>();
    for (JobInstance jobInstance : jobInstances) {
        AgentInstance agentInstance = jobInstance.isAssignedToAgent() ? agentService.findAgentAndRefreshStatus(jobInstance.getAgentUuid()) : null;
        JobInstanceModel model;
        if (null != agentInstance && !agentInstance.isNullAgent()) {
            model = new JobInstanceModel(jobInstance, jobDurationStrategy, agentInstance);
        } else if (jobInstance.getAgentUuid() != null) {
            Agent agent = agentService.findAgentByUUID(jobInstance.getAgentUuid());
            model = new JobInstanceModel(jobInstance, jobDurationStrategy, agent);
        } else {
            model = new JobInstanceModel(jobInstance, jobDurationStrategy);
        }
        models.add(model);
    }
    models.sort(JobInstanceModel.JOB_MODEL_COMPARATOR);
    return models;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Agent(com.thoughtworks.go.config.Agent) JobInstance(com.thoughtworks.go.domain.JobInstance) ArrayList(java.util.ArrayList) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel)

Example 74 with Agent

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

the class AgentRegistrationControllerTest method shouldNotAutoRegisterAgentIfKeysDoNotMatch.

@Test
public void shouldNotAutoRegisterAgentIfKeysDoNotMatch() {
    String uuid = "uuid";
    when(agentService.isRegistered(uuid)).thenReturn(false);
    ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.createAgentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
    controller.agentRequest("host", uuid, "location", "233232", "osx", "", "", "", "", "", "", token(uuid, serverConfig.getTokenGenerationKey()), request);
    verify(agentService).requestRegistration(AgentRuntimeInfo.fromServer(new Agent(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx"));
    verify(goConfigService, never()).updateConfig(any(UpdateConfigCommand.class));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) Agent(com.thoughtworks.go.config.Agent) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Example 75 with Agent

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

the class AgentRegistrationControllerTest method shouldAutoRegisterElasticAgentIfEphemeralAutoRegisterKeyIsValid.

@Test
public void shouldAutoRegisterElasticAgentIfEphemeralAutoRegisterKeyIsValid() {
    String uuid = "elastic-uuid";
    final ServerConfig serverConfig = mockedServerConfig("token-generation-key", "auto_register_key");
    final String token = token(uuid, serverConfig.getTokenGenerationKey());
    when(agentService.isRegistered(uuid)).thenReturn(false);
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.createAgentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
    when(ephemeralAutoRegisterKeyService.validateAndRevoke("someKey")).thenReturn(true);
    String elasticAgentId = "elastic-agent-id";
    String elasticPluginId = "elastic-plugin-id";
    AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(new Agent(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx");
    controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "e1", "", elasticAgentId, elasticPluginId, token, request);
    verify(agentService).findElasticAgent(elasticAgentId, elasticPluginId);
    verify(agentService, times(2)).isRegistered(uuid);
    verify(agentService).register(any(Agent.class));
    verify(agentService).requestRegistration(ElasticAgentRuntimeInfo.fromServer(agentRuntimeInfo, elasticAgentId, elasticPluginId));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) Agent(com.thoughtworks.go.config.Agent) Username(com.thoughtworks.go.server.domain.Username) 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