public static AtlasEnumDef newEnumDef(AtlasTypeRegistry typesRegistry, boolean hasDefaultValue) { int enumDefIdx = IDX_ENUM_DEF.getAndIncrement(); AtlasEnumDef ret = new AtlasEnumDef(); ret.setName(PREFIX_ENUM_DEF + enumDefIdx); ret.setDescription(ret.getName()); int numElements = ThreadLocalRandom.current().nextInt(1, MAX_ENUM_ELEMENT_COUNT); for (int i = 0; i < numElements; i++) { String elementName = "element-" + i; ret.addElement(new AtlasEnumElementDef(elementName, elementName.toUpperCase(), i)); } if (hasDefaultValue) { int idxDefault = ThreadLocalRandom.current().nextInt(0, numElements); ret.setDefaultValue(ret.getElementDefs().get(idxDefault).getValue()); } AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create enum-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
public static AtlasEnumDef newEnumDef(AtlasTypeRegistry typesRegistry, boolean hasDefaultValue) { int enumDefIdx = IDX_ENUM_DEF.getAndIncrement(); AtlasEnumDef ret = new AtlasEnumDef(); ret.setName(PREFIX_ENUM_DEF + enumDefIdx); ret.setDescription(ret.getName()); int numElements = ThreadLocalRandom.current().nextInt(1, MAX_ENUM_ELEMENT_COUNT); for (int i = 0; i < numElements; i++) { String elementName = "element-" + i; ret.addElement(new AtlasEnumElementDef(elementName, elementName.toUpperCase(), i)); } if (hasDefaultValue) { int idxDefault = ThreadLocalRandom.current().nextInt(0, numElements); ret.setDefaultValue(ret.getElementDefs().get(idxDefault).getValue()); } AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create enum-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
@Test public void testNestedUpdates() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; String failureMsg = null; AtlasClassificationDef testTag1 = new AtlasClassificationDef("testTag1"); AtlasClassificationDef testTag2 = new AtlasClassificationDef("testTag2"); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addType(testTag1); // changes should not be seen in typeRegistry until lock is released assertFalse(typeRegistry.isRegisteredType(testTag1.getName()), "type added should be seen in typeRegistry only after commit"); boolean isNestedUpdateSuccess = addType(typeRegistry, testTag2); assertTrue(isNestedUpdateSuccess); // changes made in nested commit, inside addType(), should not be seen in typeRegistry until lock is released here assertFalse(typeRegistry.isRegisteredType(testTag2.getName()), "type added within nested commit should be seen in typeRegistry only after outer commit"); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg); assertTrue(typeRegistry.isRegisteredType(testTag1.getName())); assertTrue(typeRegistry.isRegisteredType(testTag2.getName())); }
AtlasTransientTypeRegistry ttr = registry.lockTypeRegistryForUpdate(); ttr.addType(entityDefA); ttr.addType(entityDefB); ttr.addType(entityDefC); ttr.addType(entityDefD); ttr.addType(entityDefE); ttr.addType(entityDefF); ttr.addType(classifyDef1); ttr.addType(classifyDef2); ttr.addType(classifyDef3); ttr.addType(classifyDef4); ttr.addType(classifyDef5); ttr.addType(classifyDef6); ttr.addType(classifyDef9); ttr.addType(classifyDef10); registry.releaseTypeRegistryForUpdate(ttr, true); ttr.addType(classifyDef7); fail("Fail disjoined parent case"); } catch (AtlasBaseException ae) { ttr.addType(classifyDef8); fail("Fail trying to add an entity type that is not in the parent"); } catch (AtlasBaseException ae) {
public static AtlasClassificationDef newClassificationDef(AtlasTypeRegistry typesRegistry, AtlasClassificationDef[] superTypes) { int classificationDefIdx = IDX_CLASSIFICATION_DEF.getAndIncrement(); AtlasClassificationDef ret = new AtlasClassificationDef(); ret.setName(PREFIX_CLASSIFICATION_DEF + classificationDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); if (superTypes != null) { for (AtlasClassificationDef superType : superTypes) { ret.addSuperType(superType.getName()); } } AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create classification-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
public static AtlasEntityDef newEntityDef(AtlasTypeRegistry typesRegistry, AtlasEntityDef[] superTypes) { int entDefIdx = IDX_ENTITY_DEF.getAndIncrement(); AtlasEntityDef ret = new AtlasEntityDef(); ret.setName(PREFIX_ENTITY_DEF + entDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); if (superTypes != null) { for (AtlasEntityDef superType : superTypes) { ret.addSuperType(superType.getName()); } } AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create entity-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
public static AtlasClassificationDef newClassificationDef(AtlasTypeRegistry typesRegistry, AtlasClassificationDef[] superTypes) { int classificationDefIdx = IDX_CLASSIFICATION_DEF.getAndIncrement(); AtlasClassificationDef ret = new AtlasClassificationDef(); ret.setName(PREFIX_CLASSIFICATION_DEF + classificationDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); if (superTypes != null) { for (AtlasClassificationDef superType : superTypes) { ret.addSuperType(superType.getName()); } } AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create classification-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
public static AtlasEntityDef newEntityDef(AtlasTypeRegistry typesRegistry, AtlasEntityDef[] superTypes) { int entDefIdx = IDX_ENTITY_DEF.getAndIncrement(); AtlasEntityDef ret = new AtlasEntityDef(); ret.setName(PREFIX_ENTITY_DEF + entDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); if (superTypes != null) { for (AtlasEntityDef superType : superTypes) { ret.addSuperType(superType.getName()); } } AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create entity-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
public static AtlasStructDef newStructDef(AtlasTypeRegistry typesRegistry) { int structDefIdx = IDX_STRUCT_DEF.getAndIncrement(); AtlasStructDef ret = new AtlasStructDef(); ret.setName(PREFIX_STRUCT_DEF + structDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create struct-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
@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"); }
public static AtlasStructDef newStructDef(AtlasTypeRegistry typesRegistry) { int structDefIdx = IDX_STRUCT_DEF.getAndIncrement(); AtlasStructDef ret = new AtlasStructDef(); ret.setName(PREFIX_STRUCT_DEF + structDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create struct-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
@Test public void testEntityDefInvalidHierarchy_Self() { AtlasEntityDef entDef1 = new AtlasEntityDef("entDef-1"); entDef1.addSuperType(entDef1.getName()); AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; String failureMsg = null; try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addType(entDef1); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNotNull(failureMsg, "expected invalid supertype failure"); }
@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"); }
private boolean addType(AtlasTypeRegistry typeRegistry, AtlasBaseTypeDef typeDef) { boolean ret = false; AtlasTransientTypeRegistry ttr = null; try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addType(typeDef); ret = true; } catch (AtlasBaseException excp) { // ignore } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, ret); } return ret; }