sentry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ann...@apache.org
Subject sentry git commit: SENTRY-1331: Add a kerberos end to end test case to access isActive and isHa metrics. (Rahul Sharma, reviewed by Anne Yu)
Date Tue, 26 Jul 2016 03:39:48 GMT
Repository: sentry
Updated Branches:
  refs/heads/sentry-ha-redesign 5cdd7cdfc -> 2ce6bb275


SENTRY-1331: Add a kerberos end to end test case to access isActive and isHa metrics. (Rahul
Sharma, reviewed by Anne Yu)


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

Branch: refs/heads/sentry-ha-redesign
Commit: 2ce6bb275f41662ba5b7b98563d3e05fa442fd90
Parents: 5cdd7cd
Author: Anne Yu <anneyu@cloudera.com>
Authored: Mon Jul 25 21:16:23 2016 -0700
Committer: Anne Yu <anneyu@cloudera.com>
Committed: Mon Jul 25 21:16:23 2016 -0700

----------------------------------------------------------------------
 .../thrift/TestSentryServiceMetrics.java        | 39 +++++++--
 .../service/thrift/SentryWebMetricParser.java   | 86 ++++++++++++++++++++
 2 files changed, 120 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/2ce6bb27/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java
b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java
index 3fff450..bc375e3 100644
--- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceMetrics.java
@@ -18,18 +18,30 @@
 
 package org.apache.sentry.provider.db.service.thrift;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
+import org.apache.hadoop.security.authentication.client.KerberosAuthenticator;
 import org.apache.sentry.service.thrift.SentryServiceIntegrationBase;
-import org.junit.*;
+import org.apache.sentry.service.thrift.SentryWebMetricParser;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.security.PrivilegedExceptionAction;
 
 public class TestSentryServiceMetrics extends SentryServiceIntegrationBase {
 
   @BeforeClass
   public static void setup() throws Exception {
-    kerberos = false;
-    beforeSetup();
+    kerberos = true;
+    webServerEnabled = true;
+    webSecurity = true;
     setupConf();
     startSentryService();
-    afterSetup();
   }
 
   //Overriding this method as the tests do not require a client handle
@@ -48,11 +60,28 @@ public class TestSentryServiceMetrics extends SentryServiceIntegrationBase
{
     Assert.assertEquals(Boolean.TRUE,server.getIsActiveGauge().getValue());
   }
 
+  @Test
+  public void testMetricsWeb() throws Exception {
+    clientUgi.doAs(new PrivilegedExceptionAction<Void>() {
+      @Override
+      public Void run() throws Exception {
+        final URL url = new URL("http://"+ SERVER_HOST + ":" + webServerPort + "/metrics");
+        HttpURLConnection conn = new AuthenticatedURL(new KerberosAuthenticator()).
+                openConnection(url, new AuthenticatedURL.Token());
+        //make sure we are able to access the metrics page
+        Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
+        String response = IOUtils.toString(conn.getInputStream());
+        SentryWebMetricParser mp = new SentryWebMetricParser(response);
+        Assert.assertEquals(Boolean.FALSE,mp.isHA());
+        Assert.assertEquals(Boolean.TRUE,mp.isActive());
+        return null;
+      }} );
+  }
+
   //Overriding this method as the client handle does not exist.
   @Override
   @After
   public void after() {
 
   }
-
 }

http://git-wip-us.apache.org/repos/asf/sentry/blob/2ce6bb27/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryWebMetricParser.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryWebMetricParser.java
b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryWebMetricParser.java
new file mode 100644
index 0000000..8446d95
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/service/thrift/SentryWebMetricParser.java
@@ -0,0 +1,86 @@
+/*
+ * 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.sentry.service.thrift;
+
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+
+
+/**
+ * The SentryWebMetricParser is used to parse the metrics displayed on the sentry web ui.
+ */
+public class SentryWebMetricParser {
+  private JsonNode root;
+  private final String sentryService = SentryService.class.getName();
+  private ObjectMapper mapper;
+
+  public SentryWebMetricParser(String response) throws IOException {
+    this.mapper = new ObjectMapper();
+    this.root = mapper.readTree(response);
+  }
+
+  public void refreshRoot(String response) throws IOException {
+    root = mapper.readTree(response);
+  }
+
+  public JsonNode getRoot() {
+    return root;
+  }
+
+  public JsonNode getGauges(JsonNode root) {
+    JsonNode gauges = root.findPath("gauges");
+    return gauges;
+  }
+
+  public JsonNode getCounters(JsonNode root) {
+    JsonNode counters = root.findPath("counters");
+    return counters;
+  }
+
+  public JsonNode getHistograms(JsonNode root) {
+    JsonNode histograms = root.findPath("histograms");
+    return histograms;
+  }
+
+  public JsonNode getMeters(JsonNode root) {
+    JsonNode meters = root.findPath("meters");
+    return meters;
+  }
+
+  public JsonNode getTimers(JsonNode root) {
+    JsonNode timers = root.findPath("timers");
+    return timers;
+  }
+
+  public JsonNode getValue(JsonNode node) {
+    return node.findPath("value");
+  }
+
+  public boolean isHA() {
+    JsonNode gauges = getGauges(root);
+    JsonNode obj = getValue(gauges.findPath(sentryService + ".is_ha"));
+    return obj.getValueAsBoolean();
+  }
+
+  public boolean isActive() {
+    JsonNode gauges = getGauges(root);
+    JsonNode obj = getValue(gauges.findPath(sentryService + ".is_active"));
+    return obj.getBooleanValue();
+  }
+}
\ No newline at end of file


Mime
View raw message