public Collection<Message> doUpgrade() throws Exception { JiraServiceContainer serviceContainer; while ((serviceContainer = serviceManager.getServiceWithName(USER_COUNTER_SERVICE))!=null) { log.info("Removing " + serviceContainer.getName()); serviceManager.removeService(serviceContainer.getId()); } return null; }
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); } } }
private void unscheduleJob(final JiraServiceContainer jiraServiceContainer) { unscheduleJob(jiraServiceContainer.getId()); if (jiraServiceContainer.isUsable() && jiraServiceContainer.isLocalService()) { messagingService.sendRemote(UNSCHEDULE_SERVICE, jiraServiceContainer.getId().toString()); } }
@Override public void append(final JiraServiceContainer input, final Map<String, Object> map) { map.put("name", input.getName()); map.put("class", input.getServiceClass()); map.put("schedule", input.getCronExpression()); map.put("properties", arrarify(translateValues(extendedSystemInfoUtils.getServicePropertyMap(input), i18nBean))); } }.build(extendedSystemInfoUtils.getServices());
private void addServiceInfo(final PropertyStore store) { callAndLogExceptions((Callable<Void>) () -> { DecimalFormat df = new DecimalFormat("#"); PropertyStore servicesStore = store.addCategory(SERVICES); Collection<JiraServiceContainer> services = utils.getServices(); for (JiraServiceContainer service : services) { PropertyStore serviceStore = servicesStore.addCategory(SERVICES_SERVICE); serviceStore.setValue(SERVICES_SERVICE_NAME, service.getName()); serviceStore.setValue(SERVICES_SERVICE_DELAY, df.format(service.getDelay() / 1000) + "ms"); if (service instanceof UnloadableJiraServiceContainer) { serviceStore.setValue(SERVICES_SERVICE_STATUS, "unloaded"); } else { serviceStore.setValue(SERVICES_SERVICE_LAST_RUN, factory.formatter().format(new Date(service.getLastRun()))); if (service.getDescription() != null) { serviceStore.setValue(SERVICES_SERVICE_DESCRIPTION, service.getDescription()); } } } return null; }); }
private void scheduleSimpleJob(final JiraServiceContainer jiraServiceContainer) throws SchedulerServiceException { // Work out the fire time delay. Date nextFireTime = null; long lastRunMillis = jiraServiceContainer.getLastRun(); final long nextRunMillis = lastRunMillis > 0 ? lastRunMillis + jiraServiceContainer.getDelay() : System.currentTimeMillis(); final boolean localService = jiraServiceContainer.isLocalService(); if (nextRunMillis > System.currentTimeMillis()) { nextFireTime = new Date(nextRunMillis); } JobConfig config = JobConfig.forJobRunnerKey(SERVICE_JOB_KEY) .withSchedule(Schedule.forInterval(jiraServiceContainer.getDelay(), nextFireTime)) .withRunMode(localService ? RunMode.RUN_LOCALLY : RunMode.RUN_ONCE_PER_CLUSTER) .withParameters(ImmutableMap.<String, Serializable>of(SERVICE_ID_KEY, jiraServiceContainer.getId())); schedulerService.scheduleJob(toJobId(jiraServiceContainer.getId()), config); }
private void printServiceInfo(JiraServiceContainer service) { logMsg.outputProperty(service.getName(), service.getServiceClass()); logMsg.outputProperty("Service Schedule", service.getCronExpression(), 2); try { final long lastRun = service.getLastRun(); if (lastRun > 0) { final DateFormat df = DateFormat.getInstance(); final Date dt = new Date(lastRun); logMsg.outputProperty("Last Run", df.format(dt)); } final Map<String, String> properties = ConfigurableObjectUtil.getPropertyMap(service); for (final Map.Entry<String, String> entry : properties.entrySet()) { logMsg.outputProperty(entry.getKey(), entry.getValue(), 2); } } catch (final Exception e) { logMsg.outputProperty("Exception getting Service information", e.toString()); } }
@Override public boolean apply(@Nullable JiraServiceContainer aServiceManageableByTheUser) { return serviceId.equals(aServiceManageableByTheUser.getId()); } });
private void scheduleJob(final JiraServiceContainer jiraServiceContainer, final boolean notify) throws SchedulerServiceException { if (StringUtils.isNotEmpty(jiraServiceContainer.getCronExpression())) { scheduleCronJob(jiraServiceContainer); } else if (jiraServiceContainer.getDelay() > 0) { scheduleSimpleJob(jiraServiceContainer); } else { return; } final boolean localService = jiraServiceContainer.isLocalService(); if (localService && notify) { messagingService.sendRemote(RESCHEDULE_SERVICE, jiraServiceContainer.getId().toString()); } }
private void editServiceConfig(final JiraServiceContainer config, final Long delay, final String cronExpression, final Map<String, String[]> params) throws ServiceException { final GenericValue serviceConfigGV = getGenericValueForConfig(config); if (log.isDebugEnabled()) { log.debug("Editing service with id '" + serviceConfigGV.getLong(SERVICE_CONFIG_ID) + "'."); } // store the updated properties final PropertySet ps = createPropertySet(serviceConfigGV, config, params); // store the updated schedule if (delay != null) { serviceConfigGV.set(SERVICE_CONFIG_TIME, delay); } serviceConfigGV.set(SERVICE_CONFIG_CRON, cronExpression); ofBizDelegator.store(serviceConfigGV); // update the object to reflect the changes in the db config.setDelay(serviceConfigGV.getLong(SERVICE_CONFIG_TIME)); config.setCronExpression(serviceConfigGV.getString(SERVICE_CONFIG_CRON)); try { config.init(ps); } catch (ObjectConfigurationException ex) { throw new ServiceException("An error occurred when initialising Service '" + config.getName() + "'.", ex); } }
private static JobRunnerResponse runService(final JiraServiceContainer service) { // make the logs come out with the name of the running service final String serviceName = service.getName(); setLog4JInfo(MOCK_USER_NAME, serviceName); try { if (LOG.isDebugEnabled()) { LOG.debug("Running Service [" + service + ']'); } ComponentAccessor.getJiraAuthenticationContext().clearLoggedInUser(); service.run(); if (LOG.isDebugEnabled()) { LOG.debug("Finished Running Service [" + service + ']'); } return JobRunnerResponse.success(); } catch (final RuntimeException e) { LOG.error("An error occurred while trying to run service '" + serviceName + "'. " + e.getMessage(), e); return JobRunnerResponse.failed(e); } finally { service.setLastRun(); setLog4JInfo(MOCK_USER_NAME, ""); } }
private void scheduleCronJob(final JiraServiceContainer jiraServiceContainer) throws SchedulerServiceException { final boolean localService = jiraServiceContainer.isLocalService(); JobConfig config = JobConfig.forJobRunnerKey(SERVICE_JOB_KEY) .withSchedule(Schedule.forCronExpression(jiraServiceContainer.getCronExpression())) .withRunMode(localService ? RunMode.RUN_LOCALLY : RunMode.RUN_ONCE_PER_CLUSTER) .withParameters(ImmutableMap.<String, Serializable>of(SERVICE_ID_KEY, jiraServiceContainer.getId())); schedulerService.scheduleJob(toJobId(jiraServiceContainer.getId()), config); }
if (name.equalsIgnoreCase(service.getName())) if (clazz.equals(service.getServiceClass())) serviceExists = service.isUnique();
if (service.getServiceClass().equals(clazz)) ComponentAccessor.getServiceManager().removeService(serviceContainer.getId());
@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 + '\''); }
public long getDelayInMins(JiraServiceContainer serviceContainer) { return serviceContainer.getDelay() / 60000; }
@Override public String getSnapshotCronExpression(final ApplicationUser user) { try { final JiraServiceContainer service = serviceManager.getServiceWithName(IndexSnapshotService.getServiceName()); if (service != null) { return service.getCronExpression(); } return null; } catch (Exception e) { return null; } } }
@Override public boolean apply(@Nullable JiraServiceContainer aServiceManageableByTheUser) { return serviceId.equals(aServiceManageableByTheUser.getId()); } });
public String doDefault() throws Exception { if (canEditService(id)) { delay = getService().getDelay() / (60 * 1000); // prime our data for display getObjectConfigurationKeys(); return INPUT; } else { return "securitybreach"; } }