Search in sources :

Example 31 with AtlasEntityDef

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

the class TypedefsJerseyResourceIT method testDuplicateCreate.

@Test
public void testDuplicateCreate() throws Exception {
    AtlasEntityDef type = createClassTypeDef(randomString(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(type);
    AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
    assertNotNull(created);
    try {
        created = clientV2.createAtlasTypeDefs(typesDef);
        fail("Expected 409");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
    }
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 32 with AtlasEntityDef

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

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

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

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

the class TypedefsJerseyResourceIT method testUpdate.

@Test
public void testUpdate() throws Exception {
    String entityType = randomString();
    AtlasEntityDef typeDefinition = createClassTypeDef(entityType, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    atlasTypesDef.getEntityDefs().add(typeDefinition);
    AtlasTypesDef createdTypeDefs = clientV2.createAtlasTypeDefs(atlasTypesDef);
    assertNotNull(createdTypeDefs);
    assertEquals(createdTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
    //Add attribute description
    typeDefinition = createClassTypeDef(typeDefinition.getName(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string"));
    emptyTypeDefs(atlasTypesDef);
    atlasTypesDef.getEntityDefs().add(typeDefinition);
    AtlasTypesDef updatedTypeDefs = clientV2.updateAtlasTypeDefs(atlasTypesDef);
    assertNotNull(updatedTypeDefs);
    assertEquals(updatedTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
    assertEquals(updatedTypeDefs.getEntityDefs().get(0).getName(), atlasTypesDef.getEntityDefs().get(0).getName());
    MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl();
    filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY");
    AtlasTypesDef allTypeDefs = clientV2.getAllTypeDefs(new SearchFilter(filterParams));
    assertNotNull(allTypeDefs);
    Boolean entityDefFound = false;
    for (AtlasEntityDef atlasEntityDef : allTypeDefs.getEntityDefs()) {
        if (atlasEntityDef.getName().equals(typeDefinition.getName())) {
            assertEquals(atlasEntityDef.getAttributeDefs().size(), 2);
            entityDefFound = true;
            break;
        }
    }
    assertTrue(entityDefFound, "Required entityDef not found.");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)67 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)30 Test (org.testng.annotations.Test)25 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)24 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)24 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)19 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)18 ArrayList (java.util.ArrayList)17 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)17 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)14 HashMap (java.util.HashMap)12 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)7 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)6 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)5 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)5 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)5 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)5