ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stoa...@apache.org
Subject [15/51] [abbrv] ambari git commit: Component addition to host audit event
Date Thu, 24 Mar 2016 12:08:47 GMT
Component addition to host audit event


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

Branch: refs/heads/audit_logging
Commit: b07aa180dd8e16be2a5ebe6bfea88b63a4713a8a
Parents: d9ef0ee
Author: Daniel Gergely <dgergely@hortonworks.com>
Authored: Tue Feb 23 14:07:01 2016 +0100
Committer: Toader, Sebastian <stoader@hortonworks.com>
Committed: Thu Mar 24 13:06:46 2016 +0100

----------------------------------------------------------------------
 .../AddComponentToHostRequestAuditEvent.java    | 83 ++++++++++++++++++++
 .../request/eventcreator/HostEventCreator.java  | 38 ++++++++-
 2 files changed, 119 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b07aa180/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java
b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java
new file mode 100644
index 0000000..4270505
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/event/AddComponentToHostRequestAuditEvent.java
@@ -0,0 +1,83 @@
+/*
+ * 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.event;
+
+import org.apache.ambari.server.audit.request.RequestAuditEvent;
+
+public class AddComponentToHostRequestAuditEvent extends RequestAuditEvent {
+
+  public static class AddComponentToHostRequestAuditEventBuilder extends RequestAuditEventBuilder<AddComponentToHostRequestAuditEvent,
AddComponentToHostRequestAuditEventBuilder> {
+
+    private String hostName;
+    private String component;
+
+    public AddComponentToHostRequestAuditEventBuilder() {
+      super.withOperation("Component addition to host");
+    }
+
+    @Override
+    protected AddComponentToHostRequestAuditEvent newAuditEvent() {
+      return new AddComponentToHostRequestAuditEvent(this);
+    }
+
+    /**
+     * Appends to the event the details of the incoming request.
+     * @param builder builder for the audit event details.
+     */
+    @Override
+    protected void buildAuditMessage(StringBuilder builder) {
+      super.buildAuditMessage(builder);
+
+      builder.append(", Hostname(")
+        .append(hostName)
+        .append(", Component(")
+        .append(component)
+        .append(")");
+    }
+
+    public AddComponentToHostRequestAuditEventBuilder withHostName(String hostName) {
+      this.hostName = hostName;
+      return this;
+    }
+
+    public AddComponentToHostRequestAuditEventBuilder withComponent(String component) {
+      this.component = component;
+      return this;
+    }
+  }
+
+  protected AddComponentToHostRequestAuditEvent() {
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  protected AddComponentToHostRequestAuditEvent(AddComponentToHostRequestAuditEventBuilder
builder) {
+    super(builder);
+  }
+
+  /**
+   * Returns an builder for {@link AddComponentToHostRequestAuditEvent}
+   * @return a builder instance
+   */
+  public static AddComponentToHostRequestAuditEventBuilder builder() {
+    return new AddComponentToHostRequestAuditEventBuilder();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b07aa180/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 fef39fb..837f6b6 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
@@ -29,6 +29,7 @@ import org.apache.ambari.server.audit.AuditEvent;
 import org.apache.ambari.server.audit.StartOperationFailedAuditEvent;
 import org.apache.ambari.server.audit.StartOperationSucceededAuditEvent;
 import org.apache.ambari.server.audit.request.RequestAuditEventCreator;
+import org.apache.ambari.server.audit.request.event.AddComponentToHostRequestAuditEvent;
 import org.apache.ambari.server.audit.request.event.AddHostRequestAuditEvent;
 import org.apache.ambari.server.audit.request.event.DeleteAlertGroupRequestAuditEvent;
 import org.apache.ambari.server.audit.request.event.DeleteHostRequestAuditEvent;
@@ -40,9 +41,9 @@ import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.User;
 
 /**
- * This creator handles host requests (add, delete)
+ * This creator handles host requests (add, delete, add component)
  * For resource type {@link Resource.Type#HostComponent}
- * and request types {@link Request.Type#POST} and {@link Request.Type#DELETE}
+ * and request types {@link Request.Type#POST}, {@link Request.Type#DELETE} and {@link Request.Type#QUERY_POST}
  */
 public class HostEventCreator implements RequestAuditEventCreator {
 
@@ -54,6 +55,7 @@ public class HostEventCreator implements RequestAuditEventCreator {
   {
     requestTypes.add(Request.Type.POST);
     requestTypes.add(Request.Type.DELETE);
+    requestTypes.add(Request.Type.QUERY_POST);
   }
 
   private Set<Resource.Type> resourceTypes = new HashSet<Resource.Type>();
@@ -105,6 +107,17 @@ public class HostEventCreator implements RequestAuditEventCreator {
           .withUserName(username)
           .withHostName(getHostName(request))
           .build();
+      case QUERY_POST:
+        return AddComponentToHostRequestAuditEvent.builder()
+          .withTimestamp(DateTime.now())
+          .withRequestType(request.getRequestType())
+          .withResultStatus(result.getStatus())
+          .withUrl(request.getURI())
+          .withRemoteIp(request.getRemoteAddress())
+          .withUserName(username)
+          .withHostName(getHostNameFromQuery(request))
+          .withComponent(getHostComponent(request))
+          .build();
       default:
         return null;
     }
@@ -116,4 +129,25 @@ public class HostEventCreator implements RequestAuditEventCreator {
     }
     return null;
   }
+
+  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");
+      if(set != null && !set.isEmpty()) {
+        return set.iterator().next().get(PropertyHelper.getPropertyId("HostRoles","component_name"));
+      }
+    }
+    return null;
+  }
+
+  private String getHostNameFromQuery(Request request) {
+    final String key = PropertyHelper.getPropertyId("Hosts","host_name");
+    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);
+    }
+    return null;
+  }
 }


Mime
View raw message