Search in sources :

Example 11 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 12 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 13 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)

Example 14 with TypesDef

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

the class DefaultMetadataService method restoreTypeSystem.

private void restoreTypeSystem() throws AtlasException {
    LOG.info("Restoring type system from the store");
    TypesDef typesDef = typeStore.restore();
    refreshCache(typesDef);
    LOG.info("Restored type system from the store");
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef)

Example 15 with TypesDef

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

the class ClassTest method testSerDeWithDescription.

@Test
public void testSerDeWithDescription() throws Exception {
    HierarchicalTypeDefinition<ClassType> clsType = TypesUtil.createClassTypeDef("Random", "Random-description", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE));
    TypesDef typesDef = getTypesDef(clsType);
    String json = TypesSerialization.toJson(typesDef);
    System.out.println("json " + json);
    TypesSerialization.fromJson(json);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) Test(org.testng.annotations.Test)

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