コード例 #1
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;
  }
コード例 #2
0
  @SuppressWarnings("unchecked")
  @Override
  public List<GatewayVerb> getVerbs() {

    log.debug("Getting list with all active verb");
    try {

      List<GatewayVerb> verbs = new ArrayList<GatewayVerb>();
      Selector selector = Pelops.createSelector(schemaName);
      LinkedHashMap<Bytes, List<Column>> rows =
          selector.getColumnsFromRows(
              "verbs",
              Selector.newKeyRange("", "", 10000), // 10000 mixers limit,
              false,
              ConsistencyLevel.ONE);

      for (Map.Entry<Bytes, List<Column>> row : rows.entrySet()) {
        if (row.getValue().size() > 0) {
          for (Column column : row.getValue()) {
            GatewayVerb verb =
                new GatewayVerb(
                    row.getKey().toUTF8(),
                    Bytes.toUTF8(column.getName()),
                    Bytes.toUTF8(column.getValue()));
            verbs.add(verb);
          }
        }
      }

      return verbs;
    } catch (PelopsException pe) {
      log.error(pe.getMessage(), pe);
      return Collections.EMPTY_LIST;
    }
  }
コード例 #3
0
 public List<NotificationEntry> getNotifications(String username, String startId) {
   try {
     byte[] timeUUIDAsBytes = EMPTY_BYTE_ARRAY;
     if (startId != null && startId.length() > 0) {
       UUID uuid = UUIDUtil.fromString(startId);
       final byte[] idAsBytes = UUIDUtil.toBytes(uuid);
       timeUUIDAsBytes = getTimeUUIDFromID(username, idAsBytes);
       if (timeUUIDAsBytes == null) {
         timeUUIDAsBytes = EMPTY_BYTE_ARRAY;
       }
     }
     Selector selector = Pelops.createSelector(TRENDOCEAN_POOL, TRENDOCEAN_KEYSPACE);
     SlicePredicate columnPredicate =
         Selector.newColumnsPredicate(timeUUIDAsBytes, EMPTY_BYTE_ARRAY, true, PAGE_SIZE);
     List<SuperColumn> columns =
         selector.getSuperColumnsFromRow(username, WALL_CF, columnPredicate, ConsistencyLevel.ONE);
     List<NotificationEntry> notificationList = new ArrayList<NotificationEntry>(columns.size());
     for (SuperColumn superColumn : columns) {
       List<Column> wallEntryColumns = superColumn.getColumns();
       String notificationId = null;
       NotificationType notificationType = null;
       String questionId = null;
       String relatedUser = null;
       long answerCount = -1L;
       long time = 0;
       for (Column notificationColumn : wallEntryColumns) {
         String notificationColumnName = toString(notificationColumn.getName());
         if (notificationColumnName.equals("_id")) {
           notificationId = UUIDUtil.toUUID(notificationColumn.getValue()).toString();
           long timeInMicroSeconds = notificationColumn.getTimestamp();
           time = timeInMicroSeconds / 1000L;
         } else if (notificationColumnName.equals("_type")) {
           notificationType = NotificationType.fromId(toByte(notificationColumn));
         } else if (notificationColumnName.equals("questionId")) {
           questionId = toString(notificationColumn);
         } else if (notificationColumnName.equals("relatedUser")) {
           relatedUser = toString(notificationColumn);
         } else if (notificationColumnName.equals("answerCount")) {
           answerCount = toLong(notificationColumn);
         } else {
           logger.warn("Invalid notification column:{}", notificationColumnName);
         }
       }
       NotificationEntry notificationEntry = new NotificationEntry();
       notificationEntry.setId(notificationId);
       notificationEntry.setTime(time);
       notificationEntry.setNotificationType(notificationType);
       notificationEntry.setQuestionId(questionId);
       notificationList.add(notificationEntry);
       notificationEntry.setUsername(relatedUser);
       notificationEntry.setAnswerCount(answerCount);
     }
     return notificationList;
   } catch (NotFoundException ex) {
     return Collections.EMPTY_LIST;
   } catch (Exception ex) {
     logger.error("Can not get time uuid", ex);
     throw new TrendOceanException(ex);
   }
 }
コード例 #4
0
  private GatewayMixer buildMixer(List<Column> columns, String name) {

    String nodeJid = null;
    List<String> participants = new ArrayList<String>();
    if (columns != null && columns.size() > 0) {
      for (Column column : columns) {
        String columnName = Bytes.toUTF8(column.getName());
        if (columnName.equals("node")) {
          nodeJid = Bytes.toUTF8(column.getValue());
        } else {
          participants.add(Bytes.toUTF8(column.getName()));
        }
      }
      if (nodeJid != null) {
        GatewayMixer mixer = new GatewayMixer(name, nodeJid);
        mixer.addCalls(participants);
        return mixer;
      }
    }
    return null;
  }
コード例 #5
0
  @SuppressWarnings("unchecked")
  @Override
  public List<String> getClientResources(String bareJid) {

    try {
      log.debug("Finding resources for clients with jid: [%s]", bareJid);
      Selector selector = Pelops.createSelector(schemaName);
      List<Column> resourceColumn =
          selector.getColumnsFromRow("clients", bareJid, false, ConsistencyLevel.ONE);
      List<String> resources = new ArrayList<String>();
      for (Column column : resourceColumn) {
        String name = Bytes.toUTF8(column.getName());
        if (!name.equals("appId")) {
          resources.add(Bytes.toUTF8(column.getName()));
        }
      }
      return resources;
    } catch (PelopsException pe) {
      log.error(pe.getMessage(), pe);
      return Collections.EMPTY_LIST;
    }
  }
コード例 #6
0
 /** Provides retrieving of a next column. */
 private void shiftColumn() {
   if (m_iColumns.hasNext()) {
     // Current list may be used
     ColumnOrSuperColumn cosc = m_iColumns.next();
     m_sliceSize++;
     Column column = cosc.getColumn();
     m_next = new DColumn(column.getName(), column.getValue());
   } else if (m_sliceSize < CassandraDefs.MAX_COLS_BATCH_SIZE) {
     // All columns were read; no sense to try to get more columns
     m_next = null;
     return;
   } else if (m_next != null) {
     // Save current column name
     String lastName = m_next.getName();
     List<ColumnOrSuperColumn> columns = getNextSlice(lastName);
     m_sliceSize = 0;
     m_iColumns = columns.iterator();
     if (!m_iColumns.hasNext()) {
       // column was deleted? We cannot iterate correctly...
       m_next = null;
       return;
     }
     // Normally the first column is the same as was the previous one.
     ColumnOrSuperColumn cosc = m_iColumns.next();
     m_sliceSize++;
     Column column = cosc.getColumn();
     m_next = new DColumn(column.getName(), column.getValue());
     // Most probably we've got a column already read...
     // Shift from this column to the next one.
     if (lastName.equals(m_next.getName())) {
       // Just shift to next column
       shiftColumn();
     }
     // else the column was deleted.
     // We cannot guarantee that the iteration will continue correctly.
   }
 } // shiftColumn
コード例 #7
0
 /**
  * Purge expired entries. Expiration entries are stored in a single key (expirationKey) within a
  * specific ColumnFamily (set by configuration). The entries are grouped by expiration timestamp
  * in SuperColumns within which each entry's key is mapped to a column
  */
 @Override
 protected void purgeInternal() throws CacheLoaderException {
   if (trace) log.trace("purgeInternal");
   Cassandra.Client cassandraClient = null;
   try {
     cassandraClient = dataSource.getConnection();
     // We need to get all supercolumns from the beginning of time until
     // now, in SLICE_SIZE chunks
     SlicePredicate predicate = new SlicePredicate();
     predicate.setSlice_range(
         new SliceRange(
             ByteBufferUtil.EMPTY_BYTE_BUFFER,
             ByteBufferUtil.bytes(System.currentTimeMillis()),
             false,
             SLICE_SIZE));
     Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap =
         new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
     for (boolean complete = false; !complete; ) {
       // Get all columns
       List<ColumnOrSuperColumn> slice =
           cassandraClient.get_slice(
               expirationKey, expirationColumnParent, predicate, readConsistencyLevel);
       complete = slice.size() < SLICE_SIZE;
       // Delete all keys returned by the slice
       for (ColumnOrSuperColumn crumb : slice) {
         SuperColumn scol = crumb.getSuper_column();
         for (Iterator<Column> i = scol.getColumnsIterator(); i.hasNext(); ) {
           Column col = i.next();
           // Remove the entry row
           remove0(ByteBuffer.wrap(col.getName()), mutationMap);
         }
         // Remove the expiration supercolumn
         addMutation(
             mutationMap,
             expirationKey,
             config.expirationColumnFamily,
             ByteBuffer.wrap(scol.getName()),
             null,
             null);
       }
     }
     cassandraClient.batch_mutate(mutationMap, writeConsistencyLevel);
   } catch (Exception e) {
     throw new CacheLoaderException(e);
   } finally {
     dataSource.releaseConnection(cassandraClient);
   }
 }
コード例 #8
0
  @Override
  public List<String> getFilteredApplications(String id) throws DatastoreException {

    log.debug("Getting the list of filtered jids for id [%s]", id);
    List<String> ids = new ArrayList<String>();
    Selector selector = Pelops.createSelector(schemaName);
    try {
      List<Column> columns = selector.getColumnsFromRow("filters", id, false, ConsistencyLevel.ONE);
      for (Column column : columns) {
        ids.add(Bytes.toUTF8(column.getName()));
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return Collections.EMPTY_LIST;
    }
    return ids;
  }
コード例 #9
0
  private GatewayCall buildCall(List<Column> columns, String id) {

    if (columns != null && columns.size() > 0) {
      GatewayCall call = new GatewayCall();
      call.setCallId(id);
      for (Column column : columns) {
        String name = Bytes.toUTF8(column.getName());
        if (name.equals("node")) {
          call.setNodeJid(Bytes.toUTF8(column.getValue()));
        }
        if (name.equals("jid")) {
          call.setClientJid(Bytes.toUTF8(column.getValue()));
        }
      }
      return call;
    }
    return null;
  }
コード例 #10
0
  @Override
  public GatewayVerb getVerb(String mixerName, String id) {

    log.debug("Getting the verb [%s] from mixer [%s]", id, mixerName);
    Selector selector = Pelops.createSelector(schemaName);
    try {
      List<Column> columns =
          selector.getColumnsFromRow("verbs", mixerName, false, ConsistencyLevel.ONE);
      for (Column column : columns) {
        if (Bytes.toUTF8(column.getName()).equals(id)) {
          return new GatewayVerb(mixerName, id, Bytes.toUTF8(column.getValue()));
        }
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }
    return null;
  }
コード例 #11
0
  private void populateApplicationData(Application application, List<Column> columns) {

    for (Column column : columns) {
      String name = Bytes.toUTF8(column.getName());
      if (name.equals("appId")) {
        application.setAppId(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("platformId")) {
        application.setPlatform(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("name")) {
        application.setName(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("accountId")) {
        application.setAccountId(Bytes.toUTF8((column.getValue())));
      }
      if (name.equals("permissions")) {
        application.setPermissions(Bytes.toUTF8((column.getValue())));
      }
    }
  }
コード例 #12
0
  @SuppressWarnings("unchecked")
  @Override
  public List<GatewayVerb> getVerbs(String mixerName) {

    log.debug("Getting the list of active verbs for mixer [%s]", mixerName);
    List<GatewayVerb> ids = new ArrayList<GatewayVerb>();
    Selector selector = Pelops.createSelector(schemaName);
    try {
      List<Column> columns =
          selector.getColumnsFromRow("verbs", mixerName, false, ConsistencyLevel.ONE);
      for (Column column : columns) {
        GatewayVerb verb =
            new GatewayVerb(
                mixerName, Bytes.toUTF8(column.getName()), Bytes.toUTF8(column.getValue()));
        ids.add(verb);
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return Collections.EMPTY_LIST;
    }
    return ids;
  }
コード例 #13
0
  @Override
  public GatewayClient getClient(String jid) {

    log.debug("Finding client with jid: [%s]", jid);
    GatewayClient client = null;
    try {
      String bareJid = JIDUtils.getBareJid(jid);
      String resource = JIDUtils.getResource(jid);
      boolean resourceFound = false;

      Selector selector = Pelops.createSelector(schemaName);
      List<Column> columns =
          selector.getColumnsFromRow("clients", bareJid, false, ConsistencyLevel.ONE);
      if (columns != null && columns.size() > 0) {
        for (Column column : columns) {
          String name = Bytes.toUTF8(column.getName());
          if (name.equals(resource)) {
            resourceFound = true;
          }
        }
      }

      if (resourceFound) {
        Application application = getApplication(JIDUtils.getBareJid(jid));
        if (application != null) {
          client = new GatewayClient();
          client.setJid(jid);
          client.setPlatform(application.getPlatform());
        }
      }

    } catch (PelopsException pe) {
      log.error(pe.getMessage(), pe);
    }
    return client;
  }
コード例 #14
0
 @Override
 public ByteBuffer getRawName() {
   return ByteBuffer.wrap(column.getName());
 }