Repository: incubator-rya Updated Branches: refs/heads/master c941aea8b -> 4b755c64d
RYA-254 Closes #143, Added a factory method to the ProspectorServiceEvalStatsDAO to make it more convenient to construct. This required moving some of the Accumulo specific configuration parameters into the AccumuloRdfConfiguration object from ConfigUtils. Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/4b755c64 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/4b755c64 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/4b755c64 Branch: refs/heads/master Commit: 4b755c64debdf9ca2e137eab7cdc1a2a890cdb69 Parents: c941aea Author: Kevin Chilton <kevin.chil...@parsons.com> Authored: Mon Mar 6 17:11:30 2017 -0500 Committer: pujav65 <puja...@gmail.com> Committed: Fri May 5 11:37:54 2017 -0400 ---------------------------------------------------------------------- .../rya/accumulo/AccumuloRdfConfiguration.java | 73 ++++++++++--- .../rya/accumulo/utils/ConnectorFactory.java | 74 +++++++++++++ .../rya/indexing/accumulo/ConfigUtils.java | 109 +++++++++++++------ .../accumulo/entity/EntityOptimizer.java | 5 +- .../apache/rya/sail/config/RyaSailFactory.java | 7 +- .../prospector/service/ProspectorService.java | 13 ++- .../service/ProspectorServiceEvalStatsDAO.java | 24 +++- 7 files changed, 241 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4b755c64/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfiguration.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfiguration.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfiguration.java index d988b20..0200cf7 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfiguration.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/AccumuloRdfConfiguration.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.security.Authorizations; import org.apache.hadoop.conf.Configuration; @@ -34,25 +35,18 @@ import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; - -/** - * Created by IntelliJ IDEA. - * Date: 4/25/12 - * Time: 3:24 PM - * To change this template use File | Settings | File Templates. - */ public class AccumuloRdfConfiguration extends RdfCloudTripleStoreConfiguration { + public static final String USE_MOCK_INSTANCE = ".useMockInstance"; public static final String CLOUDBASE_INSTANCE = "sc.cloudbase.instancename"; public static final String CLOUDBASE_ZOOKEEPERS = "sc.cloudbase.zookeepers"; public static final String CLOUDBASE_USER = "sc.cloudbase.username"; public static final String CLOUDBASE_PASSWORD = "sc.cloudbase.password"; - public static final String USE_MOCK_INSTANCE = ".useMockInstance"; - + public static final String MAXRANGES_SCANNER = "ac.query.maxranges"; - + public static final String CONF_ADDITIONAL_INDEXERS = "ac.additional.indexers"; - + public static final String CONF_FLUSH_EACH_UPDATE = "ac.dao.flush"; public static final String ITERATOR_SETTINGS_SIZE = "ac.iterators.size"; @@ -210,10 +204,61 @@ public class AccumuloRdfConfiguration extends RdfCloudTripleStoreConfiguration { } + /** + * Indicates that a Mock instance of Accumulo is being used to back the Rya instance. + * + * @return {@code true} if the Rya instance is backed by a mock Accumulo; otherwise {@code false}. + */ + public boolean useMockInstance() { + return super.getBoolean(USE_MOCK_INSTANCE, false); + } + + /** + * Get the Accumulo username from the configuration object that is meant to + * be used when connecting a {@link Connector} to Accumulo. + * + * @return The username if one could be found; otherwise {@code null}. + */ + public String getUsername() { + return super.get(CLOUDBASE_USER); + } + + /** + * Get the Accumulo password from the configuration object that is meant to + * be used when connecting a {@link Connector} to Accumulo. + * + * @return The password if one could be found; otherwise an empty string. + */ + public String getPassword() { + return super.get(CLOUDBASE_PASSWORD, ""); + } + + /** + * Get the Accumulo instance name from the configuration object that is + * meant to be used when connecting a {@link Connector} to Accumulo. + * + * @return The instance name if one could be found; otherwise {@code null}. + */ + public String getInstanceName() { + return super.get(CLOUDBASE_INSTANCE); + } + + /** + * Get a comma delimited list of the names of the Zookeeper servers from + * the configuration object that is meant to be used when connecting a + * {@link Connector} to Accumulo. + * + * @return The zookeepers list if one could be found; otherwise {@code null}. + */ + public String getZookeepers() { + return super.get(CLOUDBASE_ZOOKEEPERS); + } + public Authorizations getAuthorizations() { String[] auths = getAuths(); - if (auths == null || auths.length == 0) + if (auths == null || auths.length == 0) { return AccumuloRdfConstants.ALL_AUTHORIZATIONS; + } return new Authorizations(auths); } @@ -230,7 +275,7 @@ public class AccumuloRdfConfiguration extends RdfCloudTripleStoreConfiguration { for (Class<? extends AccumuloIndexer> ai : indexers){ strs.add(ai.getName()); } - + setStrings(CONF_ADDITIONAL_INDEXERS, strs.toArray(new String[]{})); } @@ -281,7 +326,7 @@ public class AccumuloRdfConfiguration extends RdfCloudTripleStoreConfiguration { int priority = Integer.valueOf(this.get(String.format(ITERATOR_SETTINGS_PRIORITY, i))); int optionsSize = Integer.valueOf(this.get(String.format(ITERATOR_SETTINGS_OPTIONS_SIZE, i))); - Map<String, String> options = new HashMap<String, String>(optionsSize); + Map<String, String> options = new HashMap<>(optionsSize); for(int j = 0; j < optionsSize; j++) { String key = this.get(String.format(ITERATOR_SETTINGS_OPTIONS_KEY, i, j)); String value = this.get(String.format(ITERATOR_SETTINGS_OPTIONS_VALUE, i, j)); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4b755c64/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/utils/ConnectorFactory.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/utils/ConnectorFactory.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/utils/ConnectorFactory.java new file mode 100644 index 0000000..6fb3daa --- /dev/null +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/utils/ConnectorFactory.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.accumulo.utils; + +import static java.util.Objects.requireNonNull; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.ZooKeeperInstance; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * A utility class that helps create instances of {@link Connector}. + */ +@DefaultAnnotation(NonNull.class) +public class ConnectorFactory { + + /** + * Private constructor to prevent instantiation. + */ + private ConnectorFactory() { } + + /** + * Create a {@link Connector} that connects to an Accumulo instance. The {@link AccumuloRdfConfiguration#USE_MOCK_INSTANCE} + * flag must be set if the configuration information needs to connect to a mock instance of Accumulo. If this is + * the case, then the Zookeepers information should not be set. + * + * @param config - The configuration that will be used to initialize the connector. (not null) + * @return The {@link Connector} that was created by {@code config}. + * @throws AccumuloException The connector couldn't be created because of an Accumulo problem. + * @throws AccumuloSecurityException The connector couldn't be created because of an Accumulo security violation. + */ + public static Connector connect(AccumuloRdfConfiguration config) throws AccumuloException, AccumuloSecurityException { + requireNonNull(config); + + // Wrap the configuration as the Accumulo configuration so that we may have access + // to Accumulo specific configuration values. + final AccumuloRdfConfiguration accConf = new AccumuloRdfConfiguration(config); + + // Create the Mock or Zookeeper backed Instance depending on the configuration. + final Instance instance; + if(accConf.useMockInstance()) { + instance = new MockInstance(accConf.getInstanceName()); + } else { + instance = new ZooKeeperInstance(accConf.getInstanceName(), accConf.getZookeepers()); + } + + // Return a connector using the configured username and password. + return instance.getConnector(accConf.getUsername(), new PasswordToken(accConf.getPassword())); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4b755c64/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java index 17438b1..41ae9ad 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/ConfigUtils.java @@ -1,5 +1,3 @@ -package org.apache.rya.indexing.accumulo; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ package org.apache.rya.indexing.accumulo; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.indexing.accumulo; import static java.util.Objects.requireNonNull; @@ -44,6 +43,7 @@ import org.apache.hadoop.mapreduce.JobContext; import org.apache.hadoop.util.ReflectionUtils; import org.apache.log4j.Logger; import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.accumulo.utils.ConnectorFactory; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.instance.RyaDetails; import org.apache.rya.indexing.FilterFunctionOptimizer; @@ -67,48 +67,45 @@ import com.google.common.base.Optional; import com.google.common.collect.Lists; /** - * A set of configuration utils to read a Hadoop {@link Configuration} object - * and create Cloudbase/Accumulo objects. Soon will deprecate this class. Use - * installer for the set methods, use {@link RyaDetails} for the get methods. - * New code must separate parameters that are set at Rya install time from that - * which is specific to the client. Also Accumulo index tables are pushed down - * to the implementation and not configured in conf. + * A set of configuration utils to read a Hadoop {@link Configuration} object and create Cloudbase/Accumulo objects. + * Soon will deprecate this class. Use installer for the set methods, use {@link RyaDetails} for the get methods. + * New code must separate parameters that are set at Rya install time from that which is specific to the client. + * Also Accumulo index tables are pushed down to the implementation and not configured in conf. */ public class ConfigUtils { private static final Logger logger = Logger.getLogger(ConfigUtils.class); /** - * @Deprecated use {@link RdfCloudTripleStoreConfiguration#CONF_TBL_PREFIX} - * instead + * @Deprecated use {@link RdfCloudTripleStoreConfiguration#CONF_TBL_PREFIX} instead. */ @Deprecated public static final String CLOUDBASE_TBL_PREFIX = RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX; + /** - * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_INSTANCE} - * instead + * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_INSTANCE} instead. */ @Deprecated public static final String CLOUDBASE_INSTANCE = AccumuloRdfConfiguration.CLOUDBASE_INSTANCE; + /** - * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_ZOOKEEPERS} - * instead + * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_ZOOKEEPERS} instead. */ @Deprecated public static final String CLOUDBASE_ZOOKEEPERS = AccumuloRdfConfiguration.CLOUDBASE_ZOOKEEPERS; + /** - * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_USER} instead + * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_USER} instead. */ @Deprecated public static final String CLOUDBASE_USER = AccumuloRdfConfiguration.CLOUDBASE_USER; + /** - * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_PASSWORD} - * instead + * @Deprecated use {@link AccumuloRdfConfiguration#CLOUDBASE_PASSWORD} instead. */ @Deprecated public static final String CLOUDBASE_PASSWORD = AccumuloRdfConfiguration.CLOUDBASE_PASSWORD; /** - * @Deprecated use {@link RdfCloudTripleStoreConfiguration#CONF_QUERY_AUTH} - * instead + * @Deprecated use {@link RdfCloudTripleStoreConfiguration#CONF_QUERY_AUTH} instead. */ @Deprecated public static final String CLOUDBASE_AUTHS = RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH; @@ -233,7 +230,7 @@ public class ConfigUtils { protected static Set<URI> getPredicates(final Configuration conf, final String confName) { final String[] validPredicateStrings = conf.getStrings(confName, new String[] {}); - final Set<URI> predicates = new HashSet<URI>(); + final Set<URI> predicates = new HashSet<>(); for (final String prediateString : validPredicateStrings) { predicates.add(new URIImpl(prediateString)); } @@ -300,8 +297,15 @@ public class ConfigUtils { return getUsername(job.getConfiguration()); } + /** + * Get the Accumulo username from the configuration object that is meant to + * be used when connecting a {@link Connector} to Accumulo. + * + * @param conf - The configuration object that will be interrogated. (not null) + * @return The username if one could be found; otherwise {@code null}. + */ public static String getUsername(final Configuration conf) { - return conf.get(CLOUDBASE_USER); + return new AccumuloRdfConfiguration(conf).getUsername(); } public static Authorizations getAuthorizations(final JobContext job) { @@ -320,33 +324,71 @@ public class ConfigUtils { return getInstance(job.getConfiguration()); } + /** + * Create an {@link Instance} that may be used to create {@link Connector}s + * to Accumulo. If the configuration has the {@link #USE_MOCK_INSTANCE} flag + * set, then the instance will be be a {@link MockInstance} instead of a + * Zookeeper backed instance. + * + * @param conf - The configuration object that will be interrogated. (not null) + * @return The {@link Instance} that may be used to connect to Accumulo. + */ public static Instance getInstance(final Configuration conf) { + // Pull out the Accumulo specific configuration values. + final AccumuloRdfConfiguration accConf = new AccumuloRdfConfiguration(conf); + String instanceName = accConf.getInstanceName(); + String zoookeepers = accConf.getZookeepers(); + + // Create an Instance a mock if the mock flag is set. if (useMockInstance(conf)) { - return new MockInstance(conf.get(CLOUDBASE_INSTANCE)); + return new MockInstance(instanceName); } - return new ZooKeeperInstance(conf.get(CLOUDBASE_INSTANCE), conf.get(CLOUDBASE_ZOOKEEPERS)); + + // Otherwise create an Instance to a Zookeeper managed instance of Accumulo. + return new ZooKeeperInstance(instanceName, zoookeepers); } public static String getPassword(final JobContext job) { return getPassword(job.getConfiguration()); } + /** + * Get the Accumulo password from the configuration object that is meant to + * be used when connecting a {@link Connector} to Accumulo. + * + * @param conf - The configuration object that will be interrogated. (not null) + * @return The password if one could be found; otherwise an empty string. + */ public static String getPassword(final Configuration conf) { - return conf.get(CLOUDBASE_PASSWORD, ""); + return new AccumuloRdfConfiguration(conf).getPassword(); } public static Connector getConnector(final JobContext job) throws AccumuloException, AccumuloSecurityException { return getConnector(job.getConfiguration()); } + /** + * Create an Accumulo {@link Connector} using the configured connection information. + * If the connection information points to a mock instance of Accumulo, then the + * {@link #USE_MOCK_INSTANCE} flag must be set. + * + * @param conf - Configures how the connector will be built. (not null) + * @return A {@link Connector} that may be used to interact with the configured Accumulo instance. + * @throws AccumuloException The connector couldn't be created because of an Accumulo problem. + * @throws AccumuloSecurityException The connector couldn't be created because of an Accumulo security violation. + */ public static Connector getConnector(final Configuration conf) throws AccumuloException, AccumuloSecurityException { - final Instance instance = ConfigUtils.getInstance(conf); - - return instance.getConnector(getUsername(conf), getPassword(conf)); + return ConnectorFactory.connect( new AccumuloRdfConfiguration(conf) ); } + /** + * Indicates that a Mock instance of Accumulo is being used to back the Rya instance. + * + * @param conf - The configuration object that will be interrogated. (not null) + * @return {@code true} if the Rya instance is backed by a mock Accumulo; otherwise {@code false}. + */ public static boolean useMockInstance(final Configuration conf) { - return conf.getBoolean(USE_MOCK_INSTANCE, false); + return new AccumuloRdfConfiguration(conf).useMockInstance(); } protected static int getNumPartitions(final Configuration conf) { @@ -420,10 +462,9 @@ public class ConfigUtils { useFilterIndex = true; } } else { - - if (getUsePCJ(conf) || getUseOptimalPCJ(conf)) { - conf.setPcjOptimizer(PCJOptimizer.class); - } + if (getUsePCJ(conf) || getUseOptimalPCJ(conf)) { + conf.setPcjOptimizer(PCJOptimizer.class); + } if (getUsePcjUpdaterIndex(conf)) { indexList.add(PrecomputedJoinIndexer.class.getName()); @@ -455,7 +496,5 @@ public class ConfigUtils { conf.setStrings(AccumuloRdfConfiguration.CONF_ADDITIONAL_INDEXERS, indexList.toArray(new String[] {})); conf.setStrings(RdfCloudTripleStoreConfiguration.CONF_OPTIMIZERS, optimizers.toArray(new String[] {})); - } - -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4b755c64/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityOptimizer.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityOptimizer.java b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityOptimizer.java index 244493a..d06cfd7 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityOptimizer.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/accumulo/entity/EntityOptimizer.java @@ -27,7 +27,6 @@ import java.util.Set; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; -import org.apache.accumulo.core.client.TableExistsException; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; import org.apache.rya.accumulo.AccumuloRdfConfiguration; @@ -72,7 +71,7 @@ public class EntityOptimizer implements QueryOptimizer, Configurable { eval = new AccumuloSelectivityEvalDAO(conf, ConfigUtils.getConnector(conf)); ((AccumuloSelectivityEvalDAO)eval).setRdfEvalDAO(new ProspectorServiceEvalStatsDAO(ConfigUtils.getConnector(conf), conf)); eval.init(); - } catch (final AccumuloException | AccumuloSecurityException | TableExistsException e) { + } catch (final AccumuloException | AccumuloSecurityException e) { LOG.warn("A problem was encountered while constructing the EntityOptimizer.", e); } @@ -104,7 +103,7 @@ public class EntityOptimizer implements QueryOptimizer, Configurable { eval = new AccumuloSelectivityEvalDAO(this.conf, ConfigUtils.getConnector(this.conf)); ((AccumuloSelectivityEvalDAO)eval).setRdfEvalDAO(new ProspectorServiceEvalStatsDAO(ConfigUtils.getConnector(this.conf), this.conf)); eval.init(); - } catch (final AccumuloException | AccumuloSecurityException | TableExistsException e) { + } catch (final AccumuloException | AccumuloSecurityException e) { LOG.warn("A problem was encountered while setting the Configuration for the EntityOptimizer.", e); } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4b755c64/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java index 68f1394..bdb33ce 100644 --- a/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java +++ b/extras/indexing/src/main/java/org/apache/rya/sail/config/RyaSailFactory.java @@ -26,8 +26,6 @@ import java.util.Objects; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; -import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.hadoop.conf.Configuration; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; @@ -147,9 +145,8 @@ public class RyaSailFactory { public static void updateAccumuloConfig(final AccumuloRdfConfiguration config, final String user, final String pswd, final String ryaInstance) throws AccumuloException, AccumuloSecurityException { try { - final PasswordToken pswdToken = new PasswordToken(pswd); - final Instance accInst = ConfigUtils.getInstance(config); - final AccumuloRyaInstanceDetailsRepository ryaDetailsRepo = new AccumuloRyaInstanceDetailsRepository(accInst.getConnector(user, pswdToken), ryaInstance); + final Connector connector = ConfigUtils.getConnector(config); + final AccumuloRyaInstanceDetailsRepository ryaDetailsRepo = new AccumuloRyaInstanceDetailsRepository(connector, ryaInstance); RyaDetailsToConfiguration.addRyaDetailsToConfiguration(ryaDetailsRepo.getRyaInstanceDetails(), config); } catch(final RyaDetailsRepositoryException e) { LOG.info("Instance does not have a rya details collection, skipping."); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4b755c64/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java ---------------------------------------------------------------------- diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java index 205d4fc..6e0609d 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorService.java @@ -64,18 +64,21 @@ public class ProspectorService { * @param tableName - The name of the Accumulo table that will be queried for Prospect results. (not null) * @throws AccumuloException A problem occurred while creating the table. * @throws AccumuloSecurityException A problem occurred while creating the table. - * @throws TableExistsException A problem occurred while creating the table. */ - public ProspectorService(Connector connector, String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException { + public ProspectorService(Connector connector, String tableName) throws AccumuloException, AccumuloSecurityException { this.connector = requireNonNull(connector); this.tableName = requireNonNull(tableName); this.plans = ProspectorUtils.planMap(manager.getPlans()); // Create the table if it doesn't already exist. - final TableOperations tos = connector.tableOperations(); - if(!tos.exists(tableName)) { - tos.create(tableName); + try { + final TableOperations tos = connector.tableOperations(); + if(!tos.exists(tableName)) { + tos.create(tableName); + } + } catch(TableExistsException e) { + // Do nothing. Something else must have made it while we were. } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/4b755c64/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAO.java ---------------------------------------------------------------------- diff --git a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAO.java b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAO.java index 3bb3b26..3e45781 100644 --- a/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAO.java +++ b/extras/rya.prospector/src/main/java/org/apache/rya/prospector/service/ProspectorServiceEvalStatsDAO.java @@ -18,6 +18,8 @@ */ package org.apache.rya.prospector.service; +import static java.util.Objects.requireNonNull; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -25,8 +27,10 @@ import java.util.List; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; -import org.apache.accumulo.core.client.TableExistsException; import org.apache.accumulo.core.client.TableNotFoundException; +import org.apache.hadoop.conf.Configuration; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.accumulo.utils.ConnectorFactory; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; import org.apache.rya.api.persist.RdfDAOException; import org.apache.rya.api.persist.RdfEvalStatsDAO; @@ -50,10 +54,26 @@ public class ProspectorServiceEvalStatsDAO implements RdfEvalStatsDAO<RdfCloudTr this.prospectorService = prospectorService; } - public ProspectorServiceEvalStatsDAO(Connector connector, RdfCloudTripleStoreConfiguration conf) throws AccumuloException, AccumuloSecurityException, TableExistsException { + public ProspectorServiceEvalStatsDAO(Connector connector, RdfCloudTripleStoreConfiguration conf) throws AccumuloException, AccumuloSecurityException { this.prospectorService = new ProspectorService(connector, getProspectTableName(conf)); } + /** + * Creates an instance of {@link ProspectorServiceEvalStatsDAO} that is connected to the Accumulo and Rya instance + * that is specified within the provided {@link Configuration}. + * + * @param config - Configures which instance of Accumulo Rya this DAO will be backed by. (not null) + * @return A new instance of {@link ProspectorServiceEvalStatsDAO}. + * @throws AccumuloException The connector couldn't be created because of an Accumulo problem. + * @throws AccumuloSecurityException The connector couldn't be created because of an Accumulo security violation. + */ + public static ProspectorServiceEvalStatsDAO make(Configuration config) throws AccumuloException, AccumuloSecurityException { + requireNonNull(config); + AccumuloRdfConfiguration accConfig = new AccumuloRdfConfiguration(config); + return new ProspectorServiceEvalStatsDAO(ConnectorFactory.connect(accConfig), accConfig); + } + + @Override public void init() { assert prospectorService != null;