use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasHbaseResourceMapper 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);
Map<String, RangerPolicyResource> elements = new HashMap<String, RangerPolicyResource>();
if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_NAMESPACE)) {
if (StringUtils.isNotEmpty(resourceStr)) {
String namespaceName = StringUtils.strip(resourceStr);
if (StringUtils.isNotEmpty(namespaceName)) {
elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(namespaceName + RANGER_NAMESPACE_TABLE_DELIMITER + "*"));
}
}
} else if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_TABLE)) {
if (StringUtils.isNotEmpty(resourceStr)) {
elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(resourceStr));
}
} else if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_COLUMN_FAMILY)) {
String[] resources = resourceStr.split(QUALIFIED_NAME_DELIMITER);
String tblName = null;
String familyName = null;
if (resources.length == 2) {
tblName = resources[0];
familyName = resources[1];
} else if (resources.length > 2) {
StringBuilder tblNameBuf = new StringBuilder(resources[0]);
for (int i = 1; i < resources.length - 1; i++) {
tblNameBuf.append(QUALIFIED_NAME_DELIMITER_CHAR).append(resources[i]);
}
tblName = tblNameBuf.toString();
familyName = resources[resources.length - 1];
}
if (StringUtils.isNotEmpty(tblName) && StringUtils.isNotEmpty(familyName)) {
elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(tblName));
elements.put(RANGER_TYPE_HBASE_COLUMN_FAMILY, new RangerPolicyResource(familyName));
}
} else if (StringUtils.equals(entityType, ENTITY_TYPE_HBASE_COLUMN)) {
String[] resources = resourceStr.split(QUALIFIED_NAME_DELIMITER);
String tblName = null;
String familyName = null;
String colName = null;
if (resources.length == 3) {
tblName = resources[0];
familyName = resources[1];
colName = resources[2];
} else if (resources.length > 3) {
StringBuilder tblNameBuf = new StringBuilder(resources[0]);
for (int i = 1; i < resources.length - 2; i++) {
tblNameBuf.append(QUALIFIED_NAME_DELIMITER_CHAR).append(resources[i]);
}
tblName = tblNameBuf.toString();
familyName = resources[resources.length - 2];
colName = resources[resources.length - 1];
}
if (StringUtils.isNotEmpty(tblName) && StringUtils.isNotEmpty(familyName) && StringUtils.isNotEmpty(colName)) {
elements.put(RANGER_TYPE_HBASE_TABLE, new RangerPolicyResource(tblName));
elements.put(RANGER_TYPE_HBASE_COLUMN_FAMILY, new RangerPolicyResource(familyName));
elements.put(RANGER_TYPE_HBASE_COLUMN, new RangerPolicyResource(colName));
}
} else {
throwExceptionWithMessage("unrecognized entity-type: " + entityType);
}
if (elements.isEmpty()) {
throwExceptionWithMessage("invalid qualifiedName for entity-type '" + entityType + "': " + qualifiedName);
}
return new RangerServiceResource(entityGuid, serviceName, elements);
}
use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasNotificationMapper method buildServiceTagsForEntityDeleteNotification.
@SuppressWarnings("unchecked")
private static ServiceTags buildServiceTagsForEntityDeleteNotification(RangerAtlasEntityWithTags entityWithTags) {
final ServiceTags ret;
RangerAtlasEntity entity = entityWithTags.getEntity();
String guid = entity.getGuid();
if (StringUtils.isNotBlank(guid)) {
ret = new ServiceTags();
RangerServiceResource serviceResource = new RangerServiceResource();
serviceResource.setGuid(guid);
ret.getServiceResources().add(serviceResource);
} else {
ret = buildServiceTags(entityWithTags, null);
if (ret != null) {
// tag-definitions should NOT be deleted as part of service-resource delete
ret.setTagDefinitions(MapUtils.EMPTY_MAP);
// Ranger deletes tags associated with deleted service-resource
ret.setTags(MapUtils.EMPTY_MAP);
}
}
if (ret != null) {
ret.setOp(ServiceTags.OP_DELETE);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasResourceMapperUtil method getRangerServiceResource.
public static RangerServiceResource getRangerServiceResource(RangerAtlasEntity atlasEntity) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> getRangerServiceResource(" + atlasEntity.getGuid() + ")");
}
RangerServiceResource resource = null;
AtlasResourceMapper mapper = atlasResourceMappers.get(atlasEntity.getTypeName());
if (mapper != null) {
try {
resource = mapper.buildResource(atlasEntity);
} catch (Exception exception) {
LOG.error("Could not get serviceResource for atlas entity:" + atlasEntity.getGuid() + ": ", exception);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== getRangerServiceResource(" + atlasEntity.getGuid() + "): resource=" + resource);
}
return resource;
}
use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.
the class AtlasStormResourceMapper method buildResource.
@Override
public RangerServiceResource buildResource(final RangerAtlasEntity entity) throws Exception {
String qualifiedName = (String) entity.getAttributes().get(AtlasResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME);
String topology = getResourceNameFromQualifiedName(qualifiedName);
if (StringUtils.isEmpty(topology)) {
throwExceptionWithMessage("topology 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<>();
Boolean isExcludes = Boolean.FALSE;
Boolean isRecursive = Boolean.TRUE;
elements.put(RANGER_TYPE_STORM_TOPOLOGY, new RangerPolicyResource(topology, 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 TestHbaseResourceMapper method testHbaseDottedColumn.
@Test
public void testHbaseDottedColumn() throws Exception {
Map<String, Object> entAttribs = new HashMap<String, Object>();
entAttribs.put(ENTITY_ATTRIBUTE_QUALIFIED_NAME, DOTTED_COLUMN_QUALIFIED_NAME);
RangerAtlasEntity entity = getHbaseColumnEntity(entAttribs);
RangerServiceResource resource = resourceMapper.buildResource(entity);
assertColumnResource(resource, true);
}
Aggregations