@Test public void testConstraintInValidInverseRef_InvalidAttributeType() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithInvalidInverseAttributeType()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - invalid refAttribute type"); }
@Test public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute"); }
@Test public void testConstraintInValidInverseRef_MissingParams() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithMissingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_MISSING_PARAMS, "expected invalid constraint failure - missing refAttribute"); }
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef);
@Test public void testValidConstraints() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); String failureMsg = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDef()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE); AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN); assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef()); assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName()); assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef()); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS)); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN); }
@Test public void testValidConstraints() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); String failureMsg = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDef()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE); AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN); assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef()); assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName()); assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef()); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS)); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN); }
private AtlasTypeRegistry getTypeRegistry() { AtlasTypeRegistry ret = new AtlasTypeRegistry(); AtlasEntityDef defReferenceable = new AtlasEntityDef(TYPENAME_REFERENCEABLE); AtlasEntityDef defAsset = new AtlasEntityDef(TYPENAME_ASSET); AtlasEntityDef defHdfsPath = new AtlasEntityDef(HDFS_PATH); AtlasEntityDef defHiveDb = new AtlasEntityDef(HIVE_DATABASE); AtlasEntityDef defHiveTable = new AtlasEntityDef(HIVE_TABLE); AtlasEntityDef defHiveColumn = new AtlasEntityDef(HIVE_COLUMN); AtlasEntityDef defHiveStorDesc = new AtlasEntityDef(HIVE_STORAGE_DESCRIPTOR); AtlasEntityDef defNonAsset = new AtlasEntityDef(TYPENAME_NON_ASSET); defAsset.addSuperType(TYPENAME_REFERENCEABLE); defHdfsPath.addSuperType(TYPENAME_ASSET); defHiveDb.addSuperType(TYPENAME_ASSET); defHiveTable.addSuperType(TYPENAME_ASSET); defHiveColumn.addSuperType(TYPENAME_ASSET); defNonAsset.addSuperType(TYPENAME_REFERENCEABLE); AtlasTypesDef typesDef = new AtlasTypesDef(); typesDef.setEntityDefs(Arrays.asList(defReferenceable, defAsset, defHdfsPath, defHiveDb, defHiveTable, defHiveColumn, defHiveStorDesc, defNonAsset)); try { AtlasTypeRegistry.AtlasTransientTypeRegistry ttr = ret.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef); ret.releaseTypeRegistryForUpdate(ttr, true); } catch (AtlasBaseException excp) { LOG.warn("failed to initialize type-registry", excp); } return ret; }
@Override public void init() throws AtlasBaseException { LOG.info("==> AtlasTypeDefGraphStore.init()"); AtlasTransientTypeRegistry ttr = null; boolean commitUpdates = false; try { ttr = typeRegistry.lockTypeRegistryForUpdate(typeUpdateLockMaxWaitTimeSeconds); ttr.clear(); AtlasTypesDef typesDef = new AtlasTypesDef(getEnumDefStore(ttr).getAll(), getStructDefStore(ttr).getAll(), getClassificationDefStore(ttr).getAll(), getEntityDefStore(ttr).getAll(), getRelationshipDefStore(ttr).getAll()); rectifyTypeErrorsIfAny(typesDef); ttr.addTypes(typesDef); commitUpdates = true; } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commitUpdates); LOG.info("<== AtlasTypeDefGraphStore.init()"); } }
@Test public void testConstraintInValidInverseRef_InvalidAttributeType() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithInvalidInverseAttributeType()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - invalid refAttribute type"); }
@Test public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute"); }
@Test public void testConstraintInValidInverseRef_NonExistingAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING, "expected invalid constraint failure - non-existing refAttribute"); }
@Test public void testConstraintInValidInverseRef_MissingParams() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithMissingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_MISSING_PARAMS, "expected invalid constraint failure - missing refAttribute"); }
@Test public void testConstraintInvalidOwnedRef_InvalidAttributeType() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDefWithOwnedRefOnInvalidType()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_OWNED_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute"); }
@Test public void testConstraintInvalidOwnedRef_InvalidAttributeType() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDefWithOwnedRefOnInvalidType()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_OWNED_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute"); }
@Test public void testConstraintInValidInverseRef_NonExistingAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING, "expected invalid constraint failure - non-existing refAttribute"); }
@Override public void init() throws AtlasBaseException { AtlasTransientTypeRegistry ttr = null; boolean commitUpdates = false; try { ttr = typeRegistry.lockTypeRegistryForUpdate(typeUpdateLockMaxWaitTimeSeconds); ttr.clear(); AtlasTypesDef typesDef = new AtlasTypesDef(getEnumDefStore(ttr).getAll(), getStructDefStore(ttr).getAll(), getClassificationDefStore(ttr).getAll(), getEntityDefStore(ttr).getAll(), getRelationshipDefStore(ttr).getAll()); rectifyTypeErrorsIfAny(typesDef); ttr.addTypes(typesDef); commitUpdates = true; } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commitUpdates); } }
private void tryTypeCreation(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException { // Translate any NOT FOUND errors to BAD REQUEST try { ttr.addTypes(typesDef); } catch (AtlasBaseException e) { if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode() || AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) { throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage()); } else { throw e; } } } }
private void createTypes(List<? extends AtlasBaseTypeDef> typeDefs) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typeDefs); typeRegistry.releaseTypeRegistryForUpdate(ttr, true); }
private void createTypes(List<? extends AtlasBaseTypeDef> typeDefs) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typeDefs); typeRegistry.releaseTypeRegistryForUpdate(ttr, true); }