Java Code Examples for org.apache.atlas.type.AtlasTypeRegistry#lockTypeRegistryForUpdate()

The following examples show how to use org.apache.atlas.type.AtlasTypeRegistry#lockTypeRegistryForUpdate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassificationAssociatorTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void updaterEntityWithUniqueName() throws IOException, AtlasBaseException {
    AtlasEntityDef ed = getAtlasEntityDefFromFile("col-entity-def-unique-name");

    AtlasEntityHeaders entityHeaderMap = getEntityHeaderMapFromFile("header-PII-no-qualifiedName");
    AtlasEntityStore entitiesStore = mock(AtlasEntityStore.class);
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTypeRegistry.AtlasTransientTypeRegistry ttr = typeRegistry.lockTypeRegistryForUpdate();
    ttr.addTypes(CollectionUtils.newSingletonArrayList(ed));
    AtlasGraph atlasGraph = mock(AtlasGraph.class);

    ClassificationAssociatorUpdaterForSpy updater = new ClassificationAssociatorUpdaterForSpy(atlasGraph, ttr, entitiesStore, "col-entity-PII");
    String summary = updater.setClassifications(entityHeaderMap.getGuidHeaderMap());

    TypeReference<String[]> typeReference = new TypeReference<String[]>() {};
    String[] summaryArray = AtlasJson.fromJson(summary, typeReference);
    assertEquals(summaryArray.length, 1);
    assertSummaryElement(summaryArray[0], "Update", STATUS_DONE, "PII");
}
 
Example 2
Source File: RestUtilsTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasTypeRegistry createRegistry(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
    AtlasTypeRegistry          reg = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry tmp = reg.lockTypeRegistryForUpdate();

    tmp.addTypes(toConvert);
    reg.releaseTypeRegistryForUpdate(tmp, true);

    return reg;
}
 
Example 3
Source File: ModelTestUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: ModelTestUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: ModelTestUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: ModelTestUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: TransformationHandlerTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: RestUtilsTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasTypeRegistry createRegistry(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
    AtlasTypeRegistry reg = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry tmp = reg.lockTypeRegistryForUpdate();
    tmp.addTypes(toConvert);
    reg.releaseTypeRegistryForUpdate(tmp, true);
    return reg;
}
 
Example 9
Source File: ModelTestUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: ModelTestUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: ModelTestUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: ModelTestUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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;
}