Commit 08f56903 by Madhan Neethiraj

ATLAS-1232: added preCreate(), preDelete() in typedef persistence, to enable…

ATLAS-1232: added preCreate(), preDelete() in typedef persistence, to enable edge creation for references in a later stage
parent b6acff6d
......@@ -43,8 +43,6 @@ public interface AtlasTypeDefStore {
AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasBaseException;
List<AtlasEnumDef> createEnumDefs(List<AtlasEnumDef> atlasEnumDefs) throws AtlasBaseException;
List<AtlasEnumDef> getAllEnumDefs() throws AtlasBaseException;
AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException;
......@@ -66,8 +64,6 @@ public interface AtlasTypeDefStore {
/*************************/
AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasBaseException;
List<AtlasStructDef> createStructDefs(List<AtlasStructDef> structDefs) throws AtlasBaseException;
List<AtlasStructDef> getAllStructDefs() throws AtlasBaseException;
AtlasStructDef getStructDefByName(String name) throws AtlasBaseException;
......@@ -90,8 +86,6 @@ public interface AtlasTypeDefStore {
/*********************************/
AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) throws AtlasBaseException;
List<AtlasClassificationDef> createClassificationDefs(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException;
List<AtlasClassificationDef> getAllClassificationDefs() throws AtlasBaseException;
AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException;
......@@ -116,8 +110,6 @@ public interface AtlasTypeDefStore {
/*************************/
AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> createEntityDefs(List<AtlasEntityDef> entityDefs) throws AtlasBaseException;
List<AtlasEntityDef> getAllEntityDefs() throws AtlasBaseException;
AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException;
......@@ -140,5 +132,7 @@ public interface AtlasTypeDefStore {
AtlasTypesDef updateTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
void deleteTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException;
}
......@@ -357,16 +357,16 @@ public class AtlasStructType extends AtlasType {
*/
private void resolveForeignKeyConstraint(AtlasAttributeDef attribDef, AtlasConstraintDef constraintDef,
AtlasType attribType) throws AtlasBaseException {
if (!(this instanceof AtlasEntityType)) {
if (this.getTypeCategory() != TypeCategory.ENTITY) {
throw new AtlasBaseException(getTypeName() + "." + attribDef.getName() + ": "
+ AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_FOREIGN_KEY + " constraint not supported");
}
if (attribType instanceof AtlasArrayType) {
if (attribType.getTypeCategory() == TypeCategory.ARRAY) {
attribType = ((AtlasArrayType)attribType).getElementType();
}
if (!(attribType instanceof AtlasEntityType)) {
if (attribType.getTypeCategory() != TypeCategory.ENTITY) {
throw new AtlasBaseException(getTypeName() + "." + attribDef.getName() + ": "
+ AtlasConstraintDef.CONSTRAINT_TYPE_FOREIGN_KEY + " incompatible attribute type "
+ attribType.getTypeName());
......@@ -383,16 +383,17 @@ public class AtlasStructType extends AtlasType {
*/
private void resolveMappedFromRefConstraint(AtlasAttributeDef attribDef, AtlasConstraintDef constraintDef,
AtlasType attribType) throws AtlasBaseException {
if (!(this instanceof AtlasEntityType)) {
if (this.getTypeCategory() != TypeCategory.ENTITY) {
throw new AtlasBaseException(getTypeName() + "." + attribDef.getName() + ": "
+ CONSTRAINT_TYPE_MAPPED_FROM_REF + " constraint not supported");
}
if (attribType instanceof AtlasArrayType) {
if (attribType.getTypeCategory() == TypeCategory.ARRAY) {
attribType = ((AtlasArrayType)attribType).getElementType();
}
if (!(attribType instanceof AtlasEntityType)) {
if (attribType.getTypeCategory() != TypeCategory.ENTITY) {
throw new AtlasBaseException(getTypeName() + "." + attribDef.getName() + ": "
+ CONSTRAINT_TYPE_MAPPED_FROM_REF + " incompatible attribute type "
+ attribType.getTypeName());
......@@ -421,7 +422,7 @@ public class AtlasStructType extends AtlasType {
+ " should be " + getTypeName() + ", but found " + refAttrib.getTypeName());
}
mappedFromRefAttributes.put(attribDef.getName(), new TypeAttributePair(refAttrib.getTypeName(), refAttribName));
mappedFromRefAttributes.put(attribDef.getName(), new TypeAttributePair(attribType.getTypeName(), refAttribName));
}
private class TypeAttributePair {
......
......@@ -40,7 +40,6 @@ import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -197,6 +196,33 @@ public class AtlasTypeRegistry {
classificationDefs = new TypeDefCache<>(other.classificationDefs, allTypes);
entityDefs = new TypeDefCache<>(other.entityDefs, allTypes);
}
void updateGuid(String typeName, String guid) {
if (typeName != null) {
enumDefs.updateGuid(typeName, guid);
structDefs.updateGuid(typeName, guid);
classificationDefs.updateGuid(typeName, guid);
entityDefs.updateGuid(typeName, guid);
}
}
void removeByGuid(String guid) {
if (guid != null) {
enumDefs.removeTypeDefByGuid(guid);
structDefs.removeTypeDefByGuid(guid);
classificationDefs.removeTypeDefByGuid(guid);
entityDefs.removeTypeDefByGuid(guid);
}
}
void removeByName(String typeName) {
if (typeName != null) {
enumDefs.removeTypeDefByName(typeName);
structDefs.removeTypeDefByName(typeName);
classificationDefs.removeTypeDefByName(typeName);
entityDefs.removeTypeDefByName(typeName);
}
}
}
public static class AtlasTransientTypeRegistry extends AtlasTypeRegistry {
......@@ -227,6 +253,19 @@ public class AtlasTypeRegistry {
}
}
public void updateGuid(String typeName, String guid) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.updateGuid({}, {})", typeName, guid);
}
registryData.updateGuid(typeName, guid);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.updateGuid({}, {})", typeName, guid);
}
}
public void addTypes(Collection<? extends AtlasBaseTypeDef> typeDefs) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addTypes(length={})", (typeDefs == null ? 0 : typeDefs.size()));
......@@ -351,10 +390,7 @@ public class AtlasTypeRegistry {
}
if (guid != null) {
registryData.enumDefs.removeTypeDefByGuid(guid);
registryData.structDefs.removeTypeDefByGuid(guid);
registryData.classificationDefs.removeTypeDefByGuid(guid);
registryData.entityDefs.removeTypeDefByGuid(guid);
registryData.removeByGuid(guid);
resolveReferences();
}
......@@ -370,10 +406,7 @@ public class AtlasTypeRegistry {
}
if (name != null) {
registryData.enumDefs.removeTypeDefByName(name);
registryData.structDefs.removeTypeDefByName(name);
registryData.classificationDefs.removeTypeDefByName(name);
registryData.entityDefs.removeTypeDefByName(name);
registryData.removeByName(name);
resolveReferences();
}
......@@ -390,10 +423,6 @@ public class AtlasTypeRegistry {
}
if (typeDef != null) {
if (StringUtils.isBlank(typeDef.getGuid())) {
typeDef.setGuid(UUID.randomUUID().toString());
}
if (typeDef.getClass().equals(AtlasEnumDef.class)) {
AtlasEnumDef enumDef = (AtlasEnumDef) typeDef;
......@@ -599,6 +628,20 @@ class TypeCache {
return ret;
}
public void updateGuid(String typeName, String currGuid, String newGuid) {
if (currGuid != null) {
typeGuidMap.remove(currGuid);
}
if (typeName != null && newGuid != null) {
AtlasType type = typeNameMap.get(typeName);
if (type != null) {
typeGuidMap.put(newGuid, type);
}
}
}
public void removeTypeByGuid(String guid) {
if (guid != null) {
typeGuidMap.remove(guid);
......@@ -659,6 +702,30 @@ class TypeDefCache<T extends AtlasBaseTypeDef> {
return ret;
}
public void updateGuid(String typeName, String newGuid) {
if (typeName != null) {
T typeDef = typeDefNameMap.get(typeName);
if (typeDef != null) {
String currGuid = typeDef.getGuid();
if (!StringUtils.equals(currGuid, newGuid)) {
if (currGuid != null) {
typeDefGuidMap.remove(currGuid);
}
typeDef.setGuid(newGuid);
if (newGuid != null) {
typeDefGuidMap.put(newGuid, typeDef);
}
typeCache.updateGuid(typeName, currGuid, newGuid);
}
}
}
}
public void removeTypeDefByGuid(String guid) {
if (guid != null) {
T typeDef = typeDefGuidMap.remove(guid);
......
......@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1232 added preCreate(), preDelete() in typedef persistence, to enable edge creation for references in a later stage (mneethiraj)
ATLAS-1183 UI: help link should point to atlas website (kevalbhatt via shwethags)
ATLAS-1182 Hive Column level lineage docs (svimal2106 via shwethags)
ATLAS-1230 updated AtlasTypeRegistry to support batch, atomic type updates (mneethiraj)
......
......@@ -28,9 +28,9 @@ import java.util.List;
* Interface for graph persistence store for AtlasClassificationDef
*/
public interface AtlasClassificationDefStore {
AtlasClassificationDef create(AtlasClassificationDef classificationDef) throws AtlasBaseException;
Object preCreate(AtlasClassificationDef classificationDef) throws AtlasBaseException;
List<AtlasClassificationDef> create(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException;
AtlasClassificationDef create(AtlasClassificationDef classifiDef, Object preCreateResult) throws AtlasBaseException;
List<AtlasClassificationDef> getAll() throws AtlasBaseException;
......@@ -38,19 +38,19 @@ public interface AtlasClassificationDefStore {
AtlasClassificationDef getByGuid(String guid) throws AtlasBaseException;
AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException;
AtlasClassificationDef update(AtlasClassificationDef classifiDef) throws AtlasBaseException;
AtlasClassificationDef updateByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException;
AtlasClassificationDef updateByName(String name, AtlasClassificationDef classifiDef) throws AtlasBaseException;
List<AtlasClassificationDef> update(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException;
AtlasClassificationDef updateByGuid(String guid, AtlasClassificationDef classifiDef) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
Object preDeleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
Object preDeleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
AtlasClassificationDefs search(SearchFilter filter) throws AtlasBaseException;
}
......@@ -19,6 +19,7 @@ package org.apache.atlas.repository.store.graph;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs;
......@@ -28,9 +29,9 @@ import java.util.List;
* Interface for graph persistence store for AtlasEntityDef
*/
public interface AtlasEntityDefStore {
AtlasEntityDef create(AtlasEntityDef entityDef) throws AtlasBaseException;
Object preCreate(AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> create(List<AtlasEntityDef> entityDefs) throws AtlasBaseException;
AtlasEntityDef create(AtlasEntityDef entityDef, Object preCreateResult) throws AtlasBaseException;
List<AtlasEntityDef> getAll() throws AtlasBaseException;
......@@ -38,19 +39,19 @@ public interface AtlasEntityDefStore {
AtlasEntityDef getByGuid(String guid) throws AtlasBaseException;
AtlasEntityDef update(AtlasEntityDef entityDef) throws AtlasBaseException;
AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException;
AtlasEntityDef updateByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> update(List<AtlasEntityDef> entityDefs) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
Object preDeleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
Object preDeleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
AtlasEntityDefs search(SearchFilter filter) throws AtlasBaseException;
}
......@@ -30,27 +30,21 @@ import java.util.List;
public interface AtlasEnumDefStore {
AtlasEnumDef create(AtlasEnumDef enumDef) throws AtlasBaseException;
List<AtlasEnumDef> create(List<AtlasEnumDef> atlasEnumDefs) throws AtlasBaseException;
List<AtlasEnumDef> getAll() throws AtlasBaseException;
AtlasEnumDef getByName(String name) throws AtlasBaseException;
AtlasEnumDef getByGuid(String guid) throws AtlasBaseException;
AtlasEnumDef update(AtlasEnumDef enumDef) throws AtlasBaseException;
AtlasEnumDef updateByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException;
AtlasEnumDef updateByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException;
List<AtlasEnumDef> update(List<AtlasEnumDef> enumDefs) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
AtlasEnumDefs search(SearchFilter filter) throws AtlasBaseException;
}
......@@ -28,9 +28,9 @@ import java.util.List;
* Interface for graph persistence store for AtlasStructDef
*/
public interface AtlasStructDefStore {
AtlasStructDef create(AtlasStructDef structDef) throws AtlasBaseException;
Object preCreate(AtlasStructDef structDef) throws AtlasBaseException;
List<AtlasStructDef> create(List<AtlasStructDef> structDefs) throws AtlasBaseException;
AtlasStructDef create(AtlasStructDef structDef, Object preCreateResult) throws AtlasBaseException;
List<AtlasStructDef> getAll() throws AtlasBaseException;
......@@ -38,19 +38,19 @@ public interface AtlasStructDefStore {
AtlasStructDef getByGuid(String guid) throws AtlasBaseException;
AtlasStructDef update(AtlasStructDef structDef) throws AtlasBaseException;
AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException;
AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException;
List<AtlasStructDef> update(List<AtlasStructDef> structDefs) throws AtlasBaseException;
void deleteByName(String name) throws AtlasBaseException;
Object preDeleteByName(String name) throws AtlasBaseException;
void deleteByNames(List<String> names) throws AtlasBaseException;
void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException;
void deleteByGuid(String guid) throws AtlasBaseException;
Object preDeleteByGuid(String name) throws AtlasBaseException;
void deleteByGuids(List<String> guids) throws AtlasBaseException;
void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException;
AtlasStructDefs search(SearchFilter filter) throws AtlasBaseException;
}
......@@ -35,6 +35,7 @@ import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -87,19 +88,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
AtlasEnumDef ret = getEnumDefStore(ttr).create(enumDef);
typeRegistry.commitTransientTypeRegistry(ttr);
return ret;
}
@Override
@GraphTransaction
public List<AtlasEnumDef> createEnumDefs(List<AtlasEnumDef> enumDefs) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
ttr.addTypes(enumDefs);
List<AtlasEnumDef> ret = getEnumDefStore(ttr).create(enumDefs);
ttr.updateGuid(ret.getName(), ret.getGuid());
typeRegistry.commitTransientTypeRegistry(ttr);
......@@ -201,21 +190,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.addType(structDef);
AtlasStructDef ret = getStructDefStore(ttr).create(structDef);
AtlasStructDef ret = getStructDefStore(ttr).create(structDef, null);
typeRegistry.commitTransientTypeRegistry(ttr);
return ret;
}
@Override
@GraphTransaction
public List<AtlasStructDef> createStructDefs(List<AtlasStructDef> structDefs) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
ttr.addTypes(structDefs);
List<AtlasStructDef> ret = getStructDefStore(ttr).create(structDefs);
ttr.updateGuid(ret.getName(), ret.getGuid());
typeRegistry.commitTransientTypeRegistry(ttr);
......@@ -287,7 +264,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.removeTypeByName(name);
getStructDefStore(ttr).deleteByName(name);
getStructDefStore(ttr).deleteByName(name, null);
typeRegistry.commitTransientTypeRegistry(ttr);
}
......@@ -299,7 +276,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.removeTypeByGuid(guid);
getStructDefStore(ttr).deleteByGuid(guid);
getStructDefStore(ttr).deleteByGuid(guid, null);
typeRegistry.commitTransientTypeRegistry(ttr);
}
......@@ -318,22 +295,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.addType(classificationDef);
AtlasClassificationDef ret = getClassificationDefStore(ttr).create(classificationDef);
typeRegistry.commitTransientTypeRegistry(ttr);
return ret;
}
@Override
@GraphTransaction
public List<AtlasClassificationDef> createClassificationDefs(List<AtlasClassificationDef> classificationDefs)
throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
ttr.addTypes(classificationDefs);
AtlasClassificationDef ret = getClassificationDefStore(ttr).create(classificationDef, null);
List<AtlasClassificationDef> ret = getClassificationDefStore(ttr).create(classificationDefs);
ttr.updateGuid(ret.getName(), ret.getGuid());
typeRegistry.commitTransientTypeRegistry(ttr);
......@@ -407,7 +371,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.removeTypeByName(name);
getClassificationDefStore(ttr).deleteByName(name);
getClassificationDefStore(ttr).deleteByName(name, null);
typeRegistry.commitTransientTypeRegistry(ttr);
}
......@@ -419,7 +383,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.removeTypeByGuid(guid);
getClassificationDefStore(ttr).deleteByGuid(guid);
getClassificationDefStore(ttr).deleteByGuid(guid, null);
typeRegistry.commitTransientTypeRegistry(ttr);
}
......@@ -437,21 +401,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.addType(entityDef);
AtlasEntityDef ret = getEntityDefStore(ttr).create(entityDef);
typeRegistry.commitTransientTypeRegistry(ttr);
return ret;
}
@Override
@GraphTransaction
public List<AtlasEntityDef> createEntityDefs(List<AtlasEntityDef> entityDefs) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
ttr.addTypes(entityDefs);
AtlasEntityDef ret = getEntityDefStore(ttr).create(entityDef, null);
List<AtlasEntityDef> ret = getEntityDefStore(ttr).create(entityDefs);
ttr.updateGuid(ret.getName(), ret.getGuid());
typeRegistry.commitTransientTypeRegistry(ttr);
......@@ -523,7 +475,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.removeTypeByName(name);
getEntityDefStore(ttr).deleteByName(name);
getEntityDefStore(ttr).deleteByName(name, null);
typeRegistry.commitTransientTypeRegistry(ttr);
}
......@@ -535,7 +487,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
ttr.removeTypeByGuid(guid);
getEntityDefStore(ttr).deleteByGuid(guid);
getEntityDefStore(ttr).deleteByGuid(guid, null);
typeRegistry.commitTransientTypeRegistry(ttr);
}
......@@ -549,39 +501,161 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override
@GraphTransaction
public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
LOG.info("Creating EnumDefs");
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={})",
CollectionUtils.size(typesDef.getEnumDefs()),
CollectionUtils.size(typesDef.getStructDefs()),
CollectionUtils.size(typesDef.getClassificationDefs()),
CollectionUtils.size(typesDef.getEntityDefs()));
}
AtlasTypesDef ret = new AtlasTypesDef();
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
ttr.addTypes(typesDef);
List<AtlasEnumDef> enumDefs = getEnumDefStore(ttr).create(typesDef.getEnumDefs());
List<AtlasStructDef> structDefs = getStructDefStore(ttr).create(typesDef.getStructDefs());
List<AtlasClassificationDef> classifiDefs = getClassificationDefStore(ttr).create(typesDef.getClassificationDefs());
List<AtlasEntityDef> entityDefs = getEntityDefStore(ttr).create(typesDef.getEntityDefs());
AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
AtlasStructDefStore structDefStore = getStructDefStore(ttr);
AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
List<Object> preCreateStructDefs = new ArrayList<>();
List<Object> preCreateClassifiDefs = new ArrayList<>();
List<Object> preCreateEntityDefs = new ArrayList<>();
AtlasTypesDef ret = new AtlasTypesDef(enumDefs, structDefs, classifiDefs, entityDefs);
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
AtlasEnumDef createdDef = enumDefStore.create(enumDef);
ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
ret.getEnumDefs().add(createdDef);
}
}
if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
preCreateStructDefs.add(structDefStore.preCreate(structDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
preCreateClassifiDefs.add(classifiDefStore.preCreate(classifiDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
preCreateEntityDefs.add(entityDefStore.preCreate(entityDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
int i = 0;
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
AtlasStructDef createdDef = structDefStore.create(structDef, preCreateStructDefs.get(i));
ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
ret.getStructDefs().add(createdDef);
i++;
}
}
if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
int i = 0;
for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
AtlasClassificationDef createdDef = classifiDefStore.create(classifiDef, preCreateClassifiDefs.get(i));
ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
ret.getClassificationDefs().add(createdDef);
i++;
}
}
if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
int i = 0;
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
AtlasEntityDef createdDef = entityDefStore.create(entityDef, preCreateEntityDefs.get(i));
ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
ret.getEntityDefs().add(createdDef);
i++;
}
}
typeRegistry.commitTransientTypeRegistry(ttr);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={})",
CollectionUtils.size(typesDef.getEnumDefs()),
CollectionUtils.size(typesDef.getStructDefs()),
CollectionUtils.size(typesDef.getClassificationDefs()),
CollectionUtils.size(typesDef.getEntityDefs()));
}
return ret;
}
@Override
@GraphTransaction
public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
LOG.info("Updating EnumDefs");
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()));
}
AtlasTypesDef ret = new AtlasTypesDef();
AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry();
ttr.updateTypes(typesDef);
List<AtlasEnumDef> enumDefs = getEnumDefStore(ttr).update(typesDef.getEnumDefs());
List<AtlasStructDef> structDefs = getStructDefStore(ttr).update(typesDef.getStructDefs());
List<AtlasClassificationDef> classifiDefs = getClassificationDefStore(ttr).update(typesDef.getClassificationDefs());
List<AtlasEntityDef> entityDefs = getEntityDefStore(ttr).update(typesDef.getEntityDefs());
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));
}
}
typeRegistry.commitTransientTypeRegistry(ttr);
AtlasTypesDef ret = new AtlasTypesDef(enumDefs, structDefs, classifiDefs, entityDefs);
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;
......@@ -589,6 +663,117 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@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 = typeRegistry.createTransientTypeRegistry();
ttr.addTypes(typesDef);
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());
}
}
}
typeRegistry.commitTransientTypeRegistry(ttr);
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()));
}
}
@Override
@GraphTransaction
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
AtlasTypesDef typesDef = new AtlasTypesDef();
Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);
......
......@@ -31,6 +31,7 @@ import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -49,45 +50,57 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
@Override
public AtlasClassificationDef create(AtlasClassificationDef classificationDef) throws AtlasBaseException {
public AtlasVertex preCreate(AtlasClassificationDef classificationDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.create({})", classificationDef);
LOG.debug("==> AtlasClassificationDefStoreV1.preCreate({})", classificationDef);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByName(classificationDef.getName());
AtlasType type = typeRegistry.getType(classificationDef.getName());
if (vertex != null) {
throw new AtlasBaseException(classificationDef.getName() + ": type already exists");
if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) {
throw new AtlasBaseException(classificationDef.getName() + ": not a classification type");
}
vertex = typeDefStore.createTypeVertex(classificationDef);
AtlasVertex ret = typeDefStore.findTypeVertexByName(classificationDef.getName());
toVertex(classificationDef, vertex);
if (ret != null) {
throw new AtlasBaseException(classificationDef.getName() + ": type already exists");
}
AtlasClassificationDef ret = toClassificationDef(vertex);
ret = typeDefStore.createTypeVertex(classificationDef);
updateVertexPreCreate(classificationDef, (AtlasClassificationType)type, ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.create({}): {}", classificationDef, ret);
LOG.debug("<== AtlasClassificationDefStoreV1.preCreate({}): {}", classificationDef, ret);
}
return ret;
}
@Override
public List<AtlasClassificationDef> create(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException {
public AtlasClassificationDef create(AtlasClassificationDef classificationDef, Object preCreateResult)
throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.create({})", classificationDefs);
LOG.debug("==> AtlasClassificationDefStoreV1.create({}, {})", classificationDef, preCreateResult);
}
List<AtlasClassificationDef> ret = new ArrayList<>();
AtlasVertex vertex;
for (AtlasClassificationDef classificationDef : classificationDefs) {
ret.add(create(classificationDef));
if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
vertex = preCreate(classificationDef);
} else {
vertex = (AtlasVertex)preCreateResult;
}
updateVertexAddReferences(classificationDef, vertex);
AtlasClassificationDef ret = toClassificationDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.create({}, {})", classificationDefs, ret);
LOG.debug("<== AtlasClassificationDefStoreV1.create({}, {}): {}", classificationDef, preCreateResult, ret);
}
return ret;
}
......@@ -155,18 +168,42 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
@Override
public AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException {
public AtlasClassificationDef update(AtlasClassificationDef classifiDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.update({})", classifiDef);
}
AtlasClassificationDef ret = StringUtils.isNotBlank(classifiDef.getName())
? updateByName(classifiDef.getName(), classifiDef) : updateByGuid(classifiDef.getGuid(), classifiDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.update({}): {}", classifiDef, ret);
}
return ret;
}
@Override
public AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef)
throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.updateByName({}, {})", name, classificationDef);
}
AtlasType type = typeRegistry.getType(classificationDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) {
throw new AtlasBaseException(classificationDef.getName() + ": not a struct type");
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with name " + name);
}
toVertex(classificationDef, vertex);
updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex);
updateVertexAddReferences(classificationDef, vertex);
AtlasClassificationDef ret = toClassificationDef(vertex);
......@@ -183,13 +220,20 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
LOG.debug("==> AtlasClassificationDefStoreV1.updateByGuid({})", guid);
}
AtlasType type = typeRegistry.getTypeByGuid(guid);
if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) {
throw new AtlasBaseException(classificationDef.getName() + ": not a struct type");
}
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with guid " + guid);
}
toVertex(classificationDef, vertex);
updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex);
updateVertexAddReferences(classificationDef, vertex);
AtlasClassificationDef ret = toClassificationDef(vertex);
......@@ -201,34 +245,38 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
@Override
public List<AtlasClassificationDef> update(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException {
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.update({})", classificationDefs);
LOG.debug("==> AtlasClassificationDefStoreV1.preDeleteByName({})", name);
}
List<AtlasClassificationDef> ret = new ArrayList<>();
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
for (AtlasClassificationDef classificationDef : classificationDefs) {
ret.add(updateByName(classificationDef.getName(), classificationDef));
if (ret == null) {
throw new AtlasBaseException("no classificationDef exists with name " + name);
}
typeDefStore.deleteTypeVertexOutEdges(ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.update({}): {}", classificationDefs, ret);
LOG.debug("<== AtlasClassificationDefStoreV1.preDeleteByName({}): ret=", name, ret);
}
return ret;
}
@Override
public void deleteByName(String name) throws AtlasBaseException {
public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.deleteByName({})", name);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
AtlasVertex vertex;
if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with name " + name);
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByName(name);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
......@@ -239,30 +287,38 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
@Override
public void deleteByNames(List<String> names) throws AtlasBaseException {
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.deleteByNames({})", names);
LOG.debug("==> AtlasClassificationDefStoreV1.preDeleteByGuid({})", guid);
}
for (String name : names) {
deleteByName(name);
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
if (ret == null) {
throw new AtlasBaseException("no classificationDef exists with guid " + guid);
}
typeDefStore.deleteTypeVertexOutEdges(ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.deleteByNames({})", names);
LOG.debug("<== AtlasClassificationDefStoreV1.preDeleteByGuid({}): ret=", guid, ret);
}
return ret;
}
@Override
public void deleteByGuid(String guid) throws AtlasBaseException {
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.deleteByGuid({})", guid);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
AtlasVertex vertex;
if (vertex == null) {
throw new AtlasBaseException("no classificationDef exists with guid " + guid);
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByGuid(guid);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
......@@ -273,28 +329,12 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
@Override
public void deleteByGuids(List<String> guids) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.deleteByGuids({})", guids);
}
for (String guid : guids) {
deleteByGuid(guid);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasClassificationDefStoreV1.deleteByGuids({})", guids);
}
}
@Override
public AtlasClassificationDefs search(SearchFilter filter) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasClassificationDefStoreV1.search({})", filter);
}
List<AtlasClassificationDef> classificationDefs = new ArrayList<AtlasClassificationDef>();
List<AtlasClassificationDef> classificationDefs = new ArrayList<>();
Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.TRAIT);
while(vertices.hasNext()) {
......@@ -317,17 +357,22 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
return ret;
}
private void toVertex(AtlasClassificationDef classificationDef, AtlasVertex vertex) throws AtlasBaseException {
AtlasType type = typeRegistry.getType(classificationDef.getName());
private void updateVertexPreCreate(AtlasClassificationDef classificationDef,
AtlasClassificationType classificationType,
AtlasVertex vertex) {
AtlasStructDefStoreV1.updateVertexPreCreate(classificationDef, classificationType, vertex);
}
if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) {
throw new AtlasBaseException(classificationDef.getName() + ": not a classification type");
}
private void updateVertexPreUpdate(AtlasClassificationDef classificationDef,
AtlasClassificationType classificationType,
AtlasVertex vertex) {
AtlasStructDefStoreV1.updateVertexPreUpdate(classificationDef, classificationType, vertex);
}
AtlasStructDefStoreV1.toVertex(classificationDef, (AtlasClassificationType)type,
vertex, typeDefStore, typeRegistry);
private void updateVertexAddReferences(AtlasClassificationDef classificationDef, AtlasVertex vertex) throws AtlasBaseException {
AtlasStructDefStoreV1.updateVertexAddReferences(classificationDef, vertex, typeDefStore);
typeDefStore.createSuperTypeEdges(vertex, classificationDef.getSuperTypes());
typeDefStore.createSuperTypeEdges(vertex, classificationDef.getSuperTypes(), TypeCategory.TRAIT);
}
private AtlasClassificationDef toClassificationDef(AtlasVertex vertex) throws AtlasBaseException {
......
......@@ -30,6 +30,7 @@ import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -48,43 +49,56 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public AtlasEntityDef create(AtlasEntityDef entityDef) throws AtlasBaseException {
public AtlasVertex preCreate(AtlasEntityDef entityDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.create({})", entityDef);
LOG.debug("==> AtlasEntityDefStoreV1.preCreate({})", entityDef);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByName(entityDef.getName());
AtlasType type = typeRegistry.getType(entityDef.getName());
if (vertex != null) {
throw new AtlasBaseException(entityDef.getName() + ": type already exists");
if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) {
throw new AtlasBaseException(entityDef.getName() + ": not an entity type");
}
vertex = typeDefStore.createTypeVertex(entityDef);
AtlasVertex ret = typeDefStore.findTypeVertexByName(entityDef.getName());
if (ret != null) {
throw new AtlasBaseException(entityDef.getName() + ": type already exists");
}
toVertex(entityDef, vertex);
ret = typeDefStore.createTypeVertex(entityDef);
AtlasEntityDef ret = toEntityDef(vertex);
updateVertexPreCreate(entityDef, (AtlasEntityType)type, ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.create({}): {}", entityDef, ret);
LOG.debug("<== AtlasEntityDefStoreV1.preCreate({}): {}", entityDef, ret);
}
return ret;
}
@Override
public List<AtlasEntityDef> create(List<AtlasEntityDef> entityDefs) throws AtlasBaseException {
public AtlasEntityDef create(AtlasEntityDef entityDef, Object preCreateResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.create({})", entityDefs);
LOG.debug("==> AtlasEntityDefStoreV1.create({}, {})", entityDef, preCreateResult);
}
List<AtlasEntityDef> ret = new ArrayList<>();
for (AtlasEntityDef entityDef : entityDefs) {
ret.add(create(entityDef));
AtlasVertex vertex;
if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
vertex = preCreate(entityDef);
} else {
vertex = (AtlasVertex)preCreateResult;
}
updateVertexAddReferences(entityDef, vertex);
AtlasEntityDef ret = toEntityDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.create({}, {})", entityDefs, ret);
LOG.debug("<== AtlasEntityDefStoreV1.create({}, {}): {}", entityDef, preCreateResult, ret);
}
return ret;
}
......@@ -153,18 +167,41 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public AtlasEntityDef update(AtlasEntityDef entityDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.update({})", entityDef);
}
AtlasEntityDef ret = StringUtils.isNotBlank(entityDef.getName()) ? updateByName(entityDef.getName(), entityDef)
: updateByGuid(entityDef.getGuid(), entityDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.update({}): {}", entityDef, ret);
}
return ret;
}
@Override
public AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.updateByName({}, {})", name, entityDef);
}
AtlasType type = typeRegistry.getType(entityDef.getName());
if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) {
throw new AtlasBaseException(entityDef.getName() + ": not an entity type");
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS);
if (vertex == null) {
throw new AtlasBaseException("no entityDef exists with name " + name);
}
toVertex(entityDef, vertex);
updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex);
updateVertexAddReferences(entityDef, vertex);
AtlasEntityDef ret = toEntityDef(vertex);
......@@ -181,13 +218,20 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
LOG.debug("==> AtlasEntityDefStoreV1.updateByGuid({})", guid);
}
AtlasType type = typeRegistry.getTypeByGuid(guid);
if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) {
throw new AtlasBaseException(entityDef.getName() + ": not an entity type");
}
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS);
if (vertex == null) {
throw new AtlasBaseException("no entityDef exists with guid " + guid);
}
toVertex(entityDef, vertex);
updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex);
updateVertexAddReferences(entityDef, vertex);
AtlasEntityDef ret = toEntityDef(vertex);
......@@ -199,89 +243,86 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public List<AtlasEntityDef> update(List<AtlasEntityDef> entityDefs) throws AtlasBaseException {
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.update({})", entityDefs);
LOG.debug("==> AtlasEntityDefStoreV1.preDeleteByName({})", name);
}
List<AtlasEntityDef> ret = new ArrayList<>();
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS);
for (AtlasEntityDef entityDef : entityDefs) {
ret.add(updateByName(entityDef.getName(), entityDef));
if (ret == null) {
throw new AtlasBaseException("no entityDef exists with name " + name);
}
typeDefStore.deleteTypeVertexOutEdges(ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.update({}): {}", entityDefs, ret);
LOG.debug("<== AtlasEntityDefStoreV1.preDeleteByName({}): {}", name, ret);
}
return ret;
}
@Override
public void deleteByName(String name) throws AtlasBaseException {
public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.deleteByName({})", name);
LOG.debug("==> AtlasEntityDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS);
AtlasVertex vertex;
if (vertex == null) {
throw new AtlasBaseException("no entityDef exists with name " + name);
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByName(name);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.deleteByName({})", name);
}
}
@Override
public void deleteByNames(List<String> names) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.deleteByNames({})", names);
}
for (String name : names) {
deleteByName(name);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.deleteByNames({})", names);
LOG.debug("<== AtlasEntityDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
}
@Override
public void deleteByGuid(String guid) throws AtlasBaseException {
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.deleteByGuid({})", guid);
LOG.debug("==> AtlasEntityDefStoreV1.preDeleteByGuid({})", guid);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS);
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS);
if (vertex == null) {
if (ret == null) {
throw new AtlasBaseException("no entityDef exists with guid " + guid);
}
typeDefStore.deleteTypeVertex(vertex);
typeDefStore.deleteTypeVertexOutEdges(ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.deleteByGuid({})", guid);
LOG.debug("<== AtlasEntityDefStoreV1.preDeleteByGuid({}): {}", guid, ret);
}
return ret;
}
@Override
public void deleteByGuids(List<String> guids) throws AtlasBaseException {
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEntityDefStoreV1.deleteByGuids({})", guids);
LOG.debug("==> AtlasEntityDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
for (String guid : guids) {
deleteByGuid(guid);
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByGuid(guid);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEntityDefStoreV1.deleteByGuids({})", guids);
LOG.debug("<== AtlasEntityDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
}
......@@ -291,7 +332,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
LOG.debug("==> AtlasEntityDefStoreV1.search({})", filter);
}
List<AtlasEntityDef> entityDefs = new ArrayList<AtlasEntityDef>();
List<AtlasEntityDef> entityDefs = new ArrayList<>();
Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.CLASS);
while(vertices.hasNext()) {
......@@ -314,16 +355,18 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
return ret;
}
private void toVertex(AtlasEntityDef entityDef, AtlasVertex vertex) throws AtlasBaseException {
AtlasType type = typeRegistry.getType(entityDef.getName());
private void updateVertexPreCreate(AtlasEntityDef entityDef, AtlasEntityType entityType, AtlasVertex vertex) {
AtlasStructDefStoreV1.updateVertexPreCreate(entityDef, entityType, vertex);
}
if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) {
throw new AtlasBaseException(entityDef.getName() + ": not a entity type");
}
private void updateVertexPreUpdate(AtlasEntityDef entityDef, AtlasEntityType entityType, AtlasVertex vertex) {
AtlasStructDefStoreV1.updateVertexPreUpdate(entityDef, entityType, vertex);
}
AtlasStructDefStoreV1.toVertex(entityDef, (AtlasEntityType)type, vertex, typeDefStore, typeRegistry);
private void updateVertexAddReferences(AtlasEntityDef entityDef, AtlasVertex vertex) throws AtlasBaseException {
AtlasStructDefStoreV1.updateVertexAddReferences(entityDef, vertex, typeDefStore);
typeDefStore.createSuperTypeEdges(vertex, entityDef.getSuperTypes());
typeDefStore.createSuperTypeEdges(vertex, entityDef.getSuperTypes(), TypeCategory.CLASS);
}
private AtlasEntityDef toEntityDef(AtlasVertex vertex) throws AtlasBaseException {
......
......@@ -26,6 +26,7 @@ import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasEnumDefStore;
import org.apache.atlas.repository.util.FilterUtil;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.commons.collections.CollectionUtils;
......@@ -73,25 +74,6 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
}
@Override
public List<AtlasEnumDef> create(List<AtlasEnumDef> enumDefs) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.create({})", enumDefs);
}
List<AtlasEnumDef> ret = new ArrayList<>();
for (AtlasEnumDef enumDef : enumDefs) {
ret.add(create(enumDef));
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.create({}): {}", enumDefs, ret);
}
return ret;
}
@Override
public List<AtlasEnumDef> getAll() throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.getAll()");
......@@ -156,6 +138,22 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
}
@Override
public AtlasEnumDef update(AtlasEnumDef enumDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.update({})", enumDef);
}
AtlasEnumDef ret = StringUtils.isNotBlank(enumDef.getGuid()) ? updateByGuid(enumDef.getGuid(), enumDef)
: updateByName(enumDef.getName(), enumDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.update({}): {}", enumDef, ret);
}
return ret;
}
@Override
public AtlasEnumDef updateByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.updateByName({}, {})", name, enumDef);
......@@ -202,25 +200,6 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
}
@Override
public List<AtlasEnumDef> update(List<AtlasEnumDef> enumDefs) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.update({})", enumDefs);
}
List<AtlasEnumDef> ret = new ArrayList<>();
for (AtlasEnumDef enumDef : enumDefs) {
ret.add(updateByName(enumDef.getName(), enumDef));
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.update({}): {}", enumDefs, ret);
}
return ret;
}
@Override
public void deleteByName(String name) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.deleteByName({})", name);
......@@ -240,21 +219,6 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
}
@Override
public void deleteByNames(List<String> names) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.deleteByNames({})", names);
}
for (String name : names) {
deleteByName(name);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.deleteByName({})", names);
}
}
@Override
public void deleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.deleteByGuid({})", guid);
......@@ -274,27 +238,12 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
}
@Override
public void deleteByGuids(List<String> guids) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.deleteByGuids({})", guids);
}
for (String guid : guids) {
deleteByGuid(guid);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasEnumDefStoreV1.deleteByGuids({})", guids);
}
}
@Override
public AtlasEnumDefs search(SearchFilter filter) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasEnumDefStoreV1.search({})", filter);
}
List<AtlasEnumDef> enumDefs = new ArrayList<AtlasEnumDef>();
List<AtlasEnumDef> enumDefs = new ArrayList<>();
Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.ENUM);
while(vertices.hasNext()) {
......
......@@ -34,14 +34,12 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasStructDefStore;
import org.apache.atlas.repository.util.FilterUtil;
import org.apache.atlas.type.AtlasArrayType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.compress.archivers.dump.DumpArchiveEntry;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -64,15 +62,9 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public AtlasStructDef create(AtlasStructDef structDef) throws AtlasBaseException {
public AtlasVertex preCreate(AtlasStructDef structDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.create({})", structDef);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByName(structDef.getName());
if (vertex != null) {
throw new AtlasBaseException(structDef.getName() + ": type already exists");
LOG.debug("==> AtlasStructDefStoreV1.preCreate({})", structDef);
}
AtlasType type = typeRegistry.getType(structDef.getName());
......@@ -81,32 +73,43 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
throw new AtlasBaseException(structDef.getName() + ": not a struct type");
}
vertex = typeDefStore.createTypeVertex(structDef);
AtlasVertex ret = typeDefStore.findTypeVertexByName(structDef.getName());
toVertex(structDef, (AtlasStructType)type, vertex, typeDefStore, typeRegistry);
if (ret != null) {
throw new AtlasBaseException(structDef.getName() + ": type already exists");
}
AtlasStructDef ret = toStructDef(vertex);
ret = typeDefStore.createTypeVertex(structDef);
AtlasStructDefStoreV1.updateVertexPreCreate(structDef, (AtlasStructType)type, ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.create({}): {}", structDef, ret);
LOG.debug("<== AtlasStructDefStoreV1.preCreate({}): {}", structDef, ret);
}
return ret;
}
@Override
public List<AtlasStructDef> create(List<AtlasStructDef> structDefs) throws AtlasBaseException {
public AtlasStructDef create(AtlasStructDef structDef, Object preCreateResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.create({})", structDefs);
LOG.debug("==> AtlasStructDefStoreV1.create({}, {})", structDef, preCreateResult);
}
List<AtlasStructDef> ret = new ArrayList<>();
for (AtlasStructDef structDef : structDefs) {
ret.add(create(structDef));
AtlasVertex vertex;
if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
vertex = preCreate(structDef);
} else {
vertex = (AtlasVertex)preCreateResult;
}
AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
AtlasStructDef ret = toStructDef(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.create({}, {})", structDefs, ret);
LOG.debug("<== AtlasStructDefStoreV1.create({}, {}): {}", structDef, preCreateResult, ret);
}
return ret;
......@@ -176,15 +179,25 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException {
public AtlasStructDef update(AtlasStructDef structDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.updateByName({}, {})", name, structDef);
LOG.debug("==> AtlasStructDefStoreV1.update({})", structDef);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
AtlasStructDef ret = StringUtils.isNotBlank(structDef.getName()) ? updateByName(structDef.getName(), structDef)
: updateByGuid(structDef.getGuid(), structDef);
if (vertex == null) {
throw new AtlasBaseException("no structDef exists with name " + name);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.update({}): {}", structDef, ret);
}
return ret;
}
@Override
public AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.updateByName({}, {})", name, structDef);
}
AtlasType type = typeRegistry.getType(structDef.getName());
......@@ -193,7 +206,14 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
throw new AtlasBaseException(structDef.getName() + ": not a struct type");
}
toVertex(structDef, (AtlasStructType)type, vertex);
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
if (vertex == null) {
throw new AtlasBaseException("no structDef exists with name " + name);
}
AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex);
AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
AtlasStructDef ret = toStructDef(vertex);
......@@ -210,19 +230,20 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
LOG.debug("==> AtlasStructDefStoreV1.updateByGuid({})", guid);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
AtlasType type = typeRegistry.getTypeByGuid(guid);
if (vertex == null) {
throw new AtlasBaseException("no structDef exists with guid " + guid);
if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) {
throw new AtlasBaseException(structDef.getName() + ": not a struct type");
}
AtlasType type = typeRegistry.getType(structDef.getName());
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) {
throw new AtlasBaseException(structDef.getName() + ": not a struct type");
if (vertex == null) {
throw new AtlasBaseException("no structDef exists with guid " + guid);
}
toVertex(structDef, (AtlasStructType)type, vertex);
AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex);
AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
AtlasStructDef ret = toStructDef(vertex);
......@@ -234,89 +255,86 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
@Override
public List<AtlasStructDef> update(List<AtlasStructDef> structDefs) throws AtlasBaseException {
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.update({})", structDefs);
LOG.debug("==> AtlasStructDefStoreV1.preDeleteByName({})", name);
}
List<AtlasStructDef> ret = new ArrayList<>();
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
for (AtlasStructDef structDef : structDefs) {
ret.add(updateByName(structDef.getName(), structDef));
if (ret == null) {
throw new AtlasBaseException("no structDef exists with name " + name);
}
typeDefStore.deleteTypeVertexOutEdges(ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.update({}): {}", structDefs, ret);
LOG.debug("<== AtlasStructDefStoreV1.preDeleteByName({}): {}", name, ret);
}
return ret;
}
@Override
public void deleteByName(String name) throws AtlasBaseException {
public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.deleteByName({})", name);
LOG.debug("==> AtlasStructDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
AtlasVertex vertex;
if (vertex == null) {
throw new AtlasBaseException("no structDef exists with name " + name);
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByName(name);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.deleteByName({})", name);
LOG.debug("<== AtlasStructDefStoreV1.deleteByName({}, {})", name, preDeleteResult);
}
}
@Override
public void deleteByNames(List<String> names) throws AtlasBaseException {
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.deleteByNames({})", names);
LOG.debug("==> AtlasStructDefStoreV1.preDeleteByGuid({})", guid);
}
for (String name : names) {
deleteByName(name);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.deleteByNames({})", names);
}
}
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
@Override
public void deleteByGuid(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.deleteByGuid({})", guid);
}
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
if (vertex == null) {
if (ret == null) {
throw new AtlasBaseException("no structDef exists with guid " + guid);
}
typeDefStore.deleteTypeVertex(vertex);
typeDefStore.deleteTypeVertexOutEdges(ret);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.deleteByGuid({})", guid);
LOG.debug("<== AtlasStructDefStoreV1.preDeleteByGuid({}): {}", guid, ret);
}
return ret;
}
@Override
public void deleteByGuids(List<String> guids) throws AtlasBaseException {
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasStructDefStoreV1.deleteByGuids({})", guids);
LOG.debug("==> AtlasStructDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
for (String guid : guids) {
deleteByGuid(guid);
AtlasVertex vertex;
if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
vertex = preDeleteByGuid(guid);
} else {
vertex = (AtlasVertex)preDeleteResult;
}
typeDefStore.deleteTypeVertex(vertex);
if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasStructDefStoreV1.deleteByGuids({})", guids);
LOG.debug("<== AtlasStructDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult);
}
}
......@@ -326,7 +344,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
LOG.debug("==> AtlasStructDefStoreV1.search({})", filter);
}
List<AtlasStructDef> structDefs = new ArrayList<AtlasStructDef>();
List<AtlasStructDef> structDefs = new ArrayList<>();
Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.STRUCT);
while (vertices.hasNext()) {
......@@ -349,10 +367,6 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
return ret;
}
private void toVertex(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex) {
toVertex(structDef, structType, vertex, typeDefStore, typeRegistry);
}
private AtlasStructDef toStructDef(AtlasVertex vertex) throws AtlasBaseException {
AtlasStructDef ret = null;
......@@ -363,8 +377,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
return ret;
}
public static void toVertex(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex,
AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) {
public static void updateVertexPreCreate(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex) {
List<String> attrNames = new ArrayList<>(structDef.getAttributeDefs().size());
for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
......@@ -373,11 +386,21 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasGraphUtilsV1.setProperty(vertex, propertyKey, toJsonFromAttributeDef(attributeDef, structType));
attrNames.add(attributeDef.getName());
addReferencesForAttribute(vertex, attributeDef, typeDefStore);
}
AtlasGraphUtilsV1.setProperty(vertex, AtlasGraphUtilsV1.getPropertyKey(structDef), attrNames);
}
public static void updateVertexPreUpdate(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex) {
AtlasStructDefStoreV1.updateVertexPreCreate(structDef, structType, vertex);
}
public static void updateVertexAddReferences(AtlasStructDef structDef, AtlasVertex vertex,
AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
addReferencesForAttribute(vertex, attributeDef, typeDefStore);
}
}
public static AtlasStructDef toStructDef(AtlasVertex vertex, AtlasStructDef structDef,
AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
AtlasStructDef ret = (structDef != null) ? structDef :new AtlasStructDef();
......@@ -402,7 +425,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef,
AtlasTypeDefGraphStoreV1 typeDefStore) {
AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());
String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
......@@ -412,14 +435,12 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName);
if (referencedTypeVertex == null) {
// create vertex?
throw new AtlasBaseException(referencedTypeName + ": unknown datatype");
}
if (referencedTypeVertex != null) {
String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName());
String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName());
typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label);
}
typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label);
}
}
}
......@@ -430,7 +451,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
String reverseAttribName = null;
if (isForeignKey) { // check if the referenced entity has foreignKeyRef to this attribute
AtlasType attribType = structType.getAttributeType(attributeDef.getTypeName());
AtlasType attribType = structType.getAttributeType(attributeDef.getName());
if (attribType.getTypeCategory() == AtlasType.TypeCategory.ARRAY) {
attribType = ((AtlasArrayType)attribType).getElementType();
......@@ -444,7 +465,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
boolean isComposite = isMappedFromRef || (isForeignKey && StringUtils.isBlank(reverseAttribName));
Map<String, Object> attribInfo = new HashMap<String, Object>();
Map<String, Object> attribInfo = new HashMap<>();
attribInfo.put("name", attributeDef.getName());
attribInfo.put("dataType", attributeDef.getTypeName());
......@@ -452,7 +473,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
attribInfo.put("isIndexable", attributeDef.isIndexable());
attribInfo.put("isComposite", isComposite);
attribInfo.put("reverseAttributeName", reverseAttribName);
Map<String, Object> multiplicity = new HashMap<String, Object>();
Map<String, Object> multiplicity = new HashMap<>();
multiplicity.put("lower", attributeDef.getValuesMinCount());
multiplicity.put("upper", attributeDef.getValuesMaxCount());
multiplicity.put("isUnique", AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality()));
......@@ -521,7 +542,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
if (isComposite) {
if (StringUtils.isNotBlank(refAttributeName)) { // ex: hive_table.columns, hive_column.table
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> params = new HashMap<>();
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_REF_ATTRIBUTE, refAttributeName);
ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_MAPPED_FROM_REF, params));
......
......@@ -198,6 +198,14 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
return ret;
}
public void deleteTypeVertexOutEdges(AtlasVertex vertex) throws AtlasBaseException {
Iterable<AtlasEdge> edges = vertex.getEdges(AtlasEdgeDirection.OUT);
for (AtlasEdge edge : edges) {
atlasGraph.removeEdge(edge);
}
}
public void deleteTypeVertex(AtlasVertex vertex) throws AtlasBaseException {
Iterator<AtlasEdge> inEdges = vertex.getEdges(AtlasEdgeDirection.IN).iterator();
......@@ -303,10 +311,10 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
return ret;
}
public void createSuperTypeEdges(AtlasVertex vertex, Set<String> superTypes) {
public void createSuperTypeEdges(AtlasVertex vertex, Set<String> superTypes, TypeCategory typeCategory) {
if (CollectionUtils.isNotEmpty(superTypes)) {
for (String superType : superTypes) {
AtlasVertex superTypeVertex = findTypeVertexByNameAndCategory(superType, TypeCategory.CLASS);
AtlasVertex superTypeVertex = findTypeVertexByNameAndCategory(superType, typeCategory);
getOrCreateEdge(vertex, superTypeVertex, AtlasGraphUtilsV1.SUPERTYPE_EDGE_LABEL);
}
......
......@@ -33,6 +33,7 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.web.util.Servlets;
import org.apache.http.annotation.Experimental;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -383,6 +384,7 @@ public class TypesREST {
@Path("/entitydef/name/{name}")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Experimental
public AtlasEntityDef updateEntityDefByName(@PathParam("name") String name, AtlasEntityDef entityDef) throws Exception {
AtlasEntityDef ret = null;
......@@ -395,6 +397,7 @@ public class TypesREST {
@Path("/entitydef/guid/{guid}")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Experimental
public AtlasEntityDef updateEntityDefByGuid(@PathParam("guid") String guid, AtlasEntityDef entityDef) throws Exception {
AtlasEntityDef ret = null;
......@@ -406,6 +409,7 @@ public class TypesREST {
@DELETE
@Path("/entitydef/name/{name}")
@Produces(Servlets.JSON_MEDIA_TYPE)
@Experimental
public void deleteEntityDef(@PathParam("name") String name) throws Exception {
typeDefStore.deleteEntityDefByName(name);
}
......@@ -413,6 +417,7 @@ public class TypesREST {
@DELETE
@Path("/entitydef/guid/{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE)
@Experimental
public void deleteEntityDefByGuid(@PathParam("guid") String guid) throws Exception {
typeDefStore.deleteEntityDefByGuid(guid);
}
......@@ -488,6 +493,7 @@ public class TypesREST {
@Path("/typedefs")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Experimental
public AtlasTypesDef updateAtlasTypeDefs(final AtlasTypesDef typesDef) throws Exception {
AtlasTypesDef ret = null;
......@@ -501,6 +507,24 @@ public class TypesREST {
}
/**
* Bulk delete API for all types
* @param typesDef A composite object that captures all types to be deleted
* @throws Exception
*/
@DELETE
@Path("/typedefs")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Experimental
public void deleteAtlasTypeDefs(final AtlasTypesDef typesDef) {
try {
typeDefStore.deleteTypesDef(typesDef);
} catch (AtlasBaseException ex) {
throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.NOT_MODIFIED));
}
}
/**
* Populate a SearchFilter on the basis of the Query Parameters
* @return
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment