Search in sources :

Example 86 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class EntityProcessor method processNode.

@Override
public void processNode(ObjectGraphWalker.Node nd) throws AtlasException {
    IReferenceableInstance ref = null;
    Id id = null;
    if (nd.attributeName == null) {
        ref = (IReferenceableInstance) nd.instance;
        id = ref.getId();
    } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
        if (nd.value != null && (nd.value instanceof Id)) {
            id = (Id) nd.value;
        }
    }
    if (id != null) {
        if (id.isUnassigned()) {
            if (ref != null) {
                if (idToInstanceMap.containsKey(id)) {
                    // Oops
                    throw new RepositoryException(String.format("Unexpected internal error: Id %s processed again", id));
                }
                idToInstanceMap.put(id, ref);
            }
        }
    }
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) RepositoryException(org.apache.atlas.repository.RepositoryException) Id(org.apache.atlas.typesystem.persistence.Id)

Example 87 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class AtlasEntityFormatConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext context) throws AtlasBaseException {
    Object ret = null;
    if (v2Obj != null) {
        AtlasEntityType entityType = (AtlasEntityType) type;
        if (v2Obj instanceof Map) {
            Map v2Map = (Map) v2Obj;
            String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
            String typeName = type.getTypeName();
            if (StringUtils.isEmpty(idStr)) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
            }
            final Map v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isEmpty(v2Attribs)) {
                ret = new Id(idStr, 0, typeName);
            } else {
                ret = new Referenceable(idStr, typeName, super.fromV2ToV1(entityType, v2Attribs, context));
            }
        } else if (v2Obj instanceof AtlasEntity) {
            AtlasEntity entity = (AtlasEntity) v2Obj;
            ret = new Referenceable(entity.getGuid(), entity.getTypeName(), fromV2ToV1(entityType, entity.getAttributes(), context));
        } else if (v2Obj instanceof AtlasObjectId) {
            // transient-id
            AtlasEntity entity = context.getById(((AtlasObjectId) v2Obj).getGuid());
            if (entity == null) {
                throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Could not find entity ", v2Obj.toString());
            }
            ret = this.fromV2ToV1(entity, typeRegistry.getType(((AtlasObjectId) v2Obj).getTypeName()), context);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or AtlasEntity or String", v2Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.typesystem.Referenceable) 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.typesystem.persistence.Id) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Map(java.util.Map)

Example 88 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class HiveMetastoreBridgeIT method testCreateTableAndImport.

@Test
public void testCreateTableAndImport() throws Exception {
    String tableName = tableName();
    String pFile = createTestDFSPath("parentPath");
    final String query = String.format("create EXTERNAL table %s(id string, cnt int) location '%s'", tableName, pFile);
    runCommand(query);
    String dbId = assertDatabaseIsRegistered(DEFAULT_DB);
    String tableId = assertTableIsRegistered(DEFAULT_DB, tableName);
    //verify lineage is created
    String processId = assertEntityIsRegistered(HiveDataTypes.HIVE_PROCESS.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, getTableProcessQualifiedName(DEFAULT_DB, tableName), null);
    Referenceable processReference = atlasClient.getEntity(processId);
    validateHDFSPaths(processReference, INPUTS, pFile);
    List<Id> outputs = (List<Id>) processReference.get(OUTPUTS);
    assertEquals(outputs.size(), 1);
    assertEquals(outputs.get(0).getId()._getId(), tableId);
    int tableCount = atlasClient.listEntities(HiveDataTypes.HIVE_TABLE.getName()).size();
    //Now import using import tool - should be no-op. This also tests update since table exists
    hiveMetaStoreBridge.importTable(atlasClient.getEntity(dbId), DEFAULT_DB, tableName, true);
    String tableId2 = assertTableIsRegistered(DEFAULT_DB, tableName);
    assertEquals(tableId2, tableId);
    String processId2 = assertEntityIsRegistered(HiveDataTypes.HIVE_PROCESS.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, getTableProcessQualifiedName(DEFAULT_DB, tableName), null);
    assertEquals(processId2, processId);
    //assert that table is de-duped and no new entity is created
    int newTableCount = atlasClient.listEntities(HiveDataTypes.HIVE_TABLE.getName()).size();
    assertEquals(newTableCount, tableCount);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) List(java.util.List) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 89 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class HiveHookIT method validateTables.

private void validateTables(Referenceable processReference, String attrName, Set<? extends Entity> expectedTables) throws Exception {
    List<Id> tableRef = (List<Id>) processReference.get(attrName);
    Iterator<? extends Entity> iterator = expectedTables.iterator();
    for (int i = 0; i < expectedTables.size(); i++) {
        Entity hiveEntity = iterator.next();
        if (Entity.Type.TABLE.equals(hiveEntity.getType()) || Entity.Type.DFS_DIR.equals(hiveEntity.getType())) {
            Referenceable entity = atlasClient.getEntity(tableRef.get(i)._getId());
            LOG.debug("Validating output {} {} ", i, entity);
            Assert.assertEquals(entity.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), hiveEntity.getName());
        }
    }
}
Also used : ReadEntity(org.apache.hadoop.hive.ql.hooks.ReadEntity) Entity(org.apache.hadoop.hive.ql.hooks.Entity) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) Referenceable(org.apache.atlas.typesystem.Referenceable) ImmutableList(com.google.common.collect.ImmutableList) Id(org.apache.atlas.typesystem.persistence.Id)

Example 90 with Id

use of org.apache.atlas.typesystem.persistence.Id in project incubator-atlas by apache.

the class DiscoverInstances method processNode.

@Override
public void processNode(ObjectGraphWalker.Node nd) throws AtlasException {
    IReferenceableInstance ref = null;
    Id id = null;
    if (nd.attributeName == null) {
        ref = (IReferenceableInstance) nd.instance;
        id = ref.getId();
    } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
        if (nd.value != null && (nd.value instanceof Id)) {
            id = (Id) nd.value;
        }
    }
    if (id != null) {
        if (id.isUnassigned()) {
            if (!idToNewIdMap.containsKey(id)) {
                idToNewIdMap.put(id, repository.newId(id.typeName));
            }
            if (ref != null && idToInstanceMap.containsKey(ref)) {
                // Oops
                throw new RepositoryException(String.format("Unexpected internal error: Id %s processed again", id));
            }
            if (ref != null) {
                idToInstanceMap.put(id, ref);
            }
        }
    }
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id)

Aggregations

Id (org.apache.atlas.typesystem.persistence.Id)94 Referenceable (org.apache.atlas.typesystem.Referenceable)50 Test (org.testng.annotations.Test)37 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)28 List (java.util.List)17 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)12 ImmutableList (com.google.common.collect.ImmutableList)10 TraitType (org.apache.atlas.typesystem.types.TraitType)10 JSONObject (org.codehaus.jettison.json.JSONObject)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)7 Struct (org.apache.atlas.typesystem.Struct)7 ClassType (org.apache.atlas.typesystem.types.ClassType)7 AtlasException (org.apache.atlas.AtlasException)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)5