knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [57/64] knox git commit: KNOX-998 - Refactoring package after merge
Date Fri, 01 Sep 2017 13:17:55 GMT
KNOX-998 - Refactoring package after merge


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

Branch: refs/heads/KNOX-998-Package_Restructuring
Commit: a25f8a77bc80b7314b2e7a7983a125592db759fe
Parents: a4ba9bb
Author: Sandeep More <more@apache.org>
Authored: Tue Aug 29 10:37:00 2017 -0400
Committer: Sandeep More <more@apache.org>
Committed: Tue Aug 29 10:37:00 2017 -0400

----------------------------------------------------------------------
 .../services/metrics/impl/instr/InstrUtils.java | 54 ++++++++++++++++++++
 1 file changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/a25f8a77/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
new file mode 100644
index 0000000..9b6249f
--- /dev/null
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/instr/InstrUtils.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.knox.gateway.services.metrics.impl.instr;
+
+import com.google.common.base.Strings;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class InstrUtils {
+
+    //This regular expression pattern is used to parse the *first* two elements
+    //of a path. For example, if the path is “/webhdfs/v1/d1/d2/d2/d4”, this pattern
+    //can be used to get the first two ("/webhdfs/v1/"). The "?" in pattern
+    //ensures not to be greedy in matching.
+    private static Pattern p = Pattern.compile("/.*?/.*?/");
+
+    /**
+     * This function parses the pathinfo provided  in any servlet context and
+     * returns the segment that is related to the resource.
+     * For example, if the path is "/webhdfs/v1/d1/d2/d2/d4". it returns "/webhdfs/v1"
+     *
+     * @param fullPath
+     * @return
+     */
+    public static String getResourcePath(String fullPath) {
+        String resourcePath = "";
+        if (!Strings.isNullOrEmpty(fullPath)) {
+            Matcher m = p.matcher(fullPath);
+            if (m.find()) {
+                resourcePath = m.group(0);
+            } else {
+                resourcePath = fullPath;
+            }
+        }
+        return resourcePath;
+    }
+
+}


Mime
View raw message