Search in sources :

Example 86 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class EntityJerseyResourceIT method testCreateNestedEntities.

@Test
public void testCreateNestedEntities() throws Exception {
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
    databaseInstance.set("name", "db_" + randomString());
    databaseInstance.set("description", "foo database");
    int nTables = 5;
    int colsPerTable = 3;
    List<Referenceable> tables = new ArrayList<>();
    List<Referenceable> allColumns = new ArrayList<>();
    for (int i = 0; i < nTables; i++) {
        String tableName = "db1-table-" + i + randomString();
        Referenceable tableInstance = new Referenceable(HIVE_TABLE_TYPE);
        tableInstance.set("name", tableName);
        tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
        tableInstance.set("db", databaseInstance);
        tableInstance.set("description", tableName + " table");
        tables.add(tableInstance);
        List<Referenceable> columns = new ArrayList<>();
        for (int j = 0; j < colsPerTable; j++) {
            Referenceable columnInstance = new Referenceable(COLUMN_TYPE);
            columnInstance.set("name", tableName + "-col-" + j + randomString());
            columnInstance.set("dataType", "String");
            columnInstance.set("comment", "column " + j + " for table " + i);
            allColumns.add(columnInstance);
            columns.add(columnInstance);
        }
        tableInstance.set("columns", columns);
    }
    // Create the tables.  The database and columns should be created automatically, since
    // the tables reference them.
    List<String> entityGUIDs = atlasClientV1.createEntity(tables);
    assertNotNull(entityGUIDs);
    assertEquals(entityGUIDs.size(), nTables * (colsPerTable + 1) + 1);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Test(org.testng.annotations.Test)

Example 87 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class EntityJerseyResourceIT method testDeleteTraitNonExistent.

@Test(expectedExceptions = AtlasServiceException.class)
public void testDeleteTraitNonExistent() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    final String traitName = "blah_trait";
    atlasClientV1.deleteTrait(guid, traitName);
    fail("trait=" + traitName + " should be defined in type system before it can be deleted");
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 88 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class EntityJerseyResourceIT method testSubmitEntityWithBadDateFormat.

@Test
public void testSubmitEntityWithBadDateFormat() {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = null;
    try {
        dbId = createInstance(hiveDBInstance);
        Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
        hiveTableInstance.set("lastAccessTime", "2014-07-11");
        createInstance(hiveTableInstance);
    } catch (AtlasServiceException e) {
        // Should catch the exception
        assertEquals(e.getStatus().getStatusCode(), BAD_REQUEST.getStatusCode());
    } catch (Exception e) {
    // ignore
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) AtlasServiceException(org.apache.atlas.AtlasServiceException) Test(org.testng.annotations.Test)

Example 89 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class EntityJerseyResourceIT method testDeleteEntityByUniqAttribute.

@Test
public void testDeleteEntityByUniqAttribute() throws Exception {
    // Create database entity
    Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    db1.set(NAME, dbName);
    db1.set(QUALIFIED_NAME, dbName);
    db1.set(CLUSTER_NAME, randomString());
    db1.set(DESCRIPTION, randomString());
    db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    db1.set("owner", "user1");
    db1.set(CLUSTER_NAME, "cl1");
    db1.set("parameters", Collections.EMPTY_MAP);
    db1.set("location", "/tmp");
    Id db1Id = createInstance(db1);
    // Delete the database entity
    List<String> deletedGuidsList = atlasClientV1.deleteEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName).getDeletedEntities();
    // Verify that deleteEntities() response has database entity guids
    Assert.assertEquals(deletedGuidsList.size(), 1);
    Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
    // Verify entities were deleted from the repository.
    for (String guid : deletedGuidsList) {
        Referenceable entity = atlasClientV1.getEntity(guid);
        assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 90 with Referenceable

use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.

the class EntityJerseyResourceIT method testDeleteExistentTraitNonExistentForEntity.

@Test
public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    final String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("type", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(AtlasType.toV1Json(typesDef));
    try {
        atlasClientV1.deleteTrait(guid, traitName);
        fail("Call should've failed for deletion of invalid trait");
    } catch (AtlasServiceException e) {
        assertNotNull(e);
        assertNotNull(e.getStatus());
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)143 Test (org.testng.annotations.Test)64 Id (org.apache.atlas.v1.model.instance.Id)37 Struct (org.apache.atlas.v1.model.instance.Struct)23 ArrayList (java.util.ArrayList)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 HashMap (java.util.HashMap)12 List (java.util.List)10 AtlasException (org.apache.atlas.AtlasException)10 HookNotification (org.apache.atlas.model.notification.HookNotification)10 Map (java.util.Map)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 AtlasServiceException (org.apache.atlas.AtlasServiceException)8 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)8 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)7 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)5