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