Search in sources :

Example 11 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class RyaSailFactory method getMongoDAO.

/**
 * Connects to MongoDB and creates a MongoDBRyaDAO.
 * @param config - user configuration
 * @return - MongoDBRyaDAO with Indexers configured according to user's specification
 * @throws RyaDAOException if the DAO can't be initialized
 */
public static MongoDBRyaDAO getMongoDAO(MongoDBRdfConfiguration mongoConfig) throws RyaDAOException {
    // Create the MongoClient that will be used by the Sail object's components.
    final MongoClient client = createMongoClient(mongoConfig);
    // Add the Indexer and Optimizer names to the configuration object that are configured to be used.
    ConfigUtils.setIndexers(mongoConfig);
    // Populate the configuration using previously stored Rya Details if this instance uses them.
    try {
        final MongoRyaInstanceDetailsRepository ryaDetailsRepo = new MongoRyaInstanceDetailsRepository(client, mongoConfig.getRyaInstanceName());
        RyaDetailsToConfiguration.addRyaDetailsToConfiguration(ryaDetailsRepo.getRyaInstanceDetails(), mongoConfig);
    } catch (final RyaDetailsRepositoryException e) {
        LOG.info("Instance does not have a rya details collection, skipping.");
    }
    // Set the configuration to the stateful configuration that is used to pass the constructed objects around.
    final StatefulMongoDBRdfConfiguration statefulConfig = new StatefulMongoDBRdfConfiguration(mongoConfig, client);
    final List<MongoSecondaryIndex> indexers = statefulConfig.getInstances(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, MongoSecondaryIndex.class);
    statefulConfig.setIndexers(indexers);
    // Create the DAO that is able to interact with MongoDB.
    final MongoDBRyaDAO mongoDao = new MongoDBRyaDAO();
    mongoDao.setConf(statefulConfig);
    mongoDao.init();
    return mongoDao;
}
Also used : MongoClient(com.mongodb.MongoClient) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) MongoSecondaryIndex(org.apache.rya.mongodb.MongoSecondaryIndex)

Example 12 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class MongoPcjStorage method dropPcj.

@Override
public void dropPcj(final String pcjId) throws PCJStorageException {
    requireNonNull(pcjId);
    // PCJ.
    try {
        new RyaDetailsUpdater(ryaDetailsRepo).update(originalDetails -> {
            // Drop the PCJ's metadata from the instance's metadata.
            final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails);
            mutated.getPCJIndexDetails().removePCJDetails(pcjId);
            return mutated.build();
        });
    } catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
        throw new PCJStorageException(String.format("Could not drop an existing PCJ for Rya instance '%s' " + "because of a problem while updating the instance's details.", ryaInstanceName), e);
    }
    // Delete the table that hold's the PCJ's results.
    pcjDocs.dropPcj(pcjId);
}
Also used : RyaDetailsUpdater(org.apache.rya.api.instance.RyaDetailsUpdater) CouldNotApplyMutationException(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)

Example 13 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class AccumuloPcjStorage method dropPcj.

@Override
public void dropPcj(final String pcjId) throws PCJStorageException {
    requireNonNull(pcjId);
    // Update the Rya Details for this instance to no longer include the PCJ.
    try {
        new RyaDetailsUpdater(ryaDetailsRepo).update(originalDetails -> {
            // Drop the PCJ's metadata from the instance's metadata.
            final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails);
            mutated.getPCJIndexDetails().removePCJDetails(pcjId);
            return mutated.build();
        });
    } catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
        throw new PCJStorageException(String.format("Could not drop an existing PCJ for Rya instance '%s' " + "because of a problem while updating the instance's details.", ryaInstanceName), e);
    }
    // Delete the table that hold's the PCJ's results.
    final String pcjTableName = pcjTableNameFactory.makeTableName(ryaInstanceName, pcjId);
    pcjTables.dropPcjTable(accumuloConn, pcjTableName);
}
Also used : RyaDetailsUpdater(org.apache.rya.api.instance.RyaDetailsUpdater) CouldNotApplyMutationException(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)

Example 14 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class GeoRyaSailFactory method getRyaSail.

private static Sail getRyaSail(final Configuration config) throws InferenceEngineException, RyaDAOException, AccumuloException, AccumuloSecurityException, SailException {
    final RdfCloudTripleStore store = new RdfCloudTripleStore();
    final RyaDAO<?> dao;
    final RdfCloudTripleStoreConfiguration rdfConfig;
    final String user;
    final String pswd;
    // XXX Should(?) be MongoDBRdfConfiguration.MONGO_COLLECTION_PREFIX inside the if below. RYA-135
    final String ryaInstance = config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
    Objects.requireNonNull(ryaInstance, "RyaInstance or table prefix is missing from configuration." + RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX);
    if (ConfigUtils.getUseMongo(config)) {
        // Get a reference to a Mongo DB configuration object.
        final MongoDBRdfConfiguration mongoConfig = (config instanceof MongoDBRdfConfiguration) ? (MongoDBRdfConfiguration) config : new MongoDBRdfConfiguration(config);
        // Create the MongoClient that will be used by the Sail object's components.
        final MongoClient client = createMongoClient(mongoConfig);
        // Add the Indexer and Optimizer names to the configuration object that are configured to be used.
        OptionalConfigUtils.setIndexers(mongoConfig);
        // Populate the configuration using previously stored Rya Details if this instance uses them.
        try {
            final MongoRyaInstanceDetailsRepository ryaDetailsRepo = new MongoRyaInstanceDetailsRepository(client, mongoConfig.getRyaInstanceName());
            RyaDetailsToConfiguration.addRyaDetailsToConfiguration(ryaDetailsRepo.getRyaInstanceDetails(), mongoConfig);
        } catch (final RyaDetailsRepositoryException e) {
            LOG.info("Instance does not have a rya details collection, skipping.");
        }
        // Set the configuration to the stateful configuration that is used to pass the constructed objects around.
        final StatefulMongoDBRdfConfiguration statefulConfig = new StatefulMongoDBRdfConfiguration(mongoConfig, client);
        final List<MongoSecondaryIndex> indexers = statefulConfig.getInstances(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, MongoSecondaryIndex.class);
        statefulConfig.setIndexers(indexers);
        rdfConfig = statefulConfig;
        // Create the DAO that is able to interact with MongoDB.
        final MongoDBRyaDAO mongoDao = new MongoDBRyaDAO();
        mongoDao.setConf(statefulConfig);
        mongoDao.init();
        dao = mongoDao;
    } else {
        rdfConfig = new AccumuloRdfConfiguration(config);
        user = rdfConfig.get(ConfigUtils.CLOUDBASE_USER);
        pswd = rdfConfig.get(ConfigUtils.CLOUDBASE_PASSWORD);
        Objects.requireNonNull(user, "Accumulo user name is missing from configuration." + ConfigUtils.CLOUDBASE_USER);
        Objects.requireNonNull(pswd, "Accumulo user password is missing from configuration." + ConfigUtils.CLOUDBASE_PASSWORD);
        rdfConfig.setTableLayoutStrategy(new TablePrefixLayoutStrategy(ryaInstance));
        RyaSailFactory.updateAccumuloConfig((AccumuloRdfConfiguration) rdfConfig, user, pswd, ryaInstance);
        dao = getAccumuloDAO((AccumuloRdfConfiguration) rdfConfig);
    }
    store.setRyaDAO(dao);
    rdfConfig.setTablePrefix(ryaInstance);
    if (rdfConfig.isInfer()) {
        final InferenceEngine inferenceEngine = new InferenceEngine();
        inferenceEngine.setConf(rdfConfig);
        inferenceEngine.setRyaDAO(dao);
        inferenceEngine.init();
        store.setInferenceEngine(inferenceEngine);
    }
    store.initialize();
    return store;
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) MongoSecondaryIndex(org.apache.rya.mongodb.MongoSecondaryIndex) MongoClient(com.mongodb.MongoClient) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) InferenceEngine(org.apache.rya.rdftriplestore.inference.InferenceEngine) TablePrefixLayoutStrategy(org.apache.rya.api.layout.TablePrefixLayoutStrategy) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)

Example 15 with RyaDetailsRepositoryException

use of org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException in project incubator-rya by apache.

the class AccumuloRemoveUser method removeUser.

@Override
public void removeUser(final String instanceName, final String username) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(instanceName);
    requireNonNull(username);
    // Update the instance details.
    final RyaDetailsUpdater updater = new RyaDetailsUpdater(new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName));
    try {
        updater.update(originalDetails -> RyaDetails.builder(originalDetails).removeUser(username).build());
    } catch (RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
        throw new RyaClientException("Could not remove the user '" + username + "' from the Rya instance's details.", e);
    }
    // Revoke all access to all the instance's tables.
    try {
        // Build the list of tables that are present within the Rya instance.
        final List<String> tables = new RyaTableNames().getTableNames(instanceName, getConnector());
        // Update the user permissions for those tables.
        for (final String table : tables) {
            try {
                TABLE_PERMISSIONS.revokeAllPermissions(username, table, getConnector());
            } catch (AccumuloException | AccumuloSecurityException e) {
                throw new RyaClientException("Could not revoke access to table '" + table + "' from user '" + username + "'.", e);
            }
        }
    } catch (PCJStorageException | RyaDetailsRepositoryException e) {
        throw new RyaClientException("Could not determine which tables exist for the '" + instanceName + "' instance of Rya.", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetailsUpdater(org.apache.rya.api.instance.RyaDetailsUpdater) CouldNotApplyMutationException(org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException) AccumuloRyaInstanceDetailsRepository(org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository) RyaTableNames(org.apache.rya.accumulo.utils.RyaTableNames) RyaDetailsRepositoryException(org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Aggregations

RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)23 RyaDetails (org.apache.rya.api.instance.RyaDetails)15 RyaClientException (org.apache.rya.api.client.RyaClientException)12 RyaDetailsUpdater (org.apache.rya.api.instance.RyaDetailsUpdater)10 CouldNotApplyMutationException (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException)10 RyaDetailsRepository (org.apache.rya.api.instance.RyaDetailsRepository)9 AccumuloRyaInstanceDetailsRepository (org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)6 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)6 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)6 PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)6 MongoRyaInstanceDetailsRepository (org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository)6 NotInitializedException (org.apache.rya.api.instance.RyaDetailsRepository.NotInitializedException)4 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)4 RyaTableNames (org.apache.rya.accumulo.utils.RyaTableNames)3 PCJIndexDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)3 RyaDetailsMutator (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator)3 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)3 StatefulMongoDBRdfConfiguration (org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration)3 SailException (org.openrdf.sail.SailException)3