Commit 4301264e by Ballistar13

Updated the DemoDataDriver to pull the table objects from the system

after they are created so nesting works correctly.
parent a8ef4901
...@@ -62,7 +62,7 @@ public class DefaultMetadataService implements MetadataService { ...@@ -62,7 +62,7 @@ public class DefaultMetadataService implements MetadataService {
this.typeSystem = TypeSystem.getInstance(); this.typeSystem = TypeSystem.getInstance();
this.repository = repository; this.repository = repository;
registerListener(searchIndexer); //registerListener(searchIndexer);
} }
/** /**
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
package org.apache.hadoop.metadata; package org.apache.hadoop.metadata;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
...@@ -51,7 +55,8 @@ import java.util.Arrays; ...@@ -51,7 +55,8 @@ import java.util.Arrays;
public class DemoDataDriver { public class DemoDataDriver {
private static ArrayList<ITypedReferenceableInstance> tableArray; private static ArrayList<ITypedReferenceableInstance> initTableArray;
private static ArrayList<ITypedReferenceableInstance> postSaveTableArray;
private static ArrayList<ITypedReferenceableInstance> lineageArray; private static ArrayList<ITypedReferenceableInstance> lineageArray;
private static final Logger LOG = LoggerFactory private static final Logger LOG = LoggerFactory
...@@ -59,6 +64,7 @@ public class DemoDataDriver { ...@@ -59,6 +64,7 @@ public class DemoDataDriver {
private static final String DATABASE_TYPE = "hive_database"; private static final String DATABASE_TYPE = "hive_database";
private static final String TABLE_TYPE = "hive_table"; private static final String TABLE_TYPE = "hive_table";
private static final String LINEAGE_TYPE = "HiveLineage";
protected TypeSystem typeSystem; protected TypeSystem typeSystem;
protected WebResource service; protected WebResource service;
...@@ -115,9 +121,9 @@ public class DemoDataDriver { ...@@ -115,9 +121,9 @@ public class DemoDataDriver {
assert clientResponse.getStatus() == Response.Status.OK.getStatusCode(); assert clientResponse.getStatus() == Response.Status.OK.getStatusCode();
} }
public void getEntityList() throws Exception { public void getEntityList(String s) throws Exception {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/list/").path(TABLE_TYPE) .path("api/metadata/entities/list/").path(s)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class); .method(HttpMethod.GET, ClientResponse.class);
...@@ -130,6 +136,30 @@ public class DemoDataDriver { ...@@ -130,6 +136,30 @@ public class DemoDataDriver {
assert list != null; assert list != null;
assert list.length() > 0; assert list.length() > 0;
} }
public String getEntityReturnList(){
ClientResponse clientResponse = service
.path("api/metadata/entities/list/").path(TABLE_TYPE)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class);
assert clientResponse.getStatus() == Response.Status.OK.getStatusCode();
String responseAsString = clientResponse.getEntity(String.class);
return responseAsString;
}
public String getTableEntityByGUID(String guid) throws Exception {
ClientResponse clientResponse = service
.path("api/metadata/entities/definition/"+guid)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class);
assert clientResponse.getStatus() == Response.Status.OK.getStatusCode();
String responseAsString = clientResponse.getEntity(String.class);
return responseAsString;
}
private void createTypes() throws Exception { private void createTypes() throws Exception {
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = createClassTypeDef( HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = createClassTypeDef(
...@@ -171,8 +201,9 @@ public class DemoDataDriver { ...@@ -171,8 +201,9 @@ public class DemoDataDriver {
Multiplicity.REQUIRED, true, null), Multiplicity.REQUIRED, true, null),
createRequiredAttrDef("success", DataTypes.STRING_TYPE), createRequiredAttrDef("success", DataTypes.STRING_TYPE),
createRequiredAttrDef("executionEngine", DataTypes.STRING_TYPE), createRequiredAttrDef("executionEngine", DataTypes.STRING_TYPE),
new AttributeDefinition("sourceTables", DataTypes.arrayTypeName(TABLE_TYPE), new AttributeDefinition("sourceTables", DataTypes
Multiplicity.COLLECTION, true, "forwardLineage")); .arrayTypeName(TABLE_TYPE), Multiplicity.COLLECTION,
true, "forwardLineage"));
typeSystem.defineTypes(ImmutableList.of(structTypeDefinition), typeSystem.defineTypes(ImmutableList.of(structTypeDefinition),
ImmutableList.of(classificationTypeDefinition), ImmutableList ImmutableList.of(classificationTypeDefinition), ImmutableList
...@@ -184,9 +215,8 @@ public class DemoDataDriver { ...@@ -184,9 +215,8 @@ public class DemoDataDriver {
String tableTypesAsJSON = TypesSerialization.toJson( String tableTypesAsJSON = TypesSerialization.toJson(
typeSystem, typeSystem,
Arrays.asList(new String[] { DATABASE_TYPE, TABLE_TYPE, Arrays.asList(new String[] { DATABASE_TYPE, TABLE_TYPE,
"serdeType", "classification"})); "serdeType", "classification" }));
String lineageTypesAsJSON = TypesSerialization.toJson( String lineageTypesAsJSON = TypesSerialization.toJson(typeSystem,
typeSystem,
Arrays.asList(new String[] { "HiveLineage" })); Arrays.asList(new String[] { "HiveLineage" }));
sumbitType(tableTypesAsJSON, TABLE_TYPE); sumbitType(tableTypesAsJSON, TABLE_TYPE);
sumbitType(lineageTypesAsJSON, "HiveLineage"); sumbitType(lineageTypesAsJSON, "HiveLineage");
...@@ -257,7 +287,7 @@ public class DemoDataDriver { ...@@ -257,7 +287,7 @@ public class DemoDataDriver {
lineageInstance.set("success", success); lineageInstance.set("success", success);
lineageInstance.set("executionEngine", executionEngine); lineageInstance.set("executionEngine", executionEngine);
for (ITypedReferenceableInstance table : tableArray) { for (ITypedReferenceableInstance table : postSaveTableArray) {
if (table.get("name").equals(tableName)) { if (table.get("name").equals(tableName)) {
lineageInstance.set("tableName", table); lineageInstance.set("tableName", table);
break; break;
...@@ -266,8 +296,8 @@ public class DemoDataDriver { ...@@ -266,8 +296,8 @@ public class DemoDataDriver {
ArrayList<ITypedReferenceableInstance> sourceTablesRefArr = new ArrayList<ITypedReferenceableInstance>(); ArrayList<ITypedReferenceableInstance> sourceTablesRefArr = new ArrayList<ITypedReferenceableInstance>();
for (String s : sourceTables.split(",")) { for (String s : sourceTables.split(",")) {
System.out.println("search for table "+s); System.out.println("search for table " + s);
for (ITypedReferenceableInstance table : tableArray) { for (ITypedReferenceableInstance table : postSaveTableArray) {
if (table.get("name").equals(s)) { if (table.get("name").equals(s)) {
sourceTablesRefArr.add(table); sourceTablesRefArr.add(table);
} }
...@@ -290,17 +320,35 @@ public class DemoDataDriver { ...@@ -290,17 +320,35 @@ public class DemoDataDriver {
driver.createTypes(); driver.createTypes();
driver.submitTypes(); driver.submitTypes();
DemoDataDriver.tableArray = new ArrayList<ITypedReferenceableInstance>(); DemoDataDriver.initTableArray = new ArrayList<ITypedReferenceableInstance>();
DemoDataDriver.postSaveTableArray = new ArrayList<ITypedReferenceableInstance>();
DemoDataDriver.lineageArray = new ArrayList<ITypedReferenceableInstance>(); DemoDataDriver.lineageArray = new ArrayList<ITypedReferenceableInstance>();
String[][] tableData = getTestTableData(); String[][] tableData = getTestTableData();
//Create Table Objects
for (String[] row : tableData) { for (String[] row : tableData) {
ITypedReferenceableInstance tableInstance = driver ITypedReferenceableInstance tableInstance = driver
.createHiveTableInstance(row[0], row[1], row[2], row[3], .createHiveTableInstance(row[0], row[1], row[2], row[3],
row[4]); row[4]);
tableArray.add(tableInstance); initTableArray.add(tableInstance);
} }
//Save Table Objects
for (ITypedReferenceableInstance i : initTableArray) {
driver.submitEntity(i); }
//Returned the Saved Table Objects
JsonParser jp = new JsonParser();
JsonObject jo = (JsonObject) jp.parse(driver.getEntityReturnList());
JsonArray ja = jo.getAsJsonArray("list");
for (JsonElement e : ja){
JsonObject joInner = (JsonObject)jp.parse(driver.getTableEntityByGUID(e.getAsString()));
ITypedReferenceableInstance tabRef = Serialization$.MODULE$.fromJson(joInner.get("definition").getAsString().toString());
postSaveTableArray.add(tabRef);
}
//Create Lineage Objects
String[][] lineageData = getTestLineageData(); String[][] lineageData = getTestLineageData();
for (String[] row : lineageData) { for (String[] row : lineageData) {
ITypedReferenceableInstance lineageInstance = driver ITypedReferenceableInstance lineageInstance = driver
...@@ -309,19 +357,24 @@ public class DemoDataDriver { ...@@ -309,19 +357,24 @@ public class DemoDataDriver {
lineageArray.add(lineageInstance); lineageArray.add(lineageInstance);
} }
/*for (ITypedReferenceableInstance i : tableArray) { //Save Lineage Objects
driver.submitEntity(i);
}*/
for (ITypedReferenceableInstance i : lineageArray) { for (ITypedReferenceableInstance i : lineageArray) {
driver.submitEntity(i); driver.submitEntity(i);
} }
System.out.println("###############DATABASES ADDED##############################");
driver.getEntityList(); driver.getEntityList(DemoDataDriver.DATABASE_TYPE);
System.out.println("##################TABLES ADDED##############################");
driver.getEntityList(DemoDataDriver.TABLE_TYPE);
System.out.println("#################LINEAGE ADDED##############################");
driver.getEntityList(DemoDataDriver.LINEAGE_TYPE);
System.out.println("############################################################");
System.out.println("DEMO DATA ADDED SUCCESSFULLY");
} }
private static String[][] getTestLineageData() { private static String[][] getTestLineageData() {
return new String[][] { return new String[][] {
{ {
"s123456_20150106120303_036186d5-a991-4dfc-9ff2-05b072c7e711", "s123456_20150106120303_036186d5-a991-4dfc-9ff2-05b072c7e711",
"90797386-3933-4ab0-ae68-a7baa7e155d4", "90797386-3933-4ab0-ae68-a7baa7e155d4",
"Service User 02", "Service User 02",
...@@ -360,8 +413,7 @@ public class DemoDataDriver { ...@@ -360,8 +413,7 @@ public class DemoDataDriver {
"DS imported dataset from internet of ideas", "DS imported dataset from internet of ideas",
"org.apache.hadoop.hive.ql.io.orc.OrcSerde", "org.apache.hadoop.hive.ql.io.orc.OrcSerde",
"org.apache.hadoop.hive.ql.io.orc.OrcSerde" }, "org.apache.hadoop.hive.ql.io.orc.OrcSerde" },
{ { "ds_db",
"ds_db",
"providerComparativeModel", "providerComparativeModel",
"DS created Table for comparing charges findings to dataset from internet", "DS created Table for comparing charges findings to dataset from internet",
"org.apache.hadoop.hive.ql.io.orc.OrcSerde", "org.apache.hadoop.hive.ql.io.orc.OrcSerde",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment