You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by gc...@apache.org on 2015/02/11 22:56:57 UTC

incubator-sentry git commit: SENTRY-640: Add core model for lily hbase indexer

Repository: incubator-sentry
Updated Branches:
  refs/heads/master 08adb2cbc -> adf02be4c


SENTRY-640: Add core model for lily hbase indexer


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

Branch: refs/heads/master
Commit: adf02be4cc3ea8d77cdf2ffbcff8388674b25681
Parents: 08adb2c
Author: Gregory Chanan <gc...@cloudera.com>
Authored: Tue Feb 10 15:29:11 2015 -0800
Committer: Gregory Chanan <gc...@cloudera.com>
Committed: Wed Feb 11 13:35:32 2015 -0800

----------------------------------------------------------------------
 pom.xml                                         |  5 ++
 sentry-core/pom.xml                             |  1 +
 sentry-core/sentry-core-model-indexer/pom.xml   | 43 +++++++++++
 .../sentry/core/model/indexer/Indexer.java      | 51 +++++++++++++
 .../model/indexer/IndexerActionFactory.java     | 80 ++++++++++++++++++++
 .../core/model/indexer/IndexerConstants.java    | 25 ++++++
 .../core/model/indexer/IndexerModelAction.java  | 39 ++++++++++
 .../model/indexer/IndexerModelAuthorizable.java | 28 +++++++
 .../core/indexer/TestIndexerBitFieldAction.java | 75 ++++++++++++++++++
 sentry-core/sentry-core-model-search/pom.xml    |  2 +-
 sentry-dist/pom.xml                             |  4 +
 11 files changed, 352 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 65c2e75..abdd093 100644
--- a/pom.xml
+++ b/pom.xml
@@ -294,6 +294,11 @@ limitations under the License.
       </dependency>
       <dependency>
         <groupId>org.apache.sentry</groupId>
+        <artifactId>sentry-core-model-indexer</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.sentry</groupId>
         <artifactId>sentry-core-model-search</artifactId>
         <version>${project.version}</version>
       </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-core/pom.xml b/sentry-core/pom.xml
index 2dce738..1552133 100644
--- a/sentry-core/pom.xml
+++ b/sentry-core/pom.xml
@@ -31,6 +31,7 @@ limitations under the License.
   <modules>
     <module>sentry-core-common</module>
     <module>sentry-core-model-db</module>
+    <module>sentry-core-model-indexer</module>
     <module>sentry-core-model-search</module>
   </modules>
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-indexer/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-indexer/pom.xml b/sentry-core/sentry-core-model-indexer/pom.xml
new file mode 100644
index 0000000..76108c1
--- /dev/null
+++ b/sentry-core/sentry-core-model-indexer/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0"?>
+<!--
+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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.sentry</groupId>
+    <artifactId>sentry-core</artifactId>
+    <version>1.5.0-incubating-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>sentry-core-model-indexer</artifactId>
+  <name>Sentry Core Model Indexer</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.sentry</groupId>
+      <artifactId>sentry-core-common</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/Indexer.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/Indexer.java b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/Indexer.java
new file mode 100644
index 0000000..9b1c6fd
--- /dev/null
+++ b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/Indexer.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.sentry.core.model.indexer;
+
+public class Indexer implements IndexerModelAuthorizable {
+
+  /**
+   * Represents all indexers
+   */
+  public static final Indexer ALL = new Indexer(IndexerConstants.ALL);
+
+  private final String name;
+
+  public Indexer(String name) {
+    this.name = name;
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public String toString() {
+    return "Indexer [name=" + name + "]";
+  }
+
+  @Override
+  public AuthorizableType getAuthzType() {
+    return AuthorizableType.Indexer;
+  }
+
+  @Override
+  public String getTypeName() {
+    return getAuthzType().name();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerActionFactory.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerActionFactory.java b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerActionFactory.java
new file mode 100644
index 0000000..3ca85bc
--- /dev/null
+++ b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerActionFactory.java
@@ -0,0 +1,80 @@
+/**
+ * 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.core.model.indexer;
+
+import java.util.List;
+
+import org.apache.sentry.core.common.BitFieldAction;
+import org.apache.sentry.core.common.BitFieldActionFactory;
+
+import com.google.common.collect.Lists;
+
+public class IndexerActionFactory extends BitFieldActionFactory {
+  public enum IndexerAction {
+    WRITE(IndexerConstants.WRITE, 0x0001),
+    READ(IndexerConstants.READ, 0x0002),
+    ALL(IndexerConstants.ALL, 0x0001|0x0002);
+
+    private String name;
+    private int code;
+    private IndexerAction(String name, int code) {
+      this.name = name;
+      this.code = code;
+    }
+    public String getName() {
+      return name;
+    }
+    public int getCode() {
+      return code;
+    }
+  }
+
+  public static class IndexerBitFieldAction extends BitFieldAction {
+    public IndexerBitFieldAction(IndexerAction action) {
+      super(action.getName(), action.getCode());
+    }
+  }
+
+  private final static IndexerAction[] AllActions = IndexerAction.values();
+  /**
+   * One bit set action array
+   */
+  private final static IndexerAction[] OneBitActions = new IndexerAction[]{IndexerAction.WRITE, IndexerAction.READ};
+
+  @Override
+  public List<? extends BitFieldAction> getActionsByCode(int actionCode) {
+    List<IndexerBitFieldAction> actions = Lists.newArrayList();
+    for (IndexerAction action : OneBitActions) {
+      if ((action.code & actionCode) == action.code) {
+        actions.add(new IndexerBitFieldAction(action));
+      }
+    }
+    return actions;
+  }
+
+  @Override
+  public BitFieldAction getActionByName(String name) {
+    IndexerBitFieldAction val = null;
+    for (IndexerAction action : AllActions) {
+      if (action.name.equalsIgnoreCase(name)) {
+        return new IndexerBitFieldAction(action);
+      }
+    }
+    return val;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerConstants.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerConstants.java b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerConstants.java
new file mode 100644
index 0000000..2182525
--- /dev/null
+++ b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerConstants.java
@@ -0,0 +1,25 @@
+/*
+ * 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.core.model.indexer;
+
+public class IndexerConstants {
+
+  public static final String ALL = "*";
+  public static final String READ = "read";
+  public static final String WRITE = "write";
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAction.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAction.java b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAction.java
new file mode 100644
index 0000000..f8d5cfb
--- /dev/null
+++ b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAction.java
@@ -0,0 +1,39 @@
+/*
+ * 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.core.model.indexer;
+
+import org.apache.sentry.core.common.Action;
+
+/**
+ * Represents actions in the Indexer model.
+ */
+public enum IndexerModelAction implements Action {
+
+  WRITE(IndexerConstants.WRITE),
+  READ(IndexerConstants.READ),
+  ALL(IndexerConstants.ALL);
+
+  private final String value;
+  private IndexerModelAction(String value) {
+    this.value = value;
+  }
+
+  @Override
+  public String getValue() {
+    return value;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAuthorizable.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAuthorizable.java b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAuthorizable.java
new file mode 100644
index 0000000..d92a5c8
--- /dev/null
+++ b/sentry-core/sentry-core-model-indexer/src/main/java/org/apache/sentry/core/model/indexer/IndexerModelAuthorizable.java
@@ -0,0 +1,28 @@
+/*
+ * 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.core.model.indexer;
+
+import org.apache.sentry.core.common.Authorizable;
+
+public interface IndexerModelAuthorizable extends Authorizable {
+
+  public enum AuthorizableType {
+    Indexer
+  };
+
+  public AuthorizableType getAuthzType();
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-indexer/src/test/java/org/apache/sentry/core/indexer/TestIndexerBitFieldAction.java
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-indexer/src/test/java/org/apache/sentry/core/indexer/TestIndexerBitFieldAction.java b/sentry-core/sentry-core-model-indexer/src/test/java/org/apache/sentry/core/indexer/TestIndexerBitFieldAction.java
new file mode 100644
index 0000000..a490cd8
--- /dev/null
+++ b/sentry-core/sentry-core-model-indexer/src/test/java/org/apache/sentry/core/indexer/TestIndexerBitFieldAction.java
@@ -0,0 +1,75 @@
+/**
+ * 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.core.indexer;
+
+import java.util.List;
+
+import org.apache.sentry.core.model.indexer.IndexerActionFactory;
+import org.apache.sentry.core.model.indexer.IndexerActionFactory.IndexerAction;
+import org.apache.sentry.core.model.indexer.IndexerActionFactory.IndexerBitFieldAction;
+import org.apache.sentry.core.model.indexer.IndexerConstants;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertEquals;
+
+public class TestIndexerBitFieldAction {
+  IndexerActionFactory actionFactory = new IndexerActionFactory();
+
+  @Test
+  public void testImpliesAction() {
+    IndexerBitFieldAction writeAction = new IndexerBitFieldAction(IndexerAction.WRITE);
+    IndexerBitFieldAction readAction = new IndexerBitFieldAction(IndexerAction.READ);
+    IndexerBitFieldAction allAction = new IndexerBitFieldAction(IndexerAction.ALL);
+
+    assertTrue(allAction.implies(readAction));
+    assertTrue(allAction.implies(writeAction));
+    assertTrue(allAction.implies(allAction));
+    assertTrue(writeAction.implies(writeAction));
+    assertTrue(readAction.implies(readAction));
+
+    assertFalse(readAction.implies(writeAction));
+    assertFalse(readAction.implies(allAction));
+    assertFalse(writeAction.implies(readAction));
+    assertFalse(writeAction.implies(allAction));
+  }
+
+  @Test
+  public void testGetActionByName() throws Exception {
+    IndexerBitFieldAction writeAction = (IndexerBitFieldAction)actionFactory.getActionByName(IndexerConstants.WRITE);
+    IndexerBitFieldAction readAction = (IndexerBitFieldAction)actionFactory.getActionByName(IndexerConstants.READ);
+    IndexerBitFieldAction allAction = (IndexerBitFieldAction)actionFactory.getActionByName(IndexerConstants.ALL);
+
+    assertTrue(writeAction.equals(new IndexerBitFieldAction(IndexerAction.WRITE)));
+    assertTrue(readAction.equals(new IndexerBitFieldAction(IndexerAction.READ)));
+    assertTrue(allAction.equals(new IndexerBitFieldAction(IndexerAction.ALL)));
+  }
+
+  @Test
+  public void testGetActionsByCode() throws Exception {
+    IndexerBitFieldAction writeAction = new IndexerBitFieldAction(IndexerAction.WRITE);
+    IndexerBitFieldAction readAction = new IndexerBitFieldAction(IndexerAction.READ);
+
+    assertEquals(Lists.newArrayList(writeAction, readAction), actionFactory.getActionsByCode(IndexerAction.ALL.getCode()));
+    assertEquals(Lists.newArrayList(writeAction), actionFactory.getActionsByCode(IndexerAction.WRITE.getCode()));
+    assertEquals(Lists.newArrayList(readAction), actionFactory.getActionsByCode(IndexerAction.READ.getCode()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-core/sentry-core-model-search/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-core/sentry-core-model-search/pom.xml b/sentry-core/sentry-core-model-search/pom.xml
index 1753b51..3c4aaab 100644
--- a/sentry-core/sentry-core-model-search/pom.xml
+++ b/sentry-core/sentry-core-model-search/pom.xml
@@ -25,7 +25,7 @@ limitations under the License.
   </parent>
 
   <artifactId>sentry-core-model-search</artifactId>
-  <name>Sentry Core Model Solr</name>
+  <name>Sentry Core Model Search</name>
 
   <dependencies>
     <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/adf02be4/sentry-dist/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-dist/pom.xml b/sentry-dist/pom.xml
index 04a63de..67c6641 100644
--- a/sentry-dist/pom.xml
+++ b/sentry-dist/pom.xml
@@ -36,6 +36,10 @@ limitations under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.sentry</groupId>
+      <artifactId>sentry-core-model-indexer</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sentry</groupId>
       <artifactId>sentry-core-model-search</artifactId>
     </dependency>
     <dependency>