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