use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentInstances method register.
public AgentInstance register(AgentRuntimeInfo runtimeInfo) {
AgentInstance agentInstance = findAgentAndRefreshStatus(runtimeInfo.getUUId());
if (!agentInstance.isRegistered()) {
if (isMaxPendingAgentsLimitReached()) {
throw new MaxPendingAgentsLimitReachedException(systemEnvironment.get(MAX_PENDING_AGENTS_ALLOWED));
}
agentInstance = AgentInstance.createFromLiveAgent(runtimeInfo, systemEnvironment, agentStatusChangeListener);
this.add(agentInstance);
}
agentInstance.update(runtimeInfo);
return agentInstance;
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class ElasticAgentPluginService method jobCompleted.
public void jobCompleted(JobInstance job) {
AgentInstance agentInstance = agentService.findAgent(job.getAgentUuid());
if (!agentInstance.isElastic()) {
LOGGER.debug("Agent {} is not elastic. Skipping further execution.", agentInstance.getUuid());
return;
}
if (job.isAssignedToAgent()) {
jobCreationTimeMap.remove(job.getId());
}
String pluginId = agentInstance.elasticAgentMetadata().elasticPluginId();
String elasticAgentId = agentInstance.elasticAgentMetadata().elasticAgentId();
JobIdentifier jobIdentifier = job.getIdentifier();
ElasticProfile elasticProfile = job.getPlan().getElasticProfile();
ClusterProfile clusterProfile = job.getPlan().getClusterProfile();
try {
secretParamResolver.resolve(elasticProfile);
Map<String, String> elasticProfileConfiguration = elasticProfile.getConfigurationAsMap(true, true);
Map<String, String> clusterProfileConfiguration = emptyMap();
if (clusterProfile != null) {
secretParamResolver.resolve(clusterProfile);
clusterProfileConfiguration = clusterProfile.getConfigurationAsMap(true, true);
}
elasticAgentPluginRegistry.reportJobCompletion(pluginId, elasticAgentId, jobIdentifier, elasticProfileConfiguration, clusterProfileConfiguration);
} catch (RulesViolationException | SecretResolutionFailureException e) {
String description = format("The job completion call to the plugin for the job identifier [%s] failed for secrets resolution: %s ", jobIdentifier.toString(), e.getMessage());
ServerHealthState healthState = error("Failed to notify plugin", description, general(scopeForJob(jobIdentifier)));
healthState.setTimeout(Timeout.FIVE_MINUTES);
serverHealthService.update(healthState);
LOGGER.error(description);
}
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentUpdateValidatorTest method setUp.
@BeforeEach
void setUp() {
result = new HttpOperationResult();
goConfigService = mock(GoConfigService.class);
agentInstance = mock(AgentInstance.class);
BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
when(goConfigService.getEnvironments()).thenReturn(cruiseConfig.getEnvironments());
}
use of com.thoughtworks.go.domain.AgentInstance 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.domain.AgentInstance in project gocd by gocd.
the class JobAssignmentIntegrationTest method shouldAssignJobToRemoteAgent.
@Test
public void shouldAssignJobToRemoteAgent() throws UnknownHostException {
AgentInstance local = setupLocalAgent();
AgentInstance remote = setupRemoteAgent();
fixture.createPipelineWithFirstStageScheduled();
assignmentService.onTimer();
assignmentService.assignWorkToAgent(local);
assignmentService.onTimer();
Work work = assignmentService.assignWorkToAgent(remote);
assertThat(work, instanceOf(BuildWork.class));
}
Aggregations