Search in sources :

Example 1 with MergeParentMetadata

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

the class AccumuloParentMetadataRepositoryAdapterTest method setAndGetTest.

@Test
public void setAndGetTest() throws ParentMetadataExistsException, ParentMetadataDoesNotExistException {
    final MergeParentMetadata mergeParentMetadata = new MergeParentMetadata.Builder().setRyaInstanceName(TEST_INSTANCE).setTimestamp(TEST_TIMESTAMP).setFilterTimestmap(TEST_FILTER_TIMESTAMP).setParentTimeOffset(TEST_TIME_OFFSET).build();
    accumuloParentMetadataRepository.set(mergeParentMetadata);
    final MergeParentMetadata actual = accumuloParentMetadataRepository.get();
    assertEquals(mergeParentMetadata, actual);
}
Also used : MergeParentMetadata(org.apache.rya.export.api.metadata.MergeParentMetadata) Test(org.junit.Test)

Example 2 with MergeParentMetadata

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

the class MemoryTimeMerger method export.

/**
 * Exports all statements after the provided timestamp.
 * @throws ParentMetadataExistsException -
 * @throws FetchStatementException
 */
private void export() throws ParentMetadataExistsException, FetchStatementException {
    LOG.info("Creating parent metadata in the child.");
    // setup parent metadata repo in the child
    final MergeParentMetadata metadata = new MergeParentMetadata.Builder().setRyaInstanceName(ryaInstanceName).setTimestamp(new Date()).setParentTimeOffset(timeOffset).setFilterTimestmap(timestamp).build();
    childStore.setParentMetadata(metadata);
    // fetch all statements after timestamp from the parent
    final Iterator<RyaStatement> statements = parentStore.fetchStatements();
    LOG.info("Exporting statements.");
    while (statements.hasNext()) {
        System.out.print(".");
        final RyaStatement statement = statements.next();
        try {
            childStore.addStatement(statement);
        } catch (final AddStatementException e) {
            LOG.error("Failed to add statement: " + statement + " to the statement store.", e);
        }
    }
}
Also used : AddStatementException(org.apache.rya.export.api.store.AddStatementException) MergeParentMetadata(org.apache.rya.export.api.metadata.MergeParentMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) Date(java.util.Date)

Example 3 with MergeParentMetadata

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

the class MemoryTimeMerger method runJob.

@Override
public void runJob() {
    final Optional<MergeParentMetadata> metadata = parentStore.getParentMetadata();
    // check the parent for a parent metadata repo
    if (metadata.isPresent()) {
        LOG.info("Merging statements...");
        final MergeParentMetadata parentMetadata = metadata.get();
        if (parentMetadata.getRyaInstanceName().equals(ryaInstanceName)) {
            try {
                importStatements(parentMetadata);
            } catch (AddStatementException | ContainsStatementException | RemoveStatementException | FetchStatementException e) {
                LOG.error("Failed to import statements.", e);
            }
        }
    } else {
        try {
            LOG.info("Cloning statements...");
            export();
        } catch (final ParentMetadataExistsException | FetchStatementException e) {
            LOG.error("Failed to export statements.", e);
        }
    }
}
Also used : AddStatementException(org.apache.rya.export.api.store.AddStatementException) ParentMetadataExistsException(org.apache.rya.export.api.metadata.ParentMetadataExistsException) MergeParentMetadata(org.apache.rya.export.api.metadata.MergeParentMetadata) ContainsStatementException(org.apache.rya.export.api.store.ContainsStatementException) RemoveStatementException(org.apache.rya.export.api.store.RemoveStatementException) FetchStatementException(org.apache.rya.export.api.store.FetchStatementException)

Example 4 with MergeParentMetadata

use of org.apache.rya.export.api.metadata.MergeParentMetadata 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)

Example 5 with MergeParentMetadata

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

the class ParentMetadataRepositoryAdapter method deserialize.

/**
 * Deserialize the mongoBD object into {@link MergeParentMetadata}.
 * @param dbo - The mongo {@link DBObject} to deserialize.
 * @return The {@link MergeParentMetadata}
 */
public MergeParentMetadata deserialize(final DBObject dbo) {
    final Date timestamp = (Date) dbo.get(TIMESTAMP_KEY);
    final String ryaInstance = (String) dbo.get(RYANAME_KEY);
    final Date filterTimestamp = (Date) dbo.get(FILTER_TIMESTAMP_KEY);
    final Long offset = (Long) dbo.get(PARENT_TIME_OFFSET_KEY);
    return new MergeParentMetadata.Builder().setRyaInstanceName(ryaInstance).setTimestamp(timestamp).setFilterTimestmap(filterTimestamp).setParentTimeOffset(offset).build();
}
Also used : MergeParentMetadata(org.apache.rya.export.api.metadata.MergeParentMetadata) Date(java.util.Date)

Aggregations

MergeParentMetadata (org.apache.rya.export.api.metadata.MergeParentMetadata)7 Date (java.util.Date)3 Test (org.junit.Test)3 DBObject (com.mongodb.DBObject)2 ParentMetadataExistsException (org.apache.rya.export.api.metadata.ParentMetadataExistsException)2 AddStatementException (org.apache.rya.export.api.store.AddStatementException)2 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 RyaStatement (org.apache.rya.api.domain.RyaStatement)1 MergerException (org.apache.rya.export.api.MergerException)1 ParentMetadataDoesNotExistException (org.apache.rya.export.api.metadata.ParentMetadataDoesNotExistException)1