Пример #1
0
 /** Update metrics for alive/dead nodes. */
 private void setAliveDeadMetrics() {
   clusterManager.getMetrics().setAliveNodes(nameToNode.size());
   int totalHosts = hostsReader.getHosts().size();
   if (totalHosts > 0) {
     clusterManager.getMetrics().setDeadNodes(totalHosts - nameToNode.size());
   }
 }
Пример #2
0
 public synchronized ClusterRuntime clusterStatus(String clusterName) throws KaramelException {
   String name = clusterName.toLowerCase();
   if (!repository.containsKey(name)) {
     throw new KaramelException(
         String.format("Repository doesn't contain a cluster name '%s'", clusterName));
   }
   ClusterManager cluster = repository.get(name);
   return cluster.getRuntime();
 }
Пример #3
0
 public synchronized void resumeCluster(String clusterName) throws KaramelException {
   String name = clusterName.toLowerCase();
   logger.info(String.format("User asked for resuming the cluster '%s'", clusterName));
   if (!repository.containsKey(name)) {
     throw new KaramelException(
         String.format("Repository doesn't contain a cluster name '%s'", clusterName));
   }
   ClusterManager cluster = repository.get(name);
   checkContext(cluster.getDefinition());
   cluster.enqueue(ClusterManager.Command.RESUME);
 }
Пример #4
0
  /* (non-Javadoc)
   * @see java.lang.Runnable#run()
   */
  @Override
  public void run() {

    ICluster cluster = ClusterManager.getCluster();

    while (true) {

      try {
        Thread.sleep(3000); // wait 3 sec.
      } catch (InterruptedException e) {
      }

      try {
        ITestClusterService service =
            (ITestClusterService) cluster.getClusterService(ITestClusterService.SERVICE_NAME);
        if (service == null) {
          System.err.println("ERROR: service is null");
        } else {

          long nextNumber = service.takeNextNumber();
          // System.out.println("Next Number is: " + nextNumber);

          cluster.sendEvent(
              new ClusterEvent("TestNumberSequence", "NumberToken", new Long(nextNumber)), true);
          StartTestInstance.addNumber(nextNumber);
        }

      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
  }
 /**
  * Add the node connection to the node connection map
  *
  * @param nodeId the node ID for the channel
  * @param channel the new channel
  */
 protected void nodeConnected(short nodeId, Channel channel) {
   logger.debug("[{}->{}] Connection established", syncManager.getLocalNodeId(), nodeId);
   synchronized (connections) {
     NodeConnection c = connections.get(nodeId);
     if (c == null) {
       connections.put(nodeId, c = new NodeConnection());
     }
     c.nodeChannel = channel;
     c.state = NodeConnectionState.CONNECTED;
   }
   clusterManager.connectionStateChange();
 }
Пример #6
0
 public synchronized void startCluster(String json) throws KaramelException {
   Gson gson = new Gson();
   JsonCluster jsonCluster = gson.fromJson(json, JsonCluster.class);
   ClusterDefinitionValidator.validate(jsonCluster);
   String yml = ClusterDefinitionService.jsonToYaml(jsonCluster);
   // We have to do it again otherwise the global scope attributes get lost
   // for more info refer to https://github.com/karamelchef/karamel/issues/28
   jsonCluster = ClusterDefinitionService.yamlToJsonObject(yml);
   ClusterDefinitionService.saveYaml(yml);
   logger.info(String.format("Let me see if I can start '%s' ...", jsonCluster.getName()));
   String clusterName = jsonCluster.getName();
   String name = clusterName.toLowerCase();
   if (repository.containsKey(name)) {
     logger.info(String.format("'%s' is already running :-|", jsonCluster.getName()));
     throw new KaramelException(String.format("Cluster '%s' is already running", clusterName));
   }
   ClusterContext checkedContext = checkContext(jsonCluster);
   ClusterManager cluster = new ClusterManager(jsonCluster, checkedContext);
   repository.put(name, cluster);
   cluster.start();
   cluster.enqueue(ClusterManager.Command.LAUNCH);
 }
  /**
   * Remove the connection from the connection registry and clean up any remaining shrapnel
   *
   * @param nodeId
   */
  public void disconnectNode(short nodeId) {
    synchronized (connections) {
      Short n = Short.valueOf(nodeId);
      MessageWindow mw = messageWindows.get(n);
      if (mw != null) {
        mw.lock.lock();
        mw.disconnected = true;
        try {
          mw.full.signalAll();
          messageWindows.remove(n);
        } finally {
          mw.lock.unlock();
        }
      }

      NodeConnection nc = connections.get(nodeId);
      if (nc != null) {
        nc.nuke();
      }
      connections.remove(nodeId);
    }
    clusterManager.connectionStateChange();
  }
Пример #8
0
  /**
   * return true if a new node has been added - else return false
   *
   * @param clusterNodeInfo the node that is heartbeating
   * @return true if this is a new node that has been added, false otherwise
   */
  public boolean heartbeat(ClusterNodeInfo clusterNodeInfo) throws DisallowedNode {
    ClusterNode node = nameToNode.get(clusterNodeInfo.name);
    if (!canAllowNode(clusterNodeInfo.getAddress().getHost())) {
      if (node != null) {
        node.heartbeat(clusterNodeInfo);
      } else {
        throw new DisallowedNode(clusterNodeInfo.getAddress().getHost());
      }
      return false;
    }
    boolean newNode = false;
    Map<ResourceType, String> currentResources = clusterNodeInfo.getResourceInfos();
    if (currentResources == null) {
      currentResources = new EnumMap<ResourceType, String>(ResourceType.class);
    }

    if (node == null) {
      LOG.info("Adding node with heartbeat: " + clusterNodeInfo.toString());
      node =
          new ClusterNode(
              clusterNodeInfo,
              topologyCache.getNode(clusterNodeInfo.address.host),
              cpuToResourcePartitioning);
      addNode(node, currentResources);
      newNode = true;
    }

    node.heartbeat(clusterNodeInfo);

    boolean appsChanged = false;
    Map<ResourceType, String> prevResources = nameToApps.get(clusterNodeInfo.name);
    Set<ResourceType> deletedApps = null;
    for (Map.Entry<ResourceType, String> entry : prevResources.entrySet()) {
      String newAppInfo = currentResources.get(entry.getKey());
      String oldAppInfo = entry.getValue();
      if (newAppInfo == null || !newAppInfo.equals(oldAppInfo)) {
        if (deletedApps == null) {
          deletedApps = EnumSet.noneOf(ResourceType.class);
        }
        deletedApps.add(entry.getKey());
        appsChanged = true;
      }
    }
    Map<ResourceType, String> addedApps = null;
    for (Map.Entry<ResourceType, String> entry : currentResources.entrySet()) {
      String newAppInfo = entry.getValue();
      String oldAppInfo = prevResources.get(entry.getKey());
      if (oldAppInfo == null || !oldAppInfo.equals(newAppInfo)) {
        if (addedApps == null) {
          addedApps = new EnumMap<ResourceType, String>(ResourceType.class);
        }
        addedApps.put(entry.getKey(), entry.getValue());
        appsChanged = true;
      }
    }
    if (deletedApps != null) {
      for (ResourceType deleted : deletedApps) {
        clusterManager.nodeAppRemoved(clusterNodeInfo.name, deleted);
      }
    }
    if (addedApps != null) {
      for (Map.Entry<ResourceType, String> added : addedApps.entrySet()) {
        addAppToNode(node, added.getKey(), added.getValue());
      }
    }

    updateRunnability(node);
    return newNode || appsChanged;
  }
Пример #9
0
 /**
  * Blacklist a resource on a node.
  *
  * @param nodeName The node name
  * @param resourceType The resource type.
  */
 void blacklistNode(String nodeName, ResourceType resourceType) {
   LOG.info("Node " + nodeName + " has been blacklisted for resource " + resourceType);
   clusterManager.getMetrics().setBlacklistedNodes(faultManager.getBlacklistedNodeCount());
   deleteAppFromNode(nodeName, resourceType);
 }
 @Override
 public Void execute(ClusterManager context) throws Exception {
   context.advertiseAll();
   return null;
 }
Пример #11
0
 @Override
 public void resume(ServiceType service, String hostname, int port) throws IOException {
   hBaseClusterManager.resume(service, hostname, port);
 }