public void unscheduleJob(final String name) { // Remove the service if it exists. We use getServices() rather than // getServiceWithName() because there was // a bug where multiple services with the same name were being // created. getServiceWithName() will throw an // exception in that circumstance, so we'll just iterate through // them all and delete all the ones that have // a matching name. Collection<JiraServiceContainer> services = serviceManager.getServices(); // We have to copy the services into a second map, otherwise after // deleting one, we get a // ConcurrentModificationException services = new HashSet<JiraServiceContainer>(services); for (final JiraServiceContainer service : services) { if (name.equals(service.getName())) { try { serviceManager.removeService(service.getId()); } catch (final Exception e) { log.error("Error removing service to jira", e); } } } }
/** * Creates a new Node State Checker service if it doesn't exist. */ public void createNodeCheckerServiceIfNeeded(final I18nHelper i18n) { try { final String serviceName = i18n.getText(SERVICE_NAME_KEY); if (serviceManager.getServiceWithName(serviceName) == null) { final Map<String, String[]> params = new HashMap<String, String[]>(0); serviceManager.addService(serviceName, NodeStateCheckerService.class.getName(), DELAY, params); } } catch (final Exception e) // intentionally catching RuntimeException as well { LOG.error(i18nHelper.getText("admin.errors.setup.error.adding.service", e.toString())); } } }
public void doUpgrade() throws FishEyeUpgradeException { try { if (serviceManager.getServiceWithName(SERVICE_NAME) != null) { try { log.info("Removing old " + SERVICE_NAME); serviceManager.removeServiceByName(SERVICE_NAME); serviceManager.refreshAll(); } catch (Exception e) { log.error("Exception encountered whilst trying to remove service '" + SERVICE_NAME + "'", e); } } } catch (Exception e) { log.error("Error resolving service with name " + SERVICE_NAME, e); } }
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; }
/** * @return * @param serviceId */ public boolean isUnsafeService(final long serviceId) { try { if (serviceManager.containsServiceWithId(serviceId)) { final JiraServiceContainer serviceWithId = serviceManager.getServiceWithId(serviceId); final String serviceClass = serviceWithId.getServiceClass(); return "com.atlassian.jira.service.services.export.ExportService".equals(serviceClass) || "com.atlassian.jira.service.services.file.FileService".equals(serviceClass); } } catch (Exception e) { throw new RuntimeException(e); } return false; }
@Override public void updateRecoverySettings(final ApplicationUser user, final boolean recoveryEnabled, final String cronExpression) throws Exception { JiraServiceContainer service = serviceManager.getServiceWithName(IndexSnapshotService.getServiceName()); if (permissionManager.hasPermission(Permissions.SYSTEM_ADMIN, user)) { if (recoveryEnabled) { if (service == null) { serviceManager.addService(IndexSnapshotService.getServiceName(), IndexSnapshotService.class, cronExpression); } else { serviceManager.editService(service.getId(), cronExpression, Collections.<String, String[]>emptyMap()); } } else { if (service != null) { serviceManager.removeService(service.getId()); } } eventPublisher.publish(new IndexRecoveryEnabledEvent(recoveryEnabled)); } }
Collection<JiraServiceContainer> services = serviceManager.getServices(); serviceManager.removeService(service.getId()); serviceManager.addService(name, "com.atlassian.sal.jira.scheduling.JiraPluginScheduler$JiraPluginSchedulerService", repeatInterval,
ComponentAccessor.getServiceManager().addService(name, clazz, "0 * * * * ?"); ComponentAccessor.getServiceManager().removeService(serviceContainer.getId());
public Collection<JiraServiceContainer> getServices() { return manager.getServices(); }
/** * Creates a new Backup service, or updates an already existing one with the parameters supplied. */ public void createOrUpdateBackupService(final I18nHelper i18n, final String backupPath) { try { final Map<String, String[]> params = new HashMap<String, String[]>(); params.put(ExportService.USE_DEFAULT_DIRECTORY, new String[] { "true" }); final String serviceName = geti18nTextWithDefault(i18n, SERVICE_NAME_KEY, "Backup Service"); if (serviceManager.getServiceWithName(serviceName) == null) { serviceManager.addService(serviceName, ExportService.class.getName(), DELAY, params); } else { serviceManager.editServiceByName(serviceName, DELAY, params); } getApplicationProperties().setString(APKeys.JIRA_PATH_BACKUP, backupPath); } catch (final Exception e) // intentionally catching RuntimeException as well { log.error("Error creating backup service", e); addErrorMessage(getText("admin.errors.setup.error.adding.service", e.toString())); } }
@Override public void doUpgrade(boolean setupMode) throws Exception { serviceManager.addService( beanFactory.getInstance(applicationProperties.getDefaultLocale()).getText("admin.services.auditing.auditlogcleaner.service"), AuditLogCleaningService.class, ONE_DAY_IN_MILLIS); serviceManager.refreshAll(); } }
@Override public boolean isRecoveryEnabled(final ApplicationUser user) { try { return serviceManager.getServiceWithName(IndexSnapshotService.getServiceName()) != null; } catch (Exception e) { return false; } }
public void scheduleJob(final String name, final Class<? extends PluginJob> job, final Map<String, Object> jobDataMap, final Date startTime, final long repeatInterval) { // Create a map to hold the configuration for the job final Map<String, String[]> serviceDataMap = new HashMap<String, String[]>(); serviceDataMap.put(PLUGIN_JOB_NAME, new String[] { name }); // Put a service descriptor in the map final JiraPluginSchedulerServiceDescriptor sd = new JiraPluginSchedulerServiceDescriptor(); sd.setJob(job); sd.setJobDataMap(jobDataMap); serviceMap.put(name, sd); try { // Remove the service if it exists. removeServicesByName(name); serviceManager.addService(name, JiraPluginSchedulerService.class, repeatInterval, serviceDataMap); } catch (final Exception e) { log.error("Error adding service to jira", e); } }
private void repairServiceConfigs() { final Map<Long, String> repairs = getRepairs(); if (repairs.isEmpty()) { return; } repairs.forEach((id, cronExpression) -> Update.into(SERVICE_CONFIG) .set(CRON_EXPRESSION, cronExpression) .whereIdEquals(id) .execute(entityEngine)); serviceManager.refreshAll(); }
@Override protected void doValidation() { if (serviceId > 0) { if (!manager.containsServiceWithId(serviceId)) { addError("serviceId", "No service with this id exists"); } } }
@RequiresXsrfCheck protected String doExecute() throws Exception { if (canEditService(id)) { try { String cronExpression = new CronExpressionGenerator().getCronExpressionFromInput(cronEditorBean); serviceManager.editService(id, cronExpression, primeParamsWithSavedValues(params)); } catch (Exception e) { log.error("Error occurred trying to update service properties: " + e, e); addErrorMessage(getText("admin.errors.error.occured.trying.to.update.service.properties", e)); } if (getHasErrorMessages()) { return ERROR; } else { return getRedirect("ViewServices!default.jspa"); } } else { return "securitybreach"; } }
public Collection<Message> doUpgrade() throws Exception { JiraServiceContainer dailyBackupsService; while ((dailyBackupsService = serviceManager.getServiceWithName(DAILY_BACKUPS))!=null) { log.info("Removing " + dailyBackupsService.getName()); serviceManager.removeService(dailyBackupsService.getId()); } return null; }
serviceManager.removeService(delete); return getRedirect("ViewServices!default.jspa"); JiraServiceContainer serviceContainer = serviceManager.addService(getName(), getClazz(), cronExpression, delay, null); return getRedirect("EditService!default.jspa?id=" + serviceContainer.getId());
public Collection<JiraServiceContainer> getServices() { final Collection<JiraServiceContainer> services = new TreeSet<>(JiraService.NAME_COMPARATOR); services.addAll(serviceManager.getServices()); return services; }
@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; } } }