You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by st...@apache.org on 2016/04/12 15:00:00 UTC

[1/3] ambari git commit: AMBARI-15804. Audit logging cleanup and tests. (Daniel Gergely via stoader)

Repository: ambari
Updated Branches:
  refs/heads/trunk 7f8da72ff -> af13ef739


http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java
new file mode 100644
index 0000000..dd4fdc7
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.UpdateUpgradeItemRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.UpgradeItemEventCreator;
+import org.apache.ambari.server.controller.internal.UpgradeItemResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Test;
+
+public class UpgradeItemEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    UpgradeItemEventCreator creator = new UpgradeItemEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UpgradeItemResourceProvider.UPGRADE_ITEM_STAGE_ID, "1");
+    properties.put(UpgradeItemResourceProvider.UPGRADE_REQUEST_ID, "9");
+    properties.put(PropertyHelper.getPropertyId("UpgradeItem", "status"), "Status");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.UpgradeItem, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Action confirmation by the user), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Stage id(1), Status(Status), Request id(9)";
+
+    Assert.assertTrue("Class mismatch", event instanceof UpdateUpgradeItemRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java
new file mode 100644
index 0000000..746d87b
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.ActivateUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.AdminUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.CreateUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.UserPasswordChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.UserEventCreator;
+import org.apache.ambari.server.controller.internal.UserResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class UserEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, "false");
+    properties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, "true");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.User, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(User creation), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Created Username(myUser), Active(yes), Administrator(no)";
+
+    Assert.assertTrue("Class mismatch", event instanceof CreateUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.User, "userToDelete");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.User, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(User delete), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Deleted Username(userToDelete)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void activeTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, "true");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.User, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Set user active/inactive), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Affected username(myUser), Active(yes)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ActivateUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void adminTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, "false");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.User, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Set user admin), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Affeted username(myUser), Administrator(no)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AdminUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void passwordChangeTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_OLD_PASSWORD_PROPERTY_ID, "oldPassword");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.User, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Password change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Affected username(myUser)";
+
+    Assert.assertTrue("Class mismatch", event instanceof UserPasswordChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java
new file mode 100644
index 0000000..bf7b663
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.request.eventcreator.ValidationIgnoreEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ValidationIgnoreEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test(expected = AssertionError.class)
+  public void postTest() {
+    ValidationIgnoreEventCreator creator = new ValidationIgnoreEventCreator();
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Validation, null, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEventCreatorTestHelper.getEvent(creator, request, result);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java
new file mode 100644
index 0000000..4369273
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddViewInstanceRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.ChangeViewInstanceRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteViewInstanceRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ViewInstanceEventCreator;
+import org.apache.ambari.server.controller.internal.ViewInstanceResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ViewInstanceEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    ViewInstanceEventCreator creator = new ViewInstanceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ViewInstanceResourceProvider.VIEW_NAME_PROPERTY_ID, "MyView");
+    properties.put(ViewInstanceResourceProvider.VIEW_VERSION_PROPERTY_ID, "1.9");
+    properties.put(ViewInstanceResourceProvider.INSTANCE_NAME_PROPERTY_ID, "MyViewInstance");
+    properties.put(ViewInstanceResourceProvider.LABEL_PROPERTY_ID, "MyViewLabel");
+    properties.put(ViewInstanceResourceProvider.DESCRIPTION_PROPERTY_ID, "Test view");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.ViewInstance, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(MyView), Version(1.9), Name(MyViewInstance), Display name(MyViewLabel), Description(Test view)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddViewInstanceRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    ViewInstanceEventCreator creator = new ViewInstanceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ViewInstanceResourceProvider.VIEW_NAME_PROPERTY_ID, "MyView");
+    properties.put(ViewInstanceResourceProvider.VIEW_VERSION_PROPERTY_ID, "1.9");
+    properties.put(ViewInstanceResourceProvider.INSTANCE_NAME_PROPERTY_ID, "MyViewInstance");
+    properties.put(ViewInstanceResourceProvider.LABEL_PROPERTY_ID, "MyViewLabel");
+    properties.put(ViewInstanceResourceProvider.DESCRIPTION_PROPERTY_ID, "Test view");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.ViewInstance, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(MyView), Version(1.9), Name(MyViewInstance), Display name(MyViewLabel), Description(Test view)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ChangeViewInstanceRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    ViewInstanceEventCreator creator = new ViewInstanceEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.View, "MyView");
+    resource.put(Resource.Type.ViewVersion, "1.2");
+    resource.put(Resource.Type.ViewInstance, "MyViewInstance");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.ViewInstance, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View deletion), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(MyView), Version(1.2), Name(MyViewInstance)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteViewInstanceRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
new file mode 100644
index 0000000..ab2b068
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.NamedPropertySet;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.ViewPrivilegeChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ViewPrivilegeEventCreator;
+import org.apache.ambari.server.controller.internal.ViewPrivilegeResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ViewPrivilegeEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void putTest() {
+    ViewPrivilegeEventCreator creator = new ViewPrivilegeEventCreator();
+
+    Map<String,Object> props = new HashMap<>();
+    props.put(ViewPrivilegeResourceProvider.PRIVILEGE_VIEW_NAME_PROPERTY_ID, "MyView");
+    props.put(ViewPrivilegeResourceProvider.PRIVILEGE_VIEW_VERSION_PROPERTY_ID, "MyView");
+    props.put(ViewPrivilegeResourceProvider.PRIVILEGE_INSTANCE_NAME_PROPERTY_ID, "MyView");
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ViewPrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "USER");
+    properties.put(ViewPrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission1");
+    properties.put(ViewPrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, userName);
+
+    Map<String,Object> properties2 = new HashMap<>();
+    properties2.put(ViewPrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "USER");
+    properties2.put(ViewPrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission2");
+    properties2.put(ViewPrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, userName + "2");
+
+    Map<String,Object> properties3 = new HashMap<>();
+    properties3.put(ViewPrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "GROUP");
+    properties3.put(ViewPrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission1");
+    properties3.put(ViewPrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, "testgroup");
+
+    NamedPropertySet nps = new NamedPropertySet("1",properties);
+    NamedPropertySet nps2 = new NamedPropertySet("2",properties2);
+    NamedPropertySet nps3 = new NamedPropertySet("3",properties3);
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.ViewPrivilege, props, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    request.getBody().addPropertySet(nps);
+    request.getBody().addPropertySet(nps2);
+    request.getBody().addPropertySet(nps3);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View permission change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(MyView), Version(MyView), Name(MyView), Permissions(\n" +
+      "Permission2: \n" +
+      "  Users: testuser2\n" +
+      "Permission1: \n" +
+      "  Users: testuser\n" +
+      "  Groups: testgroup)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ViewPrivilegeChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+
+}


[2/3] ambari git commit: AMBARI-15804. Audit logging cleanup and tests. (Daniel Gergely via stoader)

Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ComponentEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ComponentEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ComponentEventCreatorTest.java
new file mode 100644
index 0000000..59f6ff2
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ComponentEventCreatorTest.java
@@ -0,0 +1,229 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.api.util.TreeNode;
+import org.apache.ambari.server.api.util.TreeNodeImpl;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.StartOperationRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ComponentEventCreator;
+import org.apache.ambari.server.controller.internal.HostComponentResourceProvider;
+import org.apache.ambari.server.controller.internal.RequestOperationLevel;
+import org.apache.ambari.server.controller.internal.RequestResourceProvider;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Test;
+
+public class ComponentEventCreatorTest extends AuditEventCreatorTestBase {
+
+  @Test
+  public void deleteTest() {
+    ComponentEventCreator creator = new ComponentEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ambari1.example.com");
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.HostComponent, "MyComponent");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.HostComponent, properties, resource);
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Delete component MyComponent), Host name(ambari1.example.com), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putForAllHostsTest() {
+    allHostsTest(Request.Type.PUT);
+  }
+  @Test
+  public void postForAllHostsTest() {
+    allHostsTest(Request.Type.POST);
+  }
+
+  private void allHostsTest(Request.Type type) {
+    ComponentEventCreator creator = new ComponentEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ambari1.example.com");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID, "mycluster");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(type, Resource.Type.HostComponent, properties, null);
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_LEVEL_ID, "CLUSTER");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_CLUSTER_ID, "mycluster");
+    request.getBody().setQueryString("hostname.in(a,b,c)");
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(STARTED: all services on all hosts that matches hostname.in(a,b,c) (mycluster)), Host name(ambari1.example.com), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void hostTest() {
+    ComponentEventCreator creator = new ComponentEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ambari1.example.com");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID, "mycluster");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.HostComponent, properties, null);
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_LEVEL_ID, "HOST");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_HOST_NAME, "ambari1.example.com");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_CLUSTER_ID, "mycluster");
+    request.getBody().addRequestInfoProperty("query", "host_component.in(MYCOMPONENT,MYCOMPONENT2)");
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(STARTED: MYCOMPONENT,MYCOMPONENT2 on ambari1.example.com (mycluster)), Host name(ambari1.example.com), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void hostComponentTest() {
+    ComponentEventCreator creator = new ComponentEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ambari1.example.com");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID, "mycluster");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "MYCOMPONENT");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.HostComponent, properties, null);
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_LEVEL_ID, "HOST_COMPONENT");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_SERVICE_ID, "MYSERVICE");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_HOST_NAME, "ambari1.example.com");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_CLUSTER_ID, "mycluster");
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(STARTED: MYCOMPONENT/MYSERVICE on ambari1.example.com (mycluster)), Host name(ambari1.example.com), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void maintenanceModeTest() {
+    ComponentEventCreator creator = new ComponentEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ambari1.example.com");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_MAINTENANCE_STATE_PROPERTY_ID, "ON");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "MYCOMPONENT");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.HostComponent, properties, null);
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Turn ON Maintenance Mode for MYCOMPONENT), Host name(ambari1.example.com), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void failureTest() {
+    ComponentEventCreator creator = new ComponentEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ambari1.example.com");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_MAINTENANCE_STATE_PROPERTY_ID, "ON");
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "MYCOMPONENT");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.HostComponent, properties, null);
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, "Failed for testing"), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Turn ON Maintenance Mode for MYCOMPONENT), Host name(ambari1.example.com), RequestId(1), Status(Failed to queue), Reason(Failed for testing)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  private void addRequestId(TreeNode<Resource> resultTree, Long requestId) {
+    Resource resource = new ResourceImpl(Resource.Type.Request);
+    resource.addCategory(PropertyHelper.getPropertyCategory(RequestResourceProvider.REQUEST_ID_PROPERTY_ID));
+    resource.setProperty(RequestResourceProvider.REQUEST_ID_PROPERTY_ID, requestId);
+    TreeNode<Resource> requestNode = new TreeNodeImpl<>(resultTree, resource, "request");
+    resultTree.addChild(requestNode);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ConfigurationChangeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ConfigurationChangeEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ConfigurationChangeEventCreatorTest.java
new file mode 100644
index 0000000..a0a06fb
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ConfigurationChangeEventCreatorTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.api.util.TreeNode;
+import org.apache.ambari.server.api.util.TreeNodeImpl;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.ClusterNameChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.ConfigurationChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ConfigurationChangeEventCreator;
+import org.apache.ambari.server.controller.internal.ClusterResourceProvider;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.internal.ServiceConfigVersionResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ConfigurationChangeEventCreatorTest extends AuditEventCreatorTestBase {
+
+  @Test
+  public void clusterNameChangeTest() {
+    ConfigurationChangeEventCreator creator = new ConfigurationChangeEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, "newname");
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Cluster, "oldname");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.Cluster, properties, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Cluster name change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Old name(oldname), New name(newname)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ClusterNameChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void configurationChangeTest() {
+    ConfigurationChangeEventCreator creator = new ConfigurationChangeEventCreator();
+
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    Resource resource = new ResourceImpl(Resource.Type.Cluster);
+    TreeNode<Resource> resourceNode = new TreeNodeImpl<>(resultTree, resource, "resources");
+    Resource version = new ResourceImpl(Resource.Type.Cluster);
+    version.setProperty(ServiceConfigVersionResourceProvider.SERVICE_CONFIG_VERSION_PROPERTY_ID, "1");
+    version.setProperty(ServiceConfigVersionResourceProvider.SERVICE_CONFIG_VERSION_NOTE_PROPERTY_ID, "note");
+    TreeNode<Resource> versionNode = new TreeNodeImpl<>(resourceNode, version, "");
+    resourceNode.addChild(versionNode);
+    resultTree.addChild(resourceNode);
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.Cluster, new HashMap<String, Object>(), null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Configuration change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), VersionNumber(V1), VersionNote(note)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ConfigurationChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/CredentialEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/CredentialEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/CredentialEventCreatorTest.java
new file mode 100644
index 0000000..fda478e
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/CredentialEventCreatorTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddCredentialRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.CredentialEventCreator;
+import org.apache.ambari.server.controller.internal.CredentialResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class CredentialEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    CredentialEventCreator creator = new CredentialEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(CredentialResourceProvider.CREDENTIAL_CLUSTER_NAME_PROPERTY_ID, "mycluster");
+    properties.put(CredentialResourceProvider.CREDENTIAL_TYPE_PROPERTY_ID, "USER");
+    properties.put(CredentialResourceProvider.CREDENTIAL_ALIAS_PROPERTY_ID, "Alias");
+    properties.put(CredentialResourceProvider.CREDENTIAL_PRINCIPAL_PROPERTY_ID, "newuser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Credential, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Credential addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(USER), Principal(newuser), Alias(Alias), Cluster name(mycluster)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddCredentialRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/DefaultEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/DefaultEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/DefaultEventCreatorTest.java
new file mode 100644
index 0000000..56aaaed
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/DefaultEventCreatorTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.request.RequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.DefaultEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class DefaultEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    DefaultEventCreator creator = new DefaultEventCreator();
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Credential, null, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK)";
+
+    Assert.assertTrue("Class mismatch", event instanceof RequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/GroupEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/GroupEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/GroupEventCreatorTest.java
new file mode 100644
index 0000000..7d5ad79
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/GroupEventCreatorTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.CreateGroupRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteGroupRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.GroupEventCreator;
+import org.apache.ambari.server.controller.internal.GroupResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class GroupEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    GroupEventCreator creator = new GroupEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(GroupResourceProvider.GROUP_GROUPNAME_PROPERTY_ID, "GroupName");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Group, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Group creation), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Group(GroupName)";
+
+    Assert.assertTrue("Class mismatch", event instanceof CreateGroupRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    GroupEventCreator creator = new GroupEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Group, "GroupName");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.Group, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Group delete), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Group(GroupName)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteGroupRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/HostEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/HostEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/HostEventCreatorTest.java
new file mode 100644
index 0000000..ae7ba9d
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/HostEventCreatorTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddComponentToHostRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.AddHostRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteHostRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.HostEventCreator;
+import org.apache.ambari.server.controller.internal.HostComponentResourceProvider;
+import org.apache.ambari.server.controller.internal.HostResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class HostEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    HostEventCreator creator = new HostEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, "ambari1.example.com");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Host, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Host addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Hostname(ambari1.example.com)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddHostRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void queryPostTest() {
+    HostEventCreator creator = new HostEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+
+    Set<Map<String,String>> set = new HashSet<>();
+    Map<String,String> map = new HashMap<>();
+    map.put(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "MYCOMPONENT");
+    set.add(map);
+
+    properties.put("host_components", set);
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.QUERY_POST, Resource.Type.Host, properties, null, HostResourceProvider.HOST_NAME_PROPERTY_ID + "=ambari1.example.com");
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Component addition to host), RequestType(QUERY_POST), url(http://example.com:8080/api/v1/testHosts/host_name=ambari1.example.com), ResultStatus(200 OK), Hostname(ambari1.example.com), Component(MYCOMPONENT)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddComponentToHostRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    HostEventCreator creator = new HostEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Host, "ambari1.example.com");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.Host, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Host deletion), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Hostname(ambari1.example.com)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteHostRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/MemberEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/MemberEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/MemberEventCreatorTest.java
new file mode 100644
index 0000000..6e9ec0f
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/MemberEventCreatorTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddUserToGroupRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.MembershipChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.RemoveUserFromGroupRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.MemberEventCreator;
+import org.apache.ambari.server.controller.internal.MemberResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class MemberEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    MemberEventCreator creator = new MemberEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Group, "GroupName");
+    resource.put(Resource.Type.Member, "MemberName");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Member, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(User addition to group), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Group(GroupName), Affected username(MemberName)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddUserToGroupRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    MemberEventCreator creator = new MemberEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(MemberResourceProvider.MEMBER_GROUP_NAME_PROPERTY_ID, "GroupName");
+    properties.put(MemberResourceProvider.MEMBER_USER_NAME_PROPERTY_ID, "MemberName");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.Member, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Membership change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Group(GroupName), Members(MemberName)";
+
+    Assert.assertTrue("Class mismatch", event instanceof MembershipChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    MemberEventCreator creator = new MemberEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Group, "GroupName");
+    resource.put(Resource.Type.Member, "MemberName");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.Member, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(User removal from group), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Group(GroupName), Affected username(MemberName)";
+
+    Assert.assertTrue("Class mismatch", event instanceof RemoveUserFromGroupRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
new file mode 100644
index 0000000..ff4abd6
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.NamedPropertySet;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.ClusterPrivilegeChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.PrivilegeChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.PrivilegeEventCreator;
+import org.apache.ambari.server.controller.internal.PrivilegeResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class PrivilegeEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    PrivilegeEventCreator creator = new PrivilegeEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(PrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "USER");
+    properties.put(PrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission2");
+    properties.put(PrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, userName + "2");
+
+    NamedPropertySet nps = new NamedPropertySet("1",properties);
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.ClusterPrivilege, null, null);
+    request.getBody().addPropertySet(nps);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(User role change), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Role(Permission2), User(" + userName + "2)";
+
+    Assert.assertTrue("Class mismatch", event instanceof PrivilegeChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    PrivilegeEventCreator creator = new PrivilegeEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(PrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "USER");
+    properties.put(PrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission1");
+    properties.put(PrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, userName);
+
+    Map<String,Object> properties2 = new HashMap<>();
+    properties2.put(PrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "USER");
+    properties2.put(PrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission2");
+    properties2.put(PrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, userName + "2");
+
+    Map<String,Object> properties3 = new HashMap<>();
+    properties3.put(PrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "GROUP");
+    properties3.put(PrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission1");
+    properties3.put(PrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, "testgroup");
+
+    NamedPropertySet nps = new NamedPropertySet("1",properties);
+    NamedPropertySet nps2 = new NamedPropertySet("2",properties2);
+    NamedPropertySet nps3 = new NamedPropertySet("3",properties3);
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.ClusterPrivilege, null, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    request.getBody().addPropertySet(nps);
+    request.getBody().addPropertySet(nps2);
+    request.getBody().addPropertySet(nps3);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Role change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Roles(\n" +
+      "Permission2: \n" +
+      "  Users: " + userName + "2\n" +
+      "Permission1: \n" +
+      "  Users: " + userName + "\n" +
+      "  Groups: testgroup)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ClusterPrivilegeChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RecomendationIgnoreEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RecomendationIgnoreEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RecomendationIgnoreEventCreatorTest.java
new file mode 100644
index 0000000..d5ffcf4
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RecomendationIgnoreEventCreatorTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.request.eventcreator.RecommendationIgnoreEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class RecomendationIgnoreEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test(expected = AssertionError.class)
+  public void postTest() {
+    RecommendationIgnoreEventCreator creator = new RecommendationIgnoreEventCreator();
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Recommendation, null, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEventCreatorTestHelper.getEvent(creator, request, result);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryEventCreatorTest.java
new file mode 100644
index 0000000..3479334
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryEventCreatorTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddRepositoryRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.UpdateRepositoryRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.RepositoryEventCreator;
+import org.apache.ambari.server.controller.internal.RepositoryResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class RepositoryEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    RepositoryEventCreator creator = new RepositoryEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, "Repo1");
+    properties.put(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID, "StackName");
+    properties.put(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID, "1.2-56");
+    properties.put(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID, "redhat7");
+    properties.put(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, "http://example.com");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Repository, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Repository addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Stack(StackName), Stack version(1.2-56), OS(redhat7), Repo id(Repo1), Base URL(http://example.com)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddRepositoryRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    RepositoryEventCreator creator = new RepositoryEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, "Repo1");
+    properties.put(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID, "StackName");
+    properties.put(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID, "1.2-56");
+    properties.put(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID, "redhat7");
+    properties.put(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, "http://example.com");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.Repository, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Repository update), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Stack(StackName), Stack version(1.2-56), OS(redhat7), Repo id(Repo1), Base URL(http://example.com)";
+
+    Assert.assertTrue("Class mismatch", event instanceof UpdateRepositoryRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryVersionEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryVersionEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryVersionEventCreatorTest.java
new file mode 100644
index 0000000..18e2d3f
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RepositoryVersionEventCreatorTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddRepositoryVersionRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.ChangeRepositoryVersionRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteRepositoryVersionRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.RepositoryVersionEventCreator;
+import org.apache.ambari.server.controller.internal.OperatingSystemResourceProvider;
+import org.apache.ambari.server.controller.internal.RepositoryResourceProvider;
+import org.apache.ambari.server.controller.internal.RepositoryVersionResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class RepositoryVersionEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    RepositoryVersionEventCreator creator = new RepositoryVersionEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID, "StackName");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID, "1.9");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "MyStack");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, "1.2-56");
+
+    properties.put("operating_systems", createOperatingSystems());
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.RepositoryVersion, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Repository version addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Stack(StackName), Stack version(1.9), Display name(MyStack), Repo version(1.2-56), Repositories(\n" +
+      "Operating system: redhat6\n" +
+      "    Repository ID(2), Repository name(MyRepo6), Base url(http://example6.com)\n" +
+      "Operating system: redhat7\n" +
+      "    Repository ID(1), Repository name(MyRepo), Base url(http://example.com)\n" +
+      ")";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddRepositoryVersionRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    RepositoryVersionEventCreator creator = new RepositoryVersionEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID, "StackName");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID, "1.9");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "MyStack");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, "1.2-56");
+
+    properties.put("operating_systems", createOperatingSystems());
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.RepositoryVersion, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Repository version change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Stack(StackName), Stack version(1.9), Display name(MyStack), Repo version(1.2-56), Repositories(\n" +
+      "Operating system: redhat6\n" +
+      "    Repository ID(2), Repository name(MyRepo6), Base url(http://example6.com)\n" +
+      "Operating system: redhat7\n" +
+      "    Repository ID(1), Repository name(MyRepo), Base url(http://example.com)\n" +
+      ")";
+
+    Assert.assertTrue("Class mismatch", event instanceof ChangeRepositoryVersionRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    RepositoryVersionEventCreator creator = new RepositoryVersionEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Stack, "HDP");
+    resource.put(Resource.Type.StackVersion, "1.9");
+    resource.put(Resource.Type.RepositoryVersion, "1.2-56");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.RepositoryVersion, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Repository version removal), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Stack(HDP), Stack version(1.9), Repo version ID(1.2-56)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteRepositoryVersionRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  private Set<Map<String, Object>> createOperatingSystems() {
+    Set<Map<String, Object>> operatingSystems = new HashSet<>();
+
+    // ***
+    Map<String, Object> operatingSystem = new HashMap<>();
+    operatingSystem.put(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID, "redhat7");
+
+    Set<Map<String,String>> repositories = new HashSet<>();
+
+    Map<String, String> repository = new HashMap<>();
+    repository.put(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, "1");
+    repository.put(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, "MyRepo");
+    repository.put(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, "http://example.com");
+    repositories.add(repository);
+
+    operatingSystem.put("repositories", repositories);
+    // ***
+    Map<String, Object> operatingSystem2 = new HashMap<>();
+    operatingSystem2.put(OperatingSystemResourceProvider.OPERATING_SYSTEM_OS_TYPE_PROPERTY_ID, "redhat6");
+
+    Set<Map<String,String>> repositories2 = new HashSet<>();
+
+    Map<String, String> repository2 = new HashMap<>();
+    repository2.put(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, "2");
+    repository2.put(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, "MyRepo6");
+    repository2.put(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, "http://example6.com");
+    repositories2.add(repository2);
+
+    operatingSystem2.put("repositories", repositories2);
+    // ***
+
+    operatingSystems.add(operatingSystem);
+    operatingSystems.add(operatingSystem2);
+    return operatingSystems;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RequestEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RequestEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RequestEventCreatorTest.java
new file mode 100644
index 0000000..1074f0e
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/RequestEventCreatorTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddRequestRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.RequestEventCreator;
+import org.apache.ambari.server.controller.internal.RequestOperationLevel;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class RequestEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    RequestEventCreator creator = new RequestEventCreator();
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Request, null, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+    request.getBody().addRequestInfoProperty("command", "MyCommand");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_CLUSTER_ID, "mycluster");
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Request from server), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Command(MyCommand), Cluster name(mycluster)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddRequestRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceConfigDownloadEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceConfigDownloadEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceConfigDownloadEventCreatorTest.java
new file mode 100644
index 0000000..52bfd35
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceConfigDownloadEventCreatorTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.ClientConfigDownloadRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ServiceConfigDownloadEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ServiceConfigDownloadEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void getTest() {
+    ServiceConfigDownloadEventCreator creator = new ServiceConfigDownloadEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Service, "MYSERVICE");
+    resource.put(Resource.Type.Component, "MYCOMPONENT");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.GET, Resource.Type.ClientConfig, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Client config download), RequestType(GET), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Service(MYSERVICE), Component(MYCOMPONENT)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ClientConfigDownloadRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceEventCreatorTest.java
new file mode 100644
index 0000000..01cc1e3
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ServiceEventCreatorTest.java
@@ -0,0 +1,185 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.api.util.TreeNode;
+import org.apache.ambari.server.api.util.TreeNodeImpl;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteServiceRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.StartOperationRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ServiceEventCreator;
+import org.apache.ambari.server.controller.internal.RequestOperationLevel;
+import org.apache.ambari.server.controller.internal.RequestResourceProvider;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
+import org.apache.ambari.server.controller.internal.ServiceResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Test;
+
+public class ServiceEventCreatorTest extends AuditEventCreatorTestBase {
+
+  @Test
+  public void deleteTest() {
+    ServiceEventCreator creator = new ServiceEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Service, "MyService");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.Service, null, resource);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Service deletion), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Service(MyService)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteServiceRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putForAllHostsTest() {
+    clusterTest(Request.Type.PUT);
+  }
+  @Test
+  public void postForAllHostsTest() {
+    clusterTest(Request.Type.POST);
+  }
+
+  private void clusterTest(Request.Type type) {
+    ServiceEventCreator creator = new ServiceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID, "STARTED");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(type, Resource.Type.Service, properties, null);
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_LEVEL_ID, "CLUSTER");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_CLUSTER_ID, "mycluster");
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(STARTED: all services (mycluster)), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void serviceTest() {
+    ServiceEventCreator creator = new ServiceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID, "STARTED");
+    properties.put(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID, "MyService");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.Service, properties, null);
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_LEVEL_ID, "SERVICE");
+    request.getBody().addRequestInfoProperty(RequestOperationLevel.OPERATION_CLUSTER_ID, "mycluster");
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(STARTED: MyService (mycluster)), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void maintenanceModeTest() {
+    ServiceEventCreator creator = new ServiceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ServiceResourceProvider.SERVICE_MAINTENANCE_STATE_PROPERTY_ID, "ON");
+    properties.put(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID, "MyService");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.Service, properties, null);
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Turn ON Maintenance Mode for MyService), RequestId(1), Status(Successfully queued)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void failureTest() {
+    ServiceEventCreator creator = new ServiceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ServiceResourceProvider.SERVICE_MAINTENANCE_STATE_PROPERTY_ID, "ON");
+    properties.put(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID, "MyService");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.Service, properties, null);
+
+    TreeNode<Resource> resultTree = new TreeNodeImpl<>(null, null, null);
+    addRequestId(resultTree, 1L);
+
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, "Failed for testing"), resultTree);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Turn ON Maintenance Mode for MyService), RequestId(1), Status(Failed to queue), Reason(Failed for testing)";
+
+    Assert.assertTrue("Class mismatch", event instanceof StartOperationRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  private void addRequestId(TreeNode<Resource> resultTree, Long requestId) {
+    Resource resource = new ResourceImpl(Resource.Type.Request);
+    resource.addCategory(PropertyHelper.getPropertyCategory(RequestResourceProvider.REQUEST_ID_PROPERTY_ID));
+    resource.setProperty(RequestResourceProvider.REQUEST_ID_PROPERTY_ID, requestId);
+    TreeNode<Resource> requestNode = new TreeNodeImpl<>(resultTree, resource, "request");
+    resultTree.addChild(requestNode);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UnauthorizedEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UnauthorizedEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UnauthorizedEventCreatorTest.java
new file mode 100644
index 0000000..ffe5462
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UnauthorizedEventCreatorTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AccessUnauthorizedAuditEvent;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.UnauthorizedEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class UnauthorizedEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void unauthorizedTest() {
+    unauthorizedTest(ResultStatus.STATUS.UNAUTHORIZED);
+  }
+
+  @Test
+  public void forbiddenTest() {
+    unauthorizedTest(ResultStatus.STATUS.FORBIDDEN);
+  }
+
+  private void unauthorizedTest(ResultStatus.STATUS status) {
+    UnauthorizedEventCreator creator = new UnauthorizedEventCreator();
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Service, null, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(status));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(null), ResourcePath(http://example.com:8080/api/v1/test), Status(Failed), Reason(Access not authorized)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AccessUnauthorizedAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java
new file mode 100644
index 0000000..57074fd
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddUpgradeRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.UpgradeEventCreator;
+import org.apache.ambari.server.controller.internal.UpgradeResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class UpgradeEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    UpgradeEventCreator creator = new UpgradeEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UpgradeResourceProvider.UPGRADE_VERSION, "1.9");
+    properties.put(UpgradeResourceProvider.UPGRADE_TYPE, "ROLLING");
+    properties.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "mycluster");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Upgrade, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Upgrade addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Repository version(1.9), Upgrade type(ROLLING), Cluster name(mycluster)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddUpgradeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+}


[3/3] ambari git commit: AMBARI-15804. Audit logging cleanup and tests. (Daniel Gergely via stoader)

Posted by st...@apache.org.
AMBARI-15804. Audit logging cleanup and tests. (Daniel Gergely via stoader)


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

Branch: refs/heads/trunk
Commit: af13ef73931bf672536199b944d4c3e26ad24ac4
Parents: 7f8da72
Author: Daniel Gergely <dg...@hortonworks.com>
Authored: Tue Apr 12 14:59:45 2016 +0200
Committer: Toader, Sebastian <st...@hortonworks.com>
Committed: Tue Apr 12 14:59:45 2016 +0200

----------------------------------------------------------------------
 .../kerberos/AbstractKerberosAuditEvent.java    |  26 +-
 .../CreatePrincipalKerberosAuditEvent.java      |   3 +-
 .../DestroyPrincipalKerberosAuditEvent.java     |   3 +-
 .../request/ActivateUserRequestAuditEvent.java  |   2 +-
 .../AddComponentToHostRequestAuditEvent.java    |  15 +-
 .../ConfigurationChangeEventCreator.java        |  15 +-
 .../request/eventcreator/HostEventCreator.java  |  32 ++-
 .../eventcreator/PrivilegeEventCreator.java     |   3 +-
 .../RepositoryVersionEventCreator.java          |  10 +-
 .../RequestAuditEventCreatorHelper.java         |  37 +--
 .../request/eventcreator/UserEventCreator.java  |  16 +-
 .../kerberos/CreateKeytabFilesServerAction.java |   6 +-
 .../kerberos/CreatePrincipalsServerAction.java  |   2 +
 .../kerberos/DestroyPrincipalsServerAction.java |   2 +
 .../kerberos/FinalizeKerberosServerAction.java  |   2 +
 .../server/audit/TaskStatusAuditEventTest.java  |  62 +++++
 ...angeSecurityStateKerberosAuditEventTest.java |  61 +++++
 .../CreateKeyTabKerberosAuditEventTest.java     |  59 +++++
 .../CreatePrincipalKerberosAuditEventTest.java  |  55 ++++
 .../DestroyPrincipalKerberosAuditEventTest.java |  55 ++++
 .../creator/AlertGroupEventCreatorTest.java     | 105 ++++++++
 .../creator/AlertTargetEventCreatorTest.java    | 115 +++++++++
 .../creator/AuditEventCreatorTestBase.java      |  84 ++++++
 .../creator/AuditEventCreatorTestHelper.java    | 253 +++++++++++++++++++
 .../creator/BlueprintEventCreatorTest.java      |  78 ++++++
 .../BlueprintExportEventCreatorTest.java        |  50 ++++
 .../creator/ComponentEventCreatorTest.java      | 229 +++++++++++++++++
 .../ConfigurationChangeEventCreatorTest.java    |  93 +++++++
 .../creator/CredentialEventCreatorTest.java     |  61 +++++
 .../creator/DefaultEventCreatorTest.java        |  51 ++++
 .../request/creator/GroupEventCreatorTest.java  |  79 ++++++
 .../request/creator/HostEventCreatorTest.java   | 109 ++++++++
 .../request/creator/MemberEventCreatorTest.java | 103 ++++++++
 .../creator/PrivilegeEventCreatorTest.java      | 112 ++++++++
 .../RecomendationIgnoreEventCreatorTest.java    |  41 +++
 .../creator/RepositoryEventCreatorTest.java     |  88 +++++++
 .../RepositoryVersionEventCreatorTest.java      | 163 ++++++++++++
 .../creator/RequestEventCreatorTest.java        |  53 ++++
 .../ServiceConfigDownloadEventCreatorTest.java  |  58 +++++
 .../creator/ServiceEventCreatorTest.java        | 185 ++++++++++++++
 .../creator/UnauthorizedEventCreatorTest.java   |  60 +++++
 .../creator/UpgradeEventCreatorTest.java        |  59 +++++
 .../creator/UpgradeItemEventCreatorTest.java    |  60 +++++
 .../request/creator/UserEventCreatorTest.java   | 147 +++++++++++
 .../ValidationIgnoreEventCreatorTest.java       |  41 +++
 .../creator/ViewInstanceEventCreatorTest.java   | 110 ++++++++
 .../creator/ViewPrivilegeEventCreatorTest.java  |  90 +++++++
 47 files changed, 3076 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/AbstractKerberosAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/AbstractKerberosAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/AbstractKerberosAuditEvent.java
index 77c162c..3de4e48 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/AbstractKerberosAuditEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/AbstractKerberosAuditEvent.java
@@ -42,6 +42,16 @@ public class AbstractKerberosAuditEvent extends AbstractAuditEvent {
     protected String reasonOfFailure;
 
     /**
+     * ID of the related request
+     */
+    protected Long requestId;
+
+    /**
+     * ID of the related task
+     */
+    protected Long taskId;
+
+    /**
      * Builds and audit log message based on the member variables
      *
      * @param builder builder for the audit event details.
@@ -60,7 +70,11 @@ public class AbstractKerberosAuditEvent extends AbstractAuditEvent {
           .append(reasonOfFailure);
       }
 
-      builder.append(")");
+      builder.append("), RequestId(")
+        .append(requestId)
+        .append("), TaskId(")
+        .append(taskId)
+        .append(")");
     }
 
     public TBuilder withOperation(String operation) {
@@ -72,6 +86,16 @@ public class AbstractKerberosAuditEvent extends AbstractAuditEvent {
       this.reasonOfFailure = reasonOfFailure;
       return (TBuilder) this;
     }
+
+    public TBuilder withRequestId(Long requestId) {
+      this.requestId = requestId;
+      return (TBuilder) this;
+    }
+
+    public TBuilder withTaskId(Long taskId) {
+      this.taskId = taskId;
+      return (TBuilder) this;
+    }
   }
 
   protected AbstractKerberosAuditEvent() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/CreatePrincipalKerberosAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/CreatePrincipalKerberosAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/CreatePrincipalKerberosAuditEvent.java
index e3fbbe4..51c3c6b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/CreatePrincipalKerberosAuditEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/CreatePrincipalKerberosAuditEvent.java
@@ -35,7 +35,8 @@ public class CreatePrincipalKerberosAuditEvent extends AbstractKerberosAuditEven
     protected void buildAuditMessage(StringBuilder builder) {
       super.buildAuditMessage(builder);
       builder.append(", Principal(")
-        .append(principal);
+        .append(principal)
+        .append(")");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/DestroyPrincipalKerberosAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/DestroyPrincipalKerberosAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/DestroyPrincipalKerberosAuditEvent.java
index ba56f21..1e3dd36 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/DestroyPrincipalKerberosAuditEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/kerberos/DestroyPrincipalKerberosAuditEvent.java
@@ -42,7 +42,8 @@ public class DestroyPrincipalKerberosAuditEvent extends AbstractKerberosAuditEve
       super.buildAuditMessage(builder);
 
       builder.append(", Principal(")
-        .append(principal);
+        .append(principal)
+        .append(")");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ActivateUserRequestAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ActivateUserRequestAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ActivateUserRequestAuditEvent.java
index df5726d..c947fb1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ActivateUserRequestAuditEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ActivateUserRequestAuditEvent.java
@@ -41,7 +41,7 @@ public class ActivateUserRequestAuditEvent extends RequestAuditEvent {
     private String username;
 
     public ActivateUserRequestAuditEventBuilder() {
-      super.withOperation("Set user activate");
+      super.withOperation("Set user active/inactive");
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/AddComponentToHostRequestAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/AddComponentToHostRequestAuditEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/AddComponentToHostRequestAuditEvent.java
index 2c9eedd..c248665 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/AddComponentToHostRequestAuditEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/AddComponentToHostRequestAuditEvent.java
@@ -18,12 +18,15 @@
 
 package org.apache.ambari.server.audit.event.request;
 
+import java.util.Set;
+
 import javax.annotation.concurrent.Immutable;
 
 import org.apache.ambari.server.audit.request.RequestAuditEvent;
+import org.apache.commons.lang.StringUtils;
 
 /**
- * Audit event for adding component to a host
+ * Audit event for adding components to a host
  */
 @Immutable
 public class AddComponentToHostRequestAuditEvent extends RequestAuditEvent {
@@ -38,7 +41,7 @@ public class AddComponentToHostRequestAuditEvent extends RequestAuditEvent {
     /**
      * Component name
      */
-    private String component;
+    private Set<String> components;
 
     public AddComponentToHostRequestAuditEventBuilder() {
       super.withOperation("Component addition to host");
@@ -60,8 +63,8 @@ public class AddComponentToHostRequestAuditEvent extends RequestAuditEvent {
 
       builder.append(", Hostname(")
         .append(hostName)
-        .append(", Component(")
-        .append(component)
+        .append("), Component(")
+        .append(components == null ? "" : StringUtils.join(components, ", "))
         .append(")");
     }
 
@@ -70,8 +73,8 @@ public class AddComponentToHostRequestAuditEvent extends RequestAuditEvent {
       return this;
     }
 
-    public AddComponentToHostRequestAuditEventBuilder withComponent(String component) {
-      this.component = component;
+    public AddComponentToHostRequestAuditEventBuilder withComponents(Set<String> component) {
+      this.components = component;
       return this;
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ConfigurationChangeEventCreator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ConfigurationChangeEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ConfigurationChangeEventCreator.java
index 139f6f6..6589658 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ConfigurationChangeEventCreator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/ConfigurationChangeEventCreator.java
@@ -24,6 +24,7 @@ import java.util.Set;
 import org.apache.ambari.server.api.services.Request;
 import org.apache.ambari.server.api.services.Result;
 import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.api.util.TreeNode;
 import org.apache.ambari.server.audit.event.AuditEvent;
 import org.apache.ambari.server.audit.event.request.ClusterNameChangeRequestAuditEvent;
 import org.apache.ambari.server.audit.event.request.ConfigurationChangeRequestAuditEvent;
@@ -32,6 +33,7 @@ import org.apache.ambari.server.controller.internal.ServiceConfigVersionResource
 import org.apache.ambari.server.controller.spi.Resource;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 /**
  * This creator handles operation requests (start, stop, install, etc)
@@ -81,8 +83,8 @@ public class ConfigurationChangeEventCreator implements RequestAuditEventCreator
   public AuditEvent createAuditEvent(Request request, Result result) {
 
     if (!request.getBody().getPropertySets().isEmpty()) {
-      Map<String, Object> map = request.getBody().getPropertySets().iterator().next();
-      if (map.size() == 1 && map.containsKey(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID)) {
+      Map<String, Object> map = Iterables.getFirst(request.getBody().getPropertySets(), null);
+      if (map != null && map.size() == 1 && map.containsKey(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID)) {
         String newName = String.valueOf(map.get(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));
         String oldName = request.getResource().getKeyValueMap().get(Resource.Type.Cluster);
         return ClusterNameChangeRequestAuditEvent.builder()
@@ -134,10 +136,11 @@ public class ConfigurationChangeEventCreator implements RequestAuditEventCreator
    * @return
    */
   private Map<String, Object> getServiceConfigMap(Result result) {
-    if (result.getResultTree().getChild("resources") != null &&
-      !result.getResultTree().getChild("resources").getChildren().isEmpty() &&
-      result.getResultTree().getChild("resources").getChildren().iterator().next().getObject() != null) {
-      return result.getResultTree().getChild("resources").getChildren().iterator().next().getObject().getPropertiesMap().get("");
+    if (result.getResultTree().getChild("resources") != null) {
+      TreeNode<Resource> first = Iterables.getFirst(result.getResultTree().getChild("resources").getChildren(), null);
+      if(first != null && first.getObject() != null) {
+        return first.getObject().getPropertiesMap().get("");
+      }
     }
     return null;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java
index 7c27d19..60fc77c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/HostEventCreator.java
@@ -18,9 +18,13 @@
 
 package org.apache.ambari.server.audit.request.eventcreator;
 
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+import org.apache.ambari.server.api.services.NamedPropertySet;
 import org.apache.ambari.server.api.services.Request;
 import org.apache.ambari.server.api.services.Result;
 import org.apache.ambari.server.api.services.ResultStatus;
@@ -33,6 +37,7 @@ import org.apache.ambari.server.controller.internal.HostResourceProvider;
 import org.apache.ambari.server.controller.spi.Resource;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 /**
  * This creator handles host requests (add, delete, add component)
@@ -109,7 +114,7 @@ public class HostEventCreator implements RequestAuditEventCreator {
           .withUrl(request.getURI())
           .withRemoteIp(request.getRemoteAddress())
           .withHostName(getHostNameFromQuery(request))
-          .withComponent(getHostComponent(request))
+          .withComponents(getHostComponents(request))
           .build();
       default:
         return null;
@@ -121,14 +126,18 @@ public class HostEventCreator implements RequestAuditEventCreator {
    * @param request
    * @return
    */
-  private String getHostComponent(Request request) {
-    if (!request.getBody().getNamedPropertySets().isEmpty()) {
-      Set<Map<String, String>> set = (Set<Map<String, String>>) request.getBody().getNamedPropertySets().iterator().next().getProperties().get("host_components");
+  private Set<String> getHostComponents(Request request) {
+    Set<String> components = new HashSet<>();
+    NamedPropertySet propertySet = Iterables.getFirst(request.getBody().getNamedPropertySets(), null);
+    if (propertySet != null && propertySet.getProperties().get("host_components") instanceof Set) {
+      Set<Map<String, String>> set = (Set<Map<String, String>>) propertySet.getProperties().get("host_components");
       if (set != null && !set.isEmpty()) {
-        return set.iterator().next().get(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
+        for(Map<String, String> element : set) {
+          components.add(element.get(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID));
+        }
       }
     }
-    return null;
+    return components;
   }
 
   /**
@@ -138,11 +147,12 @@ public class HostEventCreator implements RequestAuditEventCreator {
    */
   private String getHostNameFromQuery(Request request) {
     final String key = HostResourceProvider.HOST_NAME_PROPERTY_ID;
-    if (request.getBody().getQueryString().contains(key)) {
-      String q = request.getBody().getQueryString();
-      int startIndex = q.indexOf(key) + key.length() + 1;
-      int endIndex = q.indexOf("&", startIndex) == -1 ? q.length() : q.indexOf("&", startIndex);
-      return q.substring(startIndex, endIndex);
+    if (request.getURI().contains(key)) {
+      Pattern pattern = Pattern.compile(".*" + key + "\\s*=\\s*([^&\\s]+).*");
+      Matcher matcher = pattern.matcher(request.getURI());
+      if(matcher.find()) {
+        return matcher.group(1);
+      }
     }
     return null;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/PrivilegeEventCreator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/PrivilegeEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/PrivilegeEventCreator.java
index cd14dd1..5c476c6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/PrivilegeEventCreator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/PrivilegeEventCreator.java
@@ -37,6 +37,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.User;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 /**
  * This creator handles privilege requests
@@ -100,7 +101,7 @@ public class PrivilegeEventCreator implements RequestAuditEventCreator {
           .withGroups(groups)
           .build();
       case POST:
-        String role = users.isEmpty() ? (groups.isEmpty() ? null : groups.keySet().iterator().next()) : users.keySet().iterator().next();
+        String role = users.isEmpty() ? Iterables.getFirst(groups.keySet(), null) : Iterables.getFirst(users.keySet(), null);
         return PrivilegeChangeRequestAuditEvent.builder()
           .withTimestamp(System.currentTimeMillis())
           .withRequestType(request.getRequestType())

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
index 30fd377..2f09b74 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
@@ -37,6 +37,7 @@ import org.apache.ambari.server.controller.internal.RepositoryVersionResourcePro
 import org.apache.ambari.server.controller.spi.Resource;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 /**
  * This creator handles privilege requests
@@ -138,12 +139,11 @@ public class RepositoryVersionEventCreator implements RequestAuditEventCreator {
 
     Map<String, List<Map<String, String>>> result = new HashMap<String, List<Map<String, String>>>();
 
-    if (!request.getBody().getPropertySets().isEmpty()) {
-      if (request.getBody().getPropertySets().iterator().next().get("operating_systems") instanceof Set) {
-        Set<Object> set = (Set<Object>) request.getBody().getPropertySets().iterator().next().get("operating_systems");
+    Map<String, Object> first = Iterables.getFirst(request.getBody().getPropertySets(), null);
 
-        result = createResultForOperationSystems(set);
-      }
+    if (first != null && first.get("operating_systems") instanceof Set) {
+      Set<Object> set = (Set<Object>) first.get("operating_systems");
+      result = createResultForOperationSystems(set);
     }
     return result;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
index a02428f..f7a6e36 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
@@ -23,8 +23,11 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ambari.server.api.services.NamedPropertySet;
 import org.apache.ambari.server.api.services.Request;
 
+import com.google.common.collect.Iterables;
+
 /**
  * The purpose of this class is to retrieve information from {@link Request} objects.
  * This information can be a single value or a list of values.
@@ -38,8 +41,9 @@ public class RequestAuditEventCreatorHelper {
    * @return
    */
   public static String getNamedProperty(Request request, String propertyName) {
-    if (isValid(request, propertyName)) {
-      return String.valueOf(request.getBody().getNamedPropertySets().iterator().next().getProperties().get(propertyName));
+    NamedPropertySet first = Iterables.getFirst(request.getBody().getNamedPropertySets(), null);
+    if (first != null && first.getProperties().get(propertyName) instanceof String) {
+      return String.valueOf(first.getProperties().get(propertyName));
     }
     return null;
   }
@@ -51,8 +55,9 @@ public class RequestAuditEventCreatorHelper {
    * @return
    */
   public static List<String> getNamedPropertyList(Request request, String propertyName) {
-    if (isValidList(request, propertyName)) {
-      List<String> list = (List<String>) request.getBody().getNamedPropertySets().iterator().next().getProperties().get(propertyName);
+    NamedPropertySet first = Iterables.getFirst(request.getBody().getNamedPropertySets(), null);
+    if (first != null && first.getProperties().get(propertyName) instanceof List) {
+      List<String> list = (List<String>) first.getProperties().get(propertyName);
       if (list != null) {
         return list;
       }
@@ -61,30 +66,6 @@ public class RequestAuditEventCreatorHelper {
   }
 
   /**
-   * Checks if the property is valid: can be found and has correct type
-   * @param request
-   * @param propertyName
-   * @return
-   */
-  private static boolean isValid(Request request, String propertyName) {
-    return !request.getBody().getNamedPropertySets().isEmpty() &&
-      request.getBody().getNamedPropertySets().iterator().next().getProperties() != null &&
-      request.getBody().getNamedPropertySets().iterator().next().getProperties().get(propertyName) instanceof String;
-  }
-
-  /**
-   * Checks if the property is a valid list: can be found and has correct type
-   * @param request
-   * @param propertyName
-   * @return
-   */
-  private static boolean isValidList(Request request, String propertyName) {
-    return !request.getBody().getNamedPropertySets().isEmpty() &&
-      request.getBody().getNamedPropertySets().iterator().next().getProperties() != null &&
-      request.getBody().getNamedPropertySets().iterator().next().getProperties().get(propertyName) instanceof List;
-  }
-
-  /**
    * Returns a property from a request
    * @param request
    * @param propertyName

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/UserEventCreator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/UserEventCreator.java b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/UserEventCreator.java
index 54d02a7..bc469ac 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/UserEventCreator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/UserEventCreator.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.audit.request.eventcreator;
 
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.api.services.Request;
@@ -33,6 +34,7 @@ import org.apache.ambari.server.controller.internal.UserResourceProvider;
 import org.apache.ambari.server.controller.spi.Resource;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 /**
  * This creator handles user requests
@@ -166,7 +168,8 @@ public class UserEventCreator implements RequestAuditEventCreator {
    * @return
    */
   private boolean hasAdmin(Request request) {
-    return !request.getBody().getPropertySets().isEmpty() && request.getBody().getPropertySets().iterator().next().containsKey(UserResourceProvider.USER_ADMIN_PROPERTY_ID);
+    Map<String, Object> first = Iterables.getFirst(request.getBody().getPropertySets(), null);
+    return first != null && first.containsKey(UserResourceProvider.USER_ADMIN_PROPERTY_ID);
   }
 
   /**
@@ -175,7 +178,8 @@ public class UserEventCreator implements RequestAuditEventCreator {
    * @return
    */
   private boolean hasActive(Request request) {
-    return !request.getBody().getPropertySets().isEmpty() && request.getBody().getPropertySets().iterator().next().containsKey(UserResourceProvider.USER_ACTIVE_PROPERTY_ID);
+    Map<String, Object> first = Iterables.getFirst(request.getBody().getPropertySets(), null);
+    return first != null && first.containsKey(UserResourceProvider.USER_ACTIVE_PROPERTY_ID);
   }
 
   /**
@@ -184,7 +188,8 @@ public class UserEventCreator implements RequestAuditEventCreator {
    * @return
    */
   private boolean hasOldPassword(Request request) {
-    return !request.getBody().getPropertySets().isEmpty() && request.getBody().getPropertySets().iterator().next().containsKey(UserResourceProvider.USER_OLD_PASSWORD_PROPERTY_ID);
+    Map<String, Object> first = Iterables.getFirst(request.getBody().getPropertySets(), null);
+    return first != null && first.containsKey(UserResourceProvider.USER_OLD_PASSWORD_PROPERTY_ID);
   }
 
   /**
@@ -193,8 +198,9 @@ public class UserEventCreator implements RequestAuditEventCreator {
    * @return
    */
   private String getUsername(Request request) {
-    if (!request.getBody().getPropertySets().isEmpty()) {
-      return String.valueOf(request.getBody().getPropertySets().iterator().next().get(UserResourceProvider.USER_USERNAME_PROPERTY_ID));
+    Map<String, Object> first = Iterables.getFirst(request.getBody().getPropertySets(), null);
+    if (first != null) {
+      return String.valueOf(first.get(UserResourceProvider.USER_USERNAME_PROPERTY_ID));
     }
     return null;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
index 8c728db..732b06d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
@@ -151,7 +151,11 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
       throws AmbariException {
 
 
-    CreateKeyTabKerberosAuditEvent.CreateKeyTabKerberosAuditEventBuilder auditEventBuilder = CreateKeyTabKerberosAuditEvent.builder().withTimestamp(System.currentTimeMillis());
+    CreateKeyTabKerberosAuditEvent.CreateKeyTabKerberosAuditEventBuilder auditEventBuilder = CreateKeyTabKerberosAuditEvent.builder();
+    auditEventBuilder.withTimestamp(System.currentTimeMillis());
+    auditEventBuilder.withRequestId(getHostRoleCommand().getRequestId());
+    auditEventBuilder.withTaskId(getHostRoleCommand().getTaskId());
+
     CommandReport commandReport = null;
     String message = null;
     try {

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
index 03a181e..61cc5df 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreatePrincipalsServerAction.java
@@ -176,6 +176,8 @@ public class CreatePrincipalsServerAction extends KerberosServerAction {
                                                ActionLog actionLog) {
     CreatePrincipalKerberosAuditEvent.CreatePrincipalKerberosAuditEventBuilder auditEventBuilder = CreatePrincipalKerberosAuditEvent.builder()
       .withTimestamp(System.currentTimeMillis())
+      .withRequestId(getHostRoleCommand().getRequestId())
+      .withTaskId(getHostRoleCommand().getTaskId())
       .withPrincipal(principal);
     CreatePrincipalResult result = null;
     String message = null;

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
index 95dd7a3..2bdcd81 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/DestroyPrincipalsServerAction.java
@@ -93,6 +93,8 @@ public class DestroyPrincipalsServerAction extends KerberosServerAction {
     actionLog.writeStdOut(message);
     DestroyPrincipalKerberosAuditEvent.DestroyPrincipalKerberosAuditEventBuilder auditEventBuilder = DestroyPrincipalKerberosAuditEvent.builder()
       .withTimestamp(System.currentTimeMillis())
+      .withRequestId(getHostRoleCommand().getRequestId())
+      .withTaskId(getHostRoleCommand().getTaskId())
       .withPrincipal(evaluatedPrincipal);
 
     try {

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
index 922cadb..7205d09 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/FinalizeKerberosServerAction.java
@@ -98,6 +98,8 @@ public class FinalizeKerberosServerAction extends KerberosServerAction {
               .withComponent(sch.getServiceComponentName())
               .withHostName(sch.getHostName())
               .withState(sch.getDesiredSecurityState().toString())
+              .withRequestId(getHostRoleCommand().getRequestId())
+              .withTaskId(getHostRoleCommand().getTaskId())
               .build();
             auditLog(auditEvent);
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/TaskStatusAuditEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/TaskStatusAuditEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/TaskStatusAuditEventTest.java
new file mode 100644
index 0000000..8f769c7
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/TaskStatusAuditEventTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.ambari.server.audit;
+
+import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.audit.event.TaskStatusAuditEvent;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class TaskStatusAuditEventTest {
+
+  @Test
+  public void testAuditMessage() throws Exception {
+    // Given
+    String testUserName = "USER1";
+    String testOperation = "START MYCOMPONENT";
+    String testRequestDetails = "Start MyComponent";
+    String testHostName = "ambari.example.com";
+    HostRoleStatus testStatus = HostRoleStatus.IN_PROGRESS;
+    Long testRequestId = 100L;
+    Long testTaskId = 99L;
+
+    TaskStatusAuditEvent event = TaskStatusAuditEvent.builder()
+      .withTimestamp(System.currentTimeMillis())
+      .withUserName(testUserName)
+      .withOperation(testOperation)
+      .withRequestId(testRequestId.toString())
+      .withDetails(testRequestDetails)
+      .withHostName(testHostName)
+      .withStatus(testStatus.name())
+      .withTaskId(testTaskId.toString())
+      .build();
+
+    // When
+    String actualAuditMessage = event.getAuditMessage();
+
+    // Then
+    String expectedAuditMessage = String.format("User(%s), Operation(%s), Details(%s), Status(%s), RequestId(%d), TaskId(%d), Hostname(%s)", testUserName, testOperation, testRequestDetails, testStatus, testRequestId, testTaskId, testHostName);
+
+    assertThat(actualAuditMessage, equalTo(expectedAuditMessage));
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/ChangeSecurityStateKerberosAuditEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/ChangeSecurityStateKerberosAuditEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/ChangeSecurityStateKerberosAuditEventTest.java
new file mode 100644
index 0000000..c835536
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/ChangeSecurityStateKerberosAuditEventTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.ambari.server.audit.kerberos;
+
+import org.apache.ambari.server.audit.event.kerberos.ChangeSecurityStateKerberosAuditEvent;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class ChangeSecurityStateKerberosAuditEventTest {
+
+  @Test
+  public void testAuditMessage() throws Exception {
+    // Given
+    String testOperation = "Change security state";
+    String testHostName = "testhost.example.com";
+    String testService = "MyService";
+    String testComponent = "MyComponent";
+    String testState = "MyState";
+    Long testRequestId = 100L;
+    Long testTaskId = 99L;
+
+    ChangeSecurityStateKerberosAuditEvent event = ChangeSecurityStateKerberosAuditEvent.builder()
+      .withTimestamp(System.currentTimeMillis())
+      .withOperation(testOperation)
+      .withRequestId(testRequestId)
+      .withTaskId(testTaskId)
+      .withHostName(testHostName)
+      .withComponent(testComponent)
+      .withService(testService)
+      .withState(testState)
+      .build();
+
+    // When
+    String actualAuditMessage = event.getAuditMessage();
+
+    // Then
+    String expectedAuditMessage = String.format("Operation(%s), Status(Success), RequestId(%s), TaskId(%s), Hostname(%s), Service(%s), Component(%s), State(%s)", testOperation, testRequestId, testTaskId, testHostName, testService, testComponent, testState);
+
+    assertThat(actualAuditMessage, equalTo(expectedAuditMessage));
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreateKeyTabKerberosAuditEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreateKeyTabKerberosAuditEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreateKeyTabKerberosAuditEventTest.java
new file mode 100644
index 0000000..dbc2583
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreateKeyTabKerberosAuditEventTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.ambari.server.audit.kerberos;
+
+import org.apache.ambari.server.audit.event.kerberos.CreateKeyTabKerberosAuditEvent;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class CreateKeyTabKerberosAuditEventTest {
+
+  @Test
+  public void testAuditMessage() throws Exception {
+    // Given
+    String testOperation = "Create keytab file";
+    String testPrincipal = "testPrincipal";
+    String testHostName = "testhost.example.com";
+    String testKeyTabFile = "/tmp/mykeytabfile.ktf";
+    Long testRequestId = 100L;
+    Long testTaskId = 99L;
+
+    CreateKeyTabKerberosAuditEvent event = CreateKeyTabKerberosAuditEvent.builder()
+      .withTimestamp(System.currentTimeMillis())
+      .withOperation(testOperation)
+      .withRequestId(testRequestId)
+      .withPrincipal(testPrincipal)
+      .withTaskId(testTaskId)
+      .withHostName(testHostName)
+      .withKeyTabFilePath(testKeyTabFile)
+      .build();
+
+    // When
+    String actualAuditMessage = event.getAuditMessage();
+
+    // Then
+    String expectedAuditMessage = String.format("Operation(%s), Status(Success), RequestId(%s), TaskId(%s), Principal(%s), Hostname(%s), Keytab file(%s)", testOperation, testRequestId, testTaskId, testPrincipal, testHostName, testKeyTabFile);
+
+    assertThat(actualAuditMessage, equalTo(expectedAuditMessage));
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreatePrincipalKerberosAuditEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreatePrincipalKerberosAuditEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreatePrincipalKerberosAuditEventTest.java
new file mode 100644
index 0000000..c3eb96f
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/CreatePrincipalKerberosAuditEventTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.ambari.server.audit.kerberos;
+
+import org.apache.ambari.server.audit.event.kerberos.CreatePrincipalKerberosAuditEvent;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class CreatePrincipalKerberosAuditEventTest {
+
+  @Test
+  public void testAuditMessage() throws Exception {
+    // Given
+    String testOperation = "Create principal";
+    String testPrincipal = "testPrincipal";
+    Long testRequestId = 100L;
+    Long testTaskId = 99L;
+
+    CreatePrincipalKerberosAuditEvent event = CreatePrincipalKerberosAuditEvent.builder()
+      .withTimestamp(System.currentTimeMillis())
+      .withOperation(testOperation)
+      .withRequestId(testRequestId)
+      .withPrincipal(testPrincipal)
+      .withTaskId(testTaskId)
+      .build();
+
+    // When
+    String actualAuditMessage = event.getAuditMessage();
+
+    // Then
+    String expectedAuditMessage = String.format("Operation(%s), Status(Success), RequestId(%d), TaskId(%d), Principal(%s)", testOperation, testRequestId, testTaskId, testPrincipal);
+
+    assertThat(actualAuditMessage, equalTo(expectedAuditMessage));
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/DestroyPrincipalKerberosAuditEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/DestroyPrincipalKerberosAuditEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/DestroyPrincipalKerberosAuditEventTest.java
new file mode 100644
index 0000000..901f362
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/kerberos/DestroyPrincipalKerberosAuditEventTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.ambari.server.audit.kerberos;
+
+import org.apache.ambari.server.audit.event.kerberos.DestroyPrincipalKerberosAuditEvent;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class DestroyPrincipalKerberosAuditEventTest {
+
+  @Test
+  public void testAuditMessage() throws Exception {
+    // Given
+    String testOperation = "Destroy principal";
+    String testPrincipal = "testPrincipal";
+    Long testRequestId = 100L;
+    Long testTaskId = 99L;
+
+    DestroyPrincipalKerberosAuditEvent event = DestroyPrincipalKerberosAuditEvent.builder()
+      .withTimestamp(System.currentTimeMillis())
+      .withOperation(testOperation)
+      .withRequestId(testRequestId)
+      .withPrincipal(testPrincipal)
+      .withTaskId(testTaskId)
+      .build();
+
+    // When
+    String actualAuditMessage = event.getAuditMessage();
+
+    // Then
+    String expectedAuditMessage = String.format("Operation(%s), Status(Success), RequestId(%d), TaskId(%d), Principal(%s)", testOperation, testRequestId, testTaskId, testPrincipal);
+
+    assertThat(actualAuditMessage, equalTo(expectedAuditMessage));
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertGroupEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertGroupEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertGroupEventCreatorTest.java
new file mode 100644
index 0000000..1e04677
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertGroupEventCreatorTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddAlertGroupRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.ChangeAlertGroupRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteAlertGroupRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.AlertGroupEventCreator;
+import org.apache.ambari.server.controller.internal.AlertGroupResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class AlertGroupEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    AlertGroupEventCreator creator = new AlertGroupEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(AlertGroupResourceProvider.ALERT_GROUP_NAME, "GroupName");
+    properties.put(AlertGroupResourceProvider.ALERT_GROUP_DEFINITIONS, Arrays.asList("D","E","F","S"));
+    properties.put(AlertGroupResourceProvider.ALERT_GROUP_TARGETS, Arrays.asList("T","G","T","S"));
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.AlertGroup, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Alert group addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Alert group name(GroupName), Definition IDs(D, E, F, S), Notification IDs(T, G, T, S)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddAlertGroupRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    AlertGroupEventCreator creator = new AlertGroupEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(AlertGroupResourceProvider.ALERT_GROUP_NAME, "GroupName");
+    properties.put(AlertGroupResourceProvider.ALERT_GROUP_DEFINITIONS, Arrays.asList("D","E","F","S"));
+    properties.put(AlertGroupResourceProvider.ALERT_GROUP_TARGETS, Arrays.asList("T","G","T","S"));
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.AlertGroup, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Alert group change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Alert group name(GroupName), Definition IDs(D, E, F, S), Notification IDs(T, G, T, S)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ChangeAlertGroupRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    AlertGroupEventCreator creator = new AlertGroupEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.AlertGroup, "999");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.AlertGroup, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Alert group removal), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Alert group ID(999)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteAlertGroupRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertTargetEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertTargetEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertTargetEventCreatorTest.java
new file mode 100644
index 0000000..019044c
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AlertTargetEventCreatorTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddAlertTargetRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.ChangeAlertTargetRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteAlertTargetRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.AlertTargetEventCreator;
+import org.apache.ambari.server.controller.internal.AlertTargetResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.notifications.dispatchers.EmailDispatcher;
+import org.apache.ambari.server.state.services.AlertNoticeDispatchService;
+import org.junit.Test;
+
+public class AlertTargetEventCreatorTest extends AuditEventCreatorTestBase {
+
+  @Test
+  public void postTest() {
+    AlertTargetEventCreator creator = new AlertTargetEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_DESCRIPTION, "Target description");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_NAME, "Target name");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_NOTIFICATION_TYPE, "NotifType");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES + "/" + EmailDispatcher.JAVAMAIL_FROM_PROPERTY, "email");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_STATES, Arrays.asList("S","T","A","T","E","S"));
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_GROUPS, Arrays.asList("G","R","P","S"));
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES + "/" + AlertNoticeDispatchService.AMBARI_DISPATCH_RECIPIENTS, Arrays.asList("a@a.com","b@b.com","c@c.com"));
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.AlertTarget, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Notification addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Notification name(Target name), Description(Target description), Notification type(NotifType), Group IDs(G, R, P, S), Email from(email), Email to(a@a.com, b@b.com, c@c.com), Alert states(S, T, A, T, E, S)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddAlertTargetRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    AlertTargetEventCreator creator = new AlertTargetEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_DESCRIPTION, "Target description");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_NAME, "Target name");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_NOTIFICATION_TYPE, "NotifType");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES + "/" + EmailDispatcher.JAVAMAIL_FROM_PROPERTY, "email");
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_STATES, Arrays.asList("S","T","A","T","E","S"));
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_GROUPS, Arrays.asList("G","R","P","S"));
+    properties.put(AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES + "/" + AlertNoticeDispatchService.AMBARI_DISPATCH_RECIPIENTS, Arrays.asList("a@a.com","b@b.com","c@c.com"));
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.AlertTarget, properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Notification change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Notification name(Target name), Description(Target description), Notification type(NotifType), Group IDs(G, R, P, S), Email from(email), Email to(a@a.com, b@b.com, c@c.com), Alert states(S, T, A, T, E, S)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ChangeAlertTargetRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    AlertTargetEventCreator creator = new AlertTargetEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.AlertTarget, "888");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.AlertTarget, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Notification removal), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Notification ID(888)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteAlertTargetRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestBase.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestBase.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestBase.java
new file mode 100644
index 0000000..2fdbe40
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestBase.java
@@ -0,0 +1,84 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.junit.BeforeClass;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.User;
+
+public class AuditEventCreatorTestBase {
+
+  protected final static String userName = "testuser";
+
+  @BeforeClass
+  public static void beforeClass() {
+    SecurityContextHolder.setContext(new SecurityContext() {
+      @Override
+      public Authentication getAuthentication() {
+        return new Authentication() {
+          @Override
+          public Collection<? extends GrantedAuthority> getAuthorities() {
+            return null;
+          }
+
+          @Override
+          public Object getCredentials() {
+            return null;
+          }
+
+          @Override
+          public Object getDetails() {
+            return null;
+          }
+
+          @Override
+          public Object getPrincipal() {
+            return new User(userName, "password", Collections.EMPTY_LIST);
+          }
+
+          @Override
+          public boolean isAuthenticated() {
+            return true;
+          }
+
+          @Override
+          public void setAuthenticated(boolean b) throws IllegalArgumentException {
+
+          }
+
+          @Override
+          public String getName() {
+            return ((User) getPrincipal()).getUsername();
+          }
+        };
+      }
+
+      @Override
+      public void setAuthentication(Authentication authentication) {
+
+      }
+    });
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestHelper.java
new file mode 100644
index 0000000..86c1ebb
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/AuditEventCreatorTestHelper.java
@@ -0,0 +1,253 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.api.query.Query;
+import org.apache.ambari.server.api.query.render.Renderer;
+import org.apache.ambari.server.api.resources.ResourceDefinition;
+import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.resources.SubResourceDefinition;
+import org.apache.ambari.server.api.services.NamedPropertySet;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.RequestBody;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.api.util.TreeNode;
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.request.RequestAuditLogger;
+import org.apache.ambari.server.audit.request.RequestAuditLoggerImpl;
+import org.apache.ambari.server.audit.request.eventcreator.RequestAuditEventCreator;
+import org.apache.ambari.server.controller.spi.PageRequest;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SortRequest;
+import org.apache.ambari.server.controller.spi.TemporalInfo;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+
+public class AuditEventCreatorTestHelper {
+
+  public static AuditEvent getEvent(RequestAuditEventCreator eventCreator, Request request, Result result) {
+    Set<RequestAuditEventCreator> creatorSet = new HashSet<>();
+    creatorSet.add(eventCreator);
+
+    AuditLogger auditLogger = EasyMock.createNiceMock(AuditLogger.class);
+    EasyMock.expect(auditLogger.isEnabled()).andReturn(true).anyTimes();
+    Capture<AuditEvent> capture = EasyMock.newCapture();
+    auditLogger.log(EasyMock.capture(capture));
+    EasyMock.expectLastCall();
+    EasyMock.replay(auditLogger);
+
+    RequestAuditLogger requestAuditLogger = new RequestAuditLoggerImpl(auditLogger, creatorSet);
+
+    requestAuditLogger.log(request, result);
+
+    return capture.getValue();
+  }
+
+  public static Request createRequest(final Request.Type requestType, final Resource.Type resourceType, final Map<String,Object> properties, final Map<Resource.Type, String> resource) {
+    return createRequest(requestType, resourceType, properties, resource, "");
+  }
+
+  public static Request createRequest(final Request.Type requestType, final Resource.Type resourceType, final Map<String,Object> properties, final Map<Resource.Type, String> resource, final String queryString) {
+    return new Request() {
+
+      RequestBody body = new RequestBody();
+
+      @Override
+      public Result process() {
+        return null;
+      }
+
+      @Override
+      public ResourceInstance getResource() {
+        return new ResourceInstance() {
+          @Override
+          public void setKeyValueMap(Map<Resource.Type, String> keyValueMap) {
+
+          }
+
+          @Override
+          public Map<Resource.Type, String> getKeyValueMap() {
+            return resource;
+          }
+
+          @Override
+          public Query getQuery() {
+            return null;
+          }
+
+          @Override
+          public ResourceDefinition getResourceDefinition() {
+            return new ResourceDefinition() {
+              @Override
+              public String getPluralName() {
+                return null;
+              }
+
+              @Override
+              public String getSingularName() {
+                return null;
+              }
+
+              @Override
+              public Resource.Type getType() {
+                return resourceType;
+              }
+
+              @Override
+              public Set<SubResourceDefinition> getSubResourceDefinitions() {
+                return null;
+              }
+
+              @Override
+              public List<PostProcessor> getPostProcessors() {
+                return null;
+              }
+
+              @Override
+              public Renderer getRenderer(String name) throws IllegalArgumentException {
+                return null;
+              }
+
+              @Override
+              public Collection<String> getCreateDirectives() {
+                return null;
+              }
+
+              @Override
+              public boolean isCreatable() {
+                return false;
+              }
+
+              @Override
+              public Collection<String> getUpdateDirectives() {
+                return null;
+              }
+            };
+          }
+
+          @Override
+          public Map<String, ResourceInstance> getSubResources() {
+            return null;
+          }
+
+          @Override
+          public boolean isCollectionResource() {
+            return false;
+          }
+        };
+      }
+
+      @Override
+      public String getURI() {
+        return "http://example.com:8080/api/v1/test" + queryString;
+      }
+
+      @Override
+      public Type getRequestType() {
+        return requestType;
+      }
+
+      @Override
+      public int getAPIVersion() {
+        return 0;
+      }
+
+      @Override
+      public Predicate getQueryPredicate() {
+        return null;
+      }
+
+      @Override
+      public Map<String, TemporalInfo> getFields() {
+        return null;
+      }
+
+      @Override
+      public RequestBody getBody() {
+        if(properties != null) {
+          NamedPropertySet nps = new NamedPropertySet("", properties);
+          body.addPropertySet(nps);
+        }
+        return body;
+      }
+
+      @Override
+      public Map<String, List<String>> getHttpHeaders() {
+        return null;
+      }
+
+      @Override
+      public PageRequest getPageRequest() {
+        return null;
+      }
+
+      @Override
+      public SortRequest getSortRequest() {
+        return null;
+      }
+
+      @Override
+      public Renderer getRenderer() {
+        return null;
+      }
+
+      @Override
+      public String getRemoteAddress() {
+        return "1.2.3.4";
+      }
+    };
+  }
+
+  public static Result createResult(final ResultStatus status) {
+    return createResult(status, null);
+  }
+
+  public static Result createResult(final ResultStatus status, final TreeNode<Resource> resultTree) {
+    return new Result() {
+      @Override
+      public TreeNode<Resource> getResultTree() {
+        return resultTree;
+      }
+
+      @Override
+      public boolean isSynchronous() {
+        return false;
+      }
+
+      @Override
+      public ResultStatus getStatus() {
+        return status;
+      }
+
+      @Override
+      public void setResultStatus(ResultStatus status) {
+
+      }
+    };
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintEventCreatorTest.java
new file mode 100644
index 0000000..705b468
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintEventCreatorTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddBlueprintRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteBlueprintRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.BlueprintEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class BlueprintEventCreatorTest extends AuditEventCreatorTestBase {
+
+  @Test
+  public void postTest() {
+    BlueprintEventCreator creator = new BlueprintEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Blueprint, "myBluePrint");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Blueprint, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Upload blueprint), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Blueprint name(myBluePrint)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddBlueprintRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    BlueprintEventCreator creator = new BlueprintEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.Blueprint, "myBluePrint");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.Blueprint, null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Delete blueprint), RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Blueprint name(myBluePrint)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteBlueprintRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintExportEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintExportEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintExportEventCreatorTest.java
new file mode 100644
index 0000000..f826b5a
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/BlueprintExportEventCreatorTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.BlueprintExportRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.BlueprintExportEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class BlueprintExportEventCreatorTest extends AuditEventCreatorTestBase {
+
+  @Test
+  public void getTest() {
+    BlueprintExportEventCreator creator = new BlueprintExportEventCreator();
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.GET, Resource.Type.Cluster, null, null, "?format=blueprint");
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Blueprint export), RequestType(GET), url(http://example.com:8080/api/v1/test?format=blueprint), ResultStatus(200 OK)";
+
+    Assert.assertTrue("Class mismatch", event instanceof BlueprintExportRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+}