kumaab commented on code in PR #895: URL: https://github.com/apache/ranger/pull/895#discussion_r3003627980
########## tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasTrinoResourceMapper.java: ########## @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ranger.tagsync.source.atlas; + +import org.apache.commons.lang3.StringUtils; +import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource; +import org.apache.ranger.plugin.model.RangerServiceResource; +import org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity; + +import java.util.HashMap; +import java.util.Map; + +public class AtlasTrinoResourceMapper extends AtlasResourceMapper { + public static final String ENTITY_TYPE_TRINO_INSTANCE = "trino_instance"; + public static final String ENTITY_TYPE_TRINO_CATALOG = "trino_catalog"; + public static final String ENTITY_TYPE_TRINO_SCHEMA = "trino_schema"; + public static final String ENTITY_TYPE_TRINO_TABLE = "trino_table"; + public static final String ENTITY_TYPE_TRINO_COLUMN = "trino_column"; + public static final String RANGER_TYPE_TRINO_CATALOG = "catalog"; + public static final String RANGER_TYPE_TRINO_SCHEMA = "schema"; + public static final String RANGER_TYPE_TRINO_TABLE = "table"; + public static final String RANGER_TYPE_TRINO_COLUMN = "column"; + + public static final String[] SUPPORTED_ENTITY_TYPES = { + ENTITY_TYPE_TRINO_INSTANCE, + ENTITY_TYPE_TRINO_CATALOG, + ENTITY_TYPE_TRINO_SCHEMA, + ENTITY_TYPE_TRINO_TABLE, + ENTITY_TYPE_TRINO_COLUMN + }; + + public AtlasTrinoResourceMapper() { + super("trino", SUPPORTED_ENTITY_TYPES); + } + + /* + * qualifiedName can be of format, depending upon the entity-type: + * trino_instance: <instanceName> + * trino_catalog: <catalog>@<instanceName> + * trino_schema: <catalog>.<schema>@<instanceName> + * trino_table: <catalog>.<schema>.<table>@<instanceName> + * trino_column: <catalog>.<schema>.<table>.<column>@<instanceName> + */ + @Override + public RangerServiceResource buildResource(RangerAtlasEntity entity) throws Exception { + String qualifiedName = (String) entity.getAttributes().get(AtlasResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME); + + if (StringUtils.isEmpty(qualifiedName)) { + throw new Exception("attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "' not found in entity"); + } + + String entityType = entity.getTypeName(); + String entityGuid = entity.getGuid(); + String resourceStr = getResourceNameFromQualifiedName(qualifiedName); + + if (StringUtils.isEmpty(resourceStr)) { + throwExceptionWithMessage("resource not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); + } + + String trinoInstance = getClusterNameFromQualifiedName(qualifiedName); + if (StringUtils.equals(resourceStr, qualifiedName)){ + trinoInstance = resourceStr; + } + + if (StringUtils.isEmpty(trinoInstance)) { + throwExceptionWithMessage("trino-instance not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); + } + String serviceName = getRangerServiceName(trinoInstance); + + String[] parts = resourceStr.split(QUALIFIED_NAME_DELIMITER); + if (parts.length < 1 || parts.length > 4) { + throwExceptionWithMessage("invalid resource format in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); + } + + Map<String, RangerPolicyResource> elements = new HashMap<>(); + if (StringUtils.equals(entityType, ENTITY_TYPE_TRINO_INSTANCE) && StringUtils.equals(resourceStr, qualifiedName)) { + elements.put(ENTITY_TYPE_TRINO_INSTANCE, new RangerPolicyResource(resourceStr)); // there is no mapping for trino_instance in Ranger Review Comment: Verified by sending a message for `trino_instance` with latest PR changes: ``` 27 Mar 2026 23:12:11 DEBUG o.a.r.t.s.a.AtlasResourceMapperUtil [Thread-7] - 43 ==> isEntityTypeHandled(entityTypeName=trino_instance) 27 Mar 2026 23:12:11 DEBUG o.a.r.t.s.a.AtlasResourceMapperUtil [Thread-7] - 49 <== isEntityTypeHandled(entityTypeName=trino_instance) : false 27 Mar 2026 23:12:11 DEBUG o.a.r.t.s.a.AtlasTagSource [Thread-7] - 194 Message-offset=4, Notification={ Notification-Type: CLASSIFICATION_ADD, {entity={typeName=trino_instance, guid=11111111-1111-1111-1111-111111111111, attributes={ name=qualifiedName, value=dev}, , classifications={classificationName=SENSITIVE, attributes={{attributeName=kind,attributeValue=instance}}, validityPeriods={}}}} 27 Mar 2026 23:12:11 DEBUG o.a.r.t.s.a.AtlasNotificationMapper [Thread-7] - 128 Notification : [org.apache.ranger.tagsync.source.atlas.EntityNotificationWrapper@76f95b38] will NOT be processed. 27 Mar 2026 23:12:11 WARN o.a.r.t.s.a.AtlasNotificationMapper [Thread-7] - 72 Tag-sync is not enabled to handle notifications for Entity-type:[trino_instance] 27 Mar 2026 23:12:11 DEBUG o.a.r.t.s.a.AtlasNotificationMapper [Thread-7] - 75 Dropped process entity notification for Atlas-Entity [{typeName=trino_instance, guid=11111111-1111-1111-1111-111111111111, attributes={ name=qualifiedName, value=dev}] ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
