Search in sources :

Example 31 with AtlasAttributeDef

use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef 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 32 with AtlasAttributeDef

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

the class TestAtlasTypeRegistry method testRegistryValidityOnInvalidUpdate.

/* create 2 entity types: L0 and L1, with L0 as superType of L1
     * add entity type L2, with L0, L1 and L2 as super-types - this should fail due to L2 self-referencing itself in super-types
     * verify that after the update failure, the registry still has correct super-type/sub-type information for L0 and L1
     */
@Test
public void testRegistryValidityOnInvalidUpdate() {
    AtlasEntityDef entL0 = new AtlasEntityDef("L0");
    AtlasEntityDef entL1 = new AtlasEntityDef("L1");
    entL1.addSuperType(entL0.getName());
    entL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL1.addAttribute(new AtlasAttributeDef("L1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entL0);
    typesDef.getEntityDefs().add(entL1);
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    String failureMsg = null;
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(typesDef);
        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);
    validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1")));
    validateSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0")));
    validateSubTypes(typeRegistry, "L1", new HashSet<String>());
    // create a circular reference
    AtlasEntityDef entL2 = new AtlasEntityDef("L2");
    entL2.addSuperType(entL0.getName());
    entL2.addSuperType(entL1.getName());
    entL2.addSuperType(entL2.getName());
    typesDef.clear();
    typesDef.getEntityDefs().add(entL2);
    try {
        commit = false;
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.updateTypes(typesDef);
        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNotNull(failureMsg);
    assertNull(typeRegistry.getEntityTypeByName("L2"));
    validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1")));
    validateSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0")));
    validateSubTypes(typeRegistry, "L1", new HashSet<String>());
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) Test(org.testng.annotations.Test)

Example 33 with AtlasAttributeDef

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

the class TestAtlasTypeRegistry method testEntityDefValidHierarchy.

/*
     *             L0
     *          /      \
     *         /         \
     *      L1_1----      L1_2
     *      /  \    \    /   \
     *     /    \    \  /     \
     *   L2_1  L2_2   L2_3   L2_4
     */
@Test
public void testEntityDefValidHierarchy() {
    AtlasEntityDef entL0 = new AtlasEntityDef("L0");
    AtlasEntityDef entL1_1 = new AtlasEntityDef("L1-1");
    AtlasEntityDef entL1_2 = new AtlasEntityDef("L1-2");
    AtlasEntityDef entL2_1 = new AtlasEntityDef("L2-1");
    AtlasEntityDef entL2_2 = new AtlasEntityDef("L2-2");
    AtlasEntityDef entL2_3 = new AtlasEntityDef("L2-3");
    AtlasEntityDef entL2_4 = new AtlasEntityDef("L2-4");
    entL1_1.addSuperType(entL0.getName());
    entL1_2.addSuperType(entL0.getName());
    entL2_1.addSuperType(entL1_1.getName());
    entL2_2.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_2.getName());
    entL2_4.addSuperType(entL1_2.getName());
    entL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entL0);
    typesDef.getEntityDefs().add(entL1_1);
    typesDef.getEntityDefs().add(entL1_2);
    typesDef.getEntityDefs().add(entL2_1);
    typesDef.getEntityDefs().add(entL2_2);
    typesDef.getEntityDefs().add(entL2_3);
    typesDef.getEntityDefs().add(entL2_4);
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    String failureMsg = null;
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addTypes(typesDef);
        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);
    validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
    validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));
    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
    validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());
    validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
    validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
    validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
    validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
    validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
    validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
    validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) Test(org.testng.annotations.Test)

Example 34 with AtlasAttributeDef

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

the class TestAtlasEntityType method createTableEntityDefWithOwnedRefOnInvalidType.

private AtlasEntityDef createTableEntityDefWithOwnedRefOnInvalidType() {
    AtlasEntityDef table = new AtlasEntityDef(TYPE_TABLE);
    AtlasAttributeDef attrName = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);
    attrName.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
    table.addAttribute(attrName);
    return table;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Example 35 with AtlasAttributeDef

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

the class TestAtlasEntityType method createTableEntityDef.

private AtlasEntityDef createTableEntityDef() {
    AtlasEntityDef table = new AtlasEntityDef(TYPE_TABLE);
    AtlasAttributeDef attrName = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);
    AtlasAttributeDef attrColumns = new AtlasAttributeDef(ATTR_COLUMNS, AtlasBaseTypeDef.getArrayTypeName(TYPE_COLUMN));
    attrColumns.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
    table.addAttribute(attrName);
    table.addAttribute(attrColumns);
    return table;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Aggregations

AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)52 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)19 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)17 HashMap (java.util.HashMap)14 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)13 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 ArrayList (java.util.ArrayList)11 Test (org.testng.annotations.Test)10 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)9 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)8 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)7 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)5 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)4 Map (java.util.Map)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2