Search in sources :

Example 21 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class TypedefsJerseyResourceIT method createHiveTypesV2.

private AtlasTypesDef createHiveTypesV2() throws Exception {
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    AtlasEntityDef databaseTypeDefinition = createClassTypeDef("database", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"));
    atlasTypesDef.getEntityDefs().add(databaseTypeDefinition);
    AtlasEntityDef tableTypeDefinition = createClassTypeDef("table", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"), AtlasTypeUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName("string")), AtlasTypeUtil.createOptionalAttrDef("created", "date"), AtlasTypeUtil.createOptionalAttrDef("parameters", DataTypes.mapTypeName("string", "string")), AtlasTypeUtil.createRequiredAttrDef("type", "string"), new AtlasAttributeDef("database", "database", false, Cardinality.SINGLE, 1, 1, true, true, Collections.<AtlasConstraintDef>emptyList()));
    atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
    AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil.createTraitTypeDef("fetl", ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("level", "int"));
    atlasTypesDef.getClassificationDefs().add(fetlTypeDefinition);
    return atlasTypesDef;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 22 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class TypedefsJerseyResourceIT method testCreate.

@Test
public void testCreate() throws Exception {
    createType(typeDefinitions);
    for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) {
        AtlasEnumDef byName = atlasClientV2.getEnumDefByName(enumDef.getName());
        assertNotNull(byName);
    }
    for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
        AtlasStructDef byName = atlasClientV2.getStructDefByName(structDef.getName());
        assertNotNull(byName);
    }
    for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
        AtlasClassificationDef byName = atlasClientV2.getClassificationDefByName(classificationDef.getName());
        assertNotNull(byName);
    }
    for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
        AtlasEntityDef byName = atlasClientV2.getEntityDefByName(entityDef.getName());
        assertNotNull(byName);
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) Test(org.testng.annotations.Test)

Example 23 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class QuickStartV2 method createTypeDefinitions.

AtlasTypesDef createTypeDefinitions() throws Exception {
    AtlasEntityDef dbType = AtlasTypeUtil.createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE, "1.0", null, AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string"), AtlasTypeUtil.createOptionalAttrDef("locationUri", "string"), AtlasTypeUtil.createOptionalAttrDef("owner", "string"), AtlasTypeUtil.createOptionalAttrDef("createTime", "long"));
    AtlasEntityDef sdType = AtlasTypeUtil.createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, "1.0", null, AtlasTypeUtil.createOptionalAttrDefWithConstraint("table", TABLE_TYPE, CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {

        {
            put(CONSTRAINT_PARAM_ATTRIBUTE, "sd");
        }
    }), AtlasTypeUtil.createOptionalAttrDef("location", "string"), AtlasTypeUtil.createOptionalAttrDef("inputFormat", "string"), AtlasTypeUtil.createOptionalAttrDef("outputFormat", "string"), AtlasTypeUtil.createRequiredAttrDef("compressed", "boolean"));
    AtlasEntityDef colType = AtlasTypeUtil.createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, "1.0", null, AtlasTypeUtil.createOptionalAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("dataType", "string"), AtlasTypeUtil.createOptionalAttrDef("comment", "string"), AtlasTypeUtil.createOptionalAttrDefWithConstraint("table", TABLE_TYPE, CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {

        {
            put(CONSTRAINT_PARAM_ATTRIBUTE, "columns");
        }
    }));
    colType.setOptions(new HashMap<String, String>() {

        {
            put("schemaAttributes", "[\"name\", \"description\", \"owner\", \"type\", \"comment\", \"position\"]");
        }
    });
    AtlasEntityDef tblType = AtlasTypeUtil.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, "1.0", ImmutableSet.of("DataSet"), AtlasTypeUtil.createRequiredAttrDef("db", DATABASE_TYPE), AtlasTypeUtil.createRequiredAttrDefWithConstraint("sd", STORAGE_DESC_TYPE, CONSTRAINT_TYPE_OWNED_REF, null), AtlasTypeUtil.createOptionalAttrDef("owner", "string"), AtlasTypeUtil.createOptionalAttrDef("createTime", "long"), AtlasTypeUtil.createOptionalAttrDef("lastAccessTime", "long"), AtlasTypeUtil.createOptionalAttrDef("retention", "long"), AtlasTypeUtil.createOptionalAttrDef("viewOriginalText", "string"), AtlasTypeUtil.createOptionalAttrDef("viewExpandedText", "string"), AtlasTypeUtil.createOptionalAttrDef("tableType", "string"), AtlasTypeUtil.createOptionalAttrDef("temporary", "boolean"), AtlasTypeUtil.createRequiredListAttrDefWithConstraint("columns", AtlasBaseTypeDef.getArrayTypeName(COLUMN_TYPE), CONSTRAINT_TYPE_OWNED_REF, null));
    tblType.setOptions(new HashMap<String, String>() {

        {
            put("schemaElementsAttribute", "columns");
        }
    });
    AtlasEntityDef procType = AtlasTypeUtil.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, "1.0", ImmutableSet.of("Process"), AtlasTypeUtil.createOptionalAttrDef("userName", "string"), AtlasTypeUtil.createOptionalAttrDef("startTime", "long"), AtlasTypeUtil.createOptionalAttrDef("endTime", "long"), AtlasTypeUtil.createRequiredAttrDef("queryText", "string"), AtlasTypeUtil.createRequiredAttrDef("queryPlan", "string"), AtlasTypeUtil.createRequiredAttrDef("queryId", "string"), AtlasTypeUtil.createRequiredAttrDef("queryGraph", "string"));
    AtlasEntityDef viewType = AtlasTypeUtil.createClassTypeDef(VIEW_TYPE, VIEW_TYPE, "1.0", ImmutableSet.of("DataSet"), AtlasTypeUtil.createRequiredAttrDef("db", DATABASE_TYPE), AtlasTypeUtil.createOptionalListAttrDef("inputTables", AtlasBaseTypeDef.getArrayTypeName(TABLE_TYPE)));
    AtlasClassificationDef dimClassifDef = AtlasTypeUtil.createTraitTypeDef(DIMENSION_CLASSIFICATION, "Dimension Classification", "1.0", ImmutableSet.<String>of());
    AtlasClassificationDef factClassifDef = AtlasTypeUtil.createTraitTypeDef(FACT_CLASSIFICATION, "Fact Classification", "1.0", ImmutableSet.<String>of());
    AtlasClassificationDef piiClassifDef = AtlasTypeUtil.createTraitTypeDef(PII_CLASSIFICATION, "PII Classification", "1.0", ImmutableSet.<String>of());
    AtlasClassificationDef metricClassifDef = AtlasTypeUtil.createTraitTypeDef(METRIC_CLASSIFICATION, "Metric Classification", "1.0", ImmutableSet.<String>of());
    AtlasClassificationDef etlClassifDef = AtlasTypeUtil.createTraitTypeDef(ETL_CLASSIFICATION, "ETL Classification", "1.0", ImmutableSet.<String>of());
    AtlasClassificationDef jdbcClassifDef = AtlasTypeUtil.createTraitTypeDef(JDBC_CLASSIFICATION, "JdbcAccess Classification", "1.0", ImmutableSet.<String>of());
    AtlasClassificationDef logClassifDef = AtlasTypeUtil.createTraitTypeDef(LOGDATA_CLASSIFICATION, "LogData Classification", "1.0", ImmutableSet.<String>of());
    return AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.of(dimClassifDef, factClassifDef, piiClassifDef, metricClassifDef, etlClassifDef, jdbcClassifDef, logClassifDef), ImmutableList.of(dbType, sdType, colType, tblType, procType, viewType));
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashMap(java.util.HashMap)

Example 24 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class BaseResourceIT method createTypeDefinitionsV2.

protected void createTypeDefinitionsV2() throws Exception {
    AtlasConstraintDef isCompositeSourceConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF);
    AtlasConstraintDef isCompositeTargetConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, Collections.<String, Object>singletonMap(CONSTRAINT_PARAM_ATTRIBUTE, "randomTable"));
    AtlasEntityDef dbClsTypeDef = AtlasTypeUtil.createClassTypeDef(DATABASE_TYPE_V2, null, AtlasTypeUtil.createUniqueRequiredAttrDef(NAME, "string"), AtlasTypeUtil.createRequiredAttrDef(DESCRIPTION, "string"), AtlasTypeUtil.createOptionalAttrDef("locationUri", "string"), AtlasTypeUtil.createOptionalAttrDef("owner", "string"), AtlasTypeUtil.createOptionalAttrDef("createTime", "int"), AtlasTypeUtil.createOptionalAttrDef("createTime", "int"), //there is a serializ
    new AtlasAttributeDef("randomTable", DataTypes.arrayTypeName(HIVE_TABLE_TYPE_V2), true, Cardinality.SET, 0, -1, false, true, Collections.singletonList(isCompositeSourceConstraint)));
    AtlasEntityDef columnClsDef = AtlasTypeUtil.createClassTypeDef(COLUMN_TYPE_V2, null, AtlasTypeUtil.createOptionalAttrDef(NAME, "string"), AtlasTypeUtil.createOptionalAttrDef("dataType", "string"), AtlasTypeUtil.createOptionalAttrDef("comment", "string"));
    AtlasStructDef structTypeDef = AtlasTypeUtil.createStructTypeDef("serdeType", AtlasTypeUtil.createRequiredAttrDef(NAME, "string"), AtlasTypeUtil.createRequiredAttrDef("serde", "string"));
    AtlasEnumDef enumDef = new AtlasEnumDef("tableType", DESCRIPTION, Arrays.asList(new AtlasEnumDef.AtlasEnumElementDef("MANAGED", null, 1), new AtlasEnumDef.AtlasEnumElementDef("EXTERNAL", null, 2)));
    AtlasEntityDef tblClsDef = AtlasTypeUtil.createClassTypeDef(HIVE_TABLE_TYPE_V2, ImmutableSet.of("DataSet"), AtlasTypeUtil.createOptionalAttrDef("owner", "string"), AtlasTypeUtil.createOptionalAttrDef("createTime", "long"), AtlasTypeUtil.createOptionalAttrDef("lastAccessTime", "date"), AtlasTypeUtil.createOptionalAttrDef("temporary", "boolean"), new AtlasAttributeDef("db", DATABASE_TYPE_V2, true, Cardinality.SINGLE, 0, 1, false, true, Collections.singletonList(isCompositeTargetConstraint)), //some tests don't set the columns field or set it to null...
    AtlasTypeUtil.createOptionalAttrDef("columns", DataTypes.arrayTypeName(COLUMN_TYPE_V2)), AtlasTypeUtil.createOptionalAttrDef("tableType", "tableType"), AtlasTypeUtil.createOptionalAttrDef("serde1", "serdeType"), AtlasTypeUtil.createOptionalAttrDef("serde2", "serdeType"));
    AtlasEntityDef loadProcessClsDef = AtlasTypeUtil.createClassTypeDef(HIVE_PROCESS_TYPE_V2, ImmutableSet.of("Process"), AtlasTypeUtil.createOptionalAttrDef("userName", "string"), AtlasTypeUtil.createOptionalAttrDef("startTime", "int"), AtlasTypeUtil.createOptionalAttrDef("endTime", "long"), AtlasTypeUtil.createRequiredAttrDef("queryText", "string"), AtlasTypeUtil.createRequiredAttrDef("queryPlan", "string"), AtlasTypeUtil.createRequiredAttrDef("queryId", "string"), AtlasTypeUtil.createRequiredAttrDef("queryGraph", "string"));
    AtlasClassificationDef classificationTrait = AtlasTypeUtil.createTraitTypeDef("classification", ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("tag", "string"));
    AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef("pii", ImmutableSet.<String>of());
    AtlasClassificationDef phiTrait = AtlasTypeUtil.createTraitTypeDef("phi", ImmutableSet.<String>of());
    AtlasClassificationDef pciTrait = AtlasTypeUtil.createTraitTypeDef("pci", ImmutableSet.<String>of());
    AtlasClassificationDef soxTrait = AtlasTypeUtil.createTraitTypeDef("sox", ImmutableSet.<String>of());
    AtlasClassificationDef secTrait = AtlasTypeUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
    AtlasClassificationDef financeTrait = AtlasTypeUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
    AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.of(enumDef), ImmutableList.of(structTypeDef), ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait), ImmutableList.of(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef));
    batchCreateTypes(typesDef);
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 25 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testAddTraitWithAttribute.

@Test(dependsOnMethods = "testGetTraitNames")
public void testAddTraitWithAttribute() throws Exception {
    final String traitName = "PII_Trait" + randomString();
    AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("type", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(piiTrait);
    createType(typesDef);
    AtlasClassification traitInstance = new AtlasClassification(traitName);
    traitInstance.setAttribute("type", "SSN");
    final String guid = createHiveTable().getGuid();
    atlasClientV2.addClassifications(guid, ImmutableList.of(traitInstance));
    // verify the response
    AtlasEntity withAssociationByGuid = atlasClientV2.getEntityByGuid(guid).getEntity();
    assertNotNull(withAssociationByGuid);
    assertFalse(withAssociationByGuid.getClassifications().isEmpty());
    boolean found = false;
    for (AtlasClassification atlasClassification : withAssociationByGuid.getClassifications()) {
        String attribute = (String) atlasClassification.getAttribute("type");
        if (attribute != null && attribute.equals("SSN")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)45 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)24 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)22 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)21 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)18 Test (org.testng.annotations.Test)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 ArrayList (java.util.ArrayList)8 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)8 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)5 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 HashMap (java.util.HashMap)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2