Search in sources :

Example 46 with AgentInstance

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;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) MaxPendingAgentsLimitReachedException(com.thoughtworks.go.domain.exception.MaxPendingAgentsLimitReachedException)

Example 47 with 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);
    }
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) SecretResolutionFailureException(com.thoughtworks.go.plugin.access.exceptions.SecretResolutionFailureException) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 48 with AgentInstance

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());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 49 with AgentInstance

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;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Agent(com.thoughtworks.go.config.Agent)

Example 50 with AgentInstance

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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) NoWork(com.thoughtworks.go.remote.work.NoWork) BuildWork(com.thoughtworks.go.remote.work.BuildWork) Test(org.junit.jupiter.api.Test)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)129 Test (org.junit.Test)61 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)32 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)32 ArrayList (java.util.ArrayList)21 Agent (com.thoughtworks.go.config.Agent)20 Test (org.junit.jupiter.api.Test)20 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 AgentConfig (com.thoughtworks.go.config.AgentConfig)16 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)12 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)10 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)8 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)8 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)7 ResponseEntity (org.springframework.http.ResponseEntity)7 BuildWork (com.thoughtworks.go.remote.work.BuildWork)6 NoWork (com.thoughtworks.go.remote.work.NoWork)6 Work (com.thoughtworks.go.remote.work.Work)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6