Java Code Examples for org.apache.atlas.exception.AtlasBaseException#getAtlasErrorCode()

The following examples show how to use org.apache.atlas.exception.AtlasBaseException#getAtlasErrorCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInValidInverseRef_NonExistingAttribute() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING,
                 "expected invalid constraint failure - non-existing refAttribute");
}
 
Example 2
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInValidInverseRef_NonExistingAttribute() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING,
                 "expected invalid constraint failure - non-existing refAttribute");
}
 
Example 3
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInvalidOwnedRef_InvalidAttributeType() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDefWithOwnedRefOnInvalidType());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_OWNED_REF_ATTRIBUTE_INVALID_TYPE,
            "expected invalid constraint failure - missing refAttribute");
}
 
Example 4
Source File: DefaultTypeSystem.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void createTraitType(AtlasClassificationDef classificationDef) throws AtlasBaseException {
    try {
        typeDefStore.getClassificationDefByName(classificationDef.getName());
    } catch (AtlasBaseException tne) {
        //Type not found . Create
        if (tne.getAtlasErrorCode() == AtlasErrorCode.TYPE_NAME_NOT_FOUND) {
            AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(),
                ImmutableList.of(classificationDef),
                ImmutableList.<AtlasEntityDef>of());

            typeDefStore.createTypesDef(typesDef);
        } else {
            throw tne;
        }
    }
}
 
Example 5
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInValidInverseRef_InvalidAttributeType() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithInvalidInverseAttributeType());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_INVALID_TYPE,
            "expected invalid constraint failure - invalid refAttribute type");
}
 
Example 6
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE,
            "expected invalid constraint failure - missing refAttribute");
}
 
Example 7
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInValidInverseRef_InvalidAttributeType() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithInvalidInverseAttributeType());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_INVALID_TYPE,
            "expected invalid constraint failure - invalid refAttribute type");
}
 
Example 8
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstraintInvalidOwnedRef_InvalidAttributeType() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    AtlasErrorCode             errorCode   = null;

    entityDefs.add(createTableEntityDefWithOwnedRefOnInvalidType());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        commit = true;
    } catch (AtlasBaseException excp) {
        errorCode = excp.getAtlasErrorCode();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_OWNED_REF_ATTRIBUTE_INVALID_TYPE,
            "expected invalid constraint failure - missing refAttribute");
}
 
Example 9
Source File: EntityGraphRetriever.java    From atlas with Apache License 2.0 6 votes vote down vote up
public AtlasEntitiesWithExtInfo getEntitiesByUniqueAttributes(String typeName, List<Map<String, Object>> uniqueAttributesList, boolean isMinExtInfo) throws AtlasBaseException {
    AtlasEntitiesWithExtInfo ret        = new AtlasEntitiesWithExtInfo();
    AtlasEntityType          entityType = typeRegistry.getEntityTypeByName(typeName);

    if (entityType != null) {
        for (Map<String, Object> uniqAttributes : uniqueAttributesList) {
            try {
                AtlasVertex vertex = AtlasGraphUtilsV2.getVertexByUniqueAttributes(this.graph, entityType, uniqAttributes);

                if (vertex != null) {
                    AtlasEntity entity = mapVertexToAtlasEntity(vertex, ret, isMinExtInfo);

                    ret.addEntity(entity);
                }
            } catch(AtlasBaseException e) {
                if (e.getAtlasErrorCode() != AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) {
                    throw e;
                }
            }
        }
    }

    ret.compact();

    return ret;
}
 
Example 10
Source File: AtlasBaseExceptionMapper.java    From atlas with Apache License 2.0 6 votes vote down vote up
protected Response buildAtlasBaseExceptionResponse(AtlasBaseException baseException) {
    Map<String, String> errorJsonMap = new LinkedHashMap<>();
    AtlasErrorCode errorCode = baseException.getAtlasErrorCode();
    errorJsonMap.put("errorCode", errorCode.getErrorCode());
    errorJsonMap.put("errorMessage", baseException.getMessage());

    if (baseException.getCause() != null) {
        errorJsonMap.put("errorCause", baseException.getCause().getMessage());
    }

    Response.ResponseBuilder responseBuilder = Response.status(errorCode.getHttpCode());

    // No body for 204 (and maybe 304)
    if (Response.Status.NO_CONTENT != errorCode.getHttpCode()) {
        responseBuilder.entity(AtlasType.toJson(errorJsonMap));
    }
    return responseBuilder.build();
}
 
Example 11
Source File: AtlasTypeDefGraphStore.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void tryTypeCreation(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    // Translate any NOT FOUND errors to BAD REQUEST
    try {
        ttr.addTypes(typesDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode() ||
                AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 12
Source File: EntityResource.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static WebApplicationException toWebApplicationException(AtlasBaseException e) {
    if (e.getAtlasErrorCode() == AtlasErrorCode.CLASSIFICATION_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    }

    if (e.getAtlasErrorCode() == AtlasErrorCode.INVALID_PARAMETERS
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    }

    return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
}
 
Example 13
Source File: EntityResource.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static WebApplicationException toWebApplicationException(AtlasBaseException e) {
    if (e.getAtlasErrorCode() == AtlasErrorCode.CLASSIFICATION_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_GUID_NOT_FOUND
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    }

    if (e.getAtlasErrorCode() == AtlasErrorCode.INVALID_PARAMETERS
        || e.getAtlasErrorCode() == AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS) {
        return new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    }

    return new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
}
 
Example 14
Source File: AtlasBaseExceptionMapper.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected Response buildAtlasBaseExceptionResponse(AtlasBaseException baseException) {
    Map<String, String> errorJsonMap = new LinkedHashMap<>();
    AtlasErrorCode errorCode = baseException.getAtlasErrorCode();
    errorJsonMap.put("errorCode", errorCode.getErrorCode());
    errorJsonMap.put("errorMessage", baseException.getMessage());
    Response.ResponseBuilder responseBuilder = Response.status(errorCode.getHttpCode());

    // No body for 204 (and maybe 304)
    if (Response.Status.NO_CONTENT != errorCode.getHttpCode()) {
        responseBuilder.entity(AtlasType.toJson(errorJsonMap));
    }
    return responseBuilder.build();
}
 
Example 15
Source File: AtlasTypeDefGraphStore.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void tryUpdateByGUID(String guid, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    try {
        ttr.updateTypeByGuid(guid, typeDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 16
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships{})",
                CollectionUtils.size(typesDef.getEnumDefs()),
                CollectionUtils.size(typesDef.getStructDefs()),
                CollectionUtils.size(typesDef.getClassificationDefs()),
                CollectionUtils.size(typesDef.getEntityDefs()),
                CollectionUtils.size(typesDef.getRelationshipDefs()));
    }

    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();

    // Translate any NOT FOUND errors to BAD REQUEST
    try {
        ttr.updateTypes(typesDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }

    AtlasTypesDef ret = updateGraphStore(typesDef, ttr);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})",
                CollectionUtils.size(typesDef.getEnumDefs()),
                CollectionUtils.size(typesDef.getStructDefs()),
                CollectionUtils.size(typesDef.getClassificationDefs()),
                CollectionUtils.size(typesDef.getEntityDefs()),
                CollectionUtils.size(typesDef.getRelationshipDefs()));
    }

    return ret;

}
 
Example 17
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void tryUpdateByName(String name, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    try {
        ttr.updateTypeByName(name, typeDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 18
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void tryUpdateByGUID(String guid, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    try {
        ttr.updateTypeByGuid(guid, typeDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 19
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void tryTypeCreation(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    // Translate any NOT FOUND errors to BAD REQUEST
    try {
        ttr.addTypes(typesDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode() ||
                AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 20
Source File: AtlasTypeDefGraphStore.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void tryUpdateByName(String name, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    try {
        ttr.updateTypeByName(name, typeDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}