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);
}
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);
}
}
}
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);
}
}
}
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);
}
}
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();
}
Aggregations