Search in sources :

Example 1 with ServerMaintenanceMode

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

the class BuildAssignmentServiceIntegrationTest method setUp.

@BeforeEach
public void setUp(@TempDir Path tempDir) throws Exception {
    maintenanceModeService.update(new ServerMaintenanceMode(false, "admin", new Date()));
    configCache = new ConfigCache();
    registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    configHelper = new GoConfigFileHelper().usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    dbHelper.onSetUp();
    fixture = new PipelineWithTwoStages(materialRepository, transactionTemplate, tempDir);
    fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
    repository = new SvnCommand(null, testRepo.projectRepositoryUrl());
    evolveConfig = configHelper.addPipeline("evolve", STAGE_NAME, repository, "unit");
    configHelper.addPipeline("anotherPipeline", STAGE_NAME, repository, "anotherTest");
    configHelper.addPipeline("thirdPipeline", STAGE_NAME, repository, "yetAnotherTest");
    goConfigService.forceNotifyListeners();
    goCache.clear();
    u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper);
    notifier.disableUpdates();
}
Also used : PipelineWithTwoStages(com.thoughtworks.go.fixture.PipelineWithTwoStages) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) ServerMaintenanceMode(com.thoughtworks.go.server.domain.ServerMaintenanceMode) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ServerMaintenanceMode

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

the class ServerMaintenanceModeControllerV1 method getMaintenanceModeInfo.

public String getMaintenanceModeInfo(Request req, Response res) throws IOException {
    ServerMaintenanceMode serverMaintenanceMode = maintenanceModeService.get();
    if (serverMaintenanceMode.isMaintenanceMode()) {
        Collection<MaintenanceModeService.MaterialPerformingMDU> runningMDUs = maintenanceModeService.getRunningMDUs();
        List<ArrayList<JobInstance>> allRunningJobs = getRunningJobs();
        ArrayList<JobInstance> buildingJobs = allRunningJobs.get(0);
        ArrayList<JobInstance> scheduledJobs = allRunningJobs.get(1);
        boolean hasNoRunningSystems = runningMDUs.isEmpty() && buildingJobs.isEmpty();
        return writerForTopLevelObject(req, res, writer -> {
            MaintenanceModeInfoRepresenter.toJSON(writer, serverMaintenanceMode, hasNoRunningSystems, runningMDUs, buildingJobs, scheduledJobs);
        });
    } else {
        return writerForTopLevelObject(req, res, writer -> {
            MaintenanceModeInfoRepresenter.toJSON(writer, serverMaintenanceMode, false, null, null, null);
        });
    }
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) ServerMaintenanceMode(com.thoughtworks.go.server.domain.ServerMaintenanceMode)

Example 3 with ServerMaintenanceMode

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

the class ServerMaintenanceModeControllerV1 method enableMaintenanceModeState.

public String enableMaintenanceModeState(Request req, Response res) throws Exception {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ServerMaintenanceMode existingMaintenanceModeState = maintenanceModeService.get();
    if (existingMaintenanceModeState.isMaintenanceMode()) {
        result.conflict("Failed to enable server maintenance mode. Server is already in maintenance mode.");
        return renderHTTPOperationResult(result, req, res);
    }
    maintenanceModeService.update(new ServerMaintenanceMode(true, 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 4 with ServerMaintenanceMode

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

the class MaintenanceModeServiceTest method shouldReturnUsernameWhenServerIsInMaintenanceMode.

@Test
void shouldReturnUsernameWhenServerIsInMaintenanceMode() {
    maintenanceModeService.update(new ServerMaintenanceMode(true, "admin", new Date()));
    assertThat(maintenanceModeService.updatedBy()).isEqualTo("admin");
}
Also used : ServerMaintenanceMode(com.thoughtworks.go.server.domain.ServerMaintenanceMode) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with ServerMaintenanceMode

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

the class MaintenanceModeServiceTest method shouldUpdateMaintenanceModeSettings.

@Test
void shouldUpdateMaintenanceModeSettings() {
    assertThat(maintenanceModeService.isMaintenanceMode()).isFalse();
    maintenanceModeService.update(new ServerMaintenanceMode(true, "admin", new Date()));
    assertThat(maintenanceModeService.isMaintenanceMode()).isTrue();
}
Also used : 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