ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [06/11] ambari git commit: AMBARI-18374. rolling restart datanode cluster name show null (Wang Yaoxin via magyari_sandor)
Date Mon, 19 Sep 2016 15:31:57 GMT
AMBARI-18374. rolling restart datanode cluster name show null (Wang Yaoxin via magyari_sandor)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: fd02688f27afa6e4607f3694dee5e5643e8e2b72
Parents: 1fdda49
Author: Wang Yaoxin <18896724276@139.com>
Authored: Wed Sep 14 15:36:56 2016 +0530
Committer: Sandor Magyari <smagyari@hortonworks.com>
Committed: Mon Sep 19 11:54:34 2016 +0200

----------------------------------------------------------------------
 .../eventcreator/RequestEventCreator.java       | 30 ++++++++++++++++++--
 .../creator/RequestEventCreatorTest.java        | 27 ++++++++++++++++++
 2 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fd02688f/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestEventCreator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestEventCreator.java
b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestEventCreator.java
index 075e328..f0ea4ec 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestEventCreator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestEventCreator.java
@@ -27,7 +27,8 @@ import org.apache.ambari.server.audit.event.AuditEvent;
 import org.apache.ambari.server.audit.event.request.AddRequestRequestAuditEvent;
 import org.apache.ambari.server.controller.internal.RequestOperationLevel;
 import org.apache.ambari.server.controller.spi.Resource;
-
+import java.util.Map;
+import org.apache.ambari.server.controller.internal.RequestResourceProvider;
 import com.google.common.collect.ImmutableSet;
 
 /**
@@ -87,10 +88,33 @@ public class RequestEventCreator implements RequestAuditEventCreator {
           .withUrl(request.getURI())
           .withRemoteIp(request.getRemoteAddress())
           .withCommand(request.getBody().getRequestInfoProperties().get("command"))
-          .withClusterName(request.getBody().getRequestInfoProperties().get(RequestOperationLevel.OPERATION_CLUSTER_ID))
-          .build();
+          .withClusterName(getClusterName(request, RequestOperationLevel.OPERATION_CLUSTER_ID))
+	  .build();
       default:
         return null;
     }
   }
+  /**
+   *Returns clusterName from the request based on the propertyName parameter
+   *@param request
+   *@param propertyName
+   *@return
+   */
+  private String getClusterName(Request request ,String propertyName) {
+    Map<String, String> requestInfoProps = request.getBody().getRequestInfoProperties();
+    return requestInfoProps.containsKey(propertyName)?requestInfoProps.get(propertyName):getProperty(request,
RequestResourceProvider.REQUEST_CLUSTER_NAME_PROPERTY_ID);
+  }
+
+  /**
+   *Returns property from the request based on the propertyName parameter
+   *@param request
+   *@param propertyName
+   *@return
+   */
+  private String getProperty(Request request, String propertyName) {
+    if (!request.getBody().getPropertySets().isEmpty()) {
+      return String.valueOf(request.getBody().getPropertySets().iterator().next().get(propertyName));
+    }
+    return null;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd02688f/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
index 1074f0e..ddb42a7 100644
--- 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
@@ -19,7 +19,11 @@
 package org.apache.ambari.server.audit.request.creator;
 
 import junit.framework.Assert;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 
+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;
@@ -27,6 +31,7 @@ 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.internal.RequestResourceProvider;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.junit.Test;
 
@@ -50,4 +55,26 @@ public class RequestEventCreatorTest extends AuditEventCreatorTestBase{
     Assert.assertEquals(expected, actual);
     Assert.assertTrue(actual.contains(userName));
   }
+  @Test
+  public void postScheduleTest() {
+    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");
+
+    Map<String, Object> mapProperties = new HashMap<String, Object>();
+    mapProperties.put(RequestResourceProvider.REQUEST_CLUSTER_NAME_PROPERTY_ID, "mycluster");
+    NamedPropertySet namedPropSet = new NamedPropertySet("", mapProperties);
+    request.getBody().addPropertySet(namedPropSet);
+
+    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));
+  }
+
 }


Mime
View raw message