Search in sources :

Example 31 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method updateEnumDefByName.

@Override
@GraphTransaction
public AtlasEnumDef updateEnumDefByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException {
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    tryUpdateByName(name, enumDef, ttr);
    return getEnumDefStore(ttr).updateByName(name, enumDef);
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 32 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method updateTypesDef.

@Override
@GraphTransaction
public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    // Translate any NOT FOUND errors to BAD REQUEST
    try {
        ttr.updateTypes(typesDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
    AtlasTypesDef ret = updateGraphStore(typesDef, ttr);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 33 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method createUpdateTypesDef.

@Override
@GraphTransaction
public AtlasTypesDef createUpdateTypesDef(AtlasTypesDef typesToCreate, AtlasTypesDef typesToUpdate) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.createUpdateTypesDef({}, {})", typesToCreate, typesToUpdate);
    }
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    if (!typesToUpdate.isEmpty()) {
        ttr.updateTypesWithNoRefResolve(typesToUpdate);
    }
    // Translate any NOT FOUND errors to BAD REQUEST
    tryTypeCreation(typesToCreate, ttr);
    AtlasTypesDef ret = addToGraphStore(typesToCreate, ttr);
    if (!typesToUpdate.isEmpty()) {
        AtlasTypesDef updatedTypes = updateGraphStore(typesToUpdate, ttr);
        if (CollectionUtils.isNotEmpty(updatedTypes.getEnumDefs())) {
            for (AtlasEnumDef enumDef : updatedTypes.getEnumDefs()) {
                ret.getEnumDefs().add(enumDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getStructDefs())) {
            for (AtlasStructDef structDef : updatedTypes.getStructDefs()) {
                ret.getStructDefs().add(structDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getClassificationDefs())) {
            for (AtlasClassificationDef classificationDef : updatedTypes.getClassificationDefs()) {
                ret.getClassificationDefs().add(classificationDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getEntityDefs())) {
            for (AtlasEntityDef entityDef : updatedTypes.getEntityDefs()) {
                ret.getEntityDefs().add(entityDef);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.createUpdateTypesDef({}, {}): {}", typesToCreate, typesToUpdate, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 34 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method lockTypeRegistryAndReleasePostCommit.

private AtlasTransientTypeRegistry lockTypeRegistryAndReleasePostCommit() throws AtlasBaseException {
    AtlasTransientTypeRegistry ttr = typeRegistry.lockTypeRegistryForUpdate(typeUpdateLockMaxWaitTimeSeconds);
    new TypeRegistryUpdateHook(ttr);
    return ttr;
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)

Aggregations

AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)34 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)20 Test (org.testng.annotations.Test)14 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)12 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)9 ArrayList (java.util.ArrayList)7 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)5 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)3 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)3 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)3 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)3 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)1 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)1