Commit 92b96657 by rmani Committed by Madhan Neethiraj

ATLAS-2235: code improvements suggested by static code analysis

parent 3fd57d75
......@@ -374,8 +374,12 @@ public class HBaseAtlasHook extends AtlasHook {
* @return Unique qualified name to identify the Table instance in Atlas.
*/
public static String getColumnFamilyQualifiedName(String clusterName, String nameSpace, String tableName, String columnFamily) {
if (clusterName == null || nameSpace == null || tableName == null || columnFamily == null) {
return null;
} else {
return String.format("%s.%s.%s@%s", nameSpace.toLowerCase(), stripNameSpace(tableName.toLowerCase()), columnFamily.toLowerCase(), clusterName);
}
}
/**
* Construct the qualified name used to uniquely identify a Table instance in Atlas.
......@@ -386,8 +390,12 @@ public class HBaseAtlasHook extends AtlasHook {
* @return Unique qualified name to identify the Table instance in Atlas.
*/
public static String getTableQualifiedName(String clusterName, String nameSpace, String tableName) {
if (clusterName == null || nameSpace == null || tableName == null) {
return null;
} else {
return String.format("%s.%s@%s", nameSpace.toLowerCase(), stripNameSpace(tableName.toLowerCase()), clusterName);
}
}
/**
* Construct the qualified name used to uniquely identify a HBase NameSpace instance in Atlas.
......@@ -397,8 +405,12 @@ public class HBaseAtlasHook extends AtlasHook {
* @return Unique qualified name to identify the HBase NameSpace instance in Atlas.
*/
public static String getNameSpaceQualifiedName(String clusterName, String nameSpace) {
if (clusterName == null || nameSpace == null) {
return null;
} else {
return String.format("%s@%s", nameSpace.toLowerCase(), clusterName);
}
}
private static String stripNameSpace(String tableName) {
return tableName.substring(tableName.indexOf(":") + 1);
......@@ -765,7 +777,7 @@ public class HBaseAtlasHook extends AtlasHook {
UserGroupInformation ugi = getUGI();
User user = getActiveUser();
String userName = user.getShortName();
String userName = (user != null) ? user.getShortName() : null;
HBaseOperationContext hbaseOperationContext = new HBaseOperationContext(namespaceDescriptor, nameSpace, operation, ugi, userName, userName);
createAtlasInstances(hbaseOperationContext);
......@@ -784,7 +796,7 @@ public class HBaseAtlasHook extends AtlasHook {
UserGroupInformation ugi = getUGI();
User user = getActiveUser();
String userName = user.getShortName();
String userName = (user != null) ? user.getShortName() : null;
Map<String, String> hbaseConf = null;
String owner = null;
String tableNameSpace = null;
......@@ -827,7 +839,7 @@ public class HBaseAtlasHook extends AtlasHook {
UserGroupInformation ugi = getUGI();
User user = getActiveUser();
String userName = user.getShortName();
String userName = (user != null) ? user.getShortName() : null;
String owner = userName;
Map<String, String> hbaseConf = null;
......
......@@ -91,10 +91,16 @@ public class HBaseAtlasHookIT {
//assert on qualified name
String nameSpace = assertNameSpaceIsRegistered(ns.getName());
AtlasEntityWithExtInfo nameSpaceRef = getAtlasClient().getEntityByGuid(nameSpace);
AtlasClientV2 atlasClient = getAtlasClient();
if (atlasClient != null) {
AtlasEntityWithExtInfo nameSpaceRef = atlasClient.getEntityByGuid(nameSpace);
String nameSpaceQualifiedName = HBaseAtlasHook.getNameSpaceQualifiedName(CLUSTER_NAME, ns.getName());
Assert.assertEquals(nameSpaceRef.getEntity().getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), nameSpaceQualifiedName);
} else {
Assert.fail("Unable to create AtlasClient for Testing");
}
}
@Test
......@@ -125,10 +131,16 @@ public class HBaseAtlasHookIT {
//assert on qualified name
String table = assertTableIsRegistered(namespace, tablename);
AtlasEntityWithExtInfo tableRef = getAtlasClient().getEntityByGuid(table);
AtlasClientV2 atlasClient = getAtlasClient();
if (atlasClient != null) {
AtlasEntityWithExtInfo tableRef = atlasClient.getEntityByGuid(table);
String entityName = HBaseAtlasHook.getTableQualifiedName(CLUSTER_NAME, namespace, tablename);
Assert.assertEquals(tableRef.getEntity().getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), entityName);
} else {
Assert.fail("Unable to create AtlasClient for Testing");
}
}
// Methods for creating HBase
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment