Author: lewismc Date: Wed Jan 22 11:49:02 2014 New Revision: 1560321 URL: http://svn.apache.org/r1560321 Log: port GORA-231 Provide better error handling in AccumuloStore.readMapping when file does not exist.
Modified: gora/branches/GORA_94/CHANGES.txt gora/branches/GORA_94/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java gora/branches/GORA_94/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java Modified: gora/branches/GORA_94/CHANGES.txt URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/CHANGES.txt?rev=1560321&r1=1560320&r2=1560321&view=diff ============================================================================== --- gora/branches/GORA_94/CHANGES.txt (original) +++ gora/branches/GORA_94/CHANGES.txt Wed Jan 22 11:49:02 2014 @@ -4,6 +4,8 @@ Gora Change Log +* GORA-231 Provide better error handling in AccumuloStore.readMapping when file does not exist. (apgiannakidis via lewismc) + * GORA-283 Specify field name for types not being considered in gora-cassandra (lewismc) * GORA-285 Change logging at o.a.g.mapreduce.GoraRecordWriter from INFO to WARN (lewismc) Modified: gora/branches/GORA_94/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java?rev=1560321&r1=1560320&r2=1560321&view=diff ============================================================================== --- gora/branches/GORA_94/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java (original) +++ gora/branches/GORA_94/gora-core/src/main/java/org/apache/gora/store/DataStoreFactory.java Wed Jan 22 11:49:02 2014 @@ -56,7 +56,7 @@ public class DataStoreFactory{ public static final String MAPPING_FILE = "mapping.file"; - public static final String SCHEMA_NAME = "schema.name"; + public static final String SCHEMA_NAME = "schema.name"; /** * Do not use! Deprecated because it shares system wide state. @@ -64,7 +64,7 @@ public class DataStoreFactory{ */ @Deprecated() public static final Properties properties = createProps(); - + /** * Creates a new {@link Properties}. It adds the default gora configuration * resources. This properties object can be modified and used to instantiate @@ -75,9 +75,9 @@ public class DataStoreFactory{ */ public static Properties createProps() { try { - Properties properties = new Properties(); + Properties properties = new Properties(); InputStream stream = DataStoreFactory.class.getClassLoader() - .getResourceAsStream(GORA_DEFAULT_PROPERTIES_FILE); + .getResourceAsStream(GORA_DEFAULT_PROPERTIES_FILE); if(stream != null) { try { properties.load(stream); @@ -150,11 +150,11 @@ public class DataStoreFactory{ public static <D extends DataStore<K,T>, K, T extends Persistent> D createDataStore(Class<D> dataStoreClass, Class<K> keyClass , Class<T> persistent, Configuration conf, Properties properties, String schemaName) - throws GoraException { + throws GoraException { try { setDefaultSchemaName(properties, schemaName); D dataStore = - ReflectionUtils.newInstance(dataStoreClass); + ReflectionUtils.newInstance(dataStoreClass); if ((dataStore instanceof Configurable) && conf != null) { ((Configurable)dataStore).setConf(conf); } @@ -182,7 +182,7 @@ public class DataStoreFactory{ public static <D extends DataStore<K,T>, K, T extends Persistent> D createDataStore(Class<D> dataStoreClass , Class<K> keyClass, Class<T> persistent, Configuration conf, Properties properties) - throws GoraException { + throws GoraException { return createDataStore(dataStoreClass, keyClass, persistent, conf, properties, null); } @@ -216,10 +216,10 @@ public class DataStoreFactory{ @SuppressWarnings("unchecked") public static <K, T extends Persistent> DataStore<K, T> getDataStore( String dataStoreClass, Class<K> keyClass, Class<T> persistentClass, Configuration conf) - throws GoraException { + throws GoraException { try { Class<? extends DataStore<K,T>> c - = (Class<? extends DataStore<K, T>>) Class.forName(dataStoreClass); + = (Class<? extends DataStore<K, T>>) Class.forName(dataStoreClass); return createDataStore(c, keyClass, persistentClass, conf, createProps(), null); } catch(GoraException ex) { throw ex; @@ -241,7 +241,7 @@ public class DataStoreFactory{ @SuppressWarnings({ "unchecked" }) public static <K, T extends Persistent> DataStore<K, T> getDataStore( String dataStoreClass, String keyClass, String persistentClass, Configuration conf) - throws GoraException { + throws GoraException { try { Class<? extends DataStore<K,T>> c @@ -333,7 +333,7 @@ public class DataStoreFactory{ String val = findProperty(properties, store, baseKey, null); if(val == null) { throw new IOException("Property with base name \""+baseKey+"\" could not be found, make " + - "sure to include this property in gora.properties file"); + "sure to include this property in gora.properties file"); } return val; } @@ -362,9 +362,28 @@ public class DataStoreFactory{ return findProperty(properties, store, OUTPUT_PATH, null); } + /** + * Looks for the <code>gora-<classname>-mapping.xml</code> as a resource + * on the classpath. This can however also be specified within the + * <code>gora.properties</code> file with the key + * <code>gora.<classname>.mapping.file=</code>. + * @param properties which hold keys from which we can obtain values for datastore mappings. + * @param store {@link org.apache.gora.store.DataStore} object to get the mapping for. + * @param defaultValue default value for the <code>gora-<classname>-mapping.xml</code> + * @return mappingFilename if one is located. + * @throws IOException if there is a problem reading or obtaining the mapping file. + */ public static String getMappingFile(Properties properties, DataStore<?,?> store - , String defaultValue) { - return findProperty(properties, store, MAPPING_FILE, defaultValue); + , String defaultValue) throws IOException { + + String mappingFilename = findProperty(properties, store, MAPPING_FILE, defaultValue); + + InputStream mappingFile = store.getClass().getClassLoader().getResourceAsStream(mappingFilename); + + if (mappingFile == null) + throw new IOException("Unable to open mapping file: "+mappingFilename); + + return mappingFilename; } private static String getDefaultDataStore(Properties properties) { Modified: gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java?rev=1560321&r1=1560320&r2=1560321&view=diff ============================================================================== --- gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java (original) +++ gora/branches/GORA_94/gora-core/src/test/java/org/apache/gora/store/DataStoreTestUtil.java Wed Jan 22 11:49:02 2014 @@ -518,6 +518,10 @@ public class DataStoreTestUtil { for (int j = 1; j < urls.length; j += 2) { webPage.getOutlinks().put(new Utf8(anchor + j), new Utf8(urls[j])); } + //test for double put of same entries + for (int j = 1; j < urls.length; j += 2) { + webPage.getOutlinks().put(new Utf8(anchor + j), new Utf8(urls[j])); + } dataStore.put(webPage.getUrl().toString(), webPage); } Modified: gora/branches/GORA_94/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java URL: http://svn.apache.org/viewvc/gora/branches/GORA_94/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java?rev=1560321&r1=1560320&r2=1560321&view=diff ============================================================================== --- gora/branches/GORA_94/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java (original) +++ gora/branches/GORA_94/gora-solr/src/main/java/org/apache/gora/solr/store/SolrStore.java Wed Jan 22 11:49:02 2014 @@ -95,8 +95,8 @@ public class SolrStore<K, T extends Pers @Override public void initialize( Class<K> keyClass, Class<T> persistentClass, Properties properties ) { super.initialize( keyClass, persistentClass, properties ); - String mappingFile = DataStoreFactory.getMappingFile( properties, this, DEFAULT_MAPPING_FILE ); try { + String mappingFile = DataStoreFactory.getMappingFile( properties, this, DEFAULT_MAPPING_FILE ); mapping = readMapping( mappingFile ); } catch ( IOException e ) {