Search in sources :

Example 1 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.

the class RyaDetailsFormatter method format.

/**
 * Pretty formats an instance of {@link RyaDetails}.
 *
 * @param storageType - The type of storage the instance is installed on. (not null)
 * @param details - The object to format. (not null)
 * @return A pretty render of the object.
 */
public String format(final StorageType storageType, final RyaDetails details) {
    requireNonNull(details);
    final StringBuilder report = new StringBuilder();
    report.append("General Metadata:\n");
    report.append("  Instance Name: ").append(details.getRyaInstanceName()).append("\n");
    report.append("  RYA Version: ").append(details.getRyaVersion()).append("\n");
    if (storageType == StorageType.ACCUMULO) {
        report.append("  Users: ").append(Joiner.on(", ").join(details.getUsers())).append("\n");
    }
    report.append("Secondary Indicies:\n");
    if (storageType == StorageType.ACCUMULO) {
        report.append("  Entity Centric Index:\n");
        report.append("    Enabled: ").append(details.getEntityCentricIndexDetails().isEnabled()).append("\n");
    }
    // RYA-215        report.append("  Geospatial Index:\n");
    // RYA-215        report.append("    Enabled: ").append( details.getGeoIndexDetails().isEnabled() ).append("\n");
    report.append("  Free Text Index:\n");
    report.append("    Enabled: ").append(details.getFreeTextIndexDetails().isEnabled()).append("\n");
    report.append("  Temporal Index:\n");
    report.append("    Enabled: ").append(details.getTemporalIndexDetails().isEnabled()).append("\n");
    report.append("  PCJ Index:\n");
    final PCJIndexDetails pcjDetails = details.getPCJIndexDetails();
    report.append("    Enabled: ").append(pcjDetails.isEnabled()).append("\n");
    if (pcjDetails.isEnabled()) {
        if (pcjDetails.getFluoDetails().isPresent()) {
            final String fluoAppName = pcjDetails.getFluoDetails().get().getUpdateAppName();
            report.append("    Fluo App Name: ").append(fluoAppName).append("\n");
        }
        final ImmutableMap<String, PCJDetails> pcjs = pcjDetails.getPCJDetails();
        report.append("    PCJs:\n");
        if (pcjs.isEmpty()) {
            report.append("      No PCJs have been added yet.\n");
        } else {
            for (final PCJDetails pcj : pcjs.values()) {
                report.append("      ID: ").append(pcj.getId()).append("\n");
                final String updateStrategy = format(pcj.getUpdateStrategy(), "None");
                report.append("        Update Strategy: ").append(updateStrategy).append("\n");
                final String lastUpdateTime = format(pcj.getLastUpdateTime(), "unavailable");
                report.append("        Last Update Time: ").append(lastUpdateTime).append("\n");
            }
        }
        if (storageType == StorageType.ACCUMULO) {
            report.append("Statistics:\n");
            report.append("  Prospector:\n");
            final String prospectorLastUpdateTime = format(details.getProspectorDetails().getLastUpdated(), "unavailable");
            report.append("    Last Update Time: ").append(prospectorLastUpdateTime).append("\n");
            report.append("  Join Selectivity:\n");
            final String jsLastUpdateTime = format(details.getJoinSelectivityDetails().getLastUpdated(), "unavailable");
            report.append("    Last Updated Time: ").append(jsLastUpdateTime).append("\n");
        }
    }
    return report.toString();
}
Also used : PCJIndexDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)

Example 2 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails 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);
    }
}
Also used : AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) RyaDetailsUpdater(org.apache.rya.api.instance.RyaDetailsUpdater) PcjException(org.apache.rya.indexing.pcj.storage.PcjException) UnsupportedQueryException(org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException) RyaDetails(org.apache.rya.api.instance.RyaDetails) AccumuloRyaInstanceDetailsRepository(org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MalformedQueryException(org.openrdf.query.MalformedQueryException) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) FluoDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails) PCJIndexDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetailsMutator(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator) CouldNotApplyMutationException(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException) RepositoryException(org.openrdf.repository.RepositoryException) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaDetailsRepository(org.apache.rya.api.instance.RyaDetailsRepository) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 3 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails 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);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) RyaDetails(org.apache.rya.api.instance.RyaDetails) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) FluoDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails) PCJIndexDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)

Example 4 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails 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);
}
Also used : CreatePCJ(org.apache.rya.api.client.CreatePCJ) AccumuloCreatePCJ(org.apache.rya.api.client.accumulo.AccumuloCreatePCJ) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) DeletePCJ(org.apache.rya.api.client.DeletePCJ) Install(org.apache.rya.api.client.Install) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) Test(org.junit.Test)

Example 5 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.

the class MongoPcjStorageIT method dropPCJ.

@Test
public void dropPCJ() throws Exception {
    try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
        final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
        detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
        // 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 ImmutableMap<String, PCJDetails> detailsMap = detailsRepo.getRyaInstanceDetails().getPCJIndexDetails().getPCJDetails();
        assertFalse(detailsMap.containsKey(pcjId));
    }
}
Also used : ProspectorDetails(org.apache.rya.api.instance.RyaDetails.ProspectorDetails) EntityCentricIndexDetails(org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails) TemporalIndexDetails(org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) FreeTextIndexDetails(org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) JoinSelectivityDetails(org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) Test(org.junit.Test)

Aggregations

PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)16 Test (org.junit.Test)9 RyaDetails (org.apache.rya.api.instance.RyaDetails)8 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)8 RyaDetailsRepository (org.apache.rya.api.instance.RyaDetailsRepository)6 AccumuloRyaInstanceDetailsRepository (org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository)5 RyaClientException (org.apache.rya.api.client.RyaClientException)5 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)5 RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)4 BasicDBObject (com.mongodb.BasicDBObject)3 Date (java.util.Date)3 CreatePCJ (org.apache.rya.api.client.CreatePCJ)3 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)3 PCJIndexDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)3 RyaDetailsUpdater (org.apache.rya.api.instance.RyaDetailsUpdater)3 RyaDetailsMutator (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator)3 CouldNotApplyMutationException (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException)3 MongoRyaInstanceDetailsRepository (org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository)3 Connector (org.apache.accumulo.core.client.Connector)2 Install (org.apache.rya.api.client.Install)2