Repository: knox
Updated Branches:
  refs/heads/KNOX-481 a1d43564d -> 272fb90ed


KNOX-462: Proper error message when root tag of topology file incorrect
Contributed by J.Andreina via KNOX-462.3.patch.


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

Branch: refs/heads/KNOX-481
Commit: 2192932e012186ca8dc5777bdcc1b14d162c9128
Parents: 5abdde8
Author: Kevin Minder <kevin.min...@hortonworks.com>
Authored: Thu Feb 12 10:07:14 2015 -0500
Committer: Kevin Minder <kevin.min...@hortonworks.com>
Committed: Thu Feb 12 10:07:14 2015 -0500

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../apache/hadoop/gateway/GatewayMessages.java  |  3 ++
 .../topology/impl/DefaultTopologyService.java   | 35 ++++++++++++++++++--
 .../apache/hadoop/gateway/audit/api/Action.java |  1 +
 4 files changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/2192932e/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e795281..4d072b6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,9 @@ Release Notes - Apache Knox - Version 0.6.0
   * [KNOX-494] - knox-env.sh script should print proper warning message , if 
JAVA is not set. (Andreina J via lmccay)
   * [KNOX-493] - Data and sub data directory should be made configurable. 
(Andreina J via lmccay)
 
+** Improvement
+  * [KNOX-462] - Proper error message when root tag of topology file incorrect
+
 ------------------------------------------------------------------------------
 Release Notes - Apache Knox - Version 0.5.1
 ------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/knox/blob/2192932e/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
----------------------------------------------------------------------
diff --git 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
index 9325c02..4fd2a7c 100644
--- 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
+++ 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayMessages.java
@@ -97,6 +97,9 @@ public interface GatewayMessages {
   @Message( level = MessageLevel.ERROR, text = "Failed to redeploy topology 
{0}: {1}" )
   void failedToRedeployTopology( String name, 
@StackTrace(level=MessageLevel.DEBUG) Throwable e );
 
+  @Message(level = MessageLevel.ERROR, text = "Failed to load topology {0}: 
Topology configuration is invalid!")
+  void failedToLoadTopology(String fileName);
+
   @Message( level = MessageLevel.ERROR, text = "Failed to redeploy topologies: 
{0}" )
   void failedToRedeployTopologies( @StackTrace(level=MessageLevel.DEBUG) 
Throwable e );
 

http://git-wip-us.apache.org/repos/asf/knox/blob/2192932e/gateway-server/src/main/java/org/apache/hadoop/gateway/services/topology/impl/DefaultTopologyService.java
----------------------------------------------------------------------
diff --git 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/topology/impl/DefaultTopologyService.java
 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/topology/impl/DefaultTopologyService.java
index c80d8a1..74a29bc 100644
--- 
a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/topology/impl/DefaultTopologyService.java
+++ 
b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/topology/impl/DefaultTopologyService.java
@@ -28,6 +28,12 @@ import 
org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
 import org.apache.commons.io.monitor.FileAlterationMonitor;
 import org.apache.commons.io.monitor.FileAlterationObserver;
 import org.apache.hadoop.gateway.GatewayMessages;
+import org.apache.hadoop.gateway.audit.api.Action;
+import org.apache.hadoop.gateway.audit.api.ActionOutcome;
+import org.apache.hadoop.gateway.audit.api.AuditServiceFactory;
+import org.apache.hadoop.gateway.audit.api.Auditor;
+import org.apache.hadoop.gateway.audit.api.ResourceType;
+import org.apache.hadoop.gateway.audit.log4j.audit.AuditConstants;
 import org.apache.hadoop.gateway.config.GatewayConfig;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 import org.apache.hadoop.gateway.services.ServiceLifecycleException;
@@ -65,7 +71,9 @@ import static 
org.apache.commons.digester3.binder.DigesterLoader.newLoader;
 public class DefaultTopologyService
     extends FileAlterationListenerAdaptor
     implements TopologyService, TopologyMonitor, TopologyProvider, FileFilter, 
FileAlterationListener {
-
+  private static Auditor auditor = 
AuditServiceFactory.getAuditService().getAuditor(
+    AuditConstants.DEFAULT_AUDITOR_NAME, AuditConstants.KNOX_SERVICE_NAME,
+    AuditConstants.KNOX_COMPONENT_NAME);
   private static final List<String> SUPPORTED_TOPOLOGY_FILE_EXTENSIONS = new 
ArrayList<String>();
   static {
     SUPPORTED_TOPOLOGY_FILE_EXTENSIONS.add("xml");
@@ -111,6 +119,9 @@ public class DefaultTopologyService
     Topology topology;
     Digester digester = digesterLoader.newDigester();
     TopologyBuilder topologyBuilder = 
digester.parse(FileUtils.openInputStream(file));
+    if (null == topologyBuilder) {
+      return null;
+    }
     topology = topologyBuilder.build();
     topology.setUri(file.toURI());
     topology.setName(FilenameUtils.removeExtension(file.getName()));
@@ -137,10 +148,14 @@ public class DefaultTopologyService
             continue;
           }
         } else {
+          auditor.audit(Action.REDEPLOY, topology.getName(), 
ResourceType.TOPOLOGY,
+            ActionOutcome.FAILURE);
           log.failedToRedeployTopology(topology.getName());
           break;
         }
       } catch (InterruptedException e) {
+        auditor.audit(Action.REDEPLOY, topology.getName(), 
ResourceType.TOPOLOGY,
+          ActionOutcome.FAILURE);
         log.failedToRedeployTopology(topology.getName(), e);
         e.printStackTrace();
       }
@@ -201,15 +216,28 @@ public class DefaultTopologyService
     if (directory.exists() && directory.canRead()) {
       for (File file : directory.listFiles(this)) {
         try {
-          map.put(file, loadTopology(file));
+          Topology loadTopology = loadTopology(file);
+          if (null != loadTopology) {
+            map.put(file, loadTopology);
+          } else {
+            auditor.audit(Action.LOAD, file.getAbsolutePath(), 
ResourceType.TOPOLOGY,
+              ActionOutcome.FAILURE);
+            log.failedToLoadTopology(file.getAbsolutePath());
+          }
         } catch (IOException e) {
           // Maybe it makes sense to throw exception
+          auditor.audit(Action.LOAD, file.getAbsolutePath(), 
ResourceType.TOPOLOGY,
+            ActionOutcome.FAILURE);
           log.failedToLoadTopology(file.getAbsolutePath(), e);
         } catch (SAXException e) {
           // Maybe it makes sense to throw exception
+          auditor.audit(Action.LOAD, file.getAbsolutePath(), 
ResourceType.TOPOLOGY,
+            ActionOutcome.FAILURE);
           log.failedToLoadTopology(file.getAbsolutePath(), e);
         } catch (Exception e) {
           // Maybe it makes sense to throw exception
+          auditor.audit(Action.LOAD, file.getAbsolutePath(), 
ResourceType.TOPOLOGY,
+            ActionOutcome.FAILURE);
           log.failedToLoadTopology(file.getAbsolutePath(), e);
         }
       }
@@ -240,8 +268,10 @@ public class DefaultTopologyService
       }
 
     } catch (JAXBException e) {
+      auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, 
ActionOutcome.FAILURE);
       log.failedToDeployTopology(t.getName(), e);
     } catch (IOException io) {
+      auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, 
ActionOutcome.FAILURE);
       log.failedToDeployTopology(t.getName(), io);
     }
     reloadTopologies();
@@ -292,6 +322,7 @@ public class DefaultTopologyService
       try {
         listener.handleTopologyEvent(events);
       } catch (RuntimeException e) {
+        auditor.audit(Action.LOAD, "Topology_Event", ResourceType.TOPOLOGY, 
ActionOutcome.FAILURE);
         log.failedToHandleTopologyEvents(e);
       }
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/2192932e/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/api/Action.java
----------------------------------------------------------------------
diff --git 
a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/api/Action.java
 
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/api/Action.java
index b60b367..2b87627 100644
--- 
a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/api/Action.java
+++ 
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/audit/api/Action.java
@@ -25,6 +25,7 @@ public abstract class Action {
   public static final String AUTHORIZATION = "authorization";
   public static final String REDEPLOY = "redeploy";
   public static final String DEPLOY = "deploy";
+  public static final String LOAD = "load";
   public static final String UNDEPLOY = "undeploy";
   public static final String IDENTITY_MAPPING = "identity-mapping";
   public static final String DISPATCH = "dispatch";

Reply via email to