Esempio n. 1
0
 public void initialize() throws TaskSystemException {
   try {
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = factory.newDocumentBuilder();
     Document document = builder.parse(getTaskConfigurationInputSource());
     NodeList rootElement =
         document.getElementsByTagName(SchedulerConstants.SPRING_BEANS_FILE_ROOT_TAG);
     if (rootElement.getLength() > 0) { // new Quartz scheduler
       springTaskContext =
           new FileSystemXmlApplicationContext("file:" + getTaskConfigurationFilePath());
       scheduler =
           (Scheduler) springTaskContext.getBean(SchedulerConstants.SPRING_SCHEDULER_BEAN_NAME);
       jobExplorer =
           (JobExplorer) springTaskContext.getBean(SchedulerConstants.JOB_EXPLORER_BEAN_NAME);
       jobRepository =
           (JobRepository) springTaskContext.getBean(SchedulerConstants.JOB_REPOSITORY_BEAN_NAME);
       jobLauncher =
           (JobLauncher) springTaskContext.getBean(SchedulerConstants.JOB_LAUNCHER_BEAN_NAME);
       jobLocator =
           (JobLocator) springTaskContext.getBean(SchedulerConstants.JOB_LOCATOR_BEAN_NAME);
     } else { // old legacy Mifos Scheduler
       StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
       String configPath = getQuartzSchedulerConfigurationFilePath();
       schedulerFactory.initialize(configPath);
       scheduler = schedulerFactory.getScheduler();
       if (!scheduler.isInStandbyMode()) {
         scheduler.standby();
       }
       registerTasksOldConfigurationFile(document);
       scheduler.start();
     }
   } catch (Exception e) {
     throw new TaskSystemException(e);
   }
 }
Esempio n. 2
0
  public boolean stop() {
    try {
      if (scheduler != null && scheduler.isStarted()) {

        // This is to immediately stop the scheduler to avoid firing new services
        scheduler.standby();

        if (logger.isDebugEnabled()) {
          logger.debug("ShuttingDown Message Processor Scheduler : " + scheduler.getMetaData());
        }

        try {
          scheduler.interrupt(
              new JobKey(
                  name + "-job", MessageProcessorConstants.SCHEDULED_MESSAGE_PROCESSOR_GROUP));
        } catch (UnableToInterruptJobException e) {
          logger.info("Unable to interrupt job [" + name + "-job]");
        }

        // gracefully shutdown
        scheduler.shutdown(true);
      }

    } catch (SchedulerException e) {
      throw new SynapseException("Error ShuttingDown Message processor scheduler ", e);
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Stopped message processor [" + getName() + "].");
    }

    return true;
  }
Esempio n. 3
0
  public boolean deactivate() {
    try {
      if (scheduler != null && scheduler.isStarted()) {
        if (logger.isDebugEnabled()) {
          logger.debug("Deactivating message processor [" + getName() + "]");
        }

        // This is to immediately stop the scheduler to avoid firing new services
        scheduler.standby();

        try {
          scheduler.interrupt(
              new JobKey(
                  name + "-job", MessageProcessorConstants.SCHEDULED_MESSAGE_PROCESSOR_GROUP));
        } catch (UnableToInterruptJobException e) {
          logger.info("Unable to interrupt job [" + name + "-job]");
        }

        // This is to remove the consumer from the queue.
        messageConsumer.cleanup();

        if (logger.isDebugEnabled()) {
          logger.debug("Successfully deactivated the message processor [" + getName() + "]");
        }

        setActivated(isActive());

        // This means the deactivation has happened automatically. So we have to persist the
        // deactivation manually.
        if (isPaused()) {
          try {
            // TODO: Need to make sure if this is the best way.
            String directory = configuration.getPathToConfigFile() + "/message-processors";
            DeploymentEngine deploymentEngine =
                (DeploymentEngine) configuration.getAxisConfiguration().getConfigurator();
            MessageProcessorDeployer dep =
                (MessageProcessorDeployer) deploymentEngine.getDeployer(directory, "xml");
            dep.restoreSynapseArtifact(name);
          } catch (Exception e) {
            logger.warn("Couldn't persist the state of the message processor [" + name + "]");
          }
        }

        return true;
      } else {
        return false;
      }
    } catch (SchedulerException e) {
      throw new SynapseException("Error Standing-by Message processor scheduler ", e);
    }
  }
  @Test
  public void testExecuteQuickImport() throws Exception {
    expect(mockBarrier.await(20, TimeUnit.SECONDS)).andReturn(true);

    expect(mockBeanFactory.getInstance(currentUser)).andReturn(new MockI18nHelper()).anyTimes();
    // called during validation!
    expect(mockPermissionManager.hasPermission(Permissions.SYSTEM_ADMIN, currentUser))
        .andReturn(true);

    // This is called during the first parse of the XML file.  At this stage nothing should have
    // been created yet!
    final MockGenericValue mockGv = new MockGenericValue("someentity");
    expect(mockOfBizDelegator.makeValue(EasyMock.<String>anyObject())).andReturn(mockGv).anyTimes();
    expect(mockAttachmentPathManager.getDefaultAttachmentPath())
        .andReturn(directories.get(0).getAbsolutePath())
        .anyTimes();
    expect(mockIndexPathManager.getDefaultIndexRootPath())
        .andReturn(directories.get(1).getAbsolutePath())
        .anyTimes();
    expect(
            mockLicenseStringFactory.create(
                EasyMock.<String>anyObject(), EasyMock.<String>anyObject()))
        .andStubReturn("");

    // after the first parse check the build number.
    expect(mockBuildUtilsInfo.getCurrentBuildNumber()).andStubReturn("99999999");
    expect(mockBuildUtilsInfo.getMinimumUpgradableBuildNumber()).andStubReturn("0");

    // after the first parse we also verify the license is good.
    expect(
            mockJiraLicenseService.validate(
                EasyMock.<I18nHelper>anyObject(), EasyMock.<String>anyObject()))
        .andStubReturn(mockValidationResult);
    expect(mockValidationResult.getLicenseVersion()).andStubReturn(2);
    expect(mockValidationResult.getErrorCollection()).andStubReturn(new SimpleErrorCollection());

    // this gets called during shutdownAndFlushAsyncServices.  After parse and before the import.
    // This shuts down
    // the scheduler
    mockScheduler.standby();
    expect(mockScheduler.getJobGroupNames()).andReturn(new String[] {"group1"});
    expect(mockScheduler.getJobNames("group1")).andReturn(new String[] {"job1", "job2"});
    expect(mockScheduler.deleteJob("job1", "group1")).andReturn(true);
    expect(mockScheduler.deleteJob("job2", "group1")).andReturn(true);
    mockMailQueue.sendBuffer();
    expect(mockTaskManager.awaitUntilActiveTasksComplete(20)).andReturn(true);

    // Expect AO to be cleared.
    backup.clear();

    // Once the import is running one of the first things to do is to clear out the old database
    // values.
    expect(mockOfBizDelegator.getModelReader()).andReturn(mockModelReader);
    expect(mockModelReader.getEntityNames())
        .andReturn(CollectionBuilder.<String>list("Issue", "User"));
    expect(mockModelReader.getModelEntity("Issue")).andReturn(new ModelEntity());
    expect(mockOfBizDelegator.removeByAnd("Issue", Collections.<String, Object>emptyMap()))
        .andReturn(10);
    expect(mockModelReader.getModelEntity("User")).andReturn(new ModelEntity());
    expect(mockOfBizDelegator.removeByAnd("User", Collections.<String, Object>emptyMap()))
        .andReturn(5);

    // then we go through and create all our GVs (already mocked out during the first parse above)

    // once everything's been imported need to refresh the ofbiz sequencer and check for data
    // consistency.
    mockOfBizDelegator.refreshSequencer();
    mockConsistencyChecker.checkDataConsistency();

    // after the consistency check lets do the upgrade
    expect(mockUpgradeManager.doUpgradeIfNeededAndAllowed(null))
        .andReturn(Collections.<String>emptyList());

    // now do a reindex
    mockIndexManager.deactivate();
    expect(mockIndexManager.size()).andReturn(5);
    expect(mockIndexManager.activate((Context) notNull())).andReturn(1L);

    // raise the JiraStartedEvent
    mockPluginEventManager.broadcast(EasyMock.<JiraStartedEvent>anyObject());

    // finally we can restart the scheduler!
    expect(
            mockScheduler.scheduleJob(
                EasyMock.<JobDetail>anyObject(), EasyMock.<Trigger>anyObject()))
        .andReturn(new Date())
        .anyTimes();
    mockScheduler.start();

    final String filePath = getDataFilePath("jira-export-test.xml");
    final DataImportParams params =
        new DataImportParams.Builder(filePath).setQuickImport(true).build();

    // Finally everything's mocked out.  Run the import!
    executeTest(params, true, DataImportService.ImportError.NONE);

    // create() should have been called on our GVs
    assertTrue(mockGv.isCreated());
    // the world should have been rebuilt!
    assertTrue(((MockDataImportDependencies) mockDependencies).globalRefreshCalled);
  }