added logger in catch

Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/b7d27496
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/b7d27496
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/b7d27496

Branch: refs/heads/steven/hdfs
Commit: b7d274967bba213b8df34031e5e9ef33c917caaf
Parents: d9e6f5d
Author: efikalti <[email protected]>
Authored: Fri Aug 21 18:12:02 2015 +0300
Committer: efikalti <[email protected]>
Committed: Fri Aug 21 18:12:02 2015 +0300

----------------------------------------------------------------------
 .../org/apache/vxquery/hdfs2/HDFSFunctions.java | 89 +++++++++++++-------
 .../VXQueryCollectionOperatorDescriptor.java    | 32 +++++--
 2 files changed, 81 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/b7d27496/vxquery-core/src/main/java/org/apache/vxquery/hdfs2/HDFSFunctions.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/hdfs2/HDFSFunctions.java 
b/vxquery-core/src/main/java/org/apache/vxquery/hdfs2/HDFSFunctions.java
index 7604e48..5435b48 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/hdfs2/HDFSFunctions.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/hdfs2/HDFSFunctions.java
@@ -27,6 +27,8 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -57,6 +59,7 @@ import edu.uci.ics.hyracks.hdfs2.dataflow.FileSplitsFactory;
 import org.apache.hadoop.mapreduce.RecordReader;
 import org.apache.hadoop.mapreduce.TaskAttemptContext;
 import org.apache.hadoop.mapreduce.lib.input.FileSplit;
+import org.apache.vxquery.metadata.VXQueryCollectionOperatorDescriptor;
 
 public class HDFSFunctions {
 
@@ -72,6 +75,7 @@ public class HDFSFunctions {
     private final String TEMP = "java.io.tmpdir";
     private final String dfs_path = "vxquery_splits_schedule.txt";
     private final String filepath = System.getProperty(TEMP) + 
"splits_schedule.txt";
+    protected static final Logger LOGGER = 
Logger.getLogger(HDFSFunctions.class.getName());
 
     /**
      * Create the configuration and add the paths for core-site and hdfs-site 
as resources.
@@ -99,11 +103,17 @@ public class HDFSFunctions {
             inputFormat = 
ReflectionUtils.newInstance(job.getInputFormatClass(), job.getConfiguration());
             splits = inputFormat.getSplits(job);
         } catch (IOException e) {
-            System.err.println(e);
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.severe(e.getMessage());
+            }
         } catch (ClassNotFoundException e) {
-            System.err.println(e);
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.severe(e.getMessage());
+            }
         } catch (InterruptedException e) {
-            System.err.println(e);
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.severe(e.getMessage());
+            }
         }
     }
 
@@ -113,15 +123,13 @@ public class HDFSFunctions {
      * 
      * @param filename
      * @return
+     * @throws IOException
+     * @throws IllegalArgumentException
      */
-    public boolean isLocatedInHDFS(String filename) {
-        try {
-            //search file path
-            if (fs.exists(new Path(filename))) {
-                return true;
-            }
-        } catch (IOException ex) {
-            System.err.println(ex);
+    public boolean isLocatedInHDFS(String filename) throws 
IllegalArgumentException, IOException {
+        //search file path
+        if (fs.exists(new Path(filename))) {
+            return true;
         }
         return searchInDirectory(fs.getHomeDirectory(), filename) != null;
     }
@@ -148,8 +156,10 @@ public class HDFSFunctions {
                     return path;
                 }
             }
-        } catch (IOException ex) {
-            System.err.println(ex);
+        } catch (IOException e) {
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.severe(e.getMessage());
+            }
         }
         return null;
     }
@@ -164,18 +174,17 @@ public class HDFSFunctions {
         if (this.conf_path == null) {
             // load properties file
             Properties prop = new Properties();
-            String propFilePath = 
"../vxquery-server/src/main/resources/conf/cluster.properties";
+            String propFilePath = 
"vxquery-server/src/main/resources/conf/cluster.properties";
             try {
                 prop.load(new FileInputStream(propFilePath));
             } catch (FileNotFoundException e) {
-                propFilePath = 
"vxquery-server/src/main/resources/conf/cluster.properties";
-                try {
-                    prop.load(new FileInputStream(propFilePath));
-                } catch (FileNotFoundException e1) {
-                } catch (IOException e1) {
+                if (LOGGER.isLoggable(Level.SEVERE)) {
+                    LOGGER.severe(e.getMessage());
                 }
             } catch (IOException e) {
-                System.err.println(e);
+                if (LOGGER.isLoggable(Level.SEVERE)) {
+                    LOGGER.severe(e.getMessage());
+                }
                 return false;
             }
             // get the property value for HDFS_CONF
@@ -205,12 +214,16 @@ public class HDFSFunctions {
                     fs.delete(dest, true); //recursive delete
                 }
             } catch (IOException e) {
-                System.err.println(e);
+                if (LOGGER.isLoggable(Level.SEVERE)) {
+                    LOGGER.severe(e.getMessage());
+                }
             }
             try {
                 fs.copyFromLocalFile(path, dest);
             } catch (IOException e) {
-                System.err.println(e);
+                if (LOGGER.isLoggable(Level.SEVERE)) {
+                    LOGGER.severe(e.getMessage());
+                }
             }
         }
         return false;
@@ -229,11 +242,15 @@ public class HDFSFunctions {
             try {
                 fs = FileSystem.get(conf);
                 return this.fs;
-            } catch (IOException ex) {
-                System.err.println(ex);
+            } catch (IOException e) {
+                if (LOGGER.isLoggable(Level.SEVERE)) {
+                    LOGGER.severe(e.getMessage());
+                }
             }
         } else {
-            System.err.println("Could not locate hdfs configuarion folder.");
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.severe("Could not locate HDFS configuration folder.");
+            }
         }
         return null;
     }
@@ -388,15 +405,23 @@ public class HDFSFunctions {
                     reader.initialize(inputSplits.get(i), context);
                     return reader;
                 } catch (HyracksDataException e) {
-                    System.err.println(e);
+                    if (LOGGER.isLoggable(Level.SEVERE)) {
+                        LOGGER.severe(e.getMessage());
+                    }
                 } catch (IOException e) {
-                    System.err.println(e);
+                    if (LOGGER.isLoggable(Level.SEVERE)) {
+                        LOGGER.severe(e.getMessage());
+                    }
                 } catch (InterruptedException e) {
-                    System.err.println(e);
+                    if (LOGGER.isLoggable(Level.SEVERE)) {
+                        LOGGER.severe(e.getMessage());
+                    }
                 }
             }
-        } catch (HyracksDataException e1) {
-            e1.printStackTrace();
+        } catch (HyracksDataException e) {
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.severe(e.getMessage());
+            }
         }
         return null;
     }
@@ -444,7 +469,9 @@ public class HDFSFunctions {
             Document doc = builder.parse(new InputSource(new 
StringReader(xmlStr)));
             return doc;
         } catch (Exception e) {
-            System.err.println(e);
+            if (LOGGER.isLoggable(Level.SEVERE)) {
+                LOGGER.severe(e.getMessage());
+            }
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/b7d27496/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java
 
b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java
index 0231154..0395788 100644
--- 
a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java
+++ 
b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java
@@ -198,16 +198,24 @@ public class VXQueryCollectionOperatorDescriptor extends 
AbstractSingleActivityO
                                         }
 
                                     } catch (InterruptedException e) {
-                                        System.err.println(e);
+                                        if (LOGGER.isLoggable(Level.SEVERE)) {
+                                            LOGGER.severe(e.getMessage());
+                                        }
                                     }
                                 }
 
                             } catch (IOException e) {
-                                e.printStackTrace();
-                            } catch (ParserConfigurationException e1) {
-                                e1.printStackTrace();
-                            } catch (SAXException e1) {
-                                e1.printStackTrace();
+                                if (LOGGER.isLoggable(Level.SEVERE)) {
+                                    LOGGER.severe(e.getMessage());
+                                }
+                            } catch (ParserConfigurationException e) {
+                                if (LOGGER.isLoggable(Level.SEVERE)) {
+                                    LOGGER.severe(e.getMessage());
+                                }
+                            } catch (SAXException e) {
+                                if (LOGGER.isLoggable(Level.SEVERE)) {
+                                    LOGGER.severe(e.getMessage());
+                                }
                             }
                         } else {
                             try {
@@ -234,15 +242,21 @@ public class VXQueryCollectionOperatorDescriptor extends 
AbstractSingleActivityO
                                             + directory + ") passed to 
collection.");
                                 }
                             } catch (FileNotFoundException e) {
-                                System.err.println(e);
+                                if (LOGGER.isLoggable(Level.SEVERE)) {
+                                    LOGGER.severe(e.getMessage());
+                                }
                             } catch (IOException e) {
-                                System.err.println(e);
+                                if (LOGGER.isLoggable(Level.SEVERE)) {
+                                    LOGGER.severe(e.getMessage());
+                                }
                             }
                         }
                         try {
                             fs.close();
                         } catch (IOException e) {
-                            System.err.println(e);
+                            if (LOGGER.isLoggable(Level.SEVERE)) {
+                                LOGGER.severe(e.getMessage());
+                            }
                         }
                     }
                 }

Reply via email to