Java Code Examples for com.netflix.astyanax.util.TimeUUIDUtils

The following examples show how to use com.netflix.astyanax.util.TimeUUIDUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Raigad   Source File: InstanceDataDAOCassandra.java    License: Apache License 2.0 6 votes vote down vote up
public void createInstanceEntry(RaigadInstance instance) throws Exception {
    logger.info("Creating new instance entry");

    String key = getRowKey(instance);
    // If the key exists throw exception
    if (getInstance(instance.getApp(), instance.getDC(), instance.getId()) != null) {
        logger.info(String.format("Key already exists: %s", key));
        return;
    }

    // Grab the lock
    getLock(instance);

    MutationBatch mutationBatch = bootKeyspace.prepareMutationBatch();
    ColumnListMutation<String> columnListMutation = mutationBatch.withRow(CF_INSTANCES, key);
    columnListMutation.putColumn(CN_CLUSTER, instance.getApp(), null);
    columnListMutation.putColumn(CN_AZ, instance.getAvailabilityZone(), null);
    columnListMutation.putColumn(CN_INSTANCEID, instance.getInstanceId(), null);
    columnListMutation.putColumn(CN_HOSTNAME, instance.getHostName(), null);
    columnListMutation.putColumn(CN_IP, instance.getHostIP(), null);
    columnListMutation.putColumn(CN_LOCATION, instance.getDC(), null);
    columnListMutation.putColumn(CN_ASGNAME, instance.getAsg(), null);
    columnListMutation.putColumn(CN_UPDATETIME, TimeUUIDUtils.getUniqueTimeUUIDinMicros(), null);

    mutationBatch.execute();
}
 
Example 2
Source Project: staash   Source File: SimpleReverseIndexer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void tagId(String id, Map<String, String> tags) throws IndexerException  {
        MutationBatch mb = keyspace.prepareMutationBatch();
        
        ColumnListMutation<String> idRow = mb.withRow(dataCf, id);
        UUID uuid = TimeUUIDUtils.getUniqueTimeUUIDinMicros();
        for (Map.Entry<String, String> tag : tags.entrySet()) {
            String rowkey = tag.getKey() + "=" + tag.getValue();
            System.out.println("Rowkey: " + rowkey);
            mb.withRow(indexCf, tag.getKey() + "=" + tag.getValue())
              .putEmptyColumn(new IndexEntry(id, uuid));
//            idRow.putColumn(tag.getKey(), tag.getValue());
        }
        
        try {
            mb.execute();
        } catch (ConnectionException e) {
            throw new IndexerException("Failed to store tags : " + tags + " for id " + id, e);
        }
    }
 
Example 3
Source Project: usergrid   Source File: NodeShardAllocationImpl.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Return true if the node has been created within our timeout.  If this is the case, we dont' need to check
 * cassandra, we know it won't exist
 */
private boolean isNewNode( DirectedEdgeMeta directedEdgeMeta ) {


    //The timeout is in milliseconds.  Time for a time uuid is 1/10000 of a milli, so we need to get the units
    // correct
    final long timeoutDelta = graphFig.getShardCacheTimeout();

    final long timeNow = timeService.getCurrentTime();

    boolean isNew = true;

    for ( DirectedEdgeMeta.NodeMeta node : directedEdgeMeta.getNodes() ) {

        //short circuit if not a type 1 time UUID
        if ( !isNew || node.getId().getUuid().version() != 1 ) {
            return false;
        }

        final long uuidTime = TimeUUIDUtils.getTimeFromUUID( node.getId().getUuid() );

        final long newExpirationTimeout = uuidTime + timeoutDelta;

        //our expiration is after our current time, treat it as new
        isNew = isNew && newExpirationTimeout > timeNow;
    }

    return isNew;
}