Repository: sentry Updated Branches: refs/heads/master b19cb01b4 -> a68386e3a
SENTRY-1843: Fork sentry-binding-hive-follower package to support Hive 2.x, (kalyan kumar kalvagadda reviewed by Colm O hEigeartaigh) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/a68386e3 Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/a68386e3 Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/a68386e3 Branch: refs/heads/master Commit: a68386e3a2af834b7679129c76a168c5402727af Parents: b19cb01 Author: Kalyan Kumar Kalvagadda <kkal...@cloudera.com> Authored: Wed Aug 2 13:11:38 2017 -0500 Committer: Kalyan Kumar Kalvagadda <kkal...@cloudera.com> Committed: Wed Aug 2 13:11:38 2017 -0500 ---------------------------------------------------------------------- sentry-binding/pom.xml | 3 +- .../sentry-binding-hive-follower-v2/pom.xml | 71 ++++++ .../json/SentryJSONAddPartitionMessage.java | 48 ++++ .../json/SentryJSONAlterPartitionMessage.java | 66 +++++ .../json/SentryJSONAlterTableMessage.java | 54 ++++ .../json/SentryJSONCreateDatabaseMessage.java | 44 ++++ .../json/SentryJSONCreateTableMessage.java | 44 ++++ .../json/SentryJSONDropDatabaseMessage.java | 44 ++++ .../json/SentryJSONDropPartitionMessage.java | 51 ++++ .../json/SentryJSONDropTableMessage.java | 45 ++++ .../json/SentryJSONMessageDeserializer.java | 138 ++++++++++ .../json/SentryJSONMessageFactory.java | 161 ++++++++++++ .../json/SentryJSONAddPartitionMessage.java | 43 ++-- .../json/SentryJSONAlterPartitionMessage.java | 66 ++--- .../json/SentryJSONAlterTableMessage.java | 59 ++--- .../json/SentryJSONCreateDatabaseMessage.java | 32 +-- .../json/SentryJSONCreateTableMessage.java | 33 ++- .../json/SentryJSONDropDatabaseMessage.java | 34 +-- .../json/SentryJSONDropPartitionMessage.java | 47 ++-- .../json/SentryJSONDropTableMessage.java | 32 +-- .../json/SentryJSONMessageDeserializer.java | 187 +++++++------- .../json/SentryJSONMessageFactory.java | 251 ++++++++++--------- sentry-provider/sentry-provider-db/pom.xml | 33 ++- 23 files changed, 1187 insertions(+), 399 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/pom.xml ---------------------------------------------------------------------- diff --git a/sentry-binding/pom.xml b/sentry-binding/pom.xml index 71fe47c..505ae98 100644 --- a/sentry-binding/pom.xml +++ b/sentry-binding/pom.xml @@ -34,7 +34,6 @@ limitations under the License. <module>sentry-binding-hive-common</module> <module>sentry-binding-solr</module> <module>sentry-binding-sqoop</module> - <module>sentry-binding-hive-follower</module> <module>sentry-binding-hive-conf</module> </modules> @@ -47,6 +46,7 @@ limitations under the License. </activation> <modules> <module>sentry-binding-hive</module> + <module>sentry-binding-hive-follower</module> </modules> </profile> <profile> @@ -56,6 +56,7 @@ limitations under the License. </activation> <modules> <module>sentry-binding-hive-v2</module> + <module>sentry-binding-hive-follower-v2</module> </modules> </profile> </profiles> http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/pom.xml ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/pom.xml b/sentry-binding/sentry-binding-hive-follower-v2/pom.xml new file mode 100644 index 0000000..fa7e928 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/pom.xml @@ -0,0 +1,71 @@ +<?xml version="1.0"?> +<!-- +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.sentry</groupId> + <artifactId>sentry-binding</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <artifactId>sentry-binding-hive-follower-v2</artifactId> + <name>Hive follower v2 for Sentry</name> + + <properties> + <datanucleus-api-jdo.version>4.2.1</datanucleus-api-jdo.version> + <datanucleus-core.version>4.1.6</datanucleus-core.version> + <datanucleus-rdbms.version>4.1.7</datanucleus-rdbms.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-core</artifactId> + <version>${datanucleus-core.version}</version> + </dependency> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-api-jdo</artifactId> + <version>${datanucleus-api-jdo.version}</version> + </dependency> + <dependency> + <groupId>org.datanucleus</groupId> + <artifactId>datanucleus-rdbms</artifactId> + <version>${datanucleus-rdbms.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.hive</groupId> + <artifactId>hive-exec</artifactId> + <version>${hive.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.hive.hcatalog</groupId> + <artifactId>hive-hcatalog-server-extensions</artifactId> + <version>${hive.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java new file mode 100644 index 0000000..10d7a93 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java @@ -0,0 +1,48 @@ +/** + * 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.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.json.JSONAddPartitionMessage; +import org.codehaus.jackson.annotate.JsonProperty; + +import java.util.List; +import java.util.Map; + +public class SentryJSONAddPartitionMessage extends JSONAddPartitionMessage { + @JsonProperty + private List<String> locations; + + public SentryJSONAddPartitionMessage() { + } + + public SentryJSONAddPartitionMessage(String server, String servicePrincipal, String db, String table, + List<Map<String, String>> partitions, Long timestamp, List<String> locations) { + super(server, servicePrincipal, db, table, partitions, timestamp); + this.locations = locations; + } + + public List<String> getLocations() { + return locations; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java new file mode 100644 index 0000000..b29d727 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java @@ -0,0 +1,66 @@ +/** + * 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.metastore.messaging.json; + +import com.google.common.collect.ImmutableList; +import org.apache.hive.hcatalog.messaging.json.JSONAlterPartitionMessage; +import org.codehaus.jackson.annotate.JsonProperty; + +import java.util.List; + +public class SentryJSONAlterPartitionMessage extends JSONAlterPartitionMessage { + @JsonProperty + private String newLocation; + @JsonProperty + private String oldLocation; + @JsonProperty + private List<String> newValues; + + public SentryJSONAlterPartitionMessage() { + super("", "", "", "", ImmutableList.<String>of(), null); + } + + public SentryJSONAlterPartitionMessage(String server, String servicePrincipal, + String db, String table, + List<String> values, List<String> newValues, + Long timestamp, String oldlocation, + String newLocation) { + super(server, servicePrincipal, db, table, values, timestamp); + this.newLocation = newLocation; + this.oldLocation = oldlocation; + this.newValues = newValues; + } + + public String getNewLocation() { + return newLocation; + } + + public String getOldLocation() { + return oldLocation; + } + + public List<String> getNewValues() { + return newValues; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java new file mode 100644 index 0000000..4670494 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * 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.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.json.JSONAlterTableMessage; +import org.codehaus.jackson.annotate.JsonProperty; + +public class SentryJSONAlterTableMessage extends JSONAlterTableMessage { + @JsonProperty + private String newLocation; + @JsonProperty + private String oldLocation; + + public SentryJSONAlterTableMessage() { + super("", "", "", "", null); + } + + public SentryJSONAlterTableMessage(String server, String servicePrincipal, + String db, String table, Long timestamp, + String oldLocation, String newLocation) { + super(server, servicePrincipal, db, table, timestamp); + this.newLocation = newLocation; + this.oldLocation = oldLocation; + } + + public String getNewLocation() { + return newLocation; + } + + public String getOldLocation() { + return oldLocation; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java new file mode 100644 index 0000000..8c62758 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.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.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.json.JSONCreateDatabaseMessage; +import org.codehaus.jackson.annotate.JsonProperty; + +public class SentryJSONCreateDatabaseMessage extends JSONCreateDatabaseMessage { + @JsonProperty + private String location; + + public SentryJSONCreateDatabaseMessage() { + } + + public SentryJSONCreateDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp, String location) { + super(server, servicePrincipal, db, timestamp); + this.location = location; + } + + public String getLocation() { + return location; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java new file mode 100644 index 0000000..d15bc48 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.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.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.json.JSONCreateTableMessage; +import org.codehaus.jackson.annotate.JsonProperty; + +public class SentryJSONCreateTableMessage extends JSONCreateTableMessage { + @JsonProperty + private String location; + + public SentryJSONCreateTableMessage() { + } + + public SentryJSONCreateTableMessage(String server, String servicePrincipal, String db, String table, Long timestamp, String location) { + super(server, servicePrincipal, db, table, timestamp); + this.location = location; + } + + public String getLocation() { + return location; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java new file mode 100644 index 0000000..c8e7c75 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.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.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.json.JSONDropDatabaseMessage; +import org.codehaus.jackson.annotate.JsonProperty; + +public class SentryJSONDropDatabaseMessage extends JSONDropDatabaseMessage { + @JsonProperty + private String location; + + public SentryJSONDropDatabaseMessage() { + } + + public SentryJSONDropDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp, String location) { + super(server, servicePrincipal, db, timestamp); + this.location = location; + } + + public String getLocation() { + return location; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java new file mode 100644 index 0000000..d5f899c --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java @@ -0,0 +1,51 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.sentry.binding.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.json.JSONDropPartitionMessage; +import org.codehaus.jackson.annotate.JsonProperty; + +import java.util.List; +import java.util.Map; + +public class SentryJSONDropPartitionMessage extends JSONDropPartitionMessage { + @JsonProperty + private List<String> locations; + + public SentryJSONDropPartitionMessage() { + } + + public SentryJSONDropPartitionMessage(String server, String servicePrincipal, + String db, String table, + List<Map<String, String>> partitions, + Long timestamp, List<String> locations) { + super(server, servicePrincipal, db, table, partitions, timestamp); + this.locations = locations; + } + + public List<String> getLocations() { + return locations; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } + +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java new file mode 100644 index 0000000..e67f562 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java @@ -0,0 +1,45 @@ +/** + * 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.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.json.JSONDropTableMessage; +import org.codehaus.jackson.annotate.JsonProperty; + + +public class SentryJSONDropTableMessage extends JSONDropTableMessage { + @JsonProperty + private String location; + + public SentryJSONDropTableMessage() { + } + + public SentryJSONDropTableMessage(String server, String servicePrincipal, String db, String table, Long timestamp, String location) { + super(server, servicePrincipal, db, table, timestamp); + this.location = location; + } + + public String getLocation() { + return location; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java new file mode 100644 index 0000000..cc0bbec --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java @@ -0,0 +1,138 @@ +/** + * 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.metastore.messaging.json; + +import org.apache.hive.hcatalog.messaging.*; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; + +public class SentryJSONMessageDeserializer extends MessageDeserializer { + private static ObjectMapper mapper = new ObjectMapper(); + + static { + mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + public SentryJSONMessageDeserializer() { + } + + /** + * Method to de-serialize CreateDatabaseMessage instance. + */ + @Override + public SentryJSONCreateDatabaseMessage getCreateDatabaseMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONCreateDatabaseMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONCreateDatabaseMessage: ", e); + } + } + + /** + * Method to de-serialize DropDatabaseMessage instance. + */ + @Override + public SentryJSONDropDatabaseMessage getDropDatabaseMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONDropDatabaseMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONDropDatabaseMessage: ", e); + } + } + + /** + * Method to de-serialize CreateTableMessage instance. + */ + @Override + public SentryJSONCreateTableMessage getCreateTableMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONCreateTableMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONCreateTableMessage: ", e); + } + } + + /** + * Method to de-serialize AlterTableMessage instance. + */ + @Override + public SentryJSONAlterTableMessage getAlterTableMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONAlterTableMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONAlterTableMessage: ", e); + } + } + + /** + * Method to de-serialize DropTableMessage instance. + */ + @Override + public SentryJSONDropTableMessage getDropTableMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONDropTableMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONDropTableMessage: ", e); + } + } + + /** + * Method to de-serialize AddPartitionMessage instance. + */ + @Override + public SentryJSONAddPartitionMessage getAddPartitionMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONAddPartitionMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONAddPartitionMessage: ", e); + } + } + + /** + * Method to de-serialize AlterPartitionMessage instance. + */ + @Override + public SentryJSONAlterPartitionMessage getAlterPartitionMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONAlterPartitionMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONAlterPartitionMessage: ", e); + } + } + + /** + * Method to de-serialize DropPartitionMessage instance. + */ + @Override + public SentryJSONDropPartitionMessage getDropPartitionMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONDropPartitionMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONDropPartitionMessage: ", e); + } + } + + public static String serialize(Object object) { + try { + return mapper.writeValueAsString(object); + } catch (Exception exception) { + throw new IllegalArgumentException("Could not serialize: ", exception); + } + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java new file mode 100644 index 0000000..f173243 --- /dev/null +++ b/sentry-binding/sentry-binding-hive-follower-v2/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.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.metastore.messaging.json; + +import com.google.common.collect.Lists; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hive.common.classification.InterfaceAudience; +import org.apache.hadoop.hive.common.classification.InterfaceStability; +import org.apache.hadoop.hive.metastore.api.Database; +import org.apache.hadoop.hive.metastore.api.Partition; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy; +import org.apache.hive.hcatalog.messaging.*; + +import java.util.*; + +public class SentryJSONMessageFactory extends MessageFactory { + private static final Log LOG = LogFactory.getLog(SentryJSONMessageFactory.class.getName()); + private static SentryJSONMessageDeserializer deserializer = new SentryJSONMessageDeserializer(); + + public SentryJSONMessageFactory() { + LOG.info("Using SentryJSONMessageFactory for building Notification log messages "); + } + + public MessageDeserializer getDeserializer() { + return deserializer; + } + + public String getVersion() { + return "0.1"; + } + + public String getMessageFormat() { + return "json"; + } + + public SentryJSONCreateDatabaseMessage buildCreateDatabaseMessage(Database db) { + return new SentryJSONCreateDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), + now(), db.getLocationUri()); + } + + public SentryJSONDropDatabaseMessage buildDropDatabaseMessage(Database db) { + return new SentryJSONDropDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), + now(), db.getLocationUri()); + } + + public SentryJSONCreateTableMessage buildCreateTableMessage(Table table) { + return new SentryJSONCreateTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), now(), table.getSd().getLocation()); + } + + public SentryJSONAlterTableMessage buildAlterTableMessage(Table before, Table after) { + return new SentryJSONAlterTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), + before.getTableName(), now(), before.getSd().getLocation(), after.getSd().getLocation()); + } + + public SentryJSONDropTableMessage buildDropTableMessage(Table table) { + return new SentryJSONDropTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), now(), table.getSd().getLocation()); + } + + public SentryJSONAddPartitionMessage buildAddPartitionMessage(Table table, List<Partition> partitions) { + return new SentryJSONAddPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), getPartitionKeyValues(table, partitions), now(), + getPartitionLocations(partitions)); + } + + private List<String> getPartitionLocations(List<Partition> partitions) { + List<String> paths = Lists.newLinkedList(); + for (Partition partition : partitions) { + paths.add(partition.getSd().getLocation()); + } + return paths; + } + + private List<String> getPartitionLocations(PartitionSpecProxy partitionSpec) { + Iterator<Partition> iterator = partitionSpec.getPartitionIterator(); + List<String> locations = Lists.newLinkedList(); + while (iterator.hasNext()) { + locations.add(iterator.next().getSd().getLocation()); + } + return locations; + } + + @InterfaceAudience.LimitedPrivate( {"Hive"}) + @InterfaceStability.Evolving + public SentryJSONAddPartitionMessage buildAddPartitionMessage(Table table, PartitionSpecProxy partitionSpec) { + return new SentryJSONAddPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), getPartitionKeyValues(table, partitionSpec), now(), + getPartitionLocations(partitionSpec)); + } + + @Override + public SentryJSONAlterPartitionMessage buildAlterPartitionMessage(Partition before, Partition after) { + return new SentryJSONAlterPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), + before.getTableName(), before.getValues(), after.getValues(), now(), before.getSd().getLocation(), + after.getSd().getLocation()); + } + + public SentryJSONDropPartitionMessage buildDropPartitionMessage(Table table, Partition partition) { + return new SentryJSONDropPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, partition.getDbName(), + partition.getTableName(), Arrays.asList(getPartitionKeyValues(table, partition)), + now(), Arrays.asList(partition.getSd().getLocation())); + } + + private static Map<String, String> getPartitionKeyValues(Table table, Partition partition) { + LinkedHashMap partitionKeys = new LinkedHashMap(); + + for (int i = 0; i < table.getPartitionKeysSize(); ++i) { + partitionKeys.put((table.getPartitionKeys().get(i)).getName(), partition.getValues().get(i)); + } + + return partitionKeys; + } + + private static List<Map<String, String>> getPartitionKeyValues(Table table, List<Partition> partitions) { + List<Map<String, String>> partitionList = Lists.newLinkedList(); + + for (Partition partition : partitions) { + partitionList.add(getPartitionKeyValues(table, partition)); + } + + return partitionList; + } + + @InterfaceAudience.LimitedPrivate( {"Hive"}) + @InterfaceStability.Evolving + private static List<Map<String, String>> getPartitionKeyValues(Table table, PartitionSpecProxy partitionSpec) { + ArrayList partitionList = new ArrayList(); + PartitionSpecProxy.PartitionIterator iterator = partitionSpec.getPartitionIterator(); + + while (iterator.hasNext()) { + Partition partition = iterator.next(); + partitionList.add(getPartitionKeyValues(table, partition)); + } + + return partitionList; + } + + //This is private in parent class + private long now() { + return System.currentTimeMillis() / 1000L; + } +} http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java index 5c656eb..10d7a93 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAddPartitionMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -25,25 +25,24 @@ import java.util.List; import java.util.Map; public class SentryJSONAddPartitionMessage extends JSONAddPartitionMessage { - @JsonProperty - private List<String> locations; - - public SentryJSONAddPartitionMessage() { - } - - public SentryJSONAddPartitionMessage(String server, String servicePrincipal, String db, String table, - List<Map<String, String>> partitions, Long timestamp, List<String> locations) { - super(server, servicePrincipal, db, table, partitions, timestamp); - this.locations = locations; - } - - public List<String> getLocations() { - return locations; - } - - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } - + @JsonProperty + private List<String> locations; + + public SentryJSONAddPartitionMessage() { + } + + public SentryJSONAddPartitionMessage(String server, String servicePrincipal, String db, String table, + List<Map<String, String>> partitions, Long timestamp, List<String> locations) { + super(server, servicePrincipal, db, table, partitions, timestamp); + this.locations = locations; + } + + public List<String> getLocations() { + return locations; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java index 161bf4d..b29d727 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterPartitionMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -25,42 +25,42 @@ import org.codehaus.jackson.annotate.JsonProperty; import java.util.List; public class SentryJSONAlterPartitionMessage extends JSONAlterPartitionMessage { - @JsonProperty - private String newLocation; - @JsonProperty - private String oldLocation; - @JsonProperty - private List<String> newValues; + @JsonProperty + private String newLocation; + @JsonProperty + private String oldLocation; + @JsonProperty + private List<String> newValues; - public SentryJSONAlterPartitionMessage() { - super("", "", "", "", ImmutableList.<String>of(), null); - } + public SentryJSONAlterPartitionMessage() { + super("", "", "", "", ImmutableList.<String>of(), null); + } - public SentryJSONAlterPartitionMessage(String server, String servicePrincipal, - String db, String table, - List<String> values, List<String> newValues, - Long timestamp, String oldlocation, - String newLocation) { - super(server, servicePrincipal, db, table, values, timestamp); - this.newLocation = newLocation; - this.oldLocation = oldlocation; - this.newValues = newValues; - } + public SentryJSONAlterPartitionMessage(String server, String servicePrincipal, + String db, String table, + List<String> values, List<String> newValues, + Long timestamp, String oldlocation, + String newLocation) { + super(server, servicePrincipal, db, table, values, timestamp); + this.newLocation = newLocation; + this.oldLocation = oldlocation; + this.newValues = newValues; + } - public String getNewLocation() { - return newLocation; - } + public String getNewLocation() { + return newLocation; + } - public String getOldLocation() { - return oldLocation; - } + public String getOldLocation() { + return oldLocation; + } - public List<String> getNewValues() { - return newValues; - } + public List<String> getNewValues() { + return newValues; + } - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java index b590fe8..4670494 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONAlterTableMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -22,32 +22,33 @@ import org.apache.hive.hcatalog.messaging.json.JSONAlterTableMessage; import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONAlterTableMessage extends JSONAlterTableMessage { - @JsonProperty - private String newLocation; - @JsonProperty - private String oldLocation; - - public SentryJSONAlterTableMessage() { - super("", "", "", "", null); - } - - public SentryJSONAlterTableMessage(String server, String servicePrincipal, - String db, String table, Long timestamp, - String oldLocation, String newLocation) { - super(server, servicePrincipal, db, table, timestamp); - this.newLocation = newLocation; - this.oldLocation = oldLocation; - } - - public String getNewLocation() { - return newLocation; - } - public String getOldLocation() { - return oldLocation; - } - - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } + @JsonProperty + private String newLocation; + @JsonProperty + private String oldLocation; + + public SentryJSONAlterTableMessage() { + super("", "", "", "", null); + } + + public SentryJSONAlterTableMessage(String server, String servicePrincipal, + String db, String table, Long timestamp, + String oldLocation, String newLocation) { + super(server, servicePrincipal, db, table, timestamp); + this.newLocation = newLocation; + this.oldLocation = oldLocation; + } + + public String getNewLocation() { + return newLocation; + } + + public String getOldLocation() { + return oldLocation; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java index 1118cac..8c62758 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateDatabaseMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -22,23 +22,23 @@ import org.apache.hive.hcatalog.messaging.json.JSONCreateDatabaseMessage; import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONCreateDatabaseMessage extends JSONCreateDatabaseMessage { - @JsonProperty - private String location; + @JsonProperty + private String location; - public SentryJSONCreateDatabaseMessage() { - } + public SentryJSONCreateDatabaseMessage() { + } - public SentryJSONCreateDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp, String location) { - super(server, servicePrincipal, db, timestamp); - this.location = location; - } + public SentryJSONCreateDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp, String location) { + super(server, servicePrincipal, db, timestamp); + this.location = location; + } - public String getLocation() { - return location; - } + public String getLocation() { + return location; + } - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java index 8716316..d15bc48 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONCreateTableMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -22,24 +22,23 @@ import org.apache.hive.hcatalog.messaging.json.JSONCreateTableMessage; import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONCreateTableMessage extends JSONCreateTableMessage { - @JsonProperty - private String location; + @JsonProperty + private String location; - public SentryJSONCreateTableMessage() { - } + public SentryJSONCreateTableMessage() { + } - public SentryJSONCreateTableMessage(String server, String servicePrincipal, String db, String table, Long timestamp, String location) { - super(server, servicePrincipal, db, table, timestamp); - this.location = location; - } + public SentryJSONCreateTableMessage(String server, String servicePrincipal, String db, String table, Long timestamp, String location) { + super(server, servicePrincipal, db, table, timestamp); + this.location = location; + } - public String getLocation() { - return location; - } - - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } + public String getLocation() { + return location; + } + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java index f38f69b..c8e7c75 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropDatabaseMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -21,24 +21,24 @@ package org.apache.sentry.binding.metastore.messaging.json; import org.apache.hive.hcatalog.messaging.json.JSONDropDatabaseMessage; import org.codehaus.jackson.annotate.JsonProperty; -public class SentryJSONDropDatabaseMessage extends JSONDropDatabaseMessage{ - @JsonProperty - private String location; +public class SentryJSONDropDatabaseMessage extends JSONDropDatabaseMessage { + @JsonProperty + private String location; - public SentryJSONDropDatabaseMessage() { - } + public SentryJSONDropDatabaseMessage() { + } - public SentryJSONDropDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp, String location) { - super(server, servicePrincipal, db, timestamp); - this.location = location; - } + public SentryJSONDropDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp, String location) { + super(server, servicePrincipal, db, timestamp); + this.location = location; + } - public String getLocation() { - return location; - } + public String getLocation() { + return location; + } - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java index e2c1135..d3ebf60 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropPartitionMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -25,27 +25,26 @@ import java.util.List; import java.util.Map; public class SentryJSONDropPartitionMessage extends JSONDropPartitionMessage { - @JsonProperty - private List<String> locations; - - public SentryJSONDropPartitionMessage() { - } - - public SentryJSONDropPartitionMessage(String server, String servicePrincipal, - String db, String table, - List<Map<String, String>> partitions, - Long timestamp, List<String> locations) { - super(server, servicePrincipal, db, table, partitions, timestamp); - this.locations = locations; - } - - public List<String> getLocations() { - return locations; - } - - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } - + @JsonProperty + private List<String> locations; + + public SentryJSONDropPartitionMessage() { + } + + public SentryJSONDropPartitionMessage(String server, String servicePrincipal, + String db, String table, + List<Map<String, String>> partitions, + Long timestamp, List<String> locations) { + super(server, servicePrincipal, db, table, partitions, timestamp); + this.locations = locations; + } + + public List<String> getLocations() { + return locations; + } + + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java index 40bf2b9..e67f562 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONDropTableMessage.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -23,23 +23,23 @@ import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONDropTableMessage extends JSONDropTableMessage { - @JsonProperty - private String location; + @JsonProperty + private String location; - public SentryJSONDropTableMessage() { - } + public SentryJSONDropTableMessage() { + } - public SentryJSONDropTableMessage(String server, String servicePrincipal, String db, String table, Long timestamp, String location) { - super(server, servicePrincipal, db, table, timestamp); - this.location = location; - } + public SentryJSONDropTableMessage(String server, String servicePrincipal, String db, String table, Long timestamp, String location) { + super(server, servicePrincipal, db, table, timestamp); + this.location = location; + } - public String getLocation() { - return location; - } + public String getLocation() { + return location; + } - @Override - public String toString() { - return SentryJSONMessageDeserializer.serialize(this); - } + @Override + public String toString() { + return SentryJSONMessageDeserializer.serialize(this); + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java index 5f2287e..cc0bbec 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageDeserializer.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -23,117 +23,116 @@ import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; public class SentryJSONMessageDeserializer extends MessageDeserializer { - private static ObjectMapper mapper = new ObjectMapper(); + private static ObjectMapper mapper = new ObjectMapper(); - static { - mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); - } + static { + mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } - public SentryJSONMessageDeserializer() { - } + public SentryJSONMessageDeserializer() { + } - /** - * Method to de-serialize CreateDatabaseMessage instance. - */ - @Override - public SentryJSONCreateDatabaseMessage getCreateDatabaseMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONCreateDatabaseMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONCreateDatabaseMessage: ", e); - } + /** + * Method to de-serialize CreateDatabaseMessage instance. + */ + @Override + public SentryJSONCreateDatabaseMessage getCreateDatabaseMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONCreateDatabaseMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONCreateDatabaseMessage: ", e); } + } - /** - * Method to de-serialize DropDatabaseMessage instance. - */ - @Override - public SentryJSONDropDatabaseMessage getDropDatabaseMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONDropDatabaseMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONDropDatabaseMessage: ", e); - } + /** + * Method to de-serialize DropDatabaseMessage instance. + */ + @Override + public SentryJSONDropDatabaseMessage getDropDatabaseMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONDropDatabaseMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONDropDatabaseMessage: ", e); } + } - /** - * Method to de-serialize CreateTableMessage instance. - */ - @Override - public SentryJSONCreateTableMessage getCreateTableMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONCreateTableMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONCreateTableMessage: ", e); - } + /** + * Method to de-serialize CreateTableMessage instance. + */ + @Override + public SentryJSONCreateTableMessage getCreateTableMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONCreateTableMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONCreateTableMessage: ", e); } + } - /** - * Method to de-serialize AlterTableMessage instance. - */ - @Override - public SentryJSONAlterTableMessage getAlterTableMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONAlterTableMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONAlterTableMessage: ", e); - } + /** + * Method to de-serialize AlterTableMessage instance. + */ + @Override + public SentryJSONAlterTableMessage getAlterTableMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONAlterTableMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONAlterTableMessage: ", e); } + } - /** - * Method to de-serialize DropTableMessage instance. - */ - @Override - public SentryJSONDropTableMessage getDropTableMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONDropTableMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONDropTableMessage: ", e); - } + /** + * Method to de-serialize DropTableMessage instance. + */ + @Override + public SentryJSONDropTableMessage getDropTableMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONDropTableMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONDropTableMessage: ", e); } + } - /** - * Method to de-serialize AddPartitionMessage instance. - */ - @Override - public SentryJSONAddPartitionMessage getAddPartitionMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONAddPartitionMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONAddPartitionMessage: ", e); - } + /** + * Method to de-serialize AddPartitionMessage instance. + */ + @Override + public SentryJSONAddPartitionMessage getAddPartitionMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONAddPartitionMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONAddPartitionMessage: ", e); } + } - /** - * Method to de-serialize AlterPartitionMessage instance. - */ - @Override - public SentryJSONAlterPartitionMessage getAlterPartitionMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONAlterPartitionMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONAlterPartitionMessage: ", e); - } + /** + * Method to de-serialize AlterPartitionMessage instance. + */ + @Override + public SentryJSONAlterPartitionMessage getAlterPartitionMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONAlterPartitionMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONAlterPartitionMessage: ", e); } + } - /** - * Method to de-serialize DropPartitionMessage instance. - */ - @Override - public SentryJSONDropPartitionMessage getDropPartitionMessage(String messageBody) { - try { - return mapper.readValue(messageBody, SentryJSONDropPartitionMessage.class); - } catch (Exception e) { - throw new IllegalArgumentException("Could not construct SentryJSONDropPartitionMessage: ", e); - } + /** + * Method to de-serialize DropPartitionMessage instance. + */ + @Override + public SentryJSONDropPartitionMessage getDropPartitionMessage(String messageBody) { + try { + return mapper.readValue(messageBody, SentryJSONDropPartitionMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONDropPartitionMessage: ", e); } + } - public static String serialize(Object object) { - try { - return mapper.writeValueAsString(object); - } - catch (Exception exception) { - throw new IllegalArgumentException("Could not serialize: ", exception); - } + public static String serialize(Object object) { + try { + return mapper.writeValueAsString(object); + } catch (Exception exception) { + throw new IllegalArgumentException("Could not serialize: ", exception); } + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java index b949ee5..f173243 100644 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java +++ b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/SentryJSONMessageFactory.java @@ -7,7 +7,7 @@ * "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 + * 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, @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.sentry.binding.metastore.messaging.json; import com.google.common.collect.Lists; @@ -31,128 +32,130 @@ import org.apache.hive.hcatalog.messaging.*; import java.util.*; public class SentryJSONMessageFactory extends MessageFactory { - private static final Log LOG = LogFactory.getLog(SentryJSONMessageFactory.class.getName()); - private static SentryJSONMessageDeserializer deserializer = new SentryJSONMessageDeserializer(); - public SentryJSONMessageFactory() { - LOG.info("Using SentryJSONMessageFactory for building Notification log messages "); - } - - public MessageDeserializer getDeserializer() { - return deserializer; - } - - public String getVersion() { - return "0.1"; - } - - public String getMessageFormat() { - return "json"; - } - - public SentryJSONCreateDatabaseMessage buildCreateDatabaseMessage(Database db) { - return new SentryJSONCreateDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), - now(), db.getLocationUri()); - } - public SentryJSONDropDatabaseMessage buildDropDatabaseMessage(Database db) { - return new SentryJSONDropDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), - now(), db.getLocationUri()); - } - - public SentryJSONCreateTableMessage buildCreateTableMessage(Table table) { - return new SentryJSONCreateTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), - table.getTableName(), now(), table.getSd().getLocation()); - } - - public SentryJSONAlterTableMessage buildAlterTableMessage(Table before, Table after) { - return new SentryJSONAlterTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), - before.getTableName(), now(), before.getSd().getLocation(), after.getSd().getLocation()); - } - - public SentryJSONDropTableMessage buildDropTableMessage(Table table) { - return new SentryJSONDropTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), - table.getTableName(), now(), table.getSd().getLocation()); - } - - public SentryJSONAddPartitionMessage buildAddPartitionMessage(Table table, List<Partition> partitions) { - return new SentryJSONAddPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), - table.getTableName(), getPartitionKeyValues(table, partitions), now(), - getPartitionLocations(partitions)); - } - - private List<String> getPartitionLocations(List<Partition> partitions) { - List<String> paths = Lists.newLinkedList(); - for(Partition partition : partitions) { - paths.add(partition.getSd().getLocation()); - } - return paths; - } + private static final Log LOG = LogFactory.getLog(SentryJSONMessageFactory.class.getName()); + private static SentryJSONMessageDeserializer deserializer = new SentryJSONMessageDeserializer(); + + public SentryJSONMessageFactory() { + LOG.info("Using SentryJSONMessageFactory for building Notification log messages "); + } + + public MessageDeserializer getDeserializer() { + return deserializer; + } + + public String getVersion() { + return "0.1"; + } + + public String getMessageFormat() { + return "json"; + } - private List<String> getPartitionLocations(PartitionSpecProxy partitionSpec) { - Iterator<Partition> iterator = partitionSpec.getPartitionIterator(); - List<String> locations = Lists.newLinkedList(); - while(iterator.hasNext()) { - locations.add(iterator.next().getSd().getLocation()); - } - return locations; - } - - @InterfaceAudience.LimitedPrivate({"Hive"}) - @InterfaceStability.Evolving - public SentryJSONAddPartitionMessage buildAddPartitionMessage(Table table, PartitionSpecProxy partitionSpec) { - return new SentryJSONAddPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), - table.getTableName(), getPartitionKeyValues(table, partitionSpec), now(), - getPartitionLocations(partitionSpec)); - } - - @Override - public SentryJSONAlterPartitionMessage buildAlterPartitionMessage(Partition before, Partition after) { - return new SentryJSONAlterPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), - before.getTableName(), before.getValues(), after.getValues(), now(), before.getSd().getLocation(), - after.getSd().getLocation()); - } - - public SentryJSONDropPartitionMessage buildDropPartitionMessage(Table table, Partition partition) { - return new SentryJSONDropPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, partition.getDbName(), - partition.getTableName(), Arrays.asList(getPartitionKeyValues(table, partition)), - now(), Arrays.asList(partition.getSd().getLocation())); - } - - private static Map<String, String> getPartitionKeyValues(Table table, Partition partition) { - LinkedHashMap partitionKeys = new LinkedHashMap(); - - for(int i = 0; i < table.getPartitionKeysSize(); ++i) { - partitionKeys.put((table.getPartitionKeys().get(i)).getName(), partition.getValues().get(i)); - } - - return partitionKeys; - } - - private static List<Map<String, String>> getPartitionKeyValues(Table table, List<Partition> partitions) { - List<Map<String, String>> partitionList = Lists.newLinkedList(); - - for (Partition partition : partitions) { - partitionList.add(getPartitionKeyValues(table, partition)); - } - - return partitionList; - } - - @InterfaceAudience.LimitedPrivate({"Hive"}) - @InterfaceStability.Evolving - private static List<Map<String, String>> getPartitionKeyValues(Table table, PartitionSpecProxy partitionSpec) { - ArrayList partitionList = new ArrayList(); - PartitionSpecProxy.PartitionIterator iterator = partitionSpec.getPartitionIterator(); - - while(iterator.hasNext()) { - Partition partition = iterator.next(); - partitionList.add(getPartitionKeyValues(table, partition)); - } - - return partitionList; - } - - //This is private in parent class - private long now() { - return System.currentTimeMillis() / 1000L; - } + public SentryJSONCreateDatabaseMessage buildCreateDatabaseMessage(Database db) { + return new SentryJSONCreateDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), + now(), db.getLocationUri()); + } + + public SentryJSONDropDatabaseMessage buildDropDatabaseMessage(Database db) { + return new SentryJSONDropDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), + now(), db.getLocationUri()); + } + + public SentryJSONCreateTableMessage buildCreateTableMessage(Table table) { + return new SentryJSONCreateTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), now(), table.getSd().getLocation()); + } + + public SentryJSONAlterTableMessage buildAlterTableMessage(Table before, Table after) { + return new SentryJSONAlterTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), + before.getTableName(), now(), before.getSd().getLocation(), after.getSd().getLocation()); + } + + public SentryJSONDropTableMessage buildDropTableMessage(Table table) { + return new SentryJSONDropTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), now(), table.getSd().getLocation()); + } + + public SentryJSONAddPartitionMessage buildAddPartitionMessage(Table table, List<Partition> partitions) { + return new SentryJSONAddPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), getPartitionKeyValues(table, partitions), now(), + getPartitionLocations(partitions)); + } + + private List<String> getPartitionLocations(List<Partition> partitions) { + List<String> paths = Lists.newLinkedList(); + for (Partition partition : partitions) { + paths.add(partition.getSd().getLocation()); + } + return paths; + } + + private List<String> getPartitionLocations(PartitionSpecProxy partitionSpec) { + Iterator<Partition> iterator = partitionSpec.getPartitionIterator(); + List<String> locations = Lists.newLinkedList(); + while (iterator.hasNext()) { + locations.add(iterator.next().getSd().getLocation()); + } + return locations; + } + + @InterfaceAudience.LimitedPrivate( {"Hive"}) + @InterfaceStability.Evolving + public SentryJSONAddPartitionMessage buildAddPartitionMessage(Table table, PartitionSpecProxy partitionSpec) { + return new SentryJSONAddPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), + table.getTableName(), getPartitionKeyValues(table, partitionSpec), now(), + getPartitionLocations(partitionSpec)); + } + + @Override + public SentryJSONAlterPartitionMessage buildAlterPartitionMessage(Partition before, Partition after) { + return new SentryJSONAlterPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), + before.getTableName(), before.getValues(), after.getValues(), now(), before.getSd().getLocation(), + after.getSd().getLocation()); + } + + public SentryJSONDropPartitionMessage buildDropPartitionMessage(Table table, Partition partition) { + return new SentryJSONDropPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, partition.getDbName(), + partition.getTableName(), Arrays.asList(getPartitionKeyValues(table, partition)), + now(), Arrays.asList(partition.getSd().getLocation())); + } + + private static Map<String, String> getPartitionKeyValues(Table table, Partition partition) { + LinkedHashMap partitionKeys = new LinkedHashMap(); + + for (int i = 0; i < table.getPartitionKeysSize(); ++i) { + partitionKeys.put((table.getPartitionKeys().get(i)).getName(), partition.getValues().get(i)); + } + + return partitionKeys; + } + + private static List<Map<String, String>> getPartitionKeyValues(Table table, List<Partition> partitions) { + List<Map<String, String>> partitionList = Lists.newLinkedList(); + + for (Partition partition : partitions) { + partitionList.add(getPartitionKeyValues(table, partition)); + } + + return partitionList; + } + + @InterfaceAudience.LimitedPrivate( {"Hive"}) + @InterfaceStability.Evolving + private static List<Map<String, String>> getPartitionKeyValues(Table table, PartitionSpecProxy partitionSpec) { + ArrayList partitionList = new ArrayList(); + PartitionSpecProxy.PartitionIterator iterator = partitionSpec.getPartitionIterator(); + + while (iterator.hasNext()) { + Partition partition = iterator.next(); + partitionList.add(getPartitionKeyValues(table, partition)); + } + + return partitionList; + } + + //This is private in parent class + private long now() { + return System.currentTimeMillis() / 1000L; + } } http://git-wip-us.apache.org/repos/asf/sentry/blob/a68386e3/sentry-provider/sentry-provider-db/pom.xml ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/pom.xml b/sentry-provider/sentry-provider-db/pom.xml index 7b13cea..6b7d3c0 100644 --- a/sentry-provider/sentry-provider-db/pom.xml +++ b/sentry-provider/sentry-provider-db/pom.xml @@ -113,12 +113,7 @@ limitations under the License. <dependency> <groupId>org.apache.sentry</groupId> <artifactId>sentry-binding-hive-conf</artifactId> - <version>2.0.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.sentry</groupId> - <artifactId>sentry-binding-hive-follower</artifactId> - <version>2.0.0-SNAPSHOT</version> + <version>${project.version}</version> </dependency> <dependency> <groupId>org.apache.sentry</groupId> @@ -325,6 +320,32 @@ limitations under the License. </build> <profiles> <profile> + <id>hive-authz1</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.apache.sentry</groupId> + <artifactId>sentry-binding-hive-follower</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </profile> + <profile> + <id>hive-authz2</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.apache.sentry</groupId> + <artifactId>sentry-binding-hive-follower-v2</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + </profile> + <profile> <id>datanucleus3</id> <activation> <activeByDefault>true</activeByDefault>