Search in sources :

Example 1 with PCJIndexDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails 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 PCJIndexDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails 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 PCJIndexDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails 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 PCJIndexDetails

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

the class RyaDetailsToConfiguration method addRyaDetailsToConfiguration.

/**
 * Ensures the values in the {@link Configuration} do not conflict with the values in {@link RyaDetails}.
 * If they do, the values in {@link RyaDetails} take precedent and the {@link Configuration} value will
 * be overwritten.
 *
 * @param details - The {@link RyaDetails} to add to the {@link Configuration}. (not null)
 * @param conf - The {@link Configuration} to add {@link RyaDetails} to. (not null)
 */
public static void addRyaDetailsToConfiguration(final RyaDetails details, final Configuration conf) {
    requireNonNull(details);
    requireNonNull(conf);
    checkAndSet(conf, ConfigurationFields.USE_ENTITY, details.getEntityCentricIndexDetails().isEnabled());
    checkAndSet(conf, ConfigurationFields.USE_FREETEXT, details.getFreeTextIndexDetails().isEnabled());
    // RYA-215        checkAndSet(conf, ConfigurationFields.USE_GEO, details.getGeoIndexDetails().isEnabled());
    checkAndSet(conf, ConfigurationFields.USE_TEMPORAL, details.getTemporalIndexDetails().isEnabled());
    final PCJIndexDetails pcjDetails = details.getPCJIndexDetails();
    if (conf.getBoolean(ConfigurationFields.USE_MONGO, false)) {
        if (pcjDetails.isEnabled()) {
            conf.set(ConfigurationFields.PCJ_STORAGE_TYPE, "MONGO");
            // mongo does not currently support pcj updaters
            checkAndSet(conf, ConfigurationFields.USE_PCJ_UPDATER, false);
            conf.set(ConfigurationFields.PCJ_UPDATER_TYPE, "NO_UPDATE");
        }
    } else {
        if (pcjDetails.isEnabled()) {
            conf.set(ConfigurationFields.PCJ_STORAGE_TYPE, "ACCUMULO");
            if (pcjDetails.getFluoDetails().isPresent()) {
                checkAndSet(conf, ConfigurationFields.USE_PCJ_UPDATER, true);
                conf.set(ConfigurationFields.FLUO_APP_NAME, pcjDetails.getFluoDetails().get().getUpdateAppName());
                conf.set(ConfigurationFields.PCJ_UPDATER_TYPE, "FLUO");
            } else {
                checkAndSet(conf, ConfigurationFields.USE_PCJ_UPDATER, false);
                conf.set(ConfigurationFields.PCJ_UPDATER_TYPE, "NO_UPDATE");
            }
        }
    }
}
Also used : PCJIndexDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)

Example 5 with PCJIndexDetails

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

the class AccumuloListIncrementalQueries method listIncrementalQueries.

@Override
public String listIncrementalQueries(String instanceName) throws RyaClientException {
    requireNonNull(instanceName);
    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));
    }
    // 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 {
            return getFluoQueryString(instanceName, fluoAppName);
        } catch (Exception e) {
            throw new RyaClientException("Problem while creating Fluo Query Strings.", e);
        }
    } else {
        throw new RyaClientException(String.format("The '%s' instance of Rya does not have Fluo incremental updating enabled.", instanceName));
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetails(org.apache.rya.api.instance.RyaDetails) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) FluoDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails) RyaClientException(org.apache.rya.api.client.RyaClientException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) PCJIndexDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)

Aggregations

PCJIndexDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)9 RyaDetails (org.apache.rya.api.instance.RyaDetails)7 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)5 RyaClientException (org.apache.rya.api.client.RyaClientException)5 FluoDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails)5 PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)3 RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)3 UnsupportedQueryException (org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException)3 MalformedQueryException (org.openrdf.query.MalformedQueryException)3 ArrayList (java.util.ArrayList)2 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)2 PcjException (org.apache.rya.indexing.pcj.storage.PcjException)2 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)2 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)2 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)2 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)2 RepositoryException (org.openrdf.repository.RepositoryException)2 SailException (org.openrdf.sail.SailException)2 AccumuloRyaInstanceDetailsRepository (org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository)1 RyaDetailsRepository (org.apache.rya.api.instance.RyaDetailsRepository)1