Search in sources :

Example 36 with AtlasStructDef

use of org.apache.atlas.model.typedef.AtlasStructDef in project incubator-atlas by apache.

the class AtlasStructDefStoreV1 method updateByName.

@Override
public AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.updateByName({}, {})", name, structDef);
    }
    validateType(structDef);
    AtlasType type = typeRegistry.getType(structDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType) type, vertex, typeDefStore);
    AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
    AtlasStructDef ret = toStructDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.updateByName({}, {}): {}", name, structDef, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Example 37 with AtlasStructDef

use of org.apache.atlas.model.typedef.AtlasStructDef 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 38 with AtlasStructDef

use of org.apache.atlas.model.typedef.AtlasStructDef in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method updateGraphStore.

private AtlasTypesDef updateGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();
    AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
    AtlasStructDefStore structDefStore = getStructDefStore(ttr);
    AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
    AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
    if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
        for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
            ret.getEnumDefs().add(enumDefStore.update(enumDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            ret.getStructDefs().add(structDefStore.update(structDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            ret.getClassificationDefs().add(classifiDefStore.update(classifiDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            ret.getEntityDefs().add(entityDefStore.update(entityDef));
        }
    }
    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) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 39 with AtlasStructDef

use of org.apache.atlas.model.typedef.AtlasStructDef 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)

Aggregations

AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)39 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)24 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)21 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)19 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 ArrayList (java.util.ArrayList)11 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)11 Test (org.testng.annotations.Test)10 HashMap (java.util.HashMap)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)6 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4 AtlasType (org.apache.atlas.type.AtlasType)4 BeforeTest (org.testng.annotations.BeforeTest)4 Map (java.util.Map)3 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)3 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)3