예제 #1
0
 /**
  * Cancel grant on a node
  *
  * @param nodeName the node the grant is on
  * @param sessionId the session the grant was given to
  * @param requestId the request this grant satisfied
  */
 public void cancelGrant(String nodeName, String sessionId, int requestId) {
   ClusterNode node = nameToNode.get(nodeName);
   if (node == null) {
     LOG.warn("Canceling grant for non-existent node: " + nodeName);
     return;
   }
   synchronized (node) {
     if (node.deleted) {
       LOG.warn("Canceling grant for deleted node: " + nodeName);
       return;
     }
     String hoststr = node.getClusterNodeInfo().getAddress().getHost();
     if (!canAllowNode(hoststr)) {
       LOG.warn("Canceling grant for excluded node: " + hoststr);
       return;
     }
     ResourceRequestInfo req = node.getRequestForGrant(sessionId, requestId);
     if (req != null) {
       ResourceRequest unitReq = Utilities.getUnitResourceRequest(req.getType());
       boolean previouslyRunnable = node.checkForGrant(unitReq, resourceLimit);
       node.cancelGrant(sessionId, requestId);
       loadManager.decrementLoad(req.getType());
       if (!previouslyRunnable && node.checkForGrant(unitReq, resourceLimit)) {
         RunnableIndices r = typeToIndices.get(req.getType());
         if (!faultManager.isBlacklisted(node.getName(), req.getType())) {
           r.addRunnable(node);
         }
       }
     }
   }
 }
예제 #2
0
  /**
   * Add a grant to a node
   *
   * @param node the node the grant is on
   * @param sessionId the session the grant is given to
   * @param req the request this grant satisfies
   * @return true if the grant can be added to the node, false otherwise
   */
  public boolean addGrant(ClusterNode node, String sessionId, ResourceRequestInfo req) {
    synchronized (node) {
      if (node.deleted) {
        return false;
      }
      if (!node.checkForGrant(Utilities.getUnitResourceRequest(req.getType()), resourceLimit)) {
        return false;
      }

      node.addGrant(sessionId, req);
      loadManager.incrementLoad(req.getType());
      hostsToSessions.get(node).add(sessionId);
      if (!node.checkForGrant(Utilities.getUnitResourceRequest(req.getType()), resourceLimit)) {
        RunnableIndices r = typeToIndices.get(req.getType());
        r.deleteRunnable(node);
      }
    }
    return true;
  }
예제 #3
0
  /**
   * Register a new application on the node
   *
   * @param node the node to register on
   * @param type the type of an application
   * @param appInfo the appInfo string for the application
   */
  protected void addAppToNode(ClusterNode node, ResourceType type, String appInfo) {
    synchronized (node) {
      // Update primary index.
      Map<ResourceType, String> apps = nameToApps.get(node.getName());
      apps.put(type, appInfo);

      // Update runnable indices.
      for (Map.Entry<ResourceType, RunnableIndices> entry : typeToIndices.entrySet()) {
        if (type.equals(entry.getKey())) {
          if (node.checkForGrant(Utilities.getUnitResourceRequest(type), resourceLimit)) {
            RunnableIndices r = entry.getValue();
            r.addRunnable(node);
          }
        }
      }
    }
  }
예제 #4
0
 /**
  * Update the runnable status of a node based on resources available. This checks both resources
  * and slot availability.
  *
  * @param node The node
  */
 private void updateRunnability(ClusterNode node) {
   synchronized (node) {
     for (Map.Entry<ResourceType, RunnableIndices> entry : typeToIndices.entrySet()) {
       ResourceType type = entry.getKey();
       RunnableIndices r = entry.getValue();
       ResourceRequest unitReq = Utilities.getUnitResourceRequest(type);
       boolean currentlyRunnable = r.hasRunnable(node);
       boolean shouldBeRunnable = node.checkForGrant(unitReq, resourceLimit);
       if (currentlyRunnable && !shouldBeRunnable) {
         LOG.info("Node " + node.getName() + " is no longer " + type + " runnable");
         r.deleteRunnable(node);
       } else if (!currentlyRunnable && shouldBeRunnable) {
         LOG.info("Node " + node.getName() + " is now " + type + " runnable");
         r.addRunnable(node);
       }
     }
   }
 }
예제 #5
0
  /**
   * Add a node to be managed.
   *
   * @param node Node to be managed
   * @param resourceInfos Mapping of the resource type to runnable indices
   */
  protected void addNode(ClusterNode node, Map<ResourceType, String> resourceInfos) {
    synchronized (node) {
      // 1: primary
      nameToNode.put(node.getName(), node);
      faultManager.addNode(node.getName(), resourceInfos.keySet());
      nameToApps.put(node.getName(), resourceInfos);
      hostsToSessions.put(node, new HashSet<String>());
      setAliveDeadMetrics();

      // 2: update runnable indices
      for (Map.Entry<ResourceType, RunnableIndices> entry : typeToIndices.entrySet()) {
        ResourceType type = entry.getKey();
        if (resourceInfos.containsKey(type)) {
          if (node.checkForGrant(Utilities.getUnitResourceRequest(type), resourceLimit)) {
            RunnableIndices r = entry.getValue();
            r.addRunnable(node);
          }
        }
      }
    }
  }