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