Java Code Examples for me.prettyprint.hector.api.mutation.Mutator#addInsertion()
The following examples show how to use
me.prettyprint.hector.api.mutation.Mutator#addInsertion() .
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 File: CassandraUserStoreManager.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Adds a role to the role store. */ @Override public void doAddRole(String roleName, String[] userList, boolean shared) throws UserStoreException { Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get()); Composite composite = new Composite(); composite.addComponent(roleName, stringSerializer); composite.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(composite, CFConstants.UM_ROLES, HFactory.createColumn(CFConstants.UM_ROLE_NAME, roleName, stringSerializer, stringSerializer)); mutator.addInsertion(composite, CFConstants.UM_ROLES, HFactory.createColumn(CFConstants.UM_TENANT_ID, tenantIdString, stringSerializer, stringSerializer)); if (userList != null && userList.length > 0) { addRoleToUsersList(userList, roleName, mutator); } mutator.execute(); }
Example 2
Source File: CassandraUserStoreManager.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Maps the users to a role list. Adds the (username, tenantId) -> roleList * and (role, tenantId) -> userName * * @param userName The username of the user the roles need to be added to. * @param roleList The list of roles that needs to be mapped against the user. */ private void addUserToRoleList(String userName, String[] roleList) { Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get()); if (roleList != null) { for (String role : roleList) { Composite key = new Composite(); key.addComponent(userName, stringSerializer); key.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(role, role)); Composite keyRole = new Composite(); keyRole.addComponent(role, stringSerializer); keyRole.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName)); } mutator.execute(); } }
Example 3
Source File: CassandraUserStoreManager.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Maps the users to a role list. Adds the (username, tenantId) -> roleList * and (role, tenantId) -> userName * * @param userName The username of the user the roles need to be added to. * @param roleList The list of roles that needs to be mapped against the user. * @param mutator Passes the mutator and returns it with the insert statements. */ private Mutator<Composite> addUserToRoleList(String userName, String[] roleList, Mutator<Composite> mutator) { if (roleList != null && mutator != null) { for (String role : roleList) { Composite key = new Composite(); key.addComponent(userName, stringSerializer); key.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(role, role)); Composite keyRole = new Composite(); keyRole.addComponent(role, stringSerializer); keyRole.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName)); } } return mutator; }
Example 4
Source File: CassandraUserStoreManager.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Maps the role to a user list. Adds the (username, tenantId) -> roleList * and (role, tenantId) -> userName * * @param userNames The username list of the user the role need to be added to. * @param roleName The role that needs to be mapped against the user list. * @param mutator Passes the mutator and returns it with the insert statements. */ private Mutator<Composite> addRoleToUsersList(String[] userNames, String roleName, Mutator<Composite> mutator) { if (userNames != null) { for (String userName : userNames) { Composite key = new Composite(); key.addComponent(userName, stringSerializer); key.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(roleName, roleName)); Composite keyRole = new Composite(); keyRole.addComponent(roleName, stringSerializer); keyRole.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName)); } } return mutator; }
Example 5
Source File: CassandraPersistenceUtils.java From usergrid with Apache License 2.0 | 6 votes |
public static void addInsertToMutator( Mutator<ByteBuffer> m, Object columnFamily, Object key, Object columnName, Object columnValue, long timestamp ) { logBatchOperation( "Insert", columnFamily, key, columnName, columnValue, timestamp ); if ( columnName instanceof List<?> ) { columnName = DynamicComposite.toByteBuffer( ( List<?> ) columnName ); } if ( columnValue instanceof List<?> ) { columnValue = DynamicComposite.toByteBuffer( ( List<?> ) columnValue ); } HColumn<ByteBuffer, ByteBuffer> column = createColumn( bytebuffer( columnName ), bytebuffer( columnValue ), timestamp, be, be ); m.addInsertion( bytebuffer( key ), columnFamily.toString(), column ); }
Example 6
Source File: AbstractSearch.java From usergrid with Apache License 2.0 | 6 votes |
/** * Write the updated client pointer * * @param lastReturnedId This is a null safe parameter. If it's null, this won't be written since it means we didn't * read any messages */ protected void writeClientPointer( UUID queueId, UUID consumerId, UUID lastReturnedId ) { // nothing to do if ( lastReturnedId == null ) { return; } // we want to set the timestamp to the value from the time uuid. If this is // not the max time uuid to ever be written // for this consumer, we want this to be discarded to avoid internode race // conditions with clock drift. long colTimestamp = UUIDUtils.getTimestampInMicros( lastReturnedId ); Mutator<UUID> mutator = CountingMutator.createFlushingMutator( ko, ue ); if ( logger.isDebugEnabled() ) { logger.debug( "Writing last client id pointer of '{}' for queue '{}' and consumer '{}' with timestamp '{}", lastReturnedId, queueId, consumerId, colTimestamp ); } mutator.addInsertion( consumerId, CONSUMERS.getColumnFamily(), createColumn( queueId, lastReturnedId, colTimestamp, ue, ue ) ); mutator.execute(); }
Example 7
Source File: CassandraMQUtils.java From usergrid with Apache License 2.0 | 6 votes |
public static Mutator<ByteBuffer> addMessageToMutator( Mutator<ByteBuffer> m, Message message, long timestamp ) { Map<ByteBuffer, ByteBuffer> columns = serializeMessage( message ); if ( columns == null ) { return m; } for ( Map.Entry<ByteBuffer, ByteBuffer> column_entry : columns.entrySet() ) { if ( ( column_entry.getValue() != null ) && column_entry.getValue().hasRemaining() ) { HColumn<ByteBuffer, ByteBuffer> column = createColumn( column_entry.getKey(), column_entry.getValue(), timestamp, be, be ); m.addInsertion( bytebuffer( message.getUuid() ), QueuesCF.MESSAGE_PROPERTIES.toString(), column ); } else { m.addDeletion( bytebuffer( message.getUuid() ), QueuesCF.MESSAGE_PROPERTIES.toString(), column_entry.getKey(), be, timestamp ); } } return m; }
Example 8
Source File: CounterUtils.java From usergrid with Apache License 2.0 | 6 votes |
public Mutator<ByteBuffer> batchIncrementQueueCounter( Mutator<ByteBuffer> m, UUID queueId, String name, long value, long timestamp, UUID applicationId ) { if ( logger.isTraceEnabled() ) { logger.trace( "BIQC: Incrementing property {} of queue {} by value {}", name, queueId, value ); } m.addInsertion( bytebuffer( key( queueId, DICTIONARY_COUNTERS ).toString() ), QueuesCF.QUEUE_DICTIONARIES.toString(), createColumn( name, ByteBuffer.allocate( 0 ), timestamp, se, be ) ); if ( "o".equals( counterType ) || "p".equals( counterType ) ) { HCounterColumn<String> c = createCounterColumn( name, value ); ByteBuffer keybytes = bytebuffer( queueId ); m.addCounter( keybytes, QueuesCF.COUNTERS.toString(), c ); } if ( "n".equals( counterType ) || "p".equals( counterType ) ) { PrefixedSerializer ps = new PrefixedSerializer( applicationId, ue, ue ); batcher.add( new Count( QueuesCF.COUNTERS.toString(), ps.toByteBuffer( queueId ), name, value ) ); } return m; }
Example 9
Source File: Cassandra12xMapDAO.java From cumulusrdf with Apache License 2.0 | 5 votes |
@Override public void setAll(final Map<K, V> pairs) { final Mutator<K> mutator = createMutator(_keyspace, _serializer_k); for (final K key : pairs.keySet()) { mutator.addInsertion(key, _cf_name, createColumn(COLUMN_NAME, pairs.get(key), BYTE_SERIALIZER, _serializer_v)); } try { mutator.execute(); } catch (final Exception exception) { _log.error(MessageCatalog._00057_ADD_FAILURE, exception); } }
Example 10
Source File: ConsumerTransaction.java From usergrid with Apache License 2.0 | 5 votes |
/** * Write the transaction timeouts * * @param messages The messages to load * @param futureTimeout The time these message should expire * @param queueId The queue UUId * @param consumerId The consumer Id */ protected void writeTransactions( List<Message> messages, final long futureTimeout, UUID queueId, UUID consumerId ) { Mutator<ByteBuffer> mutator = CountingMutator.createFlushingMutator( ko, be ); ByteBuffer key = getQueueClientTransactionKey( queueId, consumerId ); int counter = 0; long time = cass.createTimestamp(); for ( Message message : messages ) { // note we're not incrementing futureSnapshot on purpose. The uuid // generation should give us a sequenced unique ID for each response, even // if the // time is the same since we increment the counter. If we read more than // 10k messages in a single transaction, our millisecond will roll to the // next due to 10k being the max amount of 1/10 microsecond headroom. Not // possible to avoid this given the way time uuids are encoded. UUID expirationId = UUIDUtils.newTimeUUID( futureTimeout, counter ); UUID messageId = message.getUuid(); if (logger.isTraceEnabled()) { logger.trace("Writing new timeout at '{}' for message '{}'", expirationId, messageId); } mutator.addInsertion( key, CONSUMER_QUEUE_TIMEOUTS.getColumnFamily(), createColumn( expirationId, messageId, time, ue, ue ) ); // add the transactionid to the message message.setTransaction( expirationId ); counter++; } mutator.execute(); }
Example 11
Source File: QueueManagerImpl.java From usergrid with Apache License 2.0 | 5 votes |
@Override public Queue updateQueue( String queuePath, Queue queue ) { queue.setPath( queuePath ); UUID timestampUuid = newTimeUUID(); long timestamp = getTimestampInMicros( timestampUuid ); Mutator<ByteBuffer> batch = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ), be ); addQueueToMutator( batch, queue, timestamp ); try { batchUpdateQueuePropertiesIndexes( batch, queuePath, queue.getUuid(), queue.getProperties(), timestampUuid ); } catch ( Exception e ) { logger.error( "Unable to update queue", e ); } batch.addInsertion( bytebuffer( queue.getUuid() ), QUEUE_PROPERTIES.getColumnFamily(), createColumn( QUEUE_CREATED, timestamp / 1000, Long.MAX_VALUE - timestamp, se, le ) ); batch.addInsertion( bytebuffer( queue.getUuid() ), QUEUE_PROPERTIES.getColumnFamily(), createColumn( QUEUE_MODIFIED, timestamp / 1000, timestamp, se, le ) ); batchExecute( batch, RETRY_COUNT ); return queue; }
Example 12
Source File: QueueManagerImpl.java From usergrid with Apache License 2.0 | 5 votes |
public void batchSubscribeToQueue( Mutator<ByteBuffer> batch, String publisherQueuePath, UUID publisherQueueId, String subscriberQueuePath, UUID subscriberQueueId, long timestamp ) { batch.addInsertion( bytebuffer( publisherQueueId ), QUEUE_SUBSCRIBERS.getColumnFamily(), createColumn( subscriberQueuePath, subscriberQueueId, timestamp, se, ue ) ); batch.addInsertion( bytebuffer( subscriberQueueId ), QUEUE_SUBSCRIPTIONS.getColumnFamily(), createColumn( publisherQueuePath, publisherQueueId, timestamp, se, ue ) ); }
Example 13
Source File: CassandraUtils.java From archiva with Apache License 2.0 | 5 votes |
public static void addInsertion( Mutator<String> mutator, String key, String columnFamily, String columnName, String value ) { if ( value != null ) { mutator.addInsertion( key, columnFamily, column( columnName, value ) ); } }
Example 14
Source File: CassandraUserStoreManager.java From carbon-identity with Apache License 2.0 | 5 votes |
@Override public void doUpdateCredentialByAdmin(String userName, Object newCredential) throws UserStoreException { if (!checkUserPasswordValid(newCredential)) { throw new UserStoreException( "Credential not valid. Credential must be a non null string with following format, " + realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_JAVA_REG_EX)); } String saltValue = null; if (TRUE.equalsIgnoreCase(realmConfig.getUserStoreProperties().get(JDBCRealmConstants.STORE_SALTED_PASSWORDS))) { saltValue = Util.getSaltValue(); } String password = Util.preparePassword((String) newCredential, saltValue); Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get()); Composite key = new Composite(); key.addComponent(userName, stringSerializer); key.addComponent(tenantIdString, stringSerializer); mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_SECRET, password, stringSerializer, stringSerializer)); mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_SALT_VALUE, saltValue, stringSerializer, stringSerializer)); try { mutator.execute(); if (log.isDebugEnabled()) { log.debug("Changed password for user " + userName + "successfully"); } } catch (HectorException e) { throw new UserStoreException("Change Password failed.", e); } }
Example 15
Source File: CassandraMetadataRepository.java From archiva with Apache License 2.0 | 4 votes |
private void updateFacets( final FacetedMetadata facetedMetadata, final ArtifactMetadataModel artifactMetadataModel ) { String cf = cassandraArchivaManager.getMetadataFacetFamilyName(); for ( final String facetId : getSupportedFacets() ) { MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId ); if ( metadataFacet == null ) { continue; } // clean first QueryResult<OrderedRows<String, String, String>> result = HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) // .setColumnFamily( cf ) // .setColumnNames( REPOSITORY_NAME.toString() ) // .addEqualsExpression( REPOSITORY_NAME.toString(), artifactMetadataModel.getRepositoryId() ) // .addEqualsExpression( NAMESPACE_ID.toString(), artifactMetadataModel.getNamespace() ) // .addEqualsExpression( PROJECT_ID.toString(), artifactMetadataModel.getProject() ) // .addEqualsExpression( PROJECT_VERSION.toString(), artifactMetadataModel.getProjectVersion() ) // .addEqualsExpression( FACET_ID.toString(), facetId ) // .execute(); for ( Row<String, String, String> row : result.get().getList() ) { this.metadataFacetTemplate.deleteRow( row.getKey() ); } Map<String, String> properties = metadataFacet.toProperties(); for ( Map.Entry<String, String> entry : properties.entrySet() ) { String key = new MetadataFacetModel.KeyBuilder().withKey( entry.getKey() ).withArtifactMetadataModel( artifactMetadataModel ).withFacetId( facetId ).withName( metadataFacet.getName() ).build(); Mutator<String> mutator = metadataFacetTemplate.createMutator() // .addInsertion( key, cf, column( REPOSITORY_NAME.toString(), artifactMetadataModel.getRepositoryId() ) ) // .addInsertion( key, cf, column( NAMESPACE_ID.toString(), artifactMetadataModel.getNamespace() ) ) // .addInsertion( key, cf, column( PROJECT_ID.toString(), artifactMetadataModel.getProject() ) ) // .addInsertion( key, cf, column( PROJECT_VERSION.toString(), artifactMetadataModel.getProjectVersion() ) ) // .addInsertion( key, cf, column( FACET_ID.toString(), facetId ) ) // .addInsertion( key, cf, column( KEY.toString(), entry.getKey() ) ) // .addInsertion( key, cf, column( VALUE.toString(), entry.getValue() ) ); if ( metadataFacet.getName() != null ) { mutator.addInsertion( key, cf, column( NAME.toString(), metadataFacet.getName() ) ); } mutator.execute(); } } }
Example 16
Source File: CassandraUserStoreManager.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Adds the user to the user store. */ @Override public void doAddUser(String userName, Object credential, String[] roleList, Map<String, String> claims, String profileName, boolean requirePasswordChange) throws UserStoreException { String userId = UUID.randomUUID().toString(); String saltValue = null; if (TRUE.equalsIgnoreCase(realmConfig.getUserStoreProperties().get(JDBCRealmConstants.STORE_SALTED_PASSWORDS))) { saltValue = Util.getSaltValue(); } String password = Util.preparePassword((String) credential, saltValue); if (doCheckExistingUser(userName)) { String message = "User with credentials " + userName + "exists"; UserStoreException userStoreException = new UserStoreException(message); log.error(message, userStoreException); throw userStoreException; } else { Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get()); Composite key = new Composite(); key.addComponent(userName, stringSerializer); key.addComponent(tenantIdString, stringSerializer); // add user ID mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_USER_ID, userId, stringSerializer, stringSerializer)); mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_USER_NAME, userName, stringSerializer, stringSerializer)); mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_SECRET, password, stringSerializer, stringSerializer)); mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_SALT_VALUE, saltValue, stringSerializer, stringSerializer)); mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_REQUIRE_CHANGE_BOOLEAN, "false", stringSerializer, stringSerializer)); mutator.addInsertion(key, CFConstants.UM_USER, HFactory.createColumn(CFConstants.UM_TENANT_ID, tenantIdString, stringSerializer, stringSerializer)); mutator = addUserToRoleList(userName, roleList, mutator); if (claims != null) { mutator = addClaimsForUser(userId, claims, mutator); } try { mutator.execute(); if (log.isDebugEnabled()) { log.debug("Added user " + userName + " successfully"); } } catch (HectorException e) { // TODO- research and check how to identify cassandra failure // and handle it efficiently. throw new UserStoreException("Adding user failed.", e); } mutator.execute(); } }
Example 17
Source File: QueueManagerImpl.java From usergrid with Apache License 2.0 | 4 votes |
public QueueIndexUpdate batchUpdateQueueIndex( QueueIndexUpdate indexUpdate, UUID subcriptionQueueId ) throws Exception { if (logger.isTraceEnabled()) { logger.trace("batchUpdateQueueIndex"); } Mutator<ByteBuffer> batch = indexUpdate.getBatch(); // queue_id,prop_name Object index_key = key( subcriptionQueueId, indexUpdate.getEntryName() ); // subscription_queue_id,subscriber_queue_id,prop_name for ( QueueIndexEntry entry : indexUpdate.getPrevEntries() ) { if ( entry.getValue() != null ) { index_key = key( subcriptionQueueId, entry.getPath() ); batch.addDeletion( bytebuffer( index_key ), PROPERTY_INDEX.getColumnFamily(), entry.getIndexComposite(), dce, indexUpdate.getTimestamp() ); } else { logger.error( "Unexpected condition - deserialized property value is null" ); } } if ( indexUpdate.getNewEntries().size() > 0 ) { for ( QueueIndexEntry indexEntry : indexUpdate.getNewEntries() ) { index_key = key( subcriptionQueueId, indexEntry.getPath() ); batch.addInsertion( bytebuffer( index_key ), PROPERTY_INDEX.getColumnFamily(), createColumn( indexEntry.getIndexComposite(), ByteBuffer.allocate( 0 ), indexUpdate.getTimestamp(), dce, be ) ); } } for ( String index : indexUpdate.getIndexesSet() ) { batch.addInsertion( bytebuffer( key( subcriptionQueueId, DICTIONARY_SUBSCRIBER_INDEXES ) ), QUEUE_DICTIONARIES.getColumnFamily(), createColumn( index, ByteBuffer.allocate( 0 ), indexUpdate.getTimestamp(), se, be ) ); } return indexUpdate; }
Example 18
Source File: ConsumerTransaction.java From usergrid with Apache License 2.0 | 4 votes |
/** * Renew the existing transaction. Does so by deleting the exiting timeout, and replacing it with a new value * * @param queuePath The queue path * @param transactionId The transaction id * @param query The query params * * @return The new transaction uuid */ public UUID renewTransaction( String queuePath, UUID transactionId, QueueQuery query ) throws TransactionNotFoundException { long now = System.currentTimeMillis(); if ( query == null ) { query = new QueueQuery(); } UUID queueId = getQueueId( queuePath ); UUID consumerId = getConsumerId( queueId, query ); ByteBuffer key = getQueueClientTransactionKey( queueId, consumerId ); // read the original transaction, if it's not there, then we can't possibly // extend it SliceQuery<ByteBuffer, UUID, UUID> q = createSliceQuery( ko, be, ue, ue ); q.setColumnFamily( CONSUMER_QUEUE_TIMEOUTS.getColumnFamily() ); q.setKey( key ); q.setColumnNames( transactionId ); HColumn<UUID, UUID> col = q.execute().get().getColumnByName( transactionId ); if ( col == null ) { throw new TransactionNotFoundException( String.format( "No transaction with id %s exists", transactionId ) ); } UUID origTrans = col.getName(); UUID messageId = col.getValue(); // Generate a new expiration and insert it UUID expirationId = UUIDUtils.newTimeUUID( now + query.getTimeout() ); if (logger.isTraceEnabled()) { logger.trace("Writing new timeout at '{}' for message '{}'", expirationId, messageId); } Mutator<ByteBuffer> mutator = CountingMutator.createFlushingMutator( ko, be ); mutator.addInsertion( key, CONSUMER_QUEUE_TIMEOUTS.getColumnFamily(), createColumn( expirationId, messageId, cass.createTimestamp(), ue, ue ) ); mutator.execute(); // now delete the old value deleteTransaction( queueId, consumerId, origTrans ); return expirationId; }
Example 19
Source File: PerfDataAccessor.java From oneops with Apache License 2.0 | 4 votes |
public void writeSampleToHeaderAndBuckets(String key, long endTime, PerfHeader header, Map<String, Double> data, HashMap<String, PerfEvent> perfEventMap) throws IOException { StringBuilder pendingKeys = new StringBuilder(""); Mutator<byte[]> mutator = createMutator(keyspace, bytesSerializer); phd.putHeader(key, header, mutator); // write the buckets / archives for (String dsRraTime : data.keySet()) { // only supporting avg due to volume if (!dsRraTime.contains("rra-average")) continue; String[] dsRraTimeParts = dsRraTime.split("::"); String dsRra = dsRraTimeParts[0]; String bucketKey = key + ":" + dsRra; long bucketEndTime = Long.parseLong(dsRraTimeParts[1]); Double cdpValue = Math.round(data.get(dsRraTime).doubleValue() * 1000.0) / 1000.0; if (dsRra.endsWith(LOGBUCKET)) { logger.info("write " + bucketKey + " : " + cdpValue); } String shard = dsRra.substring(dsRra.length() - 3).replace("-", ""); int ttl = getTTL(shard); HColumn<Long, Double> column = createDataColumn(bucketEndTime, cdpValue.doubleValue()); column.setTtl(ttl); String dataCF = DATA_CF + "_" + shard; if (isTestMode) dataCF += "_test"; mutator.addInsertion(bucketKey.getBytes(), dataCF, column); pendingKeys.append(" ," + bucketKey); // send the consolidated perf event to sensor PerfEvent pe = null; String[] rraParts = dsRra.split("-"); String eventBucket = rraParts[rraParts.length - 1]; if (perfEventMap.containsKey(eventBucket)) { pe = perfEventMap.get(eventBucket); } else { pe = setEventBucket(perfEventMap, eventBucket); } String ds = rraParts[0].replace(":rra", ""); String rraType = rraParts[1]; if (rraType.equalsIgnoreCase(AVERAGE)) { pe.getMetrics().addAvg(ds, cdpValue); } else if (rraType.equalsIgnoreCase(COUNT)) { pe.getMetrics().addCount(ds, cdpValue); } else if (rraType.equalsIgnoreCase(MAX)) { pe.getMetrics().addMax(ds, cdpValue); } else if (rraType.equalsIgnoreCase(MIN)) { pe.getMetrics().addMin(ds, cdpValue); } else if (rraType.equalsIgnoreCase(SUM)) { pe.getMetrics().addSum(ds, cdpValue); } } logger.debug("write keys:" + pendingKeys); // perform the insert/updates mutator.execute(); }
Example 20
Source File: QueueManagerImpl.java From usergrid with Apache License 2.0 | 2 votes |
public Message batchPostToQueue( Mutator<ByteBuffer> batch, String queuePath, Message message, MessageIndexUpdate indexUpdate, long timestamp ) { queuePath = normalizeQueuePath( queuePath ); UUID queueId = getQueueId( queuePath ); message.sync(); addMessageToMutator( batch, message, timestamp ); long shard_ts = roundLong( message.getTimestamp(), QUEUE_SHARD_INTERVAL ); final UUID messageUuid = message.getUuid(); if (logger.isDebugEnabled()) { logger.debug("Adding message with id '{}' to queue '{}'", messageUuid, queueId); } batch.addInsertion( getQueueShardRowKey( queueId, shard_ts ), QUEUE_INBOX.getColumnFamily(), createColumn( messageUuid, ByteBuffer.allocate( 0 ), timestamp, ue, be ) ); long oldest_ts = Long.MAX_VALUE - getTimestampInMicros( messageUuid ); batch.addInsertion( bytebuffer( queueId ), QUEUE_PROPERTIES.getColumnFamily(), createColumn( QUEUE_OLDEST, messageUuid, oldest_ts, se, ue ) ); long newest_ts = getTimestampInMicros( messageUuid ); batch.addInsertion( bytebuffer( queueId ), QUEUE_PROPERTIES.getColumnFamily(), createColumn( QUEUE_NEWEST, messageUuid, newest_ts, se, ue ) ); if (logger.isDebugEnabled()) { logger.debug("Writing UUID {} with oldest timestamp {} and newest with timestamp {}", messageUuid, oldest_ts, newest_ts); } batch.addInsertion( bytebuffer( getQueueId( "/" ) ), QUEUE_SUBSCRIBERS.getColumnFamily(), createColumn( queuePath, queueId, timestamp, se, ue ) ); counterUtils.batchIncrementQueueCounter( batch, getQueueId( "/" ), queuePath, 1L, timestamp, applicationId ); if ( indexUpdate == null ) { indexUpdate = new MessageIndexUpdate( message ); } indexUpdate.addToMutation( batch, queueId, shard_ts, timestamp ); counterUtils.addMessageCounterMutations( batch, applicationId, queueId, message, timestamp ); batch.addInsertion( bytebuffer( queueId ), QUEUE_PROPERTIES.getColumnFamily(), createColumn( QUEUE_CREATED, timestamp / 1000, Long.MAX_VALUE - timestamp, se, le ) ); batch.addInsertion( bytebuffer( queueId ), QUEUE_PROPERTIES.getColumnFamily(), createColumn( QUEUE_MODIFIED, timestamp / 1000, timestamp, se, le ) ); return message; }