Search in sources :

Example 51 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class DropDatabase method getEntities.

public List<AtlasObjectId> getEntities() throws Exception {
    List<AtlasObjectId> ret = new ArrayList<>();
    for (Entity entity : getHiveContext().getOutputs()) {
        if (entity.getType() == Entity.Type.DATABASE) {
            String dbQName = getQualifiedName(entity.getDatabase());
            AtlasObjectId dbId = new AtlasObjectId(HIVE_TYPE_DB, ATTRIBUTE_QUALIFIED_NAME, dbQName);
            context.removeFromKnownDatabase(dbQName);
            ret.add(dbId);
        } else if (entity.getType() == Entity.Type.TABLE) {
            String tblQName = getQualifiedName(entity.getTable());
            AtlasObjectId dbId = new AtlasObjectId(HIVE_TYPE_TABLE, ATTRIBUTE_QUALIFIED_NAME, tblQName);
            context.removeFromKnownTable(tblQName);
            ret.add(dbId);
        }
    }
    return ret;
}
Also used : Entity(org.apache.hadoop.hive.ql.hooks.Entity) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 52 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class DropTable method getEntities.

public List<AtlasObjectId> getEntities() throws Exception {
    List<AtlasObjectId> ret = new ArrayList<>();
    for (Entity entity : getHiveContext().getOutputs()) {
        if (entity.getType() == Entity.Type.TABLE) {
            String tblQName = getQualifiedName(entity.getTable());
            AtlasObjectId dbId = new AtlasObjectId(HIVE_TYPE_TABLE, ATTRIBUTE_QUALIFIED_NAME, tblQName);
            context.removeFromKnownTable(tblQName);
            ret.add(dbId);
        }
    }
    return ret;
}
Also used : Entity(org.apache.hadoop.hive.ql.hooks.Entity) ArrayList(java.util.ArrayList) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 53 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class HiveHookIT method testAlterTableLocation.

@Test
public void testAlterTableLocation() throws Exception {
    // Its an external table, so the HDFS location should also be registered as an entity
    String tableName = createTable(true, true, false);
    String testPath = createTestDFSPath("testBaseDir");
    String query = "alter table " + tableName + " set location '" + testPath + "'";
    runCommand(query);
    assertTableIsRegistered(DEFAULT_DB, tableName, new AssertPredicate() {

        @Override
        public void assertOnEntity(AtlasEntity tableRef) throws Exception {
            AtlasObjectId sd = toAtlasObjectId(tableRef.getAttribute(ATTRIBUTE_STORAGEDESC));
            assertNotNull(sd);
        }
    });
    String processQualifiedName = getTableProcessQualifiedName(DEFAULT_DB, tableName);
    String processId = assertEntityIsRegistered(HiveDataTypes.HIVE_PROCESS.getName(), ATTRIBUTE_QUALIFIED_NAME, processQualifiedName, null);
    AtlasEntity processEntity = atlasClientV2.getEntityByGuid(processId).getEntity();
    validateHDFSPaths(processEntity, INPUTS, testPath);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) ParseException(java.text.ParseException) AtlasServiceException(org.apache.atlas.AtlasServiceException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) Test(org.testng.annotations.Test)

Example 54 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AlterTableRename method removeAttribute.

private void removeAttribute(AtlasEntityWithExtInfo entity, String attributeName) {
    Object attributeValue = entity.getEntity().getAttribute(attributeName);
    entity.getEntity().getAttributes().remove(attributeName);
    if (attributeValue instanceof AtlasObjectId) {
        AtlasObjectId objectId = (AtlasObjectId) attributeValue;
        entity.removeReferredEntity(objectId.getGuid());
    } else if (attributeValue instanceof Collection) {
        for (Object item : (Collection) attributeValue) if (item instanceof AtlasObjectId) {
            AtlasObjectId objectId = (AtlasObjectId) item;
            entity.removeReferredEntity(objectId.getGuid());
        }
    }
}
Also used : Collection(java.util.Collection) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Example 55 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class SqoopHook method toSqoopProcessEntity.

private AtlasEntity toSqoopProcessEntity(AtlasEntity entDbStore, AtlasEntity entHiveDb, AtlasEntity entHiveTable, SqoopJobDataPublisher.Data data, String metadataNamespace) {
    AtlasEntity entProcess = new AtlasEntity(SqoopDataTypes.SQOOP_PROCESS.getName());
    String sqoopProcessName = getSqoopProcessName(data, metadataNamespace);
    Map<String, String> sqoopOptionsMap = new HashMap<>();
    Properties options = data.getOptions();
    for (Object k : options.keySet()) {
        sqoopOptionsMap.put((String) k, (String) options.get(k));
    }
    entProcess.setAttribute(AtlasClient.NAME, sqoopProcessName);
    entProcess.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, sqoopProcessName);
    entProcess.setAttribute(SqoopHook.OPERATION, data.getOperation());
    List<AtlasObjectId> sqoopObjects = Collections.singletonList(AtlasTypeUtil.getAtlasObjectId(entDbStore));
    List<AtlasObjectId> hiveObjects = Collections.singletonList(AtlasTypeUtil.getAtlasObjectId(entHiveTable != null ? entHiveTable : entHiveDb));
    if (isImportOperation(data)) {
        entProcess.setRelationshipAttribute(SqoopHook.INPUTS, AtlasTypeUtil.getAtlasRelatedObjectIdList(sqoopObjects, RELATIONSHIP_DATASET_PROCESS_INPUTS));
        entProcess.setRelationshipAttribute(SqoopHook.OUTPUTS, AtlasTypeUtil.getAtlasRelatedObjectIdList(hiveObjects, RELATIONSHIP_PROCESS_DATASET_OUTPUTS));
    } else {
        entProcess.setRelationshipAttribute(SqoopHook.INPUTS, AtlasTypeUtil.getAtlasRelatedObjectIdList(hiveObjects, RELATIONSHIP_DATASET_PROCESS_INPUTS));
        entProcess.setRelationshipAttribute(SqoopHook.OUTPUTS, AtlasTypeUtil.getAtlasRelatedObjectIdList(sqoopObjects, RELATIONSHIP_PROCESS_DATASET_OUTPUTS));
    }
    entProcess.setAttribute(SqoopHook.USER, data.getUser());
    entProcess.setAttribute(SqoopHook.START_TIME, new Date(data.getStartTime()));
    entProcess.setAttribute(SqoopHook.END_TIME, new Date(data.getEndTime()));
    entProcess.setAttribute(SqoopHook.CMD_LINE_OPTS, sqoopOptionsMap);
    return entProcess;
}
Also used : HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Properties(java.util.Properties) ApplicationProperties(org.apache.atlas.ApplicationProperties) Date(java.util.Date)

Aggregations

AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)255 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)70 ArrayList (java.util.ArrayList)69 Map (java.util.Map)47 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)44 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)41 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)41 HashMap (java.util.HashMap)40 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)38 List (java.util.List)36 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)33 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)32 BeforeTest (org.testng.annotations.BeforeTest)32 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)29 AtlasTypeUtil.getAtlasObjectId (org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId)24 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)22 AtlasExportRequest (org.apache.atlas.model.impexp.AtlasExportRequest)14 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)13 AtlasType (org.apache.atlas.type.AtlasType)11