This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f12835f37 HDDS-8860. Move audit to hdds-server-framework (#4919)
9f12835f37 is described below

commit 9f12835f37a59dee43228d722ed14c01e6ab44a2
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Mon Sep 11 12:06:45 2023 +0200

    HDDS-8860. Move audit to hdds-server-framework (#4919)
---
 hadoop-hdds/common/pom.xml                         |  14 --
 .../apache/hadoop/ozone/audit/package-info.java    | 131 +-------------
 .../helpers/ContainerCommandRequestPBHelper.java   | 197 ---------------------
 .../org/apache/hadoop/ozone/audit/DNAction.java    |   0
 .../apache/hadoop/ozone/audit/package-info.java}   |  20 +--
 .../container/common/impl/HddsDispatcher.java      | 171 +++++++++++++++++-
 hadoop-hdds/framework/pom.xml                      |   4 +
 .../org/apache/hadoop/ozone/audit/AuditAction.java |   0
 .../hadoop/ozone/audit/AuditEventStatus.java       |   0
 .../org/apache/hadoop/ozone/audit/AuditLogger.java |   0
 .../apache/hadoop/ozone/audit/AuditLoggerType.java |   0
 .../org/apache/hadoop/ozone/audit/AuditMarker.java |   0
 .../apache/hadoop/ozone/audit/AuditMessage.java    |   0
 .../org/apache/hadoop/ozone/audit/Auditor.java     |   0
 .../apache/hadoop/ozone/audit/package-info.java    |  14 +-
 .../hadoop/ozone/audit/AuditLogTestUtils.java      |   0
 .../org/apache/hadoop/ozone/audit/DummyAction.java |   0
 .../org/apache/hadoop/ozone/audit/DummyEntity.java |   0
 .../hadoop/ozone/audit/TestOzoneAuditLogger.java   |   0
 .../apache/hadoop/ozone/audit/package-info.java    |   0
 .../src/test/resources/auditlog.properties         |   0
 .../org/apache/hadoop/ozone/audit/SCMAction.java   |   0
 .../apache/hadoop/ozone/audit/package-info.java}   |  20 +--
 .../org/apache/hadoop/ozone/audit/OMAction.java    |   0
 .../apache/hadoop/ozone/audit/package-info.java    |  12 +-
 .../org/apache/hadoop/ozone/audit/S3GAction.java   |   0
 .../apache/hadoop/ozone/audit/package-info.java    |  20 +--
 27 files changed, 207 insertions(+), 396 deletions(-)

diff --git a/hadoop-hdds/common/pom.xml b/hadoop-hdds/common/pom.xml
index ac63fe3bb3..087de5f2aa 100644
--- a/hadoop-hdds/common/pom.xml
+++ b/hadoop-hdds/common/pom.xml
@@ -131,10 +131,6 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd";>
     </dependency>
 
 
-    <dependency>
-      <groupId>org.apache.logging.log4j</groupId>
-      <artifactId>log4j-api</artifactId>
-    </dependency>
     <dependency>
       <groupId>ch.qos.reload4j</groupId>
       <artifactId>reload4j</artifactId>
@@ -145,16 +141,6 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd";>
       <artifactId>slf4j-reload4j</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.logging.log4j</groupId>
-      <artifactId>log4j-core</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>com.lmax</groupId>
-      <artifactId>disruptor</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-pool2</artifactId>
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
index c8284fd8ff..ef1fd7e048 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
@@ -1,138 +1,23 @@
-/**
+/*
  * 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
- * <p>
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
  * 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.hadoop.ozone.audit;
+
 /**
- ******************************************************************************
- *                              Important
- * 1. Any changes to classes in this package can render the logging
- * framework broken.
- * 2. The logger framework has been designed keeping in mind future
- * plans to build a log parser.
- * 3. Please exercise great caution when attempting changes in this package.
- ******************************************************************************
- *
- *
- * This package lays the foundation for Audit logging in Ozone.
- * AuditLogging in Ozone has been built using log4j2 which brings in new
- * features that facilitate turning on/off selective audit events by using
- * MarkerFilter, checking for change in logging configuration periodically
- * and reloading the changes, use of disruptor framework for improved
- * Asynchronous logging.
- *
- * The log4j2 configurations can be specified in XML, YAML, JSON and
- * Properties file. For Ozone, we are using the Properties file due to sheer
- * simplicity, readability and ease of modification.
- *
- * log4j2 configuration file can be passed to startup command with option
- * -Dlog4j.configurationFile unlike -Dlog4j.configuration in log4j 1.x
- *
- ******************************************************************************
- *          Understanding the Audit Logging framework in Ozone.
- ******************************************************************************
- * **** Auditable ***
- * This is an interface to mark an entity as auditable.
- * This interface must be implemented by entities requiring audit logging.
- * For example - OMVolumeArgs, OMBucketArgs.
- * The implementing class must override toAuditMap() to return an
- * instance of Map<Key, Value> where both Key and Value are String.
- *
- * Key: must contain printable US ASCII characters
- * May not contain a space, =, ], or "
- * If the key is multi word then use camel case.
- *
- * Value: if it is a collection/array, then it must be converted to a comma
- * delimited string
- *
- * *** AuditAction ***
- * This is an interface to define the various type of actions to be audited.
- * To ensure separation of concern, for each sub-component you must create an
- * Enum to implement AuditAction.
- * Structure of Enum can be referred from the test class DummyAction.
- *
- * For starters, we expect following 3 implementations of AuditAction:
- * OMAction - to define action types for Ozone Manager
- * SCMAction - to define action types for Storage Container manager
- * DNAction - to define action types for Datanode
- *
- * *** AuditEventStatus ***
- * Enum to define Audit event status like success and failure.
- * This is used in AuditLogger.logXXX() methods.
- *
- *  * *** AuditLogger ***
- * This is where the audit logging magic unfolds.
- * The class has 2 Markers defined - READ and WRITE.
- * These markers are used to tag when logging events.
- *
- * *** AuditLoggerType ***
- * Enum to define the various AuditLoggers in Ozone
- *
- * *** AuditMarker ***
- * Enum to define various Audit Markers used in AuditLogging.
- *
- * *** AuditMessage ***
- * Entity to define an audit message to be logged
- * It will generate a message formatted as:
- * user=xxx ip=xxx op=XXXX_XXXX {key=val, key1=val1..} ret=XXXXXX
- *
- * *** Auditor ***
- * Interface to mark an actor class as Auditor
- * Must be implemented by class where we want to log audit events
- * Implementing class must override and implement methods
- * buildAuditMessageForSuccess and buildAuditMessageForFailure.
- *
- * ****************************************************************************
- *                              Usage
- * ****************************************************************************
- * Using the AuditLogger to log events:
- * 1. Get a logger by specifying the appropriate logger type
- * Example: ExtendedLogger AUDIT = new AuditLogger(AuditLoggerType.OMLogger)
- *
- * 2. Construct an instance of AuditMessage
- *
- * 3. Log Read/Write and Success/Failure event as needed.
- * Example
- * AUDIT.logWriteSuccess(buildAuditMessageForSuccess(params))
- *
- * 4. Log Level implicitly defaults to INFO for xxxxSuccess() and ERROR for
- * xxxxFailure()
- * AUDIT.logWriteSuccess(buildAuditMessageForSuccess(params))
- * AUDIT.logWriteFailure(buildAuditMessageForSuccess(params))
- *
- * See sample invocations in src/test in the following class:
- * org.apache.hadoop.ozone.audit.TestOzoneAuditLogger
- *
- * ****************************************************************************
- *                      Defining new Logger types
- * ****************************************************************************
- * New Logger type can be added with following steps:
- * 1. Update AuditLoggerType to add the new type
- * 2. Create new Enum by implementing AuditAction if needed
- * 3. Ensure the required entity implements Auditable
- *
- * ****************************************************************************
- *                      Defining new Marker types
- * ****************************************************************************
- * New Markers can be configured as follows:
- * 1. Define new markers in AuditMarker
- * 2. Get the Marker in AuditLogger for use in the log methods, example:
- * private static final Marker WRITE_MARKER = AuditMarker.WRITE.getMarker();
- * 3. Define log methods in AuditLogger to use the new Marker type
- * 4. Call these new methods from the required classes to audit with these
- * new markers
- * 5. The marker based filtering can be configured in log4j2 configurations
- * Refer log4j2.properties in src/test/resources for a sample.
+ * This package in hdds-common contains the parts of Ozone's audit framework
+ * that are shared between clients and servers.  See also package of the same
+ * name in hdds-server-framework for details.
  */
+package org.apache.hadoop.ozone.audit;
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerCommandRequestPBHelper.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerCommandRequestPBHelper.java
deleted file mode 100644
index 4d7f0f37c4..0000000000
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerCommandRequestPBHelper.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/**
- * 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.hadoop.ozone.container.common.helpers;
-
-import org.apache.hadoop.hdds.client.BlockID;
-import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.
-    ContainerCommandRequestProto;
-import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Type;
-import org.apache.hadoop.ozone.audit.DNAction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * Utilities for converting protobuf classes to Java classes.
- */
-public final class ContainerCommandRequestPBHelper {
-
-  static final Logger LOG =
-      LoggerFactory.getLogger(ContainerCommandRequestPBHelper.class);
-
-  private ContainerCommandRequestPBHelper() {
-  }
-
-  public static Map<String, String> getAuditParams(
-      ContainerCommandRequestProto msg) {
-    Map<String, String> auditParams = new TreeMap<>();
-    Type cmdType = msg.getCmdType();
-    String containerID = String.valueOf(msg.getContainerID());
-    switch (cmdType) {
-    case CreateContainer:
-      auditParams.put("containerID", containerID);
-      auditParams.put("containerType",
-          msg.getCreateContainer().getContainerType().toString());
-      return auditParams;
-
-    case ReadContainer:
-      auditParams.put("containerID", containerID);
-      return auditParams;
-
-    case UpdateContainer:
-      auditParams.put("containerID", containerID);
-      auditParams.put("forceUpdate",
-          String.valueOf(msg.getUpdateContainer().getForceUpdate()));
-      return auditParams;
-
-    case DeleteContainer:
-      auditParams.put("containerID", containerID);
-      auditParams.put("forceDelete",
-          String.valueOf(msg.getDeleteContainer().getForceDelete()));
-      return auditParams;
-
-    case ListContainer:
-      auditParams.put("startContainerID", containerID);
-      auditParams.put("count",
-          String.valueOf(msg.getListContainer().getCount()));
-      return auditParams;
-
-    case PutBlock:
-      try {
-        auditParams.put("blockData",
-            BlockData.getFromProtoBuf(msg.getPutBlock().getBlockData())
-                .toString());
-      } catch (IOException ex) {
-        if (LOG.isTraceEnabled()) {
-          LOG.trace("Encountered error parsing BlockData from protobuf: "
-              + ex.getMessage());
-        }
-        return null;
-      }
-      return auditParams;
-
-    case GetBlock:
-      auditParams.put("blockData",
-          BlockID.getFromProtobuf(msg.getGetBlock().getBlockID()).toString());
-      return auditParams;
-
-    case DeleteBlock:
-      auditParams.put("blockData",
-          BlockID.getFromProtobuf(msg.getDeleteBlock().getBlockID())
-              .toString());
-      return auditParams;
-
-    case ListBlock:
-      auditParams.put("startLocalID",
-          String.valueOf(msg.getListBlock().getStartLocalID()));
-      auditParams.put("count", String.valueOf(msg.getListBlock().getCount()));
-      return auditParams;
-
-    case ReadChunk:
-      auditParams.put("blockData",
-          BlockID.getFromProtobuf(msg.getReadChunk().getBlockID()).toString());
-      return auditParams;
-
-    case DeleteChunk:
-      auditParams.put("blockData",
-          BlockID.getFromProtobuf(msg.getDeleteChunk().getBlockID())
-              .toString());
-      return auditParams;
-
-    case WriteChunk:
-      auditParams.put("blockData",
-          BlockID.getFromProtobuf(msg.getWriteChunk().getBlockID())
-              .toString());
-      return auditParams;
-
-    case ListChunk:
-      auditParams.put("blockData",
-          BlockID.getFromProtobuf(msg.getListChunk().getBlockID()).toString());
-      auditParams.put("prevChunkName", msg.getListChunk().getPrevChunkName());
-      auditParams.put("count", String.valueOf(msg.getListChunk().getCount()));
-      return auditParams;
-
-    case CompactChunk: return null; //CompactChunk operation
-
-    case PutSmallFile:
-      try {
-        auditParams.put("blockData",
-            BlockData.getFromProtoBuf(msg.getPutSmallFile()
-                .getBlock().getBlockData()).toString());
-      } catch (IOException ex) {
-        if (LOG.isTraceEnabled()) {
-          LOG.trace("Encountered error parsing BlockData from protobuf: "
-              + ex.getMessage());
-        }
-      }
-      return auditParams;
-
-    case GetSmallFile:
-      auditParams.put("blockData",
-          
BlockID.getFromProtobuf(msg.getGetSmallFile().getBlock().getBlockID())
-              .toString());
-      return auditParams;
-
-    case CloseContainer:
-      auditParams.put("containerID", containerID);
-      return auditParams;
-
-    case GetCommittedBlockLength:
-      auditParams.put("blockData",
-          
BlockID.getFromProtobuf(msg.getGetCommittedBlockLength().getBlockID())
-              .toString());
-      return auditParams;
-
-    default :
-      LOG.debug("Invalid command type - {}", cmdType);
-      return null;
-    }
-
-  }
-
-  public static DNAction getAuditAction(Type cmdType) {
-    switch (cmdType) {
-    case CreateContainer  : return DNAction.CREATE_CONTAINER;
-    case ReadContainer    : return DNAction.READ_CONTAINER;
-    case UpdateContainer  : return DNAction.UPDATE_CONTAINER;
-    case DeleteContainer  : return DNAction.DELETE_CONTAINER;
-    case ListContainer    : return DNAction.LIST_CONTAINER;
-    case PutBlock         : return DNAction.PUT_BLOCK;
-    case GetBlock         : return DNAction.GET_BLOCK;
-    case DeleteBlock      : return DNAction.DELETE_BLOCK;
-    case ListBlock        : return DNAction.LIST_BLOCK;
-    case ReadChunk        : return DNAction.READ_CHUNK;
-    case DeleteChunk      : return DNAction.DELETE_CHUNK;
-    case WriteChunk       : return DNAction.WRITE_CHUNK;
-    case ListChunk        : return DNAction.LIST_CHUNK;
-    case CompactChunk     : return DNAction.COMPACT_CHUNK;
-    case PutSmallFile     : return DNAction.PUT_SMALL_FILE;
-    case GetSmallFile     : return DNAction.GET_SMALL_FILE;
-    case CloseContainer   : return DNAction.CLOSE_CONTAINER;
-    case GetCommittedBlockLength : return DNAction.GET_COMMITTED_BLOCK_LENGTH;
-    case StreamInit       : return DNAction.STREAM_INIT;
-    default :
-      LOG.debug("Invalid command type - {}", cmdType);
-      return null;
-    }
-  }
-
-}
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/DNAction.java 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/audit/DNAction.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/DNAction.java
rename to 
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/audit/DNAction.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
similarity index 82%
copy from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
copy to 
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
index 8c1d6f0c67..6882d784b7 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
@@ -1,13 +1,13 @@
-/**
+/*
  * 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
- * <p>
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
  * 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
@@ -15,16 +15,8 @@
  * the License.
  */
 
-package org.apache.hadoop.ozone.audit;
-
 /**
- * Interface to define AuditAction.
+ * This package defines DNAction - an implementation of AuditAction
+ * for various actions that will be audited in Datanode.
  */
-public interface AuditAction {
-  /**
-   * Implementation must override.
-   * @return String
-   */
-  String getAction();
-}
-
+package org.apache.hadoop.ozone.audit;
diff --git 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/HddsDispatcher.java
 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/HddsDispatcher.java
index 11f67a0482..300c15bb72 100644
--- 
a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/HddsDispatcher.java
+++ 
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/HddsDispatcher.java
@@ -23,6 +23,7 @@ import com.google.common.base.Preconditions;
 import com.google.protobuf.ServiceException;
 import org.apache.hadoop.hdds.HddsConfigKeys;
 import org.apache.hadoop.hdds.HddsUtils;
+import org.apache.hadoop.hdds.client.BlockID;
 import org.apache.hadoop.hdds.conf.ConfigurationSource;
 import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
 import 
org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto;
@@ -47,7 +48,8 @@ import org.apache.hadoop.ozone.audit.AuditLoggerType;
 import org.apache.hadoop.ozone.audit.AuditMarker;
 import org.apache.hadoop.ozone.audit.AuditMessage;
 import org.apache.hadoop.ozone.audit.Auditor;
-import 
org.apache.hadoop.ozone.container.common.helpers.ContainerCommandRequestPBHelper;
+import org.apache.hadoop.ozone.audit.DNAction;
+import org.apache.hadoop.ozone.container.common.helpers.BlockData;
 import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics;
 import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils;
 import org.apache.hadoop.ozone.container.common.interfaces.Container;
@@ -71,6 +73,7 @@ import java.io.IOException;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.TreeMap;
 
 import static 
org.apache.hadoop.hdds.scm.protocolPB.ContainerCommandResponseBuilders.malformedRequest;
 import static 
org.apache.hadoop.hdds.scm.protocolPB.ContainerCommandResponseBuilders.unsupportedRequest;
@@ -189,11 +192,9 @@ public class HddsDispatcher implements 
ContainerDispatcher, Auditor {
           msg.getTraceID());
     }
 
-    AuditAction action = ContainerCommandRequestPBHelper.getAuditAction(
-        msg.getCmdType());
+    AuditAction action = getAuditAction(msg.getCmdType());
     EventType eventType = getEventType(msg);
-    Map<String, String> params =
-        ContainerCommandRequestPBHelper.getAuditParams(msg);
+    Map<String, String> params = getAuditParams(msg);
 
     ContainerType containerType;
     ContainerCommandResponseProto responseProto = null;
@@ -491,11 +492,9 @@ public class HddsDispatcher implements 
ContainerDispatcher, Auditor {
     }
     ContainerType containerType = container.getContainerType();
     Type cmdType = msg.getCmdType();
-    AuditAction action =
-        ContainerCommandRequestPBHelper.getAuditAction(cmdType);
+    AuditAction action = getAuditAction(cmdType);
     EventType eventType = getEventType(msg);
-    Map<String, String> params =
-        ContainerCommandRequestPBHelper.getAuditParams(msg);
+    Map<String, String> params = getAuditParams(msg);
     Handler handler = getHandler(containerType);
     if (handler == null) {
       StorageContainerException ex = new StorageContainerException(
@@ -744,4 +743,158 @@ public class HddsDispatcher implements 
ContainerDispatcher, Auditor {
     }
   }
 
+  private static DNAction getAuditAction(Type cmdType) {
+    switch (cmdType) {
+    case CreateContainer  : return DNAction.CREATE_CONTAINER;
+    case ReadContainer    : return DNAction.READ_CONTAINER;
+    case UpdateContainer  : return DNAction.UPDATE_CONTAINER;
+    case DeleteContainer  : return DNAction.DELETE_CONTAINER;
+    case ListContainer    : return DNAction.LIST_CONTAINER;
+    case PutBlock         : return DNAction.PUT_BLOCK;
+    case GetBlock         : return DNAction.GET_BLOCK;
+    case DeleteBlock      : return DNAction.DELETE_BLOCK;
+    case ListBlock        : return DNAction.LIST_BLOCK;
+    case ReadChunk        : return DNAction.READ_CHUNK;
+    case DeleteChunk      : return DNAction.DELETE_CHUNK;
+    case WriteChunk       : return DNAction.WRITE_CHUNK;
+    case ListChunk        : return DNAction.LIST_CHUNK;
+    case CompactChunk     : return DNAction.COMPACT_CHUNK;
+    case PutSmallFile     : return DNAction.PUT_SMALL_FILE;
+    case GetSmallFile     : return DNAction.GET_SMALL_FILE;
+    case CloseContainer   : return DNAction.CLOSE_CONTAINER;
+    case GetCommittedBlockLength : return DNAction.GET_COMMITTED_BLOCK_LENGTH;
+    case StreamInit       : return DNAction.STREAM_INIT;
+    default :
+      LOG.debug("Invalid command type - {}", cmdType);
+      return null;
+    }
+  }
+
+  private static Map<String, String> getAuditParams(
+      ContainerCommandRequestProto msg) {
+    Map<String, String> auditParams = new TreeMap<>();
+    Type cmdType = msg.getCmdType();
+    String containerID = String.valueOf(msg.getContainerID());
+    switch (cmdType) {
+    case CreateContainer:
+      auditParams.put("containerID", containerID);
+      auditParams.put("containerType",
+          msg.getCreateContainer().getContainerType().toString());
+      return auditParams;
+
+    case ReadContainer:
+      auditParams.put("containerID", containerID);
+      return auditParams;
+
+    case UpdateContainer:
+      auditParams.put("containerID", containerID);
+      auditParams.put("forceUpdate",
+          String.valueOf(msg.getUpdateContainer().getForceUpdate()));
+      return auditParams;
+
+    case DeleteContainer:
+      auditParams.put("containerID", containerID);
+      auditParams.put("forceDelete",
+          String.valueOf(msg.getDeleteContainer().getForceDelete()));
+      return auditParams;
+
+    case ListContainer:
+      auditParams.put("startContainerID", containerID);
+      auditParams.put("count",
+          String.valueOf(msg.getListContainer().getCount()));
+      return auditParams;
+
+    case PutBlock:
+      try {
+        auditParams.put("blockData",
+            BlockData.getFromProtoBuf(msg.getPutBlock().getBlockData())
+                .toString());
+      } catch (IOException ex) {
+        if (LOG.isTraceEnabled()) {
+          LOG.trace("Encountered error parsing BlockData from protobuf: "
+              + ex.getMessage());
+        }
+        return null;
+      }
+      return auditParams;
+
+    case GetBlock:
+      auditParams.put("blockData",
+          BlockID.getFromProtobuf(msg.getGetBlock().getBlockID()).toString());
+      return auditParams;
+
+    case DeleteBlock:
+      auditParams.put("blockData",
+          BlockID.getFromProtobuf(msg.getDeleteBlock().getBlockID())
+              .toString());
+      return auditParams;
+
+    case ListBlock:
+      auditParams.put("startLocalID",
+          String.valueOf(msg.getListBlock().getStartLocalID()));
+      auditParams.put("count", String.valueOf(msg.getListBlock().getCount()));
+      return auditParams;
+
+    case ReadChunk:
+      auditParams.put("blockData",
+          BlockID.getFromProtobuf(msg.getReadChunk().getBlockID()).toString());
+      return auditParams;
+
+    case DeleteChunk:
+      auditParams.put("blockData",
+          BlockID.getFromProtobuf(msg.getDeleteChunk().getBlockID())
+              .toString());
+      return auditParams;
+
+    case WriteChunk:
+      auditParams.put("blockData",
+          BlockID.getFromProtobuf(msg.getWriteChunk().getBlockID())
+              .toString());
+      return auditParams;
+
+    case ListChunk:
+      auditParams.put("blockData",
+          BlockID.getFromProtobuf(msg.getListChunk().getBlockID()).toString());
+      auditParams.put("prevChunkName", msg.getListChunk().getPrevChunkName());
+      auditParams.put("count", String.valueOf(msg.getListChunk().getCount()));
+      return auditParams;
+
+    case CompactChunk: return null; //CompactChunk operation
+
+    case PutSmallFile:
+      try {
+        auditParams.put("blockData",
+            BlockData.getFromProtoBuf(msg.getPutSmallFile()
+                .getBlock().getBlockData()).toString());
+      } catch (IOException ex) {
+        if (LOG.isTraceEnabled()) {
+          LOG.trace("Encountered error parsing BlockData from protobuf: "
+              + ex.getMessage());
+        }
+      }
+      return auditParams;
+
+    case GetSmallFile:
+      auditParams.put("blockData",
+          
BlockID.getFromProtobuf(msg.getGetSmallFile().getBlock().getBlockID())
+              .toString());
+      return auditParams;
+
+    case CloseContainer:
+      auditParams.put("containerID", containerID);
+      return auditParams;
+
+    case GetCommittedBlockLength:
+      auditParams.put("blockData",
+          
BlockID.getFromProtobuf(msg.getGetCommittedBlockLength().getBlockID())
+              .toString());
+      return auditParams;
+
+    default :
+      LOG.debug("Invalid command type - {}", cmdType);
+      return null;
+    }
+
+  }
+
 }
diff --git a/hadoop-hdds/framework/pom.xml b/hadoop-hdds/framework/pom.xml
index d806637e23..fdc52db661 100644
--- a/hadoop-hdds/framework/pom.xml
+++ b/hadoop-hdds/framework/pom.xml
@@ -76,6 +76,10 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd";>
       <artifactId>commons-fileupload</artifactId>
       <version>${commons-fileupload.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-core</artifactId>
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
similarity index 100%
copy from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
copy to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditEventStatus.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditEventStatus.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditEventStatus.java
rename to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditEventStatus.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditLogger.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditLogger.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditLogger.java
rename to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditLogger.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditLoggerType.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditLoggerType.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditLoggerType.java
rename to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditLoggerType.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditMarker.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditMarker.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditMarker.java
rename to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditMarker.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditMessage.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditMessage.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditMessage.java
rename to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/AuditMessage.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/Auditor.java 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/Auditor.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/Auditor.java
rename to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/Auditor.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
similarity index 97%
copy from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
copy to 
hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
index c8284fd8ff..0c1ec710d2 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
+++ 
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
@@ -1,20 +1,20 @@
-/**
+/*
  * 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
- * <p>
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
  * 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.hadoop.ozone.audit;
+
 /**
  ******************************************************************************
  *                              Important
@@ -63,10 +63,13 @@ package org.apache.hadoop.ozone.audit;
  * Enum to implement AuditAction.
  * Structure of Enum can be referred from the test class DummyAction.
  *
- * For starters, we expect following 3 implementations of AuditAction:
+ * Existing implementations of AuditAction:
  * OMAction - to define action types for Ozone Manager
  * SCMAction - to define action types for Storage Container manager
  * DNAction - to define action types for Datanode
+ * S3GAction - to define action types for S3 Gateway
+ *
+ * These can be found in the corresponding HDDS/Ozone submodules.
  *
  * *** AuditEventStatus ***
  * Enum to define Audit event status like success and failure.
@@ -136,3 +139,4 @@ package org.apache.hadoop.ozone.audit;
  * 5. The marker based filtering can be configured in log4j2 configurations
  * Refer log4j2.properties in src/test/resources for a sample.
  */
+package org.apache.hadoop.ozone.audit;
diff --git 
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java
 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java
similarity index 100%
rename from 
hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java
rename to 
hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/AuditLogTestUtils.java
diff --git 
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/DummyAction.java
 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/DummyAction.java
similarity index 100%
rename from 
hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/DummyAction.java
rename to 
hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/DummyAction.java
diff --git 
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/DummyEntity.java
 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/DummyEntity.java
similarity index 100%
rename from 
hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/DummyEntity.java
rename to 
hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/DummyEntity.java
diff --git 
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
similarity index 100%
rename from 
hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
rename to 
hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/TestOzoneAuditLogger.java
diff --git 
a/hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/package-info.java
 
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/package-info.java
similarity index 100%
rename from 
hadoop-hdds/common/src/test/java/org/apache/hadoop/ozone/audit/package-info.java
rename to 
hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/audit/package-info.java
diff --git a/hadoop-hdds/common/src/test/resources/auditlog.properties 
b/hadoop-hdds/framework/src/test/resources/auditlog.properties
similarity index 100%
rename from hadoop-hdds/common/src/test/resources/auditlog.properties
rename to hadoop-hdds/framework/src/test/resources/auditlog.properties
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/SCMAction.java 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/ozone/audit/SCMAction.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/SCMAction.java
rename to 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/ozone/audit/SCMAction.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
similarity index 82%
copy from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
copy to 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
index 8c1d6f0c67..7e5b6ca8aa 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
@@ -1,13 +1,13 @@
-/**
+/*
  * 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
- * <p>
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
  * 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
@@ -15,16 +15,8 @@
  * the License.
  */
 
-package org.apache.hadoop.ozone.audit;
-
 /**
- * Interface to define AuditAction.
+ * This package defines SCMAction - an implementation of AuditAction
+ * for various actions that will be audited in SCM.
  */
-public interface AuditAction {
-  /**
-   * Implementation must override.
-   * @return String
-   */
-  String getAction();
-}
-
+package org.apache.hadoop.ozone.audit;
diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/audit/OMAction.java 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/audit/OMAction.java
similarity index 100%
rename from 
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/audit/OMAction.java
rename to 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/audit/OMAction.java
diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
similarity index 88%
rename from 
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
rename to 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
index 0f887909d4..a8ea651718 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
@@ -1,22 +1,22 @@
-/**
+/*
  * 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
- * <p>
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
  * 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.hadoop.ozone.audit;
+
 /**
  * This package defines OMAction - an implementation of AuditAction
- * OMAction defines audit action types for various actions that will be
- * audited in OzoneManager.
+ * for various actions that will be audited in Ozone Manager.
  */
+package org.apache.hadoop.ozone.audit;
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java
similarity index 100%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java
rename to 
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/S3GAction.java
diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
similarity index 82%
rename from 
hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
rename to 
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
index 8c1d6f0c67..df024d64ba 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/audit/AuditAction.java
+++ 
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/audit/package-info.java
@@ -1,13 +1,13 @@
-/**
+/*
  * 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
- * <p>
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
  * 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
@@ -15,16 +15,8 @@
  * the License.
  */
 
-package org.apache.hadoop.ozone.audit;
-
 /**
- * Interface to define AuditAction.
+ * This package defines S3GAction - an implementation of AuditAction
+ * for various actions that will be audited in S3 Gateway.
  */
-public interface AuditAction {
-  /**
-   * Implementation must override.
-   * @return String
-   */
-  String getAction();
-}
-
+package org.apache.hadoop.ozone.audit;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to