本篇文章為大家展示了Apache Atlas是如何構(gòu)建自己的API,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司、阿圖什網(wǎng)絡(luò)推廣、微信平臺小程序開發(fā)、阿圖什網(wǎng)絡(luò)營銷、阿圖什企業(yè)策劃、阿圖什品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供阿圖什建站搭建服務(wù),24小時服務(wù)熱線:18982081108,官方網(wǎng)址:jinyejixie.com
Apache Atlas是一個優(yōu)秀的服務(wù)治理組件,用于企業(yè)Hadoop集群上的數(shù)據(jù)治理和元數(shù)據(jù)管理的數(shù)據(jù)治理工具。接下來我們將討論構(gòu)建自己的Java API,這些Java API可使用Apache atlas客戶端與Apache Atlas交互以在其中創(chuàng)建新的實(shí)體和類型。
以下依賴項(xiàng)可用于pom.xml文件
<dependency> <groupId>org.apache.atlas</groupId> <artifactId>atlas-client</artifactId> <version>0.7-incubating</version> </dependency> <dependency> <groupId>org.apache.atlas</groupId> <artifactId>atlas-typesystem</artifactId> <version>0.7-incubating</version> </dependency> <dependency> <groupId>org.apache.atlas</groupId> <artifactId>atlas-notification</artifactId> <version>0.7-incubating</version> </dependency> <dependency> <groupId>org.apache.atlas</groupId> <artifactId>atlas-repository</artifactId> <version>0.7-incubating</version> </dependency>
Apache Atlas客戶端使用atlas-application屬性在我們的API和Apache Atlas服務(wù)器之間建立連接。這些屬性應(yīng)放置在resources/atlas-application.properties中
######### Security Properties ######### # SSL config atlas.enableTLS=false ######### Server Properties ######### atlas.rest.address=http://192.168.5.95:21000 atlas.hook.demo.kafka.retries=1 atlas.kafka.zookeeper.connect=192.168.5.93:2181,192.168.5.94:2181,192.168.5.95:2181 atlas.kafka.bootstrap.servers=192.168.5.93:9092,192.168.5.94:9092,192.168.5.95:9092 atlas.kafka.zookeeper.session.timeout.ms=4000 atlas.kafka.zookeeper.connection.timeout.ms=2000 atlas.kafka.zookeeper.sync.time.ms=20 atlas.kafka.auto.commit.interval.ms=1000 atlas.kafka.hook.group.id=atlas
要與Apache atlas Server,baseUrl和用戶名創(chuàng)建連接,必須在AtlasClient構(gòu)造函數(shù)中傳遞密碼
final AtlasClient atlasClient = new AtlasClient (new String[]{"http://192.168.5.95:21000"}, new String[]{"admin", "admin"});
public class AtlasTypesTest { final AtlasClient atlasClient = new AtlasClient (new String[]{"http://192.168.5.95:21000"}, new String[]{"admin", "admin"}); static final String DATABASE_TYPE = "DB_Sync"; static final String COLUMN_TYPE = "Column_Sync"; static final String TABLE_TYPE = "Table_Sync"; static final String VIEW_TYPE = "View_Sync"; public static final String DB_ATTRIBUTE = "db"; static final String STORAGE_DESC_TYPE = "StorageDesc"; public static final String COLUMNS_ATTRIBUTE = "columns"; public static final String INPUT_TABLES_ATTRIBUTE = "inputTables"; private static final String[] TYPES = {DATABASE_TYPE, TABLE_TYPE, STORAGE_DESC_TYPE, COLUMN_TYPE, VIEW_TYPE, "JdbcAccess", "ETL", "Metric", "PII", "Fact", "Dimension", "Log Data"}; /** * 組織定義types * @return */ TypesDef createTypeDefinitions() { HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil .createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE, null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), attrDef("description", DataTypes.STRING_TYPE.getName()), attrDef("locationUri", DataTypes.STRING_TYPE.getName()), attrDef("owner", DataTypes.STRING_TYPE.getName()), attrDef("createTime", DataTypes.LONG_TYPE.getName())); HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil .createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE.getName()), attrDef("dataType", DataTypes.STRING_TYPE.getName()), attrDef("comment", DataTypes.STRING_TYPE.getName())); HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil .createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null), attrDef("owner", DataTypes.STRING_TYPE.getName()), attrDef("createTime", DataTypes.LONG_TYPE.getName()), attrDef("lastAccessTime", DataTypes.LONG_TYPE.getName()), attrDef("retention", DataTypes.LONG_TYPE.getName()), attrDef("viewOriginalText", DataTypes.STRING_TYPE.getName()), attrDef("viewExpandedText", DataTypes.STRING_TYPE.getName()), attrDef("tableType", DataTypes.STRING_TYPE.getName()), attrDef("temporary", DataTypes.BOOLEAN_TYPE.getName()), new AttributeDefinition(COLUMNS_ATTRIBUTE, DataTypes.arrayTypeName(COLUMN_TYPE), Multiplicity.COLLECTION, true, null)); HierarchicalTypeDefinition<ClassType> viewClsDef = TypesUtil .createClassTypeDef(VIEW_TYPE, VIEW_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("inputTables", DataTypes.arrayTypeName(TABLE_TYPE), Multiplicity.COLLECTION, false, null)); return TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(), ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, viewClsDef)); } private void createTypes() throws Exception { TypesDef typesDef = createTypeDefinitions(); String typesAsJSON = TypesSerialization.toJson(typesDef); System.out.println("typesAsJSON = " + typesAsJSON); atlasClient.createType(typesAsJSON); verifyTypesCreated(); } private void verifyTypesCreated() throws Exception { List<String> types = atlasClient.listTypes(); for (String type : TYPES) { assert types.contains(type); } } AttributeDefinition attrDef(String name, String dT) { return attrDef(name, dT, Multiplicity.OPTIONAL, false, null); } AttributeDefinition attrDef(String name, String dT, Multiplicity m, boolean isComposite, String reverseAttributeName) { return new AttributeDefinition(name, dT, m, isComposite, reverseAttributeName); } @Test public void createNewTypes() throws Exception { createTypes(); } }
public class AtlasEntitiesTest { final AtlasClient atlasClient = new AtlasClient (new String[]{"http://192.168.5.95:21000"}, new String[]{"admin", "admin"}); /** * 創(chuàng)建實(shí)例并返創(chuàng)建的Id對象 * @param referenceable * @return * @throws Exception */ private Id createInstance(Referenceable referenceable) throws Exception { String typeName = referenceable.getTypeName(); String entityJSON = InstanceSerialization.toJson(referenceable, true); System.out.println("Submitting new entity= " + entityJSON); List<String> guids = atlasClient.createEntity(entityJSON); System.out.println("created instance for type " + typeName + ", guid: " + guids); return new Id(guids.get(guids.size() - 1), referenceable.getId().getVersion(), referenceable.getTypeName()); } /** * 創(chuàng)建數(shù)據(jù)庫實(shí)例并返創(chuàng)建的數(shù)據(jù)庫Id對象 * @param name * @param description * @param owner * @param locationUri * @param traitNames * @return * @throws Exception */ Id database(String name, String description, String owner, String locationUri, String... traitNames) throws Exception { Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames); referenceable.set("name", name); referenceable.set("description", description); referenceable.set("owner", owner); referenceable.set("locationUri", locationUri); referenceable.set("createTime", System.currentTimeMillis()); return createInstance(referenceable); } /** * 創(chuàng)建列的實(shí)例并返創(chuàng)建的列的實(shí)例對象 * @param name * @param dataType * @param comment * @param traitNames * @return * @throws Exception */ Referenceable column(String name, String dataType, String comment, String... traitNames) throws Exception { Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames); referenceable.set("name", name); referenceable.set("dataType", dataType); referenceable.set("comment", comment); return referenceable; } /** * 創(chuàng)建表的實(shí)例并返創(chuàng)建的表的Id對象 * @param name * @param description * @param dbId * @param sd * @param owner * @param tableType * @param columns * @param traitNames * @return * @throws Exception */ Id table(String name, String description, Id dbId, Referenceable sd, String owner, String tableType, List<Referenceable> columns, String... traitNames) throws Exception { Referenceable referenceable = new Referenceable(TABLE_TYPE, traitNames); referenceable.set("name", name); referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name); referenceable.set("description", description); referenceable.set("owner", owner); referenceable.set("tableType", tableType); referenceable.set("createTime", System.currentTimeMillis()); referenceable.set("lastAccessTime", System.currentTimeMillis()); referenceable.set("retention", System.currentTimeMillis()); referenceable.set("db", dbId); referenceable.set("sd", sd); referenceable.set("columns", columns); return createInstance(referenceable); } /** * 創(chuàng)建視圖的實(shí)例并返創(chuàng)建的視圖的Id對象 * @param name * @param dbId * @param inputTables * @param traitNames * @return * @throws Exception */ Id view(String name, Id dbId, List<Id> inputTables, String... traitNames) throws Exception { Referenceable referenceable = new Referenceable(VIEW_TYPE, traitNames); referenceable.set("name", name); referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name); referenceable.set("db", dbId); referenceable.set(INPUT_TABLES_ATTRIBUTE, inputTables); return createInstance(referenceable); } /** * 原始存儲描述符 * @param location * @param inputFormat * @param outputFormat * @param compressed * @return * @throws Exception */ Referenceable storageDescriptor(String location, String inputFormat, String outputFormat, boolean compressed) throws Exception { Referenceable referenceable = new Referenceable(STORAGE_DESC_TYPE); referenceable.set("location", location); referenceable.set("inputFormat", inputFormat); referenceable.set("outputFormat", outputFormat); referenceable.set("compressed", compressed); return referenceable; } @Test public void createEntities() throws Exception { //創(chuàng)建數(shù)據(jù)庫實(shí)例 Id syncDB = database("sy_sync", "Sync Database", "root", ""); //存儲描述符 Referenceable sd = storageDescriptor("", "TextInputFormat", "TextOutputFormat", true); //創(chuàng)建列實(shí)例 //1、數(shù)據(jù)源 List<Referenceable> databaseColumns = ImmutableList .of(column("id", "long", "id"), column("name", "string", "name"), column("type", "string", "type"), column("url", "string", "url"), column("database_name", "string", "database name"), column("username", "string", "username"), column("password","string","password"), column("description", "string", "description"), column("create_time", "string", "create time"), column("update_time", "string", "update time"), column("create_id", "long", "user id"), column("update_id", "long", "user id")); //2、同步文件夾 List<Referenceable> syncFolderColumns = ImmutableList .of(column("id", "long", "id"), column("name", "string", "name"), column("description", "string", "description"), column("create_time", "string", "create time"), column("update_time", "string", "update time"), column("create_id", "long", "user id"), column("update_id", "long", "user id")); //創(chuàng)建表實(shí)例 Id database = table("datasource", "database table", syncDB, sd, "root", "External", databaseColumns); Id syncFolder = table("folder", "sync folder table", syncDB, sd, "root", "External", syncFolderColumns); //創(chuàng)建視圖實(shí)例 } @Test public void getEntity() throws AtlasServiceException { Referenceable referenceable = atlasClient.getEntity("1406ddd0-5d51-41d4-b174-859bd4f34a5b"); System.out.println(InstanceSerialization.toJson(referenceable, true)); } }
上述內(nèi)容就是Apache Atlas是如何構(gòu)建自己的API,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁名稱:ApacheAtlas是如何構(gòu)建自己的API
本文地址:http://jinyejixie.com/article24/pgidce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、響應(yīng)式網(wǎng)站、營銷型網(wǎng)站建設(shè)、微信小程序、網(wǎng)頁設(shè)計(jì)公司、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)