You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2016/04/01 20:36:49 UTC
incubator-ranger git commit: RANGER-902: Added owned_by column to
x_tag table, added owner attribute to RangerTag
Repository: incubator-ranger
Updated Branches:
refs/heads/master 164d46fd1 -> d878f4e7e
RANGER-902: Added owned_by column to x_tag table, added owner attribute to RangerTag
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/d878f4e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/d878f4e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/d878f4e7
Branch: refs/heads/master
Commit: d878f4e7eed13a85c0805bacf2a239968f439d56
Parents: 164d46f
Author: Abhay Kulkarni <ak...@hortonworks.com>
Authored: Wed Mar 30 15:04:50 2016 -0700
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Fri Apr 1 11:35:45 2016 -0700
----------------------------------------------------------------------
.../apache/ranger/plugin/model/RangerTag.java | 20 ++++++++++--
.../mysql/patches/021-update-tag-for-owner.sql | 32 ++++++++++++++++++++
.../oracle/patches/021-update-tag-for-owner.sql | 28 +++++++++++++++++
.../patches/021-update-tag-for-owner.sql | 32 ++++++++++++++++++++
.../patches/021-update-tag-for-owner.sql | 22 ++++++++++++++
.../patches/021-update-tag-for-owner.sql | 22 ++++++++++++++
.../java/org/apache/ranger/entity/XXTag.java | 13 ++++++++
.../ranger/service/RangerTagServiceBase.java | 2 ++
8 files changed, 168 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerTag.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerTag.java b/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerTag.java
index 2083362..78040ba 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerTag.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/model/RangerTag.java
@@ -37,23 +37,28 @@ import java.util.Map;
public class RangerTag extends RangerBaseModelObject {
private static final long serialVersionUID = 1L;
+ public static final short OWNER_SERVICERESOURCE = 0;
+ public static final short OWNER_GLOBAL = 1;
+
private String type;
+ private Short owner = OWNER_SERVICERESOURCE;
private Map<String, String> attributes;
- public RangerTag(String guid, String type, Map<String, String> attributes) {
+ public RangerTag(String guid, String type, Short owner, Map<String, String> attributes) {
super();
setGuid(guid);
setType(type);
+ setOwner(owner);
setAttributes(attributes);
}
public RangerTag(String type, Map<String, String> attributes) {
- this(null, type, attributes);
+ this(null, type, OWNER_SERVICERESOURCE, attributes);
}
public RangerTag() {
- this(null, null, null);
+ this(null, null, OWNER_SERVICERESOURCE, null);
}
public String getType() {
@@ -72,6 +77,14 @@ public class RangerTag extends RangerBaseModelObject {
this.attributes = attributes == null ? new HashMap<String, String>() : attributes;
}
+ public Short getOwner() {
+ return this.owner;
+ }
+
+ public void setOwner(Short owner) {
+ this.owner = owner;
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -87,6 +100,7 @@ public class RangerTag extends RangerBaseModelObject {
super.toString(sb);
sb.append("type={").append(type).append("} ");
+ sb.append("owner={").append(owner).append("} ");
sb.append("attributes={");
if (attributes != null) {
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/security-admin/db/mysql/patches/021-update-tag-for-owner.sql
----------------------------------------------------------------------
diff --git a/security-admin/db/mysql/patches/021-update-tag-for-owner.sql b/security-admin/db/mysql/patches/021-update-tag-for-owner.sql
new file mode 100644
index 0000000..36c3b55
--- /dev/null
+++ b/security-admin/db/mysql/patches/021-update-tag-for-owner.sql
@@ -0,0 +1,32 @@
+-- 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.
+
+-- ---------------------------------------
+-- add column in x_tag.owned_by
+-- ---------------------------------------
+DROP PROCEDURE IF EXISTS add_columns_x_tag;
+
+DELIMITER ;;
+CREATE PROCEDURE add_columns_x_tag() BEGIN
+ IF EXISTS (SELECT * FROM information_schema.tables WHERE table_schema=database() AND table_name = 'x_tag') THEN
+ IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema=database() AND table_name = 'x_tag' AND column_name = 'owned_by') THEN
+ ALTER TABLE `x_tag` ADD COLUMN `owned_by` SMALLINT DEFAULT 0 NOT NULL;
+ END IF;
+ END IF;
+END;;
+
+DELIMITER ;
+CALL add_columns_x_tag();
+DROP PROCEDURE IF EXISTS add_columns_x_tag;
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/security-admin/db/oracle/patches/021-update-tag-for-owner.sql
----------------------------------------------------------------------
diff --git a/security-admin/db/oracle/patches/021-update-tag-for-owner.sql b/security-admin/db/oracle/patches/021-update-tag-for-owner.sql
new file mode 100644
index 0000000..2d0b4ee
--- /dev/null
+++ b/security-admin/db/oracle/patches/021-update-tag-for-owner.sql
@@ -0,0 +1,28 @@
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+DECLARE
+ v_column_exists number := 0;
+BEGIN
+ Select count(*) into v_column_exists
+ from user_tab_cols
+ where column_name = upper('owned_by')
+ and table_name = upper('x_tag');
+
+ if (v_column_exists = 0) then
+ execute immediate 'ALTER TABLE x_tag ADD owned_by NUMBER(6) DEFAULT 0 NOT NULL';
+ commit;
+ end if;
+end;/
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/security-admin/db/postgres/patches/021-update-tag-for-owner.sql
----------------------------------------------------------------------
diff --git a/security-admin/db/postgres/patches/021-update-tag-for-owner.sql b/security-admin/db/postgres/patches/021-update-tag-for-owner.sql
new file mode 100644
index 0000000..311fc49
--- /dev/null
+++ b/security-admin/db/postgres/patches/021-update-tag-for-owner.sql
@@ -0,0 +1,32 @@
+-- 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.
+
+-- function add_column_x_service_def_options
+select 'delimiter start';
+CREATE OR REPLACE FUNCTION add_column_x_tag_owned_by()
+RETURNS void AS $$
+DECLARE
+ v_column_exists integer := 0;
+BEGIN
+ select count(*) into v_column_exists from pg_attribute where attrelid in(select oid from pg_class where relname='x_tag') and attname='owned_by';
+ IF v_column_exists = 0 THEN
+ ALTER TABLE x_tag ADD COLUMN owned_by SMALLINT DEFAULT 0 NOT NULL;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+select 'delimiter end';
+
+select add_column_x_tag_owned_by();
+select 'delimiter end';
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/security-admin/db/sqlanywhere/patches/021-update-tag-for-owner.sql
----------------------------------------------------------------------
diff --git a/security-admin/db/sqlanywhere/patches/021-update-tag-for-owner.sql b/security-admin/db/sqlanywhere/patches/021-update-tag-for-owner.sql
new file mode 100644
index 0000000..56bd3c6
--- /dev/null
+++ b/security-admin/db/sqlanywhere/patches/021-update-tag-for-owner.sql
@@ -0,0 +1,22 @@
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+IF NOT EXISTS(select * from SYS.SYSCOLUMNS where tname = 'x_tag' and cname = 'owned_by') THEN
+ ALTER TABLE dbo.x_tag ADD owned_by smallint DEFAULT 0 NOT NULL;
+END IF;
+GO
+
+exit
+
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/security-admin/db/sqlserver/patches/021-update-tag-for-owner.sql
----------------------------------------------------------------------
diff --git a/security-admin/db/sqlserver/patches/021-update-tag-for-owner.sql b/security-admin/db/sqlserver/patches/021-update-tag-for-owner.sql
new file mode 100644
index 0000000..dabe841
--- /dev/null
+++ b/security-admin/db/sqlserver/patches/021-update-tag-for-owner.sql
@@ -0,0 +1,22 @@
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements. See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+GO
+IF NOT EXISTS(select * from INFORMATION_SCHEMA.columns where table_name = 'x_tag' and column_name = 'owned_by')
+BEGIN
+ ALTER TABLE [dbo].[x_tag] ADD [owned_by] [smallint] DEFAULT 0 NOT NULL;
+END
+GO
+exit
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/security-admin/src/main/java/org/apache/ranger/entity/XXTag.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/entity/XXTag.java b/security-admin/src/main/java/org/apache/ranger/entity/XXTag.java
index 4e764d3..526557e 100644
--- a/security-admin/src/main/java/org/apache/ranger/entity/XXTag.java
+++ b/security-admin/src/main/java/org/apache/ranger/entity/XXTag.java
@@ -57,6 +57,9 @@ public class XXTag extends XXDBBase implements Serializable {
@Column(name = "type")
protected Long type;
+ @Column(name = "owned_by")
+ protected Short owner;
+
@Override
public void setId(Long id) {
this.id = id;
@@ -112,6 +115,9 @@ public class XXTag extends XXDBBase implements Serializable {
this.type = type;
}
+ public Short getOwner() { return owner; }
+ public void setOwner(Short owner) { this.owner = owner; }
+
@Override
public int getMyClassType() {
return AppConstants.CLASS_TYPE_XA_TAG;
@@ -130,6 +136,7 @@ public class XXTag extends XXDBBase implements Serializable {
result = prime * result + ((guid == null) ? 0 : guid.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
+ result = prime * result + ((owner == null) ? 0 : owner.hashCode());
return result;
}
@@ -167,6 +174,11 @@ public class XXTag extends XXDBBase implements Serializable {
return false;
} else if (!type.equals(other.type))
return false;
+ if (owner == null) {
+ if (other.owner != null)
+ return false;
+ } else if (!owner.equals(other.owner))
+ return false;
return true;
}
@@ -188,6 +200,7 @@ public class XXTag extends XXDBBase implements Serializable {
sb.append("id={").append(id).append("} ");
sb.append("guid={").append(guid).append("} ");
sb.append("type={").append(type).append("} ");
+ sb.append("owner={").append(owner).append("} ");
sb.append(" }");
return sb;
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/d878f4e7/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java b/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
index 25c4853..940df90 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerTagServiceBase.java
@@ -64,6 +64,7 @@ public abstract class RangerTagServiceBase<T extends XXTag, V extends RangerTag>
xObj.setGuid(guid);
xObj.setType(xTagDef.getId());
+ xObj.setOwner(vObj.getOwner());
return xObj;
}
@@ -79,6 +80,7 @@ public abstract class RangerTagServiceBase<T extends XXTag, V extends RangerTag>
vObj.setGuid(xObj.getGuid());
vObj.setType(xTagDef.getName());
+ vObj.setOwner(xObj.getOwner());
Map<String, String> attributes = getAttributesForTag(xObj);
vObj.setAttributes(attributes);