Search in sources :

Example 6 with ServerMaintenanceMode

use of com.thoughtworks.go.server.domain.ServerMaintenanceMode in project gocd by gocd.

the class TimerSchedulerQuartzIntegrationTest method shouldNotExecuteScheduledJobsWhenServerIsInMaintenanceMode.

@Test
public void shouldNotExecuteScheduledJobsWhenServerIsInMaintenanceMode() throws InterruptedException {
    PipelineConfig uat = pipelineConfigWithTimer("uat", "* * * * * ?");
    PipelineConfig dist = pipelineConfigWithTimer("dist", "* * * * * ?");
    List<PipelineConfig> pipelineConfigs = asList(uat, dist);
    GoConfigService goConfigService = mock(GoConfigService.class);
    when(goConfigService.getAllPipelineConfigs()).thenReturn(pipelineConfigs);
    BuildCauseProducerService buildCauseProducerService = mock(BuildCauseProducerService.class);
    ServerMaintenanceMode serverMaintenanceMode = new ServerMaintenanceMode();
    serverMaintenanceMode.setMaintenanceMode(true);
    maintenanceModeService.update(serverMaintenanceMode);
    TimerScheduler timerScheduler = new TimerScheduler(scheduler, goConfigService, buildCauseProducerService, null, maintenanceModeService, systemEnvironment);
    timerScheduler.initialize();
    pauseForScheduling();
    verify(buildCauseProducerService, never()).timerSchedulePipeline(eq(uat), any(ServerHealthStateOperationResult.class));
    verify(buildCauseProducerService, never()).timerSchedulePipeline(eq(dist), any(ServerHealthStateOperationResult.class));
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) ServerMaintenanceMode(com.thoughtworks.go.server.domain.ServerMaintenanceMode) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCauseProducerService(com.thoughtworks.go.server.scheduling.BuildCauseProducerService) Test(org.junit.jupiter.api.Test)

Example 7 with ServerMaintenanceMode

use of com.thoughtworks.go.server.domain.ServerMaintenanceMode in project gocd by gocd.

the class ServerMaintenanceModeControllerV1 method disableMaintenanceModeState.

public String disableMaintenanceModeState(Request req, Response res) throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ServerMaintenanceMode existingMaintenanceModeState = maintenanceModeService.get();
    if (!existingMaintenanceModeState.isMaintenanceMode()) {
        result.conflict("Failed to disable server maintenance mode. Server is not in maintenance mode.");
        return renderHTTPOperationResult(result, req, res);
    }
    maintenanceModeService.update(new ServerMaintenanceMode(false, currentUsernameString(), clock.currentTime()));
    res.status(204);
    return NOTHING;
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ServerMaintenanceMode(com.thoughtworks.go.server.domain.ServerMaintenanceMode)

Example 8 with ServerMaintenanceMode

use of com.thoughtworks.go.server.domain.ServerMaintenanceMode in project gocd by gocd.

the class MaintenanceModeServiceTest method shouldReturnUpdatedOnTimeWhenServerIsInMaintenanceMode.

@Test
void shouldReturnUpdatedOnTimeWhenServerIsInMaintenanceMode() {
    DateTime dateTime = new DateTime(2019, 6, 18, 14, 30, 15, DateTimeZone.UTC);
    maintenanceModeService.update(new ServerMaintenanceMode(true, "admin", dateTime.toDate()));
    assertThat(maintenanceModeService.updatedOn()).isEqualTo("2019-06-18T14:30:15Z");
}
Also used : ServerMaintenanceMode(com.thoughtworks.go.server.domain.ServerMaintenanceMode) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 9 with ServerMaintenanceMode

use of com.thoughtworks.go.server.domain.ServerMaintenanceMode in project gocd by gocd.

the class BuildAssignmentServiceIntegrationTest method shouldNotScheduleJobsDuringServerMaintenanceMode.

@Test
public void shouldNotScheduleJobsDuringServerMaintenanceMode() throws Exception {
    maintenanceModeService.update(new ServerMaintenanceMode(true, "admin", new Date()));
    JobConfig jobConfig = evolveConfig.findBy(new CaseInsensitiveString(STAGE_NAME)).jobConfigByInstanceName("unit", true);
    jobConfig.addResourceConfig("some-resource");
    scheduleHelper.schedule(evolveConfig, modifySomeFiles(evolveConfig), DEFAULT_APPROVED_BY);
    Agent agent = AgentMother.localAgent();
    agent.setResources("some-resource");
    buildAssignmentService.onTimer();
    Work work = buildAssignmentService.assignWorkToAgent(agent(agent));
    assertThat(work, is(BuildAssignmentService.NO_WORK));
    Pipeline pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(evolveConfig.name()));
    JobInstance job = pipeline.findStage(STAGE_NAME).findJob("unit");
    JobPlan loadedPlan = jobInstanceDao.loadPlan(job.getId());
    assertThat(loadedPlan.getResources().toResourceConfigs(), is(jobConfig.resourceConfigs()));
    assertThat(job.getState(), is(JobState.Scheduled));
    assertNull(job.getAgentUuid());
}
Also used : BuildWork(com.thoughtworks.go.remote.work.BuildWork) Work(com.thoughtworks.go.remote.work.Work) DeniedAgentWork(com.thoughtworks.go.remote.work.DeniedAgentWork) ServerMaintenanceMode(com.thoughtworks.go.server.domain.ServerMaintenanceMode) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

ServerMaintenanceMode (com.thoughtworks.go.server.domain.ServerMaintenanceMode)9 Test (org.junit.jupiter.api.Test)5 Date (java.util.Date)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 SvnCommand (com.thoughtworks.go.domain.materials.svn.SvnCommand)1 PipelineWithTwoStages (com.thoughtworks.go.fixture.PipelineWithTwoStages)1 BuildWork (com.thoughtworks.go.remote.work.BuildWork)1 DeniedAgentWork (com.thoughtworks.go.remote.work.DeniedAgentWork)1 Work (com.thoughtworks.go.remote.work.Work)1 BuildCauseProducerService (com.thoughtworks.go.server.scheduling.BuildCauseProducerService)1 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)1 DateTime (org.joda.time.DateTime)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1