Search in sources :

Example 56 with AtlasBaseException

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

the class BasicTestSetup method loadEmployeeDataset.

protected void loadEmployeeDataset() {
    if (!baseLoaded) {
        loadBaseModels();
    }
    // Define employee dataset types
    AtlasTypesDef employeeTypes = TestUtilsV2.defineDeptEmployeeTypes();
    try {
        typeDefStore.createTypesDef(employeeTypes);
    } catch (AtlasBaseException e) {
        fail("Employee Type setup is required");
    }
    // Define entities for department
    AtlasEntity.AtlasEntitiesWithExtInfo deptEg2 = TestUtilsV2.createDeptEg2();
    try {
        entityStore.createOrUpdate(new AtlasEntityStream(deptEg2), false);
    } catch (AtlasBaseException e) {
        fail("Employee entity setup should've passed");
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream)

Example 57 with AtlasBaseException

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

the class DSLQueriesTest method pollForData.

private void pollForData() throws InterruptedException {
    Object[][] basicVerificationQueries = new Object[][] { { "hive_db", 3 }, { "hive_process", 7 }, { "hive_table", 10 }, { "hive_column", 17 }, { "hive_storagedesc", 1 }, { "Manager", 2 }, { "Employee", 4 } };
    int pollingAttempts = 5;
    // in msecs
    int pollingBackoff = 0;
    boolean success;
    for (int attempt = 0; attempt < pollingAttempts; attempt++, pollingBackoff += attempt * 5000) {
        LOG.debug("Polling -- Attempt {}, Backoff {}", attempt, pollingBackoff);
        success = false;
        for (Object[] verificationQuery : basicVerificationQueries) {
            String query = (String) verificationQuery[0];
            int expected = (int) verificationQuery[1];
            try {
                AtlasSearchResult result = discoveryService.searchUsingDslQuery(query, 25, 0);
                if (result.getEntities() == null || result.getEntities().isEmpty()) {
                    LOG.warn("DSL {} returned no entities", query);
                    success = false;
                } else if (result.getEntities().size() != expected) {
                    LOG.warn("DSL {} returned unexpected number of entities. Expected {} Actual {}", query, expected, result.getEntities().size());
                    success = false;
                } else {
                    success = true;
                }
            } catch (AtlasBaseException e) {
                LOG.error("Got exception for DSL {}, errorCode: {}", query, e.getAtlasErrorCode());
                waitOrBailout(pollingAttempts, pollingBackoff, attempt);
            }
        }
        // DSL queries were successful
        if (success) {
            LOG.info("Polling was success");
            break;
        } else {
            waitOrBailout(pollingAttempts, pollingBackoff, attempt);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult)

Example 58 with AtlasBaseException

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

the class AtlasArrayFormatConverter method isValidValueV1.

@Override
public boolean isValidValueV1(Object v1Obj, AtlasType type) {
    boolean ret = false;
    if (v1Obj == null) {
        return true;
    }
    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrType = (AtlasArrayType) type;
        AtlasType elemType = arrType.getElementType();
        AtlasFormatConverter elemConverter = null;
        try {
            elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
        } catch (AtlasBaseException excp) {
            LOG.warn("failed to get element converter. type={}", type.getTypeName(), excp);
            ret = false;
        }
        if (elemConverter != null) {
            if (v1Obj instanceof Collection) {
                // for empty array
                ret = true;
                for (Object v1Elem : (Collection) v1Obj) {
                    ret = elemConverter.isValidValueV1(v1Elem, elemType);
                    if (!ret) {
                        break;
                    }
                }
            } else {
                ret = elemConverter.isValidValueV1(v1Obj, elemType);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("AtlasArrayFormatConverter.isValidValueV1(type={}, value={}): {}", (v1Obj != null ? v1Obj.getClass().getCanonicalName() : null), v1Obj, ret);
    }
    return ret;
}
Also used : AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType) Collection(java.util.Collection)

Example 59 with AtlasBaseException

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

the class AtlasInstanceConverter method toAtlasEntities.

public AtlasEntitiesWithExtInfo toAtlasEntities(String[] jsonEntities) throws AtlasBaseException, AtlasException {
    Referenceable[] referenceables = new Referenceable[jsonEntities.length];
    for (int i = 0; i < jsonEntities.length; i++) {
        referenceables[i] = AtlasType.fromV1Json(jsonEntities[i], Referenceable.class);
    }
    AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
    ConverterContext context = new ConverterContext();
    for (Referenceable referenceable : referenceables) {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());
        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName());
        }
        AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, context);
        context.addEntity(entity);
    }
    AtlasEntitiesWithExtInfo ret = context.getEntities();
    return ret;
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 60 with AtlasBaseException

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

the class AtlasObjectIdConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    Id ret = null;
    if (v2Obj != null) {
        if (v2Obj instanceof Map) {
            Map v2Map = (Map) v2Obj;
            String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
            String typeName = (String) v2Map.get(AtlasObjectId.KEY_TYPENAME);
            if (StringUtils.isEmpty(idStr)) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
            }
            ret = new Id(idStr, 0, typeName);
        } else if (v2Obj instanceof AtlasObjectId) {
            // transient-id
            AtlasObjectId objId = (AtlasObjectId) v2Obj;
            ret = new Id(objId.getGuid(), 0, objId.getTypeName());
        } else if (v2Obj instanceof AtlasEntity) {
            AtlasEntity entity = (AtlasEntity) v2Obj;
            ret = new Id(entity.getGuid(), entity.getVersion() == null ? 0 : entity.getVersion().intValue(), entity.getTypeName());
        } else {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, type.getTypeCategory().name());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.v1.model.instance.Id) Map(java.util.Map)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 ArrayList (java.util.ArrayList)60 Test (org.testng.annotations.Test)60 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