Search in sources :

Example 16 with AtlasStructDef

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

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

the class TypedefsJerseyResourceIT method testInvalidGets.

@Test
public void testInvalidGets() throws Exception {
    try {
        AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEnumDef byGuid = clientV2.getEnumDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasStructDef byName = clientV2.getStructDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasStructDef byGuid = clientV2.getStructDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasClassificationDef byName = clientV2.getClassificationDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasClassificationDef byGuid = clientV2.getClassificationDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEntityDef byName = clientV2.getEntityDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEntityDef byGuid = clientV2.getEntityDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) Test(org.testng.annotations.Test)

Example 18 with AtlasStructDef

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

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

the class GraphBackedSearchIndexer method cleanupIndexForAttribute.

private void cleanupIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) {
    final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
    String attribTypeName = attributeDef.getTypeName();
    boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
    boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
    boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);
    try {
        AtlasType atlasType = typeRegistry.getType(attribTypeName);
        if (isMapType || isArrayType || isClassificationType(atlasType) || isEntityType(atlasType)) {
            LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
        } else if (isBuiltInType || isEnumType(atlasType)) {
            cleanupIndex(management, propertyName);
        } else if (isStructType(atlasType)) {
            AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName);
            cleanupIndices(management, structDef);
        }
    } catch (AtlasBaseException e) {
        LOG.error("No type exists for {}", attribTypeName, e);
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType)

Example 20 with AtlasStructDef

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

the class GraphBackedSearchIndexer method createIndexForAttribute.

private void createIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) {
    final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName());
    AtlasCardinality cardinality = toAtlasCardinality(attributeDef.getCardinality());
    boolean isUnique = attributeDef.getIsUnique();
    boolean isIndexable = attributeDef.getIsIndexable();
    String attribTypeName = attributeDef.getTypeName();
    boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName);
    boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName);
    boolean isMapType = AtlasTypeUtil.isMapType(attribTypeName);
    try {
        AtlasType atlasType = typeRegistry.getType(attribTypeName);
        if (isMapType || isArrayType || isClassificationType(atlasType) || isEntityType(atlasType)) {
            LOG.warn("Ignoring non-indexable attribute {}", attribTypeName);
        } else if (isBuiltInType) {
            createIndexes(management, propertyName, getPrimitiveClass(attribTypeName), isUnique, cardinality, false, isIndexable);
        } else if (isEnumType(atlasType)) {
            createIndexes(management, propertyName, String.class, isUnique, cardinality, false, isIndexable);
        } else if (isStructType(atlasType)) {
            AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName);
            updateIndexForTypeDef(management, structDef);
        }
    } catch (AtlasBaseException e) {
        LOG.error("No type exists for {}", attribTypeName, e);
    }
}
Also used : AtlasCardinality(org.apache.atlas.repository.graphdb.AtlasCardinality) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType)

Aggregations

AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)39 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)24 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)21 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)19 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 ArrayList (java.util.ArrayList)11 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)11 Test (org.testng.annotations.Test)10 HashMap (java.util.HashMap)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)6 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4 AtlasType (org.apache.atlas.type.AtlasType)4 BeforeTest (org.testng.annotations.BeforeTest)4 Map (java.util.Map)3 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)3 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)3