Search in sources :

Example 11 with TraitTypeDefinition

use of org.apache.atlas.v1.model.typedef.TraitTypeDefinition in project atlas by apache.

the class EntityJerseyResourceIT method testAddTraitWithNoRegistration.

@Test(expectedExceptions = AtlasServiceException.class)
public void testAddTraitWithNoRegistration() throws Exception {
    final String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    Struct traitInstance = new Struct(traitName);
    String traitInstanceAsJSON = AtlasType.toV1Json(traitInstance);
    LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
    atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS);
}
Also used : Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 12 with TraitTypeDefinition

use of org.apache.atlas.v1.model.typedef.TraitTypeDefinition 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 13 with TraitTypeDefinition

use of org.apache.atlas.v1.model.typedef.TraitTypeDefinition 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 14 with TraitTypeDefinition

use of org.apache.atlas.v1.model.typedef.TraitTypeDefinition in project atlas by apache.

the class DataSetLineageJerseyResourceIT method setupInstances.

private void setupInstances() throws Exception {
    TraitTypeDefinition factTrait = TypesUtil.createTraitTypeDef(FACT, null, Collections.<String>emptySet());
    TraitTypeDefinition etlTrait = TypesUtil.createTraitTypeDef(ETL, null, Collections.<String>emptySet());
    TraitTypeDefinition dimensionTrait = TypesUtil.createTraitTypeDef(DIMENSION, null, Collections.<String>emptySet());
    TraitTypeDefinition metricTrait = TypesUtil.createTraitTypeDef(METRIC, null, Collections.<String>emptySet());
    createType(getTypesDef(null, null, Arrays.asList(factTrait, etlTrait, dimensionTrait, metricTrait), null));
    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", PII), column("sales", "double", "product id", METRIC));
    salesFactTable = "sales_fact" + randomString();
    Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns, FACT);
    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, DIMENSION);
    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, METRIC);
    loadProcess("loadSalesDaily" + randomString(), "John ETL", Arrays.asList(salesFact, timeDim), Collections.singletonList(salesFactDaily), "create table as select ", "plan", "id", "graph", ETL);
    salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
    Id salesFactMonthly = table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI", "MANAGED", salesFactColumns, METRIC);
    loadProcess("loadSalesMonthly" + randomString(), "John ETL", Collections.singletonList(salesFactDaily), Collections.singletonList(salesFactMonthly), "create table as select ", "plan", "id", "graph", ETL);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) TraitTypeDefinition(org.apache.atlas.v1.model.typedef.TraitTypeDefinition) Id(org.apache.atlas.v1.model.instance.Id)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)9 Test (org.testng.annotations.Test)9 Id (org.apache.atlas.v1.model.instance.Id)8 Struct (org.apache.atlas.v1.model.instance.Struct)6 TraitTypeDefinition (org.apache.atlas.v1.model.typedef.TraitTypeDefinition)4 AtlasServiceException (org.apache.atlas.AtlasServiceException)3 AttributeDefinition (org.apache.atlas.v1.model.typedef.AttributeDefinition)2 TypesDef (org.apache.atlas.v1.model.typedef.TypesDef)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)1 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)1 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)1 EnumValue (org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue)1