Search in sources :

Example 1 with MergerException

use of org.apache.rya.export.api.MergerException in project incubator-rya by apache.

the class AccumuloParentMetadataRepository method set.

@Override
public void set(final MergeParentMetadata metadata) throws ParentMetadataExistsException {
    try {
        createTableIfNeeded();
        writeMetadata(metadata);
    } catch (final MergerException e) {
        throw new ParentMetadataExistsException("Unable to set MergeParentMetadata", e);
    }
}
Also used : ParentMetadataExistsException(org.apache.rya.export.api.metadata.ParentMetadataExistsException) MergerException(org.apache.rya.export.api.MergerException)

Example 2 with MergerException

use of org.apache.rya.export.api.MergerException in project incubator-rya by apache.

the class AccumuloParentMetadataRepository method createTableIfNeeded.

private void createTableIfNeeded() throws MergerException {
    try {
        if (!doesMetadataTableExist()) {
            log.debug("Creating table: " + mergeParentMetadataTableName);
            connector.tableOperations().create(mergeParentMetadataTableName);
            log.debug("Created table: " + mergeParentMetadataTableName);
            log.debug("Granting authorizations to table: " + mergeParentMetadataTableName);
            final String username = accumuloRyaDao.getConf().get(MRUtils.AC_USERNAME_PROP);
            connector.securityOperations().grantTablePermission(username, mergeParentMetadataTableName, TablePermission.WRITE);
            log.debug("Granted authorizations to table: " + mergeParentMetadataTableName);
        }
    } catch (final TableExistsException | AccumuloException | AccumuloSecurityException e) {
        throw new MergerException("Could not create a new MergeParentMetadata table named: " + mergeParentMetadataTableName, e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) MergerException(org.apache.rya.export.api.MergerException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 3 with MergerException

use of org.apache.rya.export.api.MergerException in project incubator-rya by apache.

the class AccumuloParentMetadataRepository method writeMetadata.

private void writeMetadata(final MergeParentMetadata metadata) throws MergerException {
    BatchWriter writer = null;
    try {
        // Write each result.
        final List<Mutation> mutations = makeWriteMetadataMutations(metadata);
        writer = connector.createBatchWriter(mergeParentMetadataTableName, new BatchWriterConfig());
        writer.addMutations(mutations);
    } catch (final AccumuloException | TableNotFoundException e) {
        throw new MergerException("Unable to set MergeParentMetadata in Accumulo", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final MutationsRejectedException e) {
                throw new MergerException("Could not add results to a MergeParentMetadata table because some of the mutations were rejected.", e);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MergerException(org.apache.rya.export.api.MergerException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 4 with MergerException

use of org.apache.rya.export.api.MergerException in project incubator-rya by apache.

the class MergeDriverClient method main.

public static void main(final String[] args) throws ParseException, MergeConfigurationException, UnknownHostException, MergerException, java.text.ParseException, SailException, AccumuloException, AccumuloSecurityException, InferenceEngineException, RepositoryException, MalformedQueryException, UpdateExecutionException {
    final String log4jConfiguration = System.getProperties().getProperty("log4j.configuration");
    if (StringUtils.isNotBlank(log4jConfiguration)) {
        final String parsedConfiguration = PathUtils.clean(StringUtils.removeStart(log4jConfiguration, "file:"));
        final File configFile = new File(parsedConfiguration);
        if (configFile.exists()) {
            DOMConfigurator.configure(parsedConfiguration);
        } else {
            BasicConfigurator.configure();
        }
    }
    final MergeConfigurationCLI config = new MergeConfigurationCLI(args);
    try {
        configuration = config.createConfiguration();
    } catch (final MergeConfigurationException e) {
        LOG.error("Configuration failed.", e);
    }
    final boolean useTimeSync = configuration.getUseNtpServer();
    Optional<Long> offset = Optional.absent();
    if (useTimeSync) {
        final String tomcat = configuration.getChildTomcatUrl();
        final String ntpHost = configuration.getNtpServerHost();
        try {
            offset = Optional.<Long>fromNullable(TimeUtils.getNtpServerAndMachineTimeDifference(ntpHost, tomcat));
        } catch (final IOException e) {
            LOG.error("Unable to get time difference between time server: " + ntpHost + " and the server: " + tomcat, e);
        }
    }
    final StatementStoreFactory storeFactory = new StatementStoreFactory(configuration);
    try {
        final RyaStatementStore parentStore = storeFactory.getParentStatementStore();
        final RyaStatementStore childStore = storeFactory.getChildStatementStore();
        LOG.info("Starting Merge Tool");
        if (configuration.getParentDBType() == ACCUMULO && configuration.getChildDBType() == ACCUMULO) {
            final AccumuloRyaStatementStore childAStore = (AccumuloRyaStatementStore) childStore;
            final AccumuloRyaStatementStore parentAStore = (AccumuloRyaStatementStore) parentStore;
        // do map reduce merging.
        // TODO: Run Merger
        } else {
            if (configuration.getMergePolicy() == TIMESTAMP) {
                final TimestampPolicyMergeConfiguration timeConfig = (TimestampPolicyMergeConfiguration) configuration;
                final Long timeOffset;
                if (offset.isPresent()) {
                    timeOffset = offset.get();
                } else {
                    timeOffset = 0L;
                }
                final MemoryTimeMerger merger = new MemoryTimeMerger(parentStore, childStore, new VisibilityStatementMerger(), timeConfig.getToolStartTime(), configuration.getParentRyaInstanceName(), timeOffset);
                merger.runJob();
            }
        }
    } catch (final Exception e) {
        LOG.error("Something went wrong creating a Rya Statement Store connection.", e);
    }
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            LOG.error("Uncaught exception in " + thread.getName(), throwable);
        }
    });
    LOG.info("Finished running Merge Tool");
    System.exit(1);
}
Also used : StatementStoreFactory(org.apache.rya.export.client.merge.StatementStoreFactory) TimestampPolicyMergeConfiguration(org.apache.rya.export.api.conf.policy.TimestampPolicyMergeConfiguration) VisibilityStatementMerger(org.apache.rya.export.client.merge.VisibilityStatementMerger) MemoryTimeMerger(org.apache.rya.export.client.merge.MemoryTimeMerger) IOException(java.io.IOException) MergeConfigurationCLI(org.apache.rya.export.client.conf.MergeConfigurationCLI) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) SailException(org.openrdf.sail.SailException) RepositoryException(org.openrdf.repository.RepositoryException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) UpdateExecutionException(org.openrdf.query.UpdateExecutionException) MalformedQueryException(org.openrdf.query.MalformedQueryException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MergerException(org.apache.rya.export.api.MergerException) ParseException(org.apache.commons.cli.ParseException) MergeConfigurationException(org.apache.rya.export.api.conf.MergeConfigurationException) MergeConfigurationException(org.apache.rya.export.api.conf.MergeConfigurationException) AccumuloRyaStatementStore(org.apache.rya.export.accumulo.AccumuloRyaStatementStore) File(java.io.File) AccumuloRyaStatementStore(org.apache.rya.export.accumulo.AccumuloRyaStatementStore) RyaStatementStore(org.apache.rya.export.api.store.RyaStatementStore)

Aggregations

MergerException (org.apache.rya.export.api.MergerException)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 File (java.io.File)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 BatchWriter (org.apache.accumulo.core.client.BatchWriter)1 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 Mutation (org.apache.accumulo.core.data.Mutation)1 ParseException (org.apache.commons.cli.ParseException)1 AccumuloRyaStatementStore (org.apache.rya.export.accumulo.AccumuloRyaStatementStore)1 MergeConfigurationException (org.apache.rya.export.api.conf.MergeConfigurationException)1 TimestampPolicyMergeConfiguration (org.apache.rya.export.api.conf.policy.TimestampPolicyMergeConfiguration)1 ParentMetadataExistsException (org.apache.rya.export.api.metadata.ParentMetadataExistsException)1 RyaStatementStore (org.apache.rya.export.api.store.RyaStatementStore)1 MergeConfigurationCLI (org.apache.rya.export.client.conf.MergeConfigurationCLI)1 MemoryTimeMerger (org.apache.rya.export.client.merge.MemoryTimeMerger)1