コード例 #1
0
  @SuppressWarnings("unchecked")
  public List<RayoNode> getRayoNodesForPlatform(String platformId) {

    try {
      log.debug("Finding rayo nodes for platform: [%s]", platformId);
      Set<String> platforms = new HashSet<String>();
      platforms.add(platformId);

      List<RayoNode> nodes = new ArrayList<RayoNode>();
      Selector selector = Pelops.createSelector(schemaName);
      List<SuperColumn> columns =
          selector.getSuperColumnsFromRow("nodes", platformId, false, ConsistencyLevel.ONE);
      for (SuperColumn column : columns) {
        String id = Bytes.toUTF8(column.getName());
        RayoNode rayoNode = buildNode(column.getColumns());
        rayoNode.setHostname(id);
        rayoNode.setPlatforms(platforms);
        nodes.add(rayoNode);
      }

      return nodes;
    } catch (PelopsException pe) {
      log.error(pe.getMessage(), pe);
      return Collections.EMPTY_LIST;
    }
  }
コード例 #2
0
  @Override
  public RayoNode getNode(String rayoNode) {

    log.debug("Getting node with id: [%s]", rayoNode);
    RayoNode node = null;
    try {
      Selector selector = Pelops.createSelector(schemaName);
      Map<String, List<SuperColumn>> rows =
          selector.getSuperColumnsFromRowsUtf8Keys(
              "nodes",
              Selector.newKeyRange("", "", 100), // 100 platforms limit should be enough :)
              Selector.newColumnsPredicate(rayoNode),
              ConsistencyLevel.ONE);

      Iterator<Entry<String, List<SuperColumn>>> it = rows.entrySet().iterator();
      while (it.hasNext()) {
        Entry<String, List<SuperColumn>> element = it.next();
        String currPlatform = element.getKey();
        List<SuperColumn> platformOccurrences = element.getValue();
        for (SuperColumn column : platformOccurrences) {
          if (node == null) {
            node = new RayoNode();
            node = buildNode(column.getColumns());
            node.setHostname(rayoNode);
          }
          node.addPlatform(currPlatform);
        }
      }
    } catch (PelopsException pe) {
      log.error(pe.getMessage(), pe);
      return null;
    }
    return node;
  }
コード例 #3
0
  @Override
  public RayoNode removeNode(String rayoNode) throws DatastoreException {

    log.debug("Removing node: [%s]", rayoNode);
    RayoNode node = getNode(rayoNode);
    if (node == null) {
      log.error("Node not found: [%s]", rayoNode);
      throw new RayoNodeNotFoundException();
    }
    RowDeletor deletor = Pelops.createRowDeletor(schemaName);
    deletor.deleteRow("ips", node.getIpAddress(), ConsistencyLevel.ONE);

    Mutator mutator = Pelops.createMutator(schemaName);
    for (String platform : node.getPlatforms()) {
      mutator.deleteColumn("nodes", platform, rayoNode);
    }

    try {
      mutator.execute(ConsistencyLevel.ONE);
      log.debug("Node [%s] deleted successfully", rayoNode);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new DatastoreException("Could not remove node");
    }

    return node;
  }
コード例 #4
0
  private RayoNode store(RayoNode node) throws DatastoreException {

    Mutator mutator = Pelops.createMutator(schemaName);
    for (String platform : node.getPlatforms()) {
      mutator.writeSubColumns(
          "nodes",
          platform,
          node.getHostname(),
          mutator.newColumnList(
              mutator.newColumn("priority", String.valueOf(node.getPriority())),
              mutator.newColumn("weight", String.valueOf(node.getWeight())),
              mutator.newColumn("ip", node.getIpAddress()),
              mutator.newColumn("consecutive-errors", String.valueOf(node.getConsecutiveErrors())),
              mutator.newColumn("blacklisted", String.valueOf(node.isBlackListed()))));
    }

    mutator.writeColumn(
        "ips",
        Bytes.fromUTF8(node.getIpAddress()),
        mutator.newColumn(Bytes.fromUTF8("node"), Bytes.fromUTF8(node.getHostname())));

    try {
      mutator.execute(ConsistencyLevel.ONE);
      log.debug("Node [%s] stored successfully", node);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new DatastoreException(String.format("Could not create node [%s]", node));
    }
    return node;
  }
コード例 #5
0
  private RayoNode buildNode(List<Column> columns) {

    if (columns != null && columns.size() > 0) {
      RayoNode node = new RayoNode();
      for (Column column : columns) {
        String name = Bytes.toUTF8(column.getName());
        if (name.equals("ip")) {
          node.setIpAddress(Bytes.toUTF8(column.getValue()));
        }
        if (name.equals("weight")) {
          node.setWeight(Integer.parseInt(Bytes.toUTF8(column.getValue())));
        }
        if (name.equals("priority")) {
          node.setPriority(Integer.parseInt(Bytes.toUTF8(column.getValue())));
        }
        if (name.equals("consecutive-errors")) {
          node.setConsecutiveErrors(Integer.parseInt(Bytes.toUTF8(column.getValue())));
        }
        if (name.equals("blacklisted")) {
          node.setBlackListed(Boolean.valueOf(Bytes.toUTF8(column.getValue())));
        }
        if (name.equals("platforms")) {
          node.setPlatforms(
              new HashSet<String>(
                  Arrays.asList(StringUtils.split(Bytes.toUTF8(column.getValue()), ","))));
        }
      }
      return node;
    }
    return null;
  }
コード例 #6
0
  @Override
  public RayoNode storeNode(RayoNode node) throws DatastoreException {

    log.debug("Storing node: [%s]", node);

    RayoNode stored = getNode(node.getHostname());
    if (stored != null) {
      log.error("Node [%s] already exists", node);
      throw new RayoNodeAlreadyExistsException();
    }
    return store(node);
  }
コード例 #7
0
  public RayoNode updateNode(RayoNode node) throws DatastoreException {

    log.debug("Updating node: [%s]", node);

    RayoNode stored = getNode(node.getHostname());
    if (stored == null) {
      log.error("Node [%s] does not exist", node);
      throw new RayoNodeNotFoundException();
    }

    return store(node);
  }