use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasHdfsResourceMapper method buildResource.
@Override
public RangerServiceResource buildResource(final RangerAtlasEntity entity) throws Exception {
String path = (String) entity.getAttributes().get(ENTITY_ATTRIBUTE_PATH);
String clusterName = (String) entity.getAttributes().get(ENTITY_ATTRIBUTE_CLUSTER_NAME);
String qualifiedName = (String) entity.getAttributes().get(AtlasResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME);
String nameServiceId = (String) entity.getAttributes().get(ENTITY_ATTRIBUTE_NAME_SERVICE_ID);
if (StringUtils.isEmpty(path)) {
path = getResourceNameFromQualifiedName(qualifiedName);
if (StringUtils.isEmpty(path)) {
throwExceptionWithMessage("path not found in attribute '" + ENTITY_ATTRIBUTE_PATH + "' or '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "'");
}
}
if (StringUtils.isEmpty(clusterName)) {
clusterName = getClusterNameFromQualifiedName(qualifiedName);
if (StringUtils.isEmpty(clusterName)) {
clusterName = defaultClusterName;
}
if (StringUtils.isEmpty(clusterName)) {
throwExceptionWithMessage("attributes " + ENTITY_ATTRIBUTE_CLUSTER_NAME + ", " + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "' not found in entity");
}
}
String entityGuid = entity.getGuid();
String serviceName = StringUtils.isNotBlank(nameServiceId) ? getCustomRangerServiceNameForClusterAndNameService(clusterName, nameServiceId) : getRangerServiceName(clusterName);
Boolean isExcludes = Boolean.FALSE;
Boolean isRecursive = Boolean.TRUE;
Path pathObj = new Path(path);
Map<String, RangerPolicyResource> elements = new HashMap<String, RangerPolicy.RangerPolicyResource>();
elements.put(RANGER_TYPE_HDFS_PATH, new RangerPolicyResource(pathObj.toUri().getPath(), isExcludes, isRecursive));
RangerServiceResource ret = new RangerServiceResource(entityGuid, serviceName, elements);
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasHiveResourceMapper method buildResource.
@Override
public RangerServiceResource buildResource(final 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 resourceStr = getResourceNameFromQualifiedName(qualifiedName);
if (StringUtils.isEmpty(resourceStr)) {
throwExceptionWithMessage("resource not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName);
}
String clusterName = getClusterNameFromQualifiedName(qualifiedName);
if (StringUtils.isEmpty(clusterName)) {
throwExceptionWithMessage("cluster-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName);
}
String entityType = entity.getTypeName();
String entityGuid = entity.getGuid();
String serviceName = getRangerServiceName(clusterName);
String[] resources = resourceStr.split(QUALIFIED_NAME_DELIMITER);
String dbName = resources.length > 0 ? resources[0] : null;
String tblName = resources.length > 1 ? resources[1] : null;
String colName = resources.length > 2 ? resources[2] : null;
Map<String, RangerPolicyResource> elements = new HashMap<String, RangerPolicyResource>();
if (StringUtils.equals(entityType, ENTITY_TYPE_HIVE_DB)) {
if (StringUtils.isNotEmpty(dbName)) {
elements.put(RANGER_TYPE_HIVE_DB, new RangerPolicyResource(dbName));
}
} else if (StringUtils.equals(entityType, ENTITY_TYPE_HIVE_TABLE)) {
if (StringUtils.isNotEmpty(dbName) && StringUtils.isNotEmpty(tblName)) {
elements.put(RANGER_TYPE_HIVE_DB, new RangerPolicyResource(dbName));
elements.put(RANGER_TYPE_HIVE_TABLE, new RangerPolicyResource(tblName));
}
} else if (StringUtils.equals(entityType, ENTITY_TYPE_HIVE_COLUMN)) {
if (StringUtils.isNotEmpty(dbName) && StringUtils.isNotEmpty(tblName) && StringUtils.isNotEmpty(colName)) {
elements.put(RANGER_TYPE_HIVE_DB, new RangerPolicyResource(dbName));
elements.put(RANGER_TYPE_HIVE_TABLE, new RangerPolicyResource(tblName));
elements.put(RANGER_TYPE_HIVE_COLUMN, new RangerPolicyResource(colName));
}
} else {
throwExceptionWithMessage("unrecognized entity-type: " + entityType);
}
if (elements.isEmpty()) {
throwExceptionWithMessage("invalid qualifiedName for entity-type '" + entityType + "': " + qualifiedName);
}
RangerServiceResource ret = new RangerServiceResource(entityGuid, serviceName, elements);
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasKafkaResourceMapper method buildResource.
@Override
public RangerServiceResource buildResource(final RangerAtlasEntity entity) throws Exception {
String qualifiedName = (String) entity.getAttributes().get(AtlasResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME);
String topic = getResourceNameFromQualifiedName(qualifiedName);
if (StringUtils.isEmpty(topic)) {
throwExceptionWithMessage("topic not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "'");
}
String clusterName = getClusterNameFromQualifiedName(qualifiedName);
if (StringUtils.isEmpty(clusterName)) {
clusterName = defaultClusterName;
}
if (StringUtils.isEmpty(clusterName)) {
throwExceptionWithMessage("attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "' not found in entity");
}
Map<String, RangerPolicyResource> elements = new HashMap<String, RangerPolicy.RangerPolicyResource>();
Boolean isExcludes = Boolean.FALSE;
Boolean isRecursive = Boolean.TRUE;
elements.put(RANGER_TYPE_KAFKA_TOPIC, new RangerPolicyResource(topic, isExcludes, isRecursive));
String entityGuid = entity.getGuid();
String serviceName = getRangerServiceName(clusterName);
return new RangerServiceResource(entityGuid, serviceName, elements);
}
use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasNotificationMapper method buildServiceTags.
private static ServiceTags buildServiceTags(RangerAtlasEntityWithTags entityWithTags, Map<String, ServiceTags> serviceTagsMap) {
ServiceTags ret = null;
RangerAtlasEntity entity = entityWithTags.getEntity();
RangerServiceResource serviceResource = AtlasResourceMapperUtil.getRangerServiceResource(entity);
if (serviceResource != null) {
List<RangerTag> tags = getTags(entityWithTags);
List<RangerTagDef> tagDefs = getTagDefs(entityWithTags);
String serviceName = serviceResource.getServiceName();
ret = createOrGetServiceTags(serviceTagsMap, serviceName);
if (serviceTagsMap == null || CollectionUtils.isNotEmpty(tags)) {
serviceResource.setId((long) ret.getServiceResources().size());
ret.getServiceResources().add(serviceResource);
List<Long> tagIds = new ArrayList<>();
if (CollectionUtils.isNotEmpty(tags)) {
for (RangerTag tag : tags) {
tag.setId((long) ret.getTags().size());
ret.getTags().put(tag.getId(), tag);
tagIds.add(tag.getId());
}
}
ret.getResourceToTagIds().put(serviceResource.getId(), tagIds);
if (CollectionUtils.isNotEmpty(tagDefs)) {
for (RangerTagDef tagDef : tagDefs) {
tagDef.setId((long) ret.getTagDefinitions().size());
ret.getTagDefinitions().put(tagDef.getId(), tagDef);
}
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Entity " + entityWithTags + " does not have any tags associated with it when full-sync is being done.");
LOG.debug("Will not add this entity to serviceTags, so that this entity, if exists, will be removed from ranger");
}
}
} else {
LOG.error("Failed to build serviceResource for entity:" + entity.getGuid());
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class TestHbaseResourceMapper method testHbaseColumnFamily.
@Test
public void testHbaseColumnFamily() throws Exception {
Map<String, Object> entAttribs = new HashMap<String, Object>();
entAttribs.put(ENTITY_ATTRIBUTE_QUALIFIED_NAME, COLUMN_FAMILY_QUALIFIED_NAME);
RangerAtlasEntity entity = getHbaseColumnFamilyEntity(entAttribs);
RangerServiceResource resource = resourceMapper.buildResource(entity);
assertColumnFamilyResource(resource, false);
}
Aggregations