Search in sources :

Example 16 with Referenceable

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

the class HiveHookIT method validateProcess.

private Referenceable validateProcess(HiveHook.HiveEventContext event, Set<ReadEntity> inputTables, Set<WriteEntity> outputTables) throws Exception {
    String processId = assertProcessIsRegistered(event, inputTables, outputTables);
    Referenceable process = atlasClient.getEntity(processId);
    if (inputTables == null) {
        Assert.assertNull(process.get(INPUTS));
    } else {
        Assert.assertEquals(((List<Referenceable>) process.get(INPUTS)).size(), inputTables.size());
        validateInputTables(process, inputTables);
    }
    if (outputTables == null) {
        Assert.assertNull(process.get(OUTPUTS));
    } else {
        Assert.assertEquals(((List<Id>) process.get(OUTPUTS)).size(), outputTables.size());
        validateOutputTables(process, outputTables);
    }
    return process;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id)

Example 17 with Referenceable

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

the class GraphHelperTest method testGetInstancesByUniqueAttributes.

@Test
public void testGetInstancesByUniqueAttributes() throws Exception {
    GraphHelper helper = GraphHelper.getInstance();
    List<ITypedReferenceableInstance> instances = new ArrayList<>();
    List<String> guids = new ArrayList<>();
    TypeSystem ts = TypeSystem.getInstance();
    ClassType dbType = ts.getDataType(ClassType.class, TestUtils.DATABASE_TYPE);
    for (int i = 0; i < 10; i++) {
        Referenceable db = TestUtils.createDBEntity();
        String guid = createInstance(db);
        ITypedReferenceableInstance instance = convert(db, dbType);
        instances.add(instance);
        guids.add(guid);
    }
    //lookup vertices via getVertexForInstanceByUniqueAttributes
    List<AtlasVertex> vertices = helper.getVerticesForInstancesByUniqueAttribute(dbType, instances);
    assertEquals(instances.size(), vertices.size());
    //assert vertex matches the vertex we get through getVertexForGUID
    for (int i = 0; i < instances.size(); i++) {
        String guid = guids.get(i);
        AtlasVertex foundVertex = vertices.get(i);
        AtlasVertex expectedVertex = helper.getVertexForGUID(guid);
        assertEquals(foundVertex, expectedVertex);
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 18 with Referenceable

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

the class GraphRepoMapperScaleTest method testSubmitEntity.

@Test
public void testSubmitEntity() throws Exception {
    Referenceable databaseInstance = new Referenceable(TestUtils.DATABASE_TYPE);
    databaseInstance.set("name", DATABASE_NAME);
    databaseInstance.set("description", "foo database");
    // System.out.println("databaseInstance = " + databaseInstance);
    ClassType dbType = typeSystem.getDataType(ClassType.class, TestUtils.DATABASE_TYPE);
    ITypedReferenceableInstance db = dbType.convert(databaseInstance, Multiplicity.REQUIRED);
    dbGUID = result(db).getCreatedEntities().get(0);
    Referenceable dbInstance = new Referenceable(dbGUID, TestUtils.DATABASE_TYPE, databaseInstance.getValuesMap());
    for (int index = 0; index < 1000; index++) {
        ITypedReferenceableInstance table = createHiveTableInstance(dbInstance, index);
        result(table);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 19 with Referenceable

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

the class EntityNotificationIT method testDeleteEntity.

@Test
public void testDeleteEntity() throws Exception {
    final String tableName = "table-" + randomString();
    final String dbName = "db-" + randomString();
    Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(HiveDBInstance);
    Referenceable tableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    final Id tableId = createInstance(tableInstance);
    final String guid = tableId._getId();
    waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(EntityNotification.OperationType.ENTITY_CREATE, HIVE_TABLE_TYPE_BUILTIN, guid));
    final String name = (String) tableInstance.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME);
    atlasClientV1.deleteEntity(HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
    waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(EntityNotification.OperationType.ENTITY_DELETE, HIVE_TABLE_TYPE_BUILTIN, guid));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 20 with Referenceable

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

the class NotificationEntityChangeListenerTest method testGetAllTraitsSuperTraits.

@Test
public void testGetAllTraitsSuperTraits() throws Exception {
    TypeSystem typeSystem = mock(TypeSystem.class);
    String traitName = "MyTrait";
    IStruct myTrait = new Struct(traitName);
    String superTraitName = "MySuperTrait";
    TraitType traitDef = mock(TraitType.class);
    Set<String> superTypeNames = Collections.singleton(superTraitName);
    TraitType superTraitDef = mock(TraitType.class);
    Set<String> superSuperTypeNames = Collections.emptySet();
    Referenceable entity = getEntity("id", myTrait);
    when(typeSystem.getDataType(TraitType.class, traitName)).thenReturn(traitDef);
    when(typeSystem.getDataType(TraitType.class, superTraitName)).thenReturn(superTraitDef);
    when(traitDef.getAllSuperTypeNames()).thenReturn(superTypeNames);
    when(superTraitDef.getAllSuperTypeNames()).thenReturn(superSuperTypeNames);
    List<IStruct> allTraits = NotificationEntityChangeListener.getAllTraits(entity, typeSystem);
    assertEquals(2, allTraits.size());
    for (IStruct trait : allTraits) {
        String typeName = trait.getTypeName();
        assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) Referenceable(org.apache.atlas.typesystem.Referenceable) TraitType(org.apache.atlas.typesystem.types.TraitType) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.typesystem.Referenceable)235 Test (org.testng.annotations.Test)114 Id (org.apache.atlas.typesystem.persistence.Id)50 ArrayList (java.util.ArrayList)45 List (java.util.List)25 Struct (org.apache.atlas.typesystem.Struct)25 HashMap (java.util.HashMap)24 BeforeTest (org.testng.annotations.BeforeTest)24 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)22 AfterTest (org.testng.annotations.AfterTest)22 HookNotification (org.apache.atlas.notification.hook.HookNotification)20 IStruct (org.apache.atlas.typesystem.IStruct)18 ClassType (org.apache.atlas.typesystem.types.ClassType)16 JSONObject (org.codehaus.jettison.json.JSONObject)16 ImmutableList (com.google.common.collect.ImmutableList)15 AtlasServiceException (org.apache.atlas.AtlasServiceException)14 TraitType (org.apache.atlas.typesystem.types.TraitType)12 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)12 Date (java.util.Date)11 AtlasException (org.apache.atlas.AtlasException)11