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

[1/6] incubator-sentry git commit: SENTRY-197: Create tool to dump and load of entire Sentry service (Colin Ma, Reviewed by:Sravya Tirukkovalur, Guoquan Shen, Dapeng Sun, Anne Yu)

Repository: incubator-sentry
Updated Branches:
  refs/heads/master 6c3184acc -> 92cde111f


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java
new file mode 100644
index 0000000..2482eb4
--- /dev/null
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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.tests.e2e.hive;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sentry.binding.hive.SentryPolicyFileFormatFactory;
+import org.apache.sentry.binding.hive.SentryPolicyFileFormatter;
+import org.apache.sentry.binding.hive.authz.SentryConfigTool;
+import org.apache.sentry.provider.common.PolicyFileConstants;
+import org.apache.sentry.provider.common.ProviderConstants;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.io.Resources;
+
+public class TestPolicyImportExport extends AbstractTestWithStaticConfiguration {
+
+  // resources/testPolicyImport.ini is used for the import test and all the following
+  // privileges(PRIVILIEGE1...8) are defined the same as in testPolicyImport.ini, used for verifying
+  // the test result.
+  public static String PRIVILIEGE1 = "server=server1";
+  public static String PRIVILIEGE2 = "server=server1->action=select->grantoption=false";
+  public static String PRIVILIEGE3 = "server=server1->db=db2->action=insert->grantoption=true";
+  public static String PRIVILIEGE4 = "server=server1->db=db1->table=tbl1->action=insert";
+  public static String PRIVILIEGE5 = "server=server1->db=db1->table=tbl2->column=col1->action=insert";
+  public static String PRIVILIEGE6 = "server=server1->db=db1->table=tbl3->column=col1->action=*->grantoption=true";
+  public static String PRIVILIEGE7 = "server=server1->db=db1->table=tbl4->column=col1->action=all->grantoption=true";
+  public static String PRIVILIEGE8 = "server=server1->uri=hdfs://testserver:9999/path2->action=insert";
+
+  private SentryConfigTool configTool;
+  private Map<String, Map<String, Set<String>>> policyFileMappingData;
+
+  @BeforeClass
+  public static void setupTestStaticConfiguration() throws Exception{
+    useSentryService = true;
+    // add current user to admin group to get the permission for import/export
+    String requestorUserName = System.getProperty("user.name", "");
+    StaticUserGroup.getStaticMapping().put(requestorUserName, ADMINGROUP);
+    AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
+  }
+
+  @Before
+  public void setup() throws Exception {
+    configTool = new SentryConfigTool();
+    configTool.setPolicyFile(context.getPolicyFile().getPath());
+    configTool.setupConfig();
+    importAdminPrivilege();
+  }
+
+  private void importAdminPrivilege() throws Exception {
+    prepareForImport("testPolicyImportAdmin.ini");
+    configTool.importPolicy();
+  }
+
+  private void prepareExceptedData() {
+    // test data for:
+    // [groups]
+    // group1=roleImport1,roleImport2
+    // group2=roleImport1,roleImport2,roleImport3
+    // group3=roleImport2,roleImport3
+    // [roles]
+    // roleImport1=privilege1,privilege2,privilege3,privilege4
+    // roleImport2=privilege3,privilege4,privilege5,privilege6
+    // roleImport3=privilege5,privilege6,privilege7,privilege8
+    policyFileMappingData = Maps.newHashMap();
+    Map<String, Set<String>> groupRolesMap = Maps.newHashMap();
+    Map<String, Set<String>> rolePrivilegesMap = Maps.newHashMap();
+    groupRolesMap.put("group1", Sets.newHashSet("roleimport1", "roleimport2"));
+    groupRolesMap.put("group2", Sets.newHashSet("roleimport1", "roleimport2", "roleimport3"));
+    groupRolesMap.put("group3", Sets.newHashSet("roleimport2", "roleimport3"));
+    // the adminrole is defined in testPolicyImportAdmin.ini
+    groupRolesMap.put("admin", Sets.newHashSet("adminrole"));
+    rolePrivilegesMap.put("roleimport1",
+        Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4));
+    rolePrivilegesMap.put("roleimport2",
+        Sets.newHashSet(PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6));
+    rolePrivilegesMap.put("roleimport3",
+        Sets.newHashSet(PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+    // the adminrole is defined in testPolicyImportAdmin.ini
+    rolePrivilegesMap.put("adminrole", Sets.newHashSet(PRIVILIEGE1));
+    policyFileMappingData.put(PolicyFileConstants.GROUPS, groupRolesMap);
+    policyFileMappingData.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+
+  }
+
+  @Test
+  public void testImportExportPolicy() throws Exception {
+    String importFileName = "testPolicyImport.ini";
+    String exportFileName = "testPolicyExport.ini";
+    File importFile = new File(dataDir, importFileName);
+    File exportFile = new File(dataDir, exportFileName);
+    FileOutputStream to = new FileOutputStream(importFile);
+    Resources.copy(Resources.getResource(importFileName), to);
+    to.close();
+    configTool.setImportPolicyFilePath(importFile.getAbsolutePath());
+    configTool.importPolicy();
+
+    configTool.setExportPolicyFilePath(exportFile.getAbsolutePath());
+    configTool.exportPolicy();
+
+    SentryPolicyFileFormatter sentryPolicyFileFormatter = SentryPolicyFileFormatFactory
+        .createFileFormatter(configTool.getAuthzConf());
+    Map<String, Map<String, Set<String>>> exportMappingData = sentryPolicyFileFormatter.parse(
+        exportFile.getAbsolutePath(), configTool.getAuthzConf());
+
+    prepareExceptedData();
+    validateSentryMappingData(exportMappingData, policyFileMappingData);
+  }
+
+  @Test
+  public void testImportExportPolicyForError() throws Exception {
+    prepareForImport("testPolicyImportError.ini");
+    try {
+      configTool.importPolicy();
+      fail("IllegalArgumentException should be thrown for: Invalid key value: server [server]");
+    } catch (IllegalArgumentException ex) {
+      // ignore
+    }
+  }
+
+  private void prepareForImport(String resorceName) throws Exception {
+    File importFile = new File(dataDir, resorceName);
+    FileOutputStream to = new FileOutputStream(importFile);
+    Resources.copy(Resources.getResource(resorceName), to);
+    to.close();
+    configTool.setImportPolicyFilePath(importFile.getAbsolutePath());
+  }
+
+  // verify the mapping data
+  public void validateSentryMappingData(Map<String, Map<String, Set<String>>> actualMappingData,
+      Map<String, Map<String, Set<String>>> expectedMappingData) {
+    validateGroupRolesMap(actualMappingData.get(PolicyFileConstants.GROUPS),
+        expectedMappingData.get(PolicyFileConstants.GROUPS));
+    validateRolePrivilegesMap(actualMappingData.get(PolicyFileConstants.ROLES),
+        expectedMappingData.get(PolicyFileConstants.ROLES));
+  }
+
+  // verify the mapping data for [group,role]
+  private void validateGroupRolesMap(Map<String, Set<String>> actualMap,
+      Map<String, Set<String>> expectedMap) {
+    assertEquals(expectedMap.keySet().size(), actualMap.keySet().size());
+    for (String groupName : actualMap.keySet()) {
+      Set<String> actualRoles = actualMap.get(groupName);
+      Set<String> expectedRoles = expectedMap.get(groupName);
+      assertEquals(actualRoles.size(), expectedRoles.size());
+      assertTrue(actualRoles.equals(expectedRoles));
+    }
+  }
+
+  // verify the mapping data for [role,privilege]
+  private void validateRolePrivilegesMap(Map<String, Set<String>> actualMap,
+      Map<String, Set<String>> expectedMap) {
+    assertEquals(expectedMap.keySet().size(), actualMap.keySet().size());
+    for (String roleName : actualMap.keySet()) {
+      Set<String> actualPrivileges = actualMap.get(roleName);
+      Set<String> exceptedPrivileges = expectedMap.get(roleName);
+      assertEquals(exceptedPrivileges.size(), actualPrivileges.size());
+      for (String actualPrivilege : actualPrivileges) {
+        boolean isFound = exceptedPrivileges.contains(actualPrivilege);
+        if (!isFound) {
+          String withOptionPrivilege = ProviderConstants.AUTHORIZABLE_JOINER.join(actualPrivilege,
+              ProviderConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME,
+                  "false"));
+          isFound = exceptedPrivileges.contains(withOptionPrivilege);
+        }
+        assertTrue(isFound);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImport.ini
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImport.ini b/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImport.ini
new file mode 100644
index 0000000..15fc5bf
--- /dev/null
+++ b/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImport.ini
@@ -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.
+
+[groups]
+group1=roleImport1,roleImport2
+group2=roleImport1,roleImport2,roleImport3
+group3=roleImport2,roleImport3
+[roles]
+roleImport1=server=server1,server=server1->action=select->grantoption=false,server=server1->db=db2->action=insert->grantoption=true,server=server1->db=db1->table=tbl1->action=insert
+roleImport2=server=server1->db=db2->action=insert->grantoption=true,server=server1->db=db1->table=tbl1->action=insert,server=server1->db=db1->table=tbl2->column=col1->action=insert,server=server1->db=db1->table=tbl3->column=col1->action=*->grantoption=true
+roleImport3=server=server1->db=db1->table=tbl2->column=col1->action=insert,server=server1->db=db1->table=tbl3->column=col1->action=*->grantoption=true,server=server1->db=db1->table=tbl4->column=col1->action=all->grantoption=true,server=server1->uri=hdfs://testserver:9999/path2->action=insert

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportAdmin.ini
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportAdmin.ini b/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportAdmin.ini
new file mode 100644
index 0000000..c778d05
--- /dev/null
+++ b/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportAdmin.ini
@@ -0,0 +1,22 @@
+# 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.
+
+[groups]
+admin=adminRole
+
+[roles]
+adminRole=server=server1

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportError.ini
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportError.ini b/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportError.ini
new file mode 100644
index 0000000..4d53f2b
--- /dev/null
+++ b/sentry-tests/sentry-tests-hive/src/test/resources/testPolicyImportError.ini
@@ -0,0 +1,21 @@
+# 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.
+
+[groups]
+group1=roleImport1
+[roles]
+roleImport1=server->db=db_1


[4/6] incubator-sentry git commit: SENTRY-197: Create tool to dump and load of entire Sentry service (Colin Ma, Reviewed by:Sravya Tirukkovalur, Guoquan Shen, Dapeng Sun, Anne Yu)

Posted by co...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataResponse.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataResponse.java b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataResponse.java
new file mode 100644
index 0000000..3809df3
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataResponse.java
@@ -0,0 +1,496 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.0)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ *  @generated
+ */
+package org.apache.sentry.provider.db.service.thrift;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.thrift.scheme.IScheme;
+import org.apache.thrift.scheme.SchemeFactory;
+import org.apache.thrift.scheme.StandardScheme;
+
+import org.apache.thrift.scheme.TupleScheme;
+import org.apache.thrift.protocol.TTupleProtocol;
+import org.apache.thrift.protocol.TProtocolException;
+import org.apache.thrift.EncodingUtils;
+import org.apache.thrift.TException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.EnumMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.EnumSet;
+import java.util.Collections;
+import java.util.BitSet;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TSentryExportMappingDataResponse implements org.apache.thrift.TBase<TSentryExportMappingDataResponse, TSentryExportMappingDataResponse._Fields>, java.io.Serializable, Cloneable {
+  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSentryExportMappingDataResponse");
+
+  private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.STRUCT, (short)1);
+  private static final org.apache.thrift.protocol.TField MAPPING_DATA_FIELD_DESC = new org.apache.thrift.protocol.TField("mappingData", org.apache.thrift.protocol.TType.STRUCT, (short)2);
+
+  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+  static {
+    schemes.put(StandardScheme.class, new TSentryExportMappingDataResponseStandardSchemeFactory());
+    schemes.put(TupleScheme.class, new TSentryExportMappingDataResponseTupleSchemeFactory());
+  }
+
+  private org.apache.sentry.service.thrift.TSentryResponseStatus status; // required
+  private TSentryMappingData mappingData; // required
+
+  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+    STATUS((short)1, "status"),
+    MAPPING_DATA((short)2, "mappingData");
+
+    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+    static {
+      for (_Fields field : EnumSet.allOf(_Fields.class)) {
+        byName.put(field.getFieldName(), field);
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, or null if its not found.
+     */
+    public static _Fields findByThriftId(int fieldId) {
+      switch(fieldId) {
+        case 1: // STATUS
+          return STATUS;
+        case 2: // MAPPING_DATA
+          return MAPPING_DATA;
+        default:
+          return null;
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, throwing an exception
+     * if it is not found.
+     */
+    public static _Fields findByThriftIdOrThrow(int fieldId) {
+      _Fields fields = findByThriftId(fieldId);
+      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+      return fields;
+    }
+
+    /**
+     * Find the _Fields constant that matches name, or null if its not found.
+     */
+    public static _Fields findByName(String name) {
+      return byName.get(name);
+    }
+
+    private final short _thriftId;
+    private final String _fieldName;
+
+    _Fields(short thriftId, String fieldName) {
+      _thriftId = thriftId;
+      _fieldName = fieldName;
+    }
+
+    public short getThriftFieldId() {
+      return _thriftId;
+    }
+
+    public String getFieldName() {
+      return _fieldName;
+    }
+  }
+
+  // isset id assignments
+  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+  static {
+    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+    tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, org.apache.sentry.service.thrift.TSentryResponseStatus.class)));
+    tmpMap.put(_Fields.MAPPING_DATA, new org.apache.thrift.meta_data.FieldMetaData("mappingData", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TSentryMappingData.class)));
+    metaDataMap = Collections.unmodifiableMap(tmpMap);
+    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSentryExportMappingDataResponse.class, metaDataMap);
+  }
+
+  public TSentryExportMappingDataResponse() {
+  }
+
+  public TSentryExportMappingDataResponse(
+    org.apache.sentry.service.thrift.TSentryResponseStatus status,
+    TSentryMappingData mappingData)
+  {
+    this();
+    this.status = status;
+    this.mappingData = mappingData;
+  }
+
+  /**
+   * Performs a deep copy on <i>other</i>.
+   */
+  public TSentryExportMappingDataResponse(TSentryExportMappingDataResponse other) {
+    if (other.isSetStatus()) {
+      this.status = new org.apache.sentry.service.thrift.TSentryResponseStatus(other.status);
+    }
+    if (other.isSetMappingData()) {
+      this.mappingData = new TSentryMappingData(other.mappingData);
+    }
+  }
+
+  public TSentryExportMappingDataResponse deepCopy() {
+    return new TSentryExportMappingDataResponse(this);
+  }
+
+  @Override
+  public void clear() {
+    this.status = null;
+    this.mappingData = null;
+  }
+
+  public org.apache.sentry.service.thrift.TSentryResponseStatus getStatus() {
+    return this.status;
+  }
+
+  public void setStatus(org.apache.sentry.service.thrift.TSentryResponseStatus status) {
+    this.status = status;
+  }
+
+  public void unsetStatus() {
+    this.status = null;
+  }
+
+  /** Returns true if field status is set (has been assigned a value) and false otherwise */
+  public boolean isSetStatus() {
+    return this.status != null;
+  }
+
+  public void setStatusIsSet(boolean value) {
+    if (!value) {
+      this.status = null;
+    }
+  }
+
+  public TSentryMappingData getMappingData() {
+    return this.mappingData;
+  }
+
+  public void setMappingData(TSentryMappingData mappingData) {
+    this.mappingData = mappingData;
+  }
+
+  public void unsetMappingData() {
+    this.mappingData = null;
+  }
+
+  /** Returns true if field mappingData is set (has been assigned a value) and false otherwise */
+  public boolean isSetMappingData() {
+    return this.mappingData != null;
+  }
+
+  public void setMappingDataIsSet(boolean value) {
+    if (!value) {
+      this.mappingData = null;
+    }
+  }
+
+  public void setFieldValue(_Fields field, Object value) {
+    switch (field) {
+    case STATUS:
+      if (value == null) {
+        unsetStatus();
+      } else {
+        setStatus((org.apache.sentry.service.thrift.TSentryResponseStatus)value);
+      }
+      break;
+
+    case MAPPING_DATA:
+      if (value == null) {
+        unsetMappingData();
+      } else {
+        setMappingData((TSentryMappingData)value);
+      }
+      break;
+
+    }
+  }
+
+  public Object getFieldValue(_Fields field) {
+    switch (field) {
+    case STATUS:
+      return getStatus();
+
+    case MAPPING_DATA:
+      return getMappingData();
+
+    }
+    throw new IllegalStateException();
+  }
+
+  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+  public boolean isSet(_Fields field) {
+    if (field == null) {
+      throw new IllegalArgumentException();
+    }
+
+    switch (field) {
+    case STATUS:
+      return isSetStatus();
+    case MAPPING_DATA:
+      return isSetMappingData();
+    }
+    throw new IllegalStateException();
+  }
+
+  @Override
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof TSentryExportMappingDataResponse)
+      return this.equals((TSentryExportMappingDataResponse)that);
+    return false;
+  }
+
+  public boolean equals(TSentryExportMappingDataResponse that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_status = true && this.isSetStatus();
+    boolean that_present_status = true && that.isSetStatus();
+    if (this_present_status || that_present_status) {
+      if (!(this_present_status && that_present_status))
+        return false;
+      if (!this.status.equals(that.status))
+        return false;
+    }
+
+    boolean this_present_mappingData = true && this.isSetMappingData();
+    boolean that_present_mappingData = true && that.isSetMappingData();
+    if (this_present_mappingData || that_present_mappingData) {
+      if (!(this_present_mappingData && that_present_mappingData))
+        return false;
+      if (!this.mappingData.equals(that.mappingData))
+        return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    HashCodeBuilder builder = new HashCodeBuilder();
+
+    boolean present_status = true && (isSetStatus());
+    builder.append(present_status);
+    if (present_status)
+      builder.append(status);
+
+    boolean present_mappingData = true && (isSetMappingData());
+    builder.append(present_mappingData);
+    if (present_mappingData)
+      builder.append(mappingData);
+
+    return builder.toHashCode();
+  }
+
+  public int compareTo(TSentryExportMappingDataResponse other) {
+    if (!getClass().equals(other.getClass())) {
+      return getClass().getName().compareTo(other.getClass().getName());
+    }
+
+    int lastComparison = 0;
+    TSentryExportMappingDataResponse typedOther = (TSentryExportMappingDataResponse)other;
+
+    lastComparison = Boolean.valueOf(isSetStatus()).compareTo(typedOther.isSetStatus());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetStatus()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, typedOther.status);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    lastComparison = Boolean.valueOf(isSetMappingData()).compareTo(typedOther.isSetMappingData());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetMappingData()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.mappingData, typedOther.mappingData);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    return 0;
+  }
+
+  public _Fields fieldForId(int fieldId) {
+    return _Fields.findByThriftId(fieldId);
+  }
+
+  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+  }
+
+  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("TSentryExportMappingDataResponse(");
+    boolean first = true;
+
+    sb.append("status:");
+    if (this.status == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.status);
+    }
+    first = false;
+    if (!first) sb.append(", ");
+    sb.append("mappingData:");
+    if (this.mappingData == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.mappingData);
+    }
+    first = false;
+    sb.append(")");
+    return sb.toString();
+  }
+
+  public void validate() throws org.apache.thrift.TException {
+    // check for required fields
+    if (!isSetStatus()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'status' is unset! Struct:" + toString());
+    }
+
+    if (!isSetMappingData()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'mappingData' is unset! Struct:" + toString());
+    }
+
+    // check for sub-struct validity
+    if (status != null) {
+      status.validate();
+    }
+    if (mappingData != null) {
+      mappingData.validate();
+    }
+  }
+
+  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+    try {
+      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+    try {
+      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private static class TSentryExportMappingDataResponseStandardSchemeFactory implements SchemeFactory {
+    public TSentryExportMappingDataResponseStandardScheme getScheme() {
+      return new TSentryExportMappingDataResponseStandardScheme();
+    }
+  }
+
+  private static class TSentryExportMappingDataResponseStandardScheme extends StandardScheme<TSentryExportMappingDataResponse> {
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot, TSentryExportMappingDataResponse struct) throws org.apache.thrift.TException {
+      org.apache.thrift.protocol.TField schemeField;
+      iprot.readStructBegin();
+      while (true)
+      {
+        schemeField = iprot.readFieldBegin();
+        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+          break;
+        }
+        switch (schemeField.id) {
+          case 1: // STATUS
+            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+              struct.status = new org.apache.sentry.service.thrift.TSentryResponseStatus();
+              struct.status.read(iprot);
+              struct.setStatusIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          case 2: // MAPPING_DATA
+            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+              struct.mappingData = new TSentryMappingData();
+              struct.mappingData.read(iprot);
+              struct.setMappingDataIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          default:
+            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+        }
+        iprot.readFieldEnd();
+      }
+      iprot.readStructEnd();
+      struct.validate();
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot, TSentryExportMappingDataResponse struct) throws org.apache.thrift.TException {
+      struct.validate();
+
+      oprot.writeStructBegin(STRUCT_DESC);
+      if (struct.status != null) {
+        oprot.writeFieldBegin(STATUS_FIELD_DESC);
+        struct.status.write(oprot);
+        oprot.writeFieldEnd();
+      }
+      if (struct.mappingData != null) {
+        oprot.writeFieldBegin(MAPPING_DATA_FIELD_DESC);
+        struct.mappingData.write(oprot);
+        oprot.writeFieldEnd();
+      }
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+
+  }
+
+  private static class TSentryExportMappingDataResponseTupleSchemeFactory implements SchemeFactory {
+    public TSentryExportMappingDataResponseTupleScheme getScheme() {
+      return new TSentryExportMappingDataResponseTupleScheme();
+    }
+  }
+
+  private static class TSentryExportMappingDataResponseTupleScheme extends TupleScheme<TSentryExportMappingDataResponse> {
+
+    @Override
+    public void write(org.apache.thrift.protocol.TProtocol prot, TSentryExportMappingDataResponse struct) throws org.apache.thrift.TException {
+      TTupleProtocol oprot = (TTupleProtocol) prot;
+      struct.status.write(oprot);
+      struct.mappingData.write(oprot);
+    }
+
+    @Override
+    public void read(org.apache.thrift.protocol.TProtocol prot, TSentryExportMappingDataResponse struct) throws org.apache.thrift.TException {
+      TTupleProtocol iprot = (TTupleProtocol) prot;
+      struct.status = new org.apache.sentry.service.thrift.TSentryResponseStatus();
+      struct.status.read(iprot);
+      struct.setStatusIsSet(true);
+      struct.mappingData = new TSentryMappingData();
+      struct.mappingData.read(iprot);
+      struct.setMappingDataIsSet(true);
+    }
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataRequest.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataRequest.java b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataRequest.java
new file mode 100644
index 0000000..23ad56c
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataRequest.java
@@ -0,0 +1,689 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.0)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ *  @generated
+ */
+package org.apache.sentry.provider.db.service.thrift;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.thrift.scheme.IScheme;
+import org.apache.thrift.scheme.SchemeFactory;
+import org.apache.thrift.scheme.StandardScheme;
+
+import org.apache.thrift.scheme.TupleScheme;
+import org.apache.thrift.protocol.TTupleProtocol;
+import org.apache.thrift.protocol.TProtocolException;
+import org.apache.thrift.EncodingUtils;
+import org.apache.thrift.TException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.EnumMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.EnumSet;
+import java.util.Collections;
+import java.util.BitSet;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TSentryImportMappingDataRequest implements org.apache.thrift.TBase<TSentryImportMappingDataRequest, TSentryImportMappingDataRequest._Fields>, java.io.Serializable, Cloneable {
+  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSentryImportMappingDataRequest");
+
+  private static final org.apache.thrift.protocol.TField PROTOCOL_VERSION_FIELD_DESC = new org.apache.thrift.protocol.TField("protocol_version", org.apache.thrift.protocol.TType.I32, (short)1);
+  private static final org.apache.thrift.protocol.TField REQUESTOR_USER_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("requestorUserName", org.apache.thrift.protocol.TType.STRING, (short)2);
+  private static final org.apache.thrift.protocol.TField OVERWRITE_ROLE_FIELD_DESC = new org.apache.thrift.protocol.TField("overwriteRole", org.apache.thrift.protocol.TType.BOOL, (short)3);
+  private static final org.apache.thrift.protocol.TField MAPPING_DATA_FIELD_DESC = new org.apache.thrift.protocol.TField("mappingData", org.apache.thrift.protocol.TType.STRUCT, (short)4);
+
+  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+  static {
+    schemes.put(StandardScheme.class, new TSentryImportMappingDataRequestStandardSchemeFactory());
+    schemes.put(TupleScheme.class, new TSentryImportMappingDataRequestTupleSchemeFactory());
+  }
+
+  private int protocol_version; // required
+  private String requestorUserName; // required
+  private boolean overwriteRole; // required
+  private TSentryMappingData mappingData; // required
+
+  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+    PROTOCOL_VERSION((short)1, "protocol_version"),
+    REQUESTOR_USER_NAME((short)2, "requestorUserName"),
+    OVERWRITE_ROLE((short)3, "overwriteRole"),
+    MAPPING_DATA((short)4, "mappingData");
+
+    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+    static {
+      for (_Fields field : EnumSet.allOf(_Fields.class)) {
+        byName.put(field.getFieldName(), field);
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, or null if its not found.
+     */
+    public static _Fields findByThriftId(int fieldId) {
+      switch(fieldId) {
+        case 1: // PROTOCOL_VERSION
+          return PROTOCOL_VERSION;
+        case 2: // REQUESTOR_USER_NAME
+          return REQUESTOR_USER_NAME;
+        case 3: // OVERWRITE_ROLE
+          return OVERWRITE_ROLE;
+        case 4: // MAPPING_DATA
+          return MAPPING_DATA;
+        default:
+          return null;
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, throwing an exception
+     * if it is not found.
+     */
+    public static _Fields findByThriftIdOrThrow(int fieldId) {
+      _Fields fields = findByThriftId(fieldId);
+      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+      return fields;
+    }
+
+    /**
+     * Find the _Fields constant that matches name, or null if its not found.
+     */
+    public static _Fields findByName(String name) {
+      return byName.get(name);
+    }
+
+    private final short _thriftId;
+    private final String _fieldName;
+
+    _Fields(short thriftId, String fieldName) {
+      _thriftId = thriftId;
+      _fieldName = fieldName;
+    }
+
+    public short getThriftFieldId() {
+      return _thriftId;
+    }
+
+    public String getFieldName() {
+      return _fieldName;
+    }
+  }
+
+  // isset id assignments
+  private static final int __PROTOCOL_VERSION_ISSET_ID = 0;
+  private static final int __OVERWRITEROLE_ISSET_ID = 1;
+  private byte __isset_bitfield = 0;
+  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+  static {
+    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+    tmpMap.put(_Fields.PROTOCOL_VERSION, new org.apache.thrift.meta_data.FieldMetaData("protocol_version", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
+    tmpMap.put(_Fields.REQUESTOR_USER_NAME, new org.apache.thrift.meta_data.FieldMetaData("requestorUserName", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
+    tmpMap.put(_Fields.OVERWRITE_ROLE, new org.apache.thrift.meta_data.FieldMetaData("overwriteRole", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)));
+    tmpMap.put(_Fields.MAPPING_DATA, new org.apache.thrift.meta_data.FieldMetaData("mappingData", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TSentryMappingData.class)));
+    metaDataMap = Collections.unmodifiableMap(tmpMap);
+    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSentryImportMappingDataRequest.class, metaDataMap);
+  }
+
+  public TSentryImportMappingDataRequest() {
+    this.protocol_version = 1;
+
+    this.overwriteRole = false;
+
+  }
+
+  public TSentryImportMappingDataRequest(
+    int protocol_version,
+    String requestorUserName,
+    boolean overwriteRole,
+    TSentryMappingData mappingData)
+  {
+    this();
+    this.protocol_version = protocol_version;
+    setProtocol_versionIsSet(true);
+    this.requestorUserName = requestorUserName;
+    this.overwriteRole = overwriteRole;
+    setOverwriteRoleIsSet(true);
+    this.mappingData = mappingData;
+  }
+
+  /**
+   * Performs a deep copy on <i>other</i>.
+   */
+  public TSentryImportMappingDataRequest(TSentryImportMappingDataRequest other) {
+    __isset_bitfield = other.__isset_bitfield;
+    this.protocol_version = other.protocol_version;
+    if (other.isSetRequestorUserName()) {
+      this.requestorUserName = other.requestorUserName;
+    }
+    this.overwriteRole = other.overwriteRole;
+    if (other.isSetMappingData()) {
+      this.mappingData = new TSentryMappingData(other.mappingData);
+    }
+  }
+
+  public TSentryImportMappingDataRequest deepCopy() {
+    return new TSentryImportMappingDataRequest(this);
+  }
+
+  @Override
+  public void clear() {
+    this.protocol_version = 1;
+
+    this.requestorUserName = null;
+    this.overwriteRole = false;
+
+    this.mappingData = null;
+  }
+
+  public int getProtocol_version() {
+    return this.protocol_version;
+  }
+
+  public void setProtocol_version(int protocol_version) {
+    this.protocol_version = protocol_version;
+    setProtocol_versionIsSet(true);
+  }
+
+  public void unsetProtocol_version() {
+    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __PROTOCOL_VERSION_ISSET_ID);
+  }
+
+  /** Returns true if field protocol_version is set (has been assigned a value) and false otherwise */
+  public boolean isSetProtocol_version() {
+    return EncodingUtils.testBit(__isset_bitfield, __PROTOCOL_VERSION_ISSET_ID);
+  }
+
+  public void setProtocol_versionIsSet(boolean value) {
+    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __PROTOCOL_VERSION_ISSET_ID, value);
+  }
+
+  public String getRequestorUserName() {
+    return this.requestorUserName;
+  }
+
+  public void setRequestorUserName(String requestorUserName) {
+    this.requestorUserName = requestorUserName;
+  }
+
+  public void unsetRequestorUserName() {
+    this.requestorUserName = null;
+  }
+
+  /** Returns true if field requestorUserName is set (has been assigned a value) and false otherwise */
+  public boolean isSetRequestorUserName() {
+    return this.requestorUserName != null;
+  }
+
+  public void setRequestorUserNameIsSet(boolean value) {
+    if (!value) {
+      this.requestorUserName = null;
+    }
+  }
+
+  public boolean isOverwriteRole() {
+    return this.overwriteRole;
+  }
+
+  public void setOverwriteRole(boolean overwriteRole) {
+    this.overwriteRole = overwriteRole;
+    setOverwriteRoleIsSet(true);
+  }
+
+  public void unsetOverwriteRole() {
+    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __OVERWRITEROLE_ISSET_ID);
+  }
+
+  /** Returns true if field overwriteRole is set (has been assigned a value) and false otherwise */
+  public boolean isSetOverwriteRole() {
+    return EncodingUtils.testBit(__isset_bitfield, __OVERWRITEROLE_ISSET_ID);
+  }
+
+  public void setOverwriteRoleIsSet(boolean value) {
+    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __OVERWRITEROLE_ISSET_ID, value);
+  }
+
+  public TSentryMappingData getMappingData() {
+    return this.mappingData;
+  }
+
+  public void setMappingData(TSentryMappingData mappingData) {
+    this.mappingData = mappingData;
+  }
+
+  public void unsetMappingData() {
+    this.mappingData = null;
+  }
+
+  /** Returns true if field mappingData is set (has been assigned a value) and false otherwise */
+  public boolean isSetMappingData() {
+    return this.mappingData != null;
+  }
+
+  public void setMappingDataIsSet(boolean value) {
+    if (!value) {
+      this.mappingData = null;
+    }
+  }
+
+  public void setFieldValue(_Fields field, Object value) {
+    switch (field) {
+    case PROTOCOL_VERSION:
+      if (value == null) {
+        unsetProtocol_version();
+      } else {
+        setProtocol_version((Integer)value);
+      }
+      break;
+
+    case REQUESTOR_USER_NAME:
+      if (value == null) {
+        unsetRequestorUserName();
+      } else {
+        setRequestorUserName((String)value);
+      }
+      break;
+
+    case OVERWRITE_ROLE:
+      if (value == null) {
+        unsetOverwriteRole();
+      } else {
+        setOverwriteRole((Boolean)value);
+      }
+      break;
+
+    case MAPPING_DATA:
+      if (value == null) {
+        unsetMappingData();
+      } else {
+        setMappingData((TSentryMappingData)value);
+      }
+      break;
+
+    }
+  }
+
+  public Object getFieldValue(_Fields field) {
+    switch (field) {
+    case PROTOCOL_VERSION:
+      return Integer.valueOf(getProtocol_version());
+
+    case REQUESTOR_USER_NAME:
+      return getRequestorUserName();
+
+    case OVERWRITE_ROLE:
+      return Boolean.valueOf(isOverwriteRole());
+
+    case MAPPING_DATA:
+      return getMappingData();
+
+    }
+    throw new IllegalStateException();
+  }
+
+  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+  public boolean isSet(_Fields field) {
+    if (field == null) {
+      throw new IllegalArgumentException();
+    }
+
+    switch (field) {
+    case PROTOCOL_VERSION:
+      return isSetProtocol_version();
+    case REQUESTOR_USER_NAME:
+      return isSetRequestorUserName();
+    case OVERWRITE_ROLE:
+      return isSetOverwriteRole();
+    case MAPPING_DATA:
+      return isSetMappingData();
+    }
+    throw new IllegalStateException();
+  }
+
+  @Override
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof TSentryImportMappingDataRequest)
+      return this.equals((TSentryImportMappingDataRequest)that);
+    return false;
+  }
+
+  public boolean equals(TSentryImportMappingDataRequest that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_protocol_version = true;
+    boolean that_present_protocol_version = true;
+    if (this_present_protocol_version || that_present_protocol_version) {
+      if (!(this_present_protocol_version && that_present_protocol_version))
+        return false;
+      if (this.protocol_version != that.protocol_version)
+        return false;
+    }
+
+    boolean this_present_requestorUserName = true && this.isSetRequestorUserName();
+    boolean that_present_requestorUserName = true && that.isSetRequestorUserName();
+    if (this_present_requestorUserName || that_present_requestorUserName) {
+      if (!(this_present_requestorUserName && that_present_requestorUserName))
+        return false;
+      if (!this.requestorUserName.equals(that.requestorUserName))
+        return false;
+    }
+
+    boolean this_present_overwriteRole = true;
+    boolean that_present_overwriteRole = true;
+    if (this_present_overwriteRole || that_present_overwriteRole) {
+      if (!(this_present_overwriteRole && that_present_overwriteRole))
+        return false;
+      if (this.overwriteRole != that.overwriteRole)
+        return false;
+    }
+
+    boolean this_present_mappingData = true && this.isSetMappingData();
+    boolean that_present_mappingData = true && that.isSetMappingData();
+    if (this_present_mappingData || that_present_mappingData) {
+      if (!(this_present_mappingData && that_present_mappingData))
+        return false;
+      if (!this.mappingData.equals(that.mappingData))
+        return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    HashCodeBuilder builder = new HashCodeBuilder();
+
+    boolean present_protocol_version = true;
+    builder.append(present_protocol_version);
+    if (present_protocol_version)
+      builder.append(protocol_version);
+
+    boolean present_requestorUserName = true && (isSetRequestorUserName());
+    builder.append(present_requestorUserName);
+    if (present_requestorUserName)
+      builder.append(requestorUserName);
+
+    boolean present_overwriteRole = true;
+    builder.append(present_overwriteRole);
+    if (present_overwriteRole)
+      builder.append(overwriteRole);
+
+    boolean present_mappingData = true && (isSetMappingData());
+    builder.append(present_mappingData);
+    if (present_mappingData)
+      builder.append(mappingData);
+
+    return builder.toHashCode();
+  }
+
+  public int compareTo(TSentryImportMappingDataRequest other) {
+    if (!getClass().equals(other.getClass())) {
+      return getClass().getName().compareTo(other.getClass().getName());
+    }
+
+    int lastComparison = 0;
+    TSentryImportMappingDataRequest typedOther = (TSentryImportMappingDataRequest)other;
+
+    lastComparison = Boolean.valueOf(isSetProtocol_version()).compareTo(typedOther.isSetProtocol_version());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetProtocol_version()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.protocol_version, typedOther.protocol_version);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    lastComparison = Boolean.valueOf(isSetRequestorUserName()).compareTo(typedOther.isSetRequestorUserName());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetRequestorUserName()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.requestorUserName, typedOther.requestorUserName);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    lastComparison = Boolean.valueOf(isSetOverwriteRole()).compareTo(typedOther.isSetOverwriteRole());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetOverwriteRole()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.overwriteRole, typedOther.overwriteRole);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    lastComparison = Boolean.valueOf(isSetMappingData()).compareTo(typedOther.isSetMappingData());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetMappingData()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.mappingData, typedOther.mappingData);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    return 0;
+  }
+
+  public _Fields fieldForId(int fieldId) {
+    return _Fields.findByThriftId(fieldId);
+  }
+
+  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+  }
+
+  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("TSentryImportMappingDataRequest(");
+    boolean first = true;
+
+    sb.append("protocol_version:");
+    sb.append(this.protocol_version);
+    first = false;
+    if (!first) sb.append(", ");
+    sb.append("requestorUserName:");
+    if (this.requestorUserName == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.requestorUserName);
+    }
+    first = false;
+    if (!first) sb.append(", ");
+    sb.append("overwriteRole:");
+    sb.append(this.overwriteRole);
+    first = false;
+    if (!first) sb.append(", ");
+    sb.append("mappingData:");
+    if (this.mappingData == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.mappingData);
+    }
+    first = false;
+    sb.append(")");
+    return sb.toString();
+  }
+
+  public void validate() throws org.apache.thrift.TException {
+    // check for required fields
+    if (!isSetProtocol_version()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'protocol_version' is unset! Struct:" + toString());
+    }
+
+    if (!isSetRequestorUserName()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'requestorUserName' is unset! Struct:" + toString());
+    }
+
+    if (!isSetOverwriteRole()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'overwriteRole' is unset! Struct:" + toString());
+    }
+
+    if (!isSetMappingData()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'mappingData' is unset! Struct:" + toString());
+    }
+
+    // check for sub-struct validity
+    if (mappingData != null) {
+      mappingData.validate();
+    }
+  }
+
+  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+    try {
+      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+    try {
+      // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
+      __isset_bitfield = 0;
+      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private static class TSentryImportMappingDataRequestStandardSchemeFactory implements SchemeFactory {
+    public TSentryImportMappingDataRequestStandardScheme getScheme() {
+      return new TSentryImportMappingDataRequestStandardScheme();
+    }
+  }
+
+  private static class TSentryImportMappingDataRequestStandardScheme extends StandardScheme<TSentryImportMappingDataRequest> {
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot, TSentryImportMappingDataRequest struct) throws org.apache.thrift.TException {
+      org.apache.thrift.protocol.TField schemeField;
+      iprot.readStructBegin();
+      while (true)
+      {
+        schemeField = iprot.readFieldBegin();
+        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+          break;
+        }
+        switch (schemeField.id) {
+          case 1: // PROTOCOL_VERSION
+            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
+              struct.protocol_version = iprot.readI32();
+              struct.setProtocol_versionIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          case 2: // REQUESTOR_USER_NAME
+            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
+              struct.requestorUserName = iprot.readString();
+              struct.setRequestorUserNameIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          case 3: // OVERWRITE_ROLE
+            if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) {
+              struct.overwriteRole = iprot.readBool();
+              struct.setOverwriteRoleIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          case 4: // MAPPING_DATA
+            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+              struct.mappingData = new TSentryMappingData();
+              struct.mappingData.read(iprot);
+              struct.setMappingDataIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          default:
+            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+        }
+        iprot.readFieldEnd();
+      }
+      iprot.readStructEnd();
+      struct.validate();
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot, TSentryImportMappingDataRequest struct) throws org.apache.thrift.TException {
+      struct.validate();
+
+      oprot.writeStructBegin(STRUCT_DESC);
+      oprot.writeFieldBegin(PROTOCOL_VERSION_FIELD_DESC);
+      oprot.writeI32(struct.protocol_version);
+      oprot.writeFieldEnd();
+      if (struct.requestorUserName != null) {
+        oprot.writeFieldBegin(REQUESTOR_USER_NAME_FIELD_DESC);
+        oprot.writeString(struct.requestorUserName);
+        oprot.writeFieldEnd();
+      }
+      oprot.writeFieldBegin(OVERWRITE_ROLE_FIELD_DESC);
+      oprot.writeBool(struct.overwriteRole);
+      oprot.writeFieldEnd();
+      if (struct.mappingData != null) {
+        oprot.writeFieldBegin(MAPPING_DATA_FIELD_DESC);
+        struct.mappingData.write(oprot);
+        oprot.writeFieldEnd();
+      }
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+
+  }
+
+  private static class TSentryImportMappingDataRequestTupleSchemeFactory implements SchemeFactory {
+    public TSentryImportMappingDataRequestTupleScheme getScheme() {
+      return new TSentryImportMappingDataRequestTupleScheme();
+    }
+  }
+
+  private static class TSentryImportMappingDataRequestTupleScheme extends TupleScheme<TSentryImportMappingDataRequest> {
+
+    @Override
+    public void write(org.apache.thrift.protocol.TProtocol prot, TSentryImportMappingDataRequest struct) throws org.apache.thrift.TException {
+      TTupleProtocol oprot = (TTupleProtocol) prot;
+      oprot.writeI32(struct.protocol_version);
+      oprot.writeString(struct.requestorUserName);
+      oprot.writeBool(struct.overwriteRole);
+      struct.mappingData.write(oprot);
+    }
+
+    @Override
+    public void read(org.apache.thrift.protocol.TProtocol prot, TSentryImportMappingDataRequest struct) throws org.apache.thrift.TException {
+      TTupleProtocol iprot = (TTupleProtocol) prot;
+      struct.protocol_version = iprot.readI32();
+      struct.setProtocol_versionIsSet(true);
+      struct.requestorUserName = iprot.readString();
+      struct.setRequestorUserNameIsSet(true);
+      struct.overwriteRole = iprot.readBool();
+      struct.setOverwriteRoleIsSet(true);
+      struct.mappingData = new TSentryMappingData();
+      struct.mappingData.read(iprot);
+      struct.setMappingDataIsSet(true);
+    }
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataResponse.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataResponse.java b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataResponse.java
new file mode 100644
index 0000000..8276fcf
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryImportMappingDataResponse.java
@@ -0,0 +1,390 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.0)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ *  @generated
+ */
+package org.apache.sentry.provider.db.service.thrift;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.thrift.scheme.IScheme;
+import org.apache.thrift.scheme.SchemeFactory;
+import org.apache.thrift.scheme.StandardScheme;
+
+import org.apache.thrift.scheme.TupleScheme;
+import org.apache.thrift.protocol.TTupleProtocol;
+import org.apache.thrift.protocol.TProtocolException;
+import org.apache.thrift.EncodingUtils;
+import org.apache.thrift.TException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.EnumMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.EnumSet;
+import java.util.Collections;
+import java.util.BitSet;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TSentryImportMappingDataResponse implements org.apache.thrift.TBase<TSentryImportMappingDataResponse, TSentryImportMappingDataResponse._Fields>, java.io.Serializable, Cloneable {
+  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSentryImportMappingDataResponse");
+
+  private static final org.apache.thrift.protocol.TField STATUS_FIELD_DESC = new org.apache.thrift.protocol.TField("status", org.apache.thrift.protocol.TType.STRUCT, (short)1);
+
+  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+  static {
+    schemes.put(StandardScheme.class, new TSentryImportMappingDataResponseStandardSchemeFactory());
+    schemes.put(TupleScheme.class, new TSentryImportMappingDataResponseTupleSchemeFactory());
+  }
+
+  private org.apache.sentry.service.thrift.TSentryResponseStatus status; // required
+
+  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+    STATUS((short)1, "status");
+
+    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+    static {
+      for (_Fields field : EnumSet.allOf(_Fields.class)) {
+        byName.put(field.getFieldName(), field);
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, or null if its not found.
+     */
+    public static _Fields findByThriftId(int fieldId) {
+      switch(fieldId) {
+        case 1: // STATUS
+          return STATUS;
+        default:
+          return null;
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, throwing an exception
+     * if it is not found.
+     */
+    public static _Fields findByThriftIdOrThrow(int fieldId) {
+      _Fields fields = findByThriftId(fieldId);
+      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+      return fields;
+    }
+
+    /**
+     * Find the _Fields constant that matches name, or null if its not found.
+     */
+    public static _Fields findByName(String name) {
+      return byName.get(name);
+    }
+
+    private final short _thriftId;
+    private final String _fieldName;
+
+    _Fields(short thriftId, String fieldName) {
+      _thriftId = thriftId;
+      _fieldName = fieldName;
+    }
+
+    public short getThriftFieldId() {
+      return _thriftId;
+    }
+
+    public String getFieldName() {
+      return _fieldName;
+    }
+  }
+
+  // isset id assignments
+  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+  static {
+    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+    tmpMap.put(_Fields.STATUS, new org.apache.thrift.meta_data.FieldMetaData("status", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, org.apache.sentry.service.thrift.TSentryResponseStatus.class)));
+    metaDataMap = Collections.unmodifiableMap(tmpMap);
+    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSentryImportMappingDataResponse.class, metaDataMap);
+  }
+
+  public TSentryImportMappingDataResponse() {
+  }
+
+  public TSentryImportMappingDataResponse(
+    org.apache.sentry.service.thrift.TSentryResponseStatus status)
+  {
+    this();
+    this.status = status;
+  }
+
+  /**
+   * Performs a deep copy on <i>other</i>.
+   */
+  public TSentryImportMappingDataResponse(TSentryImportMappingDataResponse other) {
+    if (other.isSetStatus()) {
+      this.status = new org.apache.sentry.service.thrift.TSentryResponseStatus(other.status);
+    }
+  }
+
+  public TSentryImportMappingDataResponse deepCopy() {
+    return new TSentryImportMappingDataResponse(this);
+  }
+
+  @Override
+  public void clear() {
+    this.status = null;
+  }
+
+  public org.apache.sentry.service.thrift.TSentryResponseStatus getStatus() {
+    return this.status;
+  }
+
+  public void setStatus(org.apache.sentry.service.thrift.TSentryResponseStatus status) {
+    this.status = status;
+  }
+
+  public void unsetStatus() {
+    this.status = null;
+  }
+
+  /** Returns true if field status is set (has been assigned a value) and false otherwise */
+  public boolean isSetStatus() {
+    return this.status != null;
+  }
+
+  public void setStatusIsSet(boolean value) {
+    if (!value) {
+      this.status = null;
+    }
+  }
+
+  public void setFieldValue(_Fields field, Object value) {
+    switch (field) {
+    case STATUS:
+      if (value == null) {
+        unsetStatus();
+      } else {
+        setStatus((org.apache.sentry.service.thrift.TSentryResponseStatus)value);
+      }
+      break;
+
+    }
+  }
+
+  public Object getFieldValue(_Fields field) {
+    switch (field) {
+    case STATUS:
+      return getStatus();
+
+    }
+    throw new IllegalStateException();
+  }
+
+  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+  public boolean isSet(_Fields field) {
+    if (field == null) {
+      throw new IllegalArgumentException();
+    }
+
+    switch (field) {
+    case STATUS:
+      return isSetStatus();
+    }
+    throw new IllegalStateException();
+  }
+
+  @Override
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof TSentryImportMappingDataResponse)
+      return this.equals((TSentryImportMappingDataResponse)that);
+    return false;
+  }
+
+  public boolean equals(TSentryImportMappingDataResponse that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_status = true && this.isSetStatus();
+    boolean that_present_status = true && that.isSetStatus();
+    if (this_present_status || that_present_status) {
+      if (!(this_present_status && that_present_status))
+        return false;
+      if (!this.status.equals(that.status))
+        return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    HashCodeBuilder builder = new HashCodeBuilder();
+
+    boolean present_status = true && (isSetStatus());
+    builder.append(present_status);
+    if (present_status)
+      builder.append(status);
+
+    return builder.toHashCode();
+  }
+
+  public int compareTo(TSentryImportMappingDataResponse other) {
+    if (!getClass().equals(other.getClass())) {
+      return getClass().getName().compareTo(other.getClass().getName());
+    }
+
+    int lastComparison = 0;
+    TSentryImportMappingDataResponse typedOther = (TSentryImportMappingDataResponse)other;
+
+    lastComparison = Boolean.valueOf(isSetStatus()).compareTo(typedOther.isSetStatus());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetStatus()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.status, typedOther.status);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    return 0;
+  }
+
+  public _Fields fieldForId(int fieldId) {
+    return _Fields.findByThriftId(fieldId);
+  }
+
+  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+  }
+
+  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("TSentryImportMappingDataResponse(");
+    boolean first = true;
+
+    sb.append("status:");
+    if (this.status == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.status);
+    }
+    first = false;
+    sb.append(")");
+    return sb.toString();
+  }
+
+  public void validate() throws org.apache.thrift.TException {
+    // check for required fields
+    if (!isSetStatus()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'status' is unset! Struct:" + toString());
+    }
+
+    // check for sub-struct validity
+    if (status != null) {
+      status.validate();
+    }
+  }
+
+  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+    try {
+      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+    try {
+      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private static class TSentryImportMappingDataResponseStandardSchemeFactory implements SchemeFactory {
+    public TSentryImportMappingDataResponseStandardScheme getScheme() {
+      return new TSentryImportMappingDataResponseStandardScheme();
+    }
+  }
+
+  private static class TSentryImportMappingDataResponseStandardScheme extends StandardScheme<TSentryImportMappingDataResponse> {
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot, TSentryImportMappingDataResponse struct) throws org.apache.thrift.TException {
+      org.apache.thrift.protocol.TField schemeField;
+      iprot.readStructBegin();
+      while (true)
+      {
+        schemeField = iprot.readFieldBegin();
+        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+          break;
+        }
+        switch (schemeField.id) {
+          case 1: // STATUS
+            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+              struct.status = new org.apache.sentry.service.thrift.TSentryResponseStatus();
+              struct.status.read(iprot);
+              struct.setStatusIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          default:
+            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+        }
+        iprot.readFieldEnd();
+      }
+      iprot.readStructEnd();
+      struct.validate();
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot, TSentryImportMappingDataResponse struct) throws org.apache.thrift.TException {
+      struct.validate();
+
+      oprot.writeStructBegin(STRUCT_DESC);
+      if (struct.status != null) {
+        oprot.writeFieldBegin(STATUS_FIELD_DESC);
+        struct.status.write(oprot);
+        oprot.writeFieldEnd();
+      }
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+
+  }
+
+  private static class TSentryImportMappingDataResponseTupleSchemeFactory implements SchemeFactory {
+    public TSentryImportMappingDataResponseTupleScheme getScheme() {
+      return new TSentryImportMappingDataResponseTupleScheme();
+    }
+  }
+
+  private static class TSentryImportMappingDataResponseTupleScheme extends TupleScheme<TSentryImportMappingDataResponse> {
+
+    @Override
+    public void write(org.apache.thrift.protocol.TProtocol prot, TSentryImportMappingDataResponse struct) throws org.apache.thrift.TException {
+      TTupleProtocol oprot = (TTupleProtocol) prot;
+      struct.status.write(oprot);
+    }
+
+    @Override
+    public void read(org.apache.thrift.protocol.TProtocol prot, TSentryImportMappingDataResponse struct) throws org.apache.thrift.TException {
+      TTupleProtocol iprot = (TTupleProtocol) prot;
+      struct.status = new org.apache.sentry.service.thrift.TSentryResponseStatus();
+      struct.status.read(iprot);
+      struct.setStatusIsSet(true);
+    }
+  }
+
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryMappingData.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryMappingData.java b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryMappingData.java
new file mode 100644
index 0000000..05d1dd4
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryMappingData.java
@@ -0,0 +1,695 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.0)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ *  @generated
+ */
+package org.apache.sentry.provider.db.service.thrift;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.thrift.scheme.IScheme;
+import org.apache.thrift.scheme.SchemeFactory;
+import org.apache.thrift.scheme.StandardScheme;
+
+import org.apache.thrift.scheme.TupleScheme;
+import org.apache.thrift.protocol.TTupleProtocol;
+import org.apache.thrift.protocol.TProtocolException;
+import org.apache.thrift.EncodingUtils;
+import org.apache.thrift.TException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.EnumMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.EnumSet;
+import java.util.Collections;
+import java.util.BitSet;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TSentryMappingData implements org.apache.thrift.TBase<TSentryMappingData, TSentryMappingData._Fields>, java.io.Serializable, Cloneable {
+  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSentryMappingData");
+
+  private static final org.apache.thrift.protocol.TField GROUP_ROLES_MAP_FIELD_DESC = new org.apache.thrift.protocol.TField("groupRolesMap", org.apache.thrift.protocol.TType.MAP, (short)1);
+  private static final org.apache.thrift.protocol.TField ROLE_PRIVILEGES_MAP_FIELD_DESC = new org.apache.thrift.protocol.TField("rolePrivilegesMap", org.apache.thrift.protocol.TType.MAP, (short)2);
+
+  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+  static {
+    schemes.put(StandardScheme.class, new TSentryMappingDataStandardSchemeFactory());
+    schemes.put(TupleScheme.class, new TSentryMappingDataTupleSchemeFactory());
+  }
+
+  private Map<String,Set<String>> groupRolesMap; // optional
+  private Map<String,Set<TSentryPrivilege>> rolePrivilegesMap; // optional
+
+  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+    GROUP_ROLES_MAP((short)1, "groupRolesMap"),
+    ROLE_PRIVILEGES_MAP((short)2, "rolePrivilegesMap");
+
+    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+    static {
+      for (_Fields field : EnumSet.allOf(_Fields.class)) {
+        byName.put(field.getFieldName(), field);
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, or null if its not found.
+     */
+    public static _Fields findByThriftId(int fieldId) {
+      switch(fieldId) {
+        case 1: // GROUP_ROLES_MAP
+          return GROUP_ROLES_MAP;
+        case 2: // ROLE_PRIVILEGES_MAP
+          return ROLE_PRIVILEGES_MAP;
+        default:
+          return null;
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, throwing an exception
+     * if it is not found.
+     */
+    public static _Fields findByThriftIdOrThrow(int fieldId) {
+      _Fields fields = findByThriftId(fieldId);
+      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+      return fields;
+    }
+
+    /**
+     * Find the _Fields constant that matches name, or null if its not found.
+     */
+    public static _Fields findByName(String name) {
+      return byName.get(name);
+    }
+
+    private final short _thriftId;
+    private final String _fieldName;
+
+    _Fields(short thriftId, String fieldName) {
+      _thriftId = thriftId;
+      _fieldName = fieldName;
+    }
+
+    public short getThriftFieldId() {
+      return _thriftId;
+    }
+
+    public String getFieldName() {
+      return _fieldName;
+    }
+  }
+
+  // isset id assignments
+  private _Fields optionals[] = {_Fields.GROUP_ROLES_MAP,_Fields.ROLE_PRIVILEGES_MAP};
+  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+  static {
+    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+    tmpMap.put(_Fields.GROUP_ROLES_MAP, new org.apache.thrift.meta_data.FieldMetaData("groupRolesMap", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
+        new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, 
+            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), 
+            new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, 
+                new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))));
+    tmpMap.put(_Fields.ROLE_PRIVILEGES_MAP, new org.apache.thrift.meta_data.FieldMetaData("rolePrivilegesMap", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
+        new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, 
+            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), 
+            new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, 
+                new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TSentryPrivilege.class)))));
+    metaDataMap = Collections.unmodifiableMap(tmpMap);
+    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSentryMappingData.class, metaDataMap);
+  }
+
+  public TSentryMappingData() {
+  }
+
+  /**
+   * Performs a deep copy on <i>other</i>.
+   */
+  public TSentryMappingData(TSentryMappingData other) {
+    if (other.isSetGroupRolesMap()) {
+      Map<String,Set<String>> __this__groupRolesMap = new HashMap<String,Set<String>>();
+      for (Map.Entry<String, Set<String>> other_element : other.groupRolesMap.entrySet()) {
+
+        String other_element_key = other_element.getKey();
+        Set<String> other_element_value = other_element.getValue();
+
+        String __this__groupRolesMap_copy_key = other_element_key;
+
+        Set<String> __this__groupRolesMap_copy_value = new HashSet<String>();
+        for (String other_element_value_element : other_element_value) {
+          __this__groupRolesMap_copy_value.add(other_element_value_element);
+        }
+
+        __this__groupRolesMap.put(__this__groupRolesMap_copy_key, __this__groupRolesMap_copy_value);
+      }
+      this.groupRolesMap = __this__groupRolesMap;
+    }
+    if (other.isSetRolePrivilegesMap()) {
+      Map<String,Set<TSentryPrivilege>> __this__rolePrivilegesMap = new HashMap<String,Set<TSentryPrivilege>>();
+      for (Map.Entry<String, Set<TSentryPrivilege>> other_element : other.rolePrivilegesMap.entrySet()) {
+
+        String other_element_key = other_element.getKey();
+        Set<TSentryPrivilege> other_element_value = other_element.getValue();
+
+        String __this__rolePrivilegesMap_copy_key = other_element_key;
+
+        Set<TSentryPrivilege> __this__rolePrivilegesMap_copy_value = new HashSet<TSentryPrivilege>();
+        for (TSentryPrivilege other_element_value_element : other_element_value) {
+          __this__rolePrivilegesMap_copy_value.add(new TSentryPrivilege(other_element_value_element));
+        }
+
+        __this__rolePrivilegesMap.put(__this__rolePrivilegesMap_copy_key, __this__rolePrivilegesMap_copy_value);
+      }
+      this.rolePrivilegesMap = __this__rolePrivilegesMap;
+    }
+  }
+
+  public TSentryMappingData deepCopy() {
+    return new TSentryMappingData(this);
+  }
+
+  @Override
+  public void clear() {
+    this.groupRolesMap = null;
+    this.rolePrivilegesMap = null;
+  }
+
+  public int getGroupRolesMapSize() {
+    return (this.groupRolesMap == null) ? 0 : this.groupRolesMap.size();
+  }
+
+  public void putToGroupRolesMap(String key, Set<String> val) {
+    if (this.groupRolesMap == null) {
+      this.groupRolesMap = new HashMap<String,Set<String>>();
+    }
+    this.groupRolesMap.put(key, val);
+  }
+
+  public Map<String,Set<String>> getGroupRolesMap() {
+    return this.groupRolesMap;
+  }
+
+  public void setGroupRolesMap(Map<String,Set<String>> groupRolesMap) {
+    this.groupRolesMap = groupRolesMap;
+  }
+
+  public void unsetGroupRolesMap() {
+    this.groupRolesMap = null;
+  }
+
+  /** Returns true if field groupRolesMap is set (has been assigned a value) and false otherwise */
+  public boolean isSetGroupRolesMap() {
+    return this.groupRolesMap != null;
+  }
+
+  public void setGroupRolesMapIsSet(boolean value) {
+    if (!value) {
+      this.groupRolesMap = null;
+    }
+  }
+
+  public int getRolePrivilegesMapSize() {
+    return (this.rolePrivilegesMap == null) ? 0 : this.rolePrivilegesMap.size();
+  }
+
+  public void putToRolePrivilegesMap(String key, Set<TSentryPrivilege> val) {
+    if (this.rolePrivilegesMap == null) {
+      this.rolePrivilegesMap = new HashMap<String,Set<TSentryPrivilege>>();
+    }
+    this.rolePrivilegesMap.put(key, val);
+  }
+
+  public Map<String,Set<TSentryPrivilege>> getRolePrivilegesMap() {
+    return this.rolePrivilegesMap;
+  }
+
+  public void setRolePrivilegesMap(Map<String,Set<TSentryPrivilege>> rolePrivilegesMap) {
+    this.rolePrivilegesMap = rolePrivilegesMap;
+  }
+
+  public void unsetRolePrivilegesMap() {
+    this.rolePrivilegesMap = null;
+  }
+
+  /** Returns true if field rolePrivilegesMap is set (has been assigned a value) and false otherwise */
+  public boolean isSetRolePrivilegesMap() {
+    return this.rolePrivilegesMap != null;
+  }
+
+  public void setRolePrivilegesMapIsSet(boolean value) {
+    if (!value) {
+      this.rolePrivilegesMap = null;
+    }
+  }
+
+  public void setFieldValue(_Fields field, Object value) {
+    switch (field) {
+    case GROUP_ROLES_MAP:
+      if (value == null) {
+        unsetGroupRolesMap();
+      } else {
+        setGroupRolesMap((Map<String,Set<String>>)value);
+      }
+      break;
+
+    case ROLE_PRIVILEGES_MAP:
+      if (value == null) {
+        unsetRolePrivilegesMap();
+      } else {
+        setRolePrivilegesMap((Map<String,Set<TSentryPrivilege>>)value);
+      }
+      break;
+
+    }
+  }
+
+  public Object getFieldValue(_Fields field) {
+    switch (field) {
+    case GROUP_ROLES_MAP:
+      return getGroupRolesMap();
+
+    case ROLE_PRIVILEGES_MAP:
+      return getRolePrivilegesMap();
+
+    }
+    throw new IllegalStateException();
+  }
+
+  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+  public boolean isSet(_Fields field) {
+    if (field == null) {
+      throw new IllegalArgumentException();
+    }
+
+    switch (field) {
+    case GROUP_ROLES_MAP:
+      return isSetGroupRolesMap();
+    case ROLE_PRIVILEGES_MAP:
+      return isSetRolePrivilegesMap();
+    }
+    throw new IllegalStateException();
+  }
+
+  @Override
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof TSentryMappingData)
+      return this.equals((TSentryMappingData)that);
+    return false;
+  }
+
+  public boolean equals(TSentryMappingData that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_groupRolesMap = true && this.isSetGroupRolesMap();
+    boolean that_present_groupRolesMap = true && that.isSetGroupRolesMap();
+    if (this_present_groupRolesMap || that_present_groupRolesMap) {
+      if (!(this_present_groupRolesMap && that_present_groupRolesMap))
+        return false;
+      if (!this.groupRolesMap.equals(that.groupRolesMap))
+        return false;
+    }
+
+    boolean this_present_rolePrivilegesMap = true && this.isSetRolePrivilegesMap();
+    boolean that_present_rolePrivilegesMap = true && that.isSetRolePrivilegesMap();
+    if (this_present_rolePrivilegesMap || that_present_rolePrivilegesMap) {
+      if (!(this_present_rolePrivilegesMap && that_present_rolePrivilegesMap))
+        return false;
+      if (!this.rolePrivilegesMap.equals(that.rolePrivilegesMap))
+        return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    HashCodeBuilder builder = new HashCodeBuilder();
+
+    boolean present_groupRolesMap = true && (isSetGroupRolesMap());
+    builder.append(present_groupRolesMap);
+    if (present_groupRolesMap)
+      builder.append(groupRolesMap);
+
+    boolean present_rolePrivilegesMap = true && (isSetRolePrivilegesMap());
+    builder.append(present_rolePrivilegesMap);
+    if (present_rolePrivilegesMap)
+      builder.append(rolePrivilegesMap);
+
+    return builder.toHashCode();
+  }
+
+  public int compareTo(TSentryMappingData other) {
+    if (!getClass().equals(other.getClass())) {
+      return getClass().getName().compareTo(other.getClass().getName());
+    }
+
+    int lastComparison = 0;
+    TSentryMappingData typedOther = (TSentryMappingData)other;
+
+    lastComparison = Boolean.valueOf(isSetGroupRolesMap()).compareTo(typedOther.isSetGroupRolesMap());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetGroupRolesMap()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.groupRolesMap, typedOther.groupRolesMap);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    lastComparison = Boolean.valueOf(isSetRolePrivilegesMap()).compareTo(typedOther.isSetRolePrivilegesMap());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetRolePrivilegesMap()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.rolePrivilegesMap, typedOther.rolePrivilegesMap);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    return 0;
+  }
+
+  public _Fields fieldForId(int fieldId) {
+    return _Fields.findByThriftId(fieldId);
+  }
+
+  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+  }
+
+  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("TSentryMappingData(");
+    boolean first = true;
+
+    if (isSetGroupRolesMap()) {
+      sb.append("groupRolesMap:");
+      if (this.groupRolesMap == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.groupRolesMap);
+      }
+      first = false;
+    }
+    if (isSetRolePrivilegesMap()) {
+      if (!first) sb.append(", ");
+      sb.append("rolePrivilegesMap:");
+      if (this.rolePrivilegesMap == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.rolePrivilegesMap);
+      }
+      first = false;
+    }
+    sb.append(")");
+    return sb.toString();
+  }
+
+  public void validate() throws org.apache.thrift.TException {
+    // check for required fields
+    // check for sub-struct validity
+  }
+
+  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+    try {
+      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+    try {
+      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private static class TSentryMappingDataStandardSchemeFactory implements SchemeFactory {
+    public TSentryMappingDataStandardScheme getScheme() {
+      return new TSentryMappingDataStandardScheme();
+    }
+  }
+
+  private static class TSentryMappingDataStandardScheme extends StandardScheme<TSentryMappingData> {
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot, TSentryMappingData struct) throws org.apache.thrift.TException {
+      org.apache.thrift.protocol.TField schemeField;
+      iprot.readStructBegin();
+      while (true)
+      {
+        schemeField = iprot.readFieldBegin();
+        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+          break;
+        }
+        switch (schemeField.id) {
+          case 1: // GROUP_ROLES_MAP
+            if (schemeField.type == org.apache.thrift.protocol.TType.MAP) {
+              {
+                org.apache.thrift.protocol.TMap _map132 = iprot.readMapBegin();
+                struct.groupRolesMap = new HashMap<String,Set<String>>(2*_map132.size);
+                for (int _i133 = 0; _i133 < _map132.size; ++_i133)
+                {
+                  String _key134; // required
+                  Set<String> _val135; // required
+                  _key134 = iprot.readString();
+                  {
+                    org.apache.thrift.protocol.TSet _set136 = iprot.readSetBegin();
+                    _val135 = new HashSet<String>(2*_set136.size);
+                    for (int _i137 = 0; _i137 < _set136.size; ++_i137)
+                    {
+                      String _elem138; // required
+                      _elem138 = iprot.readString();
+                      _val135.add(_elem138);
+                    }
+                    iprot.readSetEnd();
+                  }
+                  struct.groupRolesMap.put(_key134, _val135);
+                }
+                iprot.readMapEnd();
+              }
+              struct.setGroupRolesMapIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          case 2: // ROLE_PRIVILEGES_MAP
+            if (schemeField.type == org.apache.thrift.protocol.TType.MAP) {
+              {
+                org.apache.thrift.protocol.TMap _map139 = iprot.readMapBegin();
+                struct.rolePrivilegesMap = new HashMap<String,Set<TSentryPrivilege>>(2*_map139.size);
+                for (int _i140 = 0; _i140 < _map139.size; ++_i140)
+                {
+                  String _key141; // required
+                  Set<TSentryPrivilege> _val142; // required
+                  _key141 = iprot.readString();
+                  {
+                    org.apache.thrift.protocol.TSet _set143 = iprot.readSetBegin();
+                    _val142 = new HashSet<TSentryPrivilege>(2*_set143.size);
+                    for (int _i144 = 0; _i144 < _set143.size; ++_i144)
+                    {
+                      TSentryPrivilege _elem145; // required
+                      _elem145 = new TSentryPrivilege();
+                      _elem145.read(iprot);
+                      _val142.add(_elem145);
+                    }
+                    iprot.readSetEnd();
+                  }
+                  struct.rolePrivilegesMap.put(_key141, _val142);
+                }
+                iprot.readMapEnd();
+              }
+              struct.setRolePrivilegesMapIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          default:
+            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+        }
+        iprot.readFieldEnd();
+      }
+      iprot.readStructEnd();
+      struct.validate();
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot, TSentryMappingData struct) throws org.apache.thrift.TException {
+      struct.validate();
+
+      oprot.writeStructBegin(STRUCT_DESC);
+      if (struct.groupRolesMap != null) {
+        if (struct.isSetGroupRolesMap()) {
+          oprot.writeFieldBegin(GROUP_ROLES_MAP_FIELD_DESC);
+          {
+            oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.SET, struct.groupRolesMap.size()));
+            for (Map.Entry<String, Set<String>> _iter146 : struct.groupRolesMap.entrySet())
+            {
+              oprot.writeString(_iter146.getKey());
+              {
+                oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRING, _iter146.getValue().size()));
+                for (String _iter147 : _iter146.getValue())
+                {
+                  oprot.writeString(_iter147);
+                }
+                oprot.writeSetEnd();
+              }
+            }
+            oprot.writeMapEnd();
+          }
+          oprot.writeFieldEnd();
+        }
+      }
+      if (struct.rolePrivilegesMap != null) {
+        if (struct.isSetRolePrivilegesMap()) {
+          oprot.writeFieldBegin(ROLE_PRIVILEGES_MAP_FIELD_DESC);
+          {
+            oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.SET, struct.rolePrivilegesMap.size()));
+            for (Map.Entry<String, Set<TSentryPrivilege>> _iter148 : struct.rolePrivilegesMap.entrySet())
+            {
+              oprot.writeString(_iter148.getKey());
+              {
+                oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, _iter148.getValue().size()));
+                for (TSentryPrivilege _iter149 : _iter148.getValue())
+                {
+                  _iter149.write(oprot);
+                }
+                oprot.writeSetEnd();
+              }
+            }
+            oprot.writeMapEnd();
+          }
+          oprot.writeFieldEnd();
+        }
+      }
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+
+  }
+
+  private static class TSentryMappingDataTupleSchemeFactory implements SchemeFactory {
+    public TSentryMappingDataTupleScheme getScheme() {
+      return new TSentryMappingDataTupleScheme();
+    }
+  }
+
+  private static class TSentryMappingDataTupleScheme extends TupleScheme<TSentryMappingData> {
+
+    @Override
+    public void write(org.apache.thrift.protocol.TProtocol prot, TSentryMappingData struct) throws org.apache.thrift.TException {
+      TTupleProtocol oprot = (TTupleProtocol) prot;
+      BitSet optionals = new BitSet();
+      if (struct.isSetGroupRolesMap()) {
+        optionals.set(0);
+      }
+      if (struct.isSetRolePrivilegesMap()) {
+        optionals.set(1);
+      }
+      oprot.writeBitSet(optionals, 2);
+      if (struct.isSetGroupRolesMap()) {
+        {
+          oprot.writeI32(struct.groupRolesMap.size());
+          for (Map.Entry<String, Set<String>> _iter150 : struct.groupRolesMap.entrySet())
+          {
+            oprot.writeString(_iter150.getKey());
+            {
+              oprot.writeI32(_iter150.getValue().size());
+              for (String _iter151 : _iter150.getValue())
+              {
+                oprot.writeString(_iter151);
+              }
+            }
+          }
+        }
+      }
+      if (struct.isSetRolePrivilegesMap()) {
+        {
+          oprot.writeI32(struct.rolePrivilegesMap.size());
+          for (Map.Entry<String, Set<TSentryPrivilege>> _iter152 : struct.rolePrivilegesMap.entrySet())
+          {
+            oprot.writeString(_iter152.getKey());
+            {
+              oprot.writeI32(_iter152.getValue().size());
+              for (TSentryPrivilege _iter153 : _iter152.getValue())
+              {
+                _iter153.write(oprot);
+              }
+            }
+          }
+        }
+      }
+    }
+
+    @Override
+    public void read(org.apache.thrift.protocol.TProtocol prot, TSentryMappingData struct) throws org.apache.thrift.TException {
+      TTupleProtocol iprot = (TTupleProtocol) prot;
+      BitSet incoming = iprot.readBitSet(2);
+      if (incoming.get(0)) {
+        {
+          org.apache.thrift.protocol.TMap _map154 = new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.SET, iprot.readI32());
+          struct.groupRolesMap = new HashMap<String,Set<String>>(2*_map154.size);
+          for (int _i155 = 0; _i155 < _map154.size; ++_i155)
+          {
+            String _key156; // required
+            Set<String> _val157; // required
+            _key156 = iprot.readString();
+            {
+              org.apache.thrift.protocol.TSet _set158 = new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRING, iprot.readI32());
+              _val157 = new HashSet<String>(2*_set158.size);
+              for (int _i159 = 0; _i159 < _set158.size; ++_i159)
+              {
+                String _elem160; // required
+                _elem160 = iprot.readString();
+                _val157.add(_elem160);
+              }
+            }
+            struct.groupRolesMap.put(_key156, _val157);
+          }
+        }
+        struct.setGroupRolesMapIsSet(true);
+      }
+      if (incoming.get(1)) {
+        {
+          org.apache.thrift.protocol.TMap _map161 = new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.SET, iprot.readI32());
+          struct.rolePrivilegesMap = new HashMap<String,Set<TSentryPrivilege>>(2*_map161.size);
+          for (int _i162 = 0; _i162 < _map161.size; ++_i162)
+          {
+            String _key163; // required
+            Set<TSentryPrivilege> _val164; // required
+            _key163 = iprot.readString();
+            {
+              org.apache.thrift.protocol.TSet _set165 = new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
+              _val164 = new HashSet<TSentryPrivilege>(2*_set165.size);
+              for (int _i166 = 0; _i166 < _set165.size; ++_i166)
+              {
+                TSentryPrivilege _elem167; // required
+                _elem167 = new TSentryPrivilege();
+                _elem167.read(iprot);
+                _val164.add(_elem167);
+              }
+            }
+            struct.rolePrivilegesMap.put(_key163, _val164);
+          }
+        }
+        struct.setRolePrivilegesMapIsSet(true);
+      }
+    }
+  }
+
+}
+


[3/6] incubator-sentry git commit: SENTRY-197: Create tool to dump and load of entire Sentry service (Colin Ma, Reviewed by:Sravya Tirukkovalur, Guoquan Shen, Dapeng Sun, Anne Yu)

Posted by co...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
index 81adec2..fbb611e 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/persistent/SentryStore.java
@@ -65,6 +65,7 @@ import org.apache.sentry.provider.db.service.thrift.TSentryActiveRoleSet;
 import org.apache.sentry.provider.db.service.thrift.TSentryAuthorizable;
 import org.apache.sentry.provider.db.service.thrift.TSentryGrantOption;
 import org.apache.sentry.provider.db.service.thrift.TSentryGroup;
+import org.apache.sentry.provider.db.service.thrift.TSentryMappingData;
 import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege;
 import org.apache.sentry.provider.db.service.thrift.TSentryPrivilegeMap;
 import org.apache.sentry.provider.db.service.thrift.TSentryRole;
@@ -76,9 +77,11 @@ import org.slf4j.LoggerFactory;
 
 import com.codahale.metrics.Gauge;
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
 import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -310,16 +313,10 @@ public class SentryStore {
     PersistenceManager pm = null;
     try {
       pm = openTransaction();
-      MSentryRole mSentryRole = getMSentryRole(pm, roleName);
-      if (mSentryRole == null) {
-        MSentryRole mRole = new MSentryRole(roleName, System.currentTimeMillis());
-        pm.makePersistent(mRole);
-        CommitContext commit = commitUpdateTransaction(pm);
-        rollbackTransaction = false;
-        return commit;
-      } else {
-        throw new SentryAlreadyExistsException("Role: " + roleName);
-      }
+      createSentryRoleCore(pm, roleName);
+      CommitContext commit = commitUpdateTransaction(pm);
+      rollbackTransaction = false;
+      return commit;
     } finally {
       if (rollbackTransaction) {
         rollbackTransaction(pm);
@@ -327,6 +324,17 @@ public class SentryStore {
     }
   }
 
+  private void createSentryRoleCore(PersistenceManager pm, String roleName)
+      throws SentryAlreadyExistsException {
+    MSentryRole mSentryRole = getMSentryRole(pm, roleName);
+    if (mSentryRole == null) {
+      MSentryRole mRole = new MSentryRole(roleName, System.currentTimeMillis());
+      pm.makePersistent(mRole);
+    } else {
+      throw new SentryAlreadyExistsException("Role: " + roleName);
+    }
+  }
+
   private <T> Long getCount(Class<T> tClass) {
     PersistenceManager pm = null;
     Long size = new Long(-1);
@@ -444,7 +452,8 @@ public class SentryStore {
           || (!isNULL(privilege.getDbName()))) {
         // If Grant is for ALL and Either INSERT/SELECT already exists..
         // need to remove it and GRANT ALL..
-        if (privilege.getAction().equalsIgnoreCase("*")) {
+        if (AccessConstants.ALL.equalsIgnoreCase(privilege.getAction())
+            || AccessConstants.ACTION_ALL.equalsIgnoreCase(privilege.getAction())) {
           TSentryPrivilege tNotAll = new TSentryPrivilege(privilege);
           tNotAll.setAction(AccessConstants.SELECT);
           MSentryPrivilege mSelect = getMSentryPrivilege(tNotAll, pm);
@@ -465,8 +474,13 @@ public class SentryStore {
           // do nothing..
           TSentryPrivilege tAll = new TSentryPrivilege(privilege);
           tAll.setAction(AccessConstants.ALL);
-          MSentryPrivilege mAll = getMSentryPrivilege(tAll, pm);
-          if ((mAll != null) && (mRole.getPrivileges().contains(mAll))) {
+          MSentryPrivilege mAll1 = getMSentryPrivilege(tAll, pm);
+          tAll.setAction(AccessConstants.ACTION_ALL);
+          MSentryPrivilege mAll2 = getMSentryPrivilege(tAll, pm);
+          if ((mAll1 != null) && (mRole.getPrivileges().contains(mAll1))) {
+            return null;
+          }
+          if ((mAll2 != null) && (mRole.getPrivileges().contains(mAll2))) {
             return null;
           }
         }
@@ -763,25 +777,9 @@ public class SentryStore {
       throws SentryNoSuchObjectException {
     boolean rollbackTransaction = true;
     PersistenceManager pm = null;
-    roleName = roleName.trim().toLowerCase();
     try {
       pm = openTransaction();
-      Query query = pm.newQuery(MSentryRole.class);
-      query.setFilter("this.roleName == t");
-      query.declareParameters("java.lang.String t");
-      query.setUnique(true);
-      MSentryRole sentryRole = (MSentryRole) query.execute(roleName);
-      if (sentryRole == null) {
-        throw new SentryNoSuchObjectException("Role " + roleName);
-      } else {
-        pm.retrieve(sentryRole);
-        int numPrivs = sentryRole.getPrivileges().size();
-        sentryRole.removePrivileges();
-        //with SENTRY-398 generic model
-        sentryRole.removeGMPrivileges();
-        privCleaner.incPrivRemoval(numPrivs);
-        pm.deletePersistent(sentryRole);
-      }
+      dropSentryRoleCore(pm, roleName);
       CommitContext commit = commitUpdateTransaction(pm);
       rollbackTransaction = false;
       return commit;
@@ -792,42 +790,38 @@ public class SentryStore {
     }
   }
 
+  private void dropSentryRoleCore(PersistenceManager pm, String roleName)
+      throws SentryNoSuchObjectException {
+    String lRoleName = roleName.trim().toLowerCase();
+    Query query = pm.newQuery(MSentryRole.class);
+    query.setFilter("this.roleName == t");
+    query.declareParameters("java.lang.String t");
+    query.setUnique(true);
+    MSentryRole sentryRole = (MSentryRole) query.execute(lRoleName);
+    if (sentryRole == null) {
+      throw new SentryNoSuchObjectException("Role " + lRoleName);
+    } else {
+      pm.retrieve(sentryRole);
+      int numPrivs = sentryRole.getPrivileges().size();
+      sentryRole.removePrivileges();
+      // with SENTRY-398 generic model
+      sentryRole.removeGMPrivileges();
+      privCleaner.incPrivRemoval(numPrivs);
+      pm.deletePersistent(sentryRole);
+    }
+  }
+
   public CommitContext alterSentryRoleAddGroups( String grantorPrincipal, String roleName,
       Set<TSentryGroup> groupNames)
           throws SentryNoSuchObjectException {
     boolean rollbackTransaction = true;
     PersistenceManager pm = null;
-    roleName = roleName.trim().toLowerCase();
     try {
       pm = openTransaction();
-      Query query = pm.newQuery(MSentryRole.class);
-      query.setFilter("this.roleName == t");
-      query.declareParameters("java.lang.String t");
-      query.setUnique(true);
-      MSentryRole role = (MSentryRole) query.execute(roleName);
-      if (role == null) {
-        throw new SentryNoSuchObjectException("Role: " + roleName);
-      } else {
-        query = pm.newQuery(MSentryGroup.class);
-        query.setFilter("this.groupName == t");
-        query.declareParameters("java.lang.String t");
-        query.setUnique(true);
-        List<MSentryGroup> groups = Lists.newArrayList();
-        for (TSentryGroup tGroup : groupNames) {
-          String groupName = tGroup.getGroupName().trim();
-          MSentryGroup group = (MSentryGroup) query.execute(groupName);
-          if (group == null) {
-            group = new MSentryGroup(groupName, System.currentTimeMillis(),
-                 Sets.newHashSet(role));
-          }
-          group.appendRole(role);
-          groups.add(group);
-        }
-        pm.makePersistentAll(groups);
-        CommitContext commit = commitUpdateTransaction(pm);
-        rollbackTransaction = false;
-        return commit;
-      }
+      alterSentryRoleAddGroupsCore(pm, roleName, groupNames);
+      CommitContext commit = commitUpdateTransaction(pm);
+      rollbackTransaction = false;
+      return commit;
     } finally {
       if (rollbackTransaction) {
         rollbackTransaction(pm);
@@ -835,6 +829,35 @@ public class SentryStore {
     }
   }
 
+  private void alterSentryRoleAddGroupsCore(PersistenceManager pm, String roleName,
+      Set<TSentryGroup> groupNames) throws SentryNoSuchObjectException {
+    String lRoleName = roleName.trim().toLowerCase();
+    Query query = pm.newQuery(MSentryRole.class);
+    query.setFilter("this.roleName == t");
+    query.declareParameters("java.lang.String t");
+    query.setUnique(true);
+    MSentryRole role = (MSentryRole) query.execute(lRoleName);
+    if (role == null) {
+      throw new SentryNoSuchObjectException("Role: " + lRoleName);
+    } else {
+      query = pm.newQuery(MSentryGroup.class);
+      query.setFilter("this.groupName == t");
+      query.declareParameters("java.lang.String t");
+      query.setUnique(true);
+      List<MSentryGroup> groups = Lists.newArrayList();
+      for (TSentryGroup tGroup : groupNames) {
+        String groupName = tGroup.getGroupName().trim();
+        MSentryGroup group = (MSentryGroup) query.execute(groupName);
+        if (group == null) {
+          group = new MSentryGroup(groupName, System.currentTimeMillis(), Sets.newHashSet(role));
+        }
+        group.appendRole(role);
+        groups.add(group);
+      }
+      pm.makePersistentAll(groups);
+    }
+  }
+
   public CommitContext alterSentryRoleDeleteGroups(String roleName,
       Set<TSentryGroup> groupNames)
           throws SentryNoSuchObjectException {
@@ -1341,7 +1364,7 @@ public class SentryStore {
     return group;
   }
 
-  private TSentryPrivilege convertToTSentryPrivilege(MSentryPrivilege mSentryPrivilege) {
+  protected TSentryPrivilege convertToTSentryPrivilege(MSentryPrivilege mSentryPrivilege) {
     TSentryPrivilege privilege = new TSentryPrivilege();
     convertToTSentryPrivilege(mSentryPrivilege, privilege);
     return privilege;
@@ -1979,4 +2002,319 @@ public class SentryStore {
       }
     }
   }
+
+  // get all mapping data for [group,role]
+  public Map<String, Set<String>> getGroupNameRoleNamesMap() {
+    boolean rollbackTransaction = true;
+    PersistenceManager pm = null;
+    try {
+      pm = openTransaction();
+      Query query = pm.newQuery(MSentryGroup.class);
+      List<MSentryGroup> mSentryGroups = (List<MSentryGroup>) query.execute();
+      Map<String, Set<String>> sentryGroupNameRoleNamesMap = Maps.newHashMap();
+      if (mSentryGroups != null) {
+        // change the List<MSentryGroup> -> Map<groupName, Set<roleName>>
+        for (MSentryGroup mSentryGroup : mSentryGroups) {
+          String groupName = mSentryGroup.getGroupName();
+          Set<String> roleNames = Sets.newHashSet();
+          for (MSentryRole mSentryRole : mSentryGroup.getRoles()) {
+            roleNames.add(mSentryRole.getRoleName());
+          }
+          if (roleNames.size() > 0) {
+            sentryGroupNameRoleNamesMap.put(groupName, roleNames);
+          }
+        }
+      }
+      commitTransaction(pm);
+      rollbackTransaction = false;
+      return sentryGroupNameRoleNamesMap;
+    } finally {
+      if (rollbackTransaction) {
+        rollbackTransaction(pm);
+      }
+    }
+  }
+
+  // get all mapping data for [role,privilege]
+  public Map<String, Set<TSentryPrivilege>> getRoleNameTPrivilegesMap() throws Exception {
+    boolean rollbackTransaction = true;
+    PersistenceManager pm = null;
+    try {
+      pm = openTransaction();
+      Query query = pm.newQuery(MSentryRole.class);
+      List<MSentryRole> mSentryRoles = (List<MSentryRole>) query.execute();
+      Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap = Maps.newHashMap();
+      if (mSentryRoles != null) {
+        // change the List<MSentryRole> -> Map<roleName, Set<TSentryPrivilege>>
+        for (MSentryRole mSentryRole : mSentryRoles) {
+          Set<TSentryPrivilege> privilegeSet = convertToTSentryPrivileges(mSentryRole
+              .getPrivileges());
+          if (privilegeSet != null && !privilegeSet.isEmpty()) {
+            sentryRolePrivilegesMap.put(mSentryRole.getRoleName(), privilegeSet);
+          }
+        }
+      }
+      commitTransaction(pm);
+      rollbackTransaction = false;
+    return sentryRolePrivilegesMap;
+    } finally {
+      if (rollbackTransaction) {
+        rollbackTransaction(pm);
+      }
+    }
+  }
+
+  // get the all exist role names
+  private Set<String> getAllRoleNames(PersistenceManager pm) {
+    Query query = pm.newQuery(MSentryRole.class);
+    List<MSentryRole> mSentryRoles = (List<MSentryRole>) query.execute();
+    Set<String> existRoleNames = Sets.newHashSet();
+    if (mSentryRoles != null) {
+      for (MSentryRole mSentryRole : mSentryRoles) {
+        existRoleNames.add(mSentryRole.getRoleName());
+      }
+    }
+    return existRoleNames;
+  }
+
+  // get the all exist groups
+  private Map<String, MSentryGroup> getGroupNameTGroupMap(PersistenceManager pm) {
+    Query query = pm.newQuery(MSentryGroup.class);
+    List<MSentryGroup> mSentryGroups = (List<MSentryGroup>) query.execute();
+    Map<String, MSentryGroup> existGroupsMap = Maps.newHashMap();
+    if (mSentryGroups != null) {
+      // change the List<MSentryGroup> -> Map<roleName, Set<MSentryGroup>>
+      for (MSentryGroup mSentryGroup : mSentryGroups) {
+        existGroupsMap.put(mSentryGroup.getGroupName(), mSentryGroup);
+      }
+    }
+    return existGroupsMap;
+  }
+
+  // get the all exist privileges
+  private List<MSentryPrivilege> getPrivilegesList(PersistenceManager pm) {
+    Query query = pm.newQuery(MSentryPrivilege.class);
+    List<MSentryPrivilege> resultList = (List<MSentryPrivilege>) query.execute();
+    if (resultList == null) {
+      resultList = Lists.newArrayList();
+    }
+    return resultList;
+  }
+
+  @VisibleForTesting
+  protected Map<String, MSentryRole> getRolesMap() {
+    boolean rollbackTransaction = true;
+    PersistenceManager pm = null;
+    try {
+      pm = openTransaction();
+
+      Query query = pm.newQuery(MSentryRole.class);
+      List<MSentryRole> mSentryRoles = (List<MSentryRole>) query.execute();
+      Map<String, MSentryRole> existRolesMap = Maps.newHashMap();
+      if (mSentryRoles != null) {
+        // change the List<MSentryRole> -> Map<roleName, Set<MSentryRole>>
+        for (MSentryRole mSentryRole : mSentryRoles) {
+          existRolesMap.put(mSentryRole.getRoleName(), mSentryRole);
+        }
+      }
+
+      commitTransaction(pm);
+      rollbackTransaction = false;
+      return existRolesMap;
+    } finally {
+      if (rollbackTransaction) {
+        rollbackTransaction(pm);
+      }
+    }
+  }
+
+  @VisibleForTesting
+  protected Map<String, MSentryGroup> getGroupNameTGroupMap() {
+    boolean rollbackTransaction = true;
+    PersistenceManager pm = null;
+    try {
+      pm = openTransaction();
+      Map<String, MSentryGroup> resultMap = getGroupNameTGroupMap(pm);
+      commitTransaction(pm);
+      rollbackTransaction = false;
+      return resultMap;
+    } finally {
+      if (rollbackTransaction) {
+        rollbackTransaction(pm);
+      }
+    }
+  }
+
+  @VisibleForTesting
+  protected List<MSentryPrivilege> getPrivilegesList() {
+    boolean rollbackTransaction = true;
+    PersistenceManager pm = null;
+    try {
+      pm = openTransaction();
+      List<MSentryPrivilege> resultList = getPrivilegesList(pm);
+      commitTransaction(pm);
+      rollbackTransaction = false;
+      return resultList;
+    } finally {
+      if (rollbackTransaction) {
+        rollbackTransaction(pm);
+      }
+    }
+  }
+
+  /**
+   * Import the sentry mapping data.
+   * 
+   * @param tSentryMappingData
+   *        Include 2 maps to save the mapping data, the following is the example of the data
+   *        structure:
+   *        for the following mapping data:
+   *        group1=role1,role2
+   *        group2=role2,role3
+   *        role1=server=server1->db=db1
+   *        role2=server=server1->db=db1->table=tbl1,server=server1->db=db1->table=tbl2
+   *        role3=server=server1->url=hdfs://localhost/path
+   * 
+   *        The GroupRolesMap in TSentryMappingData will be saved as:
+   *        {
+   *        TSentryGroup(group1)={role1, role2},
+   *        TSentryGroup(group2)={role2, role3}
+   *        }
+   *        The RolePrivilegesMap in TSentryMappingData will be saved as:
+   *        {
+   *        role1={TSentryPrivilege(server=server1->db=db1)},
+   *        role2={TSentryPrivilege(server=server1->db=db1->table=tbl1),
+   *        TSentryPrivilege(server=server1->db=db1->table=tbl2)},
+   *        role3={TSentryPrivilege(server=server1->url=hdfs://localhost/path)}
+   *        }
+   * @param isOverwriteForRole
+   *        The option for merging or overwriting the existing data during import, true for
+   *        overwriting, false for merging
+   */
+  public void importSentryMetaData(TSentryMappingData tSentryMappingData, boolean isOverwriteForRole)
+      throws Exception {
+    boolean rollbackTransaction = true;
+    PersistenceManager pm = null;
+    // change all role name in lowercase
+    TSentryMappingData mappingData = lowercaseRoleName(tSentryMappingData);
+    try {
+      pm = openTransaction();
+      Set<String> existRoleNames = getAllRoleNames(pm);
+      //
+      Map<String, Set<TSentryGroup>> importedRoleGroupsMap = covertToRoleNameTGroupsMap(mappingData
+          .getGroupRolesMap());
+      Set<String> importedRoleNames = importedRoleGroupsMap.keySet();
+      // if import with overwrite role, drop the duplicated roles in current DB first.
+      if (isOverwriteForRole) {
+        dropDuplicatedRoleForImport(pm, existRoleNames, importedRoleNames);
+        // refresh the existRoleNames for the drop role
+        existRoleNames = getAllRoleNames(pm);
+      }
+
+      // import the mapping data for [role,privilege], the existRoleNames will be updated
+      importSentryRolePrivilegeMapping(pm, existRoleNames, mappingData.getRolePrivilegesMap());
+
+      importSentryGroupRoleMapping(pm, existRoleNames, importedRoleGroupsMap);
+
+      commitTransaction(pm);
+      rollbackTransaction = false;
+    } finally {
+      if (rollbackTransaction) {
+        rollbackTransaction(pm);
+      }
+    }
+  }
+
+  // covert the Map[group->roles] to Map[role->groups]
+  private Map<String, Set<TSentryGroup>> covertToRoleNameTGroupsMap(
+      Map<String, Set<String>> groupRolesMap) {
+    Map<String, Set<TSentryGroup>> roleGroupsMap = Maps.newHashMap();
+    if (groupRolesMap != null) {
+      for (String groupName : groupRolesMap.keySet()) {
+        Set<String> roleNames = groupRolesMap.get(groupName);
+        if (roleNames != null) {
+          for (String roleName : roleNames) {
+            Set<TSentryGroup> tSentryGroups = roleGroupsMap.get(roleName);
+            if (tSentryGroups == null) {
+              tSentryGroups = Sets.newHashSet();
+            }
+            tSentryGroups.add(new TSentryGroup(groupName));
+            roleGroupsMap.put(roleName, tSentryGroups);
+          }
+        }
+      }
+    }
+    return roleGroupsMap;
+  }
+
+  private void importSentryGroupRoleMapping(PersistenceManager pm, Set<String> existRoleNames,
+      Map<String, Set<TSentryGroup>> importedRoleGroupsMap) throws Exception {
+    if (importedRoleGroupsMap == null || importedRoleGroupsMap.keySet() == null) {
+      return;
+    }
+    for (String roleName : importedRoleGroupsMap.keySet()) {
+      if (!existRoleNames.contains(roleName)) {
+        createSentryRoleCore(pm, roleName);
+      }
+      alterSentryRoleAddGroupsCore(pm, roleName, importedRoleGroupsMap.get(roleName));
+    }
+  }
+
+  // drop all duplicated with the imported role
+  private void dropDuplicatedRoleForImport(PersistenceManager pm, Set<String> existRoleNames,
+      Set<String> importedRoleNames) throws Exception {
+    Set<String> duplicatedRoleNames = Sets.intersection(existRoleNames, importedRoleNames);
+    for (String droppedRoleName : duplicatedRoleNames) {
+      dropSentryRoleCore(pm, droppedRoleName);
+    }
+  }
+
+  // change all role name in lowercase
+  private TSentryMappingData lowercaseRoleName(TSentryMappingData tSentryMappingData) {
+    Map<String, Set<String>> sentryGroupRolesMap = tSentryMappingData.getGroupRolesMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap = tSentryMappingData
+        .getRolePrivilegesMap();
+
+    Map<String, Set<String>> newSentryGroupRolesMap = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> newSentryRolePrivilegesMap = Maps.newHashMap();
+    // for mapping data [group,role]
+    for (String groupName : sentryGroupRolesMap.keySet()) {
+      Collection<String> lowcaseRoles = Collections2.transform(sentryGroupRolesMap.get(groupName),
+          new Function<String, String>() {
+            @Override
+            public String apply(String input) {
+              return input.toString().toLowerCase();
+            }
+          });
+      newSentryGroupRolesMap.put(groupName, Sets.newHashSet(lowcaseRoles));
+    }
+
+    // for mapping data [role,privilege]
+    for (String roleName : sentryRolePrivilegesMap.keySet()) {
+      newSentryRolePrivilegesMap.put(roleName.toLowerCase(), sentryRolePrivilegesMap.get(roleName));
+    }
+
+    tSentryMappingData.setGroupRolesMap(newSentryGroupRolesMap);
+    tSentryMappingData.setRolePrivilegesMap(newSentryRolePrivilegesMap);
+    return tSentryMappingData;
+  }
+
+  // import the mapping data for [role,privilege]
+  private void importSentryRolePrivilegeMapping(PersistenceManager pm, Set<String> existRoleNames,
+      Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap) throws Exception {
+    if (sentryRolePrivilegesMap != null) {
+      for (String roleName : sentryRolePrivilegesMap.keySet()) {
+        // if the rolenName doesn't exist, create it.
+        if (!existRoleNames.contains(roleName)) {
+          createSentryRoleCore(pm, roleName);
+          existRoleNames.add(roleName);
+        }
+        // get the privileges for the role
+        Set<TSentryPrivilege> tSentryPrivileges = sentryRolePrivilegesMap.get(roleName);
+        for (TSentryPrivilege tSentryPrivilege : tSentryPrivileges) {
+          alterSentryRoleGrantPrivilegeCore(pm, roleName, tSentryPrivilege);
+        }
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
index 05cbfb6..9c2d384 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClient.java
@@ -178,4 +178,12 @@ public interface SentryPolicyServiceClient {
   public String getConfigValue(String propertyName, String defaultValue) throws SentryUserException;
 
   public void close();
+
+  // Import the sentry mapping data with map structure
+  public void importPolicy(Map<String, Map<String, Set<String>>> policyFileMappingData,
+      String requestorUserName, boolean isOverwriteRole) throws SentryUserException;
+
+  // export the sentry mapping data with map structure
+  public Map<String, Map<String, Set<String>>> exportPolicy(String requestorUserName)
+      throws SentryUserException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
index 533a28c..09b3d99 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyServiceClientDefaultImpl.java
@@ -27,6 +27,7 @@ import java.util.Set;
 
 import javax.security.auth.callback.CallbackHandler;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.security.SaslRpcServer;
@@ -38,6 +39,8 @@ import org.apache.sentry.core.common.ActiveRoleSet;
 import org.apache.sentry.core.common.Authorizable;
 import org.apache.sentry.core.model.db.AccessConstants;
 import org.apache.sentry.core.model.db.DBModelAuthorizable;
+import org.apache.sentry.provider.common.PolicyFileConstants;
+import org.apache.sentry.service.thrift.SentryServiceUtil;
 import org.apache.sentry.service.thrift.ServiceConstants.ClientConfig;
 import org.apache.sentry.service.thrift.ServiceConstants.PrivilegeScope;
 import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig;
@@ -58,6 +61,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
 public class SentryPolicyServiceClientDefaultImpl implements SentryPolicyServiceClient {
@@ -816,4 +820,111 @@ public class SentryPolicyServiceClientDefaultImpl implements SentryPolicyService
       transport.close();
     }
   }
+
+  /**
+   * Import the sentry mapping data, convert the mapping data from map structure to
+   * TSentryMappingData, and call the import API.
+   * 
+   * @param policyFileMappingData
+   *        Include 2 maps to save the mapping data, the following is the example of the data
+   *        structure:
+   *        for the following mapping data:
+   *        group1=role1,role2
+   *        group2=role2,role3
+   *        role1=server=server1->db=db1
+   *        role2=server=server1->db=db1->table=tbl1,server=server1->db=db1->table=tbl2
+   *        role3=server=server1->url=hdfs://localhost/path
+   * 
+   *        The policyFileMappingData will be inputed as:
+   *        {
+   *          groups={[group1={role1, role2}], group2=[role2, role3]},
+   *          roles={role1=[server=server1->db=db1],
+   *                 role2=[server=server1->db=db1->table=tbl1,server=server1->db=db1->table=tbl2],
+   *                 role3=[server=server1->url=hdfs://localhost/path]
+   *                }
+   *        }
+   * @param requestorUserName
+   *        The name of the request user
+   */
+  public void importPolicy(Map<String, Map<String, Set<String>>> policyFileMappingData,
+      String requestorUserName, boolean isOverwriteRole)
+      throws SentryUserException {
+    try {
+      TSentryMappingData tSentryMappingData = new TSentryMappingData();
+      // convert the mapping data for [group,role] from map structure to
+      // TSentryMappingData.GroupRolesMap
+      tSentryMappingData.setGroupRolesMap(policyFileMappingData.get(PolicyFileConstants.GROUPS));
+      // convert the mapping data for [role,privilege] from map structure to
+      // TSentryMappingData.RolePrivilegesMap
+      tSentryMappingData
+          .setRolePrivilegesMap(convertRolePrivilegesMapForSentryDB(policyFileMappingData
+              .get(PolicyFileConstants.ROLES)));
+      TSentryImportMappingDataRequest request = new TSentryImportMappingDataRequest(
+          ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT, requestorUserName, isOverwriteRole,
+          tSentryMappingData);
+      TSentryImportMappingDataResponse response = client.import_sentry_mapping_data(request);
+      Status.throwIfNotOk(response.getStatus());
+    } catch (TException e) {
+      throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e);
+    }
+  }
+
+  // convert the mapping data for [role,privilege] from map structure to
+  // TSentryMappingData.RolePrivilegesMap
+  private Map<String, Set<TSentryPrivilege>> convertRolePrivilegesMapForSentryDB(
+      Map<String, Set<String>> rolePrivilegesMap) {
+    Map<String, Set<TSentryPrivilege>> rolePrivilegesMapResult = Maps.newHashMap();
+    if (rolePrivilegesMap != null) {
+      for (String tempRoleName : rolePrivilegesMap.keySet()) {
+        Set<TSentryPrivilege> tempTSentryPrivileges = Sets.newHashSet();
+        Set<String> tempPrivileges = rolePrivilegesMap.get(tempRoleName);
+        for (String tempPrivilege : tempPrivileges) {
+          tempTSentryPrivileges.add(SentryServiceUtil.convertToTSentryPrivilege(tempPrivilege));
+        }
+        rolePrivilegesMapResult.put(tempRoleName, tempTSentryPrivileges);
+      }
+    }
+    return rolePrivilegesMapResult;
+  }
+
+  // export the sentry mapping data with map structure
+  public Map<String, Map<String, Set<String>>> exportPolicy(String requestorUserName)
+      throws SentryUserException {
+    TSentryExportMappingDataRequest request = new TSentryExportMappingDataRequest(
+        ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT, requestorUserName);
+    try {
+      TSentryExportMappingDataResponse response = client.export_sentry_mapping_data(request);
+      Status.throwIfNotOk(response.getStatus());
+      TSentryMappingData tSentryMappingData = response.getMappingData();
+      Map<String, Map<String, Set<String>>> resultMap = Maps.newHashMap();
+      resultMap.put(PolicyFileConstants.GROUPS, tSentryMappingData.getGroupRolesMap());
+      resultMap.put(PolicyFileConstants.ROLES,
+          convertRolePrivilegesMapForPolicyFile(tSentryMappingData.getRolePrivilegesMap()));
+      return resultMap;
+    } catch (TException e) {
+      throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e);
+    }
+  }
+
+  // convert the mapping data for [roleName,privilege] from TSentryMappingData.RolePrivilegesMap to
+  // map structure
+  private Map<String, Set<String>> convertRolePrivilegesMapForPolicyFile(
+      Map<String, Set<TSentryPrivilege>> rolePrivilegesMap) {
+    Map<String, Set<String>> rolePrivilegesMapForFile = Maps.newHashMap();
+    if (rolePrivilegesMap != null) {
+      for (String tempRoleName : rolePrivilegesMap.keySet()) {
+        Set<TSentryPrivilege> tempSentryPrivileges = rolePrivilegesMap.get(tempRoleName);
+        Set<String> tempStrPrivileges = Sets.newHashSet();
+        for (TSentryPrivilege tSentryPrivilege : tempSentryPrivileges) {
+          // convert TSentryPrivilege to privilege in string
+          String privilegeStr = SentryServiceUtil.convertTSentryPrivilegeToStr(tSentryPrivilege);
+          if (!StringUtils.isEmpty(privilegeStr)) {
+            tempStrPrivileges.add(privilegeStr);
+          }
+        }
+        rolePrivilegesMapForFile.put(tempRoleName, tempStrPrivileges);
+      }
+    }
+    return rolePrivilegesMapForFile;
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
index 406daa0..ea9fae9 100644
--- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/provider/db/service/thrift/SentryPolicyStoreProcessor.java
@@ -857,4 +857,57 @@ public class SentryPolicyStoreProcessor implements SentryPolicyService.Iface {
     }
   }
 
+  // get the sentry mapping data and return the data with map structure
+  @Override
+  public TSentryExportMappingDataResponse export_sentry_mapping_data(
+      TSentryExportMappingDataRequest request) throws TException {
+    TSentryExportMappingDataResponse response = new TSentryExportMappingDataResponse();
+    try {
+      String requestor = request.getRequestorUserName();
+      Set<String> memberGroups = getRequestorGroups(requestor);
+      if (!inAdminGroups(memberGroups)) {
+        // disallow non-admin to import the metadata of sentry
+        throw new SentryAccessDeniedException("Access denied to " + requestor
+            + " for export the metadata of sentry.");
+      }
+      TSentryMappingData tSentryMappingData = new TSentryMappingData();
+      tSentryMappingData.setGroupRolesMap(sentryStore.getGroupNameRoleNamesMap());
+      tSentryMappingData.setRolePrivilegesMap(sentryStore.getRoleNameTPrivilegesMap());
+      response.setMappingData(tSentryMappingData);
+      response.setStatus(Status.OK());
+    } catch (Exception e) {
+      String msg = "Unknown error for request: " + request + ", message: " + e.getMessage();
+      LOGGER.error(msg, e);
+      response.setMappingData(new TSentryMappingData());
+      response.setStatus(Status.RuntimeError(msg, e));
+    }
+    return response;
+  }
+
+  // import the sentry mapping data
+  @Override
+  public TSentryImportMappingDataResponse import_sentry_mapping_data(
+      TSentryImportMappingDataRequest request) throws TException {
+    TSentryImportMappingDataResponse response = new TSentryImportMappingDataResponse();
+    try {
+      String requestor = request.getRequestorUserName();
+      Set<String> memberGroups = getRequestorGroups(requestor);
+      if (!inAdminGroups(memberGroups)) {
+        // disallow non-admin to import the metadata of sentry
+        throw new SentryAccessDeniedException("Access denied to " + requestor
+            + " for import the metadata of sentry.");
+      }
+      sentryStore.importSentryMetaData(request.getMappingData(), request.isOverwriteRole());
+      response.setStatus(Status.OK());
+    } catch (SentryInvalidInputException e) {
+      String msg = "Invalid input privilege object";
+      LOGGER.error(msg, e);
+      response.setStatus(Status.InvalidInput(msg, e));
+    } catch (Exception e) {
+      String msg = "Unknown error for request: " + request + ", message: " + e.getMessage();
+      LOGGER.error(msg, e);
+      response.setStatus(Status.RuntimeError(msg, e));
+    }
+    return response;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java
new file mode 100644
index 0000000..46798a0
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceUtil.java
@@ -0,0 +1,127 @@
+/**
+ * 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 java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sentry.provider.common.KeyValue;
+import org.apache.sentry.provider.common.PolicyFileConstants;
+import org.apache.sentry.provider.common.ProviderConstants;
+import org.apache.sentry.provider.db.service.thrift.TSentryGrantOption;
+import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege;
+import org.apache.sentry.service.thrift.ServiceConstants.PrivilegeScope;
+
+import com.google.common.collect.Lists;
+
+public class SentryServiceUtil {
+
+  // parse the privilege in String and get the TSentryPrivilege as result
+  public static TSentryPrivilege convertToTSentryPrivilege(String privilegeStr) {
+    TSentryPrivilege tSentryPrivilege = new TSentryPrivilege();
+    for (String authorizable : ProviderConstants.AUTHORIZABLE_SPLITTER.split(privilegeStr)) {
+      KeyValue tempKV = new KeyValue(authorizable);
+      String key = tempKV.getKey();
+      String value = tempKV.getValue();
+
+      if (PolicyFileConstants.PRIVILEGE_SERVER_NAME.equalsIgnoreCase(key)) {
+        tSentryPrivilege.setServerName(value);
+      } else if (PolicyFileConstants.PRIVILEGE_DATABASE_NAME.equalsIgnoreCase(key)) {
+        tSentryPrivilege.setDbName(value);
+      } else if (PolicyFileConstants.PRIVILEGE_TABLE_NAME.equalsIgnoreCase(key)) {
+        tSentryPrivilege.setTableName(value);
+      } else if (PolicyFileConstants.PRIVILEGE_COLUMN_NAME.equalsIgnoreCase(key)) {
+        tSentryPrivilege.setColumnName(value);
+      } else if (PolicyFileConstants.PRIVILEGE_URI_NAME.equalsIgnoreCase(key)) {
+        tSentryPrivilege.setURI(value);
+      } else if (PolicyFileConstants.PRIVILEGE_ACTION_NAME.equalsIgnoreCase(key)) {
+        tSentryPrivilege.setAction(value);
+      } else if (PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME.equalsIgnoreCase(key)) {
+        TSentryGrantOption grantOption = "true".equalsIgnoreCase(value) ? TSentryGrantOption.TRUE
+            : TSentryGrantOption.FALSE;
+        tSentryPrivilege.setGrantOption(grantOption);
+      }
+    }
+    tSentryPrivilege.setPrivilegeScope(getPrivilegeScope(tSentryPrivilege));
+    return tSentryPrivilege;
+  }
+
+  // for the different hierarchy for hive:
+  // 1: server->url
+  // 2: server->database->table->column
+  // if both of them are found in the privilege string, the privilege scope will be set as
+  // PrivilegeScope.URI
+  public static String getPrivilegeScope(TSentryPrivilege tSentryPrivilege) {
+    PrivilegeScope privilegeScope = PrivilegeScope.SERVER;
+    if (!StringUtils.isEmpty(tSentryPrivilege.getURI())) {
+      privilegeScope = PrivilegeScope.URI;
+    } else if (!StringUtils.isEmpty(tSentryPrivilege.getColumnName())) {
+      privilegeScope = PrivilegeScope.COLUMN;
+    } else if (!StringUtils.isEmpty(tSentryPrivilege.getTableName())) {
+      privilegeScope = PrivilegeScope.TABLE;
+    } else if (!StringUtils.isEmpty(tSentryPrivilege.getDbName())) {
+      privilegeScope = PrivilegeScope.DATABASE;
+    }
+    return privilegeScope.toString();
+  }
+
+  // convert TSentryPrivilege to privilege in string
+  public static String convertTSentryPrivilegeToStr(TSentryPrivilege tSentryPrivilege) {
+    List<String> privileges = Lists.newArrayList();
+    if (tSentryPrivilege != null) {
+      String serverName = tSentryPrivilege.getServerName();
+      String dbName = tSentryPrivilege.getDbName();
+      String tableName = tSentryPrivilege.getTableName();
+      String columnName = tSentryPrivilege.getColumnName();
+      String uri = tSentryPrivilege.getURI();
+      String action = tSentryPrivilege.getAction();
+      String grantOption = (tSentryPrivilege.getGrantOption() == TSentryGrantOption.TRUE ? "true"
+          : "false");
+      if (!StringUtils.isEmpty(serverName)) {
+        privileges.add(ProviderConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_SERVER_NAME,
+            serverName));
+        if (!StringUtils.isEmpty(uri)) {
+          privileges.add(ProviderConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_URI_NAME,
+              uri));
+        } else if (!StringUtils.isEmpty(dbName)) {
+          privileges.add(ProviderConstants.KV_JOINER.join(
+              PolicyFileConstants.PRIVILEGE_DATABASE_NAME, dbName));
+          if (!StringUtils.isEmpty(tableName)) {
+            privileges.add(ProviderConstants.KV_JOINER.join(
+                PolicyFileConstants.PRIVILEGE_TABLE_NAME, tableName));
+            if (!StringUtils.isEmpty(columnName)) {
+              privileges.add(ProviderConstants.KV_JOINER.join(
+                  PolicyFileConstants.PRIVILEGE_COLUMN_NAME, columnName));
+            }
+          }
+        }
+        if (!StringUtils.isEmpty(action)) {
+          privileges.add(ProviderConstants.KV_JOINER.join(
+              PolicyFileConstants.PRIVILEGE_ACTION_NAME, action));
+        }
+      }
+      // only append the grant option to privilege string if it's true
+      if ("true".equals(grantOption)) {
+        privileges.add(ProviderConstants.KV_JOINER.join(
+            PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME, grantOption));
+      }
+    }
+    return ProviderConstants.AUTHORIZABLE_JOINER.join(privileges);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/main/resources/sentry_policy_service.thrift
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/main/resources/sentry_policy_service.thrift b/sentry-provider/sentry-provider-db/src/main/resources/sentry_policy_service.thrift
index 5803cc4..40889e8 100644
--- a/sentry-provider/sentry-provider-db/src/main/resources/sentry_policy_service.thrift
+++ b/sentry-provider/sentry-provider-db/src/main/resources/sentry_policy_service.thrift
@@ -232,6 +232,33 @@ struct TSentryConfigValueResponse {
 2: optional string value
 }
 
+# struct for the mapping data like group to role, role to privilege
+struct TSentryMappingData {
+1: optional map<string, set<string>> groupRolesMap,          	   # for the groupName -> role mapping
+2: optional map<string, set<TSentryPrivilege>>  rolePrivilegesMap  # for the roleName -> privilege mapping
+}
+
+struct TSentryExportMappingDataRequest {
+1: required i32 protocol_version = sentry_common_service.TSENTRY_SERVICE_V1,
+2: required string requestorUserName # user on whose behalf the request is issued
+}
+
+struct TSentryExportMappingDataResponse {
+1: required sentry_common_service.TSentryResponseStatus status,
+2: required TSentryMappingData mappingData
+}
+
+struct TSentryImportMappingDataRequest {
+1: required i32 protocol_version = sentry_common_service.TSENTRY_SERVICE_V1,
+2: required string requestorUserName, # user on whose behalf the request is issued
+3: required bool overwriteRole = false, # if overwrite the exist role with the imported privileges, default is false 
+4: required TSentryMappingData mappingData
+}
+
+struct TSentryImportMappingDataResponse {
+1: required sentry_common_service.TSentryResponseStatus status
+}
+
 service SentryPolicyService
 {
   TCreateSentryRoleResponse create_sentry_role(1:TCreateSentryRoleRequest request)
@@ -250,11 +277,17 @@ service SentryPolicyService
   # For use with ProviderBackend.getPrivileges only
   TListSentryPrivilegesForProviderResponse list_sentry_privileges_for_provider(1:TListSentryPrivilegesForProviderRequest request)
 
- TDropPrivilegesResponse drop_sentry_privilege(1:TDropPrivilegesRequest request);
+  TDropPrivilegesResponse drop_sentry_privilege(1:TDropPrivilegesRequest request);
+
+  TRenamePrivilegesResponse rename_sentry_privilege(1:TRenamePrivilegesRequest request);
+
+  TListSentryPrivilegesByAuthResponse list_sentry_privileges_by_authorizable(1:TListSentryPrivilegesByAuthRequest request);
 
- TRenamePrivilegesResponse rename_sentry_privilege(1:TRenamePrivilegesRequest request);
+  TSentryConfigValueResponse get_sentry_config_value(1:TSentryConfigValueRequest request);
 
- TListSentryPrivilegesByAuthResponse list_sentry_privileges_by_authorizable(1:TListSentryPrivilegesByAuthRequest request);
+  # export the mapping data in sentry
+  TSentryExportMappingDataResponse export_sentry_mapping_data(1:TSentryExportMappingDataRequest request);
 
- TSentryConfigValueResponse get_sentry_config_value(1:TSentryConfigValueRequest request)
+  # import the mapping data in sentry
+  TSentryImportMappingDataResponse import_sentry_mapping_data(1:TSentryImportMappingDataRequest request);
 }



[5/6] incubator-sentry git commit: SENTRY-197: Create tool to dump and load of entire Sentry service (Colin Ma, Reviewed by:Sravya Tirukkovalur, Guoquan Shen, Dapeng Sun, Anne Yu)

Posted by co...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/SentryPolicyService.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/SentryPolicyService.java b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/SentryPolicyService.java
index c47f64a..0c24449 100644
--- a/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/SentryPolicyService.java
+++ b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/SentryPolicyService.java
@@ -61,6 +61,10 @@ public class SentryPolicyService {
 
     public TSentryConfigValueResponse get_sentry_config_value(TSentryConfigValueRequest request) throws org.apache.thrift.TException;
 
+    public TSentryExportMappingDataResponse export_sentry_mapping_data(TSentryExportMappingDataRequest request) throws org.apache.thrift.TException;
+
+    public TSentryImportMappingDataResponse import_sentry_mapping_data(TSentryImportMappingDataRequest request) throws org.apache.thrift.TException;
+
   }
 
   public interface AsyncIface {
@@ -91,6 +95,10 @@ public class SentryPolicyService {
 
     public void get_sentry_config_value(TSentryConfigValueRequest request, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.get_sentry_config_value_call> resultHandler) throws org.apache.thrift.TException;
 
+    public void export_sentry_mapping_data(TSentryExportMappingDataRequest request, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.export_sentry_mapping_data_call> resultHandler) throws org.apache.thrift.TException;
+
+    public void import_sentry_mapping_data(TSentryImportMappingDataRequest request, org.apache.thrift.async.AsyncMethodCallback<AsyncClient.import_sentry_mapping_data_call> resultHandler) throws org.apache.thrift.TException;
+
   }
 
   public static class Client extends org.apache.thrift.TServiceClient implements Iface {
@@ -412,6 +420,52 @@ public class SentryPolicyService {
       throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "get_sentry_config_value failed: unknown result");
     }
 
+    public TSentryExportMappingDataResponse export_sentry_mapping_data(TSentryExportMappingDataRequest request) throws org.apache.thrift.TException
+    {
+      send_export_sentry_mapping_data(request);
+      return recv_export_sentry_mapping_data();
+    }
+
+    public void send_export_sentry_mapping_data(TSentryExportMappingDataRequest request) throws org.apache.thrift.TException
+    {
+      export_sentry_mapping_data_args args = new export_sentry_mapping_data_args();
+      args.setRequest(request);
+      sendBase("export_sentry_mapping_data", args);
+    }
+
+    public TSentryExportMappingDataResponse recv_export_sentry_mapping_data() throws org.apache.thrift.TException
+    {
+      export_sentry_mapping_data_result result = new export_sentry_mapping_data_result();
+      receiveBase(result, "export_sentry_mapping_data");
+      if (result.isSetSuccess()) {
+        return result.success;
+      }
+      throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "export_sentry_mapping_data failed: unknown result");
+    }
+
+    public TSentryImportMappingDataResponse import_sentry_mapping_data(TSentryImportMappingDataRequest request) throws org.apache.thrift.TException
+    {
+      send_import_sentry_mapping_data(request);
+      return recv_import_sentry_mapping_data();
+    }
+
+    public void send_import_sentry_mapping_data(TSentryImportMappingDataRequest request) throws org.apache.thrift.TException
+    {
+      import_sentry_mapping_data_args args = new import_sentry_mapping_data_args();
+      args.setRequest(request);
+      sendBase("import_sentry_mapping_data", args);
+    }
+
+    public TSentryImportMappingDataResponse recv_import_sentry_mapping_data() throws org.apache.thrift.TException
+    {
+      import_sentry_mapping_data_result result = new import_sentry_mapping_data_result();
+      receiveBase(result, "import_sentry_mapping_data");
+      if (result.isSetSuccess()) {
+        return result.success;
+      }
+      throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "import_sentry_mapping_data failed: unknown result");
+    }
+
   }
   public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface {
     public static class Factory implements org.apache.thrift.async.TAsyncClientFactory<AsyncClient> {
@@ -846,6 +900,70 @@ public class SentryPolicyService {
       }
     }
 
+    public void export_sentry_mapping_data(TSentryExportMappingDataRequest request, org.apache.thrift.async.AsyncMethodCallback<export_sentry_mapping_data_call> resultHandler) throws org.apache.thrift.TException {
+      checkReady();
+      export_sentry_mapping_data_call method_call = new export_sentry_mapping_data_call(request, resultHandler, this, ___protocolFactory, ___transport);
+      this.___currentMethod = method_call;
+      ___manager.call(method_call);
+    }
+
+    public static class export_sentry_mapping_data_call extends org.apache.thrift.async.TAsyncMethodCall {
+      private TSentryExportMappingDataRequest request;
+      public export_sentry_mapping_data_call(TSentryExportMappingDataRequest request, org.apache.thrift.async.AsyncMethodCallback<export_sentry_mapping_data_call> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
+        super(client, protocolFactory, transport, resultHandler, false);
+        this.request = request;
+      }
+
+      public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
+        prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("export_sentry_mapping_data", org.apache.thrift.protocol.TMessageType.CALL, 0));
+        export_sentry_mapping_data_args args = new export_sentry_mapping_data_args();
+        args.setRequest(request);
+        args.write(prot);
+        prot.writeMessageEnd();
+      }
+
+      public TSentryExportMappingDataResponse getResult() throws org.apache.thrift.TException {
+        if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
+          throw new IllegalStateException("Method call not finished!");
+        }
+        org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
+        org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
+        return (new Client(prot)).recv_export_sentry_mapping_data();
+      }
+    }
+
+    public void import_sentry_mapping_data(TSentryImportMappingDataRequest request, org.apache.thrift.async.AsyncMethodCallback<import_sentry_mapping_data_call> resultHandler) throws org.apache.thrift.TException {
+      checkReady();
+      import_sentry_mapping_data_call method_call = new import_sentry_mapping_data_call(request, resultHandler, this, ___protocolFactory, ___transport);
+      this.___currentMethod = method_call;
+      ___manager.call(method_call);
+    }
+
+    public static class import_sentry_mapping_data_call extends org.apache.thrift.async.TAsyncMethodCall {
+      private TSentryImportMappingDataRequest request;
+      public import_sentry_mapping_data_call(TSentryImportMappingDataRequest request, org.apache.thrift.async.AsyncMethodCallback<import_sentry_mapping_data_call> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
+        super(client, protocolFactory, transport, resultHandler, false);
+        this.request = request;
+      }
+
+      public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
+        prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("import_sentry_mapping_data", org.apache.thrift.protocol.TMessageType.CALL, 0));
+        import_sentry_mapping_data_args args = new import_sentry_mapping_data_args();
+        args.setRequest(request);
+        args.write(prot);
+        prot.writeMessageEnd();
+      }
+
+      public TSentryImportMappingDataResponse getResult() throws org.apache.thrift.TException {
+        if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
+          throw new IllegalStateException("Method call not finished!");
+        }
+        org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
+        org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
+        return (new Client(prot)).recv_import_sentry_mapping_data();
+      }
+    }
+
   }
 
   public static class Processor<I extends Iface> extends org.apache.thrift.TBaseProcessor<I> implements org.apache.thrift.TProcessor {
@@ -872,6 +990,8 @@ public class SentryPolicyService {
       processMap.put("rename_sentry_privilege", new rename_sentry_privilege());
       processMap.put("list_sentry_privileges_by_authorizable", new list_sentry_privileges_by_authorizable());
       processMap.put("get_sentry_config_value", new get_sentry_config_value());
+      processMap.put("export_sentry_mapping_data", new export_sentry_mapping_data());
+      processMap.put("import_sentry_mapping_data", new import_sentry_mapping_data());
       return processMap;
     }
 
@@ -1135,6 +1255,46 @@ public class SentryPolicyService {
       }
     }
 
+    public static class export_sentry_mapping_data<I extends Iface> extends org.apache.thrift.ProcessFunction<I, export_sentry_mapping_data_args> {
+      public export_sentry_mapping_data() {
+        super("export_sentry_mapping_data");
+      }
+
+      public export_sentry_mapping_data_args getEmptyArgsInstance() {
+        return new export_sentry_mapping_data_args();
+      }
+
+      protected boolean isOneway() {
+        return false;
+      }
+
+      public export_sentry_mapping_data_result getResult(I iface, export_sentry_mapping_data_args args) throws org.apache.thrift.TException {
+        export_sentry_mapping_data_result result = new export_sentry_mapping_data_result();
+        result.success = iface.export_sentry_mapping_data(args.request);
+        return result;
+      }
+    }
+
+    public static class import_sentry_mapping_data<I extends Iface> extends org.apache.thrift.ProcessFunction<I, import_sentry_mapping_data_args> {
+      public import_sentry_mapping_data() {
+        super("import_sentry_mapping_data");
+      }
+
+      public import_sentry_mapping_data_args getEmptyArgsInstance() {
+        return new import_sentry_mapping_data_args();
+      }
+
+      protected boolean isOneway() {
+        return false;
+      }
+
+      public import_sentry_mapping_data_result getResult(I iface, import_sentry_mapping_data_args args) throws org.apache.thrift.TException {
+        import_sentry_mapping_data_result result = new import_sentry_mapping_data_result();
+        result.success = iface.import_sentry_mapping_data(args.request);
+        return result;
+      }
+    }
+
   }
 
   public static class create_sentry_role_args implements org.apache.thrift.TBase<create_sentry_role_args, create_sentry_role_args._Fields>, java.io.Serializable, Cloneable   {
@@ -10575,4 +10735,1456 @@ public class SentryPolicyService {
 
   }
 
+  public static class export_sentry_mapping_data_args implements org.apache.thrift.TBase<export_sentry_mapping_data_args, export_sentry_mapping_data_args._Fields>, java.io.Serializable, Cloneable   {
+    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("export_sentry_mapping_data_args");
+
+    private static final org.apache.thrift.protocol.TField REQUEST_FIELD_DESC = new org.apache.thrift.protocol.TField("request", org.apache.thrift.protocol.TType.STRUCT, (short)1);
+
+    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+    static {
+      schemes.put(StandardScheme.class, new export_sentry_mapping_data_argsStandardSchemeFactory());
+      schemes.put(TupleScheme.class, new export_sentry_mapping_data_argsTupleSchemeFactory());
+    }
+
+    private TSentryExportMappingDataRequest request; // required
+
+    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+      REQUEST((short)1, "request");
+
+      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+      static {
+        for (_Fields field : EnumSet.allOf(_Fields.class)) {
+          byName.put(field.getFieldName(), field);
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, or null if its not found.
+       */
+      public static _Fields findByThriftId(int fieldId) {
+        switch(fieldId) {
+          case 1: // REQUEST
+            return REQUEST;
+          default:
+            return null;
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, throwing an exception
+       * if it is not found.
+       */
+      public static _Fields findByThriftIdOrThrow(int fieldId) {
+        _Fields fields = findByThriftId(fieldId);
+        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+        return fields;
+      }
+
+      /**
+       * Find the _Fields constant that matches name, or null if its not found.
+       */
+      public static _Fields findByName(String name) {
+        return byName.get(name);
+      }
+
+      private final short _thriftId;
+      private final String _fieldName;
+
+      _Fields(short thriftId, String fieldName) {
+        _thriftId = thriftId;
+        _fieldName = fieldName;
+      }
+
+      public short getThriftFieldId() {
+        return _thriftId;
+      }
+
+      public String getFieldName() {
+        return _fieldName;
+      }
+    }
+
+    // isset id assignments
+    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+    static {
+      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+      tmpMap.put(_Fields.REQUEST, new org.apache.thrift.meta_data.FieldMetaData("request", org.apache.thrift.TFieldRequirementType.DEFAULT, 
+          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TSentryExportMappingDataRequest.class)));
+      metaDataMap = Collections.unmodifiableMap(tmpMap);
+      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(export_sentry_mapping_data_args.class, metaDataMap);
+    }
+
+    public export_sentry_mapping_data_args() {
+    }
+
+    public export_sentry_mapping_data_args(
+      TSentryExportMappingDataRequest request)
+    {
+      this();
+      this.request = request;
+    }
+
+    /**
+     * Performs a deep copy on <i>other</i>.
+     */
+    public export_sentry_mapping_data_args(export_sentry_mapping_data_args other) {
+      if (other.isSetRequest()) {
+        this.request = new TSentryExportMappingDataRequest(other.request);
+      }
+    }
+
+    public export_sentry_mapping_data_args deepCopy() {
+      return new export_sentry_mapping_data_args(this);
+    }
+
+    @Override
+    public void clear() {
+      this.request = null;
+    }
+
+    public TSentryExportMappingDataRequest getRequest() {
+      return this.request;
+    }
+
+    public void setRequest(TSentryExportMappingDataRequest request) {
+      this.request = request;
+    }
+
+    public void unsetRequest() {
+      this.request = null;
+    }
+
+    /** Returns true if field request is set (has been assigned a value) and false otherwise */
+    public boolean isSetRequest() {
+      return this.request != null;
+    }
+
+    public void setRequestIsSet(boolean value) {
+      if (!value) {
+        this.request = null;
+      }
+    }
+
+    public void setFieldValue(_Fields field, Object value) {
+      switch (field) {
+      case REQUEST:
+        if (value == null) {
+          unsetRequest();
+        } else {
+          setRequest((TSentryExportMappingDataRequest)value);
+        }
+        break;
+
+      }
+    }
+
+    public Object getFieldValue(_Fields field) {
+      switch (field) {
+      case REQUEST:
+        return getRequest();
+
+      }
+      throw new IllegalStateException();
+    }
+
+    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+    public boolean isSet(_Fields field) {
+      if (field == null) {
+        throw new IllegalArgumentException();
+      }
+
+      switch (field) {
+      case REQUEST:
+        return isSetRequest();
+      }
+      throw new IllegalStateException();
+    }
+
+    @Override
+    public boolean equals(Object that) {
+      if (that == null)
+        return false;
+      if (that instanceof export_sentry_mapping_data_args)
+        return this.equals((export_sentry_mapping_data_args)that);
+      return false;
+    }
+
+    public boolean equals(export_sentry_mapping_data_args that) {
+      if (that == null)
+        return false;
+
+      boolean this_present_request = true && this.isSetRequest();
+      boolean that_present_request = true && that.isSetRequest();
+      if (this_present_request || that_present_request) {
+        if (!(this_present_request && that_present_request))
+          return false;
+        if (!this.request.equals(that.request))
+          return false;
+      }
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      HashCodeBuilder builder = new HashCodeBuilder();
+
+      boolean present_request = true && (isSetRequest());
+      builder.append(present_request);
+      if (present_request)
+        builder.append(request);
+
+      return builder.toHashCode();
+    }
+
+    public int compareTo(export_sentry_mapping_data_args other) {
+      if (!getClass().equals(other.getClass())) {
+        return getClass().getName().compareTo(other.getClass().getName());
+      }
+
+      int lastComparison = 0;
+      export_sentry_mapping_data_args typedOther = (export_sentry_mapping_data_args)other;
+
+      lastComparison = Boolean.valueOf(isSetRequest()).compareTo(typedOther.isSetRequest());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      if (isSetRequest()) {
+        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.request, typedOther.request);
+        if (lastComparison != 0) {
+          return lastComparison;
+        }
+      }
+      return 0;
+    }
+
+    public _Fields fieldForId(int fieldId) {
+      return _Fields.findByThriftId(fieldId);
+    }
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+    }
+
+    @Override
+    public String toString() {
+      StringBuilder sb = new StringBuilder("export_sentry_mapping_data_args(");
+      boolean first = true;
+
+      sb.append("request:");
+      if (this.request == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.request);
+      }
+      first = false;
+      sb.append(")");
+      return sb.toString();
+    }
+
+    public void validate() throws org.apache.thrift.TException {
+      // check for required fields
+      // check for sub-struct validity
+      if (request != null) {
+        request.validate();
+      }
+    }
+
+    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+      try {
+        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+      try {
+        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private static class export_sentry_mapping_data_argsStandardSchemeFactory implements SchemeFactory {
+      public export_sentry_mapping_data_argsStandardScheme getScheme() {
+        return new export_sentry_mapping_data_argsStandardScheme();
+      }
+    }
+
+    private static class export_sentry_mapping_data_argsStandardScheme extends StandardScheme<export_sentry_mapping_data_args> {
+
+      public void read(org.apache.thrift.protocol.TProtocol iprot, export_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        org.apache.thrift.protocol.TField schemeField;
+        iprot.readStructBegin();
+        while (true)
+        {
+          schemeField = iprot.readFieldBegin();
+          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+            break;
+          }
+          switch (schemeField.id) {
+            case 1: // REQUEST
+              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+                struct.request = new TSentryExportMappingDataRequest();
+                struct.request.read(iprot);
+                struct.setRequestIsSet(true);
+              } else { 
+                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+              }
+              break;
+            default:
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+          }
+          iprot.readFieldEnd();
+        }
+        iprot.readStructEnd();
+        struct.validate();
+      }
+
+      public void write(org.apache.thrift.protocol.TProtocol oprot, export_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        struct.validate();
+
+        oprot.writeStructBegin(STRUCT_DESC);
+        if (struct.request != null) {
+          oprot.writeFieldBegin(REQUEST_FIELD_DESC);
+          struct.request.write(oprot);
+          oprot.writeFieldEnd();
+        }
+        oprot.writeFieldStop();
+        oprot.writeStructEnd();
+      }
+
+    }
+
+    private static class export_sentry_mapping_data_argsTupleSchemeFactory implements SchemeFactory {
+      public export_sentry_mapping_data_argsTupleScheme getScheme() {
+        return new export_sentry_mapping_data_argsTupleScheme();
+      }
+    }
+
+    private static class export_sentry_mapping_data_argsTupleScheme extends TupleScheme<export_sentry_mapping_data_args> {
+
+      @Override
+      public void write(org.apache.thrift.protocol.TProtocol prot, export_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        TTupleProtocol oprot = (TTupleProtocol) prot;
+        BitSet optionals = new BitSet();
+        if (struct.isSetRequest()) {
+          optionals.set(0);
+        }
+        oprot.writeBitSet(optionals, 1);
+        if (struct.isSetRequest()) {
+          struct.request.write(oprot);
+        }
+      }
+
+      @Override
+      public void read(org.apache.thrift.protocol.TProtocol prot, export_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        TTupleProtocol iprot = (TTupleProtocol) prot;
+        BitSet incoming = iprot.readBitSet(1);
+        if (incoming.get(0)) {
+          struct.request = new TSentryExportMappingDataRequest();
+          struct.request.read(iprot);
+          struct.setRequestIsSet(true);
+        }
+      }
+    }
+
+  }
+
+  public static class export_sentry_mapping_data_result implements org.apache.thrift.TBase<export_sentry_mapping_data_result, export_sentry_mapping_data_result._Fields>, java.io.Serializable, Cloneable   {
+    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("export_sentry_mapping_data_result");
+
+    private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0);
+
+    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+    static {
+      schemes.put(StandardScheme.class, new export_sentry_mapping_data_resultStandardSchemeFactory());
+      schemes.put(TupleScheme.class, new export_sentry_mapping_data_resultTupleSchemeFactory());
+    }
+
+    private TSentryExportMappingDataResponse success; // required
+
+    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+      SUCCESS((short)0, "success");
+
+      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+      static {
+        for (_Fields field : EnumSet.allOf(_Fields.class)) {
+          byName.put(field.getFieldName(), field);
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, or null if its not found.
+       */
+      public static _Fields findByThriftId(int fieldId) {
+        switch(fieldId) {
+          case 0: // SUCCESS
+            return SUCCESS;
+          default:
+            return null;
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, throwing an exception
+       * if it is not found.
+       */
+      public static _Fields findByThriftIdOrThrow(int fieldId) {
+        _Fields fields = findByThriftId(fieldId);
+        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+        return fields;
+      }
+
+      /**
+       * Find the _Fields constant that matches name, or null if its not found.
+       */
+      public static _Fields findByName(String name) {
+        return byName.get(name);
+      }
+
+      private final short _thriftId;
+      private final String _fieldName;
+
+      _Fields(short thriftId, String fieldName) {
+        _thriftId = thriftId;
+        _fieldName = fieldName;
+      }
+
+      public short getThriftFieldId() {
+        return _thriftId;
+      }
+
+      public String getFieldName() {
+        return _fieldName;
+      }
+    }
+
+    // isset id assignments
+    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+    static {
+      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+      tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, 
+          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TSentryExportMappingDataResponse.class)));
+      metaDataMap = Collections.unmodifiableMap(tmpMap);
+      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(export_sentry_mapping_data_result.class, metaDataMap);
+    }
+
+    public export_sentry_mapping_data_result() {
+    }
+
+    public export_sentry_mapping_data_result(
+      TSentryExportMappingDataResponse success)
+    {
+      this();
+      this.success = success;
+    }
+
+    /**
+     * Performs a deep copy on <i>other</i>.
+     */
+    public export_sentry_mapping_data_result(export_sentry_mapping_data_result other) {
+      if (other.isSetSuccess()) {
+        this.success = new TSentryExportMappingDataResponse(other.success);
+      }
+    }
+
+    public export_sentry_mapping_data_result deepCopy() {
+      return new export_sentry_mapping_data_result(this);
+    }
+
+    @Override
+    public void clear() {
+      this.success = null;
+    }
+
+    public TSentryExportMappingDataResponse getSuccess() {
+      return this.success;
+    }
+
+    public void setSuccess(TSentryExportMappingDataResponse success) {
+      this.success = success;
+    }
+
+    public void unsetSuccess() {
+      this.success = null;
+    }
+
+    /** Returns true if field success is set (has been assigned a value) and false otherwise */
+    public boolean isSetSuccess() {
+      return this.success != null;
+    }
+
+    public void setSuccessIsSet(boolean value) {
+      if (!value) {
+        this.success = null;
+      }
+    }
+
+    public void setFieldValue(_Fields field, Object value) {
+      switch (field) {
+      case SUCCESS:
+        if (value == null) {
+          unsetSuccess();
+        } else {
+          setSuccess((TSentryExportMappingDataResponse)value);
+        }
+        break;
+
+      }
+    }
+
+    public Object getFieldValue(_Fields field) {
+      switch (field) {
+      case SUCCESS:
+        return getSuccess();
+
+      }
+      throw new IllegalStateException();
+    }
+
+    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+    public boolean isSet(_Fields field) {
+      if (field == null) {
+        throw new IllegalArgumentException();
+      }
+
+      switch (field) {
+      case SUCCESS:
+        return isSetSuccess();
+      }
+      throw new IllegalStateException();
+    }
+
+    @Override
+    public boolean equals(Object that) {
+      if (that == null)
+        return false;
+      if (that instanceof export_sentry_mapping_data_result)
+        return this.equals((export_sentry_mapping_data_result)that);
+      return false;
+    }
+
+    public boolean equals(export_sentry_mapping_data_result that) {
+      if (that == null)
+        return false;
+
+      boolean this_present_success = true && this.isSetSuccess();
+      boolean that_present_success = true && that.isSetSuccess();
+      if (this_present_success || that_present_success) {
+        if (!(this_present_success && that_present_success))
+          return false;
+        if (!this.success.equals(that.success))
+          return false;
+      }
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      HashCodeBuilder builder = new HashCodeBuilder();
+
+      boolean present_success = true && (isSetSuccess());
+      builder.append(present_success);
+      if (present_success)
+        builder.append(success);
+
+      return builder.toHashCode();
+    }
+
+    public int compareTo(export_sentry_mapping_data_result other) {
+      if (!getClass().equals(other.getClass())) {
+        return getClass().getName().compareTo(other.getClass().getName());
+      }
+
+      int lastComparison = 0;
+      export_sentry_mapping_data_result typedOther = (export_sentry_mapping_data_result)other;
+
+      lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      if (isSetSuccess()) {
+        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, typedOther.success);
+        if (lastComparison != 0) {
+          return lastComparison;
+        }
+      }
+      return 0;
+    }
+
+    public _Fields fieldForId(int fieldId) {
+      return _Fields.findByThriftId(fieldId);
+    }
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+      }
+
+    @Override
+    public String toString() {
+      StringBuilder sb = new StringBuilder("export_sentry_mapping_data_result(");
+      boolean first = true;
+
+      sb.append("success:");
+      if (this.success == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.success);
+      }
+      first = false;
+      sb.append(")");
+      return sb.toString();
+    }
+
+    public void validate() throws org.apache.thrift.TException {
+      // check for required fields
+      // check for sub-struct validity
+      if (success != null) {
+        success.validate();
+      }
+    }
+
+    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+      try {
+        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+      try {
+        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private static class export_sentry_mapping_data_resultStandardSchemeFactory implements SchemeFactory {
+      public export_sentry_mapping_data_resultStandardScheme getScheme() {
+        return new export_sentry_mapping_data_resultStandardScheme();
+      }
+    }
+
+    private static class export_sentry_mapping_data_resultStandardScheme extends StandardScheme<export_sentry_mapping_data_result> {
+
+      public void read(org.apache.thrift.protocol.TProtocol iprot, export_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        org.apache.thrift.protocol.TField schemeField;
+        iprot.readStructBegin();
+        while (true)
+        {
+          schemeField = iprot.readFieldBegin();
+          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+            break;
+          }
+          switch (schemeField.id) {
+            case 0: // SUCCESS
+              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+                struct.success = new TSentryExportMappingDataResponse();
+                struct.success.read(iprot);
+                struct.setSuccessIsSet(true);
+              } else { 
+                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+              }
+              break;
+            default:
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+          }
+          iprot.readFieldEnd();
+        }
+        iprot.readStructEnd();
+        struct.validate();
+      }
+
+      public void write(org.apache.thrift.protocol.TProtocol oprot, export_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        struct.validate();
+
+        oprot.writeStructBegin(STRUCT_DESC);
+        if (struct.success != null) {
+          oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
+          struct.success.write(oprot);
+          oprot.writeFieldEnd();
+        }
+        oprot.writeFieldStop();
+        oprot.writeStructEnd();
+      }
+
+    }
+
+    private static class export_sentry_mapping_data_resultTupleSchemeFactory implements SchemeFactory {
+      public export_sentry_mapping_data_resultTupleScheme getScheme() {
+        return new export_sentry_mapping_data_resultTupleScheme();
+      }
+    }
+
+    private static class export_sentry_mapping_data_resultTupleScheme extends TupleScheme<export_sentry_mapping_data_result> {
+
+      @Override
+      public void write(org.apache.thrift.protocol.TProtocol prot, export_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        TTupleProtocol oprot = (TTupleProtocol) prot;
+        BitSet optionals = new BitSet();
+        if (struct.isSetSuccess()) {
+          optionals.set(0);
+        }
+        oprot.writeBitSet(optionals, 1);
+        if (struct.isSetSuccess()) {
+          struct.success.write(oprot);
+        }
+      }
+
+      @Override
+      public void read(org.apache.thrift.protocol.TProtocol prot, export_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        TTupleProtocol iprot = (TTupleProtocol) prot;
+        BitSet incoming = iprot.readBitSet(1);
+        if (incoming.get(0)) {
+          struct.success = new TSentryExportMappingDataResponse();
+          struct.success.read(iprot);
+          struct.setSuccessIsSet(true);
+        }
+      }
+    }
+
+  }
+
+  public static class import_sentry_mapping_data_args implements org.apache.thrift.TBase<import_sentry_mapping_data_args, import_sentry_mapping_data_args._Fields>, java.io.Serializable, Cloneable   {
+    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("import_sentry_mapping_data_args");
+
+    private static final org.apache.thrift.protocol.TField REQUEST_FIELD_DESC = new org.apache.thrift.protocol.TField("request", org.apache.thrift.protocol.TType.STRUCT, (short)1);
+
+    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+    static {
+      schemes.put(StandardScheme.class, new import_sentry_mapping_data_argsStandardSchemeFactory());
+      schemes.put(TupleScheme.class, new import_sentry_mapping_data_argsTupleSchemeFactory());
+    }
+
+    private TSentryImportMappingDataRequest request; // required
+
+    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+      REQUEST((short)1, "request");
+
+      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+      static {
+        for (_Fields field : EnumSet.allOf(_Fields.class)) {
+          byName.put(field.getFieldName(), field);
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, or null if its not found.
+       */
+      public static _Fields findByThriftId(int fieldId) {
+        switch(fieldId) {
+          case 1: // REQUEST
+            return REQUEST;
+          default:
+            return null;
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, throwing an exception
+       * if it is not found.
+       */
+      public static _Fields findByThriftIdOrThrow(int fieldId) {
+        _Fields fields = findByThriftId(fieldId);
+        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+        return fields;
+      }
+
+      /**
+       * Find the _Fields constant that matches name, or null if its not found.
+       */
+      public static _Fields findByName(String name) {
+        return byName.get(name);
+      }
+
+      private final short _thriftId;
+      private final String _fieldName;
+
+      _Fields(short thriftId, String fieldName) {
+        _thriftId = thriftId;
+        _fieldName = fieldName;
+      }
+
+      public short getThriftFieldId() {
+        return _thriftId;
+      }
+
+      public String getFieldName() {
+        return _fieldName;
+      }
+    }
+
+    // isset id assignments
+    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+    static {
+      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+      tmpMap.put(_Fields.REQUEST, new org.apache.thrift.meta_data.FieldMetaData("request", org.apache.thrift.TFieldRequirementType.DEFAULT, 
+          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TSentryImportMappingDataRequest.class)));
+      metaDataMap = Collections.unmodifiableMap(tmpMap);
+      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(import_sentry_mapping_data_args.class, metaDataMap);
+    }
+
+    public import_sentry_mapping_data_args() {
+    }
+
+    public import_sentry_mapping_data_args(
+      TSentryImportMappingDataRequest request)
+    {
+      this();
+      this.request = request;
+    }
+
+    /**
+     * Performs a deep copy on <i>other</i>.
+     */
+    public import_sentry_mapping_data_args(import_sentry_mapping_data_args other) {
+      if (other.isSetRequest()) {
+        this.request = new TSentryImportMappingDataRequest(other.request);
+      }
+    }
+
+    public import_sentry_mapping_data_args deepCopy() {
+      return new import_sentry_mapping_data_args(this);
+    }
+
+    @Override
+    public void clear() {
+      this.request = null;
+    }
+
+    public TSentryImportMappingDataRequest getRequest() {
+      return this.request;
+    }
+
+    public void setRequest(TSentryImportMappingDataRequest request) {
+      this.request = request;
+    }
+
+    public void unsetRequest() {
+      this.request = null;
+    }
+
+    /** Returns true if field request is set (has been assigned a value) and false otherwise */
+    public boolean isSetRequest() {
+      return this.request != null;
+    }
+
+    public void setRequestIsSet(boolean value) {
+      if (!value) {
+        this.request = null;
+      }
+    }
+
+    public void setFieldValue(_Fields field, Object value) {
+      switch (field) {
+      case REQUEST:
+        if (value == null) {
+          unsetRequest();
+        } else {
+          setRequest((TSentryImportMappingDataRequest)value);
+        }
+        break;
+
+      }
+    }
+
+    public Object getFieldValue(_Fields field) {
+      switch (field) {
+      case REQUEST:
+        return getRequest();
+
+      }
+      throw new IllegalStateException();
+    }
+
+    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+    public boolean isSet(_Fields field) {
+      if (field == null) {
+        throw new IllegalArgumentException();
+      }
+
+      switch (field) {
+      case REQUEST:
+        return isSetRequest();
+      }
+      throw new IllegalStateException();
+    }
+
+    @Override
+    public boolean equals(Object that) {
+      if (that == null)
+        return false;
+      if (that instanceof import_sentry_mapping_data_args)
+        return this.equals((import_sentry_mapping_data_args)that);
+      return false;
+    }
+
+    public boolean equals(import_sentry_mapping_data_args that) {
+      if (that == null)
+        return false;
+
+      boolean this_present_request = true && this.isSetRequest();
+      boolean that_present_request = true && that.isSetRequest();
+      if (this_present_request || that_present_request) {
+        if (!(this_present_request && that_present_request))
+          return false;
+        if (!this.request.equals(that.request))
+          return false;
+      }
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      HashCodeBuilder builder = new HashCodeBuilder();
+
+      boolean present_request = true && (isSetRequest());
+      builder.append(present_request);
+      if (present_request)
+        builder.append(request);
+
+      return builder.toHashCode();
+    }
+
+    public int compareTo(import_sentry_mapping_data_args other) {
+      if (!getClass().equals(other.getClass())) {
+        return getClass().getName().compareTo(other.getClass().getName());
+      }
+
+      int lastComparison = 0;
+      import_sentry_mapping_data_args typedOther = (import_sentry_mapping_data_args)other;
+
+      lastComparison = Boolean.valueOf(isSetRequest()).compareTo(typedOther.isSetRequest());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      if (isSetRequest()) {
+        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.request, typedOther.request);
+        if (lastComparison != 0) {
+          return lastComparison;
+        }
+      }
+      return 0;
+    }
+
+    public _Fields fieldForId(int fieldId) {
+      return _Fields.findByThriftId(fieldId);
+    }
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+    }
+
+    @Override
+    public String toString() {
+      StringBuilder sb = new StringBuilder("import_sentry_mapping_data_args(");
+      boolean first = true;
+
+      sb.append("request:");
+      if (this.request == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.request);
+      }
+      first = false;
+      sb.append(")");
+      return sb.toString();
+    }
+
+    public void validate() throws org.apache.thrift.TException {
+      // check for required fields
+      // check for sub-struct validity
+      if (request != null) {
+        request.validate();
+      }
+    }
+
+    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+      try {
+        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+      try {
+        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private static class import_sentry_mapping_data_argsStandardSchemeFactory implements SchemeFactory {
+      public import_sentry_mapping_data_argsStandardScheme getScheme() {
+        return new import_sentry_mapping_data_argsStandardScheme();
+      }
+    }
+
+    private static class import_sentry_mapping_data_argsStandardScheme extends StandardScheme<import_sentry_mapping_data_args> {
+
+      public void read(org.apache.thrift.protocol.TProtocol iprot, import_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        org.apache.thrift.protocol.TField schemeField;
+        iprot.readStructBegin();
+        while (true)
+        {
+          schemeField = iprot.readFieldBegin();
+          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+            break;
+          }
+          switch (schemeField.id) {
+            case 1: // REQUEST
+              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+                struct.request = new TSentryImportMappingDataRequest();
+                struct.request.read(iprot);
+                struct.setRequestIsSet(true);
+              } else { 
+                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+              }
+              break;
+            default:
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+          }
+          iprot.readFieldEnd();
+        }
+        iprot.readStructEnd();
+        struct.validate();
+      }
+
+      public void write(org.apache.thrift.protocol.TProtocol oprot, import_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        struct.validate();
+
+        oprot.writeStructBegin(STRUCT_DESC);
+        if (struct.request != null) {
+          oprot.writeFieldBegin(REQUEST_FIELD_DESC);
+          struct.request.write(oprot);
+          oprot.writeFieldEnd();
+        }
+        oprot.writeFieldStop();
+        oprot.writeStructEnd();
+      }
+
+    }
+
+    private static class import_sentry_mapping_data_argsTupleSchemeFactory implements SchemeFactory {
+      public import_sentry_mapping_data_argsTupleScheme getScheme() {
+        return new import_sentry_mapping_data_argsTupleScheme();
+      }
+    }
+
+    private static class import_sentry_mapping_data_argsTupleScheme extends TupleScheme<import_sentry_mapping_data_args> {
+
+      @Override
+      public void write(org.apache.thrift.protocol.TProtocol prot, import_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        TTupleProtocol oprot = (TTupleProtocol) prot;
+        BitSet optionals = new BitSet();
+        if (struct.isSetRequest()) {
+          optionals.set(0);
+        }
+        oprot.writeBitSet(optionals, 1);
+        if (struct.isSetRequest()) {
+          struct.request.write(oprot);
+        }
+      }
+
+      @Override
+      public void read(org.apache.thrift.protocol.TProtocol prot, import_sentry_mapping_data_args struct) throws org.apache.thrift.TException {
+        TTupleProtocol iprot = (TTupleProtocol) prot;
+        BitSet incoming = iprot.readBitSet(1);
+        if (incoming.get(0)) {
+          struct.request = new TSentryImportMappingDataRequest();
+          struct.request.read(iprot);
+          struct.setRequestIsSet(true);
+        }
+      }
+    }
+
+  }
+
+  public static class import_sentry_mapping_data_result implements org.apache.thrift.TBase<import_sentry_mapping_data_result, import_sentry_mapping_data_result._Fields>, java.io.Serializable, Cloneable   {
+    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("import_sentry_mapping_data_result");
+
+    private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0);
+
+    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+    static {
+      schemes.put(StandardScheme.class, new import_sentry_mapping_data_resultStandardSchemeFactory());
+      schemes.put(TupleScheme.class, new import_sentry_mapping_data_resultTupleSchemeFactory());
+    }
+
+    private TSentryImportMappingDataResponse success; // required
+
+    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+      SUCCESS((short)0, "success");
+
+      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+      static {
+        for (_Fields field : EnumSet.allOf(_Fields.class)) {
+          byName.put(field.getFieldName(), field);
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, or null if its not found.
+       */
+      public static _Fields findByThriftId(int fieldId) {
+        switch(fieldId) {
+          case 0: // SUCCESS
+            return SUCCESS;
+          default:
+            return null;
+        }
+      }
+
+      /**
+       * Find the _Fields constant that matches fieldId, throwing an exception
+       * if it is not found.
+       */
+      public static _Fields findByThriftIdOrThrow(int fieldId) {
+        _Fields fields = findByThriftId(fieldId);
+        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+        return fields;
+      }
+
+      /**
+       * Find the _Fields constant that matches name, or null if its not found.
+       */
+      public static _Fields findByName(String name) {
+        return byName.get(name);
+      }
+
+      private final short _thriftId;
+      private final String _fieldName;
+
+      _Fields(short thriftId, String fieldName) {
+        _thriftId = thriftId;
+        _fieldName = fieldName;
+      }
+
+      public short getThriftFieldId() {
+        return _thriftId;
+      }
+
+      public String getFieldName() {
+        return _fieldName;
+      }
+    }
+
+    // isset id assignments
+    public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+    static {
+      Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+      tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, 
+          new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TSentryImportMappingDataResponse.class)));
+      metaDataMap = Collections.unmodifiableMap(tmpMap);
+      org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(import_sentry_mapping_data_result.class, metaDataMap);
+    }
+
+    public import_sentry_mapping_data_result() {
+    }
+
+    public import_sentry_mapping_data_result(
+      TSentryImportMappingDataResponse success)
+    {
+      this();
+      this.success = success;
+    }
+
+    /**
+     * Performs a deep copy on <i>other</i>.
+     */
+    public import_sentry_mapping_data_result(import_sentry_mapping_data_result other) {
+      if (other.isSetSuccess()) {
+        this.success = new TSentryImportMappingDataResponse(other.success);
+      }
+    }
+
+    public import_sentry_mapping_data_result deepCopy() {
+      return new import_sentry_mapping_data_result(this);
+    }
+
+    @Override
+    public void clear() {
+      this.success = null;
+    }
+
+    public TSentryImportMappingDataResponse getSuccess() {
+      return this.success;
+    }
+
+    public void setSuccess(TSentryImportMappingDataResponse success) {
+      this.success = success;
+    }
+
+    public void unsetSuccess() {
+      this.success = null;
+    }
+
+    /** Returns true if field success is set (has been assigned a value) and false otherwise */
+    public boolean isSetSuccess() {
+      return this.success != null;
+    }
+
+    public void setSuccessIsSet(boolean value) {
+      if (!value) {
+        this.success = null;
+      }
+    }
+
+    public void setFieldValue(_Fields field, Object value) {
+      switch (field) {
+      case SUCCESS:
+        if (value == null) {
+          unsetSuccess();
+        } else {
+          setSuccess((TSentryImportMappingDataResponse)value);
+        }
+        break;
+
+      }
+    }
+
+    public Object getFieldValue(_Fields field) {
+      switch (field) {
+      case SUCCESS:
+        return getSuccess();
+
+      }
+      throw new IllegalStateException();
+    }
+
+    /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+    public boolean isSet(_Fields field) {
+      if (field == null) {
+        throw new IllegalArgumentException();
+      }
+
+      switch (field) {
+      case SUCCESS:
+        return isSetSuccess();
+      }
+      throw new IllegalStateException();
+    }
+
+    @Override
+    public boolean equals(Object that) {
+      if (that == null)
+        return false;
+      if (that instanceof import_sentry_mapping_data_result)
+        return this.equals((import_sentry_mapping_data_result)that);
+      return false;
+    }
+
+    public boolean equals(import_sentry_mapping_data_result that) {
+      if (that == null)
+        return false;
+
+      boolean this_present_success = true && this.isSetSuccess();
+      boolean that_present_success = true && that.isSetSuccess();
+      if (this_present_success || that_present_success) {
+        if (!(this_present_success && that_present_success))
+          return false;
+        if (!this.success.equals(that.success))
+          return false;
+      }
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      HashCodeBuilder builder = new HashCodeBuilder();
+
+      boolean present_success = true && (isSetSuccess());
+      builder.append(present_success);
+      if (present_success)
+        builder.append(success);
+
+      return builder.toHashCode();
+    }
+
+    public int compareTo(import_sentry_mapping_data_result other) {
+      if (!getClass().equals(other.getClass())) {
+        return getClass().getName().compareTo(other.getClass().getName());
+      }
+
+      int lastComparison = 0;
+      import_sentry_mapping_data_result typedOther = (import_sentry_mapping_data_result)other;
+
+      lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess());
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+      if (isSetSuccess()) {
+        lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, typedOther.success);
+        if (lastComparison != 0) {
+          return lastComparison;
+        }
+      }
+      return 0;
+    }
+
+    public _Fields fieldForId(int fieldId) {
+      return _Fields.findByThriftId(fieldId);
+    }
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+      schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+      schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+      }
+
+    @Override
+    public String toString() {
+      StringBuilder sb = new StringBuilder("import_sentry_mapping_data_result(");
+      boolean first = true;
+
+      sb.append("success:");
+      if (this.success == null) {
+        sb.append("null");
+      } else {
+        sb.append(this.success);
+      }
+      first = false;
+      sb.append(")");
+      return sb.toString();
+    }
+
+    public void validate() throws org.apache.thrift.TException {
+      // check for required fields
+      // check for sub-struct validity
+      if (success != null) {
+        success.validate();
+      }
+    }
+
+    private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+      try {
+        write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+      try {
+        read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+      } catch (org.apache.thrift.TException te) {
+        throw new java.io.IOException(te);
+      }
+    }
+
+    private static class import_sentry_mapping_data_resultStandardSchemeFactory implements SchemeFactory {
+      public import_sentry_mapping_data_resultStandardScheme getScheme() {
+        return new import_sentry_mapping_data_resultStandardScheme();
+      }
+    }
+
+    private static class import_sentry_mapping_data_resultStandardScheme extends StandardScheme<import_sentry_mapping_data_result> {
+
+      public void read(org.apache.thrift.protocol.TProtocol iprot, import_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        org.apache.thrift.protocol.TField schemeField;
+        iprot.readStructBegin();
+        while (true)
+        {
+          schemeField = iprot.readFieldBegin();
+          if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+            break;
+          }
+          switch (schemeField.id) {
+            case 0: // SUCCESS
+              if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
+                struct.success = new TSentryImportMappingDataResponse();
+                struct.success.read(iprot);
+                struct.setSuccessIsSet(true);
+              } else { 
+                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+              }
+              break;
+            default:
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+          }
+          iprot.readFieldEnd();
+        }
+        iprot.readStructEnd();
+        struct.validate();
+      }
+
+      public void write(org.apache.thrift.protocol.TProtocol oprot, import_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        struct.validate();
+
+        oprot.writeStructBegin(STRUCT_DESC);
+        if (struct.success != null) {
+          oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
+          struct.success.write(oprot);
+          oprot.writeFieldEnd();
+        }
+        oprot.writeFieldStop();
+        oprot.writeStructEnd();
+      }
+
+    }
+
+    private static class import_sentry_mapping_data_resultTupleSchemeFactory implements SchemeFactory {
+      public import_sentry_mapping_data_resultTupleScheme getScheme() {
+        return new import_sentry_mapping_data_resultTupleScheme();
+      }
+    }
+
+    private static class import_sentry_mapping_data_resultTupleScheme extends TupleScheme<import_sentry_mapping_data_result> {
+
+      @Override
+      public void write(org.apache.thrift.protocol.TProtocol prot, import_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        TTupleProtocol oprot = (TTupleProtocol) prot;
+        BitSet optionals = new BitSet();
+        if (struct.isSetSuccess()) {
+          optionals.set(0);
+        }
+        oprot.writeBitSet(optionals, 1);
+        if (struct.isSetSuccess()) {
+          struct.success.write(oprot);
+        }
+      }
+
+      @Override
+      public void read(org.apache.thrift.protocol.TProtocol prot, import_sentry_mapping_data_result struct) throws org.apache.thrift.TException {
+        TTupleProtocol iprot = (TTupleProtocol) prot;
+        BitSet incoming = iprot.readBitSet(1);
+        if (incoming.get(0)) {
+          struct.success = new TSentryImportMappingDataResponse();
+          struct.success.read(iprot);
+          struct.setSuccessIsSet(true);
+        }
+      }
+    }
+
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataRequest.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataRequest.java b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataRequest.java
new file mode 100644
index 0000000..8145252
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/gen/thrift/gen-javabean/org/apache/sentry/provider/db/service/thrift/TSentryExportMappingDataRequest.java
@@ -0,0 +1,486 @@
+/**
+ * Autogenerated by Thrift Compiler (0.9.0)
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ *  @generated
+ */
+package org.apache.sentry.provider.db.service.thrift;
+
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.thrift.scheme.IScheme;
+import org.apache.thrift.scheme.SchemeFactory;
+import org.apache.thrift.scheme.StandardScheme;
+
+import org.apache.thrift.scheme.TupleScheme;
+import org.apache.thrift.protocol.TTupleProtocol;
+import org.apache.thrift.protocol.TProtocolException;
+import org.apache.thrift.EncodingUtils;
+import org.apache.thrift.TException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.EnumMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.EnumSet;
+import java.util.Collections;
+import java.util.BitSet;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TSentryExportMappingDataRequest implements org.apache.thrift.TBase<TSentryExportMappingDataRequest, TSentryExportMappingDataRequest._Fields>, java.io.Serializable, Cloneable {
+  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TSentryExportMappingDataRequest");
+
+  private static final org.apache.thrift.protocol.TField PROTOCOL_VERSION_FIELD_DESC = new org.apache.thrift.protocol.TField("protocol_version", org.apache.thrift.protocol.TType.I32, (short)1);
+  private static final org.apache.thrift.protocol.TField REQUESTOR_USER_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("requestorUserName", org.apache.thrift.protocol.TType.STRING, (short)2);
+
+  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
+  static {
+    schemes.put(StandardScheme.class, new TSentryExportMappingDataRequestStandardSchemeFactory());
+    schemes.put(TupleScheme.class, new TSentryExportMappingDataRequestTupleSchemeFactory());
+  }
+
+  private int protocol_version; // required
+  private String requestorUserName; // required
+
+  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
+  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
+    PROTOCOL_VERSION((short)1, "protocol_version"),
+    REQUESTOR_USER_NAME((short)2, "requestorUserName");
+
+    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
+
+    static {
+      for (_Fields field : EnumSet.allOf(_Fields.class)) {
+        byName.put(field.getFieldName(), field);
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, or null if its not found.
+     */
+    public static _Fields findByThriftId(int fieldId) {
+      switch(fieldId) {
+        case 1: // PROTOCOL_VERSION
+          return PROTOCOL_VERSION;
+        case 2: // REQUESTOR_USER_NAME
+          return REQUESTOR_USER_NAME;
+        default:
+          return null;
+      }
+    }
+
+    /**
+     * Find the _Fields constant that matches fieldId, throwing an exception
+     * if it is not found.
+     */
+    public static _Fields findByThriftIdOrThrow(int fieldId) {
+      _Fields fields = findByThriftId(fieldId);
+      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
+      return fields;
+    }
+
+    /**
+     * Find the _Fields constant that matches name, or null if its not found.
+     */
+    public static _Fields findByName(String name) {
+      return byName.get(name);
+    }
+
+    private final short _thriftId;
+    private final String _fieldName;
+
+    _Fields(short thriftId, String fieldName) {
+      _thriftId = thriftId;
+      _fieldName = fieldName;
+    }
+
+    public short getThriftFieldId() {
+      return _thriftId;
+    }
+
+    public String getFieldName() {
+      return _fieldName;
+    }
+  }
+
+  // isset id assignments
+  private static final int __PROTOCOL_VERSION_ISSET_ID = 0;
+  private byte __isset_bitfield = 0;
+  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
+  static {
+    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
+    tmpMap.put(_Fields.PROTOCOL_VERSION, new org.apache.thrift.meta_data.FieldMetaData("protocol_version", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
+    tmpMap.put(_Fields.REQUESTOR_USER_NAME, new org.apache.thrift.meta_data.FieldMetaData("requestorUserName", org.apache.thrift.TFieldRequirementType.REQUIRED, 
+        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
+    metaDataMap = Collections.unmodifiableMap(tmpMap);
+    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TSentryExportMappingDataRequest.class, metaDataMap);
+  }
+
+  public TSentryExportMappingDataRequest() {
+    this.protocol_version = 1;
+
+  }
+
+  public TSentryExportMappingDataRequest(
+    int protocol_version,
+    String requestorUserName)
+  {
+    this();
+    this.protocol_version = protocol_version;
+    setProtocol_versionIsSet(true);
+    this.requestorUserName = requestorUserName;
+  }
+
+  /**
+   * Performs a deep copy on <i>other</i>.
+   */
+  public TSentryExportMappingDataRequest(TSentryExportMappingDataRequest other) {
+    __isset_bitfield = other.__isset_bitfield;
+    this.protocol_version = other.protocol_version;
+    if (other.isSetRequestorUserName()) {
+      this.requestorUserName = other.requestorUserName;
+    }
+  }
+
+  public TSentryExportMappingDataRequest deepCopy() {
+    return new TSentryExportMappingDataRequest(this);
+  }
+
+  @Override
+  public void clear() {
+    this.protocol_version = 1;
+
+    this.requestorUserName = null;
+  }
+
+  public int getProtocol_version() {
+    return this.protocol_version;
+  }
+
+  public void setProtocol_version(int protocol_version) {
+    this.protocol_version = protocol_version;
+    setProtocol_versionIsSet(true);
+  }
+
+  public void unsetProtocol_version() {
+    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __PROTOCOL_VERSION_ISSET_ID);
+  }
+
+  /** Returns true if field protocol_version is set (has been assigned a value) and false otherwise */
+  public boolean isSetProtocol_version() {
+    return EncodingUtils.testBit(__isset_bitfield, __PROTOCOL_VERSION_ISSET_ID);
+  }
+
+  public void setProtocol_versionIsSet(boolean value) {
+    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __PROTOCOL_VERSION_ISSET_ID, value);
+  }
+
+  public String getRequestorUserName() {
+    return this.requestorUserName;
+  }
+
+  public void setRequestorUserName(String requestorUserName) {
+    this.requestorUserName = requestorUserName;
+  }
+
+  public void unsetRequestorUserName() {
+    this.requestorUserName = null;
+  }
+
+  /** Returns true if field requestorUserName is set (has been assigned a value) and false otherwise */
+  public boolean isSetRequestorUserName() {
+    return this.requestorUserName != null;
+  }
+
+  public void setRequestorUserNameIsSet(boolean value) {
+    if (!value) {
+      this.requestorUserName = null;
+    }
+  }
+
+  public void setFieldValue(_Fields field, Object value) {
+    switch (field) {
+    case PROTOCOL_VERSION:
+      if (value == null) {
+        unsetProtocol_version();
+      } else {
+        setProtocol_version((Integer)value);
+      }
+      break;
+
+    case REQUESTOR_USER_NAME:
+      if (value == null) {
+        unsetRequestorUserName();
+      } else {
+        setRequestorUserName((String)value);
+      }
+      break;
+
+    }
+  }
+
+  public Object getFieldValue(_Fields field) {
+    switch (field) {
+    case PROTOCOL_VERSION:
+      return Integer.valueOf(getProtocol_version());
+
+    case REQUESTOR_USER_NAME:
+      return getRequestorUserName();
+
+    }
+    throw new IllegalStateException();
+  }
+
+  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
+  public boolean isSet(_Fields field) {
+    if (field == null) {
+      throw new IllegalArgumentException();
+    }
+
+    switch (field) {
+    case PROTOCOL_VERSION:
+      return isSetProtocol_version();
+    case REQUESTOR_USER_NAME:
+      return isSetRequestorUserName();
+    }
+    throw new IllegalStateException();
+  }
+
+  @Override
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof TSentryExportMappingDataRequest)
+      return this.equals((TSentryExportMappingDataRequest)that);
+    return false;
+  }
+
+  public boolean equals(TSentryExportMappingDataRequest that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_protocol_version = true;
+    boolean that_present_protocol_version = true;
+    if (this_present_protocol_version || that_present_protocol_version) {
+      if (!(this_present_protocol_version && that_present_protocol_version))
+        return false;
+      if (this.protocol_version != that.protocol_version)
+        return false;
+    }
+
+    boolean this_present_requestorUserName = true && this.isSetRequestorUserName();
+    boolean that_present_requestorUserName = true && that.isSetRequestorUserName();
+    if (this_present_requestorUserName || that_present_requestorUserName) {
+      if (!(this_present_requestorUserName && that_present_requestorUserName))
+        return false;
+      if (!this.requestorUserName.equals(that.requestorUserName))
+        return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    HashCodeBuilder builder = new HashCodeBuilder();
+
+    boolean present_protocol_version = true;
+    builder.append(present_protocol_version);
+    if (present_protocol_version)
+      builder.append(protocol_version);
+
+    boolean present_requestorUserName = true && (isSetRequestorUserName());
+    builder.append(present_requestorUserName);
+    if (present_requestorUserName)
+      builder.append(requestorUserName);
+
+    return builder.toHashCode();
+  }
+
+  public int compareTo(TSentryExportMappingDataRequest other) {
+    if (!getClass().equals(other.getClass())) {
+      return getClass().getName().compareTo(other.getClass().getName());
+    }
+
+    int lastComparison = 0;
+    TSentryExportMappingDataRequest typedOther = (TSentryExportMappingDataRequest)other;
+
+    lastComparison = Boolean.valueOf(isSetProtocol_version()).compareTo(typedOther.isSetProtocol_version());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetProtocol_version()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.protocol_version, typedOther.protocol_version);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    lastComparison = Boolean.valueOf(isSetRequestorUserName()).compareTo(typedOther.isSetRequestorUserName());
+    if (lastComparison != 0) {
+      return lastComparison;
+    }
+    if (isSetRequestorUserName()) {
+      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.requestorUserName, typedOther.requestorUserName);
+      if (lastComparison != 0) {
+        return lastComparison;
+      }
+    }
+    return 0;
+  }
+
+  public _Fields fieldForId(int fieldId) {
+    return _Fields.findByThriftId(fieldId);
+  }
+
+  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
+    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
+  }
+
+  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
+    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder("TSentryExportMappingDataRequest(");
+    boolean first = true;
+
+    sb.append("protocol_version:");
+    sb.append(this.protocol_version);
+    first = false;
+    if (!first) sb.append(", ");
+    sb.append("requestorUserName:");
+    if (this.requestorUserName == null) {
+      sb.append("null");
+    } else {
+      sb.append(this.requestorUserName);
+    }
+    first = false;
+    sb.append(")");
+    return sb.toString();
+  }
+
+  public void validate() throws org.apache.thrift.TException {
+    // check for required fields
+    if (!isSetProtocol_version()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'protocol_version' is unset! Struct:" + toString());
+    }
+
+    if (!isSetRequestorUserName()) {
+      throw new org.apache.thrift.protocol.TProtocolException("Required field 'requestorUserName' is unset! Struct:" + toString());
+    }
+
+    // check for sub-struct validity
+  }
+
+  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
+    try {
+      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
+    try {
+      // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
+      __isset_bitfield = 0;
+      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
+    } catch (org.apache.thrift.TException te) {
+      throw new java.io.IOException(te);
+    }
+  }
+
+  private static class TSentryExportMappingDataRequestStandardSchemeFactory implements SchemeFactory {
+    public TSentryExportMappingDataRequestStandardScheme getScheme() {
+      return new TSentryExportMappingDataRequestStandardScheme();
+    }
+  }
+
+  private static class TSentryExportMappingDataRequestStandardScheme extends StandardScheme<TSentryExportMappingDataRequest> {
+
+    public void read(org.apache.thrift.protocol.TProtocol iprot, TSentryExportMappingDataRequest struct) throws org.apache.thrift.TException {
+      org.apache.thrift.protocol.TField schemeField;
+      iprot.readStructBegin();
+      while (true)
+      {
+        schemeField = iprot.readFieldBegin();
+        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
+          break;
+        }
+        switch (schemeField.id) {
+          case 1: // PROTOCOL_VERSION
+            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
+              struct.protocol_version = iprot.readI32();
+              struct.setProtocol_versionIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          case 2: // REQUESTOR_USER_NAME
+            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
+              struct.requestorUserName = iprot.readString();
+              struct.setRequestorUserNameIsSet(true);
+            } else { 
+              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+            }
+            break;
+          default:
+            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+        }
+        iprot.readFieldEnd();
+      }
+      iprot.readStructEnd();
+      struct.validate();
+    }
+
+    public void write(org.apache.thrift.protocol.TProtocol oprot, TSentryExportMappingDataRequest struct) throws org.apache.thrift.TException {
+      struct.validate();
+
+      oprot.writeStructBegin(STRUCT_DESC);
+      oprot.writeFieldBegin(PROTOCOL_VERSION_FIELD_DESC);
+      oprot.writeI32(struct.protocol_version);
+      oprot.writeFieldEnd();
+      if (struct.requestorUserName != null) {
+        oprot.writeFieldBegin(REQUESTOR_USER_NAME_FIELD_DESC);
+        oprot.writeString(struct.requestorUserName);
+        oprot.writeFieldEnd();
+      }
+      oprot.writeFieldStop();
+      oprot.writeStructEnd();
+    }
+
+  }
+
+  private static class TSentryExportMappingDataRequestTupleSchemeFactory implements SchemeFactory {
+    public TSentryExportMappingDataRequestTupleScheme getScheme() {
+      return new TSentryExportMappingDataRequestTupleScheme();
+    }
+  }
+
+  private static class TSentryExportMappingDataRequestTupleScheme extends TupleScheme<TSentryExportMappingDataRequest> {
+
+    @Override
+    public void write(org.apache.thrift.protocol.TProtocol prot, TSentryExportMappingDataRequest struct) throws org.apache.thrift.TException {
+      TTupleProtocol oprot = (TTupleProtocol) prot;
+      oprot.writeI32(struct.protocol_version);
+      oprot.writeString(struct.requestorUserName);
+    }
+
+    @Override
+    public void read(org.apache.thrift.protocol.TProtocol prot, TSentryExportMappingDataRequest struct) throws org.apache.thrift.TException {
+      TTupleProtocol iprot = (TTupleProtocol) prot;
+      struct.protocol_version = iprot.readI32();
+      struct.setProtocol_versionIsSet(true);
+      struct.requestorUserName = iprot.readString();
+      struct.setRequestorUserNameIsSet(true);
+    }
+  }
+
+}
+


[2/6] incubator-sentry git commit: SENTRY-197: Create tool to dump and load of entire Sentry service (Colin Ma, Reviewed by:Sravya Tirukkovalur, Guoquan Shen, Dapeng Sun, Anne Yu)

Posted by co...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java
new file mode 100644
index 0000000..9350a50
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/persistent/TestSentryStoreImportExport.java
@@ -0,0 +1,899 @@
+/**
+ * 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.provider.db.service.persistent;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.sentry.core.model.db.AccessConstants;
+import org.apache.sentry.provider.db.service.model.MSentryGroup;
+import org.apache.sentry.provider.db.service.model.MSentryPrivilege;
+import org.apache.sentry.provider.db.service.model.MSentryRole;
+import org.apache.sentry.provider.db.service.thrift.TSentryGrantOption;
+import org.apache.sentry.provider.db.service.thrift.TSentryMappingData;
+import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege;
+import org.apache.sentry.provider.file.PolicyFile;
+import org.apache.sentry.service.thrift.ServiceConstants.PrivilegeScope;
+import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.io.Files;
+
+public class TestSentryStoreImportExport {
+
+  private static File dataDir;
+  private static SentryStore sentryStore;
+  private static String[] adminGroups = { "adminGroup1" };
+  private static PolicyFile policyFile;
+  private static File policyFilePath;
+  private TSentryPrivilege tSentryPrivilege1;
+  private TSentryPrivilege tSentryPrivilege2;
+  private TSentryPrivilege tSentryPrivilege3;
+  private TSentryPrivilege tSentryPrivilege4;
+  private TSentryPrivilege tSentryPrivilege5;
+  private TSentryPrivilege tSentryPrivilege6;
+  private TSentryPrivilege tSentryPrivilege7;
+  private TSentryPrivilege tSentryPrivilege8;
+
+  @BeforeClass
+  public static void setupEnv() throws Exception {
+    dataDir = new File(Files.createTempDir(), "sentry_policy_db");
+    Configuration conf = new Configuration(false);
+    conf.set(ServerConfig.SENTRY_VERIFY_SCHEM_VERSION, "false");
+    conf.set(ServerConfig.SENTRY_STORE_JDBC_URL, "jdbc:derby:;databaseName=" + dataDir.getPath()
+        + ";create=true");
+    conf.set(ServerConfig.SENTRY_STORE_JDBC_PASS, "sentry");
+    conf.setStrings(ServerConfig.ADMIN_GROUPS, adminGroups);
+    conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING, ServerConfig.SENTRY_STORE_LOCAL_GROUP_MAPPING);
+    policyFilePath = new File(dataDir, "local_policy_file.ini");
+    conf.set(ServerConfig.SENTRY_STORE_GROUP_MAPPING_RESOURCE, policyFilePath.getPath());
+    policyFile = new PolicyFile();
+    sentryStore = new SentryStore(conf);
+
+    String adminUser = "g1";
+    addGroupsToUser(adminUser, adminGroups);
+    writePolicyFile();
+  }
+
+  @Before
+  public void setupPrivilege() {
+    preparePrivilege();
+  }
+
+  @After
+  public void clearStore() {
+    sentryStore.clearAllTables();
+  }
+
+  // create the privileges instance for test case:
+  // privilege1=[server=server1]
+  // privilege2=[server=server1, action=select, grantOption=false]
+  // privilege3=[server=server1, db=db2, action=insert, grantOption=true]
+  // privilege4=[server=server1, db=db1, table=tbl1, action=insert, grantOption=false]
+  // privilege5=[server=server1, db=db1, table=tbl2, column=col1, action=insert, grantOption=false]
+  // privilege6=[server=server1, db=db1, table=tbl3, column=col1, action=*, grantOption=true]
+  // privilege7=[server=server1, db=db1, table=tbl4, column=col1, action=all, grantOption=true]
+  // privilege8=[server=server1, uri=hdfs://testserver:9999/path1, action=insert, grantOption=false]
+  private void preparePrivilege() {
+    tSentryPrivilege1 = createTSentryPrivilege(PrivilegeScope.SERVER.name(), "server1", "", "", "",
+        "", "", TSentryGrantOption.UNSET);
+    tSentryPrivilege2 = createTSentryPrivilege(PrivilegeScope.SERVER.name(), "server1", "", "", "",
+        "", AccessConstants.SELECT, TSentryGrantOption.FALSE);
+    tSentryPrivilege3 = createTSentryPrivilege(PrivilegeScope.DATABASE.name(), "server1", "db2",
+        "", "", "", AccessConstants.INSERT, TSentryGrantOption.TRUE);
+    tSentryPrivilege4 = createTSentryPrivilege(PrivilegeScope.TABLE.name(), "server1", "db1",
+        "tbl1", "", "", AccessConstants.INSERT, TSentryGrantOption.FALSE);
+    tSentryPrivilege5 = createTSentryPrivilege(PrivilegeScope.COLUMN.name(), "server1", "db1",
+        "tbl2", "col1", "", AccessConstants.INSERT, TSentryGrantOption.FALSE);
+    tSentryPrivilege6 = createTSentryPrivilege(PrivilegeScope.COLUMN.name(), "server1", "db1",
+        "tbl3", "col1", "", AccessConstants.ALL, TSentryGrantOption.TRUE);
+    tSentryPrivilege7 = createTSentryPrivilege(PrivilegeScope.COLUMN.name(), "server1", "db1",
+        "tbl4", "col1", "", AccessConstants.ACTION_ALL, TSentryGrantOption.TRUE);
+    tSentryPrivilege8 = createTSentryPrivilege(PrivilegeScope.URI.name(), "server1", "", "", "",
+        "hdfs://testserver:9999/path1", AccessConstants.INSERT, TSentryGrantOption.FALSE);
+  }
+
+  @AfterClass
+  public static void teardown() {
+    if (sentryStore != null) {
+      sentryStore.stop();
+    }
+    if (dataDir != null) {
+      FileUtils.deleteQuietly(dataDir);
+    }
+  }
+
+  protected static void addGroupsToUser(String user, String... groupNames) {
+    policyFile.addGroupsToUser(user, groupNames);
+  }
+
+  protected static void writePolicyFile() throws Exception {
+    policyFile.write(policyFilePath);
+  }
+
+  // Befor import, database is empty.
+  // The following information is imported:
+  // group1=role1,role2,role3
+  // group2=role1,role2,role3
+  // group3=role1,role2,role3
+  // role1=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+  // role2=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+  // role3=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+  // Both import API importSentryMetaData and export APIs getRolesMap, getGroupsMap,
+  // getPrivilegesList are tested.
+  @Test
+  public void testImportExportPolicy1() throws Exception {
+    TSentryMappingData tSentryMappingData = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap = Maps.newHashMap();
+    sentryGroupRolesMap.put("group1", Sets.newHashSet("Role1", "role2", "role3"));
+    sentryGroupRolesMap.put("group2", Sets.newHashSet("Role1", "role2", "role3"));
+    sentryGroupRolesMap.put("group3", Sets.newHashSet("Role1", "role2", "role3"));
+    sentryRolePrivilegesMap.put("Role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+    sentryRolePrivilegesMap.put("role2", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+    sentryRolePrivilegesMap.put("role3", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+    tSentryMappingData.setGroupRolesMap(sentryGroupRolesMap);
+    tSentryMappingData.setRolePrivilegesMap(sentryRolePrivilegesMap);
+    sentryStore.importSentryMetaData(tSentryMappingData, false);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2", "role3"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1", "group2", "group3"));
+
+    // test the result data for the privilege
+    verifyPrivileges(privilegesList, Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1", "role2", "role3"));
+    exceptedGroupRolesMap.put("group2", Sets.newHashSet("role1", "role2", "role3"));
+    exceptedGroupRolesMap.put("group3", Sets.newHashSet("role1", "role2", "role3"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    Map<String, Set<TSentryPrivilege>> exceptedRolePrivilegesMap = Maps.newHashMap();
+    exceptedRolePrivilegesMap.put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+    exceptedRolePrivilegesMap.put("role2", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+    exceptedRolePrivilegesMap.put("role3", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+
+    verifyRolePrivilegesMap(actualRolePrivilegesMap, exceptedRolePrivilegesMap);
+  }
+
+  // call import twice, and there has no duplicate data:
+  // The data for 1st import:
+  // group1=role1
+  // role1=privilege1,privilege2,privilege3,privilege4
+  // The data for 2nd import:
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege5,privilege6,privilege7,privilege8
+  // role3=privilege5,privilege6,privilege7,privilege8
+  // Both import API importSentryMetaData and export APIs getRolesMap, getGroupsMap,
+  // getPrivilegesList are tested.
+  @Test
+  public void testImportExportPolicy2() throws Exception {
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1"));
+    sentryRolePrivilegesMap1
+        .put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2, tSentryPrivilege3,
+            tSentryPrivilege4));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    sentryStore.importSentryMetaData(tSentryMappingData1, false);
+
+    TSentryMappingData tSentryMappingData2 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap2 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap2 = Maps.newHashMap();
+    sentryGroupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+    sentryGroupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+    sentryRolePrivilegesMap2
+        .put("role2", Sets.newHashSet(tSentryPrivilege5, tSentryPrivilege6, tSentryPrivilege7,
+            tSentryPrivilege8));
+    sentryRolePrivilegesMap2
+        .put("role3", Sets.newHashSet(tSentryPrivilege5, tSentryPrivilege6, tSentryPrivilege7,
+            tSentryPrivilege8));
+    tSentryMappingData2.setGroupRolesMap(sentryGroupRolesMap2);
+    tSentryMappingData2.setRolePrivilegesMap(sentryRolePrivilegesMap2);
+    sentryStore.importSentryMetaData(tSentryMappingData2, false);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2", "role3"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1", "group2", "group3"));
+
+    // test the result data for the privilege
+    verifyPrivileges(privilegesList, Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1"));
+    exceptedGroupRolesMap.put("group2", Sets.newHashSet("role2", "role3"));
+    exceptedGroupRolesMap.put("group3", Sets.newHashSet("role2", "role3"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    Map<String, Set<TSentryPrivilege>> exceptedRolePrivilegesMap = Maps.newHashMap();
+    exceptedRolePrivilegesMap
+        .put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2, tSentryPrivilege3,
+            tSentryPrivilege4));
+    exceptedRolePrivilegesMap
+        .put("role2", Sets.newHashSet(tSentryPrivilege5, tSentryPrivilege6, tSentryPrivilege7,
+            tSentryPrivilege8));
+    exceptedRolePrivilegesMap
+        .put("role3", Sets.newHashSet(tSentryPrivilege5, tSentryPrivilege6, tSentryPrivilege7,
+            tSentryPrivilege8));
+    verifyRolePrivilegesMap(actualRolePrivilegesMap, exceptedRolePrivilegesMap);
+  }
+
+  // call import twice, and there has data overlap:
+  // The data for 1st import:
+  // group1=role1, role2
+  // group2=role1, role2
+  // group3=role1, role2
+  // role1=privilege1,privilege2,privilege3,privilege4,privilege5
+  // role2=privilege1,privilege2,privilege3,privilege4,privilege5
+  // The data for 2nd import:
+  // group1=role2,role3
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege4,privilege5,privilege6,privilege7,privilege8
+  // role3=privilege4,privilege5,privilege6,privilege7,privilege8
+  // Both import API importSentryMetaData and export APIs getRolesMap, getGroupsMap,
+  // getPrivilegesList are tested.
+  @Test
+  public void testImportExportPolicy3() throws Exception {
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+    sentryGroupRolesMap1.put("group2", Sets.newHashSet("role1", "role2"));
+    sentryGroupRolesMap1.put("group3", Sets.newHashSet("role1", "role2"));
+    sentryRolePrivilegesMap1.put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5));
+    sentryRolePrivilegesMap1.put("role2", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    sentryStore.importSentryMetaData(tSentryMappingData1, false);
+
+    TSentryMappingData tSentryMappingData2 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap2 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap2 = Maps.newHashMap();
+    sentryGroupRolesMap2.put("group1", Sets.newHashSet("role2", "role3"));
+    sentryGroupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+    sentryGroupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+    sentryRolePrivilegesMap2.put("role2", Sets.newHashSet(tSentryPrivilege4, tSentryPrivilege5,
+        tSentryPrivilege6, tSentryPrivilege7, tSentryPrivilege8));
+    sentryRolePrivilegesMap2.put("role3", Sets.newHashSet(tSentryPrivilege4, tSentryPrivilege5,
+        tSentryPrivilege6, tSentryPrivilege7, tSentryPrivilege8));
+    tSentryMappingData2.setGroupRolesMap(sentryGroupRolesMap2);
+    tSentryMappingData2.setRolePrivilegesMap(sentryRolePrivilegesMap2);
+    sentryStore.importSentryMetaData(tSentryMappingData2, false);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2", "role3"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1", "group2", "group3"));
+
+    // test the result data for the privilege
+    verifyPrivileges(privilegesList, Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1", "role2", "role3"));
+    exceptedGroupRolesMap.put("group2", Sets.newHashSet("role1", "role2", "role3"));
+    exceptedGroupRolesMap.put("group3", Sets.newHashSet("role1", "role2", "role3"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    Map<String, Set<TSentryPrivilege>> exceptedRolePrivilegesMap = Maps.newHashMap();
+    exceptedRolePrivilegesMap.put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5));
+    exceptedRolePrivilegesMap.put("role2", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+    exceptedRolePrivilegesMap.put("role3", Sets.newHashSet(tSentryPrivilege4, tSentryPrivilege5,
+        tSentryPrivilege6, tSentryPrivilege7, tSentryPrivilege8));
+    verifyRolePrivilegesMap(actualRolePrivilegesMap, exceptedRolePrivilegesMap);
+  }
+
+  // call import twice, and there has one role without group.
+  // The data for 1st import:
+  // group1=role1, role2
+  // role1=privilege1,privilege2
+  // role2=privilege3,privilege4
+  // The data for 2nd import:
+  // group2=role2
+  // role2=privilege5,privilege6
+  // role3=privilege7,privilege8
+  // role3 is without group, will be imported also
+  @Test
+  public void testImportExportPolicy4() throws Exception {
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+    sentryRolePrivilegesMap1.put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2));
+    sentryRolePrivilegesMap1.put("role2", Sets.newHashSet(tSentryPrivilege3, tSentryPrivilege4));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    sentryStore.importSentryMetaData(tSentryMappingData1, false);
+
+    TSentryMappingData tSentryMappingData2 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap2 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap2 = Maps.newHashMap();
+    sentryGroupRolesMap2.put("group2", Sets.newHashSet("role2"));
+    sentryRolePrivilegesMap2.put("role2", Sets.newHashSet(tSentryPrivilege5, tSentryPrivilege6));
+    sentryRolePrivilegesMap2.put("role3", Sets.newHashSet(tSentryPrivilege7, tSentryPrivilege8));
+    tSentryMappingData2.setGroupRolesMap(sentryGroupRolesMap2);
+    tSentryMappingData2.setRolePrivilegesMap(sentryRolePrivilegesMap2);
+    sentryStore.importSentryMetaData(tSentryMappingData2, false);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2", "role3"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1", "group2"));
+
+    // test the result data for the privilege
+    verifyPrivileges(privilegesList, Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1", "role2"));
+    exceptedGroupRolesMap.put("group2", Sets.newHashSet("role2"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    Map<String, Set<TSentryPrivilege>> exceptedRolePrivilegesMap = Maps.newHashMap();
+    exceptedRolePrivilegesMap.put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2));
+    exceptedRolePrivilegesMap
+        .put("role2", Sets.newHashSet(tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5,
+            tSentryPrivilege6));
+    exceptedRolePrivilegesMap.put("role3", Sets.newHashSet(tSentryPrivilege7, tSentryPrivilege8));
+    verifyRolePrivilegesMap(actualRolePrivilegesMap, exceptedRolePrivilegesMap);
+  }
+
+  // test for import mapping data for [group,role] only:
+  // group1=role1, role2
+  @Test
+  public void testImportExportPolicy5() throws Exception {
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    sentryStore.importSentryMetaData(tSentryMappingData1, false);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1"));
+
+    // test the result data for the privilege
+    assertTrue(privilegesList.isEmpty());
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1", "role2"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    assertTrue(actualRolePrivilegesMap.isEmpty());
+  }
+
+  // test for filter the orphaned group:
+  // group1=role1, role2
+  // group2=role2
+  @Test
+  public void testImportExportPolicy6() throws Exception {
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+    sentryGroupRolesMap1.put("group2", Sets.newHashSet("role2"));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    sentryStore.importSentryMetaData(tSentryMappingData1, false);
+
+    // drop the role2, the group2 is orphaned group
+    sentryStore.dropSentryRole("role2");
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1", "group2"));
+
+    // test the result data for the privilege
+    assertTrue(privilegesList.isEmpty());
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    assertTrue(actualRolePrivilegesMap.isEmpty());
+  }
+
+  // call import twice, and there has no duplicate data, the import will be with the overwrite mode:
+  // The data for 1st import:
+  // group1=role1
+  // role1=privilege1
+  // The data for 2nd import:
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege2
+  // role3=privilege2
+  // Both import API importSentryMetaData and export APIs getRolesMap, getGroupsMap,
+  // getPrivilegesList are tested.
+  @Test
+  public void testImportExportPolicy7() throws Exception {
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1"));
+    sentryRolePrivilegesMap1.put("role1", Sets.newHashSet(tSentryPrivilege1));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    // the import with overwrite mode
+    sentryStore.importSentryMetaData(tSentryMappingData1, true);
+
+    TSentryMappingData tSentryMappingData2 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap2 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap2 = Maps.newHashMap();
+    sentryGroupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+    sentryGroupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+    sentryRolePrivilegesMap2.put("role2", Sets.newHashSet(tSentryPrivilege2));
+    sentryRolePrivilegesMap2.put("role3", Sets.newHashSet(tSentryPrivilege2));
+    tSentryMappingData2.setGroupRolesMap(sentryGroupRolesMap2);
+    tSentryMappingData2.setRolePrivilegesMap(sentryRolePrivilegesMap2);
+    // the import with overwrite mode
+    sentryStore.importSentryMetaData(tSentryMappingData2, true);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2", "role3"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1", "group2", "group3"));
+
+    // test the result data for the privilege
+    verifyPrivileges(privilegesList, Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2));
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1"));
+    exceptedGroupRolesMap.put("group2", Sets.newHashSet("role2", "role3"));
+    exceptedGroupRolesMap.put("group3", Sets.newHashSet("role2", "role3"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    Map<String, Set<TSentryPrivilege>> exceptedRolePrivilegesMap = Maps.newHashMap();
+    exceptedRolePrivilegesMap.put("role1", Sets.newHashSet(tSentryPrivilege1));
+    exceptedRolePrivilegesMap.put("role2", Sets.newHashSet(tSentryPrivilege2));
+    exceptedRolePrivilegesMap.put("role3", Sets.newHashSet(tSentryPrivilege2));
+    verifyRolePrivilegesMap(actualRolePrivilegesMap, exceptedRolePrivilegesMap);
+  }
+
+  // call import twice, and there has data overlap, the import will be with the overwrite mode:
+  // The data for 1st import:
+  // group1=role1, role2
+  // group2=role1, role2
+  // group3=role1, role2
+  // role1=privilege1,privilege2,privilege3,privilege4,privilege5
+  // role2=privilege1,privilege2,privilege3,privilege4,privilege5
+  // The data for 2nd import:
+  // group1=role2,role3
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege4,privilege5,privilege6,privilege7,privilege8
+  // role3=privilege4,privilege5,privilege6,privilege7,privilege8
+  // Both import API importSentryMetaData and export APIs getRolesMap, getGroupsMap,
+  // getPrivilegesList are tested.
+  @Test
+  public void testImportExportPolicy8() throws Exception {
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+    sentryGroupRolesMap1.put("group2", Sets.newHashSet("role1", "role2"));
+    sentryGroupRolesMap1.put("group3", Sets.newHashSet("role1", "role2"));
+    sentryRolePrivilegesMap1.put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5));
+    sentryRolePrivilegesMap1.put("role2", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    // the import with overwrite mode
+    sentryStore.importSentryMetaData(tSentryMappingData1, true);
+
+    TSentryMappingData tSentryMappingData2 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap2 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap2 = Maps.newHashMap();
+    sentryGroupRolesMap2.put("group1", Sets.newHashSet("role2", "role3"));
+    sentryGroupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+    sentryGroupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+    sentryRolePrivilegesMap2.put("role2", Sets.newHashSet(tSentryPrivilege4, tSentryPrivilege5,
+        tSentryPrivilege6, tSentryPrivilege7, tSentryPrivilege8));
+    sentryRolePrivilegesMap2.put("role3", Sets.newHashSet(tSentryPrivilege4, tSentryPrivilege5,
+        tSentryPrivilege6, tSentryPrivilege7, tSentryPrivilege8));
+    tSentryMappingData2.setGroupRolesMap(sentryGroupRolesMap2);
+    tSentryMappingData2.setRolePrivilegesMap(sentryRolePrivilegesMap2);
+    // the import with overwrite mode
+    sentryStore.importSentryMetaData(tSentryMappingData2, true);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+    List<MSentryPrivilege> privilegesList = sentryStore.getPrivilegesList();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2", "role3"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1", "group2", "group3"));
+
+    // test the result data for the privilege
+    verifyPrivileges(privilegesList, Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5, tSentryPrivilege6,
+        tSentryPrivilege7, tSentryPrivilege8));
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1", "role2", "role3"));
+    exceptedGroupRolesMap.put("group2", Sets.newHashSet("role1", "role2", "role3"));
+    exceptedGroupRolesMap.put("group3", Sets.newHashSet("role1", "role2", "role3"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    Map<String, Set<TSentryPrivilege>> exceptedRolePrivilegesMap = Maps.newHashMap();
+    exceptedRolePrivilegesMap.put("role1", Sets.newHashSet(tSentryPrivilege1, tSentryPrivilege2,
+        tSentryPrivilege3, tSentryPrivilege4, tSentryPrivilege5));
+    // role2 should be overwrite
+    exceptedRolePrivilegesMap.put("role2", Sets.newHashSet(tSentryPrivilege4, tSentryPrivilege5,
+        tSentryPrivilege6, tSentryPrivilege7, tSentryPrivilege8));
+    exceptedRolePrivilegesMap.put("role3", Sets.newHashSet(tSentryPrivilege4, tSentryPrivilege5,
+        tSentryPrivilege6, tSentryPrivilege7, tSentryPrivilege8));
+    verifyRolePrivilegesMap(actualRolePrivilegesMap, exceptedRolePrivilegesMap);
+  }
+
+  // test the import privileges with the action: All, *, select, insert
+  // All and * should replace the select and insert
+  // The data for import:
+  // group1=role1, role2
+  // role1=testPrivilege1,testPrivilege2,testPrivilege3,testPrivilege4
+  // role2=testPrivilege5, testPrivilege6,testPrivilege7,testPrivilege8
+  @Test
+  public void testImportExportPolicy9() throws Exception {
+    TSentryPrivilege testPrivilege1 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl1", "", "", AccessConstants.SELECT, TSentryGrantOption.TRUE);
+    TSentryPrivilege testPrivilege2 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl1", "", "", AccessConstants.INSERT, TSentryGrantOption.FALSE);
+    TSentryPrivilege testPrivilege3 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl1", "", "", AccessConstants.ACTION_ALL, TSentryGrantOption.TRUE);
+    TSentryPrivilege testPrivilege4 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl1", "", "", AccessConstants.INSERT, TSentryGrantOption.TRUE);
+    TSentryPrivilege testPrivilege5 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl2", "", "", AccessConstants.SELECT, TSentryGrantOption.TRUE);
+    TSentryPrivilege testPrivilege6 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl2", "", "", AccessConstants.INSERT, TSentryGrantOption.FALSE);
+    TSentryPrivilege testPrivilege7 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl2", "", "", AccessConstants.ALL, TSentryGrantOption.TRUE);
+    TSentryPrivilege testPrivilege8 = createTSentryPrivilege(PrivilegeScope.TABLE.name(),
+        "server1", "db1", "tbl2", "", "", AccessConstants.INSERT, TSentryGrantOption.TRUE);
+
+    TSentryMappingData tSentryMappingData1 = new TSentryMappingData();
+    Map<String, Set<String>> sentryGroupRolesMap1 = Maps.newHashMap();
+    Map<String, Set<TSentryPrivilege>> sentryRolePrivilegesMap1 = Maps.newHashMap();
+    sentryGroupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+    // after import there should be only testPrivilege2, testPrivilege3
+    sentryRolePrivilegesMap1.put("role1",
+        Sets.newHashSet(testPrivilege1, testPrivilege2, testPrivilege3, testPrivilege4));
+    // after import there should be only testPrivilege6,testPrivilege7
+    sentryRolePrivilegesMap1.put("role2",
+        Sets.newHashSet(testPrivilege5, testPrivilege6, testPrivilege7, testPrivilege8));
+    tSentryMappingData1.setGroupRolesMap(sentryGroupRolesMap1);
+    tSentryMappingData1.setRolePrivilegesMap(sentryRolePrivilegesMap1);
+    // the import with overwrite mode
+    sentryStore.importSentryMetaData(tSentryMappingData1, true);
+
+    Map<String, MSentryRole> rolesMap = sentryStore.getRolesMap();
+    Map<String, MSentryGroup> groupsMap = sentryStore.getGroupNameTGroupMap();
+
+    // test the result data for the role
+    verifyRoles(rolesMap, Sets.newHashSet("role1", "role2"));
+
+    // test the result data for the group
+    verifyGroups(groupsMap, Sets.newHashSet("group1"));
+
+    // test the mapping data for group and role
+    Map<String, Set<String>> actualGroupRolesMap = sentryStore.getGroupNameRoleNamesMap();
+    Map<String, Set<String>> exceptedGroupRolesMap = Maps.newHashMap();
+    exceptedGroupRolesMap.put("group1", Sets.newHashSet("role1", "role2"));
+    verifyGroupRolesMap(actualGroupRolesMap, exceptedGroupRolesMap);
+
+    // test the mapping data for role and privilege
+    Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap = sentryStore
+        .getRoleNameTPrivilegesMap();
+    Map<String, Set<TSentryPrivilege>> exceptedRolePrivilegesMap = Maps.newHashMap();
+    exceptedRolePrivilegesMap.put("role1", Sets.newHashSet(testPrivilege2, testPrivilege3));
+    exceptedRolePrivilegesMap.put("role2", Sets.newHashSet(testPrivilege6, testPrivilege7));
+    verifyRolePrivilegesMap(actualRolePrivilegesMap, exceptedRolePrivilegesMap);
+  }
+
+  private void verifyRoles(Map<String, MSentryRole> actualRoleMap, Set<String> expectedRoleNameSet) {
+    assertEquals(expectedRoleNameSet.size(), actualRoleMap.keySet().size());
+    for (String roleName : actualRoleMap.keySet()) {
+      assertTrue(expectedRoleNameSet.contains(roleName));
+    }
+  }
+
+  private void verifyGroups(Map<String, MSentryGroup> actualGroupsMap,
+      Set<String> expectedGroupNameSet) {
+    assertEquals(expectedGroupNameSet.size(), actualGroupsMap.keySet().size());
+    for (String groupName : actualGroupsMap.keySet()) {
+      assertTrue(expectedGroupNameSet.contains(groupName));
+    }
+  }
+
+  private void verifyPrivileges(List<MSentryPrivilege> actualPrivileges,
+      Set<TSentryPrivilege> expectedTSentryPrivilegeSet) {
+    assertEquals(expectedTSentryPrivilegeSet.size(), actualPrivileges.size());
+    for (MSentryPrivilege mSentryPrivilege : actualPrivileges) {
+      boolean isFound = false;
+      for (TSentryPrivilege tSentryPrivilege : expectedTSentryPrivilegeSet) {
+        isFound = compareTSentryPrivilege(sentryStore.convertToTSentryPrivilege(mSentryPrivilege),
+            tSentryPrivilege);
+        if (isFound) {
+          break;
+        }
+      }
+      assertTrue(isFound);
+    }
+  }
+
+  private void verifyGroupRolesMap(Map<String, Set<String>> actualGroupRolesMap,
+      Map<String, Set<String>> exceptedGroupRolesMap) {
+    assertEquals(exceptedGroupRolesMap.keySet().size(), actualGroupRolesMap.keySet().size());
+    for (String groupName : actualGroupRolesMap.keySet()) {
+      Set<String> exceptedRoles = exceptedGroupRolesMap.get(groupName);
+      Set<String> actualRoles = actualGroupRolesMap.get(groupName);
+      assertEquals(actualRoles.size(), exceptedRoles.size());
+      assertTrue(actualRoles.equals(exceptedRoles));
+    }
+  }
+
+  private void verifyRolePrivilegesMap(Map<String, Set<TSentryPrivilege>> actualRolePrivilegesMap,
+      Map<String, Set<TSentryPrivilege>> expectedRolePrivilegesMap) {
+    assertEquals(expectedRolePrivilegesMap.keySet().size(), actualRolePrivilegesMap.keySet().size());
+    for (String roleName : expectedRolePrivilegesMap.keySet()) {
+      Set<TSentryPrivilege> exceptedTSentryPrivileges = expectedRolePrivilegesMap.get(roleName);
+      Set<TSentryPrivilege> actualTSentryPrivileges = actualRolePrivilegesMap.get(roleName);
+      assertEquals(exceptedTSentryPrivileges.size(), actualTSentryPrivileges.size());
+      for (TSentryPrivilege actualPrivilege : actualTSentryPrivileges) {
+        boolean isFound = false;
+        for (TSentryPrivilege expectedPrivilege : exceptedTSentryPrivileges) {
+          isFound = compareTSentryPrivilege(expectedPrivilege, actualPrivilege);
+          if (isFound) {
+            break;
+          }
+        }
+        assertTrue(isFound);
+      }
+    }
+  }
+
+  private TSentryPrivilege createTSentryPrivilege(String scope, String server, String dbName,
+      String tableName, String columnName, String uri, String action, TSentryGrantOption grantOption) {
+    TSentryPrivilege tSentryPrivilege = new TSentryPrivilege();
+    tSentryPrivilege.setPrivilegeScope(scope);
+    tSentryPrivilege.setServerName(server);
+    tSentryPrivilege.setDbName(dbName);
+    tSentryPrivilege.setTableName(tableName);
+    tSentryPrivilege.setColumnName(columnName);
+    tSentryPrivilege.setURI(uri);
+    tSentryPrivilege.setAction(action);
+    tSentryPrivilege.setGrantOption(grantOption);
+    return tSentryPrivilege;
+  }
+
+  // compare the TSentryPrivilege without the create time
+  private boolean compareTSentryPrivilege(TSentryPrivilege tSentryPrivilege1,
+      TSentryPrivilege tSentryPrivilege2) {
+    if (tSentryPrivilege1 == null) {
+      if (tSentryPrivilege2 == null) {
+        return true;
+      } else {
+        return false;
+      }
+    } else {
+      if (tSentryPrivilege2 == null) {
+        return false;
+      }
+    }
+
+    boolean this_present_privilegeScope = true && tSentryPrivilege1.isSetPrivilegeScope();
+    boolean that_present_privilegeScope = true && tSentryPrivilege2.isSetPrivilegeScope();
+    if (this_present_privilegeScope || that_present_privilegeScope) {
+      if (!(this_present_privilegeScope && that_present_privilegeScope))
+        return false;
+      if (!tSentryPrivilege1.getPrivilegeScope().equalsIgnoreCase(
+          tSentryPrivilege2.getPrivilegeScope()))
+        return false;
+    }
+
+    boolean this_present_serverName = true && tSentryPrivilege1.isSetServerName();
+    boolean that_present_serverName = true && tSentryPrivilege2.isSetServerName();
+    if (this_present_serverName || that_present_serverName) {
+      if (!(this_present_serverName && that_present_serverName))
+        return false;
+      if (!tSentryPrivilege1.getServerName().equalsIgnoreCase(tSentryPrivilege2.getServerName()))
+        return false;
+    }
+
+    boolean this_present_dbName = true && tSentryPrivilege1.isSetDbName();
+    boolean that_present_dbName = true && tSentryPrivilege2.isSetDbName();
+    if (this_present_dbName || that_present_dbName) {
+      if (!(this_present_dbName && that_present_dbName))
+        return false;
+      if (!tSentryPrivilege1.getDbName().equalsIgnoreCase(tSentryPrivilege2.getDbName()))
+        return false;
+    }
+
+    boolean this_present_tableName = true && tSentryPrivilege1.isSetTableName();
+    boolean that_present_tableName = true && tSentryPrivilege2.isSetTableName();
+    if (this_present_tableName || that_present_tableName) {
+      if (!(this_present_tableName && that_present_tableName))
+        return false;
+      if (!tSentryPrivilege1.getTableName().equalsIgnoreCase(tSentryPrivilege2.getTableName()))
+        return false;
+    }
+
+    boolean this_present_URI = true && tSentryPrivilege1.isSetURI();
+    boolean that_present_URI = true && tSentryPrivilege2.isSetURI();
+    if (this_present_URI || that_present_URI) {
+      if (!(this_present_URI && that_present_URI))
+        return false;
+      if (!tSentryPrivilege1.getURI().equalsIgnoreCase(tSentryPrivilege2.getURI()))
+        return false;
+    }
+
+    boolean this_present_action = true && tSentryPrivilege1.isSetAction();
+    boolean that_present_action = true && tSentryPrivilege2.isSetAction();
+    if (this_present_action || that_present_action) {
+      if (!(this_present_action && that_present_action))
+        return false;
+      if (!tSentryPrivilege1.getAction().equalsIgnoreCase(tSentryPrivilege2.getAction()))
+        return false;
+    }
+
+    boolean this_present_grantOption = true && tSentryPrivilege1.isSetGrantOption();
+    boolean that_present_grantOption = true && tSentryPrivilege2.isSetGrantOption();
+    if (this_present_grantOption || that_present_grantOption) {
+      if (!(this_present_grantOption && that_present_grantOption))
+        return false;
+      if (!tSentryPrivilege1.getGrantOption().equals(tSentryPrivilege2.getGrantOption()))
+        return false;
+    }
+
+    boolean this_present_columnName = true && tSentryPrivilege1.isSetColumnName();
+    boolean that_present_columnName = true && tSentryPrivilege2.isSetColumnName();
+    if (this_present_columnName || that_present_columnName) {
+      if (!(this_present_columnName && that_present_columnName))
+        return false;
+      if (!tSentryPrivilege1.getColumnName().equalsIgnoreCase(tSentryPrivilege2.getColumnName()))
+        return false;
+    }
+
+    return true;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java
new file mode 100644
index 0000000..9d0a2d6
--- /dev/null
+++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceImportExport.java
@@ -0,0 +1,538 @@
+/**
+ * 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.provider.db.service.thrift;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sentry.provider.common.PolicyFileConstants;
+import org.apache.sentry.provider.common.ProviderConstants;
+import org.apache.sentry.service.thrift.SentryServiceIntegrationBase;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+public class TestSentryServiceImportExport extends SentryServiceIntegrationBase {
+
+  // define the privileges
+  public static String PRIVILIEGE1 = "server=server1";
+  public static String PRIVILIEGE2 = "server=server1->action=select->grantoption=false";
+  public static String PRIVILIEGE3 = "server=server1->db=db2->action=insert->grantoption=true";
+  public static String PRIVILIEGE4 = "server=server1->db=db1->table=tbl1->action=insert";
+  public static String PRIVILIEGE5 = "server=server1->db=db1->table=tbl2->column=col1->action=insert";
+  public static String PRIVILIEGE6 = "server=server1->db=db1->table=tbl3->column=col1->action=*->grantoption=true";
+  public static String PRIVILIEGE7 = "server=server1->db=db1->table=tbl4->column=col1->action=all->grantoption=true";
+  public static String PRIVILIEGE8 = "server=server1->uri=hdfs://testserver:9999/path2->action=insert";
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    kerberos = false;
+    setupConf();
+    startSentryService();
+  }
+
+  @Before
+  public void preparePolicyFile() throws Exception {
+    super.before();
+    String requestorUserName = ADMIN_USER;
+    Set<String> requestorUserGroupNames = Sets.newHashSet(ADMIN_GROUP);
+    setLocalGroupMapping(requestorUserName, requestorUserGroupNames);
+    writePolicyFile();
+  }
+
+  // Befor import, database is empty.
+  // The following information is imported:
+  // group1=role1,role2,role3
+  // group2=role1,role2,role3
+  // group3=role1,role2,role3
+  // role1=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+  // role2=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+  // role3=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+  // Both import API importPolicy and export API exportPoicy are tested.
+  @Test
+  public void testImportExportPolicy1() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        Map<String, Map<String, Set<String>>> policyFileMappingData = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap = Maps.newHashMap();
+        Set<String> roles = Sets.newHashSet("role1", "role2", "role3");
+        groupRolesMap.put("group1", roles);
+        groupRolesMap.put("group2", roles);
+        groupRolesMap.put("group3", roles);
+        Map<String, Set<String>> rolePrivilegesMap = Maps.newHashMap();
+        for (String roleName : roles) {
+          rolePrivilegesMap.put(roleName, Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3,
+              PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        }
+        policyFileMappingData.put(PolicyFileConstants.GROUPS, groupRolesMap);
+        policyFileMappingData.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+        client.importPolicy(policyFileMappingData, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        validateSentryMappingData(sentryMappingData,
+            policyFileMappingData);
+      }
+    });
+  }
+
+  // call import twice, and there has no duplicate data:
+  // The data for 1st import:
+  // group1=role1
+  // role1=privilege1,privilege2,privilege3,privilege4
+  // The data for 2nd import:
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege5,privilege6,privilege7,privilege8
+  // role3=privilege5,privilege6,privilege7,privilege8
+  // Both import API importPolicy and export API exportPoicy are tested.
+  @Test
+  public void testImportExportPolicy2() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        Map<String, Map<String, Set<String>>> policyFileMappingData1 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap1 = Maps.newHashMap();
+        groupRolesMap1.put("group1", Sets.newHashSet("role1"));
+        Map<String, Set<String>> rolePrivilegesMap1 = Maps.newHashMap();
+        rolePrivilegesMap1.put("role1",
+            Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4));
+        policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap1);
+        policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap1);
+        client.importPolicy(policyFileMappingData1, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> policyFileMappingData2 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap2 = Maps.newHashMap();
+        groupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+        groupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+        Map<String, Set<String>> rolePrivilegesMap2 = Maps.newHashMap();
+        rolePrivilegesMap2.put("role2",
+            Sets.newHashSet(PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        rolePrivilegesMap2.put("role3",
+            Sets.newHashSet(PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        policyFileMappingData2.put(PolicyFileConstants.GROUPS, groupRolesMap2);
+        policyFileMappingData2.put(PolicyFileConstants.ROLES, rolePrivilegesMap2);
+        client.importPolicy(policyFileMappingData2, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> exceptedMappingData = Maps.newHashMap();
+        // for exceptedMappingData, combine policyFileMappingData1 and policyFileMappingData2
+        exceptedMappingData.put(PolicyFileConstants.GROUPS,
+            policyFileMappingData1.get(PolicyFileConstants.GROUPS));
+        exceptedMappingData.get(PolicyFileConstants.GROUPS).putAll(
+            policyFileMappingData2.get(PolicyFileConstants.GROUPS));
+        exceptedMappingData.put(PolicyFileConstants.ROLES,
+            policyFileMappingData1.get(PolicyFileConstants.ROLES));
+        exceptedMappingData.get(PolicyFileConstants.ROLES).putAll(
+            policyFileMappingData2.get(PolicyFileConstants.ROLES));
+
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        validateSentryMappingData(sentryMappingData, exceptedMappingData);
+      }
+    });
+  }
+
+  // Call import twice, and there has overlapping groups
+  // The data for 1st import:
+  // group1=role1, role2
+  // group2=role1, role2
+  // group3=role1, role2
+  // role1=privilege1,privilege2,privilege3,privilege4,privilege5
+  // role2=privilege1,privilege2,privilege3,privilege4,privilege5
+  // The data for 2nd import:
+  // group1=role2,role3
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege4,privilege5,privilege6,privilege7,privilege8
+  // role3=privilege4,privilege5,privilege6,privilege7,privilege8
+  // Both import API importPolicy and export API exportPoicy are tested.
+  @Test
+  public void testImportExportPolicy3() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        Map<String, Map<String, Set<String>>> policyFileMappingData1 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap1 = Maps.newHashMap();
+        groupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+        groupRolesMap1.put("group2", Sets.newHashSet("role1", "role2"));
+        groupRolesMap1.put("group3", Sets.newHashSet("role1", "role2"));
+        Map<String, Set<String>> rolePrivilegesMap1 = Maps.newHashMap();
+        rolePrivilegesMap1.put("role1",
+            Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5));
+        rolePrivilegesMap1.put("role2",
+            Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5));
+        policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap1);
+        policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap1);
+        client.importPolicy(policyFileMappingData1, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> policyFileMappingData2 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap2 = Maps.newHashMap();
+        groupRolesMap2.put("group1", Sets.newHashSet("role2", "role3"));
+        groupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+        groupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+        Map<String, Set<String>> rolePrivilegesMap2 = Maps.newHashMap();
+        rolePrivilegesMap2.put("role2",
+            Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        rolePrivilegesMap2.put("role3",
+            Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        policyFileMappingData2.put(PolicyFileConstants.GROUPS, groupRolesMap2);
+        policyFileMappingData2.put(PolicyFileConstants.ROLES, rolePrivilegesMap2);
+        client.importPolicy(policyFileMappingData2, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> exceptedMappingData = Maps.newHashMap();
+        Map<String, Set<String>> exceptedRolesMap = Maps.newHashMap();
+        exceptedRolesMap.put("group1", Sets.newHashSet("role1", "role2", "role3"));
+        exceptedRolesMap.put("group2", Sets.newHashSet("role1", "role2", "role3"));
+        exceptedRolesMap.put("group3", Sets.newHashSet("role1", "role2", "role3"));
+        Map<String, Set<String>> exceptedPrivilegesMap = Maps.newHashMap();
+        exceptedPrivilegesMap.put("role1",
+            Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5));
+        exceptedPrivilegesMap.put("role2", Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3,
+            PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        exceptedPrivilegesMap.put("role3",
+            Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        exceptedMappingData.put(PolicyFileConstants.GROUPS, exceptedRolesMap);
+        exceptedMappingData.put(PolicyFileConstants.ROLES, exceptedPrivilegesMap);
+
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        validateSentryMappingData(sentryMappingData, exceptedMappingData);
+      }
+    });
+  }
+
+  // Only mapping data for [group,role] is imported:
+  // group1=role1,role2
+  @Test
+  public void testImportExportPolicy4() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        Map<String, Map<String, Set<String>>> policyFileMappingData = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap = Maps.newHashMap();
+        Set<String> roles = Sets.newHashSet("role1", "role2");
+        groupRolesMap.put("group1", roles);
+        Map<String, Set<String>> rolePrivilegesMap = Maps.newHashMap();
+        policyFileMappingData.put(PolicyFileConstants.GROUPS, groupRolesMap);
+        policyFileMappingData.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+        client.importPolicy(policyFileMappingData, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        validateSentryMappingData(sentryMappingData,
+            policyFileMappingData);
+      }
+    });
+  }
+
+  // call import twice, and there has no duplicate data, the import will be with the overwrite mode:
+  // The data for 1st import:
+  // group1=role1
+  // role1=privilege1
+  // The data for 2nd import:
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege2
+  // role3=privilege2
+  // Both import API importSentryMetaData and export APIs getRolesMap, getGroupsMap,
+  // getPrivilegesList are tested.
+  @Test
+  public void testImportExportPolicy5() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        Map<String, Map<String, Set<String>>> policyFileMappingData1 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap1 = Maps.newHashMap();
+        groupRolesMap1.put("group1", Sets.newHashSet("role1"));
+        Map<String, Set<String>> rolePrivilegesMap1 = Maps.newHashMap();
+        rolePrivilegesMap1.put("role1", Sets.newHashSet(PRIVILIEGE1));
+        policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap1);
+        policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap1);
+        client.importPolicy(policyFileMappingData1, ADMIN_USER, true);
+
+        Map<String, Map<String, Set<String>>> policyFileMappingData2 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap2 = Maps.newHashMap();
+        groupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+        groupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+        Map<String, Set<String>> rolePrivilegesMap2 = Maps.newHashMap();
+        rolePrivilegesMap2.put("role2", Sets.newHashSet(PRIVILIEGE2));
+        rolePrivilegesMap2.put("role3", Sets.newHashSet(PRIVILIEGE2));
+        policyFileMappingData2.put(PolicyFileConstants.GROUPS, groupRolesMap2);
+        policyFileMappingData2.put(PolicyFileConstants.ROLES, rolePrivilegesMap2);
+        client.importPolicy(policyFileMappingData2, ADMIN_USER, true);
+
+        Map<String, Map<String, Set<String>>> exceptedMappingData = Maps.newHashMap();
+        Map<String, Set<String>> exceptedRolesMap = Maps.newHashMap();
+        exceptedRolesMap.put("group1", Sets.newHashSet("role1"));
+        exceptedRolesMap.put("group2", Sets.newHashSet("role2", "role3"));
+        exceptedRolesMap.put("group3", Sets.newHashSet("role2", "role3"));
+        Map<String, Set<String>> exceptedPrivilegesMap = Maps.newHashMap();
+        exceptedPrivilegesMap.put("role1", Sets.newHashSet(PRIVILIEGE1));
+        exceptedPrivilegesMap.put("role2", Sets.newHashSet(PRIVILIEGE2));
+        exceptedPrivilegesMap.put("role3", Sets.newHashSet(PRIVILIEGE2));
+        exceptedMappingData.put(PolicyFileConstants.GROUPS, exceptedRolesMap);
+        exceptedMappingData.put(PolicyFileConstants.ROLES, exceptedPrivilegesMap);
+
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        validateSentryMappingData(sentryMappingData, exceptedMappingData);
+      }
+    });
+  }
+
+  // call import twice, and there has data overlap, the import will be with the overwrite mode:
+  // The data for 1st import:
+  // group1=role1, role2
+  // group2=role1, role2
+  // group3=role1, role2
+  // role1=privilege1,privilege2,privilege3,privilege4,privilege5
+  // role2=privilege1,privilege2,privilege3,privilege4,privilege5
+  // The data for 2nd import:
+  // group1=role2,role3
+  // group2=role2,role3
+  // group3=role2,role3
+  // role2=privilege4,privilege5,privilege6,privilege7,privilege8
+  // role3=privilege4,privilege5,privilege6,privilege7,privilege8
+  // Both import API importSentryMetaData and export APIs getRolesMap, getGroupsMap,
+  // getPrivilegesList are tested.
+  @Test
+  public void testImportExportPolicy6() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        Map<String, Map<String, Set<String>>> policyFileMappingData1 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap1 = Maps.newHashMap();
+        groupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+        groupRolesMap1.put("group2", Sets.newHashSet("role1", "role2"));
+        groupRolesMap1.put("group3", Sets.newHashSet("role1", "role2"));
+        Map<String, Set<String>> rolePrivilegesMap1 = Maps.newHashMap();
+        rolePrivilegesMap1.put("role1",
+            Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5));
+        rolePrivilegesMap1.put("role2",
+            Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5));
+        policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap1);
+        policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap1);
+        client.importPolicy(policyFileMappingData1, ADMIN_USER, true);
+
+        Map<String, Map<String, Set<String>>> policyFileMappingData2 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap2 = Maps.newHashMap();
+        groupRolesMap2.put("group1", Sets.newHashSet("role2", "role3"));
+        groupRolesMap2.put("group2", Sets.newHashSet("role2", "role3"));
+        groupRolesMap2.put("group3", Sets.newHashSet("role2", "role3"));
+        Map<String, Set<String>> rolePrivilegesMap2 = Maps.newHashMap();
+        rolePrivilegesMap2.put("role2",
+            Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        rolePrivilegesMap2.put("role3",
+            Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        policyFileMappingData2.put(PolicyFileConstants.GROUPS, groupRolesMap2);
+        policyFileMappingData2.put(PolicyFileConstants.ROLES, rolePrivilegesMap2);
+        client.importPolicy(policyFileMappingData2, ADMIN_USER, true);
+
+        Map<String, Map<String, Set<String>>> exceptedMappingData = Maps.newHashMap();
+        Map<String, Set<String>> exceptedRolesMap = Maps.newHashMap();
+        exceptedRolesMap.put("group1", Sets.newHashSet("role1", "role2", "role3"));
+        exceptedRolesMap.put("group2", Sets.newHashSet("role1", "role2", "role3"));
+        exceptedRolesMap.put("group3", Sets.newHashSet("role1", "role2", "role3"));
+        Map<String, Set<String>> exceptedPrivilegesMap = Maps.newHashMap();
+        exceptedPrivilegesMap.put("role1",
+            Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5));
+        exceptedPrivilegesMap.put("role2",
+            Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        exceptedPrivilegesMap.put("role3",
+            Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+        exceptedMappingData.put(PolicyFileConstants.GROUPS, exceptedRolesMap);
+        exceptedMappingData.put(PolicyFileConstants.ROLES, exceptedPrivilegesMap);
+
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        validateSentryMappingData(sentryMappingData, exceptedMappingData);
+      }
+    });
+  }
+
+  // test the import privileges with the action: All, *, select, insert
+  // All and * should replace the select and insert
+  // The data for import:
+  // group1=role1, role2
+  // role1=testPrivilege1,testPrivilege2,testPrivilege3,testPrivilege4
+  // role2=testPrivilege5, testPrivilege6,testPrivilege7,testPrivilege8
+  @Test
+  public void testImportExportPolicy7() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        String testPrivilege1 = "server=server1->db=db1->table=tbl1->action=select->grantoption=true";
+        String testPrivilege2 = "server=server1->db=db1->table=tbl1->action=insert->grantoption=false";
+        String testPrivilege3 = "server=server1->db=db1->table=tbl1->action=all->grantoption=true";
+        String testPrivilege4 = "server=server1->db=db1->table=tbl1->action=insert->grantoption=true";
+        String testPrivilege5 = "server=server1->db=db1->table=tbl2->action=select->grantoption=true";
+        String testPrivilege6 = "server=server1->db=db1->table=tbl2->action=insert->grantoption=false";
+        String testPrivilege7 = "server=server1->db=db1->table=tbl2->action=*->grantoption=true";
+        String testPrivilege8 = "server=server1->db=db1->table=tbl2->action=insert->grantoption=true";
+
+        Map<String, Map<String, Set<String>>> policyFileMappingData1 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap1 = Maps.newHashMap();
+        groupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+        Map<String, Set<String>> rolePrivilegesMap1 = Maps.newHashMap();
+        rolePrivilegesMap1.put("role1",
+            Sets.newHashSet(testPrivilege1, testPrivilege2, testPrivilege3, testPrivilege4));
+        rolePrivilegesMap1.put("role2",
+            Sets.newHashSet(testPrivilege5, testPrivilege6, testPrivilege7, testPrivilege8));
+        policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap1);
+        policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap1);
+        client.importPolicy(policyFileMappingData1, ADMIN_USER, true);
+
+        Map<String, Map<String, Set<String>>> exceptedMappingData = Maps.newHashMap();
+        Map<String, Set<String>> exceptedRolesMap = Maps.newHashMap();
+        exceptedRolesMap.put("group1", Sets.newHashSet("role1", "role2"));
+        Map<String, Set<String>> exceptedPrivilegesMap = Maps.newHashMap();
+        exceptedPrivilegesMap.put("role1", Sets.newHashSet(testPrivilege2, testPrivilege3));
+        exceptedPrivilegesMap.put("role2", Sets.newHashSet(testPrivilege6, testPrivilege7));
+        exceptedMappingData.put(PolicyFileConstants.GROUPS, exceptedRolesMap);
+        exceptedMappingData.put(PolicyFileConstants.ROLES, exceptedPrivilegesMap);
+
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        validateSentryMappingData(sentryMappingData, exceptedMappingData);
+      }
+    });
+  }
+
+  // Call import twice, and there has overlapping actions, all and * should replace the select and
+  // insert
+  // The data for 1st import:
+  // group1=role1, role2
+  // role1=privilege1(with select action),privilege2(with insert action)
+  // role2=privilege4(with select action),privilege5(with insert action)
+  // The data for 2nd import:
+  // group1=role1, role2
+  // role1=privilege3(with all action)
+  // role2=privilege6(with * action)
+  @Test
+  public void testImportExportPolicy8() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        String testPrivilege1 = "server=server1->db=db1->table=tbl1->action=select->grantoption=true";
+        String testPrivilege2 = "server=server1->db=db1->table=tbl1->action=insert->grantoption=true";
+        String testPrivilege3 = "server=server1->db=db1->table=tbl1->action=all->grantoption=true";
+        String testPrivilege4 = "server=server1->db=db1->table=tbl2->action=select->grantoption=true";
+        String testPrivilege5 = "server=server1->db=db1->table=tbl2->action=insert->grantoption=true";
+        String testPrivilege6 = "server=server1->db=db1->table=tbl2->action=*->grantoption=true";
+
+        Map<String, Map<String, Set<String>>> policyFileMappingData1 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap1 = Maps.newHashMap();
+        groupRolesMap1.put("group1", Sets.newHashSet("role1", "role2"));
+        Map<String, Set<String>> rolePrivilegesMap1 = Maps.newHashMap();
+        rolePrivilegesMap1.put("role1", Sets.newHashSet(testPrivilege1, testPrivilege2));
+        rolePrivilegesMap1.put("role2", Sets.newHashSet(testPrivilege4, testPrivilege5));
+        policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap1);
+        policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap1);
+        client.importPolicy(policyFileMappingData1, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> policyFileMappingData2 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap2 = Maps.newHashMap();
+        groupRolesMap2.put("group1", Sets.newHashSet("role1", "role2"));
+        Map<String, Set<String>> rolePrivilegesMap2 = Maps.newHashMap();
+        rolePrivilegesMap2.put("role1", Sets.newHashSet(testPrivilege3));
+        rolePrivilegesMap2.put("role2", Sets.newHashSet(testPrivilege6));
+        policyFileMappingData2.put(PolicyFileConstants.GROUPS, groupRolesMap2);
+        policyFileMappingData2.put(PolicyFileConstants.ROLES, rolePrivilegesMap2);
+        client.importPolicy(policyFileMappingData2, ADMIN_USER, false);
+
+        Map<String, Map<String, Set<String>>> exceptedMappingData = policyFileMappingData2;
+        Map<String, Map<String, Set<String>>> sentryMappingData = client.exportPolicy(ADMIN_USER);
+        // all and * should replace the select and insert
+        validateSentryMappingData(sentryMappingData, exceptedMappingData);
+      }
+    });
+  }
+
+  // test the user not in the admin group can't do the import/export
+  @Test
+  public void testImportExportPolicy9() throws Exception {
+    runTestAsSubject(new TestOperation() {
+      @Override
+      public void runTestAsSubject() throws Exception {
+        Map<String, Map<String, Set<String>>> policyFileMappingData1 = Maps.newHashMap();
+        Map<String, Set<String>> groupRolesMap1 = Maps.newHashMap();
+        Map<String, Set<String>> rolePrivilegesMap1 = Maps.newHashMap();
+        policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap1);
+        policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap1);
+        try {
+          client.importPolicy(policyFileMappingData1, "no-admin-user", false);
+          fail("non-admin can't do the import.");
+        } catch (Exception e) {
+          // excepted exception
+        }
+
+        try {
+          client.exportPolicy("no-admin-user");
+          fail("non-admin can't do the export.");
+        } catch (Exception e) {
+          // excepted exception
+        }
+      }
+    });
+  }
+
+  // verify the mapping data
+  public void validateSentryMappingData(
+      Map<String, Map<String, Set<String>>> actualMappingData,
+      Map<String, Map<String, Set<String>>> expectedMappingData) {
+    validateGroupRolesMap(actualMappingData.get(PolicyFileConstants.GROUPS),
+        expectedMappingData.get(PolicyFileConstants.GROUPS));
+    validateRolePrivilegesMap(actualMappingData.get(PolicyFileConstants.ROLES),
+        expectedMappingData.get(PolicyFileConstants.ROLES));
+  }
+
+  // verify the mapping data for [group,role]
+  private void validateGroupRolesMap(Map<String, Set<String>> actualMap,
+      Map<String, Set<String>> expectedMap) {
+    assertEquals(expectedMap.keySet().size(), actualMap.keySet().size());
+    for (String groupName : actualMap.keySet()) {
+      Set<String> actualRoles = actualMap.get(groupName);
+      Set<String> expectedRoles = expectedMap.get(groupName);
+      assertEquals(actualRoles.size(), expectedRoles.size());
+      assertTrue(actualRoles.equals(expectedRoles));
+    }
+  }
+
+  // verify the mapping data for [role,privilege]
+  private void validateRolePrivilegesMap(Map<String, Set<String>> actualMap,
+      Map<String, Set<String>> expectedMap) {
+    assertEquals(expectedMap.keySet().size(), actualMap.keySet().size());
+    for (String roleName : actualMap.keySet()) {
+      Set<String> actualPrivileges = actualMap.get(roleName);
+      Set<String> exceptedPrivileges = expectedMap.get(roleName);
+      assertEquals(exceptedPrivileges.size(), actualPrivileges.size());
+      for (String actualPrivilege : actualPrivileges) {
+        boolean isFound = exceptedPrivileges.contains(actualPrivilege);
+        if (!isFound) {
+          String withOptionPrivilege = ProviderConstants.AUTHORIZABLE_JOINER.join(actualPrivilege,
+              ProviderConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME,
+                  "false"));
+          isFound = exceptedPrivileges.contains(withOptionPrivilege);
+        }
+        assertTrue(isFound);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImport.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImport.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImport.java
deleted file mode 100644
index 7ebc0e4..0000000
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImport.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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.tests.e2e.hive;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import org.apache.sentry.SentryUserException;
-import org.apache.sentry.binding.hive.authz.SentryConfigTool;
-import org.apache.sentry.core.model.db.AccessConstants;
-import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;
-import org.apache.sentry.provider.db.service.thrift.TSentryPrivilege;
-import org.apache.sentry.provider.db.service.thrift.TSentryRole;
-import org.apache.sentry.provider.file.PolicyFile;
-import org.apache.sentry.service.thrift.SentryServiceClientFactory;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class TestPolicyImport extends AbstractTestWithStaticConfiguration {
-
-  private static String prefix;
-  private PolicyFile policyFile;
-  private SentryConfigTool configTool;
-
-  @BeforeClass
-  public static void setupTestStaticConfiguration() throws Exception{
-    useSentryService = true;
-    AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-  }
-
-  @Before
-  public void setup() throws Exception {
-    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
-    policyFile.addGroupsToUser("hive", ADMINGROUP);
-    policyFile.addGroupsToUser(ADMIN1, ADMINGROUP);
-
-    configTool = new SentryConfigTool();
-    String hiveServer2 = System.getProperty("sentry.e2etest.hiveServer2Type",
-        "InternalHiveServer2");
-    String policyOnHDFS = System.getProperty(
-        "sentry.e2etest.hive.policyOnHDFS", "true");
-    if (policyOnHDFS.trim().equalsIgnoreCase("true")
-        && (hiveServer2.equals("UnmanagedHiveServer2"))) {
-      String policyLocation = System.getProperty(
-          "sentry.e2etest.hive.policy.location", "/user/hive/sentry");
-      prefix = "hdfs://" + policyLocation + "/";
-    } else {
-      prefix = "file://" + context.getPolicyFile().getParent() + "/";
-    }
-
-  }
-
-    @Test
-  public void testImportPolicy() throws Exception {
-    policyFile.addRolesToGroup("analyst", "analyst_role", "customers_select_role", "analyst_salary_role");
-    policyFile.addRolesToGroup("jranalyst", "junior_analyst_role");
-    policyFile.addRolesToGroup("manager", "analyst_role",  "junior_analyst_role",
-        "customers_insert_role", "customers_select_role");
-    policyFile.addRolesToGroup("customers_admin", "customers_admin_role");
-
-    policyFile.addPermissionsToRole("analyst_role", "server=server1->db=analyst_db",
-        "server=server1->db=jranalyst_db->table=*->action=select");
-    policyFile.addPermissionsToRole("junior_analyst_role", "server=server1->db=jranalyst_db");
-    policyFile.addPermissionsToRole("customers_admin_role", "server=server1->db=customers");
-    policyFile.addPermissionsToRole("customers_insert_role", "server=server1->db=customers->table=*->action=insert");
-    policyFile.addPermissionsToRole("customers_select_role", "server=server1->db=customers->table=*->action=select");
-    policyFile.addPermissionsToRole("analyst_salary_role", "server=server1->db=customers->table=customer_info->column=salary->action=select");
-
-    policyFile.write(context.getPolicyFile());
-
-    configTool.setImportPolicy(true);
-    configTool.setPolicyFile(context.getPolicyFile().getPath());
-    configTool.setupConfig();
-
-    configTool.importPolicy();
-
-    SentryPolicyServiceClient client = SentryServiceClientFactory.create(configTool.getAuthzConf());
-    verifyRoles(client, "analyst", "analyst_role", "customers_select_role", "analyst_salary_role");
-    verifyRoles(client, "jranalyst", "junior_analyst_role");
-    verifyRoles(client, "manager", "analyst_role", "junior_analyst_role",
-        "customers_insert_role", "customers_select_role");
-    verifyRoles(client, "customers_admin", "customers_admin_role");
-
-    verifyPrivileges(client, "analyst_role",
-        createPrivilege(AccessConstants.ALL, "analyst_db", null, null),
-        createPrivilege(AccessConstants.SELECT, "jranalyst_db", null, null));
-    verifyPrivileges(client, "junior_analyst_role",
-        createPrivilege(AccessConstants.ALL, "jranalyst_db", null, null));
-    verifyPrivileges(client, "customers_admin_role",
-        createPrivilege(AccessConstants.ALL, "customers", null, null));
-    verifyPrivileges(client, "customers_insert_role",
-        createPrivilege(AccessConstants.INSERT, "customers", null, null));
-    verifyPrivileges(client, "customers_select_role",
-        createPrivilege(AccessConstants.SELECT, "customers", null, null));
-    verifyPrivileges(client, "analyst_salary_role",
-        createPrivilege(AccessConstants.SELECT, "customers", "customer_info", "salary", null));
-  }
-
-  private void verifyRoles(SentryPolicyServiceClient client, String group, String ... roles) throws SentryUserException {
-    Set<String> expectedRoles = new HashSet<String>(Arrays.asList(roles));
-    Set<String> actualRoles = new HashSet<String>();
-
-    Set<TSentryRole> groupRoles = client.listRolesByGroupName("hive", group);
-    for (TSentryRole role : groupRoles) {
-      actualRoles.add(role.getRoleName());
-    }
-
-    assertEquals("Expected roles don't match.", expectedRoles, actualRoles);
-  }
-
-  private void verifyPrivileges(SentryPolicyServiceClient client, String role, TSentryPrivilege ... privileges) throws SentryUserException {
-    Set<TSentryPrivilege> expectedPrivileges = new HashSet<TSentryPrivilege>(Arrays.asList(privileges));
-    Set<TSentryPrivilege> actualPrivileges = client.listAllPrivilegesByRoleName("hive", role);
-    for (TSentryPrivilege privilege : actualPrivileges) {
-      privilege.unsetCreateTime();
-    }
-
-    assertEquals("Expected privileges don't match.", expectedPrivileges, actualPrivileges);
-  }
-
-  private TSentryPrivilege createPrivilege(String action, String dbName, String tableName, String uri) {
-    String scope = "SERVER";
-    if (uri != null) {
-      scope = "URI";
-    } else if (dbName != null) {
-      if (tableName != null) {
-        scope = "TABLE";
-      } else  {
-        scope = "DATABASE";
-      }
-    }
-
-    TSentryPrivilege privilege = new TSentryPrivilege(scope, "server1", action);
-    if (dbName != null) {
-      privilege.setDbName(dbName);
-    }
-
-    if (tableName != null) {
-      privilege.setDbName(tableName);
-    }
-
-    if (uri != null) {
-      privilege.setURI(uri);
-    }
-
-    return privilege;
-  }
-
-  private TSentryPrivilege createPrivilege(String action, String dbName, String tableName, String columnName, String uri) {
-    String scope = "SERVER";
-    if (uri != null) {
-      scope = "URI";
-    } else if (dbName != null) {
-      if (columnName != null) {
-        scope = "COLUMN";
-      } else if (tableName != null) {
-        scope = "TABLE";
-      } else  {
-        scope = "DATABASE";
-      }
-    }
-
-    TSentryPrivilege privilege = new TSentryPrivilege(scope, "server1", action);
-    if (dbName != null) {
-      privilege.setDbName(dbName);
-    }
-
-    if (tableName != null) {
-      privilege.setTableName(tableName);
-    }
-
-    if (columnName != null) {
-      privilege.setColumnName(columnName);
-    }
-
-    if (uri != null) {
-      privilege.setURI(uri);
-    }
-
-    return privilege;
-  }
-}


[6/6] incubator-sentry git commit: SENTRY-197: Create tool to dump and load of entire Sentry service (Colin Ma, Reviewed by:Sravya Tirukkovalur, Guoquan Shen, Dapeng Sun, Anne Yu)

Posted by co...@apache.org.
SENTRY-197: Create tool to dump and load of entire Sentry service (Colin Ma, Reviewed by:Sravya Tirukkovalur, Guoquan Shen, Dapeng Sun, Anne Yu)


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

Branch: refs/heads/master
Commit: 92cde111f232a98bbce4b320100d408668cc444c
Parents: 6c3184a
Author: Colin Ma <co...@apache.org>
Authored: Thu Jul 30 08:38:57 2015 +0800
Committer: Colin Ma <co...@apache.org>
Committed: Thu Jul 30 08:38:57 2015 +0800

----------------------------------------------------------------------
 .../hive/SentryIniPolicyFileFormatter.java      |  161 ++
 .../hive/SentryPolicyFileFormatFactory.java     |   44 +
 .../binding/hive/SentryPolicyFileFormatter.java |   39 +
 .../binding/hive/authz/SentryConfigTool.java    |  234 +--
 .../sentry/binding/hive/conf/HiveAuthzConf.java |   14 +-
 .../hive/TestSentryIniPolicyFileFormatter.java  |  220 +++
 .../db/service/thrift/SentryPolicyService.java  | 1612 ++++++++++++++++++
 .../thrift/TSentryExportMappingDataRequest.java |  486 ++++++
 .../TSentryExportMappingDataResponse.java       |  496 ++++++
 .../thrift/TSentryImportMappingDataRequest.java |  689 ++++++++
 .../TSentryImportMappingDataResponse.java       |  390 +++++
 .../db/service/thrift/TSentryMappingData.java   |  695 ++++++++
 .../db/service/persistent/SentryStore.java      |  458 ++++-
 .../thrift/SentryPolicyServiceClient.java       |    8 +
 .../SentryPolicyServiceClientDefaultImpl.java   |  111 ++
 .../thrift/SentryPolicyStoreProcessor.java      |   53 +
 .../service/thrift/SentryServiceUtil.java       |  127 ++
 .../main/resources/sentry_policy_service.thrift |   41 +-
 .../persistent/TestSentryStoreImportExport.java |  899 ++++++++++
 .../thrift/TestSentryServiceImportExport.java   |  538 ++++++
 .../sentry/tests/e2e/hive/TestPolicyImport.java |  199 ---
 .../tests/e2e/hive/TestPolicyImportExport.java  |  195 +++
 .../src/test/resources/testPolicyImport.ini     |   25 +
 .../test/resources/testPolicyImportAdmin.ini    |   22 +
 .../test/resources/testPolicyImportError.ini    |   21 +
 25 files changed, 7362 insertions(+), 415 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java
new file mode 100644
index 0000000..79164da
--- /dev/null
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryIniPolicyFileFormatter.java
@@ -0,0 +1,161 @@
+/**
+ * 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.binding.hive;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.sentry.provider.common.PolicyFileConstants;
+import org.apache.sentry.provider.common.ProviderBackendContext;
+import org.apache.sentry.provider.common.ProviderConstants;
+import org.apache.sentry.provider.file.SimpleFileProviderBackend;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Table;
+import com.google.common.io.Files;
+
+/**
+ * SentryIniPolicyFileFormatter is to parse file and write data to file for sentry mapping data with
+ * ini format, eg:
+ * [groups]
+ * group1=role1
+ * [roles]
+ * role1=server=server1
+ */
+public class SentryIniPolicyFileFormatter implements SentryPolicyFileFormatter {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(SentryIniPolicyFileFormatter.class);
+
+  private static final String NL = System.getProperty("line.separator", "\n");
+
+  /**
+   * Write the sentry mapping data to ini file.
+   * 
+   * @param resourcePath
+   *        The path of the output file
+   * @param sentryMappingData
+   *        The map for sentry mapping data, eg:
+   *        for the following mapping data:
+   *        group1=role1,role2
+   *        group2=role2,role3
+   *        role1=server=server1->db=db1
+   *        role2=server=server1->db=db1->table=tbl1,server=server1->db=db1->table=tbl2
+   *        role3=server=server1->url=hdfs://localhost/path
+   * 
+   *        The sentryMappingData will be inputed as:
+   *        {
+   *        groups={[group1={role1, role2}], group2=[role2, role3]},
+   *        roles={role1=[server=server1->db=db1],
+   *        role2=[server=server1->db=db1->table=tbl1,server=server1->db=db1->table=tbl2],
+   *        role3=[server=server1->url=hdfs://localhost/path]
+   *        }
+   *        }
+   */
+  @Override
+  public void write(String resourcePath, Map<String, Map<String, Set<String>>> sentryMappingData)
+      throws Exception {
+    File destFile = new File(resourcePath);
+    if (destFile.exists() && !destFile.delete()) {
+      throw new IllegalStateException("Unable to delete " + destFile);
+    }
+    String contents = Joiner
+        .on(NL)
+        .join(
+        generateSection(PolicyFileConstants.GROUPS,
+                sentryMappingData.get(PolicyFileConstants.GROUPS)),
+        generateSection(PolicyFileConstants.ROLES,
+                sentryMappingData.get(PolicyFileConstants.ROLES)),
+            "");
+    LOGGER.info("Writing policy file to " + destFile + ":\n" + contents);
+    Files.write(contents, destFile, Charsets.UTF_8);
+  }
+
+  /**
+   * parse the ini file and return a map with all data
+   * 
+   * @param resourcePath
+   *        The path of the input file
+   * @param conf
+   *        The configuration info
+   * @return the result of sentry mapping data in map structure.
+   */
+  @Override
+  public Map<String, Map<String, Set<String>>> parse(String resourcePath, Configuration conf)
+      throws Exception {
+    Map<String, Map<String, Set<String>>> resultMap = Maps.newHashMap();
+    // SimpleFileProviderBackend is used for parse the ini file
+    SimpleFileProviderBackend policyFileBackend = new SimpleFileProviderBackend(conf, resourcePath);
+    ProviderBackendContext context = new ProviderBackendContext();
+    context.setAllowPerDatabase(true);
+    // parse the ini file
+    policyFileBackend.initialize(context);
+
+    // SimpleFileProviderBackend parsed the input file and output the data in Table format.
+    Table<String, String, Set<String>> groupRolePrivilegeTable = policyFileBackend
+        .getGroupRolePrivilegeTable();
+    Map<String, Set<String>> groupRolesMap = Maps.newHashMap();
+    Map<String, Set<String>> rolePrivilegesMap = Maps.newHashMap();
+    for (String groupName : groupRolePrivilegeTable.rowKeySet()) {
+      for (String roleName : groupRolePrivilegeTable.columnKeySet()) {
+        // get the roles set for the current groupName
+        Set<String> tempRoles = groupRolesMap.get(groupName);
+        if (tempRoles == null) {
+          tempRoles = Sets.newHashSet();
+        }
+        Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName);
+        // if there has privilege for [group,role], if no privilege exist, the [group, role] info
+        // will be discard.
+        if (privileges != null) {
+          // update [group, role] mapping data
+          tempRoles.add(roleName);
+          groupRolesMap.put(groupName, tempRoles);
+          // update [role, privilege] mapping data
+          rolePrivilegesMap.put(roleName, privileges);
+        }
+      }
+    }
+    resultMap.put(PolicyFileConstants.GROUPS, groupRolesMap);
+    resultMap.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+    return resultMap;
+  }
+
+  // generate the ini section according to the mapping data.
+  private String generateSection(String name, Map<String, Set<String>> mappingData) {
+    if (mappingData.isEmpty()) {
+      return "";
+    }
+    List<String> lines = Lists.newArrayList();
+    lines.add("[" + name + "]");
+    for (String key : mappingData.keySet()) {
+      lines.add(ProviderConstants.KV_JOINER.join(key,
+          ProviderConstants.ROLE_JOINER.join(mappingData.get(key))));
+    }
+    return Joiner.on(NL).join(lines);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatFactory.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatFactory.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatFactory.java
new file mode 100644
index 0000000..d2c6072
--- /dev/null
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatFactory.java
@@ -0,0 +1,44 @@
+/**
+ * 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.binding.hive;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.sentry.binding.hive.conf.HiveAuthzConf;
+import org.apache.sentry.binding.hive.conf.HiveAuthzConf.AuthzConfVars;
+
+/**
+ * SentryPolicyFileFormatFactory is used to create FileFormatter for different file type according
+ * to the configuration, the default FileFormatter is for ini file.
+ */
+public class SentryPolicyFileFormatFactory {
+
+  public static SentryPolicyFileFormatter createFileFormatter(HiveAuthzConf conf) throws Exception {
+    // The default formatter is org.apache.sentry.binding.hive.SentryIniPolicyFileFormatter, for ini
+    // file.
+    String policyFileFormatterName = conf.get(AuthzConfVars.AUTHZ_POLICY_FILE_FORMATTER.getVar());
+    // load the policy file formatter class
+    Constructor<?> policyFileFormatterConstructor = Class.forName(policyFileFormatterName)
+        .getDeclaredConstructor();
+    policyFileFormatterConstructor.setAccessible(true);
+    SentryPolicyFileFormatter sentryPolicyFileFormatter = (SentryPolicyFileFormatter) policyFileFormatterConstructor
+        .newInstance();
+    return sentryPolicyFileFormatter;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatter.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatter.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatter.java
new file mode 100644
index 0000000..14437ca
--- /dev/null
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/SentryPolicyFileFormatter.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.binding.hive;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * SentryPolicyFileFormatter is to parse file and write data to file for sentry mapping data.
+ */
+public interface SentryPolicyFileFormatter {
+
+  // write the sentry mapping data to file
+  public void write(String resourcePath, Map<String, Map<String, Set<String>>> sentryMappingData)
+      throws Exception;
+
+  // parse the sentry mapping data from file
+  public Map<String, Map<String, Set<String>>> parse(String resourcePath, Configuration conf)
+      throws Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
index 4388ca0..d9bb42d 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/authz/SentryConfigTool.java
@@ -23,7 +23,7 @@ import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.cli.CommandLine;
@@ -34,6 +34,7 @@ import org.apache.commons.cli.OptionGroup;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.Parser;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
 import org.apache.hadoop.hive.ql.Driver;
@@ -45,25 +46,28 @@ import org.apache.log4j.LogManager;
 import org.apache.sentry.Command;
 import org.apache.sentry.binding.hive.HiveAuthzBindingHook;
 import org.apache.sentry.binding.hive.HiveAuthzBindingSessionHook;
+import org.apache.sentry.binding.hive.SentryPolicyFileFormatFactory;
+import org.apache.sentry.binding.hive.SentryPolicyFileFormatter;
 import org.apache.sentry.binding.hive.conf.HiveAuthzConf;
 import org.apache.sentry.binding.hive.conf.HiveAuthzConf.AuthzConfVars;
 import org.apache.sentry.core.common.SentryConfigurationException;
 import org.apache.sentry.core.common.Subject;
-import org.apache.sentry.core.model.db.AccessConstants;
-import org.apache.sentry.core.model.db.DBModelAuthorizable;
 import org.apache.sentry.core.model.db.Server;
-import org.apache.sentry.policy.db.DBModelAuthorizables;
 import org.apache.sentry.provider.common.AuthorizationProvider;
-import org.apache.sentry.provider.common.KeyValue;
-import org.apache.sentry.provider.common.ProviderBackendContext;
-import org.apache.sentry.provider.common.ProviderConstants;
 import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;
-import org.apache.sentry.provider.db.service.thrift.TSentryRole;
-import org.apache.sentry.provider.file.SimpleFileProviderBackend;
 import org.apache.sentry.service.thrift.SentryServiceClientFactory;
 
-import com.google.common.collect.Table;
-
+/**
+ * set the required system property to be read by HiveConf and AuthzConf
+ * 
+ * @throws Exception
+ */
+// Hack, hiveConf doesn't provide a reliable way check if it found a valid
+// hive-site
+// load auth provider
+// get the configured sentry provider
+// validate policy files
+// import policy files
 public class SentryConfigTool {
   private String sentrySiteFile = null;
   private String policyFile = null;
@@ -71,9 +75,11 @@ public class SentryConfigTool {
   private String jdbcURL = null;
   private String user = null;
   private String passWord = null;
+  private String importPolicyFilePath = null;
+  private String exportPolicyFilePath = null;
   private boolean listPrivs = false;
   private boolean validate = false;
-  private boolean importPolicy = false;
+  private boolean importOverwriteRole = false;
   private HiveConf hiveConf = null;
   private HiveAuthzConf authzConf = null;
   private AuthorizationProvider sentryProvider = null;
@@ -114,12 +120,20 @@ public class SentryConfigTool {
     this.validate = validate;
   }
 
-  public boolean isImportPolicy() {
-    return importPolicy;
+  public String getImportPolicyFilePath() {
+    return importPolicyFilePath;
+  }
+
+  public void setImportPolicyFilePath(String importPolicyFilePath) {
+    this.importPolicyFilePath = importPolicyFilePath;
   }
 
-  public void setImportPolicy(boolean importPolicy) {
-    this.importPolicy = importPolicy;
+  public String getExportPolicyFilePath() {
+    return exportPolicyFilePath;
+  }
+
+  public void setExportPolicyFilePath(String exportPolicyFilePath) {
+    this.exportPolicyFilePath = exportPolicyFilePath;
   }
 
   public String getSentrySiteFile() {
@@ -178,6 +192,14 @@ public class SentryConfigTool {
     this.listPrivs = listPrivs;
   }
 
+  public boolean isImportOverwriteRole() {
+    return importOverwriteRole;
+  }
+
+  public void setImportOverwriteRole(boolean importOverwriteRole) {
+    this.importOverwriteRole = importOverwriteRole;
+  }
+
   /**
    * set the required system property to be read by HiveConf and AuthzConf
    * @throws Exception
@@ -251,133 +273,33 @@ public class SentryConfigTool {
     System.out.println("No errors found in the policy file");
   }
 
-  // import policy files
+  // import the sentry mapping data to database
   public void importPolicy() throws Exception {
-    final String requestorUserName = "hive";
-    SimpleFileProviderBackend policyFileBackend;
-    SentryPolicyServiceClient client;
-
-    policyFileBackend = new SimpleFileProviderBackend(getAuthzConf(),
-        getAuthzConf().get(AuthzConfVars.AUTHZ_PROVIDER_RESOURCE.getVar()));
-    ProviderBackendContext context = new ProviderBackendContext();
-    context.setAllowPerDatabase(true);
-    policyFileBackend.initialize(context);
-    client = SentryServiceClientFactory.create(getAuthzConf());
-    Set<String> roles = new HashSet<String>();
-    for (TSentryRole sentryRole : client.listRoles(requestorUserName)) {
-      roles.add(sentryRole.getRoleName());
-    }
-
-    Table<String, String, Set<String>> groupRolePrivilegeTable =
-        policyFileBackend.getGroupRolePrivilegeTable();
-    for(String groupName : groupRolePrivilegeTable.rowKeySet()) {
-      for(String roleName : groupRolePrivilegeTable.columnKeySet()) {
-        if (!roles.contains(roleName)) {
-          client.createRole(requestorUserName, roleName);
-          System.out.println(String.format("CREATE ROLE %s;", roleName));
-          roles.add(roleName);
-        }
-
-        Set<String> privileges = groupRolePrivilegeTable.get(groupName, roleName);
-        if (privileges == null) {
-          continue;
-        }
-        client.grantRoleToGroup(requestorUserName, groupName, roleName);
-        System.out.println(String.format("GRANT ROLE %s TO GROUP %s;",
-            roleName, groupName));
-
-        for (String permission : privileges) {
-          String server = null;
-          String database = null;
-          String table = null;
-          String column = null;
-          String uri = null;
-          String action = AccessConstants.ALL;
-          for (String authorizable : ProviderConstants.AUTHORIZABLE_SPLITTER.
-              trimResults().split(permission)) {
-            KeyValue kv = new KeyValue(authorizable);
-            DBModelAuthorizable a = DBModelAuthorizables.from(kv);
-            if (a == null) {
-              action = kv.getValue();
-              continue;
-            }
-
-            switch (a.getAuthzType()) {
-              case Server:
-                server = a.getName();
-                break;
-              case Db:
-                database = a.getName();
-                break;
-              case Table:
-              case View:
-                table = a.getName();
-                break;
-              case URI:
-                uri = a.getName();
-                break;
-              case Column:
-                column = a.getName();
-                break;
-              default:
-                break;
-            }
-          }
-
-          if (uri != null) {
-            System.out.println(String.format(
-                "# server=%s",
-                server));
-            System.out.println(String.format(
-                "GRANT ALL ON URI %s TO ROLE %s;",
-                uri, roleName));
-
-            client.grantURIPrivilege(requestorUserName, roleName, server, uri);
-          } else if (column != null && !AccessConstants.ALL.equals(column)) {
-            System.out.println(String.format(
-                "# server=%s, database=%s",
-                server, database));
-            System.out.println(String.format(
-                "GRANT %s (%s) ON TABLE %s TO ROLE %s;",
-                "*".equals(action) ? "ALL" : action.toUpperCase(), column,
-                table, roleName));
-
-            client.grantColumnPrivilege(requestorUserName, roleName, server,
-                database, table, column, action);
-          } else if (table != null && !AccessConstants.ALL.equals(table)) {
-            System.out.println(String.format(
-                "# server=%s, database=%s",
-                server, database));
-            System.out.println(String.format(
-                "GRANT %s ON TABLE %s TO ROLE %s;",
-                "*".equals(action) ? "ALL" : action.toUpperCase(), table,
-                roleName));
-
-            client.grantTablePrivilege(requestorUserName, roleName, server,
-                database, table, action);
-          } else if (database != null && !AccessConstants.ALL.equals(database)) {
-            System.out.println(String.format(
-                "# server=%s",
-                server));
-            System.out.println(String.format(
-                "GRANT %s ON DATABASE %s TO ROLE %s;",
-                "*".equals(action) ? "ALL" : action.toUpperCase(),
-                database, roleName));
-
-            client.grantDatabasePrivilege(requestorUserName, roleName, server,
-                database, action);
-          } else if (server != null) {
-            System.out.println(String.format("GRANT ALL ON SERVER %s TO ROLE %s;",
-                server, roleName));
-
-            client.grantServerPrivilege(requestorUserName, roleName, server, action);
-          } else {
-            System.out.println(String.format("No grant for permission %s",
-                permission));
-          }
-        }
-      }
-    }
+    String requestorUserName = System.getProperty("user.name", "");
+    // get the FileFormatter according to the configuration
+    SentryPolicyFileFormatter sentryPolicyFileFormatter = SentryPolicyFileFormatFactory
+        .createFileFormatter(authzConf);
+    // parse the input file, get the mapping data in map structure
+    Map<String, Map<String, Set<String>>> policyFileMappingData = sentryPolicyFileFormatter.parse(
+        importPolicyFilePath, authzConf);
+    // todo: here should be an validator to check the data's value, format, hierarchy
+    SentryPolicyServiceClient client = SentryServiceClientFactory.create(getAuthzConf());
+    // import the mapping data to database
+    client.importPolicy(policyFileMappingData, requestorUserName, importOverwriteRole);
+  }
+
+  // export the sentry mapping data to file
+  public void exportPolicy() throws Exception {
+    String requestorUserName = System.getProperty("user.name", "");
+    SentryPolicyServiceClient client = SentryServiceClientFactory.create(getAuthzConf());
+    // export the sentry mapping data from database to map structure
+    Map<String, Map<String, Set<String>>> policyFileMappingData = client
+        .exportPolicy(requestorUserName);
+    // get the FileFormatter according to the configuration
+    SentryPolicyFileFormatter sentryPolicyFileFormatter = SentryPolicyFileFormatFactory
+        .createFileFormatter(authzConf);
+    // write the sentry mapping data to exportPolicyFilePath with the data in map structure
+    sentryPolicyFileFormatter.write(exportPolicyFilePath, policyFileMappingData);
   }
 
   // list permissions for given user
@@ -510,7 +432,8 @@ public class SentryConfigTool {
   }
 
   /**
-   *  parse arguments
+   * parse arguments
+   * 
    * <pre>
    *   -d,--debug                  Enable debug output
    *   -e,--query <arg>            Query privilege verification, requires -u
@@ -523,7 +446,10 @@ public class SentryConfigTool {
    *   -u,--user <arg>             user name
    *   -v,--validate               Validate policy file
    *   -I,--import                 Import policy file
+   *   -E,--export                 Export policy file
+   *   -o,--overwrite              Overwrite the exist role data when do the import
    * </pre>
+   * 
    * @param args
    */
   private void parseArgs(String[] args) {
@@ -549,9 +475,12 @@ public class SentryConfigTool {
         "list privileges for given user, requires -u");
     listPrivsOpt.setRequired(false);
 
-    Option importOpt = new Option("I", "import", false,
+    Option importOpt = new Option("I", "import", true,
         "Import policy file");
+    importOpt.setRequired(false);
 
+    Option exportOpt = new Option("E", "export", true, "Export policy file");
+    exportOpt.setRequired(false);
     // required args
     OptionGroup sentryOptGroup = new OptionGroup();
     sentryOptGroup.addOption(helpOpt);
@@ -560,6 +489,7 @@ public class SentryConfigTool {
     sentryOptGroup.addOption(listPermsOpt);
     sentryOptGroup.addOption(listPrivsOpt);
     sentryOptGroup.addOption(importOpt);
+    sentryOptGroup.addOption(exportOpt);
     sentryOptGroup.setRequired(true);
     sentryOptions.addOptionGroup(sentryOptGroup);
 
@@ -590,6 +520,10 @@ public class SentryConfigTool {
     debugOpt.setRequired(false);
     sentryOptions.addOption(debugOpt);
 
+    Option overwriteOpt = new Option("o", "overwrite", false, "enable import overwrite");
+    overwriteOpt.setRequired(false);
+    sentryOptions.addOption(overwriteOpt);
+
     try {
       Parser parser = new GnuParser();
       CommandLine cmd = parser.parse(sentryOptions, args);
@@ -612,11 +546,15 @@ public class SentryConfigTool {
         } else if (opt.getOpt().equals("v")) {
           setValidate(true);
         } else if (opt.getOpt().equals("I")) {
-          setImportPolicy(true);
+          setImportPolicyFilePath(opt.getValue());
+        } else if (opt.getOpt().equals("E")) {
+          setExportPolicyFilePath(opt.getValue());
         } else if (opt.getOpt().equals("h")) {
           usage(sentryOptions);
         } else if (opt.getOpt().equals("d")) {
           enableDebug = true;
+        } else if (opt.getOpt().equals("o")) {
+          setImportOverwriteRole(true);
         }
       }
 
@@ -653,10 +591,14 @@ public class SentryConfigTool {
           sentryTool.validatePolicy();
         }
 
-        if (sentryTool.isImportPolicy()) {
+        if (!StringUtils.isEmpty(sentryTool.getImportPolicyFilePath())) {
           sentryTool.importPolicy();
         }
 
+        if (!StringUtils.isEmpty(sentryTool.getExportPolicyFilePath())) {
+          sentryTool.exportPolicy();
+        }
+
         // list permissions for give user
         if (sentryTool.isListPrivs()) {
           sentryTool.listPrivs();

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
index f31fa54..4f87d5a 100644
--- a/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
+++ b/sentry-binding/sentry-binding-hive/src/main/java/org/apache/sentry/binding/hive/conf/HiveAuthzConf.java
@@ -16,18 +16,17 @@
  */
 package org.apache.sentry.binding.hive.conf;
 
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hive.conf.HiveConf;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 public class HiveAuthzConf extends Configuration {
 
@@ -61,6 +60,9 @@ public class HiveAuthzConf extends Configuration {
     AUTHZ_PROVIDER_RESOURCE("sentry.hive.provider.resource", ""),
     AUTHZ_PROVIDER_BACKEND("sentry.hive.provider.backend", "org.apache.sentry.provider.file.SimpleFileProviderBackend"),
     AUTHZ_POLICY_ENGINE("sentry.hive.policy.engine", "org.apache.sentry.policy.db.SimpleDBPolicyEngine"),
+    AUTHZ_POLICY_FILE_FORMATTER(
+        "sentry.hive.policy.file.formatter",
+        "org.apache.sentry.binding.hive.SentryIniPolicyFileFormatter"),
     AUTHZ_SERVER_NAME("sentry.hive.server", "HS2"),
     AUTHZ_RESTRICT_DEFAULT_DB("sentry.hive.restrict.defaultDB", "false"),
     SENTRY_TESTING_MODE("sentry.hive.testing.mode", "false"),

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/92cde111/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java
new file mode 100644
index 0000000..655417b
--- /dev/null
+++ b/sentry-binding/sentry-binding-hive/src/test/java/org/apache/sentry/binding/hive/TestSentryIniPolicyFileFormatter.java
@@ -0,0 +1,220 @@
+/*
+ * 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.binding.hive;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sentry.binding.hive.conf.HiveAuthzConf;
+import org.apache.sentry.provider.common.PolicyFileConstants;
+import org.apache.sentry.provider.common.ProviderConstants;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+public class TestSentryIniPolicyFileFormatter {
+
+  private static final String RESOURCE_PATH = "testImportExportPolicy.ini";
+  // define the privileges
+  public static String PRIVILIEGE1 = "server=server1";
+  public static String PRIVILIEGE2 = "server=server1->action=select->grantoption=false";
+  public static String PRIVILIEGE3 = "server=server1->db=db2->action=insert->grantoption=true";
+  public static String PRIVILIEGE4 = "server=server1->db=db1->table=tbl1->action=insert";
+  public static String PRIVILIEGE5 = "server=server1->db=db1->table=tbl2->column=col1->action=insert";
+  public static String PRIVILIEGE6 = "server=server1->db=db1->table=tbl3->column=col1->action=*->grantoption=true";
+  public static String PRIVILIEGE7 = "server=server1->db=db1->table=tbl4->column=col1->action=all->grantoption=true";
+  public static String PRIVILIEGE8 = "server=server1->uri=hdfs://testserver:9999/path2->action=insert";
+
+  private Map<String, Map<String, Set<String>>> policyFileMappingData1;
+  private Map<String, Map<String, Set<String>>> policyFileMappingData2;
+  private Map<String, Map<String, Set<String>>> policyFileMappingData3;
+  private Map<String, Map<String, Set<String>>> policyFileMappingData4;
+  private Map<String, Map<String, Set<String>>> policyFileMappingData5;
+
+  private void prepareTestData() {
+    // test data for:
+    // [groups]
+    // group1=role1,role2,role3
+    // group2=role1,role2,role3
+    // group3=role1,role2,role3
+    // [roles]
+    // role1=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+    // role2=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+    // role3=privilege1,privilege2,privilege3,privilege4,privilege5,privilege6,privilege7,privilege8
+    policyFileMappingData1 = Maps.newHashMap();
+    Map<String, Set<String>> groupRolesMap = Maps.newHashMap();
+    Map<String, Set<String>> rolePrivilegesMap = Maps.newHashMap();
+    Set<String> roles = Sets.newHashSet("role1", "role2", "role3");
+    groupRolesMap.put("group1", roles);
+    groupRolesMap.put("group2", roles);
+    groupRolesMap.put("group3", roles);
+    for (String roleName : roles) {
+      rolePrivilegesMap.put(roleName, Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3,
+          PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+    }
+    policyFileMappingData1.put(PolicyFileConstants.GROUPS, groupRolesMap);
+    policyFileMappingData1.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+
+    // test data for:
+    // [groups]
+    // group1=role1
+    // group2=role2
+    // group3=role3
+    // [roles]
+    // role1=privilege1,privilege2,privilege3
+    // role2=privilege4,privilege5,privilege6
+    // role3=privilege7,privilege8
+    policyFileMappingData2 = Maps.newHashMap();
+    groupRolesMap = Maps.newHashMap();
+    rolePrivilegesMap = Maps.newHashMap();
+    groupRolesMap.put("group1", Sets.newHashSet("role1"));
+    groupRolesMap.put("group2", Sets.newHashSet("role2"));
+    groupRolesMap.put("group3", Sets.newHashSet("role3"));
+    rolePrivilegesMap.put("role1", Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3));
+    rolePrivilegesMap.put("role2", Sets.newHashSet(PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6));
+    rolePrivilegesMap.put("role3", Sets.newHashSet(PRIVILIEGE7, PRIVILIEGE8));
+    policyFileMappingData2.put(PolicyFileConstants.GROUPS, groupRolesMap);
+    policyFileMappingData2.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+
+    // test data for:
+    // [groups]
+    // group1=role1,role2
+    // group2=role1,role2,role3
+    // group3=role2,role3
+    // [roles]
+    // role1=privilege1,privilege2,privilege3,privilege4
+    // role2=privilege3,privilege4,privilege5,privilege6
+    // role3=privilege5,privilege6,privilege7,privilege8
+    policyFileMappingData3 = Maps.newHashMap();
+    groupRolesMap = Maps.newHashMap();
+    rolePrivilegesMap = Maps.newHashMap();
+    groupRolesMap.put("group1", Sets.newHashSet("role1", "role2"));
+    groupRolesMap.put("group2", Sets.newHashSet("role1", "role2", "role3"));
+    groupRolesMap.put("group3", Sets.newHashSet("role2", "role3"));
+    rolePrivilegesMap.put("role1",
+        Sets.newHashSet(PRIVILIEGE1, PRIVILIEGE2, PRIVILIEGE3, PRIVILIEGE4));
+    rolePrivilegesMap.put("role2",
+        Sets.newHashSet(PRIVILIEGE3, PRIVILIEGE4, PRIVILIEGE5, PRIVILIEGE6));
+    rolePrivilegesMap.put("role3",
+        Sets.newHashSet(PRIVILIEGE5, PRIVILIEGE6, PRIVILIEGE7, PRIVILIEGE8));
+    policyFileMappingData3.put(PolicyFileConstants.GROUPS, groupRolesMap);
+    policyFileMappingData3.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+
+    // test data for groups only
+    policyFileMappingData4 = Maps.newHashMap();
+    groupRolesMap = Maps.newHashMap();
+    rolePrivilegesMap = Maps.newHashMap();
+    groupRolesMap.put("group1", Sets.newHashSet("role1", "role2"));
+    policyFileMappingData4.put(PolicyFileConstants.GROUPS, groupRolesMap);
+    policyFileMappingData4.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+
+    // test empty data
+    policyFileMappingData5 = Maps.newHashMap();
+    groupRolesMap = Maps.newHashMap();
+    rolePrivilegesMap = Maps.newHashMap();
+    policyFileMappingData5.put(PolicyFileConstants.GROUPS, groupRolesMap);
+    policyFileMappingData5.put(PolicyFileConstants.ROLES, rolePrivilegesMap);
+  }
+
+  @Test
+  public void testImportExport() throws Exception {
+    prepareTestData();
+    File baseDir = Files.createTempDir();
+    String resourcePath = (new File(baseDir, RESOURCE_PATH)).getAbsolutePath();
+    HiveAuthzConf authzConf = new HiveAuthzConf(Resources.getResource("sentry-site.xml"));
+    SentryIniPolicyFileFormatter iniFormatter = new SentryIniPolicyFileFormatter();
+
+    // test data1
+    iniFormatter.write(resourcePath, policyFileMappingData1);
+    Map<String, Map<String, Set<String>>> parsedMappingData = iniFormatter.parse(resourcePath,
+        authzConf);
+    validateSentryMappingData(parsedMappingData, policyFileMappingData1);
+
+    // test data2
+    iniFormatter.write(resourcePath, policyFileMappingData2);
+    parsedMappingData = iniFormatter.parse(resourcePath, authzConf);
+    validateSentryMappingData(parsedMappingData, policyFileMappingData2);
+
+    // test data3
+    iniFormatter.write(resourcePath, policyFileMappingData3);
+    parsedMappingData = iniFormatter.parse(resourcePath, authzConf);
+    validateSentryMappingData(parsedMappingData, policyFileMappingData3);
+
+    // test data4
+    iniFormatter.write(resourcePath, policyFileMappingData4);
+    parsedMappingData = iniFormatter.parse(resourcePath, authzConf);
+    assertTrue(parsedMappingData.get(PolicyFileConstants.GROUPS).isEmpty());
+    assertTrue(parsedMappingData.get(PolicyFileConstants.ROLES).isEmpty());
+
+    // test data5
+    iniFormatter.write(resourcePath, policyFileMappingData5);
+    parsedMappingData = iniFormatter.parse(resourcePath, authzConf);
+    assertTrue(parsedMappingData.get(PolicyFileConstants.GROUPS).isEmpty());
+    assertTrue(parsedMappingData.get(PolicyFileConstants.ROLES).isEmpty());
+    (new File(baseDir, RESOURCE_PATH)).delete();
+  }
+
+  // verify the mapping data
+  public void validateSentryMappingData(Map<String, Map<String, Set<String>>> actualMappingData,
+      Map<String, Map<String, Set<String>>> expectedMappingData) {
+    validateGroupRolesMap(actualMappingData.get(PolicyFileConstants.GROUPS),
+        expectedMappingData.get(PolicyFileConstants.GROUPS));
+    validateRolePrivilegesMap(actualMappingData.get(PolicyFileConstants.ROLES),
+        expectedMappingData.get(PolicyFileConstants.ROLES));
+  }
+
+  // verify the mapping data for [group,role]
+  private void validateGroupRolesMap(Map<String, Set<String>> actualMap,
+      Map<String, Set<String>> expectedMap) {
+    assertEquals(expectedMap.keySet().size(), actualMap.keySet().size());
+    for (String groupName : actualMap.keySet()) {
+      Set<String> actualRoles = actualMap.get(groupName);
+      Set<String> expectedRoles = expectedMap.get(groupName);
+      assertEquals(actualRoles.size(), expectedRoles.size());
+      assertTrue(actualRoles.equals(expectedRoles));
+    }
+  }
+
+  // verify the mapping data for [role,privilege]
+  private void validateRolePrivilegesMap(Map<String, Set<String>> actualMap,
+      Map<String, Set<String>> expectedMap) {
+    assertEquals(expectedMap.keySet().size(), actualMap.keySet().size());
+    for (String roleName : actualMap.keySet()) {
+      Set<String> actualPrivileges = actualMap.get(roleName);
+      Set<String> exceptedPrivileges = expectedMap.get(roleName);
+      assertEquals(exceptedPrivileges.size(), actualPrivileges.size());
+      for (String actualPrivilege : actualPrivileges) {
+        boolean isFound = exceptedPrivileges.contains(actualPrivilege);
+        if (!isFound) {
+          String withOptionPrivilege = ProviderConstants.AUTHORIZABLE_JOINER.join(actualPrivilege,
+              ProviderConstants.KV_JOINER.join(PolicyFileConstants.PRIVILEGE_GRANT_OPTION_NAME,
+                  "false"));
+          isFound = exceptedPrivileges.contains(withOptionPrivilege);
+        }
+        assertTrue(isFound);
+      }
+    }
+  }
+}