You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/09/17 18:25:09 UTC

atlas git commit: ATLAS-2140: Throwing overly generic exceptions, or unnecessarily exceptions

Repository: atlas
Updated Branches:
  refs/heads/master 45b84fa20 -> d67b0498e


ATLAS-2140: Throwing overly generic exceptions, or unnecessarily exceptions

Change-Id: I9df89ebca2e281768d3353bd691ea7eafca96f47

Signed-off-by: Madhan Neethiraj <ma...@apache.org>


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

Branch: refs/heads/master
Commit: d67b0498edf907ea7370247447b7e86d46645c2a
Parents: 45b84fa
Author: Zsombor Gegesy <gz...@gmail.com>
Authored: Sat Sep 16 16:25:21 2017 +0200
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Sun Sep 17 11:24:26 2017 -0700

----------------------------------------------------------------------
 .../atlas/falcon/bridge/FalconBridge.java       | 25 +++++++++++---------
 .../apache/atlas/falcon/hook/FalconHook.java    | 12 ++++++----
 .../falcon/publisher/FalconEventPublisher.java  |  2 +-
 .../apache/atlas/storm/hook/StormAtlasHook.java | 25 ++++++++++----------
 .../atlas/storm/hook/StormTopologyUtil.java     |  8 +++----
 .../classloader/AtlasPluginClassLoader.java     | 19 ++++++++-------
 .../classloader/AtlasPluginClassLoaderUtil.java |  5 ++--
 7 files changed, 50 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/d67b0498/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/bridge/FalconBridge.java
----------------------------------------------------------------------
diff --git a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/bridge/FalconBridge.java b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/bridge/FalconBridge.java
index 349da66..ff74559 100644
--- a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/bridge/FalconBridge.java
+++ b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/bridge/FalconBridge.java
@@ -27,6 +27,7 @@ import org.apache.atlas.hive.model.HiveDataTypes;
 import org.apache.atlas.typesystem.Referenceable;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.falcon.FalconException;
 import org.apache.falcon.entity.CatalogStorage;
 import org.apache.falcon.entity.FeedHelper;
 import org.apache.falcon.entity.FileSystemStorage;
@@ -47,6 +48,7 @@ import org.apache.hadoop.fs.Path;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -123,7 +125,7 @@ public class FalconBridge {
         return feedEntity;
     }
 
-    public static List<Referenceable> createFeedCreationEntity(Feed feed, ConfigurationStore falconStore) throws Exception {
+    public static List<Referenceable> createFeedCreationEntity(Feed feed, ConfigurationStore falconStore) throws FalconException, URISyntaxException {
         LOG.info("Creating feed : {}", feed.getName());
 
         List<Referenceable> entities = new ArrayList<>();
@@ -198,17 +200,18 @@ public class FalconBridge {
     }
 
     /**
-     * +     * Creates process entity
-     * +     *
-     * +     * @param process process entity
-     * +     * @param falconStore config store
-     * +     * @param user falcon user
-     * +     * @param timestamp timestamp of entity
-     * +     * @return process instance reference
-     * +
+     * Creates process entity
+     * 
+     * @param process process entity
+     * @param falconStore config store
+     * @param user falcon user
+     * @param timestamp timestamp of entity
+     * @return process instance reference
+     *
+     * @throws FalconException if retrieving from the configuration store fail
      */
     public static List<Referenceable> createProcessEntity(org.apache.falcon.entity.v0.process.Process process,
-                                                          ConfigurationStore falconStore) throws Exception {
+                                                          ConfigurationStore falconStore) throws FalconException {
         LOG.info("Creating process Entity : {}", process.getName());
 
         // The requirement is for each cluster, create a process entity with name
@@ -288,7 +291,7 @@ public class FalconBridge {
     }
 
     private static List<Referenceable> getInputEntities(org.apache.falcon.entity.v0.cluster.Cluster cluster,
-                                                        Feed feed) throws Exception {
+                                                        Feed feed) throws URISyntaxException {
         org.apache.falcon.entity.v0.feed.Cluster feedCluster = FeedHelper.getCluster(feed, cluster.getName());
 
         if(feedCluster != null) {

http://git-wip-us.apache.org/repos/asf/atlas/blob/d67b0498/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
----------------------------------------------------------------------
diff --git a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
index 3b384f8..188b754 100644
--- a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
+++ b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
@@ -27,6 +27,7 @@ import org.apache.atlas.hook.AtlasHook;
 import org.apache.atlas.kafka.NotificationProvider;
 import org.apache.atlas.notification.hook.HookNotification;
 import org.apache.atlas.typesystem.Referenceable;
+import org.apache.falcon.FalconException;
 import org.apache.falcon.entity.store.ConfigurationStore;
 import org.apache.falcon.entity.v0.feed.Feed;
 import org.apache.falcon.entity.v0.process.Process;
@@ -34,6 +35,7 @@ import org.apache.hadoop.util.ShutdownHookManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
@@ -120,7 +122,7 @@ public class FalconHook extends AtlasHook implements FalconEventPublisher {
     }
 
     @Override
-    public void publish(final Data data) throws Exception {
+    public void publish(final Data data) {
         final FalconEvent event = data.getEvent();
         try {
             if (sync) {
@@ -147,7 +149,7 @@ public class FalconHook extends AtlasHook implements FalconEventPublisher {
         return HOOK_NUM_RETRIES;
     }
 
-    private void fireAndForget(FalconEvent event) throws Exception {
+    private void fireAndForget(FalconEvent event) throws FalconException, URISyntaxException {
         LOG.info("Entered Atlas hook for Falcon hook operation {}", event.getOperation());
         List<HookNotification.HookNotificationMessage> messages = new ArrayList<>();
 
@@ -163,7 +165,7 @@ public class FalconHook extends AtlasHook implements FalconEventPublisher {
         notifyEntities(messages);
     }
 
-    private List<Referenceable> createEntities(FalconEvent event, String user) throws Exception {
+    private List<Referenceable> createEntities(FalconEvent event, String user) throws FalconException, URISyntaxException {
         List<Referenceable> entities = new ArrayList<>();
 
         switch (event.getOperation()) {
@@ -190,7 +192,7 @@ public class FalconHook extends AtlasHook implements FalconEventPublisher {
         return entities;
     }
 
-    private static Operation getOperation(final FalconEvent.OPERATION op) throws Exception {
+    private static Operation getOperation(final FalconEvent.OPERATION op) throws FalconException {
         switch (op) {
         case ADD_CLUSTER:
         case ADD_FEED:
@@ -203,7 +205,7 @@ public class FalconHook extends AtlasHook implements FalconEventPublisher {
             return Operation.UPDATE;
 
         default:
-            throw new Exception("Falcon operation " + op + " is not valid or supported");
+            throw new FalconException("Falcon operation " + op + " is not valid or supported");
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/d67b0498/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/publisher/FalconEventPublisher.java
----------------------------------------------------------------------
diff --git a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/publisher/FalconEventPublisher.java b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/publisher/FalconEventPublisher.java
index ea81226..a01ec14 100644
--- a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/publisher/FalconEventPublisher.java
+++ b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/publisher/FalconEventPublisher.java
@@ -37,5 +37,5 @@ public interface FalconEventPublisher {
         }
     }
 
-    void publish(final Data data) throws Exception;
+    void publish(final Data data);
 }

http://git-wip-us.apache.org/repos/asf/atlas/blob/d67b0498/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormAtlasHook.java
----------------------------------------------------------------------
diff --git a/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormAtlasHook.java b/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormAtlasHook.java
index 5193832..c3df8fc 100644
--- a/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormAtlasHook.java
+++ b/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormAtlasHook.java
@@ -75,11 +75,10 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
      * @param topologyInfo topology info
      * @param stormConf configuration
      * @param stormTopology a storm topology
-     * @throws IllegalAccessException
      */
     @Override
     public void notify(TopologyInfo topologyInfo, Map stormConf,
-                       StormTopology stormTopology) throws IllegalAccessException {
+                       StormTopology stormTopology) {
 
         LOG.info("Collecting metadata for a new storm topology: {}", topologyInfo.get_name());
         try {
@@ -105,7 +104,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
         }
     }
 
-    private Referenceable createTopologyInstance(TopologyInfo topologyInfo, Map stormConf) throws Exception {
+    private Referenceable createTopologyInstance(TopologyInfo topologyInfo, Map stormConf) {
         Referenceable topologyReferenceable = new Referenceable(
                 StormDataTypes.STORM_TOPOLOGY.getName());
         topologyReferenceable.set("id", topologyInfo.get_id());
@@ -125,7 +124,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
     private List<Referenceable> addTopologyDataSets(StormTopology stormTopology,
                                                     Referenceable topologyReferenceable,
                                                     String topologyOwner,
-                                                    Map stormConf) throws Exception {
+                                                    Map stormConf) {
         List<Referenceable> dependentEntities = new ArrayList<>();
         // add each spout as an input data set
         addTopologyInputs(topologyReferenceable,
@@ -138,7 +137,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
     private void addTopologyInputs(Referenceable topologyReferenceable,
                                    Map<String, SpoutSpec> spouts,
                                    Map stormConf,
-                                   String topologyOwner, List<Referenceable> dependentEntities) throws IllegalAccessException {
+                                   String topologyOwner, List<Referenceable> dependentEntities) {
         final ArrayList<Referenceable> inputDataSets = new ArrayList<>();
         for (Map.Entry<String, SpoutSpec> entry : spouts.entrySet()) {
             Serializable instance = Utils.javaDeserialize(
@@ -156,7 +155,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
 
     private void addTopologyOutputs(Referenceable topologyReferenceable,
                                     StormTopology stormTopology, String topologyOwner,
-                                    Map stormConf, List<Referenceable> dependentEntities) throws Exception {
+                                    Map stormConf, List<Referenceable> dependentEntities) {
         final ArrayList<Referenceable> outputDataSets = new ArrayList<>();
 
         Map<String, Bolt> bolts = stormTopology.get_bolts();
@@ -177,7 +176,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
 
     private Referenceable createDataSet(String name, String topologyOwner,
                                               Serializable instance,
-                                              Map stormConf, List<Referenceable> dependentEntities) throws IllegalAccessException {
+                                              Map stormConf, List<Referenceable> dependentEntities) {
         Map<String, String> config = StormTopologyUtil.getFieldValues(instance, true, null);
 
         String clusterName = null;
@@ -265,7 +264,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
 
     private ArrayList<Referenceable> createTopologyGraph(StormTopology stormTopology,
                                                          Map<String, SpoutSpec> spouts,
-                                                         Map<String, Bolt> bolts) throws Exception {
+                                                         Map<String, Bolt> bolts) {
         // Add graph of nodes in the topology
         final Map<String, Referenceable> nodeEntities = new HashMap<>();
         addSpouts(spouts, nodeEntities);
@@ -279,7 +278,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
     }
 
     private void addSpouts(Map<String, SpoutSpec> spouts,
-                           Map<String, Referenceable> nodeEntities) throws IllegalAccessException {
+                           Map<String, Referenceable> nodeEntities) {
         for (Map.Entry<String, SpoutSpec> entry : spouts.entrySet()) {
             final String spoutName = entry.getKey();
             Referenceable spoutReferenceable = createSpoutInstance(
@@ -289,7 +288,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
     }
 
     private Referenceable createSpoutInstance(String spoutName,
-                                              SpoutSpec stormSpout) throws IllegalAccessException {
+                                              SpoutSpec stormSpout) {
         Referenceable spoutReferenceable = new Referenceable(StormDataTypes.STORM_SPOUT.getName());
         spoutReferenceable.set(AtlasClient.NAME, spoutName);
 
@@ -304,7 +303,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
     }
 
     private void addBolts(Map<String, Bolt> bolts,
-                          Map<String, Referenceable> nodeEntities) throws IllegalAccessException {
+                          Map<String, Referenceable> nodeEntities) {
         for (Map.Entry<String, Bolt> entry : bolts.entrySet()) {
             Referenceable boltInstance = createBoltInstance(entry.getKey(), entry.getValue());
             nodeEntities.put(entry.getKey(), boltInstance);
@@ -312,7 +311,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
     }
 
     private Referenceable createBoltInstance(String boltName,
-                                             Bolt stormBolt) throws IllegalAccessException {
+                                             Bolt stormBolt) {
         Referenceable boltReferenceable = new Referenceable(StormDataTypes.STORM_BOLT.getName());
 
         boltReferenceable.set(AtlasClient.NAME, boltName);
@@ -328,7 +327,7 @@ public class StormAtlasHook extends AtlasHook implements ISubmitterHook {
     }
 
     private void addGraphConnections(StormTopology stormTopology,
-                                     Map<String, Referenceable> nodeEntities) throws Exception {
+                                     Map<String, Referenceable> nodeEntities) {
         // adds connections between spouts and bolts
         Map<String, Set<String>> adjacencyMap =
                 StormTopologyUtil.getAdjacencyMap(stormTopology, true);

http://git-wip-us.apache.org/repos/asf/atlas/blob/d67b0498/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormTopologyUtil.java
----------------------------------------------------------------------
diff --git a/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormTopologyUtil.java b/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormTopologyUtil.java
index d999a6a..b903dbc 100644
--- a/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormTopologyUtil.java
+++ b/addons/storm-bridge/src/main/java/org/apache/atlas/storm/hook/StormTopologyUtil.java
@@ -69,8 +69,7 @@ public final class StormTopologyUtil {
     }
 
     public static Map<String, Set<String>> getAdjacencyMap(StormTopology topology,
-                                                           boolean removeSystemComponent)
-    throws Exception {
+                                                           boolean removeSystemComponent) {
         Map<String, Set<String>> adjacencyMap = new HashMap<>();
 
         for (Map.Entry<String, Bolt> entry : topology.get_bolts().entrySet()) {
@@ -129,8 +128,7 @@ public final class StormTopologyUtil {
 
     public static Map<String, String> getFieldValues(Object instance,
                                                      boolean prependClassName,
-                                                     Set<Object> objectsToSkip)
-    throws IllegalAccessException {
+                                                     Set<Object> objectsToSkip) {
         if (objectsToSkip == null) {
             objectsToSkip = new HashSet<>();
         }
@@ -213,7 +211,7 @@ public final class StormTopologyUtil {
 
     private static String getString(Object instance,
                                     boolean wrapWithQuote,
-                                    Set<Object> objectsToSkip) throws IllegalAccessException {
+                                    Set<Object> objectsToSkip) {
         if (instance == null) {
             return null;
         } else if (instance.getClass().isPrimitive() || isWrapperType(instance.getClass())) {

http://git-wip-us.apache.org/repos/asf/atlas/blob/d67b0498/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoader.java
----------------------------------------------------------------------
diff --git a/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoader.java b/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoader.java
index d7ec65d..4ed32c0 100644
--- a/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoader.java
+++ b/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoader.java
@@ -22,10 +22,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Enumeration;
 
@@ -39,12 +41,12 @@ public final class AtlasPluginClassLoader extends URLClassLoader {
 
     private final MyClassLoader componentClassLoader;
 
-    private AtlasPluginClassLoader(String pluginType, Class<?> pluginClass) throws Exception {
+    private AtlasPluginClassLoader(String pluginType, Class<?> pluginClass) throws URISyntaxException {
         this(AtlasPluginClassLoaderUtil.getPluginImplLibPath(pluginType, pluginClass));
     }
 
     //visible for testing
-    AtlasPluginClassLoader(String libraryPath) throws Exception {
+    AtlasPluginClassLoader(String libraryPath) {
         super(AtlasPluginClassLoaderUtil.getFilesInDirectories(new String[]{libraryPath}), null);
 
         componentClassLoader = AccessController.doPrivileged(new PrivilegedAction<MyClassLoader>() {
@@ -54,18 +56,17 @@ public final class AtlasPluginClassLoader extends URLClassLoader {
         });
     }
 
-    public static AtlasPluginClassLoader getInstance(final String pluginType, final Class<?> pluginClass)
-        throws Exception {
+    public static AtlasPluginClassLoader getInstance(final String pluginType, final Class<?> pluginClass) throws PrivilegedActionException {
         AtlasPluginClassLoader ret = me;
         if (ret == null) {
             synchronized (AtlasPluginClassLoader.class) {
                 ret = me;
                 if (ret == null) {
-                    me = AccessController.doPrivileged(new PrivilegedExceptionAction<AtlasPluginClassLoader>() {
-                        public AtlasPluginClassLoader run() throws Exception {
-                            return new AtlasPluginClassLoader(pluginType, pluginClass);
-                        }
-                    });
+					me = AccessController.doPrivileged(new PrivilegedExceptionAction<AtlasPluginClassLoader>() {
+					    public AtlasPluginClassLoader run() throws URISyntaxException {
+					        return new AtlasPluginClassLoader(pluginType, pluginClass);
+					    }
+					});
                     ret = me;
                 }
             }

http://git-wip-us.apache.org/repos/asf/atlas/blob/d67b0498/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoaderUtil.java
----------------------------------------------------------------------
diff --git a/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoaderUtil.java b/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoaderUtil.java
index dfdad88..f44603b 100644
--- a/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoaderUtil.java
+++ b/plugin-classloader/src/main/java/org/apache/atlas/plugin/classloader/AtlasPluginClassLoaderUtil.java
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -40,7 +41,7 @@ final class AtlasPluginClassLoaderUtil {
 
     private AtlasPluginClassLoaderUtil(){ }
 
-    public static URL[] getFilesInDirectories(String[] libDirs) throws Exception {
+    public static URL[] getFilesInDirectories(String[] libDirs) {
         if (LOG.isDebugEnabled()) {
             LOG.debug("==> AtlasPluginClassLoaderUtil.getFilesInDirectories()");
         }
@@ -95,7 +96,7 @@ final class AtlasPluginClassLoaderUtil {
         }
     }
 
-    public static String getPluginImplLibPath(String pluginType, Class<?> pluginClass) throws Exception {
+    public static String getPluginImplLibPath(String pluginType, Class<?> pluginClass) throws URISyntaxException {
         if (LOG.isDebugEnabled()) {
             LOG.debug("==> AtlasPluginClassLoaderUtil.getPluginImplLibPath for Class ({})", pluginClass.getName());
         }