Search in sources :

Example 91 with Referenceable

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

the class EntityJerseyResourceIT method testSubmitSingleEntity.

@Test
public // API should accept single entity (or jsonarray of entities)
void testSubmitSingleEntity() throws Exception {
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    databaseInstance.set("name", dbName);
    databaseInstance.set(QUALIFIED_NAME, dbName);
    databaseInstance.set("clusterName", randomString());
    databaseInstance.set("description", randomString());
    databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    databaseInstance.set("owner", "user1");
    databaseInstance.set("clusterName", "cl1");
    databaseInstance.set("parameters", Collections.EMPTY_MAP);
    databaseInstance.set("location", "/tmp");
    ObjectNode response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, AtlasType.toV1Json(databaseInstance));
    assertNotNull(response);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    EntityResult entityResult = EntityResult.fromString(response.toString());
    assertEquals(entityResult.getCreatedEntities().size(), 1);
    assertNotNull(entityResult.getCreatedEntities().get(0));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 92 with Referenceable

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

the class EntityJerseyResourceIT method testDeleteTrait.

@Test
public void testDeleteTrait() 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);
    }
    String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(typesDef);
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
    atlasClientV1.deleteTrait(guid, traitName);
    try {
        atlasClientV1.getTraitDefinition(guid, traitName);
        fail("Deleted trait definition shouldn't exist");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND);
        assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 93 with Referenceable

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

the class EntityJerseyResourceIT method testPartialUpdateByGuid.

@Test
public void testPartialUpdateByGuid() 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 tableId = createInstance(hiveTableInstance);
    final String guid = tableId._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String colName = "col1" + randomString();
    final List<Referenceable> columns = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put(NAME, colName);
    values.put("comment", "col1 comment");
    values.put(QUALIFIED_NAME, "default.table.col1@" + colName);
    values.put("comment", "col1 comment");
    values.put("type", "string");
    values.put("owner", "user1");
    values.put("position", 0);
    values.put("description", "col1");
    // table is a required reference, can't be null
    values.put("table", tableId);
    Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
    columns.add(ref);
    Referenceable tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {

        {
            put("columns", columns);
        }
    });
    LOG.debug("Updating entity= {}", tableUpdated);
    EntityResult entityResult = atlasClientV1.updateEntity(guid, tableUpdated);
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    assertEquals(entityResult.getUpdateEntities().get(0), guid);
    Referenceable entity = atlasClientV1.getEntity(guid);
    List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
    Referenceable column = refs.get(0);
    assertEquals(columns.get(0).getValues(), column.getValues());
    assertEquals(columns.get(0).getTypeName(), column.getTypeName());
    assertEquals(columns.get(0).getTraits(), column.getTraits());
    assertEquals(columns.get(0).getTraitNames(), column.getTraitNames());
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 94 with Referenceable

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

the class EntityJerseyResourceIT method testGetTraitDefinitionForEntity.

@Test
public void testGetTraitDefinitionForEntity() 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);
    }
    String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    String traitDefinitionAsJSON = AtlasType.toV1Json(typesDef);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    createType(AtlasType.toV1Json(typesDef));
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    Struct traitDef = atlasClientV1.getTraitDefinition(guid, traitName);
    Assert.assertEquals(traitDef.getTypeName(), traitName);
    List<Struct> allTraitDefs = atlasClientV1.listTraitDefinitions(guid);
    System.out.println(allTraitDefs.toString());
    Assert.assertEquals(allTraitDefs.size(), 8);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 95 with Referenceable

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

the class EntityLineageJerseyResourceIT method setupInstances.

private void setupInstances() throws Exception {
    salesDBName = "Sales" + randomString();
    Id salesDB = database(salesDBName, "Sales Database", "John ETL", "hdfs://host:8000/apps/warehouse/sales");
    List<Referenceable> salesFactColumns = Arrays.asList(column("time_id", "int", "time id"), column("product_id", "int", "product id"), column("customer_id", "int", "customer id"), column("sales", "double", "product id"));
    salesFactTable = "sales_fact" + randomString();
    Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns);
    List<Referenceable> timeDimColumns = Arrays.asList(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"), column("weekDay", "int", "week Day"));
    Id timeDim = table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL", timeDimColumns);
    Id reportingDB = database("Reporting" + randomString(), "reporting database", "Jane BI", "hdfs://host:8000/apps/warehouse/reporting");
    Id salesFactDaily = table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB, "Joe BI", "MANAGED", salesFactColumns);
    loadProcess("loadSalesDaily" + randomString(), "John ETL", Arrays.asList(salesFact, timeDim), Collections.singletonList(salesFactDaily), "create table as select ", "plan", "id", "graph");
    salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
    Id salesFactMonthly = table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI", "MANAGED", salesFactColumns);
    loadProcess("loadSalesMonthly" + randomString(), "John ETL", Collections.singletonList(salesFactDaily), Collections.singletonList(salesFactMonthly), "create table as select ", "plan", "id", "graph");
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id)

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