@Autowired public MaintenanceModeService(TimeProvider timeProvider) { this.timeProvider = timeProvider; this.serverMaintenanceMode = new ServerMaintenanceMode(); }
public void update(ServerMaintenanceMode fromRequest) { LOGGER.info("[Maintenance Mode] Server maintenance mode state updated to 'isMaintenanceMode={}' by '{}' at '{}'.", fromRequest.isMaintenanceMode(), fromRequest.updatedBy(), fromRequest.updatedOn()); this.serverMaintenanceMode = fromRequest; }
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, currentUserLoginName().toString(), clock.currentTime())); res.status(204); return NOTHING; }
public boolean isMaintenanceMode() { return get().isMaintenanceMode(); }
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, currentUserLoginName().toString(), clock.currentTime())); res.status(204); return NOTHING; }
public String getMaintenanceModeInfo(Request req, Response res) throws InvalidPluginTypeException, 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); }); } }
public static void toJSON(OutputWriter jsonWriter, ServerMaintenanceMode serverMaintenanceMode, boolean hasNoRunningSystems, Collection<MaterialPerformingMDU> runningMDUs, List<JobInstance> buildingJobs, List<JobInstance> scheduledJobs) { jsonWriter .addLinks(linksWriter -> linksWriter.addLink("self", Routes.MaintenanceMode.BASE + Routes.MaintenanceMode.INFO) .addAbsoluteLink("doc", Routes.MaintenanceMode.INFO_DOC)); jsonWriter.add("is_maintenance_mode", serverMaintenanceMode.isMaintenanceMode()); jsonWriter.addChild("metadata", metadataChildWriter -> { metadataChildWriter.add("updated_by", serverMaintenanceMode.updatedBy()); metadataChildWriter.add("updated_on", serverMaintenanceMode.updatedOn()); }); if (serverMaintenanceMode.isMaintenanceMode()) { jsonWriter.addChild("attributes", attributesWriter -> { attributesWriter.add("has_running_systems", !hasNoRunningSystems); attributesWriter.addChild("running_systems", runningSystemsChildWriter -> { runningSystemsChildWriter.addChildList("material_update_in_progress", runningMDUsToJSON(runningMDUs)); runningSystemsChildWriter.addChildList("building_jobs", runningJobsToJSON(buildingJobs)); runningSystemsChildWriter.addChildList("scheduled_jobs", runningJobsToJSON(scheduledJobs)); }); }); } }