Search in sources :

Example 16 with AtlasEnumDef

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

the class ModelTestUtil method newEnumDef.

public static AtlasEnumDef newEnumDef(AtlasTypeRegistry typesRegistry, boolean hasDefaultValue) {
    int enumDefIdx = IDX_ENUM_DEF.getAndIncrement();
    AtlasEnumDef ret = new AtlasEnumDef();
    ret.setName(PREFIX_ENUM_DEF + enumDefIdx);
    ret.setDescription(ret.getName());
    int numElements = ThreadLocalRandom.current().nextInt(1, MAX_ENUM_ELEMENT_COUNT);
    for (int i = 0; i < numElements; i++) {
        String elementName = "element-" + i;
        ret.addElement(new AtlasEnumElementDef(elementName, elementName.toUpperCase(), i));
    }
    if (hasDefaultValue) {
        int idxDefault = ThreadLocalRandom.current().nextInt(0, numElements);
        ret.setDefaultValue(ret.getElementDefs().get(idxDefault).getValue());
    }
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    try {
        ttr = typesRegistry.lockTypeRegistryForUpdate();
        ttr.addType(ret);
        commit = true;
    } catch (AtlasBaseException excp) {
        LOG.error("failed to create enum-def", excp);
        ret = null;
    } finally {
        typesRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    return ret;
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 17 with AtlasEnumDef

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

the class GraphBackedSearchIndexer method cleanupIndices.

private void cleanupIndices(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
    Preconditions.checkNotNull(typeDef, "Cannot process null typedef");
    if (LOG.isDebugEnabled()) {
        LOG.debug("Cleaning up index for {}", typeDef);
    }
    if (typeDef instanceof AtlasEnumDef) {
        // Only handle complex types like Struct, Classification and Entity
        return;
    }
    if (typeDef instanceof AtlasStructDef) {
        AtlasStructDef structDef = (AtlasStructDef) typeDef;
        List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
        if (CollectionUtils.isNotEmpty(attributeDefs)) {
            for (AtlasAttributeDef attributeDef : attributeDefs) {
                cleanupIndexForAttribute(management, typeDef.getName(), attributeDef);
            }
        }
    } else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())) {
        throw new IllegalArgumentException("bad data type" + typeDef.getName());
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 18 with AtlasEnumDef

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

the class GraphBackedSearchIndexer method addIndexForType.

private void addIndexForType(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
    if (typeDef instanceof AtlasEnumDef) {
        // Only handle complex types like Struct, Classification and Entity
        return;
    }
    if (typeDef instanceof AtlasStructDef) {
        AtlasStructDef structDef = (AtlasStructDef) typeDef;
        List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
        if (CollectionUtils.isNotEmpty(attributeDefs)) {
            for (AtlasAttributeDef attributeDef : attributeDefs) {
                createIndexForAttribute(management, typeDef.getName(), attributeDef);
            }
        }
    } else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())) {
        throw new IllegalArgumentException("bad data type" + typeDef.getName());
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 19 with AtlasEnumDef

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

the class AtlasTypeDefGraphStoreTest method testCreateWithValidSuperTypes.

@Test(dependsOnMethods = "testGet")
public void testCreateWithValidSuperTypes() {
    // Test Classification with supertype
    List<AtlasClassificationDef> classificationDefs = TestUtilsV2.getClassificationWithValidSuperType();
    AtlasTypesDef toCreate = new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), classificationDefs, Collections.<AtlasEntityDef>emptyList());
    try {
        AtlasTypesDef created = typeDefStore.createTypesDef(toCreate);
        assertEquals(created.getClassificationDefs(), toCreate.getClassificationDefs(), "Classification creation with valid supertype should've succeeded");
    } catch (AtlasBaseException e) {
        fail("Classification creation with valid supertype should've succeeded");
    }
    // Test Entity with supertype
    List<AtlasEntityDef> entityDefs = TestUtilsV2.getEntityWithValidSuperType();
    toCreate = new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), Collections.<AtlasClassificationDef>emptyList(), entityDefs);
    try {
        AtlasTypesDef created = typeDefStore.createTypesDef(toCreate);
        assertEquals(created.getEntityDefs(), toCreate.getEntityDefs(), "Entity creation with valid supertype should've succeeded");
    } catch (AtlasBaseException e) {
        fail("Entity creation with valid supertype should've succeeded");
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 20 with AtlasEnumDef

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

the class TestUtilsV2 method defineValidUpdatedDeptEmployeeTypes.

public static AtlasTypesDef defineValidUpdatedDeptEmployeeTypes() {
    String _description = "_description_updated";
    AtlasEnumDef orgLevelEnum = new AtlasEnumDef("OrgLevel", "OrgLevel" + _description, "1.0", Arrays.asList(new AtlasEnumElementDef("L1", "Element" + _description, 1), new AtlasEnumElementDef("L2", "Element" + _description, 2)));
    AtlasStructDef addressDetails = createStructTypeDef("Address", "Address" + _description, AtlasTypeUtil.createRequiredAttrDef("street", "string"), AtlasTypeUtil.createRequiredAttrDef("city", "string"), AtlasTypeUtil.createOptionalAttrDef("zip", "int"));
    AtlasEntityDef deptTypeDef = AtlasTypeUtil.createClassTypeDef(DEPARTMENT_TYPE, "Department" + _description, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("dep-code", "string"), new AtlasAttributeDef("employees", String.format("array<%s>", "Employee"), true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, new ArrayList<AtlasStructDef.AtlasConstraintDef>() {

        {
            add(new AtlasStructDef.AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
        }
    }));
    AtlasEntityDef personTypeDef = AtlasTypeUtil.createClassTypeDef("Person", "Person" + _description, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("email", "string"), AtlasTypeUtil.createOptionalAttrDef("address", "Address"), AtlasTypeUtil.createOptionalAttrDef("birthday", "date"), AtlasTypeUtil.createOptionalAttrDef("hasPets", "boolean"), AtlasTypeUtil.createOptionalAttrDef("numberOfCars", "byte"), AtlasTypeUtil.createOptionalAttrDef("houseNumber", "short"), AtlasTypeUtil.createOptionalAttrDef("carMileage", "int"), AtlasTypeUtil.createOptionalAttrDef("age", "float"), AtlasTypeUtil.createOptionalAttrDef("numberOfStarsEstimate", "biginteger"), AtlasTypeUtil.createOptionalAttrDef("approximationOfPi", "bigdecimal"));
    AtlasEntityDef employeeTypeDef = AtlasTypeUtil.createClassTypeDef("Employee", "Employee" + _description, ImmutableSet.of("Person"), AtlasTypeUtil.createOptionalAttrDef("orgLevel", "OrgLevel"), AtlasTypeUtil.createOptionalAttrDef("empCode", "string"), new AtlasAttributeDef("department", "Department", false, AtlasAttributeDef.Cardinality.SINGLE, 1, 1, false, false, Collections.<AtlasConstraintDef>emptyList()), new AtlasAttributeDef("manager", "Manager", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, new ArrayList<AtlasConstraintDef>() {

        {
            add(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {

                {
                    put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "subordinates");
                }
            }));
        }
    }), new AtlasAttributeDef("mentor", EMPLOYEE_TYPE, true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, false, Collections.<AtlasConstraintDef>emptyList()), AtlasTypeUtil.createOptionalAttrDef("shares", "long"), AtlasTypeUtil.createOptionalAttrDef("salary", "double"));
    AtlasEntityDef managerTypeDef = AtlasTypeUtil.createClassTypeDef("Manager", "Manager" + _description, ImmutableSet.of("Employee"), new AtlasAttributeDef("subordinates", String.format("array<%s>", "Employee"), false, AtlasAttributeDef.Cardinality.SET, 1, 10, false, false, Collections.<AtlasConstraintDef>emptyList()));
    AtlasClassificationDef securityClearanceTypeDef = AtlasTypeUtil.createTraitTypeDef("SecurityClearance", "SecurityClearance" + _description, ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("level", "int"));
    return new AtlasTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails), ImmutableList.of(securityClearanceTypeDef), ImmutableList.of(deptTypeDef, personTypeDef, employeeTypeDef, managerTypeDef));
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashMap(java.util.HashMap) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Aggregations

AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)31 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)21 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)19 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)18 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)14 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)10 ArrayList (java.util.ArrayList)8 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)8 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)7 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 Test (org.testng.annotations.Test)5 HashMap (java.util.HashMap)4 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2 TypesDef (org.apache.atlas.typesystem.TypesDef)2 EnumTypeDefinition (org.apache.atlas.typesystem.types.EnumTypeDefinition)2 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 EnumValue (org.apache.atlas.typesystem.types.EnumValue)1 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)1