Commit cb554197 by ashutoshm Committed by Madhan Neethiraj

ATLAS-1721: updated action-string in the audit logs generated during import

parent c3813d29
......@@ -20,7 +20,6 @@ package org.apache.atlas;
import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.json.InstanceSerialization;
import org.apache.commons.lang.StringUtils;
import java.util.Objects;
......@@ -29,7 +28,8 @@ import java.util.Objects;
*/
public class EntityAuditEvent {
public enum EntityAuditAction {
ENTITY_CREATE, ENTITY_UPDATE, ENTITY_DELETE, TAG_ADD, TAG_DELETE
ENTITY_CREATE, ENTITY_UPDATE, ENTITY_DELETE, TAG_ADD, TAG_DELETE,
ENTITY_IMPORT_CREATE, ENTITY_IMPORT_UPDATE, ENTITY_IMPORT_DELETE
}
private String entityId;
......
......@@ -26,7 +26,10 @@ define(['require'], function(require) {
ENTITY_UPDATE: "Entity Updated",
ENTITY_DELETE: "Entity Deleted",
TAG_ADD: "Tag Added",
TAG_DELETE: "Tag Deleted"
TAG_DELETE: "Tag Deleted",
ENTITY_IMPORT_CREATE: "Entity Created by import",
ENTITY_IMPORT_UPDATE: "Entity Updated by import",
ENTITY_IMPORT_DELETE: "Entity Deleted by import"
}
Enums.entityStateReadOnly = {
......
......@@ -55,10 +55,10 @@ public class EntityAuditListener implements EntityChangeListener {
}
@Override
public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities) throws AtlasException {
public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
List<EntityAuditEvent> events = new ArrayList<>();
for (ITypedReferenceableInstance entity : entities) {
EntityAuditEvent event = createEvent(entity, EntityAuditAction.ENTITY_CREATE);
EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_CREATE : EntityAuditAction.ENTITY_CREATE);
events.add(event);
}
......@@ -66,10 +66,10 @@ public class EntityAuditListener implements EntityChangeListener {
}
@Override
public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities) throws AtlasException {
public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
List<EntityAuditEvent> events = new ArrayList<>();
for (ITypedReferenceableInstance entity : entities) {
EntityAuditEvent event = createEvent(entity, EntityAuditAction.ENTITY_UPDATE);
EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_UPDATE : EntityAuditAction.ENTITY_UPDATE);
events.add(event);
}
......@@ -100,10 +100,10 @@ public class EntityAuditListener implements EntityChangeListener {
}
@Override
public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities) throws AtlasException {
public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
List<EntityAuditEvent> events = new ArrayList<>();
for (ITypedReferenceableInstance entity : entities) {
EntityAuditEvent event = createEvent(entity, EntityAuditAction.ENTITY_DELETE, "Deleted entity");
EntityAuditEvent event = createEvent(entity, isImport ? EntityAuditAction.ENTITY_IMPORT_DELETE : EntityAuditAction.ENTITY_DELETE, "Deleted entity");
events.add(event);
}
......@@ -279,6 +279,15 @@ public class EntityAuditListener implements EntityChangeListener {
case TAG_DELETE:
ret = "Deleted trait: ";
break;
case ENTITY_IMPORT_CREATE:
ret = "Created by import: ";
break;
case ENTITY_IMPORT_UPDATE:
ret = "Updated by import: ";
break;
case ENTITY_IMPORT_DELETE:
ret = "Deleted by import: ";
break;
default:
ret = "Unknown: ";
}
......
......@@ -63,7 +63,7 @@ public class AtlasEntityChangeNotifier {
this.instanceConverter = instanceConverter;
}
public void onEntitiesMutated(EntityMutationResponse entityMutationResponse) throws AtlasBaseException {
public void onEntitiesMutated(EntityMutationResponse entityMutationResponse, boolean isImport) throws AtlasBaseException {
if (CollectionUtils.isEmpty(entityChangeListeners) || instanceConverter == null) {
return;
}
......@@ -79,10 +79,10 @@ public class AtlasEntityChangeNotifier {
doFullTextMapping(updatedEntities);
doFullTextMapping(partiallyUpdatedEntities);
notifyListeners(createdEntities, EntityOperation.CREATE);
notifyListeners(updatedEntities, EntityOperation.UPDATE);
notifyListeners(partiallyUpdatedEntities, EntityOperation.PARTIAL_UPDATE);
notifyListeners(deletedEntities, EntityOperation.DELETE);
notifyListeners(createdEntities, EntityOperation.CREATE, isImport);
notifyListeners(updatedEntities, EntityOperation.UPDATE, isImport);
notifyListeners(partiallyUpdatedEntities, EntityOperation.PARTIAL_UPDATE, isImport);
notifyListeners(deletedEntities, EntityOperation.DELETE, isImport);
}
public void onClassificationAddedToEntity(String entityId, List<AtlasClassification> classifications) throws AtlasBaseException {
......@@ -125,7 +125,7 @@ public class AtlasEntityChangeNotifier {
}
}
private void notifyListeners(List<AtlasEntityHeader> entityHeaders, EntityOperation operation) throws AtlasBaseException {
private void notifyListeners(List<AtlasEntityHeader> entityHeaders, EntityOperation operation, boolean isImport) throws AtlasBaseException {
if (CollectionUtils.isEmpty(entityHeaders)) {
return;
}
......@@ -136,14 +136,14 @@ public class AtlasEntityChangeNotifier {
try {
switch (operation) {
case CREATE:
listener.onEntitiesAdded(typedRefInsts);
listener.onEntitiesAdded(typedRefInsts, isImport);
break;
case UPDATE:
case PARTIAL_UPDATE:
listener.onEntitiesUpdated(typedRefInsts);
listener.onEntitiesUpdated(typedRefInsts, isImport);
break;
case DELETE:
listener.onEntitiesDeleted(typedRefInsts);
listener.onEntitiesDeleted(typedRefInsts, isImport);
break;
}
} catch (AtlasException e) {
......
......@@ -232,7 +232,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
}
// Notify the change listeners
entityChangeNotifier.onEntitiesMutated(ret);
entityChangeNotifier.onEntitiesMutated(ret, entityStream instanceof EntityImportStream);
return ret;
}
......@@ -340,7 +340,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
EntityMutationResponse ret = deleteVertices(deletionCandidates);
// Notify the change listeners
entityChangeNotifier.onEntitiesMutated(ret);
entityChangeNotifier.onEntitiesMutated(ret, false);
return ret;
}
......@@ -376,7 +376,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
EntityMutationResponse ret = deleteVertices(deletionCandidates);
// Notify the change listeners
entityChangeNotifier.onEntitiesMutated(ret);
entityChangeNotifier.onEntitiesMutated(ret, false);
return ret;
}
......@@ -406,7 +406,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
EntityMutationResponse ret = deleteVertices(deletionCandidates);
// Notify the change listeners
entityChangeNotifier.onEntitiesMutated(ret);
entityChangeNotifier.onEntitiesMutated(ret, false);
return ret;
}
......
......@@ -21,7 +21,6 @@ package org.apache.atlas.services;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.inject.Provider;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
......@@ -73,10 +72,14 @@ import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
......@@ -701,7 +704,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
private void onEntitiesAdded(List<String> guids) throws AtlasException {
List<ITypedReferenceableInstance> entities = loadEntities(guids);
for (EntityChangeListener listener : entityChangeListeners) {
listener.onEntitiesAdded(entities);
listener.onEntitiesAdded(entities, false);
}
}
......@@ -718,7 +721,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
private void onEntitiesUpdated(List<String> guids) throws AtlasException {
List<ITypedReferenceableInstance> entities = loadEntities(guids);
for (EntityChangeListener listener : entityChangeListeners) {
listener.onEntitiesUpdated(entities);
listener.onEntitiesUpdated(entities, false);
}
}
......@@ -787,7 +790,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
private void onEntitiesDeleted(List<ITypedReferenceableInstance> entities) throws AtlasException {
for (EntityChangeListener listener : entityChangeListeners) {
listener.onEntitiesDeleted(entities);
listener.onEntitiesDeleted(entities, false);
}
}
......
......@@ -1244,12 +1244,12 @@ public class DefaultMetadataServiceTest {
private List<String> updatedEntities = new ArrayList<>();
@Override
public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities)
public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport)
throws AtlasException {
}
@Override
public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities)
public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport)
throws AtlasException {
updatedEntities.clear();
for (ITypedReferenceableInstance entity : entities) {
......@@ -1268,7 +1268,7 @@ public class DefaultMetadataServiceTest {
}
@Override
public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities)
public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport)
throws AtlasException {
deletedEntities.clear();
for (ITypedReferenceableInstance entity : entities) {
......
......@@ -19,7 +19,6 @@
package org.apache.atlas.listener;
import org.apache.atlas.AtlasException;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
......@@ -29,24 +28,25 @@ import java.util.Collection;
* Entity (a Typed instance) change notification listener.
*/
public interface EntityChangeListener {
/**
* This is upon adding new entities to the repository.
*
* @param entities the created entities
*
* @param isImport
* @throws AtlasException if the listener notification fails
*/
void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities) throws AtlasException;
void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException;
/**
* This is upon updating an entity.
*
* @param entities the updated entities
*
* @param isImport
* @throws AtlasException if the listener notification fails
*/
void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities) throws AtlasException;
void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException;
/**
* This is upon adding a new trait to a typed instance.
......@@ -72,7 +72,8 @@ public interface EntityChangeListener {
* This is upon deleting entities from the repository.
*
* @param entities the deleted entities
* @param isImport
* @throws AtlasException
*/
void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities) throws AtlasException;
void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException;
}
......@@ -77,12 +77,12 @@ public class NotificationEntityChangeListener implements EntityChangeListener {
// ----- EntityChangeListener ----------------------------------------------
@Override
public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities) throws AtlasException {
public void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
notifyOfEntityEvent(entities, EntityNotification.OperationType.ENTITY_CREATE);
}
@Override
public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities) throws AtlasException {
public void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
notifyOfEntityEvent(entities, EntityNotification.OperationType.ENTITY_UPDATE);
}
......@@ -97,7 +97,7 @@ public class NotificationEntityChangeListener implements EntityChangeListener {
}
@Override
public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities) throws AtlasException {
public void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException {
notifyOfEntityEvent(entities, EntityNotification.OperationType.ENTITY_DELETE);
}
......
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