Commit 1abd5a24 by Suma Shivaprasad

ATLAS-1087 Provide an option to turn off persisting entity definition in audits…

ATLAS-1087 Provide an option to turn off persisting entity definition in audits (sumasai, shwethags)
parent 91072c10
......@@ -6,6 +6,7 @@ INCOMPATIBLE CHANGES:
ATLAS-1060 Add composite indexes for exact match performance improvements for all attributes (sumasai via shwethags)
ALL CHANGES:
ATLAS-1087 Provide an option to turn off persisting entity definition in audits (sumasai, shwethags)
ATLAS-1097 Fix a potential NPE issue flagged by Coverity scan (mneethiraj via shwethags)
ATLAS-1090 UI: Multi-Select Tagging. (Kalyanikashikar via kevalbhatt)
ATLAS-1092 Add Table.CreateTime to process qualified Name for all hive_process (sumasai via shwethags)
......
......@@ -74,12 +74,23 @@ public class HBaseBasedAuditRepository implements Service, EntityAuditRepository
private static final String FIELD_SEPARATOR = ":";
public static final String CONFIG_PERSIST_ENTITY_DEFINITION = CONFIG_PREFIX + ".persistEntityDefinition";
public static final byte[] COLUMN_FAMILY = Bytes.toBytes("dt");
public static final byte[] COLUMN_ACTION = Bytes.toBytes("action");
public static final byte[] COLUMN_DETAIL = Bytes.toBytes("detail");
public static final byte[] COLUMN_USER = Bytes.toBytes("user");
public static final byte[] COLUMN_DEFINITION = Bytes.toBytes("def");
private static boolean persistEntityDefinition;
static {
try {
persistEntityDefinition = ApplicationProperties.get().getBoolean(CONFIG_PERSIST_ENTITY_DEFINITION, false);
} catch (AtlasException e) {
throw new RuntimeException(e);
}
}
private TableName tableName;
private Connection connection;
......@@ -111,7 +122,9 @@ public class HBaseBasedAuditRepository implements Service, EntityAuditRepository
addColumn(put, COLUMN_ACTION, event.getAction());
addColumn(put, COLUMN_USER, event.getUser());
addColumn(put, COLUMN_DETAIL, event.getDetails());
if (persistEntityDefinition) {
addColumn(put, COLUMN_DEFINITION, event.getEntityDefinitionString());
}
puts.add(put);
}
table.put(puts);
......@@ -185,7 +198,12 @@ public class HBaseBasedAuditRepository implements Service, EntityAuditRepository
event.setUser(getResultString(result, COLUMN_USER));
event.setAction(EntityAuditEvent.EntityAuditAction.valueOf(getResultString(result, COLUMN_ACTION)));
event.setDetails(getResultString(result, COLUMN_DETAIL));
event.setEntityDefinition(getResultString(result, COLUMN_DEFINITION));
if (persistEntityDefinition) {
String colDef = getResultString(result, COLUMN_DEFINITION);
if (colDef != null) {
event.setEntityDefinition(colDef);
}
}
events.add(event);
}
LOG.info("Got events for entity id {}, starting timestamp {}, #records {}", entityId, startKey, events.size());
......@@ -199,7 +217,11 @@ public class HBaseBasedAuditRepository implements Service, EntityAuditRepository
}
private String getResultString(Result result, byte[] columnName) {
return Bytes.toString(result.getValue(COLUMN_FAMILY, columnName));
byte[] rawValue = result.getValue(COLUMN_FAMILY, columnName);
if ( rawValue != null) {
return Bytes.toString(rawValue);
}
return null;
}
private EntityAuditEvent fromKey(byte[] keyBytes) {
......
......@@ -18,6 +18,7 @@
package org.apache.atlas.repository.audit;
import junit.framework.Assert;
import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.commons.lang.RandomStringUtils;
......@@ -88,7 +89,7 @@ public class AuditRepositoryTestBase {
assertEquals(events.size(), 0);
}
private void assertEventEquals(EntityAuditEvent actual, EntityAuditEvent expected) {
protected void assertEventEquals(EntityAuditEvent actual, EntityAuditEvent expected) {
if (expected != null) {
assertNotNull(actual);
}
......
......@@ -19,6 +19,7 @@
package org.apache.atlas.repository.audit;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.EntityAuditEvent;
import org.apache.commons.configuration.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
......@@ -27,6 +28,7 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
public class HBaseBasedAuditRepositoryTest extends AuditRepositoryTestBase {
......@@ -36,7 +38,7 @@ public class HBaseBasedAuditRepositoryTest extends AuditRepositoryTestBase {
public void setup() throws Exception {
eventRepository = new HBaseBasedAuditRepository();
HBaseTestUtils.startCluster();
((HBaseBasedAuditRepository)eventRepository).start();
((HBaseBasedAuditRepository) eventRepository).start();
Configuration properties = ApplicationProperties.get();
String tableNameStr = properties.getString(HBaseBasedAuditRepository.CONFIG_TABLE_NAME,
......@@ -46,7 +48,7 @@ public class HBaseBasedAuditRepositoryTest extends AuditRepositoryTestBase {
@AfterClass
public void teardown() throws Exception {
((HBaseBasedAuditRepository)eventRepository).stop();
((HBaseBasedAuditRepository) eventRepository).stop();
HBaseTestUtils.stopCluster();
}
......@@ -56,4 +58,10 @@ public class HBaseBasedAuditRepositoryTest extends AuditRepositoryTestBase {
Admin admin = connection.getAdmin();
assertTrue(admin.tableExists(tableName));
}
@Override
protected void assertEventEquals(EntityAuditEvent actual, EntityAuditEvent expected) {
super.assertEventEquals(actual, expected);
assertNull(actual.getEntityDefinition());
}
}
\ No newline at end of file
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