use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.
the class EntityGraphRetriever method addTagPropagation.
private void addTagPropagation(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasEdge edge) throws AtlasBaseException {
final List<AtlasVertex> classificationVertices = getPropagationEnabledClassificationVertices(fromVertex);
final List<AtlasVertex> impactedEntityVertices = CollectionUtils.isNotEmpty(classificationVertices) ? graphHelper.getIncludedImpactedVerticesWithReferences(toVertex, getRelationshipGuid(edge)) : null;
if (CollectionUtils.isNotEmpty(impactedEntityVertices)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Propagate {} tags: from {} entity to {} entities", classificationVertices.size(), getTypeName(fromVertex), impactedEntityVertices.size());
}
for (AtlasVertex classificationVertex : classificationVertices) {
String classificationName = getTypeName(classificationVertex);
AtlasVertex associatedEntityVertex = getAssociatedEntityVertex(classificationVertex);
AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationName);
for (AtlasVertex impactedEntityVertex : impactedEntityVertices) {
if (getClassificationEdge(impactedEntityVertex, classificationVertex) != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(" --> Classification edge already exists from [{}] --> [{}][{}] using edge label: [{}]", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex), classificationName);
}
continue;
} else if (getPropagatedClassificationEdge(impactedEntityVertex, classificationVertex) != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(" --> Propagated classification edge already exists from [{}] --> [{}][{}] using edge label: [{}]", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex), CLASSIFICATION_LABEL);
}
continue;
}
String entityTypeName = getTypeName(impactedEntityVertex);
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
if (!classificationType.canApplyToEntityType(entityType)) {
if (LOG.isDebugEnabled()) {
LOG.debug(" --> Not creating propagated classification edge from [{}] --> [{}][{}], classification is not applicable for entity type", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex));
}
continue;
}
if (LOG.isDebugEnabled()) {
LOG.debug(" --> Creating propagated classification edge from [{}] --> [{}][{}] using edge label: [{}]", getTypeName(impactedEntityVertex), getTypeName(classificationVertex), getTypeName(associatedEntityVertex), CLASSIFICATION_LABEL);
}
AtlasEdge existingEdge = getPropagatedClassificationEdge(impactedEntityVertex, classificationVertex);
if (existingEdge != null) {
continue;
}
graphHelper.addClassificationEdge(impactedEntityVertex, classificationVertex, true);
addToPropagatedTraitNames(impactedEntityVertex, classificationName);
}
}
}
}
use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.
the class AtlasRelationshipDefStoreV1 method preCreate.
@Override
public AtlasVertex preCreate(AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasRelationshipDefStoreV1.preCreate({})", relationshipDef);
}
validateType(relationshipDef);
AtlasType type = typeRegistry.getType(relationshipDef.getName());
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
}
AtlasVertex relationshipDefVertex = typeDefStore.findTypeVertexByName(relationshipDef.getName());
if (relationshipDefVertex != null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, relationshipDef.getName());
}
relationshipDefVertex = typeDefStore.createTypeVertex(relationshipDef);
updateVertexPreCreate(relationshipDef, (AtlasRelationshipType) type, relationshipDefVertex);
final AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
final AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
final String type1 = endDef1.getType();
final String type2 = endDef2.getType();
final String name1 = endDef1.getName();
final String name2 = endDef2.getName();
final AtlasVertex end1TypeVertex = typeDefStore.findTypeVertexByName(type1);
final AtlasVertex end2TypeVertex = typeDefStore.findTypeVertexByName(type2);
if (end1TypeVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type1);
}
if (end2TypeVertex == null) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type2);
}
// create an edge between the relationshipDef and each of the entityDef vertices.
AtlasEdge edge1 = typeDefStore.getOrCreateEdge(relationshipDefVertex, end1TypeVertex, AtlasGraphUtilsV1.RELATIONSHIPTYPE_EDGE_LABEL);
if (type1.equals(type2) && name1.equals(name2)) {
if (LOG.isDebugEnabled()) {
LOG.debug("AtlasRelationshipDefStoreV1.preCreate({}): created relationshipDef vertex {}," + " and one edge as {}, because end1 and end2 have the same type and name", relationshipDef, relationshipDefVertex, edge1);
}
} else {
AtlasEdge edge2 = typeDefStore.getOrCreateEdge(relationshipDefVertex, end2TypeVertex, AtlasGraphUtilsV1.RELATIONSHIPTYPE_EDGE_LABEL);
if (LOG.isDebugEnabled()) {
LOG.debug("AtlasRelationshipDefStoreV1.preCreate({}): created relationshipDef vertex {}," + " edge1 as {}, edge2 as {} ", relationshipDef, relationshipDefVertex, edge1, edge2);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasRelationshipDefStoreV1.preCreate({}): {}", relationshipDef, relationshipDefVertex);
}
return relationshipDefVertex;
}
use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.
the class GraphHelper method getPropagatedClassificationEdge.
public static AtlasEdge getPropagatedClassificationEdge(AtlasVertex entityVertex, AtlasVertex classificationVertex) {
AtlasEdge ret = null;
Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.OUT).label(CLASSIFICATION_LABEL).has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, true).has(CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, getTypeName(classificationVertex)).edges();
if (edges != null && classificationVertex != null) {
Iterator<AtlasEdge> iterator = edges.iterator();
while (iterator != null && iterator.hasNext()) {
AtlasEdge edge = iterator.next();
if (edge != null && edge.getInVertex().equals(classificationVertex)) {
ret = edge;
break;
}
}
}
return ret;
}
use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.
the class GraphHelper method getAdjacentEdgesByLabel.
// 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
public static Iterator<AtlasEdge> getAdjacentEdgesByLabel(AtlasVertex instanceVertex, AtlasEdgeDirection direction, final String 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>() {
private AtlasEdge edge = null;
@Override
public boolean hasNext() {
while (edge == null && iterator.hasNext()) {
AtlasEdge localEdge = iterator.next();
if (localEdge.getLabel().equals(edgeLabel)) {
edge = localEdge;
}
}
return edge != null;
}
@Override
public AtlasEdge next() {
if (hasNext()) {
AtlasEdge localEdge = edge;
edge = null;
return localEdge;
}
return null;
}
@Override
public void remove() {
throw new IllegalStateException("Not handled");
}
};
}
return null;
}
use of org.apache.atlas.repository.graphdb.AtlasEdge in project atlas by apache.
the class GraphHelper method getPropagatedEdges.
public static List<AtlasEdge> getPropagatedEdges(AtlasVertex classificationVertex) {
List<AtlasEdge> ret = new ArrayList<>();
Iterable edges = classificationVertex.query().direction(AtlasEdgeDirection.IN).label(CLASSIFICATION_LABEL).has(CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, true).has(CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, getTypeName(classificationVertex)).edges();
if (edges != null) {
Iterator<AtlasEdge> iterator = edges.iterator();
while (iterator.hasNext()) {
AtlasEdge edge = iterator.next();
ret.add(edge);
}
}
return ret;
}
Aggregations