use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class AtlasTypeDefGraphStore method updateClassificationDefByGuid.
@Override
@GraphTransaction
public AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException {
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
tryUpdateByGUID(guid, classificationDef, ttr);
return getClassificationDefStore(ttr).updateByGuid(guid, classificationDef);
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class AtlasTypeDefGraphStore method createTypesDef.
@Override
@GraphTransaction
public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), CollectionUtils.size(typesDef.getEntityDefs()));
}
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
tryTypeCreation(typesDef, ttr);
AtlasTypesDef ret = addToGraphStore(typesDef, 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;
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class TestAtlasTypeRegistry method testRegistryValidityOnInvalidUpdate.
/* create 2 entity types: L0 and L1, with L0 as superType of L1
* add entity type L2, with L0, L1 and L2 as super-types - this should fail due to L2 self-referencing itself in super-types
* verify that after the update failure, the registry still has correct super-type/sub-type information for L0 and L1
*/
@Test
public void testRegistryValidityOnInvalidUpdate() {
AtlasEntityDef entL0 = new AtlasEntityDef("L0");
AtlasEntityDef entL1 = new AtlasEntityDef("L1");
entL1.addSuperType(entL0.getName());
entL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
entL1.addAttribute(new AtlasAttributeDef("L1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(entL0);
typesDef.getEntityDefs().add(entL1);
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
String failureMsg = null;
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addTypes(typesDef);
commit = true;
} catch (AtlasBaseException excp) {
failureMsg = excp.getMessage();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertNull(failureMsg);
validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1")));
validateSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0")));
validateSubTypes(typeRegistry, "L1", new HashSet<String>());
// create a circular reference
AtlasEntityDef entL2 = new AtlasEntityDef("L2");
entL2.addSuperType(entL0.getName());
entL2.addSuperType(entL1.getName());
entL2.addSuperType(entL2.getName());
typesDef.clear();
typesDef.getEntityDefs().add(entL2);
try {
commit = false;
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.updateTypes(typesDef);
commit = true;
} catch (AtlasBaseException excp) {
failureMsg = excp.getMessage();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertNotNull(failureMsg);
assertNull(typeRegistry.getEntityTypeByName("L2"));
validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1")));
validateSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0")));
validateSubTypes(typeRegistry, "L1", new HashSet<String>());
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class TestAtlasTypeRegistry method testEntityDefValidHierarchy.
/*
* L0
* / \
* / \
* L1_1---- L1_2
* / \ \ / \
* / \ \ / \
* L2_1 L2_2 L2_3 L2_4
*/
@Test
public void testEntityDefValidHierarchy() {
AtlasEntityDef entL0 = new AtlasEntityDef("L0");
AtlasEntityDef entL1_1 = new AtlasEntityDef("L1-1");
AtlasEntityDef entL1_2 = new AtlasEntityDef("L1-2");
AtlasEntityDef entL2_1 = new AtlasEntityDef("L2-1");
AtlasEntityDef entL2_2 = new AtlasEntityDef("L2-2");
AtlasEntityDef entL2_3 = new AtlasEntityDef("L2-3");
AtlasEntityDef entL2_4 = new AtlasEntityDef("L2-4");
entL1_1.addSuperType(entL0.getName());
entL1_2.addSuperType(entL0.getName());
entL2_1.addSuperType(entL1_1.getName());
entL2_2.addSuperType(entL1_1.getName());
entL2_3.addSuperType(entL1_1.getName());
entL2_3.addSuperType(entL1_2.getName());
entL2_4.addSuperType(entL1_2.getName());
entL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
entL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
entL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
entL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
entL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
entL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
entL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(entL0);
typesDef.getEntityDefs().add(entL1_1);
typesDef.getEntityDefs().add(entL1_2);
typesDef.getEntityDefs().add(entL2_1);
typesDef.getEntityDefs().add(entL2_2);
typesDef.getEntityDefs().add(entL2_3);
typesDef.getEntityDefs().add(entL2_4);
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
String failureMsg = null;
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addTypes(typesDef);
commit = true;
} catch (AtlasBaseException excp) {
failureMsg = excp.getMessage();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertNull(failureMsg);
validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());
validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class TestAtlasTypeRegistry method testClassificationDefInvalidHierarchy_Self.
@Test
public void testClassificationDefInvalidHierarchy_Self() {
AtlasClassificationDef classifiDef1 = new AtlasClassificationDef("classifiDef-1");
classifiDef1.addSuperType(classifiDef1.getName());
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
String failureMsg = null;
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addType(classifiDef1);
commit = true;
} catch (AtlasBaseException excp) {
failureMsg = excp.getMessage();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertNotNull(failureMsg, "expected invalid supertype failure");
}
Aggregations