Esempio n. 1
0
  @Test
  public void testSlaveToMaster() throws Exception {
    _clusterSchedulerEngine = _getClusterSchedulerEngine(false, 2, 0);

    Assert.assertFalse(_isMaster(_clusterSchedulerEngine));

    Map<String, SchedulerResponse> schedulerResponseMap =
        _getMemoryClusteredJobs(_clusterSchedulerEngine);

    Assert.assertEquals(2, schedulerResponseMap.size());

    String newMaster =
        AddressSerializerUtil.serialize(ClusterExecutorUtil.getLocalClusterNodeAddress());

    MockLockLocalService.setLock(newMaster);

    Assert.assertTrue(_isMaster(_clusterSchedulerEngine));

    _clusterSchedulerEngine.pause(_TEST_JOB_NAME_0, _MEMORY_CLUSTER_TEST_GROUP_NAME);

    _clusterSchedulerEngine.getScheduledJobs();

    schedulerResponseMap = _getMemoryClusteredJobs(_clusterSchedulerEngine);

    Assert.assertTrue(schedulerResponseMap.isEmpty());
  }
Esempio n. 2
0
  private ClusterSchedulerEngine _getClusterSchedulerEngine(
      boolean master, int memoryClusterJobs, int persistentJobs) throws Exception {

    MockSchedulerEngine mockSchedulerEngine =
        new MockSchedulerEngine(memoryClusterJobs, persistentJobs);

    MockClusterExecutor mockClusterExecutor = new MockClusterExecutor(true, mockSchedulerEngine);

    ClusterExecutorUtil clusterExecutorUtil = new ClusterExecutorUtil();

    clusterExecutorUtil.setClusterExecutor(mockClusterExecutor);

    ClusterSchedulerEngine clusterSchedulerEngine = new ClusterSchedulerEngine(mockSchedulerEngine);

    Address masterAddress = null;

    if (master) {
      masterAddress = ClusterExecutorUtil.getLocalClusterNodeAddress();
    } else {
      masterAddress = MockClusterExecutor._anotherAddress;
    }

    MockLockLocalService.setLock(AddressSerializerUtil.serialize(masterAddress));

    SchedulerEngineHelperImpl schedulerEngineHelperImpl = new SchedulerEngineHelperImpl();

    schedulerEngineHelperImpl.setSchedulerEngine(clusterSchedulerEngine);

    SchedulerEngineHelperUtil schedulerEngineHelperUtil = new SchedulerEngineHelperUtil();

    schedulerEngineHelperUtil.setSchedulerEngineHelper(schedulerEngineHelperImpl);

    clusterSchedulerEngine.initialize();

    clusterSchedulerEngine.start();

    return clusterSchedulerEngine;
  }
    public void run() {
      _countDownLatch.countDown();

      String logPrefix = StringPool.BLANK;

      if (_log.isInfoEnabled()) {
        Thread currentThread = Thread.currentThread();

        if (_master) {
          logPrefix =
              "Monitor thread name "
                  + currentThread.getName()
                  + " with thread ID "
                  + currentThread.getId();
        } else {
          logPrefix =
              "Thread name " + currentThread.getName() + " with thread ID " + currentThread.getId();
        }
      }

      if (!_master && _log.isInfoEnabled()) {
        _log.info(logPrefix + " synchronized on latch. Waiting for others.");
      }

      try {
        if (_master) {
          _countDownLatch.await();
        } else {
          boolean result =
              _countDownLatch.await(
                  PropsValues.LUCENE_CLUSTER_INDEX_LOADING_SYNC_TIMEOUT, TimeUnit.MILLISECONDS);

          if (!result) {
            _log.error(
                logPrefix + " timed out. You may need to " + "re-trigger a reindex process.");
          }
        }
      } catch (InterruptedException ie) {
        if (_master) {
          _log.error(
              logPrefix + " was interrupted. Skip cluster index " + "loading notification.", ie);

          return;
        } else {
          _log.error(
              logPrefix + " was interrupted. You may need to " + "re-trigger a reindex process.",
              ie);
        }
      }

      if (_master) {
        Address localClusterNodeAddress = ClusterExecutorUtil.getLocalClusterNodeAddress();

        ClusterRequest clusterRequest =
            ClusterRequest.createMulticastRequest(
                new MethodHandler(
                    _loadIndexesFromClusterMethodKey, _companyIds, localClusterNodeAddress),
                true);

        try {
          ClusterExecutorUtil.execute(clusterRequest);
        } catch (SystemException se) {
          _log.error("Unable to notify peers to start index loading", se);
        }

        if (_log.isInfoEnabled()) {
          _log.info(logPrefix + " unlocked latch. Notified peers to " + "start index loading.");
        }
      }
    }