use of org.apache.rya.api.instance.RyaDetails in project incubator-rya by apache.
the class AccumuloCreatePCJ method createPCJ.
@Override
public String createPCJ(final String instanceName, final String sparql, Set<ExportStrategy> strategies) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(instanceName);
requireNonNull(sparql);
final Optional<RyaDetails> ryaDetailsHolder = getInstanceDetails.getDetails(instanceName);
final boolean ryaInstanceExists = ryaDetailsHolder.isPresent();
if (!ryaInstanceExists) {
throw new InstanceDoesNotExistException(String.format("The '%s' instance of Rya does not exist.", instanceName));
}
final PCJIndexDetails pcjIndexDetails = ryaDetailsHolder.get().getPCJIndexDetails();
final boolean pcjIndexingEnabeld = pcjIndexDetails.isEnabled();
if (!pcjIndexingEnabeld) {
throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ Indexing enabled.", instanceName));
}
// Create the PCJ table that will receive the index results.
final String pcjId;
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(getConnector(), instanceName)) {
pcjId = pcjStorage.createPcj(sparql);
// If a Fluo application is being used, task it with updating the PCJ.
final Optional<FluoDetails> fluoDetailsHolder = pcjIndexDetails.getFluoDetails();
if (fluoDetailsHolder.isPresent()) {
final String fluoAppName = fluoDetailsHolder.get().getUpdateAppName();
try {
updateFluoApp(instanceName, fluoAppName, pcjId, sparql, strategies);
} catch (RepositoryException | MalformedQueryException | SailException | QueryEvaluationException | PcjException | RyaDAOException e) {
throw new RyaClientException("Problem while initializing the Fluo application with the new PCJ.", e);
} catch (UnsupportedQueryException e) {
throw new RyaClientException("The new PCJ could not be initialized because it either contains an unsupported query node " + "or an invalid ExportStrategy for the given QueryType. Projection queries can be exported to either Rya or Kafka," + "unless they contain an aggregation, in which case they can only be exported to Kafka. Construct queries can be exported" + "to Rya and Kafka, and Periodic queries can only be exported to Rya.");
}
// Update the Rya Details to indicate the PCJ is being updated incrementally.
final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName);
try {
new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() {
@Override
public RyaDetails mutate(final RyaDetails originalDetails) throws CouldNotApplyMutationException {
// Update the original PCJ Details to indicate they are incrementally updated.
final PCJDetails originalPCJDetails = originalDetails.getPCJIndexDetails().getPCJDetails().get(pcjId);
final PCJDetails.Builder mutatedPCJDetails = PCJDetails.builder(originalPCJDetails).setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL);
// Replace the old PCJ Details with the updated ones.
final RyaDetails.Builder builder = RyaDetails.builder(originalDetails);
builder.getPCJIndexDetails().addPCJDetails(mutatedPCJDetails);
return builder.build();
}
});
} catch (RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new RyaClientException("Problem while updating the Rya instance's Details to indicate the PCJ is being incrementally updated.", e);
}
}
// Return the ID that was assigned to the PCJ.
return pcjId;
} catch (final PCJStorageException e) {
throw new RyaClientException("Problem while initializing the PCJ table.", e);
}
}
use of org.apache.rya.api.instance.RyaDetails in project incubator-rya by apache.
the class AccumuloDeletePCJ method deletePCJ.
@Override
public void deletePCJ(final String instanceName, final String pcjId) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(instanceName);
requireNonNull(pcjId);
final Optional<RyaDetails> originalDetails = getInstanceDetails.getDetails(instanceName);
final boolean ryaInstanceExists = originalDetails.isPresent();
if (!ryaInstanceExists) {
throw new InstanceDoesNotExistException(String.format("The '%s' instance of Rya does not exist.", instanceName));
}
final boolean pcjIndexingEnabeld = originalDetails.get().getPCJIndexDetails().isEnabled();
if (!pcjIndexingEnabeld) {
throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ Indexing enabled.", instanceName));
}
final boolean pcjExists = originalDetails.get().getPCJIndexDetails().getPCJDetails().containsKey(pcjId);
if (!pcjExists) {
throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ with ID '%s'.", instanceName, pcjId));
}
// If the PCJ was being maintained by a Fluo application, then stop that process.
final PCJIndexDetails pcjIndexDetails = originalDetails.get().getPCJIndexDetails();
final PCJDetails droppedPcjDetails = pcjIndexDetails.getPCJDetails().get(pcjId);
if (droppedPcjDetails.getUpdateStrategy().isPresent()) {
if (droppedPcjDetails.getUpdateStrategy().get() == PCJUpdateStrategy.INCREMENTAL) {
final Optional<FluoDetails> fluoDetailsHolder = pcjIndexDetails.getFluoDetails();
if (fluoDetailsHolder.isPresent()) {
final String fluoAppName = pcjIndexDetails.getFluoDetails().get().getUpdateAppName();
stopUpdatingPCJ(fluoAppName, pcjId);
} else {
log.error(String.format("Could not stop the Fluo application from updating the PCJ because the Fluo Details are " + "missing for the Rya instance named '%s'.", instanceName));
}
}
}
// Drop the table that holds the PCJ results from Accumulo.
try (final PrecomputedJoinStorage pcjs = new AccumuloPcjStorage(getConnector(), instanceName)) {
pcjs.dropPcj(pcjId);
} catch (final PCJStorageException e) {
throw new RyaClientException("Could not drop the PCJ's table from Accumulo.", e);
}
}
use of org.apache.rya.api.instance.RyaDetails in project incubator-rya by apache.
the class AccumuloRemoveUserIT method removedUserNotInDetails.
/**
* Ensure that when a user is removed from a Rya instance that its details are updated to no longer include the user.
*/
@Test
public void removedUserNotInDetails() throws Exception {
final String adminUser = testInstance.createUniqueUser();
final String user = testInstance.createUniqueUser();
final SecurityOperations secOps = super.getConnector().securityOperations();
// Create the user that will install the instance of Rya.
secOps.createLocalUser(adminUser, new PasswordToken(adminUser));
secOps.grantSystemPermission(adminUser, SystemPermission.CREATE_TABLE);
final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(adminUser, adminUser.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(adminUser, adminUser));
// Create the user that will be added to the instance of Rya.
secOps.createLocalUser(user, new PasswordToken(user));
final RyaClient userBClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(user, user.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(user, user));
// Install the instance of Rya.
userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
// Add userB.
userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);
// Remove userA.
userBClient.getRemoveUser().get().removeUser(getRyaInstanceName(), adminUser);
// Ensure the Rya instance's details have been updated to include the added user.
final ImmutableList<String> expectedUsers = ImmutableList.<String>builder().add(user).build();
final RyaDetails details = userBClient.getGetInstanceDetails().getDetails(getRyaInstanceName()).get();
assertEquals(expectedUsers, details.getUsers());
}
use of org.apache.rya.api.instance.RyaDetails in project incubator-rya by apache.
the class MongoDeletePCJIT method deletePCJ.
@Test
public void deletePCJ() throws Exception {
final MongoConnectionDetails connectionDetails = getConnectionDetails();
final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
// Initialize the commands that will be used by this test.
final CreatePCJ createPCJ = ryaClient.getCreatePCJ();
final Install installRya = ryaClient.getInstall();
final InstallConfiguration installConf = InstallConfiguration.builder().setEnablePcjIndex(true).build();
installRya.install(conf.getRyaInstanceName(), installConf);
System.out.println(getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection("instance_details").find().first().toJson());
// Create a PCJ.
final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://TacoJoint>." + "}";
final String pcjId = createPCJ.createPCJ(conf.getRyaInstanceName(), sparql);
final DeletePCJ deletePCJ = ryaClient.getDeletePCJ();
deletePCJ.deletePCJ(conf.getRyaInstanceName(), pcjId);
// Verify the RyaDetails were updated to include the new PCJ.
final Optional<RyaDetails> ryaDetails = ryaClient.getGetInstanceDetails().getDetails(conf.getRyaInstanceName());
final ImmutableMap<String, PCJDetails> details = ryaDetails.get().getPCJIndexDetails().getPCJDetails();
final PCJDetails pcjDetails = details.get(pcjId);
assertNull(pcjDetails);
}
use of org.apache.rya.api.instance.RyaDetails in project incubator-rya by apache.
the class MongoGetInstanceDetailsIT method getDetails.
@Test
public void getDetails() throws MongoException, RyaClientException {
final String instanceName = "instance";
// Install an instance of Rya.
final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnablePcjIndex(true).build();
final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
final Install install = ryaClient.getInstall();
install.install(instanceName, installConfig);
// Verify the correct details were persisted.
final GetInstanceDetails getInstanceDetails = ryaClient.getGetInstanceDetails();
final Optional<RyaDetails> details = getInstanceDetails.getDetails(instanceName);
final RyaDetails expectedDetails = RyaDetails.builder().setRyaInstanceName(instanceName).setRyaVersion(details.get().getRyaVersion()).setTemporalIndexDetails(new TemporalIndexDetails(true)).setFreeTextDetails(new FreeTextIndexDetails(true)).setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).setProspectorDetails(new ProspectorDetails(Optional.<Date>absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.<Date>absent())).build();
assertEquals(expectedDetails, details.get());
}
Aggregations