Search in sources :

Example 1 with ParentMetadataDoesNotExistException

use of org.apache.rya.export.api.metadata.ParentMetadataDoesNotExistException in project incubator-rya by apache.

the class AccumuloParentMetadataRepository method getMetadataFromTable.

private MergeParentMetadata getMetadataFromTable() throws ParentMetadataDoesNotExistException {
    try {
        // Create an Accumulo scanner that iterates through the metadata entries.
        final Scanner scanner = connector.createScanner(mergeParentMetadataTableName, new Authorizations());
        final Iterator<Entry<Key, Value>> entries = scanner.iterator();
        // No metadata has been stored in the table yet.
        if (!entries.hasNext()) {
            throw new ParentMetadataDoesNotExistException("Could not find any MergeParentMetadata metadata in the table named: " + mergeParentMetadataTableName);
        }
        // Fetch the metadata from the entries.
        String ryaInstanceName = null;
        Date timestamp = null;
        Date filterTimestamp = null;
        Long parentTimeOffset = null;
        while (entries.hasNext()) {
            final Entry<Key, Value> entry = entries.next();
            final Text columnQualifier = entry.getKey().getColumnQualifier();
            final byte[] value = entry.getValue().get();
            if (columnQualifier.equals(MERGE_PARENT_METADATA_RYA_INSTANCE_NAME)) {
                ryaInstanceName = STRING_LEXICODER.decode(value);
            } else if (columnQualifier.equals(MERGE_PARENT_METADATA_TIMESTAMP)) {
                timestamp = DATE_LEXICODER.decode(value);
            } else if (columnQualifier.equals(MERGE_PARENT_METADATA_FILTER_TIMESTAMP)) {
                filterTimestamp = DATE_LEXICODER.decode(value);
            } else if (columnQualifier.equals(MERGE_PARENT_METADATA_PARENT_TIME_OFFSET)) {
                parentTimeOffset = LONG_LEXICODER.decode(value);
            }
        }
        return new MergeParentMetadata(ryaInstanceName, timestamp, filterTimestamp, parentTimeOffset);
    } catch (final TableNotFoundException e) {
        throw new ParentMetadataDoesNotExistException("Could not add results to a MergeParentMetadata because the MergeParentMetadata table does not exist.", e);
    } catch (final Exception e) {
        throw new ParentMetadataDoesNotExistException("Error occurred while getting merge parent metadata.", e);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) MergeParentMetadata(org.apache.rya.export.api.metadata.MergeParentMetadata) Text(org.apache.hadoop.io.Text) Date(java.util.Date) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ParentMetadataExistsException(org.apache.rya.export.api.metadata.ParentMetadataExistsException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MergerException(org.apache.rya.export.api.MergerException) ParentMetadataDoesNotExistException(org.apache.rya.export.api.metadata.ParentMetadataDoesNotExistException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) ParentMetadataDoesNotExistException(org.apache.rya.export.api.metadata.ParentMetadataDoesNotExistException) Key(org.apache.accumulo.core.data.Key)

Aggregations

Date (java.util.Date)1 Entry (java.util.Map.Entry)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 Scanner (org.apache.accumulo.core.client.Scanner)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 Text (org.apache.hadoop.io.Text)1 MergerException (org.apache.rya.export.api.MergerException)1 MergeParentMetadata (org.apache.rya.export.api.metadata.MergeParentMetadata)1 ParentMetadataDoesNotExistException (org.apache.rya.export.api.metadata.ParentMetadataDoesNotExistException)1 ParentMetadataExistsException (org.apache.rya.export.api.metadata.ParentMetadataExistsException)1