public JiraServiceContainer addService(String name, Class<? extends JiraService> serviceClass, long delay) throws ServiceException { return addService(name, serviceClass, delay, null); }
@Override public JiraServiceContainer getServiceWithId(final Long id) { return getServiceCache().get(id); }
private void ensureServicesScheduled() { getServices().stream() .filter(JiraServiceContainer::isUsable) .forEach(this::ensureServiceScheduled); }
public void removeService(final Long id) throws Exception { final Lock updateLock = getUpdateLock(); updateLock.lock(); try { final JiraServiceContainer jiraServiceContainer = serviceConfigStore.getServiceConfigForId(id); removeService(jiraServiceContainer); } finally { updateLock.unlock(); } }
public void refreshServiceByName(final String name) throws Exception { final Lock updateLock = getUpdateLock(); updateLock.lock(); try { final JiraServiceContainer serviceContainer = serviceConfigStore.getServiceConfigForName(name); // Reschedule the job. if (serviceContainer != null) { scheduleJob(serviceContainer); } servicesReference.reset(); } finally { updateLock.unlock(); } }
private void ensureServiceScheduled(JiraServiceContainer jiraServiceContainer) { // Try and convert to cron convertToCron(jiraServiceContainer); if (schedulerService.getJobDetails(toJobId(jiraServiceContainer.getId())) == null) { try { scheduleJob(jiraServiceContainer); } catch (Exception e) { LOG.warn("Unable to schedule service '" + jiraServiceContainer.getName() + "', " + e.getMessage()); } } }
@Override public Iterable<JiraServiceContainer> getServicesManageableBy(final ApplicationUser user) { if (isAnonymous(user)) { return ImmutableSet.of(); } if (permissionManager.hasPermission(Permissions.SYSTEM_ADMIN, user)) { return getServices(); } if (permissionManager.hasPermission(Permissions.ADMINISTER, user)) { final Set<String> names = getServiceClassNames(inBuiltServiceTypes.manageableBy(user)); return Iterables.filter(getServices(), new Predicate<JiraServiceContainer>() { @Override public boolean apply(final JiraServiceContainer service) { return names.contains(service.getServiceClass()); } }); } return ImmutableSet.of(); }
private void convertToCron(final JiraServiceContainer jiraServiceContainer) { // Service containers created prior to 6.4 will be scheduled with a delay and the cronExpression will be null if (jiraServiceContainer.getCronExpression() == null) { try { ConversionResult result = new SimpleToCronTriggerConverter().convertToCronString(new Date(jiraServiceContainer.getLastRun()), jiraServiceContainer.getDelay()); String cronExpression = result.cronString; // Edit will also reschedule. editService(jiraServiceContainer.getId(), cronExpression, propertiesToMap(jiraServiceContainer.getProperties())); } catch (Exception e) { LOG.warn("Unable to convert service entry to cron format", e); } } }
@Override public void refreshAll() { servicesReference.reset(); ensureServicesScheduled(); }
private Map<Long, JiraServiceContainer> getServiceCache() { if (!picoContainerComponentsRegistered()) { throw new IllegalStateException("It is illegal to call the ServiceManager before all components are loaded. Please use " + Startable.class + " to get notified when JIRA has started."); } return servicesReference.get(); }
@Override public void runNow(final long serviceId) throws Exception { JiraServiceContainer jiraServiceContainer = getServiceWithId(serviceId); if (jiraServiceContainer == null) { throw new ServiceException("Service with id '" + serviceId + "' was not found"); } JobConfig config = JobConfig.forJobRunnerKey(SERVICE_JOB_KEY) .withSchedule(Schedule.runOnce(null)) .withRunMode(RunMode.RUN_ONCE_PER_CLUSTER) .withParameters(ImmutableMap.<String, Serializable>of(SERVICE_ID_KEY, serviceId)); JobId jobId = schedulerService.scheduleJobWithGeneratedId(config); LOG.debug("JIRA Service '" + jiraServiceContainer.getName() + "' scheduled for immediate execution with job id '" + jobId + '\''); }
private void refreshService(final Long id, boolean notify) throws Exception { final Lock updateLock = getUpdateLock(); updateLock.lock(); try { final JiraServiceContainer serviceContainer = serviceConfigStore.getServiceConfigForId(id); // Reschedule the job. if (serviceContainer != null) { scheduleJob(serviceContainer, notify); } servicesReference.reset(); } finally { updateLock.unlock(); } }
public void removeServiceByName(final String name) throws Exception { final Lock updateLock = getUpdateLock(); updateLock.lock(); try { final JiraServiceContainer jiraServiceContainer = serviceConfigStore.getServiceConfigForName(name); if (jiraServiceContainer == null) { throw new IllegalArgumentException("No services with name '" + name + "' exist."); } removeService(jiraServiceContainer); } finally { updateLock.unlock(); } }
@Override public void start() { messagingService.registerListener(RESCHEDULE_SERVICE, messageConsumer); messagingService.registerListener(UNSCHEDULE_SERVICE, messageConsumer); schedulerService.registerJobRunner(SERVICE_JOB_KEY, new ServiceRunner()); ensureServicesScheduled(); }
public void editService(final Long id, final long delay, final Map<String, String[]> params) throws Exception { final Lock updateLock = getUpdateLock(); updateLock.lock(); try { final JiraServiceContainer serviceContainer = serviceConfigStore.getServiceConfigForId(id); serviceConfigStore.editServiceConfig(serviceContainer, delay, params); // Reschedule the job. scheduleJob(serviceContainer); servicesReference.reset(); } finally { updateLock.unlock(); } }
@Override public JiraServiceContainer addService(final String name, final String serviceClassName, final String cronExpression) throws ServiceException, ClassNotFoundException { return addService(name, serviceClassName, cronExpression, null); }
@Override public boolean containsServiceWithId(final Long id) { return getServiceCache().containsKey(id); }
@Override public void editService(final Long id, final String cronExpression, final Map<String, String[]> params) throws Exception { final Lock updateLock = getUpdateLock(); updateLock.lock(); try { final JiraServiceContainer serviceContainer = serviceConfigStore.getServiceConfigForId(id); serviceConfigStore.editServiceConfig(serviceContainer, cronExpression, params); // Reschedule the job. scheduleJob(serviceContainer); servicesReference.reset(); } finally { updateLock.unlock(); } }
@Override public JiraServiceContainer addService(final String name, final String serviceClassName, final long delay) throws ServiceException, ClassNotFoundException { return addService(name, serviceClassName, delay, null); }
public Collection<JiraServiceContainer> getServices() { return Collections.unmodifiableCollection(getServiceCache().values()); }