public String set(String baseUrl, boolean maintenanceMode) { try { serviceRegistry.setMaintenanceStatus(baseUrl, maintenanceMode); if (maintenanceMode) { return baseUrl + " is now in maintenance mode\n"; } else { return baseUrl + " has returned to service\n"; } } catch (ServiceRegistryException e) { return "Error setting maintenance mode: " + e.getMessage() + "\n"; } catch (NotFoundException e) { return "Error setting maintenance mode, host " + baseUrl + " not found"; } }
private Job findJob(long jobId) throws NotFoundException, IncidentServiceException { try { return getServiceRegistry().getJob(jobId); } catch (NotFoundException e) { logger.info("Job with Id {} does not exist", jobId); throw e; } catch (ServiceRegistryException e) { logger.error("Could not retrieve job {}: {}", jobId, e.getMessage()); throw new IncidentServiceException(e); } }
public String list() { try { StringBuilder sb = new StringBuilder(); for (ServiceRegistration reg : serviceRegistry.getServiceRegistrations()) { sb.append(reg.getServiceType()); sb.append("@"); sb.append(reg.getHost()); if (reg.isInMaintenanceMode()) { sb.append(" (maintenance mode)"); } sb.append("\n"); } return sb.toString(); } catch (ServiceRegistryException e) { return "Error: " + e.getMessage() + "\n"; } }
@POST @Path("unregisterhost") @RestQuery(name = "unregisterhost", description = "Removes a server from the cluster.", returnDescription = "No content.", restParameters = { @RestParameter(name = "host", isRequired = true, description = "The host name, including the http(s) protocol", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_NO_CONTENT, description = "The host was removed successfully") }) public Response unregister(@FormParam("host") String host) { try { serviceRegistry.unregisterHost(host); return Response.status(Status.NO_CONTENT).build(); } catch (ServiceRegistryException e) { if (e.getCause() instanceof IllegalArgumentException) { return Response.status(Status.NOT_FOUND).entity(e.getMessage()).build(); } throw new WebApplicationException(e); } }
break; } catch (ServiceRegistryException e) { logger.warn("Error polling service registry for the status of {}: {}", job, e.getMessage()); } catch (JobCanceledException e) { logger.warn("Job {} got canceled", job);
private void suspendWaiterJob() { if (this.waiterJobId.isSome()) { try { final Job waiter = serviceRegistry.getJob(waiterJobId.get()); waiter.setStatus(Job.Status.WAITING); List<Long> blockedForJobs = new LinkedList<Long>(); for (Job j : jobs) { try { if (setBlockerJob(j, waiter)) { blockedForJobs.add(j.getId()); } } catch (OptimisticLockException e) { // Try again, this happens if the job finishes before we get here // If the same exception happens again then we're in a very weird state if (setBlockerJob(j, waiter)) { blockedForJobs.add(j.getId()); } } } waiter.setBlockedJobIds(blockedForJobs); this.serviceRegistry.updateJob(waiter); } catch (ServiceRegistryException e) { logger.warn("Unable to put {} into a waiting state, this may cause a deadlock: {}", waiterJobId, e.getMessage()); } catch (NotFoundException e) { logger.warn("Unable to put {} into a waiting state, job not found by the service registry. This may cause a deadlock: {}", waiterJobId, e.getMessage()); } } else { logger.debug("No waiting job set, unable to put waiting job into waiting state"); } }
private void wakeWaiterJob() { if (this.waiterJobId.isSome()) { try { final Job waiter = serviceRegistry.getJob(waiterJobId.get()); waiter.setStatus(Job.Status.RUNNING); for (Job j : jobs) { Job updatedJob = this.serviceRegistry.getJob(j.getId()); updatedJob.removeBlockingJobId(); // FYI not updating local j in jobs collection this.serviceRegistry.updateJob(updatedJob); } waiter.removeBlockedJobsIds(); this.serviceRegistry.updateJob(waiter); } catch (ServiceRegistryException e) { logger.warn("Unable to put {} into a waiting state, this may cause a deadlock: {}", waiterJobId, e.getMessage()); } catch (NotFoundException e) { logger.warn("Unable to put {} into a waiting state, job not found by the service registry. This may cause a deadlock: {}", waiterJobId, e.getMessage()); } } else { logger.debug("No waiting job set, unable to put waiting job into waiting state"); } }