Search in sources :

Example 26 with AtlasTransientTypeRegistry

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

the class TestAtlasTypeRegistry method addType.

private boolean addType(AtlasTypeRegistry typeRegistry, AtlasBaseTypeDef typeDef) {
    boolean ret = false;
    AtlasTransientTypeRegistry ttr = null;
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addType(typeDef);
        ret = true;
    } catch (AtlasBaseException excp) {
    // ignore
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)

Example 27 with AtlasTransientTypeRegistry

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

the class RestUtilsTest method createRegistry.

private AtlasTypeRegistry createRegistry(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
    AtlasTypeRegistry reg = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry tmp = reg.lockTypeRegistryForUpdate();
    tmp.addTypes(toConvert);
    reg.releaseTypeRegistryForUpdate(tmp, true);
    return reg;
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry)

Example 28 with AtlasTransientTypeRegistry

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

the class AtlasTypeDefGraphStore method deleteTypesDef.

@Override
@GraphTransaction
public void deleteTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
    AtlasStructDefStore structDefStore = getStructDefStore(ttr);
    AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
    AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
    List<Object> preDeleteStructDefs = new ArrayList<>();
    List<Object> preDeleteClassifiDefs = new ArrayList<>();
    List<Object> preDeleteEntityDefs = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            if (StringUtils.isNotBlank(structDef.getGuid())) {
                preDeleteStructDefs.add(structDefStore.preDeleteByGuid(structDef.getGuid()));
            } else {
                preDeleteStructDefs.add(structDefStore.preDeleteByName(structDef.getName()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            if (StringUtils.isNotBlank(classifiDef.getGuid())) {
                preDeleteClassifiDefs.add(classifiDefStore.preDeleteByGuid(classifiDef.getGuid()));
            } else {
                preDeleteClassifiDefs.add(classifiDefStore.preDeleteByName(classifiDef.getName()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            if (StringUtils.isNotBlank(entityDef.getGuid())) {
                preDeleteEntityDefs.add(entityDefStore.preDeleteByGuid(entityDef.getGuid()));
            } else {
                preDeleteEntityDefs.add(entityDefStore.preDeleteByName(entityDef.getName()));
            }
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        int i = 0;
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            if (StringUtils.isNotBlank(structDef.getGuid())) {
                structDefStore.deleteByGuid(structDef.getGuid(), preDeleteStructDefs.get(i));
            } else {
                structDefStore.deleteByName(structDef.getName(), preDeleteStructDefs.get(i));
            }
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        int i = 0;
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            if (StringUtils.isNotBlank(classifiDef.getGuid())) {
                classifiDefStore.deleteByGuid(classifiDef.getGuid(), preDeleteClassifiDefs.get(i));
            } else {
                classifiDefStore.deleteByName(classifiDef.getName(), preDeleteClassifiDefs.get(i));
            }
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        int i = 0;
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            if (StringUtils.isNotBlank(entityDef.getGuid())) {
                entityDefStore.deleteByGuid(entityDef.getGuid(), preDeleteEntityDefs.get(i));
            } else {
                entityDefStore.deleteByName(entityDef.getName(), preDeleteEntityDefs.get(i));
            }
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
        for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
            if (StringUtils.isNotBlank(enumDef.getGuid())) {
                enumDefStore.deleteByGuid(enumDef.getGuid());
            } else {
                enumDefStore.deleteByName(enumDef.getName());
            }
        }
    }
    // Remove all from
    ttr.removeTypesDef(typesDef);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 29 with AtlasTransientTypeRegistry

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

the class AtlasTypeDefGraphStore method updateEnumDefByGuid.

@Override
@GraphTransaction
public AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException {
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    tryUpdateByGUID(guid, enumDef, ttr);
    return getEnumDefStore(ttr).updateByGuid(guid, enumDef);
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 30 with AtlasTransientTypeRegistry

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

the class AtlasTypeDefGraphStore method updateEntityDefByName.

@Override
@GraphTransaction
public AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException {
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    tryUpdateByName(name, entityDef, ttr);
    return getEntityDefStore(ttr).updateByName(name, entityDef);
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

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