Пример #1
0
  private void doHealthChecks() {
    if (status != STATUS.OPEN) {
      return;
    }

    LOGGER.trace("beginning health check process");
    final List<HealthRecord> newResults = new ArrayList<>();
    for (final HealthChecker loopChecker : healthCheckers) {
      try {
        final List<HealthRecord> loopResults = loopChecker.doHealthCheck(pwmApplication);
        if (loopResults != null) {
          newResults.addAll(loopResults);
        }
      } catch (Exception e) {
        LOGGER.warn("unexpected error during healthCheck: " + e.getMessage(), e);
      }
    }
    for (final PwmService service : pwmApplication.getPwmServices()) {
      try {
        final List<HealthRecord> loopResults = service.healthCheck();
        if (loopResults != null) {
          newResults.addAll(loopResults);
        }
      } catch (Exception e) {
        LOGGER.warn("unexpected error during healthCheck: " + e.getMessage(), e);
      }
    }
    final Set<HealthRecord> sortedRecordList = new TreeSet<>();
    sortedRecordList.addAll(newResults);
    healthRecords = Collections.unmodifiableSet(sortedRecordList);
    lastHealthCheckDate = new Date();
    LOGGER.trace("health check process completed");
  }
  @Override
  public synchronized Map<Integer, Set<Integer>> distributeBlocks(String namespace, int numBlocks)
      throws RemoteException {
    Map<Integer, Set<Integer>> blocksToNodes = new HashMap<Integer, Set<Integer>>();
    for (int i = 0; i < numBlocks; i++) {
      for (int j = 0; j < getConfig().getReplicationFactor(); j++) {
        while (!healthChecker.isHealthy(currentNode)) {
          incrementCurrentNode();
        }
        Set<Integer> nodes = blocksToNodes.get(i);
        if (nodes == null) {
          nodes = new HashSet<Integer>();
          blocksToNodes.put(i, nodes);
        }
        nodes.add(currentNode);
        incrementCurrentNode();
      }
    }

    return blocksToNodes;
  }
  public FacilityManagerMasterImpl(Config config)
      throws IOException, AlreadyBoundException, InterruptedException {
    super(config);

    currentNode = 0;
    String[] participants = config.getParticipantIps();
    int expectedNumParticipants = participants.length;

    managers = new FacilityManager[expectedNumParticipants];
    managers[getNodeId()] = this;

    clusterName = config.getClusterName();
    rmiPort = config.getRmiPort();

    /* FILESYSTEM INIT */
    fsTable = Collections.synchronizedMap(new HashMap<String, Map<Integer, Set<Integer>>>());

    Registry r = LocateRegistry.createRegistry(rmiPort);
    r.bind(clusterName + REGISTRY_MASTER_KEY, UnicastRemoteObject.exportObject(this, 0));
    connectParticipants();

    System.out.println("Waiting for slaves to connect...");
    while (managers.length != expectedNumParticipants) {
      Thread.sleep(1000);
    }

    healthChecker = new HealthChecker(this, expectedNumParticipants);
    scheduler = new JobScheduler(this, config);
    dispatcher = new JobDispatcher(this, config);
    dispatcher.setScheduler(scheduler);
    scheduler.setDispatcher(dispatcher);
    scheduler.setHealthChecker(healthChecker);

    healthChecker.start();
    dispatcher.start();

    System.out.println("All slaves connected.");
  }