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 { ...@@ -374,7 +374,11 @@ public class HBaseAtlasHook extends AtlasHook {
* @return Unique qualified name to identify the Table instance in Atlas. * @return Unique qualified name to identify the Table instance in Atlas.
*/ */
public static String getColumnFamilyQualifiedName(String clusterName, String nameSpace, String tableName, String columnFamily) { 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 { ...@@ -386,7 +390,11 @@ public class HBaseAtlasHook extends AtlasHook {
* @return Unique qualified name to identify the Table instance in Atlas. * @return Unique qualified name to identify the Table instance in Atlas.
*/ */
public static String getTableQualifiedName(String clusterName, String nameSpace, String tableName) { 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 { ...@@ -397,7 +405,11 @@ public class HBaseAtlasHook extends AtlasHook {
* @return Unique qualified name to identify the HBase NameSpace instance in Atlas. * @return Unique qualified name to identify the HBase NameSpace instance in Atlas.
*/ */
public static String getNameSpaceQualifiedName(String clusterName, String nameSpace) { 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) { private static String stripNameSpace(String tableName) {
...@@ -765,7 +777,7 @@ public class HBaseAtlasHook extends AtlasHook { ...@@ -765,7 +777,7 @@ public class HBaseAtlasHook extends AtlasHook {
UserGroupInformation ugi = getUGI(); UserGroupInformation ugi = getUGI();
User user = getActiveUser(); User user = getActiveUser();
String userName = user.getShortName(); String userName = (user != null) ? user.getShortName() : null;
HBaseOperationContext hbaseOperationContext = new HBaseOperationContext(namespaceDescriptor, nameSpace, operation, ugi, userName, userName); HBaseOperationContext hbaseOperationContext = new HBaseOperationContext(namespaceDescriptor, nameSpace, operation, ugi, userName, userName);
createAtlasInstances(hbaseOperationContext); createAtlasInstances(hbaseOperationContext);
...@@ -784,7 +796,7 @@ public class HBaseAtlasHook extends AtlasHook { ...@@ -784,7 +796,7 @@ public class HBaseAtlasHook extends AtlasHook {
UserGroupInformation ugi = getUGI(); UserGroupInformation ugi = getUGI();
User user = getActiveUser(); User user = getActiveUser();
String userName = user.getShortName(); String userName = (user != null) ? user.getShortName() : null;
Map<String, String> hbaseConf = null; Map<String, String> hbaseConf = null;
String owner = null; String owner = null;
String tableNameSpace = null; String tableNameSpace = null;
...@@ -827,7 +839,7 @@ public class HBaseAtlasHook extends AtlasHook { ...@@ -827,7 +839,7 @@ public class HBaseAtlasHook extends AtlasHook {
UserGroupInformation ugi = getUGI(); UserGroupInformation ugi = getUGI();
User user = getActiveUser(); User user = getActiveUser();
String userName = user.getShortName(); String userName = (user != null) ? user.getShortName() : null;
String owner = userName; String owner = userName;
Map<String, String> hbaseConf = null; Map<String, String> hbaseConf = null;
......
...@@ -90,11 +90,17 @@ public class HBaseAtlasHookIT { ...@@ -90,11 +90,17 @@ public class HBaseAtlasHookIT {
admin.createNamespace(ns); admin.createNamespace(ns);
//assert on qualified name //assert on qualified name
String nameSpace = assertNameSpaceIsRegistered(ns.getName()); String nameSpace = assertNameSpaceIsRegistered(ns.getName());
AtlasEntityWithExtInfo nameSpaceRef = getAtlasClient().getEntityByGuid(nameSpace); AtlasClientV2 atlasClient = getAtlasClient();
String nameSpaceQualifiedName = HBaseAtlasHook.getNameSpaceQualifiedName(CLUSTER_NAME, ns.getName());
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 @Test
...@@ -124,11 +130,17 @@ public class HBaseAtlasHookIT { ...@@ -124,11 +130,17 @@ public class HBaseAtlasHookIT {
} }
//assert on qualified name //assert on qualified name
String table = assertTableIsRegistered(namespace, tablename); String table = assertTableIsRegistered(namespace, tablename);
AtlasEntityWithExtInfo tableRef = getAtlasClient().getEntityByGuid(table); AtlasClientV2 atlasClient = getAtlasClient();
String entityName = HBaseAtlasHook.getTableQualifiedName(CLUSTER_NAME, namespace, tablename);
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 // 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