From 34d235f393c9d5e83b47c19b846cd7c96f10577d Mon Sep 17 00:00:00 2001 From: Madhan Neethiraj <madhan@apache.org> Date: Tue, 17 Jan 2017 21:04:05 -0800 Subject: [PATCH] ATLAS-1471: avoid unnecessary overhead in debug log calls --- repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java | 53 ++++++++++++++++++++++++++++++++++++++++------------- repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapper.java | 10 ++++++++-- repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java | 43 ++++++++++++++++++++++++++++++++++--------- repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java | 28 ++++++++++++++++++---------- repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------- repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ 7 files changed, 365 insertions(+), 133 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java b/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java index 74a9cd1..9eb086f 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java @@ -79,8 +79,11 @@ public abstract class DeleteHandler { String guid = GraphHelper.getGuid(instanceVertex); Id.EntityState state = GraphHelper.getState(instanceVertex); if (requestContext.getDeletedEntityIds().contains(guid) || state == Id.EntityState.DELETED) { - LOG.debug("Skipping deletion of {} as it is already deleted", guid); - continue; + if (LOG.isDebugEnabled()) { + LOG.debug("Skipping deletion of {} as it is already deleted", guid); + } + + continue; } // Get GUIDs and vertices for all deletion candidates. @@ -131,13 +134,19 @@ public abstract class DeleteHandler { * @throws AtlasException */ protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throws AtlasException { - LOG.debug("Deleting {}", string(instanceVertex)); + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting {}", string(instanceVertex)); + } + String typeName = GraphHelper.getTypeName(instanceVertex); IDataType type = typeSystem.getDataType(IDataType.class, typeName); FieldMapping fieldMapping = getFieldMapping(type); for (AttributeInfo attributeInfo : fieldMapping.fields.values()) { - LOG.debug("Deleting attribute {} for {}", attributeInfo.name, string(instanceVertex)); + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting attribute {} for {}", attributeInfo.name, string(instanceVertex)); + } + String edgeLabel = GraphHelper.getEdgeLabel(type, attributeInfo); switch (attributeInfo.dataType().getTypeCategory()) { @@ -200,7 +209,10 @@ public abstract class DeleteHandler { */ public boolean deleteEdgeReference(AtlasEdge edge, DataTypes.TypeCategory typeCategory, boolean isComposite, boolean forceDeleteStructTrait) throws AtlasException { - LOG.debug("Deleting {}", string(edge)); + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting {}", string(edge)); + } + boolean forceDelete = (typeCategory == DataTypes.TypeCategory.STRUCT || typeCategory == DataTypes.TypeCategory.TRAIT) && forceDeleteStructTrait; if (typeCategory == DataTypes.TypeCategory.STRUCT || typeCategory == DataTypes.TypeCategory.TRAIT @@ -247,7 +259,9 @@ public abstract class DeleteHandler { protected void deleteVertex(AtlasVertex instanceVertex, boolean force) throws AtlasException { //Update external references(incoming edges) to this vertex - LOG.debug("Setting the external references to {} to null(removing edges)", string(instanceVertex)); + if (LOG.isDebugEnabled()) { + LOG.debug("Setting the external references to {} to null(removing edges)", string(instanceVertex)); + } for (AtlasEdge edge : (Iterable<AtlasEdge>) instanceVertex.getEdges(AtlasEdgeDirection.IN)) { Id.EntityState edgeState = GraphHelper.getState(edge); @@ -271,8 +285,11 @@ public abstract class DeleteHandler { * @throws AtlasException */ protected void deleteEdgeBetweenVertices(AtlasVertex outVertex, AtlasVertex inVertex, String attributeName) throws AtlasException { - LOG.debug("Removing edge from {} to {} with attribute name {}", string(outVertex), string(inVertex), - attributeName); + if (LOG.isDebugEnabled()) { + LOG.debug("Removing edge from {} to {} with attribute name {}", string(outVertex), string(inVertex), + attributeName); + } + String typeName = GraphHelper.getTypeName(outVertex); String outId = GraphHelper.getGuid(outVertex); Id.EntityState state = GraphHelper.getState(outVertex); @@ -331,8 +348,11 @@ public abstract class DeleteHandler { //if composite attribute, remove the reference as well. else, just remove the edge //for example, when table is deleted, process still references the table //but when column is deleted, table will not reference the deleted column - LOG.debug("Removing edge {} from the array attribute {}", string(elementEdge), - attributeName); + if (LOG.isDebugEnabled()) { + LOG.debug("Removing edge {} from the array attribute {}", string(elementEdge), + attributeName); + } + elements.remove(elementEdge.getId().toString()); GraphHelper.setProperty(outVertex, propertyName, elements); break; @@ -367,8 +387,11 @@ public abstract class DeleteHandler { if (shouldUpdateReverseAttribute) { //remove this key - LOG.debug("Removing edge {}, key {} from the map attribute {}", string(mapEdge), key, - attributeName); + if (LOG.isDebugEnabled()) { + LOG.debug("Removing edge {}, key {} from the map attribute {}", string(mapEdge), key, + attributeName); + } + keys.remove(key); GraphHelper.setProperty(outVertex, propertyName, keys); GraphHelper.setProperty(outVertex, keyPropertyName, null); @@ -426,7 +449,11 @@ public abstract class DeleteHandler { */ private void deleteAllTraits(AtlasVertex instanceVertex) throws AtlasException { List<String> traitNames = GraphHelper.getTraitNames(instanceVertex); - LOG.debug("Deleting traits {} for {}", traitNames, string(instanceVertex)); + + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting traits {} for {}", traitNames, string(instanceVertex)); + } + String typeName = GraphHelper.getTypeName(instanceVertex); for (String traitNameToBeDeleted : traitNames) { diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapper.java index 7c4bdc1..0d7487e 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapper.java @@ -56,12 +56,18 @@ public class FullTextMapper { ITypedReferenceableInstance typedReference; if (instanceCache.containsKey(guid)) { typedReference = instanceCache.get(guid); - LOG.debug("Cache hit: guid = {}, entityId = {}", guid, typedReference.getId()._getId()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Cache hit: guid = {}, entityId = {}", guid, typedReference.getId()._getId()); + } } else { typedReference = graphToTypedInstanceMapper.mapGraphToTypedInstance(guid, instanceVertex); instanceCache.put(guid, typedReference); - LOG.debug("Cache miss: guid = {}, entityId = {}", guid, typedReference.getId().getId()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Cache miss: guid = {}, entityId = {}", guid, typedReference.getId().getId()); + } } String fullText = forInstance(typedReference, followReferences); StringBuilder fullTextBuilder = diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java index d20e913..b9671b2 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java @@ -136,7 +136,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @GraphTransaction public List<String> createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException { - LOG.debug("adding entities={}", entities); + if (LOG.isDebugEnabled()) { + LOG.debug("adding entities={}", entities); + } + try { TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler); instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities); @@ -151,7 +154,9 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public ITypedReferenceableInstance getEntityDefinition(String guid) throws RepositoryException, EntityNotFoundException { - LOG.debug("Retrieving entity with guid={}", guid); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving entity with guid={}", guid); + } AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid); @@ -166,7 +171,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @GraphTransaction public ITypedReferenceableInstance getEntityDefinition(String entityType, String attribute, Object value) throws AtlasException { - LOG.debug("Retrieving entity with type={} and {}={}", entityType, attribute, value); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving entity with type={} and {}={}", entityType, attribute, value); + } + IDataType type = typeSystem.getDataType(IDataType.class, entityType); String propertyKey = getFieldNameInVertex(type, attribute); AtlasVertex instanceVertex = graphHelper.findVertex(propertyKey, value, @@ -180,7 +188,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public List<String> getEntityList(String entityType) throws RepositoryException { - LOG.debug("Retrieving entity list for type={}", entityType); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving entity list for type={}", entityType); + } + AtlasGraphQuery query = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, entityType); Iterator<AtlasVertex> results = query.vertices().iterator(); if (!results.hasNext()) { @@ -206,7 +217,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public List<String> getTraitNames(String guid) throws AtlasException { - LOG.debug("Retrieving trait names for entity={}", guid); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving trait names for entity={}", guid); + } + AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid); return GraphHelper.getTraitNames(instanceVertex); } @@ -224,7 +238,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { public void addTrait(String guid, ITypedStruct traitInstance) throws RepositoryException { Preconditions.checkNotNull(traitInstance, "Trait instance cannot be null"); final String traitName = traitInstance.getTypeName(); - LOG.debug("Adding a new trait={} for entity={}", traitName, guid); + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding a new trait={} for entity={}", traitName, guid); + } try { AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid); @@ -260,7 +277,9 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public void deleteTrait(String guid, String traitNameToBeDeleted) throws TraitNotFoundException, EntityNotFoundException, RepositoryException { - LOG.debug("Deleting trait={} from entity={}", traitNameToBeDeleted, guid); + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting trait={} from entity={}", traitNameToBeDeleted, guid); + } AtlasVertex instanceVertex = graphHelper.getVertexForGUID(guid); @@ -303,7 +322,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public AtlasClient.EntityResult updateEntities(ITypedReferenceableInstance... entitiesUpdated) throws RepositoryException { - LOG.debug("updating entity {}", entitiesUpdated); + if (LOG.isDebugEnabled()) { + LOG.debug("updating entity {}", entitiesUpdated); + } + try { TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler); instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.UPDATE_FULL, @@ -319,7 +341,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public AtlasClient.EntityResult updatePartial(ITypedReferenceableInstance entity) throws RepositoryException { - LOG.debug("updating entity {}", entity); + if (LOG.isDebugEnabled()) { + LOG.debug("updating entity {}", entity); + } + try { TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler); instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.UPDATE_PARTIAL, entity); diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java index 42a22a8..43d6389 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java @@ -233,7 +233,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh AtlasGraphManagement management = provider.get().getManagementSystem(); for (IDataType dataType : dataTypes) { - LOG.debug("Creating indexes for type name={}, definition={}", dataType.getName(), dataType.getClass()); + if (LOG.isDebugEnabled()) { + LOG.debug("Creating indexes for type name={}, definition={}", dataType.getName(), dataType.getClass()); + } + try { addIndexForType(management, dataType); LOG.info("Index creation for type {} complete", dataType.getName()); @@ -506,17 +509,17 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh AtlasPropertyKey propertyKey, boolean enforceUniqueness) { String propertyName = propertyKey.getName(); - LOG.debug("Creating composite index for property {} of type {} ", propertyName, propertyClass.getName()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Creating composite index for property {} of type {}; isUnique={} ", propertyName, propertyClass.getName(), enforceUniqueness); + } AtlasGraphIndex existingIndex = management.getGraphIndex(propertyName); if (existingIndex == null) { - if (enforceUniqueness) { - LOG.debug("Enabling unique index for property {} of type {} ", propertyName, propertyClass.getName()); - } management.createExactMatchIndex(propertyName, enforceUniqueness, Collections.singletonList(propertyKey)); - } - LOG.info("Created composite index for property {} of type {} ", propertyName, propertyClass.getName()); + + LOG.info("Created composite index for property {} of type {}; isUnique={} ", propertyName, propertyClass.getName(), enforceUniqueness); } @@ -536,8 +539,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh Class propertyClass, AtlasPropertyKey propertyKey, final String systemPropertyKey, AtlasCardinality cardinality) { - LOG.debug("Creating composite index for property {} of type {} and {}", propertyKey.getName(), propertyClass.getName(), - systemPropertyKey); + if (LOG.isDebugEnabled()) { + LOG.debug("Creating composite index for property {} of type {} and {}", propertyKey.getName(), propertyClass.getName(), + systemPropertyKey); + } AtlasPropertyKey typePropertyKey = management.getPropertyKey(systemPropertyKey); if (typePropertyKey == null) { @@ -562,9 +567,12 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh private void updateVertexIndex(AtlasGraphManagement management, String propertyName, Class propertyClass, AtlasCardinality cardinality, AtlasPropertyKey propertyKey) { if (checkIfVertexIndexApplicable(propertyClass, cardinality)) { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating backing index for property {} of type {} ", propertyName, propertyClass.getName()); + } + // Use backing index management.addVertexIndexKey(Constants.VERTEX_INDEX, propertyKey); - LOG.debug("Creating backing index for property {} of type {} ", propertyName, propertyClass.getName()); LOG.info("Created backing index for property {} of type {} ", propertyName, propertyClass.getName()); } diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java index bcdf344..5259249 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java @@ -24,7 +24,6 @@ import com.google.common.collect.HashBiMap; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasException; import org.apache.atlas.RequestContext; -import org.apache.atlas.aspect.Monitored; import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.RepositoryException; import org.apache.atlas.repository.graphdb.AtlasEdge; @@ -129,10 +128,12 @@ public final class GraphHelper { return vertexWithIdentity; } - @Monitored public AtlasVertex createVertexWithoutIdentity(String typeName, Id typedInstanceId, Set<String> superTypeNames) { - LOG.debug("Creating AtlasVertex for type {} id {}", typeName, - typedInstanceId != null ? typedInstanceId._getId() : null); + if (LOG.isDebugEnabled()) { + LOG.debug("Creating AtlasVertex for type {} id {}", typeName, + typedInstanceId != null ? typedInstanceId._getId() : null); + } + final AtlasVertex vertexWithoutIdentity = graph.addVertex(); // add type information @@ -157,9 +158,11 @@ public final class GraphHelper { return vertexWithoutIdentity; } - @Monitored private AtlasEdge addEdge(AtlasVertex fromVertex, AtlasVertex toVertex, String edgeLabel) { - LOG.debug("Adding edge for {} -> label {} -> {}", string(fromVertex), edgeLabel, string(toVertex)); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding edge for {} -> label {} -> {}", string(fromVertex), edgeLabel, string(toVertex)); + } + AtlasEdge edge = graph.addEdge(fromVertex, toVertex, edgeLabel); setProperty(edge, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); @@ -168,14 +171,20 @@ public final class GraphHelper { setProperty(edge, Constants.CREATED_BY_KEY, RequestContext.get().getUser()); setProperty(edge, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); - LOG.debug("Added {}", string(edge)); + if (LOG.isDebugEnabled()) { + LOG.debug("Added {}", string(edge)); + } + return edge; } public AtlasEdge getOrCreateEdge(AtlasVertex outVertex, AtlasVertex inVertex, String edgeLabel) throws RepositoryException { for (int numRetries = 0; numRetries < maxRetries; numRetries++) { try { - LOG.debug("Running edge creation attempt {}", numRetries); + if (LOG.isDebugEnabled()) { + LOG.debug("Running edge creation attempt {}", numRetries); + } + Iterator<AtlasEdge> edges = getAdjacentEdgesByLabel(inVertex, AtlasEdgeDirection.IN, edgeLabel); while (edges.hasNext()) { @@ -209,7 +218,6 @@ public final class GraphHelper { return null; } - @Monitored public AtlasEdge getEdgeByEdgeId(AtlasVertex outVertex, String edgeLabel, String edgeId) { if (edgeId == null) { return null; @@ -235,26 +243,26 @@ public final class GraphHelper { * @return AtlasVertex with the given property keys * @throws EntityNotFoundException */ - @Monitored public AtlasVertex findVertex(Object... args) throws EntityNotFoundException { - StringBuilder condition = new StringBuilder(); AtlasGraphQuery query = graph.query(); for (int i = 0 ; i < args.length; i+=2) { query = query.has((String) args[i], args[i+1]); - condition.append(args[i]).append(" = ").append(args[i+1]).append(", "); } - String conditionStr = condition.toString(); - LOG.debug("Finding AtlasVertex with {}", conditionStr); Iterator<AtlasVertex> results = query.vertices().iterator(); // returning one since entityType, qualifiedName should be unique AtlasVertex vertex = results.hasNext() ? results.next() : null; if (vertex == null) { - LOG.debug("Could not find a vertex with {}", condition.toString()); + String conditionStr = getConditionString(args); + if (LOG.isDebugEnabled()) { + LOG.debug("Could not find a vertex with {}", conditionStr); + } throw new EntityNotFoundException("Could not find an entity in the repository with " + conditionStr); } else { - LOG.debug("Found a vertex {} with {}", string(vertex), conditionStr); + if (LOG.isDebugEnabled()) { + LOG.debug("Found a vertex {} with {}", string(vertex), getConditionString(args)); + } } return vertex; @@ -262,9 +270,11 @@ public final class GraphHelper { //In some cases of parallel APIs, the edge is added, but get edge by label doesn't return the edge. ATLAS-1104 //So traversing all the edges - @Monitored public Iterator<AtlasEdge> getAdjacentEdgesByLabel(AtlasVertex instanceVertex, AtlasEdgeDirection direction, final String edgeLabel) { - LOG.debug("Finding edges for {} with label {}", string(instanceVertex), edgeLabel); + if (LOG.isDebugEnabled()) { + LOG.debug("Finding edges for {} with label {}", string(instanceVertex), edgeLabel); + } + if(instanceVertex != null && edgeLabel != null) { final Iterator<AtlasEdge> iterator = instanceVertex.getEdges(direction).iterator(); return new Iterator<AtlasEdge>() { @@ -311,7 +321,6 @@ public final class GraphHelper { * @param edgeLabel * @return */ - @Monitored public AtlasEdge getEdgeForLabel(AtlasVertex vertex, String edgeLabel) { Iterator<AtlasEdge> iterator = getAdjacentEdgesByLabel(vertex, AtlasEdgeDirection.OUT, edgeLabel); AtlasEdge latestDeletedEdge = null; @@ -321,7 +330,10 @@ public final class GraphHelper { AtlasEdge edge = iterator.next(); Id.EntityState edgeState = getState(edge); if (edgeState == null || edgeState == Id.EntityState.ACTIVE) { - LOG.debug("Found {}", string(edge)); + if (LOG.isDebugEnabled()) { + LOG.debug("Found {}", string(edge)); + } + return edge; } else { Long modificationTime = edge.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class); @@ -331,12 +343,15 @@ public final class GraphHelper { } } } + + if (LOG.isDebugEnabled()) { + LOG.debug("Found {}", latestDeletedEdge == null ? "null" : string(latestDeletedEdge)); + } + //If the vertex is deleted, return latest deleted edge - LOG.debug("Found {}", latestDeletedEdge == null ? "null" : string(latestDeletedEdge)); return latestDeletedEdge; } - @Monitored public static String vertexString(final AtlasVertex vertex) { StringBuilder properties = new StringBuilder(); for (String propertyKey : vertex.getPropertyKeys()) { @@ -347,27 +362,38 @@ public final class GraphHelper { return "v[" + vertex.getIdForDisplay() + "], Properties[" + properties + "]"; } - @Monitored public static String edgeString(final AtlasEdge edge) { return "e[" + edge.getLabel() + "], [" + edge.getOutVertex() + " -> " + edge.getLabel() + " -> " + edge.getInVertex() + "]"; } - @Monitored public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value) { - String elementStr = string(element); String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - LOG.debug("Setting property {} = \"{}\" to {}", actualPropertyName, value, elementStr); + + String elementStr = null; + + if (LOG.isDebugEnabled()) { + elementStr = string(element); + + LOG.debug("Setting property {} = \"{}\" to {}", actualPropertyName, value, elementStr); + } + Object existValue = element.getProperty(actualPropertyName, Object.class); if(value == null || (value instanceof Collection && ((Collection) value).isEmpty())) { if(existValue != null) { - LOG.info("Removing property - {} value from {}", actualPropertyName, elementStr); + if (LOG.isDebugEnabled()) { + LOG.debug("Removing property - {} value from {}", actualPropertyName, elementStr); + } + element.removeProperty(actualPropertyName); } } else { if (!value.equals(existValue)) { element.setProperty(actualPropertyName, value); - LOG.debug("Set property {} = \"{}\" to {}", actualPropertyName, value, elementStr); + + if (LOG.isDebugEnabled()) { + LOG.debug("Set property {} = \"{}\" to {}", actualPropertyName, value, elementStr); + } } } } @@ -382,21 +408,23 @@ public final class GraphHelper { * @param clazz * @return */ - @Monitored public static <T> T getSingleValuedProperty(AtlasElement element, String propertyName, Class<T> clazz) { - String elementStr = string(element); String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - LOG.debug("Reading property {} from {}", actualPropertyName, elementStr); + + if (LOG.isDebugEnabled()) { + LOG.debug("Reading property {} from {}", actualPropertyName, string(element)); + } return element.getProperty(actualPropertyName, clazz); } - @Monitored public static Object getProperty(AtlasVertex<?,?> vertex, String propertyName) { - String elementStr = string(vertex); String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - LOG.debug("Reading property {} from {}", actualPropertyName, elementStr); + + if (LOG.isDebugEnabled()) { + LOG.debug("Reading property {} from {}", actualPropertyName, string(vertex)); + } if(AtlasGraphProvider.getGraphInstance().isMultiProperty(actualPropertyName)) { return vertex.getPropertyValues(actualPropertyName, String.class); @@ -406,11 +434,13 @@ public final class GraphHelper { } } - @Monitored public static Object getProperty(AtlasEdge<?,?> edge, String propertyName) { - String elementStr = string(edge); String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - LOG.debug("Reading property {} from {}", actualPropertyName, elementStr); + + if (LOG.isDebugEnabled()) { + LOG.debug("Reading property {} from {}", actualPropertyName, string(edge)); + } + return edge.getProperty(actualPropertyName, Object.class); } @@ -430,10 +460,13 @@ public final class GraphHelper { * @param propertyName * @param value */ - @Monitored public static void addProperty(AtlasVertex vertex, String propertyName, Object value) { String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - LOG.debug("Adding property {} = \"{}\" to vertex {}", actualPropertyName, value, string(vertex)); + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding property {} = \"{}\" to vertex {}", actualPropertyName, value, string(vertex)); + } + vertex.addProperty(actualPropertyName, value); } @@ -442,12 +475,20 @@ public final class GraphHelper { * * @param edge */ - @Monitored public void removeEdge(AtlasEdge edge) { - String edgeString = string(edge); - LOG.debug("Removing {}", edgeString); + String edgeString = null; + + if (LOG.isDebugEnabled()) { + edgeString = string(edge); + + LOG.debug("Removing {}", edgeString); + } + graph.removeEdge(edge); - LOG.info("Removed {}", edgeString); + + if (LOG.isDebugEnabled()) { + LOG.info("Removed {}", edgeString); + } } /** @@ -455,12 +496,20 @@ public final class GraphHelper { * * @param vertex */ - @Monitored public void removeVertex(AtlasVertex vertex) { - String vertexString = string(vertex); - LOG.debug("Removing {}", vertexString); + String vertexString = null; + + if (LOG.isDebugEnabled()) { + vertexString = string(vertex); + + LOG.debug("Removing {}", vertexString); + } + graph.removeVertex(vertex); - LOG.info("Removed {}", vertexString); + + if (LOG.isDebugEnabled()) { + LOG.info("Removed {}", vertexString); + } } public AtlasVertex getVertexForGUID(String guid) throws EntityNotFoundException { @@ -564,7 +613,10 @@ public final class GraphHelper { */ public AtlasVertex getVertexForInstanceByUniqueAttribute(ClassType classType, IReferenceableInstance instance) throws AtlasException { - LOG.debug("Checking if there is an instance with the same unique attributes for instance {}", instance.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("Checking if there is an instance with the same unique attributes for instance {}", instance.toShortString()); + } + AtlasVertex result = null; for (AttributeInfo attributeInfo : classType.fieldMapping().fields.values()) { if (attributeInfo.isUnique) { @@ -573,7 +625,9 @@ public final class GraphHelper { result = findVertex(propertyKey, instance.get(attributeInfo.name), Constants.ENTITY_TYPE_PROPERTY_KEY, classType.getName(), Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); - LOG.debug("Found vertex by unique attribute : {}={}", propertyKey, instance.get(attributeInfo.name)); + if (LOG.isDebugEnabled()) { + LOG.debug("Found vertex by unique attribute : {}={}", propertyKey, instance.get(attributeInfo.name)); + } } catch (EntityNotFoundException e) { //Its ok if there is no entity with the same unique value } @@ -745,7 +799,6 @@ public final class GraphHelper { } - @Monitored public static void setArrayElementsProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName, List<Object> values) { String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { @@ -756,7 +809,6 @@ public final class GraphHelper { } } - @Monitored public static void setMapValueProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName, Object value) { String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { @@ -767,7 +819,6 @@ public final class GraphHelper { } } - @Monitored public static Object getMapValueProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName) { String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { @@ -778,7 +829,6 @@ public final class GraphHelper { } } - @Monitored public static List<Object> getArrayElementsProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName) { String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { @@ -921,4 +971,15 @@ public final class GraphHelper { String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); return instanceVertex.getListProperty(actualPropertyName); } + + + private String getConditionString(Object[] args) { + StringBuilder condition = new StringBuilder(); + + for (int i = 0; i < args.length; i+=2) { + condition.append(args[i]).append(" = ").append(args[i+1]).append(", "); + } + + return condition.toString(); + } } diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java index f7b1ff0..4220c35 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java @@ -70,7 +70,10 @@ public final class GraphToTypedInstanceMapper { public ITypedReferenceableInstance mapGraphToTypedInstance(String guid, AtlasVertex instanceVertex) throws AtlasException { - LOG.debug("Mapping graph root vertex {} to typed instance for guid {}", instanceVertex, guid); + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping graph root vertex {} to typed instance for guid {}", instanceVertex, guid); + } + String typeName = GraphHelper.getSingleValuedProperty(instanceVertex, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class); List<String> traits = GraphHelper.getTraitNames(instanceVertex); String state = GraphHelper.getStateAsString(instanceVertex); @@ -80,11 +83,16 @@ public final class GraphToTypedInstanceMapper { Date modifiedTime = new Date(GraphHelper.getModifiedTime(instanceVertex)); AtlasSystemAttributes systemAttributes = new AtlasSystemAttributes(createdBy, modifiedBy, createdTime, modifiedTime); - LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime); + if (LOG.isDebugEnabled()) { + LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime); + } Id id = new Id(guid, Integer.parseInt(String.valueOf(GraphHelper.getProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY))), typeName, state); - LOG.debug("Created id {} for instance type {}", id, typeName); + + if (LOG.isDebugEnabled()) { + LOG.debug("Created id {} for instance type {}", id, typeName); + } ClassType classType = typeSystem.getDataType(ClassType.class, typeName); ITypedReferenceableInstance typedInstance = @@ -100,7 +108,10 @@ public final class GraphToTypedInstanceMapper { private void mapVertexToInstanceTraits(AtlasVertex instanceVertex, ITypedReferenceableInstance typedInstance, List<String> traits) throws AtlasException { for (String traitName : traits) { - LOG.debug("mapping trait {} to instance", traitName); + if (LOG.isDebugEnabled()) { + LOG.debug("mapping trait {} to instance", traitName); + } + TraitType traitType = typeSystem.getDataType(TraitType.class, traitName); mapVertexToTraitInstance(instanceVertex, typedInstance, traitName, traitType); } @@ -110,8 +121,11 @@ public final class GraphToTypedInstanceMapper { public void mapVertexToInstance(AtlasVertex instanceVertex, ITypedInstance typedInstance, Map<String, AttributeInfo> fields) throws AtlasException { - LOG.debug("Mapping vertex {} to instance {} for fields", instanceVertex, typedInstance.getTypeName(), - fields); + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping vertex {} to instance {} for fields", instanceVertex, typedInstance.getTypeName(), + fields); + } + for (AttributeInfo attributeInfo : fields.values()) { mapVertexToAttribute(instanceVertex, typedInstance, attributeInfo); } @@ -119,7 +133,11 @@ public final class GraphToTypedInstanceMapper { private void mapVertexToAttribute(AtlasVertex instanceVertex, ITypedInstance typedInstance, AttributeInfo attributeInfo) throws AtlasException { - LOG.debug("Mapping attributeInfo {}", attributeInfo.name); + + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping attributeInfo {}", attributeInfo.name); + } + final IDataType dataType = attributeInfo.dataType(); final String vertexPropertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo); String relationshipLabel = GraphHelper.getEdgeLabel(typedInstance, attributeInfo); @@ -172,7 +190,9 @@ public final class GraphToTypedInstanceMapper { private Object mapVertexToClassReference(AtlasVertex instanceVertex, AttributeInfo attributeInfo, String relationshipLabel, IDataType dataType, AtlasEdge optionalEdge) throws AtlasException { - LOG.debug("Finding edge for {} -> label {} ", instanceVertex, relationshipLabel); + if (LOG.isDebugEnabled()) { + LOG.debug("Finding edge for {} -> label {} ", instanceVertex, relationshipLabel); + } AtlasEdge edge = null; if (optionalEdge == null) { @@ -184,7 +204,11 @@ public final class GraphToTypedInstanceMapper { if (GraphHelper.elementExists(edge)) { final AtlasVertex referenceVertex = edge.getInVertex(); final String guid = GraphHelper.getSingleValuedProperty(referenceVertex, Constants.GUID_PROPERTY_KEY, String.class); - LOG.debug("Found vertex {} for label {} with guid {}", referenceVertex, relationshipLabel, guid); + + if (LOG.isDebugEnabled()) { + LOG.debug("Found vertex {} for label {} with guid {}", referenceVertex, relationshipLabel, guid); + } + if (attributeInfo.isComposite) { //Also, when you retrieve a type's instance, you get the complete object graph of the composites LOG.debug("Found composite, mapping vertex to instance"); @@ -194,7 +218,11 @@ public final class GraphToTypedInstanceMapper { Id referenceId = new Id(guid, GraphHelper.getSingleValuedProperty(referenceVertex, Constants.VERSION_PROPERTY_KEY, Integer.class), dataType.getName(), state); - LOG.debug("Found non-composite, adding id {} ", referenceId); + + if (LOG.isDebugEnabled()) { + LOG.debug("Found non-composite, adding id {} ", referenceId); + } + return referenceId; } } @@ -205,7 +233,9 @@ public final class GraphToTypedInstanceMapper { @SuppressWarnings("unchecked") private void mapVertexToArrayInstance(AtlasVertex<?,?> instanceVertex, ITypedInstance typedInstance, AttributeInfo attributeInfo, String propertyName) throws AtlasException { - LOG.debug("mapping vertex {} to array {}", instanceVertex, attributeInfo.name); + if (LOG.isDebugEnabled()) { + LOG.debug("mapping vertex {} to array {}", instanceVertex, attributeInfo.name); + } final DataTypes.ArrayType arrayType = (DataTypes.ArrayType) attributeInfo.dataType(); final IDataType elementType = arrayType.getElemType(); @@ -257,7 +287,10 @@ public final class GraphToTypedInstanceMapper { @SuppressWarnings("unchecked") private void mapVertexToMapInstance(AtlasVertex<?,?> instanceVertex, ITypedInstance typedInstance, AttributeInfo attributeInfo, final String propertyName) throws AtlasException { - LOG.debug("mapping vertex {} to array {}", instanceVertex, attributeInfo.name); + if (LOG.isDebugEnabled()) { + LOG.debug("mapping vertex {} to array {}", instanceVertex, attributeInfo.name); + } + List<String> keys = GraphHelper.getListProperty(instanceVertex, propertyName); if (keys == null || keys.size() == 0) { return; @@ -283,7 +316,10 @@ public final class GraphToTypedInstanceMapper { private ITypedStruct mapVertexToStructInstance(AtlasVertex instanceVertex, StructType structType, String relationshipLabel, AtlasEdge optionalEdge) throws AtlasException { - LOG.debug("mapping {} to struct {}", string(instanceVertex), relationshipLabel); + if (LOG.isDebugEnabled()) { + LOG.debug("mapping {} to struct {}", string(instanceVertex), relationshipLabel); + } + ITypedStruct structInstance = null; AtlasEdge edge; @@ -296,10 +332,12 @@ public final class GraphToTypedInstanceMapper { if (GraphHelper.elementExists(edge)) { structInstance = structType.createInstance(); AtlasVertex structInstanceVertex = edge.getInVertex(); - LOG.debug("Found struct instance {}, mapping to instance {} ", string(structInstanceVertex), - structInstance.getTypeName()); - mapVertexToInstance(structInstanceVertex, structInstance, structType.fieldMapping().fields); + if (LOG.isDebugEnabled()) { + LOG.debug("Found struct instance {}, mapping to instance {} ", string(structInstanceVertex), + structInstance.getTypeName()); + } + mapVertexToInstance(structInstanceVertex, structInstance, structType.fieldMapping().fields); } return structInstance; } @@ -314,12 +352,19 @@ public final class GraphToTypedInstanceMapper { private void mapVertexToTraitInstance(AtlasVertex<?,?> instanceVertex, String typedInstanceTypeName, String traitName, TraitType traitType, ITypedStruct traitInstance) throws AtlasException { String relationshipLabel = GraphHelper.getTraitLabel(typedInstanceTypeName, traitName); - LOG.debug("Finding edge for {} -> label {} ", instanceVertex, relationshipLabel); + + if (LOG.isDebugEnabled()) { + LOG.debug("Finding edge for {} -> label {} ", instanceVertex, relationshipLabel); + } + for (AtlasEdge<?,?> edge : instanceVertex.getEdges(AtlasEdgeDirection.OUT, relationshipLabel)) { final AtlasVertex<?,?> traitInstanceVertex = edge.getInVertex(); if (traitInstanceVertex != null) { - LOG.debug("Found trait instance vertex {}, mapping to instance {} ", traitInstanceVertex, - traitInstance.getTypeName()); + if (LOG.isDebugEnabled()) { + LOG.debug("Found trait instance vertex {}, mapping to instance {} ", traitInstanceVertex, + traitInstance.getTypeName()); + } + mapVertexToInstance(traitInstanceVertex, traitInstance, traitType.fieldMapping().fields); break; } @@ -328,7 +373,10 @@ public final class GraphToTypedInstanceMapper { private void mapVertexToPrimitive(AtlasVertex<?,?> instanceVertex, ITypedInstance typedInstance, AttributeInfo attributeInfo) throws AtlasException { - LOG.debug("Adding primitive {} from vertex {}", attributeInfo, instanceVertex); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding primitive {} from vertex {}", attributeInfo, instanceVertex); + } + final String vertexPropertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo); if (GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Object.class) == null) { return; @@ -369,8 +417,11 @@ public final class GraphToTypedInstanceMapper { if (referredVertex != null) { switch (referredType.getTypeCategory()) { case STRUCT: - LOG.debug("Found struct instance vertex {}, mapping to instance {} ", referredVertex, - referredType.getName()); + if (LOG.isDebugEnabled()) { + LOG.debug("Found struct instance vertex {}, mapping to instance {} ", referredVertex, + referredType.getName()); + } + StructType structType = (StructType) referredType; ITypedStruct instance = structType.createInstance(); Map<String, AttributeInfo> fields = structType.fieldMapping().fields; diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java index 3d35f36..a6000cd 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java @@ -90,7 +90,10 @@ public final class TypedInstanceToGraphMapper { throws AtlasException { RequestContext requestContext = RequestContext.get(); for (ITypedReferenceableInstance typedInstance : typedInstances) { - LOG.debug("Adding/updating entity {}", typedInstance); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding/updating entity {}", typedInstance); + } + Collection<IReferenceableInstance> newInstances = walkClassInstances(typedInstance); TypeUtils.Pair<List<ITypedReferenceableInstance>, List<ITypedReferenceableInstance>> instancesPair = createVerticesAndDiscoverInstances(newInstances); @@ -126,7 +129,10 @@ public final class TypedInstanceToGraphMapper { EntityProcessor entityProcessor = new EntityProcessor(); try { - LOG.debug("Walking the object graph for instance {}", typedInstance.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("Walking the object graph for instance {}", typedInstance.toShortString()); + } + new ObjectGraphWalker(typeSystem, entityProcessor, typedInstance).walk(); } catch (AtlasException me) { throw new RepositoryException("TypeSystem error when walking the ObjectGraph", me); @@ -153,7 +159,9 @@ public final class TypedInstanceToGraphMapper { @Monitored private String addOrUpdateAttributesAndTraits(Operation operation, ITypedReferenceableInstance typedInstance) throws AtlasException { - LOG.debug("Adding/Updating typed instance {}", typedInstance.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding/Updating typed instance {}", typedInstance.toShortString()); + } Id id = typedInstance.getId(); if (id == null) { // oops @@ -178,8 +186,10 @@ public final class TypedInstanceToGraphMapper { void mapInstanceToVertex(ITypedInstance typedInstance, AtlasVertex instanceVertex, Map<String, AttributeInfo> fields, boolean mapOnlyUniqueAttributes, Operation operation) throws AtlasException { + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping instance {} to vertex {}", typedInstance.toShortString(), string(instanceVertex)); + } - LOG.debug("Mapping instance {} to vertex {}", typedInstance.toShortString(), string(instanceVertex)); for (AttributeInfo attributeInfo : fields.values()) { if (mapOnlyUniqueAttributes && !attributeInfo.isUnique) { continue; @@ -189,7 +199,10 @@ public final class TypedInstanceToGraphMapper { GraphHelper.setProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); GraphHelper.setProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); - LOG.debug("Setting modifiedBy: {} and modifiedTime: {}", RequestContext.get().getUser(), RequestContext.get().getRequestTime()); + + if (LOG.isDebugEnabled()) { + LOG.debug("Setting modifiedBy: {} and modifiedTime: {}", RequestContext.get().getUser(), RequestContext.get().getRequestTime()); + } } void mapAttributeToVertex(ITypedInstance typedInstance, AtlasVertex instanceVertex, @@ -198,7 +211,10 @@ public final class TypedInstanceToGraphMapper { if ( typedInstance.isValueSet(attributeInfo.name) || operation == Operation.CREATE ) { Object attrValue = typedInstance.get(attributeInfo.name); - LOG.debug("Mapping attribute {} = {}", attributeInfo.name, attrValue); + + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping attribute {} = {}", attributeInfo.name, attrValue); + } switch (attributeInfo.dataType().getTypeCategory()) { case PRIMITIVE: @@ -246,14 +262,20 @@ public final class TypedInstanceToGraphMapper { List<ITypedReferenceableInstance> instancesToUpdate = new ArrayList<>(); for (IReferenceableInstance instance : instances) { - LOG.debug("Discovering instance to create/update for {}", instance.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("Discovering instance to create/update for {}", instance.toShortString()); + } + ITypedReferenceableInstance newInstance; Id id = instance.getId(); if (!idToVertexMap.containsKey(id)) { AtlasVertex instanceVertex; if (id.isAssigned()) { // has a GUID - LOG.debug("Instance has an assigned id {}", instance.getId()._getId()); + if (LOG.isDebugEnabled()) { + LOG.debug("Instance has an assigned id {}", instance.getId()._getId()); + } + instanceVertex = graphHelper.getVertexForGUID(id.id); if (!(instance instanceof ReferenceableInstance)) { throw new IllegalStateException( @@ -269,7 +291,10 @@ public final class TypedInstanceToGraphMapper { //no entity with the given unique attribute, create new if (instanceVertex == null) { - LOG.debug("Creating new vertex for instance {}", instance.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("Creating new vertex for instance {}", instance.toShortString()); + } + newInstance = classType.convert(instance, Multiplicity.REQUIRED); instanceVertex = graphHelper.createVertexWithIdentity(newInstance, classType.getAllSuperTypeNames()); instancesToCreate.add(newInstance); @@ -278,7 +303,10 @@ public final class TypedInstanceToGraphMapper { mapInstanceToVertex(newInstance, instanceVertex, classType.fieldMapping().fields, true, Operation.CREATE); } else { - LOG.debug("Re-using existing vertex {} for instance {}", string(instanceVertex), instance.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("Re-using existing vertex {} for instance {}", string(instanceVertex), instance.toShortString()); + } + if (!(instance instanceof ReferenceableInstance)) { throw new IllegalStateException( String.format("%s is not of type ITypedReferenceableInstance", instance.toShortString())); @@ -306,7 +334,10 @@ public final class TypedInstanceToGraphMapper { private void addTraits(ITypedReferenceableInstance typedInstance, AtlasVertex instanceVertex, ClassType classType) throws AtlasException { for (String traitName : typedInstance.getTraits()) { - LOG.debug("mapping trait {}", traitName); + if (LOG.isDebugEnabled()) { + LOG.debug("mapping trait {}", traitName); + } + GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); ITypedStruct traitInstance = (ITypedStruct) typedInstance.getTrait(traitName); @@ -319,8 +350,10 @@ public final class TypedInstanceToGraphMapper { private void mapArrayCollectionToVertex(ITypedInstance typedInstance, AtlasVertex instanceVertex, AttributeInfo attributeInfo, Operation operation) throws AtlasException { - LOG.debug("Mapping instance {} for array attribute {} vertex {}", typedInstance.toShortString(), - attributeInfo.name, string(instanceVertex)); + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping instance {} for array attribute {} vertex {}", typedInstance.toShortString(), + attributeInfo.name, string(instanceVertex)); + } List newElements = (List) typedInstance.get(attributeInfo.name); boolean newAttributeEmpty = (newElements == null || newElements.isEmpty()); @@ -338,8 +371,11 @@ public final class TypedInstanceToGraphMapper { for (; index < newElements.size(); index++) { Object currentElement = (currentElements != null && index < currentElements.size()) ? currentElements.get(index) : null; - LOG.debug("Adding/updating element at position {}, current element {}, new element {}", index, - currentElement, newElements.get(index)); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding/updating element at position {}, current element {}, new element {}", index, + currentElement, newElements.get(index)); + } + Object newEntry = addOrUpdateCollectionEntry(instanceVertex, attributeInfo, elementType, newElements.get(index), currentElement, propertyName, operation); newElementsCreated.add(newEntry); @@ -372,7 +408,10 @@ public final class TypedInstanceToGraphMapper { List<AtlasEdge> cloneElements = new ArrayList<>(currentEntries); cloneElements.removeAll(newEntries); List<AtlasEdge> additionalElements = new ArrayList<>(); - LOG.debug("Removing unused entries from the old collection - {}", cloneElements); + + if (LOG.isDebugEnabled()) { + LOG.debug("Removing unused entries from the old collection - {}", cloneElements); + } if (!cloneElements.isEmpty()) { for (AtlasEdge edge : cloneElements) { @@ -393,8 +432,11 @@ public final class TypedInstanceToGraphMapper { private void mapMapCollectionToVertex(ITypedInstance typedInstance, AtlasVertex instanceVertex, AttributeInfo attributeInfo, Operation operation) throws AtlasException { - LOG.debug("Mapping instance {} to vertex {} for attribute {}", typedInstance.toShortString(), string(instanceVertex), - attributeInfo.name); + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping instance {} to vertex {} for attribute {}", typedInstance.toShortString(), string(instanceVertex), + attributeInfo.name); + } + @SuppressWarnings("unchecked") Map<Object, Object> newAttribute = (Map<Object, Object>) typedInstance.get(attributeInfo.name); @@ -544,8 +586,10 @@ public final class TypedInstanceToGraphMapper { // add a new vertex for the struct or trait instance AtlasVertex structInstanceVertex = graphHelper.createVertexWithoutIdentity(structInstance.getTypeName(), null, Collections.<String>emptySet()); // no super types for struct type - LOG.debug("created vertex {} for struct {} value {}", string(structInstanceVertex), attributeInfo.name, - structInstance.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("created vertex {} for struct {} value {}", string(structInstanceVertex), attributeInfo.name, + structInstance.toShortString()); + } // map all the attributes to this new vertex mapInstanceToVertex(structInstance, structInstanceVertex, structInstance.fieldMapping().fields, false, @@ -561,7 +605,9 @@ public final class TypedInstanceToGraphMapper { //Already existing vertex. Update AtlasVertex structInstanceVertex = currentEdge.getInVertex(); - LOG.debug("Updating struct vertex {} with struct {}", string(structInstanceVertex), newAttributeValue.toShortString()); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating struct vertex {} with struct {}", string(structInstanceVertex), newAttributeValue.toShortString()); + } // Update attributes final MessageDigest digester = MD5Utils.getDigester(); @@ -570,7 +616,10 @@ public final class TypedInstanceToGraphMapper { if (!newSignature.equals(curSignature)) { //Update struct vertex instance only if there is a change - LOG.debug("Updating struct {} since signature has changed {} {} ", newAttributeValue, curSignature, newSignature); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating struct {} since signature has changed {} {} ", newAttributeValue, curSignature, newSignature); + } + mapInstanceToVertex(newAttributeValue, structInstanceVertex, newAttributeValue.fieldMapping().fields, false, operation); GraphHelper.setProperty(structInstanceVertex, SIGNATURE_HASH_PROPERTY_KEY, String.valueOf(newSignature)); } @@ -638,7 +687,10 @@ public final class TypedInstanceToGraphMapper { ITypedReferenceableInstance newAttributeValue, AtlasVertex newVertex, AttributeInfo attributeInfo, String edgeLabel) throws AtlasException { - LOG.debug("Updating {} for reference attribute {}", string(currentEdge), attributeInfo.name); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating {} for reference attribute {}", string(currentEdge), attributeInfo.name); + } + // Update edge if it exists AtlasVertex currentVertex = currentEdge.getInVertex(); String currentEntityId = GraphHelper.getGuid(currentVertex); @@ -663,7 +715,9 @@ public final class TypedInstanceToGraphMapper { final String traitName = traitInstance.getTypeName(); AtlasVertex traitInstanceVertex = graphHelper.createVertexWithoutIdentity(traitInstance.getTypeName(), null, typeSystem.getDataType(TraitType.class, traitName).getAllSuperTypeNames()); - LOG.debug("created vertex {} for trait {}", string(traitInstanceVertex), traitName); + if (LOG.isDebugEnabled()) { + LOG.debug("created vertex {} for trait {}", string(traitInstanceVertex), traitName); + } // map all the attributes to this newly created AtlasVertex mapInstanceToVertex(traitInstance, traitInstanceVertex, traitInstance.fieldMapping().fields, false, Operation.CREATE); -- libgit2 0.27.1