Search in sources :

Example 16 with TypesDef

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

the class BaseResourceIT method createType.

protected List<String> createType(TypesDef typesDef) throws Exception {
    List<EnumTypeDefinition> enumTypes = new ArrayList<>();
    List<StructTypeDefinition> structTypes = new ArrayList<>();
    List<HierarchicalTypeDefinition<TraitType>> traitTypes = new ArrayList<>();
    List<HierarchicalTypeDefinition<ClassType>> classTypes = new ArrayList<>();
    for (EnumTypeDefinition enumTypeDefinition : typesDef.enumTypesAsJavaList()) {
        if (atlasClientV2.typeWithNameExists(enumTypeDefinition.name)) {
            LOG.warn("Type with name {} already exists. Skipping", enumTypeDefinition.name);
        } else {
            enumTypes.add(enumTypeDefinition);
        }
    }
    for (StructTypeDefinition structTypeDefinition : typesDef.structTypesAsJavaList()) {
        if (atlasClientV2.typeWithNameExists(structTypeDefinition.typeName)) {
            LOG.warn("Type with name {} already exists. Skipping", structTypeDefinition.typeName);
        } else {
            structTypes.add(structTypeDefinition);
        }
    }
    for (HierarchicalTypeDefinition<TraitType> hierarchicalTypeDefinition : typesDef.traitTypesAsJavaList()) {
        if (atlasClientV2.typeWithNameExists(hierarchicalTypeDefinition.typeName)) {
            LOG.warn("Type with name {} already exists. Skipping", hierarchicalTypeDefinition.typeName);
        } else {
            traitTypes.add(hierarchicalTypeDefinition);
        }
    }
    for (HierarchicalTypeDefinition<ClassType> hierarchicalTypeDefinition : typesDef.classTypesAsJavaList()) {
        if (atlasClientV2.typeWithNameExists(hierarchicalTypeDefinition.typeName)) {
            LOG.warn("Type with name {} already exists. Skipping", hierarchicalTypeDefinition.typeName);
        } else {
            classTypes.add(hierarchicalTypeDefinition);
        }
    }
    TypesDef toCreate = TypesUtil.getTypesDef(ImmutableList.copyOf(enumTypes), ImmutableList.copyOf(structTypes), ImmutableList.copyOf(traitTypes), ImmutableList.copyOf(classTypes));
    return atlasClientV1.createType(toCreate);
}
Also used : ArrayList(java.util.ArrayList) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef)

Example 17 with TypesDef

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

the class EntityDiscoveryJerseyResourceIT method createTypes.

private void createTypes() throws Exception {
    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 18 with TypesDef

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

the class DefaultMetadataService method createOrUpdateTypes.

private JSONObject createOrUpdateTypes(OperationType opType, String typeDefinition, boolean isUpdate) throws AtlasException {
    typeDefinition = ParamChecker.notEmpty(typeDefinition, "type definition");
    TypesDef typesDef = validateTypeDefinition(opType, typeDefinition);
    try {
        final TypeSystem.TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(typesDef, isUpdate);
        final Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
        try {
            /* Create indexes first so that if index creation fails then we rollback
                   the typesystem and also do not persist the graph
                 */
            if (isUpdate) {
                onTypesUpdated(typesAdded);
            } else {
                onTypesAdded(typesAdded);
            }
            typeStore.store(transientTypeSystem, ImmutableList.copyOf(typesAdded.keySet()));
            typeSystem.commitTypes(typesAdded);
        } catch (Throwable t) {
            throw new AtlasException("Unable to persist types ", t);
        }
        return new JSONObject() {

            {
                put(AtlasClient.TYPES, typesAdded.keySet());
            }
        };
    } catch (JSONException e) {
        LOG.error("Unable to create response for types={}", typeDefinition, e);
        throw new AtlasException("Unable to create response ", e);
    }
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) AtlasException(org.apache.atlas.AtlasException)

Example 19 with TypesDef

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

the class DefaultMetadataService method onChange.

@Override
public void onChange(ChangedTypeDefs changedTypeDefs) throws AtlasBaseException {
    // All we need here is a restore of the type-system
    LOG.info("TypeSystem reset invoked by TypeRegistry changes");
    try {
        TypesDef typesDef = typeStore.restore();
        typeSystem.reset();
        TypeSystem.TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(typesDef, false);
        Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
        LOG.info("Number of types got from transient type system: {}", typesAdded.size());
        typeSystem.commitTypes(typesAdded);
    } catch (AtlasException e) {
        LOG.error("Failed to restore type-system after TypeRegistry changes", e);
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) TypesDef(org.apache.atlas.typesystem.TypesDef) AtlasException(org.apache.atlas.AtlasException)

Example 20 with TypesDef

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

the class StoreBackedTypeCache method onTypeFault.

/**
     * Check the type store for the requested type. 
     * If found in the type store, the type and any required super and attribute types
     * are loaded from the type store, and added to the cache.
     */
@Override
public IDataType onTypeFault(String typeName) throws AtlasException {
    // Type is not cached - check the type store.
    // Any super and attribute types needed by the requested type
    // which are not cached will also be loaded from the store.
    Context context = new Context();
    TypesDef typesDef = getTypeFromStore(typeName, context);
    if (typesDef.isEmpty()) {
        // Type not found in the type store.
        return null;
    }
    // Add all types that were loaded from the store to the cache.
    TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(context.getTypesDef(), false);
    Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
    putAll(typesAdded.values());
    return typesAdded.get(typeName);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) TransientTypeSystem(org.apache.atlas.typesystem.types.TypeSystem.TransientTypeSystem) IDataType(org.apache.atlas.typesystem.types.IDataType)

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