Search in sources :

Example 26 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method updateByGuid.

@Override
public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid);
    }
    AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-Def ", (existingDef != null ? existingDef.getName() : guid));
    validateType(relationshipDef);
    AtlasType type = typeRegistry.getTypeByGuid(guid);
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
    // updates should not effect the edges between the types as we do not allow updates that change the endpoints.
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasType(org.apache.atlas.type.AtlasType)

Example 27 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipStoreV1 method validateEnds.

/**
 * Validate the ends of the passed relationship
 * @param relationship
 * @throws AtlasBaseException
 */
private void validateEnds(AtlasRelationship relationship) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("validateEnds entry relationship:" + relationship);
    }
    List<AtlasObjectId> ends = new ArrayList<>();
    List<AtlasRelationshipEndDef> endDefs = new ArrayList<>();
    String relationshipTypeName = relationship.getTypeName();
    AtlasRelationshipDef relationshipDef = typeRegistry.getRelationshipDefByName(relationshipTypeName);
    ends.add(relationship.getEnd1());
    ends.add(relationship.getEnd2());
    endDefs.add(relationshipDef.getEndDef1());
    endDefs.add(relationshipDef.getEndDef2());
    for (int i = 0; i < ends.size(); i++) {
        AtlasObjectId end = ends.get(i);
        String guid = end.getGuid();
        String typeName = end.getTypeName();
        Map<String, Object> uniqueAttributes = end.getUniqueAttributes();
        AtlasVertex endVertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (!AtlasTypeUtil.isValidGuid(guid) || endVertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        } else if (MapUtils.isNotEmpty(uniqueAttributes)) {
            AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
            if (AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqueAttributes) == null) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, uniqueAttributes.toString());
            }
        } else {
            // check whether the guid is the correct type
            String vertexTypeName = endVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);
            if (!Objects.equals(vertexTypeName, typeName)) {
                String attrName = endDefs.get(i).getName();
                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_INVALID_ENDTYPE, attrName, guid, vertexTypeName, typeName);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("validateEnds exit successfully validated relationship:" + relationship);
    }
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 28 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipDefStoreV1Test method updateValidProperties.

@DataProvider
public Object[][] updateValidProperties() {
    AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "0", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.ONE_TO_TWO, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef newType = AtlasTypeUtil.createRelationshipTypeDef("basicType", // updated
    "description1", // updated
    "1", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, // updated
    AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    return new Object[][] { { existingType, newType } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

Example 29 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipDefStoreV1Test method updateRelCat.

@DataProvider
public Object[][] updateRelCat() {
    AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef newType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.AGGREGATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    return new Object[][] { { existingType, newType } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

Example 30 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipDefStoreV1Test method updateEnd1.

@DataProvider
public Object[][] updateEnd1() {
    AtlasRelationshipDef existingType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef changeType = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeE", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef changeAttr = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr2", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    AtlasRelationshipDef changeCardinality = AtlasTypeUtil.createRelationshipTypeDef("basicType", "description", "", AtlasRelationshipDef.RelationshipCategory.ASSOCIATION, AtlasRelationshipDef.PropagateTags.BOTH, new AtlasRelationshipEndDef("typeC", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.LIST), new AtlasRelationshipEndDef("typeD", "attr1", AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE), AtlasTypeUtil.createRequiredAttrDef("aaaa", "string"), AtlasTypeUtil.createRequiredAttrDef("bbbb", "string"));
    return new Object[][] { { existingType, changeType }, { existingType, changeAttr }, { existingType, changeCardinality } };
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) DataProvider(org.testng.annotations.DataProvider)

Aggregations

AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)46 AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)25 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)13 DataProvider (org.testng.annotations.DataProvider)10 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)5 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 AtlasType (org.apache.atlas.type.AtlasType)4 Test (org.testng.annotations.Test)4 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)3 AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 PropagateTags (org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags)2 RelationshipCategory (org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 ArrayList (java.util.ArrayList)1