Search in sources :

Example 31 with TypesDef

use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.

the class DefaultMetadataServiceTest method setUp.

@BeforeTest
public void setUp() throws Exception {
    typeDefChangeListener = (DefaultMetadataService) metadataService;
    metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
    if (auditRepository instanceof HBaseBasedAuditRepository) {
        HBaseTestUtils.startCluster();
        ((HBaseBasedAuditRepository) auditRepository).start();
    }
    TestUtils.resetRequestContext();
    RequestContext.get().setUser("testuser");
    TypesDef typesDef = TestUtils.defineHiveTypes();
    try {
        metadataService.getTypeDefinition(TestUtils.TABLE_TYPE);
    } catch (TypeNotFoundException e) {
        metadataService.createType(TypesSerialization.toJson(typesDef));
    }
    String dbGUid = TestUtils.createInstance(metadataService, db);
    table = createTableEntity(dbGUid);
    String tableGuid = TestUtils.createInstance(metadataService, table);
    String tableDefinitionJson = metadataService.getEntityDefinition(TestUtils.TABLE_TYPE, NAME, (String) table.get(NAME));
    table = InstanceSerialization.fromJsonReferenceable(tableDefinitionJson, true);
    tableId = new Id(tableGuid, 0, TestUtils.TABLE_TYPE);
}
Also used : HBaseBasedAuditRepository(org.apache.atlas.repository.audit.HBaseBasedAuditRepository) TypesDef(org.apache.atlas.typesystem.TypesDef) TypeNotFoundException(org.apache.atlas.typesystem.exception.TypeNotFoundException) Id(org.apache.atlas.typesystem.persistence.Id) BeforeTest(org.testng.annotations.BeforeTest)

Example 32 with TypesDef

use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.

the class MetadataDiscoveryJerseyResourceIT method createTypes.

private void createTypes() throws Exception {
    createTypeDefinitionsV1();
    HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil.createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
    HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil.createTraitTypeDef("Classification", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
    TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(classificationTraitDefinition), ImmutableList.of(dslTestTypeDefinition));
    createType(typesDef);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 33 with TypesDef

use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.

the class BaseRepositoryTest method setUpTypes.

private void setUpTypes() throws Exception {
    TypesDef typesDef = createTypeDefinitions();
    String typesAsJSON = TypesSerialization.toJson(typesDef);
    metadataService.createType(typesAsJSON);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef)

Example 34 with TypesDef

use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.

the class TypesJerseyResourceIT method testUpdate.

@Test
public void testUpdate() throws Exception {
    HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil.createClassTypeDef(randomString(), ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
    List<String> typesCreated = atlasClientV1.createType(TypesSerialization.toJson(typeDefinition, false));
    assertEquals(typesCreated.size(), 1);
    assertEquals(typesCreated.get(0), typeDefinition.typeName);
    //Add attribute description
    typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE), createOptionalAttrDef(DESCRIPTION, DataTypes.STRING_TYPE));
    TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(typeDefinition));
    List<String> typesUpdated = atlasClientV1.updateType(typeDef);
    assertEquals(typesUpdated.size(), 1);
    Assert.assertTrue(typesUpdated.contains(typeDefinition.typeName));
    TypesDef updatedTypeDef = atlasClientV1.getType(typeDefinition.typeName);
    assertNotNull(updatedTypeDef);
    HierarchicalTypeDefinition<ClassType> updatedType = updatedTypeDef.classTypesAsJavaList().get(0);
    assertEquals(updatedType.attributeDefinitions.length, 2);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 35 with TypesDef

use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.

the class TypeConverterUtil method toAtlasTypesDef.

public static AtlasTypesDef toAtlasTypesDef(String typeDefinition, AtlasTypeRegistry registry) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();
    try {
        if (StringUtils.isEmpty(typeDefinition)) {
            throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
        }
        TypesDef typesDef = TypesSerialization.fromJson(typeDefinition);
        if (CollectionUtils.isNotEmpty(typesDef.enumTypesAsJavaList())) {
            List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.enumTypesAsJavaList());
            ret.setEnumDefs(enumDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.structTypesAsJavaList())) {
            List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.structTypesAsJavaList());
            ret.setStructDefs(structDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.classTypesAsJavaList())) {
            List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.classTypesAsJavaList(), registry);
            ret.setEntityDefs(entityDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.traitTypesAsJavaList())) {
            List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.traitTypesAsJavaList());
            ret.setClassificationDefs(classificationDefs);
        }
    } catch (Exception e) {
        LOG.error("Invalid type definition = {}", typeDefinition, e);
        throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Aggregations

TypesDef (org.apache.atlas.typesystem.TypesDef)43 Test (org.testng.annotations.Test)20 ClassType (org.apache.atlas.typesystem.types.ClassType)15 TraitType (org.apache.atlas.typesystem.types.TraitType)13 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)8 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 BeforeTest (org.testng.annotations.BeforeTest)5 AtlasException (org.apache.atlas.AtlasException)4 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)4 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)3 Referenceable (org.apache.atlas.typesystem.Referenceable)3 Id (org.apache.atlas.typesystem.persistence.Id)3 StructTypeDefinition (org.apache.atlas.typesystem.types.StructTypeDefinition)3 BeforeClass (org.testng.annotations.BeforeClass)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2