Commit e747e2ae by Venkatesh Seetharam

Fix tests to rid using TypeSystem in client

parent 35adfb8e
...@@ -22,6 +22,7 @@ import com.sun.jersey.api.client.Client; ...@@ -22,6 +22,7 @@ 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;
import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
...@@ -29,7 +30,12 @@ import javax.ws.rs.HttpMethod; ...@@ -29,7 +30,12 @@ import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import java.util.ArrayList;
import java.util.List;
/**
* Client for metadata.
*/
public class MetadataServiceClient { public class MetadataServiceClient {
public static final String REQUEST_ID = "requestId"; public static final String REQUEST_ID = "requestId";
public static final String RESULTS = "results"; public static final String RESULTS = "results";
...@@ -50,8 +56,8 @@ public class MetadataServiceClient { ...@@ -50,8 +56,8 @@ public class MetadataServiceClient {
//Type operations //Type operations
CREATE_TYPE("api/metadata/types/submit", HttpMethod.POST), CREATE_TYPE("api/metadata/types/submit", HttpMethod.POST),
GET_TYPE("api/metadata/types/definition", HttpMethod.GET), GET_TYPE("api/metadata/types/definition", HttpMethod.GET),
LIST_TYPE("api/metadata/types/list", HttpMethod.GET), LIST_TYPES("api/metadata/types/list", HttpMethod.GET),
LIST_TRAIT_TYPE("api/metadata/types/traits/list", HttpMethod.GET), LIST_TRAIT_TYPES("api/metadata/types/traits/list", HttpMethod.GET),
//Entity operations //Entity operations
CREATE_ENTITY("api/metadata/entities/submit", HttpMethod.POST), CREATE_ENTITY("api/metadata/entities/submit", HttpMethod.POST),
...@@ -81,8 +87,28 @@ public class MetadataServiceClient { ...@@ -81,8 +87,28 @@ public class MetadataServiceClient {
} }
} }
public JSONObject createEntity(String typeName, String entityAsJson) throws MetadataServiceException { public JSONObject createType(String typeName,
return callAPI(API.CREATE_ENTITY, entityAsJson, typeName); String typeAsJson) throws MetadataServiceException {
return callAPI(API.CREATE_TYPE, typeAsJson, typeName);
}
public List<String> listTypes() throws MetadataServiceException {
try {
final JSONObject jsonObject = callAPI(API.LIST_TYPES, null);
final JSONArray list = jsonObject.getJSONArray(MetadataServiceClient.RESULTS);
ArrayList<String> types = new ArrayList<>();
for (int index = 0; index < list.length(); index++) {
types.add(list.getString(index));
}
return types;
} catch (JSONException e) {
throw new MetadataServiceException(API.LIST_TYPES, e);
}
}
public JSONObject createEntity(String entityAsJson) throws MetadataServiceException {
return callAPI(API.CREATE_ENTITY, entityAsJson);
} }
public String getRequestId(JSONObject json) throws MetadataServiceException { public String getRequestId(JSONObject json) throws MetadataServiceException {
...@@ -101,7 +127,9 @@ public class MetadataServiceClient { ...@@ -101,7 +127,9 @@ public class MetadataServiceClient {
} }
} }
ClientResponse clientResponse = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(api.getMethod(), ClientResponse.class, requestObject); .method(api.getMethod(), ClientResponse.class, requestObject);
if (clientResponse.getStatus() == Response.Status.OK.getStatusCode()) { if (clientResponse.getStatus() == Response.Status.OK.getStatusCode()) {
......
...@@ -29,12 +29,10 @@ public interface EntityChangeListener { ...@@ -29,12 +29,10 @@ public interface EntityChangeListener {
/** /**
* This is upon adding a new typed instance to the repository. * This is upon adding a new typed instance to the repository.
* *
* @param typeName type name
* @param typedInstance a typed instance * @param typedInstance a typed instance
* @throws org.apache.hadoop.metadata.MetadataException * @throws org.apache.hadoop.metadata.MetadataException
*/ */
void onEntityAdded(String typeName, void onEntityAdded(ITypedReferenceableInstance typedInstance) throws MetadataException;
ITypedReferenceableInstance typedInstance) throws MetadataException;
/** /**
* This is upon adding a new trait to a typed instance. * This is upon adding a new trait to a typed instance.
......
...@@ -69,12 +69,10 @@ public interface MetadataRepository { ...@@ -69,12 +69,10 @@ public interface MetadataRepository {
* Creates an entity definition (instance) corresponding to a given type. * Creates an entity definition (instance) corresponding to a given type.
* *
* @param entity entity (typed instance) * @param entity entity (typed instance)
* @param entityType entity type name
* @return a globally unique identifier * @return a globally unique identifier
* @throws RepositoryException * @throws RepositoryException
*/ */
String createEntity(IReferenceableInstance entity, String createEntity(IReferenceableInstance entity) throws RepositoryException;
String entityType) throws RepositoryException;
/** /**
* Fetch the complete definition of an entity given its GUID. * Fetch the complete definition of an entity given its GUID.
...@@ -137,17 +135,6 @@ public interface MetadataRepository { ...@@ -137,17 +135,6 @@ public interface MetadataRepository {
ITypedStruct traitInstance) throws RepositoryException; ITypedStruct traitInstance) throws RepositoryException;
/** /**
* Adds a list of traits to an existing entity represented by a guid.
*
* @param guid globally unique identifier for the entity
* @param traitInstances list of trait instances that needs to be added to entity
* @return an entity instance with updated traits
* @throws RepositoryException
*/
// ITypedReferenceableInstance addTraits(String guid, Map<String, ITypedStruct> traitInstances)
// throws RepositoryException;
/**
* Deletes a given trait from an existing entity represented by a guid. * Deletes a given trait from an existing entity represented by a guid.
* *
* @param guid globally unique identifier for the entity * @param guid globally unique identifier for the entity
...@@ -160,8 +147,8 @@ public interface MetadataRepository { ...@@ -160,8 +147,8 @@ public interface MetadataRepository {
/** /**
* Adds the property to the entity that corresponds to the GUID * Adds the property to the entity that corresponds to the GUID
* @param guid entity id * @param guid entity id
* @param property * @param property property name
* @param value * @param value property value
*/ */
void updateEntity(String guid, String property, String value) throws RepositoryException; void updateEntity(String guid, String property, String value) throws RepositoryException;
} }
...@@ -116,9 +116,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -116,9 +116,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
} }
@Override @Override
public String createEntity(IReferenceableInstance typedInstance, public String createEntity(IReferenceableInstance typedInstance) throws RepositoryException {
String typeName) throws RepositoryException { LOG.info("adding entity={}", typedInstance);
LOG.info("adding entity={} type={}", typedInstance, typeName);
try { try {
titanGraph.rollback(); titanGraph.rollback();
......
...@@ -28,10 +28,16 @@ import org.apache.hadoop.metadata.repository.MetadataRepository; ...@@ -28,10 +28,16 @@ import org.apache.hadoop.metadata.repository.MetadataRepository;
import org.apache.hadoop.metadata.repository.typestore.ITypeStore; import org.apache.hadoop.metadata.repository.typestore.ITypeStore;
import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance; import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.typesystem.ITypedStruct; import org.apache.hadoop.metadata.typesystem.ITypedStruct;
import org.apache.hadoop.metadata.typesystem.Referenceable;
import org.apache.hadoop.metadata.typesystem.Struct;
import org.apache.hadoop.metadata.typesystem.TypesDef; import org.apache.hadoop.metadata.typesystem.TypesDef;
import org.apache.hadoop.metadata.typesystem.json.InstanceSerialization;
import org.apache.hadoop.metadata.typesystem.json.Serialization$; import org.apache.hadoop.metadata.typesystem.json.Serialization$;
import org.apache.hadoop.metadata.typesystem.json.TypesSerialization; import org.apache.hadoop.metadata.typesystem.json.TypesSerialization;
import org.apache.hadoop.metadata.typesystem.types.ClassType;
import org.apache.hadoop.metadata.typesystem.types.IDataType; import org.apache.hadoop.metadata.typesystem.types.IDataType;
import org.apache.hadoop.metadata.typesystem.types.Multiplicity;
import org.apache.hadoop.metadata.typesystem.types.TraitType;
import org.apache.hadoop.metadata.typesystem.types.TypeSystem; import org.apache.hadoop.metadata.typesystem.types.TypeSystem;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
...@@ -151,24 +157,39 @@ public class DefaultMetadataService implements MetadataService { ...@@ -151,24 +157,39 @@ public class DefaultMetadataService implements MetadataService {
/** /**
* Creates an entity, instance of the type. * Creates an entity, instance of the type.
* *
* @param entityType type * @param entityInstanceDefinition definition
* @param entityDefinition definition
* @return guid * @return guid
*/ */
@Override @Override
public String createEntity(String entityType, public String createEntity(String entityInstanceDefinition) throws MetadataException {
String entityDefinition) throws MetadataException { Preconditions.checkNotNull(entityInstanceDefinition,
Preconditions.checkNotNull(entityDefinition, "entity cannot be null"); "entity instance definition cannot be null");
Preconditions.checkNotNull(entityType, "entity type cannot be null");
ITypedReferenceableInstance entityTypedInstance =
deserializeClassInstance(entityInstanceDefinition);
ITypedReferenceableInstance entityInstance = final String guid = repository.createEntity(entityTypedInstance);
Serialization$.MODULE$.fromJson(entityDefinition);
final String guid = repository.createEntity(entityInstance, entityType);
onEntityAddedToRepo(entityType, entityInstance); onEntityAddedToRepo(entityTypedInstance);
return guid; return guid;
} }
private ITypedReferenceableInstance deserializeClassInstance(
String entityInstanceDefinition) throws MetadataException {
try {
final Referenceable entityInstance = InstanceSerialization.fromJsonReferenceable(
entityInstanceDefinition, true);
final String entityTypeName = entityInstance.getTypeName();
Preconditions.checkNotNull(entityTypeName, "entity type cannot be null");
ClassType entityType = typeSystem.getDataType(ClassType.class, entityTypeName);
return entityType.convert(entityInstance, Multiplicity.REQUIRED);
} catch (Exception e) {
throw new MetadataException("Error deserializing trait instance");
}
}
/** /**
* Return the definition for the given guid. * Return the definition for the given guid.
* *
...@@ -256,7 +277,14 @@ public class DefaultMetadataService implements MetadataService { ...@@ -256,7 +277,14 @@ public class DefaultMetadataService implements MetadataService {
throws MetadataException { throws MetadataException {
try { try {
return (ITypedStruct) Serialization$.MODULE$.traitFromJson(traitInstanceDefinition); Struct traitInstance = InstanceSerialization.fromJsonStruct(
traitInstanceDefinition, true);
final String entityTypeName = traitInstance.getTypeName();
Preconditions.checkNotNull(entityTypeName, "entity type cannot be null");
TraitType traitType = typeSystem.getDataType(TraitType.class, entityTypeName);
return traitType.convert(
traitInstance, Multiplicity.REQUIRED);
} catch (Exception e) { } catch (Exception e) {
throw new MetadataException("Error deserializing trait instance"); throw new MetadataException("Error deserializing trait instance");
} }
...@@ -301,12 +329,11 @@ public class DefaultMetadataService implements MetadataService { ...@@ -301,12 +329,11 @@ public class DefaultMetadataService implements MetadataService {
typesChangeListeners.remove(listener); typesChangeListeners.remove(listener);
} }
private void onEntityAddedToRepo(String typeName, private void onEntityAddedToRepo(ITypedReferenceableInstance typedInstance)
ITypedReferenceableInstance typedInstance)
throws MetadataException { throws MetadataException {
for (EntityChangeListener listener : entityChangeListeners) { for (EntityChangeListener listener : entityChangeListeners) {
listener.onEntityAdded(typeName, typedInstance); listener.onEntityAdded(typedInstance);
} }
} }
......
...@@ -64,11 +64,10 @@ public interface MetadataService { ...@@ -64,11 +64,10 @@ public interface MetadataService {
/** /**
* Creates an entity, instance of the type. * Creates an entity, instance of the type.
* *
* @param entityType type
* @param entityDefinition definition * @param entityDefinition definition
* @return guid * @return guid
*/ */
String createEntity(String entityType, String entityDefinition) throws MetadataException; String createEntity(String entityDefinition) throws MetadataException;
/** /**
* Return the definition for the given guid. * Return the definition for the given guid.
...@@ -87,10 +86,11 @@ public interface MetadataService { ...@@ -87,10 +86,11 @@ public interface MetadataService {
List<String> getEntityList(String entityType) throws MetadataException; List<String> getEntityList(String entityType) throws MetadataException;
/** /**
* Adds the property to the given entity id(guid) * Adds the property to the given entity id(guid).
*
* @param guid entity id * @param guid entity id
* @param property * @param property property name
* @param value * @param value property value
*/ */
void updateEntity(String guid, String property, String value) throws MetadataException; void updateEntity(String guid, String property, String value) throws MetadataException;
......
...@@ -78,7 +78,7 @@ public class GraphBackedDiscoveryServiceTest { ...@@ -78,7 +78,7 @@ public class GraphBackedDiscoveryServiceTest {
ClassType deptType = typeSystem.getDataType(ClassType.class, "Department"); ClassType deptType = typeSystem.getDataType(ClassType.class, "Department");
ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED); ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
repositoryService.createEntity(hrDept2, "Department"); repositoryService.createEntity(hrDept2);
} }
private void setupSampleData() throws ScriptException { private void setupSampleData() throws ScriptException {
...@@ -173,12 +173,10 @@ public class GraphBackedDiscoveryServiceTest { ...@@ -173,12 +173,10 @@ public class GraphBackedDiscoveryServiceTest {
{"DB, Table"}, {"DB, Table"},
/*{"DB as db1 Table where db1.name = \"Reporting\""},*/ /*{"DB as db1 Table where db1.name = \"Reporting\""},*/
{"DB name = \"Reporting\""}, {"DB name = \"Reporting\""},
/* {"Column where Column isa PII"},
{"Column where is PII"}, {"Table is Dimension"},
{"Table where is Dimension"}, {"View is Dimension"},
{"View where is Dimension"}, /*{"Column where Column isa PII select Column.name"},*/
{"Column where is PII select Column.name"},
*/
{"Column select Column.name"}, {"Column select Column.name"},
{"from Table select Table.name"}, {"from Table select Table.name"},
}; };
......
...@@ -106,7 +106,7 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -106,7 +106,7 @@ public class GraphBackedMetadataRepositoryTest {
ClassType deptType = typeSystem.getDataType(ClassType.class, "Department"); ClassType deptType = typeSystem.getDataType(ClassType.class, "Department");
ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED); ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
guid = repositoryService.createEntity(hrDept2, ENTITY_TYPE); guid = repositoryService.createEntity(hrDept2);
Assert.assertNotNull(guid); Assert.assertNotNull(guid);
} }
...@@ -154,14 +154,14 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -154,14 +154,14 @@ public class GraphBackedMetadataRepositoryTest {
ITypedReferenceableInstance db = dbType.convert(databaseInstance, Multiplicity.REQUIRED); ITypedReferenceableInstance db = dbType.convert(databaseInstance, Multiplicity.REQUIRED);
System.out.println("db = " + db); System.out.println("db = " + db);
String dbGUID = repositoryService.createEntity(db, DATABASE_TYPE); String dbGUID = repositoryService.createEntity(db);
System.out.println("added db = " + dbGUID); System.out.println("added db = " + dbGUID);
Referenceable dbInstance = new Referenceable( Referenceable dbInstance = new Referenceable(
dbGUID, DATABASE_TYPE, databaseInstance.getValuesMap()); dbGUID, DATABASE_TYPE, databaseInstance.getValuesMap());
ITypedReferenceableInstance table = createHiveTableInstance(dbInstance); ITypedReferenceableInstance table = createHiveTableInstance(dbInstance);
String tableGUID = repositoryService.createEntity(table, TABLE_TYPE); String tableGUID = repositoryService.createEntity(table);
System.out.println("added table = " + tableGUID); System.out.println("added table = " + tableGUID);
} }
......
...@@ -89,14 +89,14 @@ public class GraphRepoMapperScaleTest { ...@@ -89,14 +89,14 @@ public class GraphRepoMapperScaleTest {
ClassType dbType = typeSystem.getDataType(ClassType.class, DATABASE_TYPE); ClassType dbType = typeSystem.getDataType(ClassType.class, DATABASE_TYPE);
ITypedReferenceableInstance db = dbType.convert(databaseInstance, Multiplicity.REQUIRED); ITypedReferenceableInstance db = dbType.convert(databaseInstance, Multiplicity.REQUIRED);
dbGUID = repositoryService.createEntity(db, DATABASE_TYPE); dbGUID = repositoryService.createEntity(db);
Referenceable dbInstance = new Referenceable( Referenceable dbInstance = new Referenceable(
dbGUID, DATABASE_TYPE, databaseInstance.getValuesMap()); dbGUID, DATABASE_TYPE, databaseInstance.getValuesMap());
for (int index = 0; index < 1000; index++) { for (int index = 0; index < 1000; index++) {
ITypedReferenceableInstance table = createHiveTableInstance(dbInstance, index); ITypedReferenceableInstance table = createHiveTableInstance(dbInstance, index);
repositoryService.createEntity(table, TABLE_TYPE); repositoryService.createEntity(table);
} }
} }
......
...@@ -78,31 +78,28 @@ public class EntityResource { ...@@ -78,31 +78,28 @@ public class EntityResource {
/** /**
* Submits an entity definition (instance) corresponding to a given type. * Submits an entity definition (instance) corresponding to a given type.
*
* @param typeName name of a type which is unique.
*/ */
@POST @POST
@Path("submit/{typeName}") @Path("submit")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response submit(@Context HttpServletRequest request, public Response submit(@Context HttpServletRequest request) {
@PathParam("typeName") final String typeName) {
try { try {
final String entity = Servlets.getRequestPayload(request); final String entity = Servlets.getRequestPayload(request);
LOG.debug("submitting entity {} ", entity); LOG.debug("submitting entity {} ", entity);
final String guid = metadataService.createEntity(typeName, entity); final String guid = metadataService.createEntity(entity);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(MetadataServiceClient.RESULTS, guid); response.put(MetadataServiceClient.RESULTS, guid);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (MetadataException | IOException | IllegalArgumentException e) { } catch (MetadataException | IOException | IllegalArgumentException e) {
LOG.error("Unable to persist instance for type {}", typeName, e); LOG.error("Unable to persist entity instance", e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (JSONException e) {
LOG.error("Unable to persist instance for type {}", typeName, e); LOG.error("Unable to persist entity instance", e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} }
...@@ -193,12 +190,13 @@ public class EntityResource { ...@@ -193,12 +190,13 @@ public class EntityResource {
* @param guid entity id * @param guid entity id
* @param property property to add * @param property property to add
* @param value property's value * @param value property's value
* @return * @return response payload as json
*/ */
@PUT @PUT
@Path("update/{guid}") @Path("update/{guid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response update(@PathParam("guid") String guid, @QueryParam("property") String property, public Response update(@PathParam("guid") String guid,
@QueryParam("property") String property,
@QueryParam("value") String value) { @QueryParam("value") String value) {
try { try {
metadataService.updateEntity(guid, property, value); metadataService.updateEntity(guid, property, value);
......
...@@ -23,27 +23,28 @@ import com.sun.jersey.api.client.ClientResponse; ...@@ -23,27 +23,28 @@ import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.typesystem.types.TypeSystem; import org.apache.hadoop.metadata.typesystem.Referenceable;
import org.apache.hadoop.metadata.web.util.Servlets; import org.apache.hadoop.metadata.typesystem.TypesDef;
import org.apache.hadoop.metadata.typesystem.json.InstanceSerialization;
import org.apache.hadoop.metadata.typesystem.json.TypesSerialization;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
/**
* Base class for integration tests.
* Sets up the web resource and has helper methods to create type and entity.
*/
public abstract class BaseResourceIT { public abstract class BaseResourceIT {
protected TypeSystem typeSystem;
protected WebResource service; protected WebResource service;
protected MetadataServiceClient serviceClient; protected MetadataServiceClient serviceClient;
public void setUp() throws Exception { public void setUp() throws Exception {
typeSystem = TypeSystem.getInstance();
typeSystem.reset();
String baseUrl = "http://localhost:21000/"; String baseUrl = "http://localhost:21000/";
DefaultClientConfig config = new DefaultClientConfig(); DefaultClientConfig config = new DefaultClientConfig();
...@@ -54,10 +55,15 @@ public abstract class BaseResourceIT { ...@@ -54,10 +55,15 @@ public abstract class BaseResourceIT {
serviceClient = new MetadataServiceClient(baseUrl); serviceClient = new MetadataServiceClient(baseUrl);
} }
protected void sumbitType(String typesAsJSON, String type) throws Exception { protected void createType(TypesDef typesDef) throws Exception {
String typesAsJSON = TypesSerialization.toJson(typesDef);
createType(typesAsJSON, "removeme");
}
protected void createType(String typesAsJSON, String typeName) throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/types/submit") .path("api/metadata/types/submit")
.path(type); .path(typeName);
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
...@@ -69,8 +75,22 @@ public abstract class BaseResourceIT { ...@@ -69,8 +75,22 @@ public abstract class BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertEquals(response.get("typeName"), type); Assert.assertEquals(response.get("typeName"), typeName);
Assert.assertNotNull(response.get("types")); Assert.assertNotNull(response.get("types"));
Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
} }
protected Referenceable createInstance(Referenceable referenceable) throws Exception {
String typeName = referenceable.getTypeName();
System.out.println("creating instance of type " + typeName);
String entityJSON = InstanceSerialization.toJson(referenceable, true);
System.out.println("Submitting new entity= " + entityJSON);
JSONObject jsonObject = serviceClient.createEntity(entityJSON);
String guid = jsonObject.getString(MetadataServiceClient.RESULTS);
System.out.println("created instance for type " + typeName + ", guid: " + guid);
// return the reference to created instance with guid
return new Referenceable(guid, referenceable.getTypeName(), referenceable.getValuesMap());
}
} }
...@@ -22,26 +22,22 @@ import com.google.common.collect.ImmutableList; ...@@ -22,26 +22,22 @@ import com.google.common.collect.ImmutableList;
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;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.typesystem.Struct;
import org.apache.hadoop.metadata.typesystem.json.Serialization$;
import org.apache.hadoop.metadata.typesystem.json.TypesSerialization;
import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.typesystem.Referenceable; import org.apache.hadoop.metadata.typesystem.Referenceable;
import org.apache.hadoop.metadata.typesystem.Struct;
import org.apache.hadoop.metadata.typesystem.TypesDef;
import org.apache.hadoop.metadata.typesystem.types.ClassType; import org.apache.hadoop.metadata.typesystem.types.ClassType;
import org.apache.hadoop.metadata.typesystem.types.DataTypes; import org.apache.hadoop.metadata.typesystem.types.DataTypes;
import org.apache.hadoop.metadata.typesystem.types.EnumTypeDefinition;
import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition; import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition;
import org.apache.hadoop.metadata.typesystem.types.Multiplicity;
import org.apache.hadoop.metadata.typesystem.types.StructTypeDefinition; import org.apache.hadoop.metadata.typesystem.types.StructTypeDefinition;
import org.apache.hadoop.metadata.typesystem.types.TraitType; import org.apache.hadoop.metadata.typesystem.types.TraitType;
import org.apache.hadoop.metadata.typesystem.types.TypeUtils;
import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil; import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil;
import org.apache.hadoop.metadata.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import scala.actors.threadpool.Arrays;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
...@@ -49,17 +45,14 @@ import javax.ws.rs.core.Response; ...@@ -49,17 +45,14 @@ import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
public class MetadataDiscoveryResourceIT extends BaseResourceIT { public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
createTypes(); createTypes();
submitTypes(); createInstance();
ITypedReferenceableInstance instance = createInstance();
String instanceAsJSON = Serialization$.MODULE$.toJson(instance);
submitEntity(instanceAsJSON);
} }
@Test @Test
...@@ -210,56 +203,6 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -210,56 +203,6 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
Response.Status.NOT_FOUND.getStatusCode()); Response.Status.NOT_FOUND.getStatusCode());
} }
@Test(dependsOnMethods = "testUriExists", enabled = false)
public void testSearchForTextNoDepth() throws Exception {
WebResource resource = service
.path("api/metadata/discovery/search/fulltext")
.queryParam("depth", "0").queryParam("text", "kid").queryParam("property", "Name");
ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class);
// TODO - Get count of expected vertices and Edges
// Assert.assertEquals(true, true);
}
@Test(dependsOnMethods = "testUriExists", enabled = false)
public void testSearchTextWithDepth() throws Exception {
WebResource resource = service
.path("api/metadata/discovery/search/fulltext")
.queryParam("depth", "4").queryParam("text", "Grandad")
.queryParam("property", "Name");
ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class);
// TODO - Get count of expected vertices and Edges
// Assert.assertEquals(true, true);
}
private void submitEntity(String instanceAsJSON) throws JSONException {
WebResource resource = service
.path("api/metadata/entities/submit")
.path("dsl_test_type");
ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, instanceAsJSON);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class);
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
String guid = response.get(MetadataServiceClient.RESULTS).toString();
Assert.assertNotNull(guid);
}
private void createTypes() throws Exception { private void createTypes() throws Exception {
HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition =
TypesUtil.createClassTypeDef("dsl_test_type", TypesUtil.createClassTypeDef("dsl_test_type",
...@@ -284,30 +227,16 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -284,30 +227,16 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
HierarchicalTypeDefinition<TraitType> financeTrait = HierarchicalTypeDefinition<TraitType> financeTrait =
TypesUtil.createTraitTypeDef("Finance", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("Finance", ImmutableList.<String>of());
typeSystem.defineTypes( TypesDef typesDef = TypeUtils.getTypesDef(
ImmutableList.<EnumTypeDefinition>of(),
ImmutableList.<StructTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
ImmutableList.of(classificationTraitDefinition, piiTrait, phiTrait, pciTrait, ImmutableList.of(classificationTraitDefinition, piiTrait, phiTrait, pciTrait,
soxTrait, secTrait, financeTrait), soxTrait, secTrait, financeTrait),
ImmutableList.of(dslTestTypeDefinition)); ImmutableList.of(dslTestTypeDefinition));
createType(typesDef);
} }
private void submitTypes() throws Exception { private Referenceable createInstance() throws Exception {
@SuppressWarnings("unchecked")
String typesAsJSON = TypesSerialization.toJson(typeSystem,
Arrays.asList(new String[]{
"dsl_test_type",
"Classification",
"PII",
"PHI",
"PCI",
"SOX",
"SEC",
"Finance",
}));
sumbitType(typesAsJSON, "dsl_test_type");
}
private ITypedReferenceableInstance createInstance() throws Exception {
Referenceable entityInstance = new Referenceable("dsl_test_type", Referenceable entityInstance = new Referenceable("dsl_test_type",
"Classification", "PII", "PHI", "PCI", "SOX", "SEC", "Finance"); "Classification", "PII", "PHI", "PCI", "SOX", "SEC", "Finance");
entityInstance.set("name", "foo name"); entityInstance.set("name", "foo name");
...@@ -319,7 +248,6 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -319,7 +248,6 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
List<String> traits = entityInstance.getTraits(); List<String> traits = entityInstance.getTraits();
Assert.assertEquals(traits.size(), 7); Assert.assertEquals(traits.size(), 7);
ClassType tableType = typeSystem.getDataType(ClassType.class, "dsl_test_type"); return createInstance(entityInstance);
return tableType.convert(entityInstance, Multiplicity.REQUIRED);
} }
} }
\ No newline at end of file
...@@ -31,7 +31,6 @@ import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition; ...@@ -31,7 +31,6 @@ import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition;
import org.apache.hadoop.metadata.typesystem.types.Multiplicity; import org.apache.hadoop.metadata.typesystem.types.Multiplicity;
import org.apache.hadoop.metadata.typesystem.types.TraitType; import org.apache.hadoop.metadata.typesystem.types.TraitType;
import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil; import org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil;
import org.apache.hadoop.metadata.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.testng.Assert; import org.testng.Assert;
...@@ -187,7 +186,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -187,7 +186,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
HierarchicalTypeDefinition<TraitType> traitTypeDef = HierarchicalTypeDefinition<TraitType> traitTypeDef =
TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of()); TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of());
String json = TypesSerialization$.MODULE$.toJson(traitTypeDef, true); String json = TypesSerialization$.MODULE$.toJson(traitTypeDef, true);
sumbitType(json, traitName); createType(json, traitName);
} }
return traitNames; return traitNames;
......
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