Repository: sentry Updated Branches: refs/heads/sentry-ha-redesign 4cfc08be4 -> 5d17ebb17
SENTRY-1602: Code cleanup for Sentry JSON message factory for hive notifications (Nachiket Vaidya, Reviewed by: Alexander Kolbasov, Hao Hao and Vamsee Yarlagadda) Change-Id: I6c8c50e5a9e2b1f8d38cab57720fb0665dda14b0 Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/5d17ebb1 Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/5d17ebb1 Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/5d17ebb1 Branch: refs/heads/sentry-ha-redesign Commit: 5d17ebb17d8069a7c9c90d8b9bd470005c3ae9af Parents: 4cfc08b Author: hahao <[email protected]> Authored: Mon Feb 6 15:53:10 2017 -0800 Committer: hahao <[email protected]> Committed: Mon Feb 6 15:53:10 2017 -0800 ---------------------------------------------------------------------- .../json/JSONAlterPartitionMessage.java | 78 ------------------ .../messaging/json/JSONAlterTableMessage.java | 68 --------------- .../json/SentryJSONAddPartitionMessage.java | 2 +- .../json/SentryJSONAlterPartitionMessage.java | 22 +++-- .../json/SentryJSONAlterTableMessage.java | 17 ++-- .../json/SentryJSONCreateDatabaseMessage.java | 2 +- .../json/SentryJSONCreateTableMessage.java | 2 +- .../json/SentryJSONDropDatabaseMessage.java | 2 +- .../json/SentryJSONDropPartitionMessage.java | 14 ++-- .../json/SentryJSONDropTableMessage.java | 2 +- .../json/SentryJSONMessageDeserializer.java | 87 +++++++++++++------- .../json/SentryJSONMessageFactory.java | 67 ++++++--------- .../sentry/service/thrift/HMSFollower.java | 2 +- .../TestSentryListenerSentryDeserializer.java | 12 +-- 14 files changed, 126 insertions(+), 251 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterPartitionMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterPartitionMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterPartitionMessage.java deleted file mode 100644 index 890186b..0000000 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterPartitionMessage.java +++ /dev/null @@ -1,78 +0,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. - */ - -package org.apache.sentry.binding.metastore.messaging.json; - -import org.apache.hive.hcatalog.messaging.AlterPartitionMessage; -import org.codehaus.jackson.annotate.JsonProperty; - -import java.util.List; - -/* -* This is only needed as corresponding class in Hive 1.1.0 does not have a default constructor - */ -public class JSONAlterPartitionMessage extends AlterPartitionMessage { - @JsonProperty - String server; - @JsonProperty - String servicePrincipal; - @JsonProperty - String db; - @JsonProperty - String table; - @JsonProperty - Long timestamp; - @JsonProperty - List<String> values; - - public JSONAlterPartitionMessage() {} - public JSONAlterPartitionMessage(String server, String servicePrincipal, String db, String table, List<String> values, Long timestamp) { - this.server = server; - this.servicePrincipal = servicePrincipal; - this.db = db; - this.table = table; - this.timestamp = timestamp; - this.values = values; - this.checkValid(); - } - - public String getServer() { - return this.server; - } - - public String getServicePrincipal() { - return this.servicePrincipal; - } - - public String getDB() { - return this.db; - } - - public Long getTimestamp() { - return this.timestamp; - } - - public String getTable() { - return this.table; - } - - public List<String> getValues() { - return this.values; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterTableMessage.java ---------------------------------------------------------------------- diff --git a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterTableMessage.java b/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterTableMessage.java deleted file mode 100644 index 76211c3..0000000 --- a/sentry-binding/sentry-binding-hive-follower/src/main/java/org/apache/sentry/binding/metastore/messaging/json/JSONAlterTableMessage.java +++ /dev/null @@ -1,68 +0,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. - */ - -package org.apache.sentry.binding.metastore.messaging.json; - -import org.apache.hive.hcatalog.messaging.AlterTableMessage; -import org.codehaus.jackson.annotate.JsonProperty; - -/** - * This class is required as this class does not have a default contructor in Hive 1.1.0 - */ -public class JSONAlterTableMessage extends AlterTableMessage { - @JsonProperty - String server; - @JsonProperty - String servicePrincipal; - @JsonProperty - String db; - @JsonProperty - String table; - @JsonProperty - Long timestamp; - - public JSONAlterTableMessage() {} - public JSONAlterTableMessage(String server, String servicePrincipal, String db, String table, Long timestamp) { - this.server = server; - this.servicePrincipal = servicePrincipal; - this.db = db; - this.table = table; - this.timestamp = timestamp; - this.checkValid(); - } - - public String getServer() { - return this.server; - } - - public String getServicePrincipal() { - return this.servicePrincipal; - } - - public String getDB() { - return this.db; - } - - public Long getTimestamp() { - return this.timestamp; - } - - public String getTable() { - return this.table; - } -} http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 c0c469c..5c656eb 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 @@ -26,7 +26,7 @@ import java.util.Map; public class SentryJSONAddPartitionMessage extends JSONAddPartitionMessage { @JsonProperty - List<String> locations; + private List<String> locations; public SentryJSONAddPartitionMessage() { } http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 99eb67a..89ee863 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 @@ -18,28 +18,34 @@ 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{ +public class SentryJSONAlterPartitionMessage extends JSONAlterPartitionMessage { @JsonProperty - String location; + private String newLocation; @JsonProperty - String oldLocation; + private String oldLocation; public SentryJSONAlterPartitionMessage() { + super("", "", "", "", ImmutableList.<String>of(), null); } - public SentryJSONAlterPartitionMessage(String server, String servicePrincipal, String db, String table, - List<String> values, Long timestamp, String oldlocation, String newLocation) { + public SentryJSONAlterPartitionMessage(String server, String servicePrincipal, + String db, String table, + List<String> values, + Long timestamp, String oldlocation, + String newLocation) { super(server, servicePrincipal, db, table, values, timestamp); - this.location = newLocation; + this.newLocation = newLocation; this.oldLocation = oldlocation; } - public String getLocation() { - return location; + public String getNewLocation() { + return newLocation; } public String getOldLocation() { http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 6e59e25..b590fe8 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 @@ -18,26 +18,29 @@ 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 - String location; //newLocation + private String newLocation; @JsonProperty - String oldLocation; + private String oldLocation; public SentryJSONAlterTableMessage() { + super("", "", "", "", null); } - public SentryJSONAlterTableMessage(String server, String servicePrincipal, String db, String table, - Long timestamp, String oldLocation, String location) { + public SentryJSONAlterTableMessage(String server, String servicePrincipal, + String db, String table, Long timestamp, + String oldLocation, String newLocation) { super(server, servicePrincipal, db, table, timestamp); - this.location = location; + this.newLocation = newLocation; this.oldLocation = oldLocation; } - public String getLocation() { - return location; + public String getNewLocation() { + return newLocation; } public String getOldLocation() { return oldLocation; http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 ba19cbe..1118cac 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 @@ -23,7 +23,7 @@ import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONCreateDatabaseMessage extends JSONCreateDatabaseMessage { @JsonProperty - String location; + private String location; public SentryJSONCreateDatabaseMessage() { } http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 57d11d2..8716316 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 @@ -23,7 +23,7 @@ import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONCreateTableMessage extends JSONCreateTableMessage { @JsonProperty - String location; + private String location; public SentryJSONCreateTableMessage() { } http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 05f83f7..f38f69b 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 @@ -23,7 +23,7 @@ import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONDropDatabaseMessage extends JSONDropDatabaseMessage{ @JsonProperty - String location; + private String location; public SentryJSONDropDatabaseMessage() { } http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 2ab61f7..e2c1135 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 @@ -26,19 +26,21 @@ import java.util.Map; public class SentryJSONDropPartitionMessage extends JSONDropPartitionMessage { @JsonProperty - String location; + private List<String> locations; public SentryJSONDropPartitionMessage() { } - public SentryJSONDropPartitionMessage(String server, String servicePrincipal, String db, String table, - List<Map<String, String>> partitions, Long timestamp, String location) { + 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.location = location; + this.locations = locations; } - public String getLocation() { - return location; + public List<String> getLocations() { + return locations; } @Override http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 7005776..40bf2b9 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 @@ -24,7 +24,7 @@ import org.codehaus.jackson.annotate.JsonProperty; public class SentryJSONDropTableMessage extends JSONDropTableMessage { @JsonProperty - String location; + private String location; public SentryJSONDropTableMessage() { } http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 b645c45..5f2287e 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 @@ -23,7 +23,11 @@ import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; public class SentryJSONMessageDeserializer extends MessageDeserializer { - static ObjectMapper mapper = new ObjectMapper(); + private static ObjectMapper mapper = new ObjectMapper(); + + static { + mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } public SentryJSONMessageDeserializer() { } @@ -31,74 +35,99 @@ public class SentryJSONMessageDeserializer extends MessageDeserializer { /** * Method to de-serialize CreateDatabaseMessage instance. */ + @Override public SentryJSONCreateDatabaseMessage getCreateDatabaseMessage(String messageBody) { try { - return (SentryJSONCreateDatabaseMessage)mapper.readValue(messageBody, SentryJSONCreateDatabaseMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONCreateDatabaseMessage.", var3); + 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 (SentryJSONDropDatabaseMessage)mapper.readValue(messageBody, SentryJSONDropDatabaseMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONDropDatabaseMessage.", var3); + 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 (SentryJSONCreateTableMessage)mapper.readValue(messageBody, SentryJSONCreateTableMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONCreateTableMessage.", var3); + 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 (SentryJSONAlterTableMessage)mapper.readValue(messageBody, SentryJSONAlterTableMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONAlterTableMessage.", var3); + 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 (SentryJSONDropTableMessage)mapper.readValue(messageBody, SentryJSONDropTableMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONDropTableMessage.", var3); + 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 (SentryJSONAddPartitionMessage)mapper.readValue(messageBody, SentryJSONAddPartitionMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONAddPartitionMessage.", var3); + 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 (SentryJSONAlterPartitionMessage)mapper.readValue(messageBody, SentryJSONAlterPartitionMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONAlterPartitionMessage.", var3); + 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 (SentryJSONDropPartitionMessage)mapper.readValue(messageBody, SentryJSONDropPartitionMessage.class); - } catch (Exception var3) { - throw new IllegalArgumentException("Could not construct SentryJSONDropPartitionMessage.", var3); + return mapper.readValue(messageBody, SentryJSONDropPartitionMessage.class); + } catch (Exception e) { + throw new IllegalArgumentException("Could not construct SentryJSONDropPartitionMessage: ", e); } } - static { - mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); - } - public static String serialize(Object object) { try { return mapper.writeValueAsString(object); http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/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 00e7db8..1fc11f8 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 @@ -17,12 +17,12 @@ */ 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.FieldSchema; 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; @@ -35,8 +35,8 @@ public class SentryJSONMessageFactory extends MessageFactory { private static SentryJSONMessageDeserializer deserializer = new SentryJSONMessageDeserializer(); public SentryJSONMessageFactory() { LOG.info("Using SentryJSONMessageFactory for building Notification log messages "); - } + public MessageDeserializer getDeserializer() { return deserializer; } @@ -51,46 +51,45 @@ public class SentryJSONMessageFactory extends MessageFactory { public SentryJSONCreateDatabaseMessage buildCreateDatabaseMessage(Database db) { return new SentryJSONCreateDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), - Long.valueOf(this.now()), db.getLocationUri()); + now(), db.getLocationUri()); } public SentryJSONDropDatabaseMessage buildDropDatabaseMessage(Database db) { return new SentryJSONDropDatabaseMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, db.getName(), - Long.valueOf(this.now()), db.getLocationUri()); + now(), db.getLocationUri()); } public SentryJSONCreateTableMessage buildCreateTableMessage(Table table) { return new SentryJSONCreateTableMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, table.getDbName(), - table.getTableName(), Long.valueOf(this.now()), table.getSd().getLocation()); + 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(), Long.valueOf(this.now()), before.getSd().getLocation(), after.getSd().getLocation()); + 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(), Long.valueOf(this.now()), table.getSd().getLocation()); + 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), Long.valueOf(this.now()), - getPartitionLocations(partitions)); + table.getTableName(), getPartitionKeyValues(table, partitions), now(), + getPartitionLocations(partitions)); } private List<String> getPartitionLocations(List<Partition> partitions) { - List<String> paths = new ArrayList<String>(); - for(Partition partition:partitions) { + List<String> paths = Lists.newLinkedList(); + for(Partition partition : partitions) { paths.add(partition.getSd().getLocation()); } return paths; } - //TODO: Not sure what is this used for. Need to investigate private List<String> getPartitionLocations(PartitionSpecProxy partitionSpec) { Iterator<Partition> iterator = partitionSpec.getPartitionIterator(); - List<String> locations = new ArrayList<String>(); + List<String> locations = Lists.newLinkedList(); while(iterator.hasNext()) { locations.add(iterator.next().getSd().getLocation()); } @@ -101,56 +100,37 @@ public class SentryJSONMessageFactory extends MessageFactory { @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), Long.valueOf(this.now()), - getPartitionLocations(partitionSpec)); + table.getTableName(), getPartitionKeyValues(table, partitionSpec), now(), + getPartitionLocations(partitionSpec)); } + @Override public SentryJSONAlterPartitionMessage buildAlterPartitionMessage(Partition before, Partition after) { - /* - f (partitionEvent.getOldPartition() != null) { - oldLoc = partitionEvent.getOldPartition().getSd().getLocation(); - } - if (partitionEvent.getNewPartition() != null) { - newLoc = partitionEvent.getNewPartition().getSd().getLocation(); - } - - if ((oldLoc != null) && (newLoc != null) && (!oldLoc.equals(newLoc))) { - String authzObj = - partitionEvent.getOldPartition().getDbName() + "." - + partitionEvent.getOldPartition().getTableName(); - for (SentryMetastoreListenerPlugin plugin : sentryPlugins) { - plugin.renameAuthzObject(authzObj, oldLoc, - authzObj, newLoc); - } - } - * */ return new SentryJSONAlterPartitionMessage(HCAT_SERVER_URL, HCAT_SERVICE_PRINCIPAL, before.getDbName(), - before.getTableName(), before.getValues(), Long.valueOf(this.now()), before.getSd().getLocation(), - after.getSd().getLocation()); + before.getTableName(), before.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)), - Long.valueOf(this.now()), partition.getSd().getLocation()); + 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(((FieldSchema)table.getPartitionKeys().get(i)).getName(), partition.getValues().get(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) { - ArrayList partitionList = new ArrayList(partitions.size()); - Iterator i$ = partitions.iterator(); + List<Map<String, String>> partitionList = Lists.newLinkedList(); - while(i$.hasNext()) { - Partition partition = (Partition)i$.next(); + for (Partition partition : partitions) { partitionList.add(getPartitionKeyValues(table, partition)); } @@ -164,12 +144,13 @@ public class SentryJSONMessageFactory extends MessageFactory { PartitionSpecProxy.PartitionIterator iterator = partitionSpec.getPartitionIterator(); while(iterator.hasNext()) { - Partition partition = (Partition)iterator.next(); + 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/5d17ebb1/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java index 7f7a7d3..783c0fc 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/HMSFollower.java @@ -405,7 +405,7 @@ public class HMSFollower implements Runnable { String newDbName = event.getDbName(); String newTableName = event.getTableName(); oldLocation = alterTableMessage.getOldLocation(); - newLocation = alterTableMessage.getLocation(); + newLocation = alterTableMessage.getNewLocation(); if (oldDbName == null || oldTableName == null || newDbName == null || newTableName == null || oldLocation == null || newLocation == null) { http://git-wip-us.apache.org/repos/asf/sentry/blob/5d17ebb1/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestSentryListenerSentryDeserializer.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestSentryListenerSentryDeserializer.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestSentryListenerSentryDeserializer.java index 86a8964..4d8889a 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestSentryListenerSentryDeserializer.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestSentryListenerSentryDeserializer.java @@ -34,6 +34,7 @@ import org.junit.*; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Random; /** @@ -180,7 +181,7 @@ public class TestSentryListenerSentryDeserializer extends AbstractMetastoreTestW // Create database createMetastoreDB(client, testDB); - // Create table with partition + // Create table without partition // We need: // - dbname // - tablename @@ -262,9 +263,8 @@ public class TestSentryListenerSentryDeserializer extends AbstractMetastoreTestW assertThat(dropPartitionMessage.getDB(), IsEqualIgnoringCase.equalToIgnoringCase(testDB)); //dbName assertThat(dropPartitionMessage.getTable(), IsEqualIgnoringCase.equalToIgnoringCase(testTable)); //tableName if(!useDbNotificationListener) { - Assert.assertEquals(expectedLocation.toLowerCase(), dropPartitionMessage.getLocation()); + Assert.assertEquals(Arrays.asList(expectedLocation.toLowerCase()), dropPartitionMessage.getLocations()); } - } @Test @@ -300,7 +300,7 @@ public class TestSentryListenerSentryDeserializer extends AbstractMetastoreTestW assertThat(alterTableMessage.getTable(), IsEqualIgnoringCase.equalToIgnoringCase(testTable));//tableName if(!useDbNotificationListener) { Assert.assertEquals(oldLocation, alterTableMessage.getOldLocation()); //oldLocation - Assert.assertEquals(tbl1.getSd().getLocation(), alterTableMessage.getLocation()); //newLocation + Assert.assertEquals(tbl1.getSd().getLocation(), alterTableMessage.getNewLocation()); //newLocation } //Alter table rename managed table - location also changes @@ -332,7 +332,7 @@ public class TestSentryListenerSentryDeserializer extends AbstractMetastoreTestW assertThat(response.getEvents().get(0).getTableName(), IsEqualIgnoringCase.equalToIgnoringCase(newTableName));//newTableName if(!useDbNotificationListener) { Assert.assertEquals(oldLocation, alterTableMessage.getOldLocation()); //oldLocation - Assert.assertEquals(tbl1.getSd().getLocation(), alterTableMessage.getLocation()); //newLocation + Assert.assertEquals(tbl1.getSd().getLocation(), alterTableMessage.getNewLocation()); //newLocation } } @@ -369,7 +369,7 @@ public class TestSentryListenerSentryDeserializer extends AbstractMetastoreTestW assertThat(alterPartitionMessage.getTable(), IsEqualIgnoringCase.equalToIgnoringCase(testTable));// tableName if(!useDbNotificationListener) { Assert.assertEquals(oldLocation.toLowerCase(), alterPartitionMessage.getOldLocation()); - Assert.assertEquals(newLocation.toLowerCase(), alterPartitionMessage.getLocation()); + Assert.assertEquals(newLocation.toLowerCase(), alterPartitionMessage.getNewLocation()); } } }
