Search in sources :

Example 96 with Agent

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

the class JobAssignmentIntegrationTest method setupLocalAgent.

private AgentInstance setupLocalAgent() throws UnknownHostException {
    Agent agent = AgentMother.localAgent();
    agentService.saveOrUpdate(agent);
    return AgentInstance.createFromAgent(agent, systemEnvironment, agentStatusChangeListener());
}
Also used : Agent(com.thoughtworks.go.config.Agent)

Example 97 with Agent

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

the class ScheduleServiceRescheduleHungJobsIntegrationTest method shouldRescheduleHungBuildWhenAgentTryToGetWorkWithSameUuid.

@Test
public void shouldRescheduleHungBuildWhenAgentTryToGetWorkWithSameUuid() throws Exception {
    Agent agent = AgentMother.localAgent();
    AgentInstance instance = agent(agent);
    BuildCause buildCause = modifySomeFiles(evolveConfig);
    dbHelper.saveMaterials(buildCause.getMaterialRevisions());
    Pipeline pipeline = instanceFactory.createPipelineInstance(evolveConfig, buildCause, new DefaultSchedulingContext(DEFAULT_APPROVED_BY), "md5-test", new TimeProvider());
    buildAssignmentService.onTimer();
    Stage stage = pipeline.getFirstStage();
    JobInstance jobInstance = stage.getJobInstances().get(0);
    jobInstance.setAgentUuid(agent.getUuid());
    jobInstance.changeState(JobState.Building);
    pipelineDao.saveWithStages(pipeline);
    buildAssignmentService.onTimer();
    buildAssignmentService.assignWorkToAgent(instance);
    buildAssignmentService.onTimer();
    buildAssignmentService.assignWorkToAgent(instance);
    final Stage reloadedStage = stageDao.stageById(stage.getId());
    final JobInstance rescheduledJob = reloadedStage.getJobInstances().getByName(jobInstance.getName());
    assertThat(rescheduledJob.getState(), is(JobState.Assigned));
}
Also used : Agent(com.thoughtworks.go.config.Agent) TimeProvider(com.thoughtworks.go.util.TimeProvider) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 98 with Agent

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

the class ScheduleServiceRescheduleHungJobsIntegrationTest method shouldNotRescheduleCancelledBuilds.

@Test
public void shouldNotRescheduleCancelledBuilds() throws SQLException {
    String agentId = "uuid";
    final Pipeline pipeline = instanceFactory.createPipelineInstance(evolveConfig, modifySomeFiles(evolveConfig), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), "md5-test", new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(pipeline);
    buildAssignmentService.assignWorkToAgent(agent(new Agent(agentId)));
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            stageService.cancelStage(stageOf(pipeline), null);
        }
    });
    scheduleService.rescheduleHungJobs();
    JobInstance reloaded = jobInstanceDao.buildByIdWithTransitions(buildOf(pipeline).getId());
    assertThat(reloaded.getState(), is(JobState.Completed));
    assertThat(reloaded.getResult(), is(JobResult.Cancelled));
}
Also used : Agent(com.thoughtworks.go.config.Agent) TimeProvider(com.thoughtworks.go.util.TimeProvider) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 99 with Agent

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

the class UpdateAgentStatusTest method setUp.

@BeforeEach
public void setUp(@TempDir Path tempDir) throws Exception {
    dbHelper.onSetUp();
    configHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao);
    preCondition = new PipelineWithTwoStages(materialRepository, transactionTemplate, tempDir);
    preCondition.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
    agentService.clearAll();
    agentService.saveOrUpdate(new Agent(agentId, "CCEDev01", "10.81.2.1", "cookie"));
}
Also used : Agent(com.thoughtworks.go.config.Agent) PipelineWithTwoStages(com.thoughtworks.go.fixture.PipelineWithTwoStages) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 100 with Agent

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

the class AgentPerformanceVerifier method doAssertAgentAndItsAssociationInDBAndCache.

private void doAssertAgentAndItsAssociationInDBAndCache() {
    stream(agentService.getAgentInstances()).filter(agentInstance -> agentInstance.getUuid().startsWith("Perf-Test-Agent-")).forEach(agentInstance -> {
        Agent agentInCache = agentInstance.getAgent();
        Agent agentInDB = agentDao.fetchAgentFromDBByUUID(agentInCache.getUuid());
        if (agentInDB == null && !agentInstance.isPending()) {
            LOG.debug("Agent {} is not pending but not present in DB", agentInCache.getUuid());
            bombIfAgentInDBAndCacheAreDifferent(agentInCache, agentInDB);
        }
        Set<String> agentEnvsInEnvCache = environmentConfigService.getAgentEnvironmentNames(agentInCache.getUuid());
        HashSet<String> agentEnvsInDB = new HashSet<>(agentInDB.getEnvironmentsAsList());
        bombIfAgentEnvAssociationInDBAndEnvCacheAreDifferent(agentInCache, agentEnvsInDB, agentEnvsInEnvCache);
        bombIfMissingAgentKnownEnvAssociationInEnvCache(agentInCache, agentEnvsInEnvCache, agentEnvsInDB);
    });
    LOG.debug("\n\n*************** Hurray! Verification of performance tests succeeded and there are no threading issues reported! ***************\n\n");
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) Logger(org.slf4j.Logger) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) StandardOpenOption(java.nio.file.StandardOpenOption) AgentService(com.thoughtworks.go.server.service.AgentService) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AgentDao(com.thoughtworks.go.server.persistence.AgentDao) Executors(java.util.concurrent.Executors) Streams.stream(com.google.common.collect.Streams.stream) EnvironmentConfigService(com.thoughtworks.go.server.service.EnvironmentConfigService) Future(java.util.concurrent.Future) Paths(java.nio.file.Paths) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Agent(com.thoughtworks.go.config.Agent) com.thoughtworks.go.server.perf.commands(com.thoughtworks.go.server.perf.commands) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Path(java.nio.file.Path) Agent(com.thoughtworks.go.config.Agent)

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