use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.
the class MongoBatchUpdatePCJ method updatePCJMetadata.
private void updatePCJMetadata(final String ryaInstanceName, final String pcjId, final MongoClient client) throws RyaClientException {
// Update the PCJ's metadata to indicate it was just batch updated.
try {
final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(client, ryaInstanceName);
new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() {
@Override
public RyaDetails mutate(final RyaDetails originalDetails) throws CouldNotApplyMutationException {
// Update the original PCJ Details to indicate they were batch updated.
final PCJDetails originalPCJDetails = originalDetails.getPCJIndexDetails().getPCJDetails().get(pcjId);
final PCJDetails.Builder mutatedPCJDetails = PCJDetails.builder(originalPCJDetails).setUpdateStrategy(PCJUpdateStrategy.BATCH).setLastUpdateTime(new Date());
// Replace the old PCJ Details with the updated ones.
final RyaDetails.Builder builder = RyaDetails.builder(originalDetails);
builder.getPCJIndexDetails().addPCJDetails(mutatedPCJDetails);
return builder.build();
}
});
} catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new RyaClientException("Could not update the PCJ's metadata.", e);
}
}
use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.
the class AccumuloBatchUpdatePCJ method verifyPCJState.
private void verifyPCJState(final String ryaInstanceName, final String pcjId) throws RyaClientException {
try {
// Fetch the Rya instance's details.
final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(super.getConnector(), ryaInstanceName);
final RyaDetails ryaDetails = detailsRepo.getRyaInstanceDetails();
// Ensure PCJs are enabled.
if (!ryaDetails.getPCJIndexDetails().isEnabled()) {
throw new RyaClientException("PCJs are not enabled for the Rya instance named '" + ryaInstanceName + "'.");
}
// Ensure the PCJ exists.
if (!ryaDetails.getPCJIndexDetails().getPCJDetails().containsKey(pcjId)) {
throw new PCJDoesNotExistException("The PCJ with id '" + pcjId + "' does not exist within Rya instance '" + ryaInstanceName + "'.");
}
// Ensure the PCJ is not already being incrementally updated.
final PCJDetails pcjDetails = ryaDetails.getPCJIndexDetails().getPCJDetails().get(pcjId);
final Optional<PCJUpdateStrategy> updateStrategy = pcjDetails.getUpdateStrategy();
if (updateStrategy.isPresent() && updateStrategy.get() == PCJUpdateStrategy.INCREMENTAL) {
throw new RyaClientException("The PCJ with id '" + pcjId + "' is already being updated incrementally.");
}
} catch (final NotInitializedException e) {
throw new InstanceDoesNotExistException("No RyaDetails are initialized for the Rya instance named '" + ryaInstanceName + "'.", e);
} catch (final RyaDetailsRepositoryException e) {
throw new RyaClientException("Could not fetch the RyaDetails for the Rya instance named '" + ryaInstanceName + "'.", e);
}
}
use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.
the class AccumuloBatchUpdatePCJ method updatePCJMetadata.
private void updatePCJMetadata(final String ryaInstanceName, final String pcjId) throws RyaClientException {
// Update the PCJ's metadata to indicate it was just batch updated.
try {
final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(super.getConnector(), ryaInstanceName);
new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() {
@Override
public RyaDetails mutate(final RyaDetails originalDetails) throws CouldNotApplyMutationException {
// Update the original PCJ Details to indicate they were batch updated.
final PCJDetails originalPCJDetails = originalDetails.getPCJIndexDetails().getPCJDetails().get(pcjId);
final PCJDetails.Builder mutatedPCJDetails = PCJDetails.builder(originalPCJDetails).setUpdateStrategy(PCJUpdateStrategy.BATCH).setLastUpdateTime(new Date());
// Replace the old PCJ Details with the updated ones.
final RyaDetails.Builder builder = RyaDetails.builder(originalDetails);
builder.getPCJIndexDetails().addPCJDetails(mutatedPCJDetails);
return builder.build();
}
});
} catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new RyaClientException("Could not update the PCJ's metadata.", e);
}
}
use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.
the class AccumuloPcjStorageIT method createPCJ.
@Test
public void createPCJ() throws AccumuloException, AccumuloSecurityException, PCJStorageException, NotInitializedException, RyaDetailsRepositoryException {
// Setup the PCJ storage that will be tested against.
final Connector connector = super.getClusterInstance().getConnector();
final String ryaInstanceName = super.getRyaInstanceName();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(connector, ryaInstanceName)) {
// Create a PCJ.
final String pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
// Ensure the Rya details have been updated to include the PCJ's ID.
final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(connector, ryaInstanceName);
final ImmutableMap<String, PCJDetails> detailsMap = detailsRepo.getRyaInstanceDetails().getPCJIndexDetails().getPCJDetails();
final PCJDetails expectedDetails = PCJDetails.builder().setId(pcjId).build();
assertEquals(expectedDetails, detailsMap.get(pcjId));
}
}
use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.
the class AccumuloPcjStorageIT method dropPCJ.
@Test
public void dropPCJ() throws AccumuloException, AccumuloSecurityException, PCJStorageException, NotInitializedException, RyaDetailsRepositoryException {
// Setup the PCJ storage that will be tested against.
final Connector connector = super.getClusterInstance().getConnector();
final String ryaInstanceName = super.getRyaInstanceName();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(connector, ryaInstanceName)) {
// Create a PCJ.
final String pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
// Delete the PCJ that was just created.
pcjStorage.dropPcj(pcjId);
// Ensure the Rya details have been updated to no longer include the PCJ's ID.
final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(connector, ryaInstanceName);
final ImmutableMap<String, PCJDetails> detailsMap = detailsRepo.getRyaInstanceDetails().getPCJIndexDetails().getPCJDetails();
assertFalse(detailsMap.containsKey(pcjId));
}
}
Aggregations