Commit 92b96657 by rmani Committed by Madhan Neethiraj

ATLAS-2235: code improvements suggested by static code analysis

parent 3fd57d75
......@@ -374,7 +374,11 @@ 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) {
return String.format("%s.%s.%s@%s", nameSpace.toLowerCase(), stripNameSpace(tableName.toLowerCase()), columnFamily.toLowerCase(), clusterName);
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);
}
}
/**
......@@ -386,7 +390,11 @@ 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) {
return String.format("%s.%s@%s", nameSpace.toLowerCase(), stripNameSpace(tableName.toLowerCase()), clusterName);
if (clusterName == null || nameSpace == null || tableName == null) {
return null;
} else {
return String.format("%s.%s@%s", nameSpace.toLowerCase(), stripNameSpace(tableName.toLowerCase()), clusterName);
}
}
/**
......@@ -397,7 +405,11 @@ 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) {
return String.format("%s@%s", nameSpace.toLowerCase(), clusterName);
if (clusterName == null || nameSpace == null) {
return null;
} else {
return String.format("%s@%s", nameSpace.toLowerCase(), clusterName);
}
}
private static String stripNameSpace(String tableName) {
......@@ -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;
......
......@@ -90,11 +90,17 @@ public class HBaseAtlasHookIT {
admin.createNamespace(ns);
//assert on qualified name
String nameSpace = assertNameSpaceIsRegistered(ns.getName());
AtlasEntityWithExtInfo nameSpaceRef = getAtlasClient().getEntityByGuid(nameSpace);
String nameSpaceQualifiedName = HBaseAtlasHook.getNameSpaceQualifiedName(CLUSTER_NAME, ns.getName());
String nameSpace = assertNameSpaceIsRegistered(ns.getName());
AtlasClientV2 atlasClient = getAtlasClient();
Assert.assertEquals(nameSpaceRef.getEntity().getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), nameSpaceQualifiedName);
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
......@@ -124,11 +130,17 @@ public class HBaseAtlasHookIT {
}
//assert on qualified name
String table = assertTableIsRegistered(namespace, tablename);
AtlasEntityWithExtInfo tableRef = getAtlasClient().getEntityByGuid(table);
String entityName = HBaseAtlasHook.getTableQualifiedName(CLUSTER_NAME, namespace, tablename);
String table = assertTableIsRegistered(namespace, tablename);
AtlasClientV2 atlasClient = getAtlasClient();
Assert.assertEquals(tableRef.getEntity().getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), entityName);
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