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