Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DG-1746 rename custom to user defined #3396

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions addons/policies/bootstrap_relationship_policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@
"typeName": "AuthPolicy",
"attributes":
{
"name": "LINK_ASSETS_CUSTOM_RELATIONSHIP",
"qualifiedName": "LINK_ASSETS_CUSTOM_RELATIONSHIP",
"name": "LINK_ASSETS_USER_DEFINED_RELATIONSHIP",
"qualifiedName": "LINK_ASSETS_USER_DEFINED_RELATIONSHIP",
"policyCategory": "bootstrap",
"policySubCategory": "default",
"policyServiceName": "atlas",
Expand All @@ -860,7 +860,7 @@
"policyResourceCategory": "RELATIONSHIP",
"policyResources":
[
"relationship-type:CustomRelationship",
"relationship-type:UserDefRelationship",
"end-one-entity-type:Referenceable",
"end-two-entity-type:Referenceable",
"end-one-entity-classification:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public final class Constants {
public static final String INPUT_PORT_PRODUCT_EDGE_LABEL = "__Asset.inputPortDataProducts";
public static final String OUTPUT_PORT_PRODUCT_EDGE_LABEL = "__Asset.outputPortDataProducts";

public static final String CUSTOM_RELATIONSHIP_EDGE_LABEL = "__Referenceable.customRelationshipTo";
public static final String CUSTOM_RELATIONSHIP_END_NAME_FROM = "customRelationshipFrom";
public static final String CUSTOM_RELATIONSHIP_END_NAME_TO = "customRelationshipTo";
public static final String UD_RELATIONSHIP_EDGE_LABEL = "__Referenceable.userDefRelationshipTo";
public static final String UD_RELATIONSHIP_END_NAME_FROM = "userDefRelationshipFrom";
public static final String UD_RELATIONSHIP_END_NAME_TO = "userDefRelationshipTo";

/**
* SQL property keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public enum AtlasConfiguration {

ATLAS_MAINTENANCE_MODE("atlas.maintenance.mode", false),

ATLAS_CUSTOM_RELATIONSHIPS_MAX_COUNT("atlas.custom.relationships.max.count", 100);
ATLAS_UD_RELATIONSHIPS_MAX_COUNT("atlas.ud.relationship.max.count", 100);


private static final Configuration APPLICATION_PROPERTIES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,10 @@ public AtlasObjectId getNormalizedValue(Object obj) {
private boolean isValidMap(Map map) {
Object guid = map.get(AtlasObjectId.KEY_GUID);

if (map.containsKey(AtlasRelatedObjectId.KEY_RELATIONSHIP_ATTRIBUTES) && !map.containsKey(AtlasRelatedObjectId.KEY_RELATIONSHIP_TYPE)) {
return false;
}

if (guid != null && StringUtils.isNotEmpty(guid.toString())) {
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ private boolean isInternalType(final AtlasVertex instanceVertex) {
}

private boolean isCustomRelationship(final AtlasEdge edge) {
return edge.getLabel().equals(CUSTOM_RELATIONSHIP_EDGE_LABEL);
return edge.getLabel().equals(UD_RELATIONSHIP_EDGE_LABEL);
}

private void addToPropagatedClassificationNames(AtlasVertex entityVertex, String classificationName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.apache.atlas.repository.graphdb.janus.JanusUtils;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.repository.store.graph.v1.DeleteHandlerDelegate;
import org.apache.atlas.repository.store.graph.v1.SoftDeleteHandlerV1;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
Expand Down Expand Up @@ -100,7 +99,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
private static final String END_2_DOC_ID_KEY = "end2DocId";
private static final String ES_DOC_ID_MAP_KEY = "esDocIdMap";

private static final String CUSTOM_RELATIONSHIP_TYPE_NAME = "CustomRelationship";
private static final String UD_RELATIONSHIP_TYPE_NAME = "UserDefRelationship";

private static Set<String> EXCLUDE_MUTATION_REL_TYPE_NAMES = new HashSet<String>() {{
add(REL_DOMAIN_TO_DOMAINS);
Expand Down Expand Up @@ -142,7 +141,7 @@ public AtlasRelationship create(AtlasRelationship relationship) throws AtlasBase
AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1());
AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2());

if (relationship.getTypeName().equals(CUSTOM_RELATIONSHIP_TYPE_NAME)) {
if (relationship.getTypeName().equals(UD_RELATIONSHIP_TYPE_NAME)) {
EntityGraphMapper.validateCustomRelationship(end1Vertex, end2Vertex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public class EntityGraphMapper {

private static final int MAX_NUMBER_OF_RETRIES = AtlasConfiguration.MAX_NUMBER_OF_RETRIES.getInt();
private static final int CHUNK_SIZE = AtlasConfiguration.TASKS_GRAPH_COMMIT_CHUNK_SIZE.getInt();
private static final int CUSTOM_REL_THRESHOLD = AtlasConfiguration.ATLAS_CUSTOM_RELATIONSHIPS_MAX_COUNT.getInt();
private static final int UD_REL_THRESHOLD = AtlasConfiguration.ATLAS_UD_RELATIONSHIPS_MAX_COUNT.getInt();

private final GraphHelper graphHelper;
private final AtlasGraph graph;
Expand Down Expand Up @@ -2015,7 +2015,7 @@ public List mapArrayValue(AttributeMutationContext ctx, EntityMutationContext co
addInternalProductAttr(ctx, newElementsCreated, removedElements);
break;

case CUSTOM_RELATIONSHIP_EDGE_LABEL:
case UD_RELATIONSHIP_EDGE_LABEL:
validateCustomRelationship(ctx, newElementsCreated, false);
break;
}
Expand Down Expand Up @@ -2109,7 +2109,7 @@ public List appendArrayValue(AttributeMutationContext ctx, EntityMutationContext
addInternalProductAttr(ctx, newElementsCreated, null);
break;

case CUSTOM_RELATIONSHIP_EDGE_LABEL:
case UD_RELATIONSHIP_EDGE_LABEL:
validateCustomRelationship(ctx, newElementsCreated, true);
break;
}
Expand Down Expand Up @@ -2227,7 +2227,7 @@ public static void validateCustomRelationship(AttributeMutationContext ctx, List

if (isAppend) {
currentSize = ctx.getReferringVertex().getEdgesCount(isEdgeDirectionIn ? AtlasEdgeDirection.IN : AtlasEdgeDirection.OUT,
CUSTOM_RELATIONSHIP_EDGE_LABEL);
UD_RELATIONSHIP_EDGE_LABEL);
} else {
currentSize = newElements.size();
}
Expand All @@ -2253,23 +2253,23 @@ public static void validateCustomRelationship(AttributeMutationContext ctx, List
LOG.info("{}: {}", direction, "inVertex");
}

currentSize = targetVertex.getEdgesCount(direction, CUSTOM_RELATIONSHIP_EDGE_LABEL);
currentSize = targetVertex.getEdgesCount(direction, UD_RELATIONSHIP_EDGE_LABEL);
validateCustomRelationshipCount(currentSize, targetVertex);
}
}

public static void validateCustomRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex) throws AtlasBaseException {
long currentSize = end1Vertex.getEdgesCount(AtlasEdgeDirection.OUT, CUSTOM_RELATIONSHIP_EDGE_LABEL) + 1;
long currentSize = end1Vertex.getEdgesCount(AtlasEdgeDirection.OUT, UD_RELATIONSHIP_EDGE_LABEL) + 1;
validateCustomRelationshipCount(currentSize, end1Vertex);

currentSize = end2Vertex.getEdgesCount(AtlasEdgeDirection.IN, CUSTOM_RELATIONSHIP_EDGE_LABEL) + 1;
currentSize = end2Vertex.getEdgesCount(AtlasEdgeDirection.IN, UD_RELATIONSHIP_EDGE_LABEL) + 1;
validateCustomRelationshipCount(currentSize, end2Vertex);
}

private static void validateCustomRelationshipCount(long size, AtlasVertex vertex) throws AtlasBaseException {
if (CUSTOM_REL_THRESHOLD < size) {
if (UD_REL_THRESHOLD < size) {
throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED,
"Custom relationships size is more than " + CUSTOM_REL_THRESHOLD + ", current is " + size + " for " + vertex.getProperty(NAME, String.class));
"Custom relationships size is more than " + UD_REL_THRESHOLD + ", current is " + size + " for " + vertex.getProperty(NAME, String.class));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import static org.apache.atlas.repository.graph.GraphHelper.*;
import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.getIdFromVertex;
import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.isReference;
import static org.apache.atlas.repository.util.AtlasEntityUtils.mapOf;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN;
Expand Down Expand Up @@ -1660,10 +1661,13 @@ private AtlasObjectId mapVertexToObjectId(AtlasVertex entityVertex, String edgeL
}

if (RequestContext.get().isRequestRelationshipAttrsForSearch()) {
boolean isRelationshipAttribute = typeRegistry.getRelationshipDefByName(GraphHelper.getTypeName(edge)) != null;
String relationshipTypeName = GraphHelper.getTypeName(edge);
boolean isRelationshipAttribute = typeRegistry.getRelationshipDefByName(relationshipTypeName) != null;
if (isRelationshipAttribute) {
AtlasRelationship relationship = mapEdgeToAtlasRelationship(edge);
ret.getAttributes().put("relationshipAttributes", relationship.getAttributes());
Map<String, Object> relationshipAttributes = mapOf("typeName", relationshipTypeName);
relationshipAttributes.put("attributes", relationship.getAttributes());
ret.getAttributes().put("relationshipAttributes", relationshipAttributes);
}
}
}
Expand Down
Loading