com.netflix.astyanax.connectionpool.exceptions.NotFoundException Java Examples

The following examples show how to use com.netflix.astyanax.connectionpool.exceptions.NotFoundException. 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: ADelayedLocatorIO.java    From blueflood with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Locator> getLocators(SlotKey slotKey) throws IOException {

    Timer.Context ctx = Instrumentation.getReadTimerContext(CassandraModel.CF_METRICS_DELAYED_LOCATOR_NAME);

    try {
        RowQuery<SlotKey, Locator> query = AstyanaxIO.getKeyspace()
                .prepareQuery(CassandraModel.CF_METRICS_DELAYED_LOCATOR)
                .getKey(slotKey);
        return query.execute().getResult().getColumnNames();
    } catch (NotFoundException e) {
        Instrumentation.markNotFound(CassandraModel.CF_METRICS_DELAYED_LOCATOR_NAME);
        return Collections.emptySet();
    } catch (ConnectionException ex) {
        Instrumentation.markPoolExhausted();
        Instrumentation.markReadError();
        LOG.error("Connection exception during ADelayedLocatorIO.getLocators(" + slotKey.toString() + ")", ex);
        throw new IOException("Error reading delayed locators", ex);
    } finally {
        ctx.stop();
    }
}
 
Example #2
Source File: ALocatorIO.java    From blueflood with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the locators for a shard, i.e. those that should be rolled up, for a given shard.
 * 'Should' means:
 *  1) A locator is capable of rollup.
 *  2) A locator has had new data in the past LOCATOR_TTL seconds.
 *
 * @param shard Number of the shard you want the locators for. 0-127 inclusive.
 * @return Collection of locators
 * @throws IOException
 */
@Override
public Collection<Locator> getLocators(long shard) throws IOException {
    Timer.Context ctx = Instrumentation.getReadTimerContext(CassandraModel.CF_METRICS_LOCATOR_NAME);
    try {
        RowQuery<Long, Locator> query = AstyanaxIO.getKeyspace()
                .prepareQuery(CassandraModel.CF_METRICS_LOCATOR)
                .getKey(shard);
        if (LOG.isTraceEnabled())
            LOG.trace("ALocatorIO.getLocators() executing: select * from \"" + CassandraModel.KEYSPACE + "\"." + CassandraModel.CF_METRICS_LOCATOR_NAME + " where key=" + Long.toString(shard));
        return query.execute().getResult().getColumnNames();
    } catch (NotFoundException e) {
        Instrumentation.markNotFound(CassandraModel.CF_METRICS_LOCATOR_NAME);
        return Collections.emptySet();
    } catch (ConnectionException ex) {
        Instrumentation.markReadError(ex);
        LOG.error("Connection exception during getLocators(" + Long.toString(shard) + ")", ex);
        throw new IOException("Error reading locators", ex);
    } finally {
        ctx.stop();
    }
}
 
Example #3
Source File: AstyanaxReader.java    From blueflood with Apache License 2.0 6 votes vote down vote up
/**
 * Method that returns all metadata for a given locator as a map.
 *
 * @param locator  locator name
 * @return Map of metadata for that locator
 * @throws RuntimeException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)
 */
public Map<String, String> getMetadataValues(Locator locator) {
    Timer.Context ctx = Instrumentation.getReadTimerContext(CassandraModel.CF_METRICS_METADATA_NAME);
    try {
        final ColumnList<String> results = keyspace.prepareQuery(CassandraModel.CF_METRICS_METADATA)
                .getKey(locator)
                .execute().getResult();
        return new HashMap<String, String>(){{
            for (Column<String> result : results) {
                put(result.getName(), result.getValue(StringMetadataSerializer.get()));
            }
        }};
    } catch (NotFoundException ex) {
        Instrumentation.markNotFound(CassandraModel.CF_METRICS_METADATA_NAME);
        return null;
    } catch (ConnectionException e) {
        log.error("Error reading metadata value", e);
        Instrumentation.markReadError(e);
        throw new RuntimeException(e);
    } finally {
        ctx.stop();
    }
}
 
Example #4
Source File: MigrationInfoSerializationImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public String getStatusMessage(final String pluginName) {

    final ScopedRowKey<String> rowKey = ScopedRowKey.fromKey( STATIC_ID, pluginName);

    try {
        return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( rowKey ).getColumn( COL_STATUS_MESSAGE )
                       .execute().getResult().getStringValue();
    }
    //swallow, it doesn't exist
    catch ( NotFoundException nfe ) {
        return null;
    }
    catch ( ConnectionException e ) {
        throw new DataMigrationException( "Unable to retrieve status", e );
    }
}
 
Example #5
Source File: MigrationInfoSerializationImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public int getVersion(final String pluginName) {

    final ScopedRowKey<String> rowKey = ScopedRowKey.fromKey( STATIC_ID, pluginName);

    try {
        return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( rowKey ).getColumn( COLUMN_VERSION ).execute()
                       .getResult().getIntegerValue();
    }
    //swallow, it doesn't exist
    catch ( NotFoundException nfe ) {
        return 0;
    }
    catch ( ConnectionException e ) {
        AstyanaxUtils.isSchemaMissing("Unable to connect to cassandra to retrieve status", e);
        return 0;
    }
}
 
Example #6
Source File: MigrationInfoSerializationImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public int getStatusCode(final String pluginName) {

    final ScopedRowKey<String> rowKey = ScopedRowKey.fromKey( STATIC_ID, pluginName);

    try {
        return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( rowKey ).getColumn( COLUMN_STATUS_CODE )
                       .execute().getResult().getIntegerValue();
    }
    //swallow, it doesn't exist
    catch ( NotFoundException nfe ) {
        return 0;
    }
    catch ( ConnectionException e ) {
        throw new DataMigrationException( "Unable to retrieve status", e );
    }
}
 
Example #7
Source File: CassandraStoreImpl.java    From recipes-rss with Apache License 2.0 6 votes vote down vote up
/**
 * Get the feed urls from Cassandra
 */
@Override
public List<String> getSubscribedUrls(String userId) throws Exception{
    OperationResult<ColumnList<String>> response;
    try {
        response = getKeyspace().prepareQuery(CF_SUBSCRIPTIONS).getKey(userId).execute();
    } catch (NotFoundException e) {
        logger.error("No record found for this user: " + userId);
        throw e;
    } catch (Exception t) {
        logger.error("Exception occurred when fetching from Cassandra: " + t);
        throw t;
    }

    final List<String> items = new ArrayList<String>();
    if (response != null) {
        final ColumnList<String> columns = response.getResult();
        for (Column<String> column : columns) {
            items.add(column.getName());
        }
    }

    return items;
}
 
Example #8
Source File: AstyanaxReader.java    From blueflood with Apache License 2.0 5 votes vote down vote up
public Table<Locator, String, String> getMetadataValues(Set<Locator> locators) {
    ColumnFamily CF = CassandraModel.CF_METRICS_METADATA;
    boolean isBatch = locators.size() > 1;
    Table<Locator, String, String> metaTable = HashBasedTable.create();

    Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF.getName()) : Instrumentation.getReadTimerContext(CF.getName());
    try {
        // We don't paginate this call. So we should make sure the number of reads is tolerable.
        // TODO: Think about paginating this call.
        OperationResult<Rows<Locator, String>> query = keyspace
                .prepareQuery(CF)
                .getKeySlice(locators)
                .execute();

        for (Row<Locator, String> row : query.getResult()) {
            ColumnList<String> columns = row.getColumns();
            for (Column<String> column : columns) {
                String metaValue = column.getValue(StringMetadataSerializer.get());
                String metaKey = column.getName();
                metaTable.put(row.getKey(), metaKey, metaValue);
            }
        }
    } catch (ConnectionException e) {
        if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found.
            Instrumentation.markNotFound(CF.getName());
        } else {
            if (isBatch) { Instrumentation.markBatchReadError(e); }
            else { Instrumentation.markReadError(e); }
        }
        log.error((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName() + " for locators: " + StringUtils.join(locators, ","), e);
    } finally {
        ctx.stop();
    }

    return metaTable;
}
 
Example #9
Source File: AstyanaxReader.java    From blueflood with Apache License 2.0 5 votes vote down vote up
protected Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF,
                                                        Range range) {
    if (range.getStart() > range.getStop()) {
        throw new RuntimeException(String.format("Invalid rollup range: ", range.toString()));
    }
    boolean isBatch = locators.size() != 1;

    final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>();
    final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop());

    Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF.getName()) : Instrumentation.getReadTimerContext(CF.getName());
    try {
        // We don't paginate this call. So we should make sure the number of reads is tolerable.
        // TODO: Think about paginating this call.
        OperationResult<Rows<Locator, Long>> query = keyspace
                .prepareQuery(CF)
                .getKeySlice(locators)
                .withColumnRange(rangeBuilder.build())
                .execute();
        for (Row<Locator, Long> row : query.getResult()) {
            columns.put(row.getKey(), row.getColumns());
        }

    } catch (ConnectionException e) {
        if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found.
            Instrumentation.markNotFound(CF.getName());
        } else {
            if (isBatch) { Instrumentation.markBatchReadError(e); }
            else { Instrumentation.markReadError(e); }
        }
        log.error((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName() + " for locators: " + StringUtils.join(locators, ","), e);
    } finally {
        ctx.stop();
    }

    return columns;
}
 
Example #10
Source File: MigrationInfoSerializationImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public int getSystemVersion() {
    try {
        return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( LEGACY_ROW_KEY ).getColumn( COLUMN_VERSION )
                       .execute().getResult().getIntegerValue();
    }
    //swallow, it doesn't exist
    catch ( NotFoundException nfe ) {
        return 0;
    }
    catch ( ConnectionException e ) {
        throw new DataMigrationException( "Unable to retrieve status", e );
    }
}
 
Example #11
Source File: NodeSerializationImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<Long> getMaxVersion( final ApplicationScope scope, final Id node ) {
    ValidationUtils.validateApplicationScope( scope );
    ValidationUtils.verifyIdentity( node );

    ColumnFamilyQuery<ScopedRowKey<Id>, Boolean> query =
            keyspace.prepareQuery( GRAPH_DELETE ).setConsistencyLevel( fig.getReadCL() );



    Column<Boolean> result = null;
    try {
        result = query.getKey( ScopedRowKey.fromKey( scope.getApplication(), node ) ).getColumn( COLUMN_NAME ).execute()
                .getResult();
    }
    catch(NotFoundException nfe){
         //swallow, there's just no column
        return Optional.absent();
    }
    catch ( ConnectionException e ) {
        throw new RuntimeException( "Unable to connect to casandra", e );
    }

    return Optional.of( result.getLongValue() );


}