Search in sources :

Example 41 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException 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;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 42 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method updateVertexPreCreate.

private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException {
    AtlasRelationshipEndDef end1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef end2 = relationshipDef.getEndDef2();
    // check whether the names added on the relationship Ends are reserved if required.
    final boolean allowReservedKeywords;
    try {
        allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true);
    } catch (AtlasException e) {
        throw new AtlasBaseException(e);
    }
    if (!allowReservedKeywords) {
        if (AtlasDSL.Parser.isKeyword(end1.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END1_NAME_INVALID, end1.getName());
        }
        if (AtlasDSL.Parser.isKeyword(end2.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END2_NAME_INVALID, end2.getName());
        }
    }
    AtlasStructDefStoreV1.updateVertexPreCreate(relationshipDef, relationshipType, vertex, typeDefStore);
    // Update ends
    setVertexPropertiesFromRelationshipDef(relationshipDef, vertex);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasException(org.apache.atlas.AtlasException) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 43 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method preUpdateCheck.

/**
 * Check ends are the same and relationshipCategory is the same.
 *
 * We do this by comparing 2 relationshipDefs to avoid exposing the AtlasVertex to unit testing.
 *
 * @param newRelationshipDef
 * @param existingRelationshipDef
 * @throws AtlasBaseException
 */
public static void preUpdateCheck(AtlasRelationshipDef newRelationshipDef, AtlasRelationshipDef existingRelationshipDef) throws AtlasBaseException {
    // do not allow renames of the Def.
    String existingName = existingRelationshipDef.getName();
    String newName = newRelationshipDef.getName();
    if (!existingName.equals(newName)) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_NAME_UPDATE, newRelationshipDef.getGuid(), existingName, newName);
    }
    RelationshipCategory existingRelationshipCategory = existingRelationshipDef.getRelationshipCategory();
    RelationshipCategory newRelationshipCategory = newRelationshipDef.getRelationshipCategory();
    if (!existingRelationshipCategory.equals(newRelationshipCategory)) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_CATEGORY_UPDATE, newRelationshipDef.getName(), newRelationshipCategory.name(), existingRelationshipCategory.name());
    }
    AtlasRelationshipEndDef existingEnd1 = existingRelationshipDef.getEndDef1();
    AtlasRelationshipEndDef newEnd1 = newRelationshipDef.getEndDef1();
    if (!newEnd1.equals(existingEnd1)) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END1_UPDATE, newRelationshipDef.getName(), newEnd1.toString(), existingEnd1.toString());
    }
    AtlasRelationshipEndDef existingEnd2 = existingRelationshipDef.getEndDef2();
    AtlasRelationshipEndDef newEnd2 = newRelationshipDef.getEndDef2();
    if (!newEnd2.equals(existingEnd2)) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID_END2_UPDATE, newRelationshipDef.getName(), newEnd2.toString(), existingEnd2.toString());
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) RelationshipCategory(org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)

Example 44 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method getByName.

@Override
public AtlasRelationshipDef getByName(String name) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.getByName({})", name);
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class);
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.getByName({}): {}", name, 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)

Example 45 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasTypeDefGraphStoreTest method testSearchFunctionality.

@Test(dependsOnMethods = "testGet")
public void testSearchFunctionality() {
    SearchFilter searchFilter = new SearchFilter();
    searchFilter.setParam(SearchFilter.PARAM_SUPERTYPE, "Person");
    try {
        AtlasTypesDef typesDef = typeDefStore.searchTypesDef(searchFilter);
        assertNotNull(typesDef);
        assertNotNull(typesDef.getEntityDefs());
        assertEquals(typesDef.getEntityDefs().size(), 3);
    } catch (AtlasBaseException e) {
        fail("Search should've succeeded", e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) SearchFilter(org.apache.atlas.model.SearchFilter) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 Test (org.testng.annotations.Test)60 ArrayList (java.util.ArrayList)59 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24