Commit fef50cee by Shwetha GS

IDE java code reformat

parent 22624786
...@@ -61,14 +61,16 @@ public class FalconImporter { ...@@ -61,14 +61,16 @@ public class FalconImporter {
this.repository = repo; this.repository = repo;
} }
private Entity getEntity(FalconClient client, EntityType type, String name) throws FalconCLIException, JAXBException { private Entity getEntity(FalconClient client, EntityType type, String name)
throws FalconCLIException, JAXBException {
String entityStr = client.getDefinition(type.name(), name); String entityStr = client.getDefinition(type.name(), name);
return (Entity) type.getUnmarshaller().unmarshal(new StringReader(entityStr)); return (Entity) type.getUnmarshaller().unmarshal(new StringReader(entityStr));
} }
public void importClusters() throws MetadataException { public void importClusters() throws MetadataException {
try { try {
EntityList clusters = client.getEntityList(EntityType.CLUSTER.name(), null, null, null, null, null, null, null); EntityList clusters =
client.getEntityList(EntityType.CLUSTER.name(), null, null, null, null, null, null, null);
for (EntityList.EntityElement element : clusters.getElements()) { for (EntityList.EntityElement element : clusters.getElements()) {
Cluster cluster = (Cluster) getEntity(client, EntityType.CLUSTER, element.name); Cluster cluster = (Cluster) getEntity(client, EntityType.CLUSTER, element.name);
...@@ -80,7 +82,8 @@ public class FalconImporter { ...@@ -80,7 +82,8 @@ public class FalconImporter {
acl.set("owner", cluster.getACL().getOwner()); acl.set("owner", cluster.getACL().getOwner());
acl.set("group", cluster.getACL().getGroup()); acl.set("group", cluster.getACL().getGroup());
acl.set("permission", cluster.getACL().getPermission()); acl.set("permission", cluster.getACL().getPermission());
StructType aclType = typeSystem.getDataType(StructType.class, FalconTypeSystem.DefinedTypes.ACL.name()); StructType aclType =
typeSystem.getDataType(StructType.class, FalconTypeSystem.DefinedTypes.ACL.name());
clusterRef.set("acl", aclType.convert(acl, Multiplicity.REQUIRED)); clusterRef.set("acl", aclType.convert(acl, Multiplicity.REQUIRED));
} }
...@@ -88,7 +91,8 @@ public class FalconImporter { ...@@ -88,7 +91,8 @@ public class FalconImporter {
String[] parts = cluster.getTags().split(","); String[] parts = cluster.getTags().split(",");
List<ITypedInstance> tags = new ArrayList<>(); List<ITypedInstance> tags = new ArrayList<>();
for (String part : parts) { for (String part : parts) {
TraitType tagType = typeSystem.getDataType(TraitType.class, FalconTypeSystem.DefinedTypes.TAG.name()); TraitType tagType =
typeSystem.getDataType(TraitType.class, FalconTypeSystem.DefinedTypes.TAG.name());
String[] kv = part.trim().split("="); String[] kv = part.trim().split("=");
Struct tag = new Struct(FalconTypeSystem.DefinedTypes.TAG.name()); Struct tag = new Struct(FalconTypeSystem.DefinedTypes.TAG.name());
tag.set("name", kv[0]); tag.set("name", kv[0]);
...@@ -106,10 +110,12 @@ public class FalconImporter { ...@@ -106,10 +110,12 @@ public class FalconImporter {
List<ITypedInstance> locations = new ArrayList<>(); List<ITypedInstance> locations = new ArrayList<>();
for (Location loc : cluster.getLocations().getLocations()) { for (Location loc : cluster.getLocations().getLocations()) {
Struct location = new Struct(FalconTypeSystem.DefinedTypes.CLUSTER_LOCATION.name()); Struct location = new Struct(FalconTypeSystem.DefinedTypes.CLUSTER_LOCATION.name());
EnumType locationType = typeSystem.getDataType(EnumType.class, FalconTypeSystem.DefinedTypes.CLUSTER_LOCATION_TYPE.name()); EnumType locationType = typeSystem.getDataType(EnumType.class,
FalconTypeSystem.DefinedTypes.CLUSTER_LOCATION_TYPE.name());
location.set("type", locationType.fromValue(loc.getName().toUpperCase())); location.set("type", locationType.fromValue(loc.getName().toUpperCase()));
location.set("path", loc.getPath()); location.set("path", loc.getPath());
StructType type = typeSystem.getDataType(StructType.class, FalconTypeSystem.DefinedTypes.CLUSTER_LOCATION.name()); StructType type = typeSystem
.getDataType(StructType.class, FalconTypeSystem.DefinedTypes.CLUSTER_LOCATION.name());
locations.add(type.convert(location, Multiplicity.REQUIRED)); locations.add(type.convert(location, Multiplicity.REQUIRED));
} }
clusterRef.set("locations", locations); clusterRef.set("locations", locations);
...@@ -122,7 +128,8 @@ public class FalconImporter { ...@@ -122,7 +128,8 @@ public class FalconImporter {
interfaceStruct.set("type", interfaceFld.getType().name()); interfaceStruct.set("type", interfaceFld.getType().name());
interfaceStruct.set("endpoint", interfaceFld.getEndpoint()); interfaceStruct.set("endpoint", interfaceFld.getEndpoint());
interfaceStruct.set("version", interfaceFld.getVersion()); interfaceStruct.set("version", interfaceFld.getVersion());
StructType type = typeSystem.getDataType(StructType.class, FalconTypeSystem.DefinedTypes.CLUSTER_INTERFACE.name()); StructType type = typeSystem
.getDataType(StructType.class, FalconTypeSystem.DefinedTypes.CLUSTER_INTERFACE.name());
interfaces.add(type.convert(interfaceStruct, Multiplicity.REQUIRED)); interfaces.add(type.convert(interfaceStruct, Multiplicity.REQUIRED));
} }
clusterRef.set("interfaces", interfaces); clusterRef.set("interfaces", interfaces);
......
...@@ -54,7 +54,7 @@ public class FalconTypeSystem { ...@@ -54,7 +54,7 @@ public class FalconTypeSystem {
public static FalconTypeSystem getInstance() throws MetadataException { public static FalconTypeSystem getInstance() throws MetadataException {
if (INSTANCE == null) { if (INSTANCE == null) {
synchronized(LOG) { synchronized (LOG) {
if (INSTANCE == null) { if (INSTANCE == null) {
INSTANCE = new FalconTypeSystem(); INSTANCE = new FalconTypeSystem();
} }
...@@ -73,12 +73,16 @@ public class FalconTypeSystem { ...@@ -73,12 +73,16 @@ public class FalconTypeSystem {
new AttributeDefinition("name", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null), new AttributeDefinition("name", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null),
new AttributeDefinition("acl", DefinedTypes.ACL.name(), Multiplicity.OPTIONAL, false, null), new AttributeDefinition("acl", DefinedTypes.ACL.name(), Multiplicity.OPTIONAL, false, null),
new AttributeDefinition("tags", DefinedTypes.TAG.name(), Multiplicity.COLLECTION, false, null), new AttributeDefinition("tags", DefinedTypes.TAG.name(), Multiplicity.COLLECTION, false, null),
new AttributeDefinition("locations", TYPE_SYSTEM.defineMapType(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE).getName(), Multiplicity.COLLECTION, false, null), new AttributeDefinition("locations",
new AttributeDefinition("interfaces", DefinedTypes.CLUSTER_INTERFACE.name(), Multiplicity.COLLECTION, false, null), TYPE_SYSTEM.defineMapType(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE).getName(),
new AttributeDefinition("properties", TYPE_SYSTEM.defineMapType(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE).getName(), Multiplicity.OPTIONAL, false, null), Multiplicity.COLLECTION, false, null),
}; new AttributeDefinition("interfaces", DefinedTypes.CLUSTER_INTERFACE.name(), Multiplicity.COLLECTION,
false, null), new AttributeDefinition("properties",
TYPE_SYSTEM.defineMapType(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE).getName(),
Multiplicity.OPTIONAL, false, null),};
HierarchicalTypeDefinition<ClassType> cluster = HierarchicalTypeDefinition<ClassType> cluster =
new HierarchicalTypeDefinition<>(ClassType.class, DefinedTypes.CLUSTER.name(), ImmutableList.<String>of(), attributeDefinitions); new HierarchicalTypeDefinition<>(ClassType.class, DefinedTypes.CLUSTER.name(),
ImmutableList.<String>of(), attributeDefinitions);
LOG.debug("Created definition for " + DefinedTypes.CLUSTER.name()); LOG.debug("Created definition for " + DefinedTypes.CLUSTER.name());
return cluster; return cluster;
} }
...@@ -86,57 +90,52 @@ public class FalconTypeSystem { ...@@ -86,57 +90,52 @@ public class FalconTypeSystem {
private HierarchicalTypeDefinition<TraitType> defineTags() { private HierarchicalTypeDefinition<TraitType> defineTags() {
AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{ AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{
new AttributeDefinition("name", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null), new AttributeDefinition("name", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null),
new AttributeDefinition("value", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null) new AttributeDefinition("value", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null)};
};
HierarchicalTypeDefinition<TraitType> traitType = new HierarchicalTypeDefinition<>(TraitType.class, DefinedTypes.TAG.name(), ImmutableList.<String>of(), attributeDefinitions); HierarchicalTypeDefinition<TraitType> traitType =
new HierarchicalTypeDefinition<>(TraitType.class, DefinedTypes.TAG.name(), ImmutableList.<String>of(),
attributeDefinitions);
LOG.debug("Created definition for " + DefinedTypes.TAG.name()); LOG.debug("Created definition for " + DefinedTypes.TAG.name());
traitTypeDefinitions.add(traitType); traitTypeDefinitions.add(traitType);
return traitType; return traitType;
} }
private StructTypeDefinition defineClusterLocation() throws MetadataException { private StructTypeDefinition defineClusterLocation() throws MetadataException {
EnumValue values[] = { EnumValue values[] = {new EnumValue("WORKING", 1), new EnumValue("STAGING", 2), new EnumValue("TEMP", 3),};
new EnumValue("WORKING", 1),
new EnumValue("STAGING", 2),
new EnumValue("TEMP", 3),
};
LOG.debug("Created definition for " + DefinedTypes.CLUSTER_LOCATION_TYPE.name()); LOG.debug("Created definition for " + DefinedTypes.CLUSTER_LOCATION_TYPE.name());
EnumTypeDefinition locationType = new EnumTypeDefinition(DefinedTypes.CLUSTER_LOCATION_TYPE.name(), values); EnumTypeDefinition locationType = new EnumTypeDefinition(DefinedTypes.CLUSTER_LOCATION_TYPE.name(), values);
TYPE_SYSTEM.defineEnumType(locationType); TYPE_SYSTEM.defineEnumType(locationType);
AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{ AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{
new AttributeDefinition("type", DefinedTypes.CLUSTER_LOCATION_TYPE.name(), Multiplicity.REQUIRED, false, null), new AttributeDefinition("type", DefinedTypes.CLUSTER_LOCATION_TYPE.name(), Multiplicity.REQUIRED, false,
new AttributeDefinition("path", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null), null),
}; new AttributeDefinition("path", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null),};
LOG.debug("Created definition for " + DefinedTypes.CLUSTER_LOCATION.name()); LOG.debug("Created definition for " + DefinedTypes.CLUSTER_LOCATION.name());
StructTypeDefinition location = new StructTypeDefinition(DefinedTypes.CLUSTER_LOCATION.name(), attributeDefinitions); StructTypeDefinition location =
new StructTypeDefinition(DefinedTypes.CLUSTER_LOCATION.name(), attributeDefinitions);
structTypeDefinitions.add(location); structTypeDefinitions.add(location);
return location; return location;
} }
private StructTypeDefinition defineClusterInterface() throws MetadataException { private StructTypeDefinition defineClusterInterface() throws MetadataException {
EnumValue values[] = { EnumValue values[] = {new EnumValue("READONLY", 1), new EnumValue("WRITE", 2), new EnumValue("EXECUTE", 3),
new EnumValue("READONLY", 1), new EnumValue("WORKFLOW", 4), new EnumValue("MESSAGING", 5), new EnumValue("REGISTRY", 6),};
new EnumValue("WRITE", 2),
new EnumValue("EXECUTE", 3),
new EnumValue("WORKFLOW", 4),
new EnumValue("MESSAGING", 5),
new EnumValue("REGISTRY", 6),
};
LOG.debug("Created definition for " + DefinedTypes.CLUSTER_INTERFACE_TYPE.name()); LOG.debug("Created definition for " + DefinedTypes.CLUSTER_INTERFACE_TYPE.name());
EnumTypeDefinition interfaceType = new EnumTypeDefinition(DefinedTypes.CLUSTER_INTERFACE_TYPE.name(), values); EnumTypeDefinition interfaceType = new EnumTypeDefinition(DefinedTypes.CLUSTER_INTERFACE_TYPE.name(), values);
TYPE_SYSTEM.defineEnumType(interfaceType); TYPE_SYSTEM.defineEnumType(interfaceType);
AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{ AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{
new AttributeDefinition("type", DefinedTypes.CLUSTER_INTERFACE_TYPE.name(), Multiplicity.REQUIRED, false, null), new AttributeDefinition("type", DefinedTypes.CLUSTER_INTERFACE_TYPE.name(), Multiplicity.REQUIRED,
new AttributeDefinition("endpoint", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null), false, null),
new AttributeDefinition("version", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null), new AttributeDefinition("endpoint", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false,
}; null),
new AttributeDefinition("version", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false,
null),};
LOG.debug("Created definition for " + DefinedTypes.CLUSTER_INTERFACE.name()); LOG.debug("Created definition for " + DefinedTypes.CLUSTER_INTERFACE.name());
StructTypeDefinition interfaceEntity = new StructTypeDefinition(DefinedTypes.CLUSTER_INTERFACE.name(), attributeDefinitions); StructTypeDefinition interfaceEntity =
new StructTypeDefinition(DefinedTypes.CLUSTER_INTERFACE.name(), attributeDefinitions);
structTypeDefinitions.add(interfaceEntity); structTypeDefinitions.add(interfaceEntity);
return interfaceEntity; return interfaceEntity;
} }
...@@ -154,13 +153,10 @@ public class FalconTypeSystem { ...@@ -154,13 +153,10 @@ public class FalconTypeSystem {
private StructTypeDefinition defineACL() { private StructTypeDefinition defineACL() {
AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{ AttributeDefinition[] attributeDefinitions = new AttributeDefinition[]{
new AttributeDefinition("owner", DataTypes.STRING_TYPE.getName(), new AttributeDefinition("owner", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null),
Multiplicity.REQUIRED, false, null), new AttributeDefinition("group", DataTypes.STRING_TYPE.getName(), Multiplicity.REQUIRED, false, null),
new AttributeDefinition("group", DataTypes.STRING_TYPE.getName(), new AttributeDefinition("permission", DataTypes.STRING_TYPE.getName(), Multiplicity.OPTIONAL, false,
Multiplicity.REQUIRED, false, null), null),};
new AttributeDefinition("permission", DataTypes.STRING_TYPE.getName(),
Multiplicity.OPTIONAL, false, null),
};
LOG.debug("Created definition for " + DefinedTypes.ACL.name()); LOG.debug("Created definition for " + DefinedTypes.ACL.name());
StructTypeDefinition acl = new StructTypeDefinition(DefinedTypes.ACL.name(), attributeDefinitions); StructTypeDefinition acl = new StructTypeDefinition(DefinedTypes.ACL.name(), attributeDefinitions);
structTypeDefinitions.add(acl); structTypeDefinitions.add(acl);
......
...@@ -48,11 +48,12 @@ public class FalconImporterTest { ...@@ -48,11 +48,12 @@ public class FalconImporterTest {
FalconTypeSystem.getInstance(); FalconTypeSystem.getInstance();
FalconImporter importer = new FalconImporter(client, repo); FalconImporter importer = new FalconImporter(client, repo);
when(client.getEntityList(EntityType.CLUSTER.name(), null, null, null, null, null, null, when(client.getEntityList(EntityType.CLUSTER.name(), null, null, null, null, null, null, null))
null)).thenReturn(getEntityList()); .thenReturn(getEntityList());
//TODO Set other fields in cluster //TODO Set other fields in cluster
when(client.getDefinition(anyString(), anyString())).thenReturn(getCluster()); when(client.getDefinition(anyString(), anyString())).thenReturn(getCluster());
when(repo.createEntity(any(IReferenceableInstance.class), anyString())).thenReturn(UUID.randomUUID().toString()); when(repo.createEntity(any(IReferenceableInstance.class), anyString()))
.thenReturn(UUID.randomUUID().toString());
importer.importClusters(); importer.importClusters();
} }
......
...@@ -29,7 +29,9 @@ public class FalconTypeSystemTest { ...@@ -29,7 +29,9 @@ public class FalconTypeSystemTest {
@Test @Test
public void testTypeSystem() throws MetadataException { public void testTypeSystem() throws MetadataException {
FalconTypeSystem.getInstance(); FalconTypeSystem.getInstance();
Assert.assertNotNull(TypeSystem.getInstance().getDataType(ClassType.class, FalconTypeSystem.DefinedTypes.CLUSTER.name())); Assert.assertNotNull(
Assert.assertNotNull(TypeSystem.getInstance().getDataType(TraitType.class, FalconTypeSystem.DefinedTypes.TAG.name())); TypeSystem.getInstance().getDataType(ClassType.class, FalconTypeSystem.DefinedTypes.CLUSTER.name()));
Assert.assertNotNull(
TypeSystem.getInstance().getDataType(TraitType.class, FalconTypeSystem.DefinedTypes.TAG.name()));
} }
} }
...@@ -159,9 +159,8 @@ public class HiveMetaStoreBridge { ...@@ -159,9 +159,8 @@ public class HiveMetaStoreBridge {
LOG.debug("Getting reference for database {}", databaseName); LOG.debug("Getting reference for database {}", databaseName);
String typeName = HiveDataTypes.HIVE_DB.getName(); String typeName = HiveDataTypes.HIVE_DB.getName();
String dslQuery = String.format("%s where %s = '%s' and %s = '%s'", typeName, String dslQuery = String.format("%s where %s = '%s' and %s = '%s'", typeName, HiveDataModelGenerator.NAME,
HiveDataModelGenerator.NAME, databaseName.toLowerCase(), HiveDataModelGenerator.CLUSTER_NAME, databaseName.toLowerCase(), HiveDataModelGenerator.CLUSTER_NAME, clusterName);
clusterName);
return getEntityReferenceFromDSL(typeName, dslQuery); return getEntityReferenceFromDSL(typeName, dslQuery);
} }
...@@ -170,11 +169,12 @@ public class HiveMetaStoreBridge { ...@@ -170,11 +169,12 @@ public class HiveMetaStoreBridge {
String typeName = HiveDataTypes.HIVE_PROCESS.getName(); String typeName = HiveDataTypes.HIVE_PROCESS.getName();
//todo enable DSL //todo enable DSL
// String dslQuery = String.format("%s where queryText = \"%s\"", typeName, queryStr); // String dslQuery = String.format("%s where queryText = \"%s\"", typeName, queryStr);
// return getEntityReferenceFromDSL(typeName, dslQuery); // return getEntityReferenceFromDSL(typeName, dslQuery);
String gremlinQuery = String.format("g.V.has('__typeName', '%s').has('%s.queryText', \"%s\").toList()", String gremlinQuery =
typeName, typeName, StringEscapeUtils.escapeJava(queryStr)); String.format("g.V.has('__typeName', '%s').has('%s.queryText', \"%s\").toList()", typeName, typeName,
StringEscapeUtils.escapeJava(queryStr));
return getEntityReferenceFromGremlin(typeName, gremlinQuery); return getEntityReferenceFromGremlin(typeName, gremlinQuery);
} }
...@@ -216,9 +216,8 @@ public class HiveMetaStoreBridge { ...@@ -216,9 +216,8 @@ public class HiveMetaStoreBridge {
return getEntityReferenceFromDSL(typeName, dslQuery); return getEntityReferenceFromDSL(typeName, dslQuery);
} }
private Referenceable getEntityReferenceFromGremlin(String typeName, String gremlinQuery) throws private Referenceable getEntityReferenceFromGremlin(String typeName, String gremlinQuery)
AtlasServiceException, throws AtlasServiceException, JSONException {
JSONException {
AtlasClient client = getAtlasClient(); AtlasClient client = getAtlasClient();
JSONObject response = client.searchByGremlin(gremlinQuery); JSONObject response = client.searchByGremlin(gremlinQuery);
JSONArray results = response.getJSONArray(AtlasClient.RESULTS); JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
...@@ -236,7 +235,8 @@ public class HiveMetaStoreBridge { ...@@ -236,7 +235,8 @@ public class HiveMetaStoreBridge {
//todo replace gremlin with DSL //todo replace gremlin with DSL
// String dslQuery = String.format("%s as p where values = %s, tableName where name = '%s', " // String dslQuery = String.format("%s as p where values = %s, tableName where name = '%s', "
// + "dbName where name = '%s' and clusterName = '%s' select p", typeName, valuesStr, tableName, // + "dbName where name = '%s' and clusterName = '%s' select p", typeName, valuesStr,
// tableName,
// dbName, clusterName); // dbName, clusterName);
String datasetType = AtlasClient.DATA_SET_SUPER_TYPE; String datasetType = AtlasClient.DATA_SET_SUPER_TYPE;
...@@ -373,9 +373,8 @@ public class HiveMetaStoreBridge { ...@@ -373,9 +373,8 @@ public class HiveMetaStoreBridge {
return partRef; return partRef;
} }
private void importIndexes(String db, String table, private void importIndexes(String db, String table, Referenceable dbReferenceable, Referenceable tableReferenceable)
Referenceable dbReferenceable, throws Exception {
Referenceable tableReferenceable) throws Exception {
List<Index> indexes = hiveClient.getIndexes(db, table, Short.MAX_VALUE); List<Index> indexes = hiveClient.getIndexes(db, table, Short.MAX_VALUE);
if (indexes.size() > 0) { if (indexes.size() > 0) {
for (Index index : indexes) { for (Index index : indexes) {
...@@ -385,9 +384,8 @@ public class HiveMetaStoreBridge { ...@@ -385,9 +384,8 @@ public class HiveMetaStoreBridge {
} }
//todo should be idempotent //todo should be idempotent
private void importIndex(Index index, private void importIndex(Index index, Referenceable dbReferenceable, Referenceable tableReferenceable)
Referenceable dbReferenceable, throws Exception {
Referenceable tableReferenceable) throws Exception {
LOG.info("Importing index {} for {}.{}", index.getIndexName(), dbReferenceable, tableReferenceable); LOG.info("Importing index {} for {}.{}", index.getIndexName(), dbReferenceable, tableReferenceable);
Referenceable indexRef = new Referenceable(HiveDataTypes.HIVE_INDEX.getName()); Referenceable indexRef = new Referenceable(HiveDataTypes.HIVE_INDEX.getName());
...@@ -411,7 +409,8 @@ public class HiveMetaStoreBridge { ...@@ -411,7 +409,8 @@ public class HiveMetaStoreBridge {
createInstance(indexRef); createInstance(indexRef);
} }
private Referenceable fillStorageDescStruct(StorageDescriptor storageDesc, List<Referenceable> colList) throws Exception { private Referenceable fillStorageDescStruct(StorageDescriptor storageDesc, List<Referenceable> colList)
throws Exception {
LOG.debug("Filling storage descriptor information for " + storageDesc); LOG.debug("Filling storage descriptor information for " + storageDesc);
Referenceable sdReferenceable = new Referenceable(HiveDataTypes.HIVE_STORAGEDESC.getName()); Referenceable sdReferenceable = new Referenceable(HiveDataTypes.HIVE_STORAGEDESC.getName());
...@@ -429,7 +428,8 @@ public class HiveMetaStoreBridge { ...@@ -429,7 +428,8 @@ public class HiveMetaStoreBridge {
sdReferenceable.set("serdeInfo", serdeInfoStruct); sdReferenceable.set("serdeInfo", serdeInfoStruct);
sdReferenceable.set(HiveDataModelGenerator.STORAGE_NUM_BUCKETS, storageDesc.getNumBuckets()); sdReferenceable.set(HiveDataModelGenerator.STORAGE_NUM_BUCKETS, storageDesc.getNumBuckets());
sdReferenceable.set(HiveDataModelGenerator.STORAGE_IS_STORED_AS_SUB_DIRS, storageDesc.isStoredAsSubDirectories()); sdReferenceable
.set(HiveDataModelGenerator.STORAGE_IS_STORED_AS_SUB_DIRS, storageDesc.isStoredAsSubDirectories());
//Use the passed column list if not null, ex: use same references for table and SD //Use the passed column list if not null, ex: use same references for table and SD
List<FieldSchema> columns = storageDesc.getCols(); List<FieldSchema> columns = storageDesc.getCols();
...@@ -469,8 +469,7 @@ public class HiveMetaStoreBridge { ...@@ -469,8 +469,7 @@ public class HiveMetaStoreBridge {
return createInstance(sdReferenceable); return createInstance(sdReferenceable);
} }
private List<Referenceable> getColumns(List<FieldSchema> schemaList) throws Exception private List<Referenceable> getColumns(List<FieldSchema> schemaList) throws Exception {
{
List<Referenceable> colList = new ArrayList<>(); List<Referenceable> colList = new ArrayList<>();
for (FieldSchema fs : schemaList) { for (FieldSchema fs : schemaList) {
LOG.debug("Processing field " + fs); LOG.debug("Processing field " + fs);
...@@ -489,7 +488,7 @@ public class HiveMetaStoreBridge { ...@@ -489,7 +488,7 @@ public class HiveMetaStoreBridge {
AtlasClient dgiClient = getAtlasClient(); AtlasClient dgiClient = getAtlasClient();
//Register hive data model if its not already registered //Register hive data model if its not already registered
if (dgiClient.getType(HiveDataTypes.HIVE_PROCESS.getName()) == null ) { if (dgiClient.getType(HiveDataTypes.HIVE_PROCESS.getName()) == null) {
LOG.info("Registering Hive data model"); LOG.info("Registering Hive data model");
dgiClient.createType(dataModelGenerator.getModelAsJson()); dgiClient.createType(dataModelGenerator.getModelAsJson());
} else { } else {
......
...@@ -348,7 +348,7 @@ public class HiveHook implements ExecuteWithHookContext { ...@@ -348,7 +348,7 @@ public class HiveHook implements ExecuteWithHookContext {
explain.initialize(event.conf, event.queryPlan, null); explain.initialize(event.conf, event.queryPlan, null);
List<Task<?>> rootTasks = event.queryPlan.getRootTasks(); List<Task<?>> rootTasks = event.queryPlan.getRootTasks();
return explain.getJSONPlan(null, null, rootTasks, event.queryPlan.getFetchTask(), true, false, false); return explain.getJSONPlan(null, null, rootTasks, event.queryPlan.getFetchTask(), true, false, false);
} catch(Exception e) { } catch (Exception e) {
LOG.warn("Failed to get queryplan", e); LOG.warn("Failed to get queryplan", e);
return new JSONObject(); return new JSONObject();
} }
......
...@@ -70,27 +70,22 @@ public class BaseSSLAndKerberosTest extends BaseSecurityTest { ...@@ -70,27 +70,22 @@ public class BaseSSLAndKerberosTest extends BaseSecurityTest {
file.delete(); file.delete();
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);
CredentialProvider provider = CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);
CredentialProviderFactory.getProviders(conf).get(0);
// create new aliases // create new aliases
try { try {
char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass);
KEYSTORE_PASSWORD_KEY, storepass);
char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass);
TRUSTSTORE_PASSWORD_KEY, trustpass);
char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry("ssl.client.truststore.password", trustpass2);
"ssl.client.truststore.password", trustpass2);
char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass);
SERVER_CERT_PASSWORD_KEY, certpass);
// write out so that it can be found in checks // write out so that it can be found in checks
provider.flush(); provider.flush();
...@@ -132,8 +127,7 @@ public class BaseSSLAndKerberosTest extends BaseSecurityTest { ...@@ -132,8 +127,7 @@ public class BaseSSLAndKerberosTest extends BaseSecurityTest {
hiveConf.setVar(HiveConf.ConfVars.PREEXECHOOKS, ""); hiveConf.setVar(HiveConf.ConfVars.PREEXECHOOKS, "");
hiveConf.setVar(HiveConf.ConfVars.POSTEXECHOOKS, HiveHook.class.getName()); hiveConf.setVar(HiveConf.ConfVars.POSTEXECHOOKS, HiveHook.class.getName());
hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false); hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false);
hiveConf.setVar(HiveConf.ConfVars.METASTOREWAREHOUSE, hiveConf.setVar(HiveConf.ConfVars.METASTOREWAREHOUSE, System.getProperty("user.dir") + "/target/atlas");
System.getProperty("user.dir") + "/target/atlas");
hiveConf.set(HiveMetaStoreBridge.DGI_URL_PROPERTY, DGI_URL); hiveConf.set(HiveMetaStoreBridge.DGI_URL_PROPERTY, DGI_URL);
hiveConf.set("javax.jdo.option.ConnectionURL", "jdbc:derby:./target/metastore_db;create=true"); hiveConf.set("javax.jdo.option.ConnectionURL", "jdbc:derby:./target/metastore_db;create=true");
hiveConf.set("hive.hook.dgi.synchronous", "true"); hiveConf.set("hive.hook.dgi.synchronous", "true");
......
...@@ -121,8 +121,8 @@ public class HiveHookIT { ...@@ -121,8 +121,8 @@ public class HiveHookIT {
private String createTable(boolean partition) throws Exception { private String createTable(boolean partition) throws Exception {
String tableName = tableName(); String tableName = tableName();
runCommand("create table " + tableName + "(id int, name string) comment 'table comment' " runCommand("create table " + tableName + "(id int, name string) comment 'table comment' " + (partition ?
+ (partition ? " partitioned by(dt string)" : "")); " partitioned by(dt string)" : ""));
return tableName; return tableName;
} }
...@@ -146,7 +146,7 @@ public class HiveHookIT { ...@@ -146,7 +146,7 @@ public class HiveHookIT {
final Id sdId = (Id) tableRef.get("sd"); final Id sdId = (Id) tableRef.get("sd");
Referenceable sdRef = dgiCLient.getEntity(sdId.id); Referenceable sdRef = dgiCLient.getEntity(sdId.id);
Assert.assertEquals(sdRef.get(HiveDataModelGenerator.STORAGE_IS_STORED_AS_SUB_DIRS),false); Assert.assertEquals(sdRef.get(HiveDataModelGenerator.STORAGE_IS_STORED_AS_SUB_DIRS), false);
//Create table where database doesn't exist, will create database instance as well //Create table where database doesn't exist, will create database instance as well
assertDatabaseIsRegistered(DEFAULT_DB); assertDatabaseIsRegistered(DEFAULT_DB);
...@@ -154,7 +154,8 @@ public class HiveHookIT { ...@@ -154,7 +154,8 @@ public class HiveHookIT {
private String assertColumnIsRegistered(String colName) throws Exception { private String assertColumnIsRegistered(String colName) throws Exception {
LOG.debug("Searching for column {}", colName); LOG.debug("Searching for column {}", colName);
String query = String.format("%s where name = '%s'", HiveDataTypes.HIVE_COLUMN.getName(), colName.toLowerCase()); String query =
String.format("%s where name = '%s'", HiveDataTypes.HIVE_COLUMN.getName(), colName.toLowerCase());
return assertEntityIsRegistered(query, true); return assertEntityIsRegistered(query, true);
} }
...@@ -196,8 +197,9 @@ public class HiveHookIT { ...@@ -196,8 +197,9 @@ public class HiveHookIT {
public void testInsert() throws Exception { public void testInsert() throws Exception {
String tableName = createTable(); String tableName = createTable();
String insertTableName = createTable(); String insertTableName = createTable();
String query = "insert into " + insertTableName + " partition(dt = '2015-01-01') select id, name from " String query =
+ tableName + " where dt = '2015-01-01'"; "insert into " + insertTableName + " partition(dt = '2015-01-01') select id, name from " + tableName
+ " where dt = '2015-01-01'";
runCommand(query); runCommand(query);
assertProcessIsRegistered(query); assertProcessIsRegistered(query);
...@@ -278,13 +280,14 @@ public class HiveHookIT { ...@@ -278,13 +280,14 @@ public class HiveHookIT {
} }
private void assertProcessIsRegistered(String queryStr) throws Exception { private void assertProcessIsRegistered(String queryStr) throws Exception {
// String dslQuery = String.format("%s where queryText = \"%s\"", HiveDataTypes.HIVE_PROCESS.getName(), // String dslQuery = String.format("%s where queryText = \"%s\"", HiveDataTypes.HIVE_PROCESS.getName(),
// normalize(queryStr)); // normalize(queryStr));
// assertEntityIsRegistered(dslQuery, true); // assertEntityIsRegistered(dslQuery, true);
//todo replace with DSL //todo replace with DSL
String typeName = HiveDataTypes.HIVE_PROCESS.getName(); String typeName = HiveDataTypes.HIVE_PROCESS.getName();
String gremlinQuery = String.format("g.V.has('__typeName', '%s').has('%s.queryText', \"%s\").toList()", String gremlinQuery =
typeName, typeName, normalize(queryStr)); String.format("g.V.has('__typeName', '%s').has('%s.queryText', \"%s\").toList()", typeName, typeName,
normalize(queryStr));
JSONObject response = dgiCLient.searchByGremlin(gremlinQuery); JSONObject response = dgiCLient.searchByGremlin(gremlinQuery);
JSONArray results = response.getJSONArray(AtlasClient.RESULTS); JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
Assert.assertEquals(results.length(), 1); Assert.assertEquals(results.length(), 1);
...@@ -307,9 +310,9 @@ public class HiveHookIT { ...@@ -307,9 +310,9 @@ public class HiveHookIT {
private String assertTableIsRegistered(String dbName, String tableName, boolean registered) throws Exception { private String assertTableIsRegistered(String dbName, String tableName, boolean registered) throws Exception {
LOG.debug("Searching for table {}.{}", dbName, tableName); LOG.debug("Searching for table {}.{}", dbName, tableName);
String query = String.format("%s as t where tableName = '%s', db where name = '%s' and clusterName = '%s'" String query = String.format(
+ " select t", HiveDataTypes.HIVE_TABLE.getName(), tableName.toLowerCase(), dbName.toLowerCase(), "%s as t where tableName = '%s', db where name = '%s' and clusterName = '%s'" + " select t",
CLUSTER_NAME); HiveDataTypes.HIVE_TABLE.getName(), tableName.toLowerCase(), dbName.toLowerCase(), CLUSTER_NAME);
return assertEntityIsRegistered(query, registered); return assertEntityIsRegistered(query, registered);
} }
...@@ -336,7 +339,7 @@ public class HiveHookIT { ...@@ -336,7 +339,7 @@ public class HiveHookIT {
Assert.assertEquals(results.length(), 1); Assert.assertEquals(results.length(), 1);
} }
private String assertEntityIsRegistered(String dslQuery, boolean registered) throws Exception{ private String assertEntityIsRegistered(String dslQuery, boolean registered) throws Exception {
JSONArray results = dgiCLient.searchByDSL(dslQuery); JSONArray results = dgiCLient.searchByDSL(dslQuery);
if (registered) { if (registered) {
Assert.assertEquals(results.length(), 1); Assert.assertEquals(results.length(), 1);
......
...@@ -92,7 +92,8 @@ public class NegativeSSLAndKerberosHiveHookIT extends BaseSSLAndKerberosTest { ...@@ -92,7 +92,8 @@ public class NegativeSSLAndKerberosHiveHookIT extends BaseSSLAndKerberosTest {
configuration.setProperty(KEYSTORE_FILE_KEY, "../../webapp/target/atlas.keystore"); configuration.setProperty(KEYSTORE_FILE_KEY, "../../webapp/target/atlas.keystore");
configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
configuration.setProperty("atlas.http.authentication.type", "kerberos"); configuration.setProperty("atlas.http.authentication.type", "kerberos");
configuration.setProperty(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, SSLHostnameVerifier.DEFAULT_AND_LOCALHOST.toString()); configuration.setProperty(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY,
SSLHostnameVerifier.DEFAULT_AND_LOCALHOST.toString());
configuration.save(new FileWriter(persistDir + File.separator + "client.properties")); configuration.save(new FileWriter(persistDir + File.separator + "client.properties"));
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
package org.apache.atlas.hive.hook; package org.apache.atlas.hive.hook;
import org.apache.atlas.AtlasException;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.PropertiesUtil; import org.apache.atlas.PropertiesUtil;
import org.apache.atlas.hive.model.HiveDataTypes; import org.apache.atlas.hive.model.HiveDataTypes;
import org.apache.atlas.security.SecurityProperties; import org.apache.atlas.security.SecurityProperties;
...@@ -107,7 +107,8 @@ public class SSLAndKerberosHiveHookIT extends BaseSSLAndKerberosTest { ...@@ -107,7 +107,8 @@ public class SSLAndKerberosHiveHookIT extends BaseSSLAndKerberosTest {
configuration.setProperty(KEYSTORE_FILE_KEY, "../../webapp/target/atlas.keystore"); configuration.setProperty(KEYSTORE_FILE_KEY, "../../webapp/target/atlas.keystore");
configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
configuration.setProperty("atlas.http.authentication.type", "kerberos"); configuration.setProperty("atlas.http.authentication.type", "kerberos");
configuration.setProperty(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, SSLHostnameVerifier.DEFAULT_AND_LOCALHOST.toString()); configuration.setProperty(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY,
SSLHostnameVerifier.DEFAULT_AND_LOCALHOST.toString());
configuration.save(new FileWriter(persistDir + File.separator + "client.properties")); configuration.save(new FileWriter(persistDir + File.separator + "client.properties"));
...@@ -215,7 +216,8 @@ public class SSLAndKerberosHiveHookIT extends BaseSSLAndKerberosTest { ...@@ -215,7 +216,8 @@ public class SSLAndKerberosHiveHookIT extends BaseSSLAndKerberosTest {
assertInstanceIsRegistered(HiveDataTypes.HIVE_DB.getName(), "name", dbName); assertInstanceIsRegistered(HiveDataTypes.HIVE_DB.getName(), "name", dbName);
} }
private void assertInstanceIsRegistered(final String typeName, final String colName, final String colValue) throws Exception { private void assertInstanceIsRegistered(final String typeName, final String colName, final String colValue)
throws Exception {
Subject.doAs(subject, new PrivilegedExceptionAction<Object>() { Subject.doAs(subject, new PrivilegedExceptionAction<Object>() {
@Override @Override
public Object run() throws Exception { public Object run() throws Exception {
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
package org.apache.atlas.hive.hook; package org.apache.atlas.hive.hook;
import org.apache.atlas.AtlasException;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.hive.bridge.HiveMetaStoreBridge; import org.apache.atlas.hive.bridge.HiveMetaStoreBridge;
import org.apache.atlas.hive.model.HiveDataTypes; import org.apache.atlas.hive.model.HiveDataTypes;
import org.apache.atlas.security.SecurityProperties; import org.apache.atlas.security.SecurityProperties;
...@@ -73,7 +73,9 @@ public class SSLHiveHookIT { ...@@ -73,7 +73,9 @@ public class SSLHiveHookIT {
super(port, path); super(port, path);
} }
public Server getServer () { return server; } public Server getServer() {
return server;
}
@Override @Override
public PropertiesConfiguration getConfiguration() { public PropertiesConfiguration getConfiguration() {
...@@ -113,7 +115,8 @@ public class SSLHiveHookIT { ...@@ -113,7 +115,8 @@ public class SSLHiveHookIT {
configuration.setProperty(TRUSTSTORE_FILE_KEY, "../../webapp/target/atlas.keystore"); configuration.setProperty(TRUSTSTORE_FILE_KEY, "../../webapp/target/atlas.keystore");
configuration.setProperty(KEYSTORE_FILE_KEY, "../../webapp/target/atlas.keystore"); configuration.setProperty(KEYSTORE_FILE_KEY, "../../webapp/target/atlas.keystore");
configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl); configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
configuration.setProperty(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, SSLHostnameVerifier.DEFAULT_AND_LOCALHOST.toString()); configuration.setProperty(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY,
SSLHostnameVerifier.DEFAULT_AND_LOCALHOST.toString());
configuration.save(new FileWriter(persistDir + File.separator + "client.properties")); configuration.save(new FileWriter(persistDir + File.separator + "client.properties"));
...@@ -153,27 +156,22 @@ public class SSLHiveHookIT { ...@@ -153,27 +156,22 @@ public class SSLHiveHookIT {
file.delete(); file.delete();
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl); conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);
CredentialProvider provider = CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);
CredentialProviderFactory.getProviders(conf).get(0);
// create new aliases // create new aliases
try { try {
char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry(KEYSTORE_PASSWORD_KEY, storepass);
KEYSTORE_PASSWORD_KEY, storepass);
char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry(TRUSTSTORE_PASSWORD_KEY, trustpass);
TRUSTSTORE_PASSWORD_KEY, trustpass);
char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry("ssl.client.truststore.password", trustpass2);
"ssl.client.truststore.password", trustpass2);
char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'}; char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
provider.createCredentialEntry( provider.createCredentialEntry(SERVER_CERT_PASSWORD_KEY, certpass);
SERVER_CERT_PASSWORD_KEY, certpass);
// write out so that it can be found in checks // write out so that it can be found in checks
provider.flush(); provider.flush();
...@@ -217,7 +215,7 @@ public class SSLHiveHookIT { ...@@ -217,7 +215,7 @@ public class SSLHiveHookIT {
assertInstanceIsRegistered(HiveDataTypes.HIVE_DB.getName(), "name", dbName); assertInstanceIsRegistered(HiveDataTypes.HIVE_DB.getName(), "name", dbName);
} }
private void assertInstanceIsRegistered(String typeName, String colName, String colValue) throws Exception{ private void assertInstanceIsRegistered(String typeName, String colName, String colValue) throws Exception {
JSONArray results = dgiCLient.rawSearch(typeName, colName, colValue); JSONArray results = dgiCLient.rawSearch(typeName, colName, colValue);
Assert.assertEquals(results.length(), 1); Assert.assertEquals(results.length(), 1);
} }
......
...@@ -41,19 +41,15 @@ import java.util.Map.Entry; ...@@ -41,19 +41,15 @@ import java.util.Map.Entry;
public abstract class ABridge implements IBridge { public abstract class ABridge implements IBridge {
protected static final Logger LOG = BridgeManager.LOG; protected static final Logger LOG = BridgeManager.LOG;
protected ArrayList<Class<? extends AEntityBean>> typeBeanClasses protected ArrayList<Class<? extends AEntityBean>> typeBeanClasses = new ArrayList<Class<? extends AEntityBean>>();
= new ArrayList<Class<? extends AEntityBean>>();
MetadataRepository repo; MetadataRepository repo;
protected ABridge(MetadataRepository repo) { protected ABridge(MetadataRepository repo) {
this.repo = repo; this.repo = repo;
} }
protected HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name, protected HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name, ImmutableList<String> superTypes,
ImmutableList<String> AttributeDefinition... attrDefs) {
superTypes,
AttributeDefinition...
attrDefs) {
return new HierarchicalTypeDefinition(ClassType.class, name, superTypes, attrDefs); return new HierarchicalTypeDefinition(ClassType.class, name, superTypes, attrDefs);
} }
...@@ -67,8 +63,7 @@ public abstract class ABridge implements IBridge { ...@@ -67,8 +63,7 @@ public abstract class ABridge implements IBridge {
// turn into a HiveLineageBean // turn into a HiveLineageBean
try { try {
Class<AEntityBean> c = getTypeBeanInListByName(ref.getTypeName()); Class<AEntityBean> c = getTypeBeanInListByName(ref.getTypeName());
return this.convertFromITypedReferenceable(ref, return this.convertFromITypedReferenceable(ref, getTypeBeanInListByName(ref.getTypeName()));
getTypeBeanInListByName(ref.getTypeName()));
} catch (BridgeException | InstantiationException | IllegalAccessException | } catch (BridgeException | InstantiationException | IllegalAccessException |
IllegalArgumentException | InvocationTargetException | NoSuchMethodException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException |
SecurityException e) { SecurityException e) {
...@@ -80,8 +75,7 @@ public abstract class ABridge implements IBridge { ...@@ -80,8 +75,7 @@ public abstract class ABridge implements IBridge {
public String create(AEntityBean bean) throws MetadataException { public String create(AEntityBean bean) throws MetadataException {
ClassType type = TypeSystem.getInstance() ClassType type = TypeSystem.getInstance().getDataType(ClassType.class, bean.getClass().getSimpleName());
.getDataType(ClassType.class, bean.getClass().getSimpleName());
ITypedReferenceableInstance refBean = null; ITypedReferenceableInstance refBean = null;
try { try {
refBean = type.convert(this.convertToReferencable(bean), Multiplicity.REQUIRED); refBean = type.convert(this.convertToReferencable(bean), Multiplicity.REQUIRED);
...@@ -140,10 +134,10 @@ public abstract class ABridge implements IBridge { ...@@ -140,10 +134,10 @@ public abstract class ABridge implements IBridge {
return selfAware; return selfAware;
} }
protected final <T extends AEntityBean> T convertFromITypedReferenceable( protected final <T extends AEntityBean> T convertFromITypedReferenceable(ITypedReferenceableInstance instance,
ITypedReferenceableInstance instance, Class<? extends AEntityBean> c) Class<? extends AEntityBean> c)
throws InstantiationException, IllegalAccessException, IllegalArgumentException, throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
InvocationTargetException, NoSuchMethodException, SecurityException, BridgeException { NoSuchMethodException, SecurityException, BridgeException {
if (!instance.getTypeName().equals(c.getSimpleName())) { if (!instance.getTypeName().equals(c.getSimpleName())) {
throw new BridgeException("ReferenceableInstance type not the same as bean"); throw new BridgeException("ReferenceableInstance type not the same as bean");
} }
...@@ -151,10 +145,8 @@ public abstract class ABridge implements IBridge { ...@@ -151,10 +145,8 @@ public abstract class ABridge implements IBridge {
for (Entry<String, AttributeInfo> e : instance.fieldMapping().fields.entrySet()) { for (Entry<String, AttributeInfo> e : instance.fieldMapping().fields.entrySet()) {
try { try {
String convertedName = e.getKey().substring(0, 1).toUpperCase() + String convertedName = e.getKey().substring(0, 1).toUpperCase() + e.getKey().substring(1);
e.getKey().substring(1); this.getClass().getMethod("set" + convertedName, Class.forName(e.getValue().dataType().getName()))
this.getClass().getMethod("set" + convertedName,
Class.forName(e.getValue().dataType().getName()))
.invoke(this, instance.get(e.getKey())); .invoke(this, instance.get(e.getKey()));
} catch (MetadataException | ClassNotFoundException e1) { } catch (MetadataException | ClassNotFoundException e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
......
...@@ -50,13 +50,12 @@ public class BridgeManager { ...@@ -50,13 +50,12 @@ public class BridgeManager {
@Inject @Inject
BridgeManager(MetadataRepository rs) BridgeManager(MetadataRepository rs)
throws ConfigurationException, ClassNotFoundException, InstantiationException, throws ConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
NoSuchMethodException, SecurityException {
this.ts = TypeSystem.getInstance(); this.ts = TypeSystem.getInstance();
this.rs = rs; this.rs = rs;
if (System.getProperty("bridgeManager.propsFile") != null && if (System.getProperty("bridgeManager.propsFile") != null
System.getProperty("bridgeManager.propsFile").length() != 0) { && System.getProperty("bridgeManager.propsFile").length() != 0) {
setActiveBridges(System.getProperty("bridgeManager.propsFile")); setActiveBridges(System.getProperty("bridgeManager.propsFile"));
} else { } else {
setActiveBridges(bridgeFileDefault); setActiveBridges(bridgeFileDefault);
...@@ -73,8 +72,7 @@ public class BridgeManager { ...@@ -73,8 +72,7 @@ public class BridgeManager {
} }
public final static HierarchicalTypeDefinition<ClassType> public final static HierarchicalTypeDefinition<ClassType> convertEntityBeanToClassTypeDefinition(
convertEntityBeanToClassTypeDefinition(
Class<? extends AEntityBean> class1) { Class<? extends AEntityBean> class1) {
ArrayList<AttributeDefinition> attDefAL = new ArrayList<AttributeDefinition>(); ArrayList<AttributeDefinition> attDefAL = new ArrayList<AttributeDefinition>();
for (Field f : class1.getFields()) { for (Field f : class1.getFields()) {
...@@ -87,18 +85,16 @@ public class BridgeManager { ...@@ -87,18 +85,16 @@ public class BridgeManager {
} }
} }
HierarchicalTypeDefinition<ClassType> typeDef = new HierarchicalTypeDefinition<>( HierarchicalTypeDefinition<ClassType> typeDef =
ClassType.class, class1.getSimpleName(), new HierarchicalTypeDefinition<>(ClassType.class, class1.getSimpleName(), null,
null, (AttributeDefinition[]) attDefAL.toArray(new AttributeDefinition[0])); (AttributeDefinition[]) attDefAL.toArray(new AttributeDefinition[0]));
return typeDef; return typeDef;
} }
public final static AttributeDefinition convertFieldtoAttributeDefiniton(Field f) public final static AttributeDefinition convertFieldtoAttributeDefiniton(Field f) throws MetadataException {
throws MetadataException {
return new AttributeDefinition(f.getName(), f.getType().getSimpleName(), return new AttributeDefinition(f.getName(), f.getType().getSimpleName(), Multiplicity.REQUIRED, false, null);
Multiplicity.REQUIRED, false, null);
} }
public ArrayList<ABridge> getActiveBridges() { public ArrayList<ABridge> getActiveBridges() {
...@@ -116,8 +112,7 @@ public class BridgeManager { ...@@ -116,8 +112,7 @@ public class BridgeManager {
try { try {
BridgeManager.LOG.info("Loading : Active Bridge List"); BridgeManager.LOG.info("Loading : Active Bridge List");
config.load(bridgePropFileName); config.load(bridgePropFileName);
String[] activeBridgeList = ((String) config.getProperty("BridgeManager.activeBridges")) String[] activeBridgeList = ((String) config.getProperty("BridgeManager.activeBridges")).split(",");
.split(",");
BridgeManager.LOG.info("Loaded : Active Bridge List"); BridgeManager.LOG.info("Loaded : Active Bridge List");
BridgeManager.LOG.info("First Loaded :" + activeBridgeList[0]); BridgeManager.LOG.info("First Loaded :" + activeBridgeList[0]);
...@@ -125,8 +120,7 @@ public class BridgeManager { ...@@ -125,8 +120,7 @@ public class BridgeManager {
Class<?> bridgeCls = (Class<?>) Class.forName(s); Class<?> bridgeCls = (Class<?>) Class.forName(s);
if (ABridge.class.isAssignableFrom(bridgeCls)) { if (ABridge.class.isAssignableFrom(bridgeCls)) {
System.out.println(s + " is able to be instaciated"); System.out.println(s + " is able to be instaciated");
aBList.add((ABridge) bridgeCls.getConstructor(MetadataRepository.class) aBList.add((ABridge) bridgeCls.getConstructor(MetadataRepository.class).newInstance(rs));
.newInstance(rs));
} }
} }
......
...@@ -40,44 +40,39 @@ public class BridgeTypeBootstrapper { ...@@ -40,44 +40,39 @@ public class BridgeTypeBootstrapper {
private boolean isSetup = false; private boolean isSetup = false;
@Inject @Inject
BridgeTypeBootstrapper(Map<Class, IBridge> bridges) BridgeTypeBootstrapper(Map<Class, IBridge> bridges) throws MetadataException {
throws MetadataException {
this.bridges = bridges; this.bridges = bridges;
} }
public final static HierarchicalTypeDefinition<ClassType> public final static HierarchicalTypeDefinition<ClassType> convertEntityBeanToClassTypeDefinition(
convertEntityBeanToClassTypeDefinition(
Class<? extends AEntityBean> class1) { Class<? extends AEntityBean> class1) {
ArrayList<AttributeDefinition> attDefAL = new ArrayList<AttributeDefinition>(); ArrayList<AttributeDefinition> attDefAL = new ArrayList<AttributeDefinition>();
for (Field f : class1.getFields()) { for (Field f : class1.getFields()) {
try { try {
attDefAL.add(BridgeTypeBootstrapper.convertFieldtoAttributeDefiniton(f)); attDefAL.add(BridgeTypeBootstrapper.convertFieldtoAttributeDefiniton(f));
} catch (MetadataException e) { } catch (MetadataException e) {
BridgeManager.LOG.error("Class " + class1.getName() BridgeManager.LOG.error("Class " + class1.getName() + " cannot be converted to TypeDefinition");
+ " cannot be converted to TypeDefinition");
e.printStackTrace(); e.printStackTrace();
} }
} }
HierarchicalTypeDefinition<ClassType> typeDef = new HierarchicalTypeDefinition<>( HierarchicalTypeDefinition<ClassType> typeDef =
ClassType.class, class1.getSimpleName(), null, new HierarchicalTypeDefinition<>(ClassType.class, class1.getSimpleName(), null,
(AttributeDefinition[]) attDefAL (AttributeDefinition[]) attDefAL.toArray(new AttributeDefinition[0]));
.toArray(new AttributeDefinition[0]));
return typeDef; return typeDef;
} }
public final static AttributeDefinition convertFieldtoAttributeDefiniton( public final static AttributeDefinition convertFieldtoAttributeDefiniton(Field f) throws MetadataException {
Field f) throws MetadataException {
return new AttributeDefinition(f.getName(), return new AttributeDefinition(f.getName(), f.getType().getSimpleName().toLowerCase(), Multiplicity.REQUIRED,
f.getType().getSimpleName().toLowerCase(), Multiplicity.REQUIRED, false, null); false, null);
} }
public synchronized boolean bootstrap() throws MetadataException { public synchronized boolean bootstrap() throws MetadataException {
if (isSetup) if (isSetup) {
return false; return false;
else { } else {
LOG.info("Bootstrapping types"); LOG.info("Bootstrapping types");
_bootstrap(); _bootstrap();
isSetup = true; isSetup = true;
...@@ -94,12 +89,10 @@ public class BridgeTypeBootstrapper { ...@@ -94,12 +89,10 @@ public class BridgeTypeBootstrapper {
} }
} }
private final boolean loadTypes(IBridge bridge, TypeSystem ts) private final boolean loadTypes(IBridge bridge, TypeSystem ts) throws MetadataException {
throws MetadataException {
for (Class<? extends AEntityBean> clazz : bridge.getTypeBeanClasses()) { for (Class<? extends AEntityBean> clazz : bridge.getTypeBeanClasses()) {
LOG.info("Registering %s", clazz.getSimpleName()); LOG.info("Registering %s", clazz.getSimpleName());
ts.defineClassType(BridgeTypeBootstrapper ts.defineClassType(BridgeTypeBootstrapper.convertEntityBeanToClassTypeDefinition(clazz));
.convertEntityBeanToClassTypeDefinition(clazz));
} }
return false; return false;
} }
......
...@@ -79,8 +79,7 @@ public class HiveMetaImporter { ...@@ -79,8 +79,7 @@ public class HiveMetaImporter {
public static boolean databasesImport() throws MetaException, RepositoryException { public static boolean databasesImport() throws MetaException, RepositoryException {
ClassType classType = null; ClassType classType = null;
try { try {
classType = TypeSystem.getInstance() classType = TypeSystem.getInstance().getDataType(ClassType.class, HiveStructureBridge.DB_CLASS_TYPE);
.getDataType(ClassType.class, HiveStructureBridge.DB_CLASS_TYPE);
} catch (MetadataException e1) { } catch (MetadataException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
...@@ -118,8 +117,7 @@ public class HiveMetaImporter { ...@@ -118,8 +117,7 @@ public class HiveMetaImporter {
public static boolean tablesImport(String dbName) throws MetaException, RepositoryException { public static boolean tablesImport(String dbName) throws MetaException, RepositoryException {
ClassType classType = null; ClassType classType = null;
try { try {
classType = TypeSystem.getInstance() classType = TypeSystem.getInstance().getDataType(ClassType.class, HiveStructureBridge.TB_CLASS_TYPE);
.getDataType(ClassType.class, HiveStructureBridge.TB_CLASS_TYPE);
} catch (MetadataException e1) { } catch (MetadataException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
...@@ -129,8 +127,7 @@ public class HiveMetaImporter { ...@@ -129,8 +127,7 @@ public class HiveMetaImporter {
return true; return true;
} }
public static boolean tableImport(String dbName, String tbName) public static boolean tableImport(String dbName, String tbName) throws MetaException, RepositoryException {
throws MetaException, RepositoryException {
try { try {
Table tb = msc.getTable(dbName, tbName); Table tb = msc.getTable(dbName, tbName);
Referenceable tbRef = new Referenceable(HiveStructureBridge.TB_CLASS_TYPE); Referenceable tbRef = new Referenceable(HiveStructureBridge.TB_CLASS_TYPE);
...@@ -157,12 +154,10 @@ public class HiveMetaImporter { ...@@ -157,12 +154,10 @@ public class HiveMetaImporter {
return true; return true;
} }
public static boolean fieldsImport(String dbName, String tbName) public static boolean fieldsImport(String dbName, String tbName) throws MetaException, RepositoryException {
throws MetaException, RepositoryException {
ClassType classType = null; ClassType classType = null;
try { try {
classType = TypeSystem.getInstance() classType = TypeSystem.getInstance().getDataType(ClassType.class, HiveStructureBridge.FD_CLASS_TYPE);
.getDataType(ClassType.class, HiveStructureBridge.FD_CLASS_TYPE);
} catch (MetadataException e1) { } catch (MetadataException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
...@@ -190,8 +185,7 @@ public class HiveMetaImporter { ...@@ -190,8 +185,7 @@ public class HiveMetaImporter {
return true; return true;
} }
public static boolean fieldImport(String dbName, String tbName, String fdName) public static boolean fieldImport(String dbName, String tbName, String fdName) throws MetaException {
throws MetaException {
try { try {
for (FieldSchema fs : msc.getFields(dbName, tbName)) { for (FieldSchema fs : msc.getFields(dbName, tbName)) {
if (fs.getName().equals(fs)) { if (fs.getName().equals(fs)) {
......
...@@ -45,60 +45,50 @@ public class HiveStructureBridge extends ABridge { ...@@ -45,60 +45,50 @@ public class HiveStructureBridge extends ABridge {
} }
public boolean defineBridgeTypes(TypeSystem ts) { public boolean defineBridgeTypes(TypeSystem ts) {
ArrayList<HierarchicalTypeDefinition<?>> al ArrayList<HierarchicalTypeDefinition<?>> al = new ArrayList<HierarchicalTypeDefinition<?>>();
= new ArrayList<HierarchicalTypeDefinition<?>>();
// TODO // TODO
//convert to helper methods //convert to helper methods
// Add to arrayList // Add to arrayList
try { try {
HierarchicalTypeDefinition<ClassType> databaseClassTypeDef HierarchicalTypeDefinition<ClassType> databaseClassTypeDef =
= new HierarchicalTypeDefinition<ClassType>("ClassType", DB_CLASS_TYPE, null, new HierarchicalTypeDefinition<ClassType>("ClassType", DB_CLASS_TYPE, null,
new AttributeDefinition[]{ new AttributeDefinition[]{
new AttributeDefinition("DESC", "STRING_TYPE", Multiplicity.OPTIONAL, new AttributeDefinition("DESC", "STRING_TYPE", Multiplicity.OPTIONAL, false, null),
new AttributeDefinition("DB_LOCATION_URI", "STRING_TYPE", Multiplicity.REQUIRED,
false, null), false, null),
new AttributeDefinition("DB_LOCATION_URI", "STRING_TYPE", new AttributeDefinition("NAME", "STRING_TYPE", Multiplicity.REQUIRED, false, null),
Multiplicity.REQUIRED, false, null), new AttributeDefinition("OWNER_TYPE", "STRING_TYPE", Multiplicity.OPTIONAL, false,
new AttributeDefinition("NAME", "STRING_TYPE", Multiplicity.REQUIRED, null),
false, null), new AttributeDefinition("OWNER_NAME", "STRING_TYPE", Multiplicity.OPTIONAL, false,
new AttributeDefinition("OWNER_TYPE", "STRING_TYPE", null)});
Multiplicity.OPTIONAL, false, null),
new AttributeDefinition("OWNER_NAME", "STRING_TYPE", HierarchicalTypeDefinition<ClassType> tableClassTypeDef =
Multiplicity.OPTIONAL, false, null) new HierarchicalTypeDefinition<ClassType>("ClassType", TB_CLASS_TYPE, null,
}
);
HierarchicalTypeDefinition<ClassType> tableClassTypeDef
= new HierarchicalTypeDefinition<ClassType>("ClassType", TB_CLASS_TYPE, null,
new AttributeDefinition[]{ new AttributeDefinition[]{
new AttributeDefinition("CREATE_TIME", "LONG_TYPE", new AttributeDefinition("CREATE_TIME", "LONG_TYPE", Multiplicity.REQUIRED, false,
Multiplicity.REQUIRED, false, null), null),
new AttributeDefinition("LAST_ACCESS_TIME", "LONG_TYPE", new AttributeDefinition("LAST_ACCESS_TIME", "LONG_TYPE", Multiplicity.REQUIRED,
Multiplicity.REQUIRED, false, null),
new AttributeDefinition("OWNER", "STRING_TYPE", Multiplicity.REQUIRED,
false, null), false, null),
new AttributeDefinition("TBL_NAME", "STRING_TYPE", new AttributeDefinition("OWNER", "STRING_TYPE", Multiplicity.REQUIRED, false, null),
Multiplicity.REQUIRED, false, null), new AttributeDefinition("TBL_NAME", "STRING_TYPE", Multiplicity.REQUIRED, false,
new AttributeDefinition("TBL_TYPE", "STRING_TYPE", null),
Multiplicity.REQUIRED, false, null), new AttributeDefinition("TBL_TYPE", "STRING_TYPE", Multiplicity.REQUIRED, false,
new AttributeDefinition("VIEW_EXPANDED_TEXT", "STRING_TYPE", null),
Multiplicity.OPTIONAL, false, null), new AttributeDefinition("VIEW_EXPANDED_TEXT", "STRING_TYPE", Multiplicity.OPTIONAL,
new AttributeDefinition("VIEW_ORIGINAL_TEXT", "STRING_TYPE", false, null),
Multiplicity.OPTIONAL, false, null) new AttributeDefinition("VIEW_ORIGINAL_TEXT", "STRING_TYPE", Multiplicity.OPTIONAL,
} false, null)});
);
HierarchicalTypeDefinition<ClassType> columnClassTypeDef HierarchicalTypeDefinition<ClassType> columnClassTypeDef =
= new HierarchicalTypeDefinition<ClassType>("ClassType", FD_CLASS_TYPE, null, new HierarchicalTypeDefinition<ClassType>("ClassType", FD_CLASS_TYPE, null,
new AttributeDefinition[]{ new AttributeDefinition[]{
new AttributeDefinition("COMMENT", "STRING_TYPE", Multiplicity.OPTIONAL, new AttributeDefinition("COMMENT", "STRING_TYPE", Multiplicity.OPTIONAL, false,
false, null), null),
new AttributeDefinition("COLUMN_NAME", "STRING_TYPE", new AttributeDefinition("COLUMN_NAME", "STRING_TYPE", Multiplicity.REQUIRED, false,
Multiplicity.REQUIRED, false, null), null),
new AttributeDefinition("TYPE_NAME", "STRING_TYPE", new AttributeDefinition("TYPE_NAME", "STRING_TYPE", Multiplicity.REQUIRED, false,
Multiplicity.REQUIRED, false, null) null)});
}
);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -108,8 +98,7 @@ public class HiveStructureBridge extends ABridge { ...@@ -108,8 +98,7 @@ public class HiveStructureBridge extends ABridge {
try { try {
ts.defineClassType(htd); ts.defineClassType(htd);
} catch (MetadataException e) { } catch (MetadataException e) {
System.out.println( System.out.println(htd.hierarchicalMetaTypeName + "could not be added to the type system");
htd.hierarchicalMetaTypeName + "could not be added to the type system");
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -33,8 +33,7 @@ import java.util.ArrayList; ...@@ -33,8 +33,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class BridgeModule extends AbstractModule { public class BridgeModule extends AbstractModule {
public static final Logger LOG = LoggerFactory public static final Logger LOG = LoggerFactory.getLogger(BridgeModule.class);
.getLogger(BridgeModule.class);
@Override @Override
protected void configure() { protected void configure() {
...@@ -44,11 +43,9 @@ public class BridgeModule extends AbstractModule { ...@@ -44,11 +43,9 @@ public class BridgeModule extends AbstractModule {
bind(BridgeTypeBootstrapper.class).in(Scopes.SINGLETON); bind(BridgeTypeBootstrapper.class).in(Scopes.SINGLETON);
// Load the configured bridge classes and add them to the map binder // Load the configured bridge classes and add them to the map binder
MapBinder<Class, IBridge> mapbinder = MapBinder.newMapBinder(binder(), MapBinder<Class, IBridge> mapbinder = MapBinder.newMapBinder(binder(), Class.class, IBridge.class);
Class.class, IBridge.class);
String propsURI = System.getProperty("bridgeManager.propsFile", String propsURI = System.getProperty("bridgeManager.propsFile", "bridge-manager.properties");
"bridge-manager.properties");
List<Class<? extends IBridge>> bridges = getBridgeClasses(propsURI); List<Class<? extends IBridge>> bridges = getBridgeClasses(propsURI);
for (Class<? extends IBridge> bridgeClass : bridges) { for (Class<? extends IBridge> bridgeClass : bridges) {
...@@ -59,8 +56,7 @@ public class BridgeModule extends AbstractModule { ...@@ -59,8 +56,7 @@ public class BridgeModule extends AbstractModule {
/* /*
* Get the bridge classes from the configuration file * Get the bridge classes from the configuration file
*/ */
private List<Class<? extends IBridge>> getBridgeClasses( private List<Class<? extends IBridge>> getBridgeClasses(String bridgePropFileName) {
String bridgePropFileName) {
List<Class<? extends IBridge>> aBList = new ArrayList<Class<? extends IBridge>>(); List<Class<? extends IBridge>> aBList = new ArrayList<Class<? extends IBridge>>();
PropertiesConfiguration config = new PropertiesConfiguration(); PropertiesConfiguration config = new PropertiesConfiguration();
...@@ -68,13 +64,11 @@ public class BridgeModule extends AbstractModule { ...@@ -68,13 +64,11 @@ public class BridgeModule extends AbstractModule {
try { try {
LOG.info("Loading : Active Bridge List"); LOG.info("Loading : Active Bridge List");
config.load(bridgePropFileName); config.load(bridgePropFileName);
String[] activeBridgeList = ((String) config String[] activeBridgeList = ((String) config.getProperty("BridgeManager.activeBridges")).split(",");
.getProperty("BridgeManager.activeBridges")).split(",");
LOG.info("Loaded : Active Bridge List"); LOG.info("Loaded : Active Bridge List");
for (String s : activeBridgeList) { for (String s : activeBridgeList) {
Class<? extends IBridge> bridgeCls = (Class<? extends IBridge>) Class Class<? extends IBridge> bridgeCls = (Class<? extends IBridge>) Class.forName(s);
.forName(s);
aBList.add(bridgeCls); aBList.add(bridgeCls);
} }
......
...@@ -38,8 +38,7 @@ public class BridgeManagerTest { ...@@ -38,8 +38,7 @@ public class BridgeManagerTest {
BridgeManager bm = new BridgeManager(repo); BridgeManager bm = new BridgeManager(repo);
System.out.println(bm.getActiveBridges().size()); System.out.println(bm.getActiveBridges().size());
Assert.assertEquals(bm.activeBridges.get(0).getClass().getSimpleName(), Assert.assertEquals(bm.activeBridges.get(0).getClass().getSimpleName(), "HiveLineageBridge");
"HiveLineageBridge");
} }
@Test @Test
......
...@@ -50,8 +50,7 @@ public class TestHiveLineageBridge { ...@@ -50,8 +50,7 @@ public class TestHiveLineageBridge {
String oneId; String oneId;
private HiveLineage loadHiveLineageBean(String path) throws IOException { private HiveLineage loadHiveLineageBean(String path) throws IOException {
return new Gson().fromJson(new InputStreamReader(this.getClass().getResourceAsStream(path)), return new Gson().fromJson(new InputStreamReader(this.getClass().getResourceAsStream(path)), HiveLineage.class);
HiveLineage.class);
} }
@BeforeClass @BeforeClass
......
...@@ -86,7 +86,8 @@ public class AtlasClient { ...@@ -86,7 +86,8 @@ public class AtlasClient {
try { try {
clientConfig = getClientProperties(); clientConfig = getClientProperties();
if (clientConfig.getBoolean(TLS_ENABLED, false)) { if (clientConfig.getBoolean(TLS_ENABLED, false)) {
// create an SSL properties configuration if one doesn't exist. SSLFactory expects a file, so forced to create a // create an SSL properties configuration if one doesn't exist. SSLFactory expects a file, so forced
// to create a
// configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory // configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory
SecureClientUtils.persistSSLClientConfiguration(clientConfig); SecureClientUtils.persistSSLClientConfiguration(clientConfig);
} }
...@@ -246,12 +247,12 @@ public class AtlasClient { ...@@ -246,12 +247,12 @@ public class AtlasClient {
* @return result json object * @return result json object
* @throws AtlasServiceException * @throws AtlasServiceException
*/ */
public JSONArray rawSearch(String typeName, String attributeName, Object attributeValue) throws public JSONArray rawSearch(String typeName, String attributeName, Object attributeValue)
AtlasServiceException { throws AtlasServiceException {
// String gremlinQuery = String.format( // String gremlinQuery = String.format(
// "g.V.has(\"typeName\",\"%s\").and(_().has(\"%s.%s\", T.eq, \"%s\")).toList()", // "g.V.has(\"typeName\",\"%s\").and(_().has(\"%s.%s\", T.eq, \"%s\")).toList()",
// typeName, typeName, attributeName, attributeValue); // typeName, typeName, attributeName, attributeValue);
// return searchByGremlin(gremlinQuery); // return searchByGremlin(gremlinQuery);
String dslQuery = String.format("%s where %s = \"%s\"", typeName, attributeName, attributeValue); String dslQuery = String.format("%s where %s = \"%s\"", typeName, attributeName, attributeValue);
return searchByDSL(dslQuery); return searchByDSL(dslQuery);
} }
...@@ -341,13 +342,11 @@ public class AtlasClient { ...@@ -341,13 +342,11 @@ public class AtlasClient {
private JSONObject callAPIWithResource(API api, WebResource resource, Object requestObject) private JSONObject callAPIWithResource(API api, WebResource resource, Object requestObject)
throws AtlasServiceException { throws AtlasServiceException {
ClientResponse clientResponse = resource ClientResponse clientResponse = resource.accept(JSON_MEDIA_TYPE).type(JSON_MEDIA_TYPE)
.accept(JSON_MEDIA_TYPE)
.type(JSON_MEDIA_TYPE)
.method(api.getMethod(), ClientResponse.class, requestObject); .method(api.getMethod(), ClientResponse.class, requestObject);
Response.Status expectedStatus = HttpMethod.POST.equals(api.getMethod()) Response.Status expectedStatus =
? Response.Status.CREATED : Response.Status.OK; HttpMethod.POST.equals(api.getMethod()) ? Response.Status.CREATED : Response.Status.OK;
if (clientResponse.getStatus() == expectedStatus.getStatusCode()) { if (clientResponse.getStatus() == expectedStatus.getStatusCode()) {
String responseAsString = clientResponse.getEntity(String.class); String responseAsString = clientResponse.getEntity(String.class);
try { try {
...@@ -360,8 +359,7 @@ public class AtlasClient { ...@@ -360,8 +359,7 @@ public class AtlasClient {
throw new AtlasServiceException(api, clientResponse); throw new AtlasServiceException(api, clientResponse);
} }
private JSONObject callAPI(API api, Object requestObject, private JSONObject callAPI(API api, Object requestObject, String... pathParams) throws AtlasServiceException {
String... pathParams) throws AtlasServiceException {
WebResource resource = getResource(api, pathParams); WebResource resource = getResource(api, pathParams);
return callAPIWithResource(api, resource, requestObject); return callAPIWithResource(api, resource, requestObject);
} }
......
...@@ -62,9 +62,7 @@ public class SecureClientUtils { ...@@ -62,9 +62,7 @@ public class SecureClientUtils {
public static URLConnectionClientHandler getClientConnectionHandler(DefaultClientConfig config, public static URLConnectionClientHandler getClientConnectionHandler(DefaultClientConfig config,
PropertiesConfiguration clientConfig) { PropertiesConfiguration clientConfig) {
config.getProperties().put( config.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND,
true);
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, "ssl-client.xml")); conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, "ssl-client.xml"));
String authType = "simple"; String authType = "simple";
...@@ -95,11 +93,9 @@ public class SecureClientUtils { ...@@ -95,11 +93,9 @@ public class SecureClientUtils {
return new URLConnectionClientHandler(httpURLConnectionFactory); return new URLConnectionClientHandler(httpURLConnectionFactory);
} }
private final static ConnectionConfigurator DEFAULT_TIMEOUT_CONN_CONFIGURATOR = private final static ConnectionConfigurator DEFAULT_TIMEOUT_CONN_CONFIGURATOR = new ConnectionConfigurator() {
new ConnectionConfigurator() {
@Override @Override
public HttpURLConnection configure(HttpURLConnection conn) public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
throws IOException {
setTimeouts(conn, DEFAULT_SOCKET_TIMEOUT); setTimeouts(conn, DEFAULT_SOCKET_TIMEOUT);
return conn; return conn;
} }
...@@ -109,14 +105,13 @@ public class SecureClientUtils { ...@@ -109,14 +105,13 @@ public class SecureClientUtils {
try { try {
return newSslConnConfigurator(DEFAULT_SOCKET_TIMEOUT, conf); return newSslConnConfigurator(DEFAULT_SOCKET_TIMEOUT, conf);
} catch (Exception e) { } catch (Exception e) {
LOG.debug("Cannot load customized ssl related configuration. " + LOG.debug("Cannot load customized ssl related configuration. " + "Fallback to system-generic settings.", e);
"Fallback to system-generic settings.", e);
return DEFAULT_TIMEOUT_CONN_CONFIGURATOR; return DEFAULT_TIMEOUT_CONN_CONFIGURATOR;
} }
} }
private static ConnectionConfigurator newSslConnConfigurator(final int timeout, private static ConnectionConfigurator newSslConnConfigurator(final int timeout, Configuration conf)
Configuration conf) throws IOException, GeneralSecurityException { throws IOException, GeneralSecurityException {
final SSLFactory factory; final SSLFactory factory;
final SSLSocketFactory sf; final SSLSocketFactory sf;
final HostnameVerifier hv; final HostnameVerifier hv;
...@@ -128,8 +123,7 @@ public class SecureClientUtils { ...@@ -128,8 +123,7 @@ public class SecureClientUtils {
return new ConnectionConfigurator() { return new ConnectionConfigurator() {
@Override @Override
public HttpURLConnection configure(HttpURLConnection conn) public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
throws IOException {
if (conn instanceof HttpsURLConnection) { if (conn instanceof HttpsURLConnection) {
HttpsURLConnection c = (HttpsURLConnection) conn; HttpsURLConnection c = (HttpsURLConnection) conn;
c.setSSLSocketFactory(sf); c.setSSLSocketFactory(sf);
...@@ -168,7 +162,8 @@ public class SecureClientUtils { ...@@ -168,7 +162,8 @@ public class SecureClientUtils {
return new File(sslDir, SecurityProperties.SSL_CLIENT_PROPERTIES); return new File(sslDir, SecurityProperties.SSL_CLIENT_PROPERTIES);
} }
public static void persistSSLClientConfiguration(PropertiesConfiguration clientConfig) throws AtlasException, IOException { public static void persistSSLClientConfiguration(PropertiesConfiguration clientConfig)
throws AtlasException, IOException {
//trust settings //trust settings
Configuration configuration = new Configuration(false); Configuration configuration = new Configuration(false);
File sslClientFile = getSSLClientFile(); File sslClientFile = getSSLClientFile();
......
...@@ -36,18 +36,10 @@ import java.util.Properties; ...@@ -36,18 +36,10 @@ import java.util.Properties;
* *
*/ */
public class BaseSecurityTest { public class BaseSecurityTest {
private static final String JAAS_ENTRY = private static final String JAAS_ENTRY = "%s { \n" + " %s required\n"
"%s { \n"
+ " %s required\n"
// kerberos module // kerberos module
+ " keyTab=\"%s\"\n" + " keyTab=\"%s\"\n" + " debug=true\n" + " principal=\"%s\"\n" + " useKeyTab=true\n"
+ " debug=true\n" + " useTicketCache=false\n" + " doNotPrompt=true\n" + " storeKey=true;\n" + "}; \n";
+ " principal=\"%s\"\n"
+ " useKeyTab=true\n"
+ " useTicketCache=false\n"
+ " doNotPrompt=true\n"
+ " storeKey=true;\n"
+ "}; \n";
protected MiniKdc kdc; protected MiniKdc kdc;
protected String getWarPath() { protected String getWarPath() {
...@@ -56,8 +48,8 @@ public class BaseSecurityTest { ...@@ -56,8 +48,8 @@ public class BaseSecurityTest {
} }
protected void generateTestProperties(Properties props) throws ConfigurationException, IOException { protected void generateTestProperties(Properties props) throws ConfigurationException, IOException {
PropertiesConfiguration config = new PropertiesConfiguration(System.getProperty("user.dir") + PropertiesConfiguration config =
"/../src/conf/application.properties"); new PropertiesConfiguration(System.getProperty("user.dir") + "/../src/conf/application.properties");
for (String propName : props.stringPropertyNames()) { for (String propName : props.stringPropertyNames()) {
config.setProperty(propName, props.getProperty(propName)); config.setProperty(propName, props.getProperty(propName));
} }
...@@ -88,20 +80,11 @@ public class BaseSecurityTest { ...@@ -88,20 +80,11 @@ public class BaseSecurityTest {
return kdcWorkDir; return kdcWorkDir;
} }
public String createJAASEntry( public String createJAASEntry(String context, String principal, File keytab) {
String context,
String principal,
File keytab) {
String keytabpath = keytab.getAbsolutePath(); String keytabpath = keytab.getAbsolutePath();
// fix up for windows; no-op on unix // fix up for windows; no-op on unix
keytabpath = keytabpath.replace('\\', '/'); keytabpath = keytabpath.replace('\\', '/');
return String.format( return String.format(Locale.ENGLISH, JAAS_ENTRY, context, getKerberosAuthModuleForJVM(), keytabpath, principal);
Locale.ENGLISH,
JAAS_ENTRY,
context,
getKerberosAuthModuleForJVM(),
keytabpath,
principal);
} }
protected String getKerberosAuthModuleForJVM() { protected String getKerberosAuthModuleForJVM() {
...@@ -119,10 +102,7 @@ public class BaseSecurityTest { ...@@ -119,10 +102,7 @@ public class BaseSecurityTest {
protected File createKeytab(MiniKdc kdc, File kdcWorkDir, String principal, String filename) throws Exception { protected File createKeytab(MiniKdc kdc, File kdcWorkDir, String principal, String filename) throws Exception {
File keytab = new File(kdcWorkDir, filename); File keytab = new File(kdcWorkDir, filename);
kdc.createPrincipal(keytab, kdc.createPrincipal(keytab, principal, principal + "/localhost", principal + "/127.0.0.1");
principal,
principal + "/localhost",
principal + "/127.0.0.1");
return keytab; return keytab;
} }
} }
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
<MaxPermGen>512m</MaxPermGen> <MaxPermGen>512m</MaxPermGen>
<SnapshotsId>apache.snapshots.repo</SnapshotsId> <SnapshotsId>apache.snapshots.repo</SnapshotsId>
<SnapshotsName>Apache Snapshot Repository</SnapshotsName> <SnapshotsName>Apache Snapshot Repository</SnapshotsName>
<SnapshotsUrl> https://repository.apache.org/content/groups/snapshots</SnapshotsUrl> <SnapshotsUrl>https://repository.apache.org/content/groups/snapshots</SnapshotsUrl>
<StagingId>apache-staging</StagingId> <StagingId>apache-staging</StagingId>
<StagingName>Apache Release Distribution Repository</StagingName> <StagingName>Apache Release Distribution Repository</StagingName>
<StagingUrl>https://repository.apache.org/content/groups/staging</StagingUrl> <StagingUrl>https://repository.apache.org/content/groups/staging</StagingUrl>
...@@ -110,20 +110,28 @@ ...@@ -110,20 +110,28 @@
<profile> <profile>
<id>Windows</id> <id>Windows</id>
<activation> <activation>
<os><family>windows</family></os> <os>
<family>windows</family>
</os>
</activation> </activation>
<properties> <properties>
<python.path.l>${project.basedir}\src\bin;${project.basedir}\src\test\python\scripts;${project.basedir}\src\test\mock</python.path.l> <python.path.l>
${project.basedir}\src\bin;${project.basedir}\src\test\python\scripts;${project.basedir}\src\test\mock
</python.path.l>
</properties> </properties>
</profile> </profile>
<profile> <profile>
<id>Linux</id> <id>Linux</id>
<activation> <activation>
<os><family>!windows</family></os> <os>
<family>!windows</family>
</os>
</activation> </activation>
<properties> <properties>
<python.path.l>${project.basedir}/src/bin:${project.basedir}/src/test/mock:${project.basedir}/src/test/python/scripts</python.path.l> <python.path.l>
${project.basedir}/src/bin:${project.basedir}/src/test/mock:${project.basedir}/src/test/python/scripts
</python.path.l>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>
...@@ -913,7 +921,8 @@ ...@@ -913,7 +921,8 @@
<redirectTestOutputToFile>true</redirectTestOutputToFile> <redirectTestOutputToFile>true</redirectTestOutputToFile>
<argLine>-Djava.awt.headless=true -Dproject.version=${project.version} <argLine>-Djava.awt.headless=true -Dproject.version=${project.version}
-Dhadoop.tmp.dir=${project.build.directory}/tmp-hadoop-${user.name} -Dhadoop.tmp.dir=${project.build.directory}/tmp-hadoop-${user.name}
-Xmx1024m -XX:MaxPermSize=512m</argLine> -Xmx1024m -XX:MaxPermSize=512m
</argLine>
</configuration> </configuration>
<dependencies> <dependencies>
<dependency> <dependency>
......
...@@ -22,5 +22,7 @@ import java.lang.annotation.Retention; ...@@ -22,5 +22,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME)
public @interface GraphTransaction {} @Target(ElementType.METHOD)
public @interface GraphTransaction {
}
...@@ -42,7 +42,7 @@ public class GraphTransactionInterceptor implements MethodInterceptor { ...@@ -42,7 +42,7 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
titanGraph.commit(); titanGraph.commit();
LOG.debug("graph commit"); LOG.debug("graph commit");
return response; return response;
} catch (Throwable t){ } catch (Throwable t) {
titanGraph.rollback(); titanGraph.rollback();
LOG.error("graph rollback due to exception ", t); LOG.error("graph rollback due to exception ", t);
throw t; throw t;
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
package org.apache.atlas; package org.apache.atlas;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.google.inject.matcher.Matchers; import com.google.inject.matcher.Matchers;
import com.google.inject.multibindings.Multibinder; import com.google.inject.multibindings.Multibinder;
import com.google.inject.throwingproviders.ThrowingProviderBinder; import com.google.inject.throwingproviders.ThrowingProviderBinder;
...@@ -28,7 +26,6 @@ import org.aopalliance.intercept.MethodInterceptor; ...@@ -28,7 +26,6 @@ import org.aopalliance.intercept.MethodInterceptor;
import org.apache.atlas.discovery.DiscoveryService; import org.apache.atlas.discovery.DiscoveryService;
import org.apache.atlas.discovery.HiveLineageService; import org.apache.atlas.discovery.HiveLineageService;
import org.apache.atlas.discovery.LineageService; import org.apache.atlas.discovery.LineageService;
import org.apache.atlas.discovery.SearchIndexer;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService; import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
import org.apache.atlas.listener.TypesChangeListener; import org.apache.atlas.listener.TypesChangeListener;
import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.MetadataRepository;
...@@ -49,9 +46,7 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule { ...@@ -49,9 +46,7 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
// special wiring for Titan Graph // special wiring for Titan Graph
ThrowingProviderBinder.create(binder()) ThrowingProviderBinder.create(binder()).bind(GraphProvider.class, TitanGraph.class).to(TitanGraphProvider.class)
.bind(GraphProvider.class, TitanGraph.class)
.to(TitanGraphProvider.class)
.asEagerSingleton(); .asEagerSingleton();
// allow for dynamic binding of the metadata repo & graph service // allow for dynamic binding of the metadata repo & graph service
...@@ -62,7 +57,8 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule { ...@@ -62,7 +57,8 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule {
// bind the ITypeStore interface to an implementation // bind the ITypeStore interface to an implementation
bind(ITypeStore.class).to(GraphBackedTypeStore.class).asEagerSingleton(); bind(ITypeStore.class).to(GraphBackedTypeStore.class).asEagerSingleton();
Multibinder<TypesChangeListener> typesChangeListenerBinder = Multibinder.newSetBinder(binder(), TypesChangeListener.class); Multibinder<TypesChangeListener> typesChangeListenerBinder =
Multibinder.newSetBinder(binder(), TypesChangeListener.class);
typesChangeListenerBinder.addBinding().to(GraphBackedSearchIndexer.class); typesChangeListenerBinder.addBinding().to(GraphBackedSearchIndexer.class);
// bind the MetadataService interface to an implementation // bind the MetadataService interface to an implementation
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
package org.apache.atlas.discovery; package org.apache.atlas.discovery;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.ParamChecker; import org.apache.atlas.ParamChecker;
import org.apache.atlas.PropertiesUtil; import org.apache.atlas.PropertiesUtil;
import org.apache.atlas.discovery.graph.DefaultGraphPersistenceStrategy; import org.apache.atlas.discovery.graph.DefaultGraphPersistenceStrategy;
...@@ -65,20 +65,14 @@ public class HiveLineageService implements LineageService { ...@@ -65,20 +65,14 @@ public class HiveLineageService implements LineageService {
// todo - externalize this using type system - dog food // todo - externalize this using type system - dog food
try { try {
PropertiesConfiguration conf = PropertiesUtil.getApplicationProperties(); PropertiesConfiguration conf = PropertiesUtil.getApplicationProperties();
HIVE_TABLE_TYPE_NAME = HIVE_TABLE_TYPE_NAME = conf.getString("atlas.lineage.hive.table.type.name", "DataSet");
conf.getString("atlas.lineage.hive.table.type.name", "DataSet"); HIVE_PROCESS_TYPE_NAME = conf.getString("atlas.lineage.hive.process.type.name", "Process");
HIVE_PROCESS_TYPE_NAME = HIVE_PROCESS_INPUT_ATTRIBUTE_NAME = conf.getString("atlas.lineage.hive.process.inputs.name", "inputs");
conf.getString("atlas.lineage.hive.process.type.name", "Process"); HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME = conf.getString("atlas.lineage.hive.process.outputs.name", "outputs");
HIVE_PROCESS_INPUT_ATTRIBUTE_NAME =
conf.getString("atlas.lineage.hive.process.inputs.name", "inputs"); HIVE_TABLE_SCHEMA_QUERY =
HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME = conf.getString("atlas.lineage.hive.table.schema.query", "hive_table where name=\"%s\", columns");
conf.getString("atlas.lineage.hive.process.outputs.name", "outputs"); HIVE_TABLE_EXISTS_QUERY = conf.getString("atlas.lineage.hive.table.exists.query",
HIVE_TABLE_SCHEMA_QUERY = conf.getString(
"atlas.lineage.hive.table.schema.query",
"hive_table where name=\"%s\", columns");
HIVE_TABLE_EXISTS_QUERY = conf.getString(
"atlas.lineage.hive.table.exists.query",
"from " + HIVE_TABLE_TYPE_NAME + " where name=\"%s\""); "from " + HIVE_TABLE_TYPE_NAME + " where name=\"%s\"");
} catch (AtlasException e) { } catch (AtlasException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -91,8 +85,7 @@ public class HiveLineageService implements LineageService { ...@@ -91,8 +85,7 @@ public class HiveLineageService implements LineageService {
private final GraphBackedDiscoveryService discoveryService; private final GraphBackedDiscoveryService discoveryService;
@Inject @Inject
HiveLineageService(GraphProvider<TitanGraph> graphProvider, HiveLineageService(GraphProvider<TitanGraph> graphProvider, MetadataRepository metadataRepository,
MetadataRepository metadataRepository,
GraphBackedDiscoveryService discoveryService) throws DiscoveryException { GraphBackedDiscoveryService discoveryService) throws DiscoveryException {
this.titanGraph = graphProvider.get(); this.titanGraph = graphProvider.get();
this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository); this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository);
...@@ -112,14 +105,13 @@ public class HiveLineageService implements LineageService { ...@@ -112,14 +105,13 @@ public class HiveLineageService implements LineageService {
ParamChecker.notEmpty(tableName, "table name cannot be null"); ParamChecker.notEmpty(tableName, "table name cannot be null");
validateTableExists(tableName); validateTableExists(tableName);
HiveWhereUsedQuery outputsQuery = new HiveWhereUsedQuery( HiveWhereUsedQuery outputsQuery =
HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, new HiveWhereUsedQuery(HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME,
HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, Option.empty(),
Option.empty(), SELECT_ATTRIBUTES, true, SELECT_ATTRIBUTES, true, graphPersistenceStrategy, titanGraph);
graphPersistenceStrategy, titanGraph);
Expressions.Expression expression = outputsQuery.expr(); Expressions.Expression expression = outputsQuery.expr();
LOG.debug("Expression is [" + expression.toString() +"]"); LOG.debug("Expression is [" + expression.toString() + "]");
try { try {
return discoveryService.evaluate(expression).toJson(); return discoveryService.evaluate(expression).toJson();
} catch (Exception e) { // unable to catch ExpressionException } catch (Exception e) { // unable to catch ExpressionException
...@@ -140,11 +132,10 @@ public class HiveLineageService implements LineageService { ...@@ -140,11 +132,10 @@ public class HiveLineageService implements LineageService {
ParamChecker.notEmpty(tableName, "table name cannot be null"); ParamChecker.notEmpty(tableName, "table name cannot be null");
validateTableExists(tableName); validateTableExists(tableName);
HiveWhereUsedQuery outputsQuery = new HiveWhereUsedQuery( HiveWhereUsedQuery outputsQuery =
HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, new HiveWhereUsedQuery(HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME,
HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, Option.empty(),
Option.empty(), SELECT_ATTRIBUTES, true, SELECT_ATTRIBUTES, true, graphPersistenceStrategy, titanGraph);
graphPersistenceStrategy, titanGraph);
return outputsQuery.graph().toInstanceJson(); return outputsQuery.graph().toInstanceJson();
} }
...@@ -161,14 +152,12 @@ public class HiveLineageService implements LineageService { ...@@ -161,14 +152,12 @@ public class HiveLineageService implements LineageService {
ParamChecker.notEmpty(tableName, "table name cannot be null"); ParamChecker.notEmpty(tableName, "table name cannot be null");
validateTableExists(tableName); validateTableExists(tableName);
HiveLineageQuery inputsQuery = new HiveLineageQuery( HiveLineageQuery inputsQuery = new HiveLineageQuery(HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME,
HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, Option.empty(),
HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, SELECT_ATTRIBUTES, true, graphPersistenceStrategy, titanGraph);
Option.empty(), SELECT_ATTRIBUTES, true,
graphPersistenceStrategy, titanGraph);
Expressions.Expression expression = inputsQuery.expr(); Expressions.Expression expression = inputsQuery.expr();
LOG.debug("Expression is [" + expression.toString() +"]"); LOG.debug("Expression is [" + expression.toString() + "]");
try { try {
return discoveryService.evaluate(expression).toJson(); return discoveryService.evaluate(expression).toJson();
} catch (Exception e) { // unable to catch ExpressionException } catch (Exception e) { // unable to catch ExpressionException
...@@ -189,11 +178,9 @@ public class HiveLineageService implements LineageService { ...@@ -189,11 +178,9 @@ public class HiveLineageService implements LineageService {
ParamChecker.notEmpty(tableName, "table name cannot be null"); ParamChecker.notEmpty(tableName, "table name cannot be null");
validateTableExists(tableName); validateTableExists(tableName);
HiveLineageQuery inputsQuery = new HiveLineageQuery( HiveLineageQuery inputsQuery = new HiveLineageQuery(HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME,
HIVE_TABLE_TYPE_NAME, tableName, HIVE_PROCESS_TYPE_NAME, HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, Option.empty(),
HIVE_PROCESS_INPUT_ATTRIBUTE_NAME, HIVE_PROCESS_OUTPUT_ATTRIBUTE_NAME, SELECT_ATTRIBUTES, true, graphPersistenceStrategy, titanGraph);
Option.empty(), SELECT_ATTRIBUTES, true,
graphPersistenceStrategy, titanGraph);
return inputsQuery.graph().toInstanceJson(); return inputsQuery.graph().toInstanceJson();
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.atlas.discovery; package org.apache.atlas.discovery;
import org.apache.atlas.listener.TypesChangeListener; import org.apache.atlas.listener.TypesChangeListener;
import org.apache.atlas.repository.IndexException;
/** /**
......
...@@ -47,8 +47,7 @@ import java.util.List; ...@@ -47,8 +47,7 @@ import java.util.List;
*/ */
public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategies { public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategies {
private static final Logger LOG = LoggerFactory private static final Logger LOG = LoggerFactory.getLogger(DefaultGraphPersistenceStrategy.class);
.getLogger(DefaultGraphPersistenceStrategy.class);
private final GraphBackedMetadataRepository metadataRepository; private final GraphBackedMetadataRepository metadataRepository;
...@@ -124,14 +123,12 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi ...@@ -124,14 +123,12 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi
TypeSystem.IdType idType = TypeSystem.getInstance().getIdType(); TypeSystem.IdType idType = TypeSystem.getInstance().getIdType();
if (dataType.getName().equals(idType.getName())) { if (dataType.getName().equals(idType.getName())) {
structInstance.set(idType.typeNameAttrName(), structInstance.set(idType.typeNameAttrName(), structVertex.getProperty(typeAttributeName()));
structVertex.getProperty(typeAttributeName())); structInstance.set(idType.idAttrName(), structVertex.getProperty(idAttributeName()));
structInstance.set(idType.idAttrName(),
structVertex.getProperty(idAttributeName()));
} else { } else {
metadataRepository.getGraphToInstanceMapper().mapVertexToInstance( metadataRepository.getGraphToInstanceMapper()
structVertex, structInstance, structType.fieldMapping().fields); .mapVertexToInstance(structVertex, structInstance, structType.fieldMapping().fields);
} }
return dataType.convert(structInstance, Multiplicity.OPTIONAL); return dataType.convert(structInstance, Multiplicity.OPTIONAL);
...@@ -143,21 +140,19 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi ...@@ -143,21 +140,19 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi
// trait. for now just loading the trait struct. // trait. for now just loading the trait struct.
// metadataRepository.getGraphToInstanceMapper().mapVertexToTraitInstance( // metadataRepository.getGraphToInstanceMapper().mapVertexToTraitInstance(
// traitVertex, dataType.getName(), , traitType, traitInstance); // traitVertex, dataType.getName(), , traitType, traitInstance);
metadataRepository.getGraphToInstanceMapper().mapVertexToInstance( metadataRepository.getGraphToInstanceMapper()
traitVertex, traitInstance, traitType.fieldMapping().fields); .mapVertexToInstance(traitVertex, traitInstance, traitType.fieldMapping().fields);
break; break;
case CLASS: case CLASS:
TitanVertex classVertex = (TitanVertex) value; TitanVertex classVertex = (TitanVertex) value;
ITypedReferenceableInstance classInstance = ITypedReferenceableInstance classInstance = metadataRepository.getGraphToInstanceMapper()
metadataRepository.getGraphToInstanceMapper().mapGraphToTypedInstance( .mapGraphToTypedInstance(classVertex.<String>getProperty(Constants.GUID_PROPERTY_KEY),
classVertex.<String>getProperty(Constants.GUID_PROPERTY_KEY),
classVertex); classVertex);
return dataType.convert(classInstance, Multiplicity.OPTIONAL); return dataType.convert(classInstance, Multiplicity.OPTIONAL);
default: default:
throw new UnsupportedOperationException( throw new UnsupportedOperationException("Load for type " + dataType + "is not supported");
"Load for type " + dataType + "is not supported");
} }
} catch (AtlasException e) { } catch (AtlasException e) {
LOG.error("error while constructing an instance", e); LOG.error("error while constructing an instance", e);
...@@ -168,9 +163,8 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi ...@@ -168,9 +163,8 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi
@Override @Override
public String edgeLabel(TypeUtils.FieldInfo fInfo) { public String edgeLabel(TypeUtils.FieldInfo fInfo) {
return fInfo.reverseDataType() == null return fInfo.reverseDataType() == null ? edgeLabel(fInfo.dataType(), fInfo.attrInfo()) :
? edgeLabel(fInfo.dataType(), fInfo.attrInfo()) edgeLabel(fInfo.reverseDataType(), fInfo.attrInfo());
: edgeLabel(fInfo.reverseDataType(), fInfo.attrInfo());
} }
@Override @Override
...@@ -184,13 +178,19 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi ...@@ -184,13 +178,19 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi
} }
@Override @Override
public String instanceToTraitEdgeDirection() { return "out"; } public String instanceToTraitEdgeDirection() {
return "out";
}
@Override @Override
public String traitToInstanceEdgeDirection() { return "in"; } public String traitToInstanceEdgeDirection() {
return "in";
}
@Override @Override
public String idAttributeName() { return metadataRepository.getIdAttributeName(); } public String idAttributeName() {
return metadataRepository.getIdAttributeName();
}
@Override @Override
public scala.collection.Seq<String> typeTestExpression(String typeName, IntSequence intSeq) { public scala.collection.Seq<String> typeTestExpression(String typeName, IntSequence intSeq) {
......
...@@ -23,8 +23,8 @@ import com.thinkaurelius.titan.core.TitanIndexQuery; ...@@ -23,8 +23,8 @@ import com.thinkaurelius.titan.core.TitanIndexQuery;
import com.thinkaurelius.titan.core.TitanProperty; import com.thinkaurelius.titan.core.TitanProperty;
import com.thinkaurelius.titan.core.TitanVertex; import com.thinkaurelius.titan.core.TitanVertex;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.discovery.DiscoveryException; import org.apache.atlas.discovery.DiscoveryException;
import org.apache.atlas.discovery.DiscoveryService; import org.apache.atlas.discovery.DiscoveryService;
import org.apache.atlas.query.Expressions; import org.apache.atlas.query.Expressions;
...@@ -71,8 +71,8 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -71,8 +71,8 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
public final static String SCORE = "score"; public final static String SCORE = "score";
@Inject @Inject
GraphBackedDiscoveryService(GraphProvider<TitanGraph> graphProvider, GraphBackedDiscoveryService(GraphProvider<TitanGraph> graphProvider, MetadataRepository metadataRepository)
MetadataRepository metadataRepository) throws DiscoveryException { throws DiscoveryException {
this.titanGraph = graphProvider.get(); this.titanGraph = graphProvider.get();
this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository); this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository);
} }
...@@ -143,8 +143,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -143,8 +143,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
public GremlinQueryResult evaluate(Expressions.Expression expression) { public GremlinQueryResult evaluate(Expressions.Expression expression) {
Expressions.Expression validatedExpression = QueryProcessor.validate(expression); Expressions.Expression validatedExpression = QueryProcessor.validate(expression);
GremlinQuery gremlinQuery = GremlinQuery gremlinQuery = new GremlinTranslator(validatedExpression, graphPersistenceStrategy).translate();
new GremlinTranslator(validatedExpression, graphPersistenceStrategy).translate();
LOG.debug("Query = {}", validatedExpression); LOG.debug("Query = {}", validatedExpression);
LOG.debug("Expression Tree = {}", validatedExpression.treeString()); LOG.debug("Expression Tree = {}", validatedExpression.treeString());
LOG.debug("Gremlin Query = {}", gremlinQuery.queryStr()); LOG.debug("Gremlin Query = {}", gremlinQuery.queryStr());
...@@ -162,8 +161,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -162,8 +161,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
*/ */
@Override @Override
@GraphTransaction @GraphTransaction
public List<Map<String, String>> searchByGremlin(String gremlinQuery) public List<Map<String, String>> searchByGremlin(String gremlinQuery) throws DiscoveryException {
throws DiscoveryException {
LOG.info("Executing gremlin query={}", gremlinQuery); LOG.info("Executing gremlin query={}", gremlinQuery);
ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("gremlin-groovy"); ScriptEngine engine = manager.getEngineByName("gremlin-groovy");
...@@ -189,8 +187,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { ...@@ -189,8 +187,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
Map<String, String> oRow = new HashMap<>(); Map<String, String> oRow = new HashMap<>();
if (r instanceof Map) { if (r instanceof Map) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked") Map<Object, Object> iRow = (Map) r;
Map<Object, Object> iRow = (Map) r;
for (Map.Entry e : iRow.entrySet()) { for (Map.Entry e : iRow.entrySet()) {
Object k = e.getKey(); Object k = e.getKey();
Object v = e.getValue(); Object v = e.getValue();
......
...@@ -37,8 +37,7 @@ public class IndexException extends AtlasException { ...@@ -37,8 +37,7 @@ public class IndexException extends AtlasException {
super(cause); super(cause);
} }
public IndexException(String message, Throwable cause, boolean enableSuppression, public IndexException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace);
} }
......
...@@ -123,6 +123,7 @@ public interface MetadataRepository { ...@@ -123,6 +123,7 @@ public interface MetadataRepository {
// Trait management functions // Trait management functions
/** /**
* Gets the list of trait names for a given entity represented by a guid. * Gets the list of trait names for a given entity represented by a guid.
* *
...@@ -139,8 +140,7 @@ public interface MetadataRepository { ...@@ -139,8 +140,7 @@ public interface MetadataRepository {
* @param traitInstance trait instance that needs to be added to entity * @param traitInstance trait instance that needs to be added to entity
* @throws RepositoryException * @throws RepositoryException
*/ */
void addTrait(String guid, void addTrait(String guid, ITypedStruct traitInstance) throws RepositoryException;
ITypedStruct traitInstance) 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.
...@@ -149,8 +149,7 @@ public interface MetadataRepository { ...@@ -149,8 +149,7 @@ public interface MetadataRepository {
* @param traitNameToBeDeleted name of the trait * @param traitNameToBeDeleted name of the trait
* @throws RepositoryException * @throws RepositoryException
*/ */
void deleteTrait(String guid, void deleteTrait(String guid, String traitNameToBeDeleted) throws RepositoryException;
String traitNameToBeDeleted) throws RepositoryException;
/** /**
* Adds the property to the entity that corresponds to the GUID * Adds the property to the entity that corresponds to the GUID
......
...@@ -40,8 +40,7 @@ public class RepositoryException extends AtlasException { ...@@ -40,8 +40,7 @@ public class RepositoryException extends AtlasException {
super(cause); super(cause);
} }
public RepositoryException(String message, Throwable cause, boolean enableSuppression, public RepositoryException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace); super(message, cause, enableSuppression, writableStackTrace);
} }
} }
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import com.google.inject.Provider;
import com.thinkaurelius.titan.core.Cardinality; import com.thinkaurelius.titan.core.Cardinality;
import com.thinkaurelius.titan.core.PropertyKey; import com.thinkaurelius.titan.core.PropertyKey;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
...@@ -29,7 +28,6 @@ import com.tinkerpop.blueprints.Edge; ...@@ -29,7 +28,6 @@ import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.discovery.SearchIndexer; import org.apache.atlas.discovery.SearchIndexer;
import org.apache.atlas.listener.TypesChangeListener;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.IndexCreationException; import org.apache.atlas.repository.IndexCreationException;
import org.apache.atlas.repository.IndexException; import org.apache.atlas.repository.IndexException;
...@@ -62,8 +60,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -62,8 +60,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
private TitanManagement management; private TitanManagement management;
@Inject @Inject
public GraphBackedSearchIndexer(GraphProvider<TitanGraph> graphProvider) public GraphBackedSearchIndexer(GraphProvider<TitanGraph> graphProvider) throws RepositoryException {
throws RepositoryException {
this.titanGraph = graphProvider.get(); this.titanGraph = graphProvider.get();
...@@ -85,27 +82,24 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -85,27 +82,24 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
/* This is called only once, which is the first time Atlas types are made indexable .*/ /* This is called only once, which is the first time Atlas types are made indexable .*/
LOG.info("Indexes do not exist, Creating indexes for titanGraph."); LOG.info("Indexes do not exist, Creating indexes for titanGraph.");
management.buildIndex(Constants.VERTEX_INDEX, Vertex.class) management.buildIndex(Constants.VERTEX_INDEX, Vertex.class).buildMixedIndex(Constants.BACKING_INDEX);
.buildMixedIndex(Constants.BACKING_INDEX); management.buildIndex(Constants.EDGE_INDEX, Edge.class).buildMixedIndex(Constants.BACKING_INDEX);
management.buildIndex(Constants.EDGE_INDEX, Edge.class)
.buildMixedIndex(Constants.BACKING_INDEX);
// create a composite index for guid as its unique // create a composite index for guid as its unique
createCompositeIndex(Constants.GUID_INDEX, createCompositeIndex(Constants.GUID_INDEX, Constants.GUID_PROPERTY_KEY, String.class, true, Cardinality.SINGLE);
Constants.GUID_PROPERTY_KEY, String.class, true, Cardinality.SINGLE);
// create a composite and mixed index for type since it can be combined with other keys // create a composite and mixed index for type since it can be combined with other keys
createCompositeAndMixedIndex(Constants.ENTITY_TYPE_INDEX, createCompositeAndMixedIndex(Constants.ENTITY_TYPE_INDEX, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class,
Constants.ENTITY_TYPE_PROPERTY_KEY, String.class, false, Cardinality.SINGLE); false, Cardinality.SINGLE);
// create a composite and mixed index for type since it can be combined with other keys // create a composite and mixed index for type since it can be combined with other keys
createCompositeAndMixedIndex(Constants.SUPER_TYPES_INDEX, createCompositeAndMixedIndex(Constants.SUPER_TYPES_INDEX, Constants.SUPER_TYPES_PROPERTY_KEY, String.class,
Constants.SUPER_TYPES_PROPERTY_KEY, String.class, false, Cardinality.SET); false, Cardinality.SET);
// create a composite and mixed index for traitNames since it can be combined with other // create a composite and mixed index for traitNames since it can be combined with other
// keys. Traits must be a set and not a list. // keys. Traits must be a set and not a list.
createCompositeAndMixedIndex(Constants.TRAIT_NAMES_INDEX, createCompositeAndMixedIndex(Constants.TRAIT_NAMES_INDEX, Constants.TRAIT_NAMES_PROPERTY_KEY, String.class,
Constants.TRAIT_NAMES_PROPERTY_KEY, String.class, false, Cardinality.SET); false, Cardinality.SET);
// Index for full text search // Index for full text search
createFullTextIndex(); createFullTextIndex();
...@@ -132,8 +126,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -132,8 +126,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
private void createTypeStoreIndexes() { private void createTypeStoreIndexes() {
//Create unique index on typeName //Create unique index on typeName
createCompositeIndex(Constants.TYPENAME_PROPERTY_KEY, Constants.TYPENAME_PROPERTY_KEY, String.class, createCompositeIndex(Constants.TYPENAME_PROPERTY_KEY, Constants.TYPENAME_PROPERTY_KEY, String.class, true,
true, Cardinality.SINGLE); Cardinality.SINGLE);
//create index on vertex type //create index on vertex type
createCompositeIndex(Constants.VERTEX_TYPE_PROPERTY_KEY, Constants.VERTEX_TYPE_PROPERTY_KEY, String.class, createCompositeIndex(Constants.VERTEX_TYPE_PROPERTY_KEY, Constants.VERTEX_TYPE_PROPERTY_KEY, String.class,
...@@ -150,7 +144,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -150,7 +144,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
@Override @Override
public void onAdd(Collection<? extends IDataType> dataTypes) throws AtlasException { public void onAdd(Collection<? extends IDataType> dataTypes) throws AtlasException {
for(IDataType dataType : dataTypes) { for (IDataType dataType : dataTypes) {
LOG.info("Creating indexes for type name={}, definition={}", dataType.getName(), dataType.getClass()); LOG.info("Creating indexes for type name={}, definition={}", dataType.getName(), dataType.getClass());
try { try {
addIndexForType(dataType); addIndexForType(dataType);
...@@ -285,27 +279,21 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -285,27 +279,21 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
} }
*/ */
private void createCompositeAndMixedIndex(String indexName, private void createCompositeAndMixedIndex(String indexName, String propertyName, Class propertyClass,
String propertyName, Class propertyClass,
boolean isUnique, Cardinality cardinality) { boolean isUnique, Cardinality cardinality) {
createCompositeIndex(indexName, propertyName, propertyClass, isUnique, cardinality); createCompositeIndex(indexName, propertyName, propertyClass, isUnique, cardinality);
createVertexMixedIndex(propertyName, propertyClass); createVertexMixedIndex(propertyName, propertyClass);
} }
private PropertyKey createCompositeIndex(String indexName, private PropertyKey createCompositeIndex(String indexName, String propertyName, Class propertyClass,
String propertyName, Class propertyClass,
boolean isUnique, Cardinality cardinality) { boolean isUnique, Cardinality cardinality) {
PropertyKey propertyKey = management.getPropertyKey(propertyName); PropertyKey propertyKey = management.getPropertyKey(propertyName);
if (propertyKey == null) { if (propertyKey == null) {
propertyKey = management propertyKey =
.makePropertyKey(propertyName) management.makePropertyKey(propertyName).dataType(propertyClass).cardinality(cardinality).make();
.dataType(propertyClass)
.cardinality(cardinality)
.make();
TitanManagement.IndexBuilder indexBuilder = management TitanManagement.IndexBuilder indexBuilder =
.buildIndex(indexName, Vertex.class) management.buildIndex(indexName, Vertex.class).addKey(propertyKey);
.addKey(propertyKey);
if (isUnique) { if (isUnique) {
indexBuilder = indexBuilder.unique(); indexBuilder = indexBuilder.unique();
...@@ -323,13 +311,11 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -323,13 +311,11 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
PropertyKey propertyKey = management.getPropertyKey(propertyName); PropertyKey propertyKey = management.getPropertyKey(propertyName);
if (propertyKey == null) { if (propertyKey == null) {
// ignored cardinality as Can only index single-valued property keys on vertices // ignored cardinality as Can only index single-valued property keys on vertices
propertyKey = management propertyKey = management.makePropertyKey(propertyName).dataType(propertyClass).make();
.makePropertyKey(propertyName)
.dataType(propertyClass)
.make();
if (!checkIfMixedIndexApplicable(propertyClass)) { if (!checkIfMixedIndexApplicable(propertyClass)) {
LOG.debug("Creating composite index for property {} of type {} ", propertyName, propertyClass.getName()); LOG.debug("Creating composite index for property {} of type {} ", propertyName,
propertyClass.getName());
//Use standard index as backing index only supports string, int and geo types //Use standard index as backing index only supports string, int and geo types
management.buildIndex(propertyName, Vertex.class).addKey(propertyKey).buildCompositeIndex(); management.buildIndex(propertyName, Vertex.class).addKey(propertyKey).buildCompositeIndex();
LOG.debug("Created composite index for property {} of type {} ", propertyName, propertyClass.getName()); LOG.debug("Created composite index for property {} of type {} ", propertyName, propertyClass.getName());
...@@ -348,7 +334,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -348,7 +334,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
private boolean checkIfMixedIndexApplicable(Class propertyClass) { private boolean checkIfMixedIndexApplicable(Class propertyClass) {
//TODO - Check why date types are failing in ES/Solr //TODO - Check why date types are failing in ES/Solr
if (propertyClass == Boolean.class || propertyClass == BigDecimal.class || propertyClass == BigInteger.class || propertyClass == Date.class) { if (propertyClass == Boolean.class || propertyClass == BigDecimal.class || propertyClass == BigInteger.class
|| propertyClass == Date.class) {
return false; return false;
} }
return true; return true;
...@@ -358,8 +345,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -358,8 +345,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
try { try {
management.commit(); management.commit();
} catch (Exception e) { } catch (Exception e) {
LOG.error("Index commit failed" , e); LOG.error("Index commit failed", e);
throw new IndexException("Index commit failed " , e); throw new IndexException("Index commit failed ", e);
} }
} }
...@@ -367,8 +354,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer { ...@@ -367,8 +354,8 @@ public class GraphBackedSearchIndexer implements SearchIndexer {
try { try {
management.rollback(); management.rollback();
} catch (Exception e) { } catch (Exception e) {
LOG.error("Index rollback failed " , e); LOG.error("Index rollback failed ", e);
throw new IndexException("Index rollback failed " , e); throw new IndexException("Index rollback failed ", e);
} }
} }
......
...@@ -45,11 +45,10 @@ public final class GraphHelper { ...@@ -45,11 +45,10 @@ public final class GraphHelper {
private GraphHelper() { private GraphHelper() {
} }
public static Vertex createVertexWithIdentity(Graph graph, public static Vertex createVertexWithIdentity(Graph graph, ITypedReferenceableInstance typedInstance,
ITypedReferenceableInstance typedInstance,
Set<String> superTypeNames) { Set<String> superTypeNames) {
final Vertex vertexWithIdentity = createVertexWithoutIdentity( final Vertex vertexWithIdentity =
graph, typedInstance.getTypeName(), typedInstance.getId(), superTypeNames); createVertexWithoutIdentity(graph, typedInstance.getTypeName(), typedInstance.getId(), superTypeNames);
// add identity // add identity
final String guid = UUID.randomUUID().toString(); final String guid = UUID.randomUUID().toString();
...@@ -58,9 +57,7 @@ public final class GraphHelper { ...@@ -58,9 +57,7 @@ public final class GraphHelper {
return vertexWithIdentity; return vertexWithIdentity;
} }
public static Vertex createVertexWithoutIdentity(Graph graph, public static Vertex createVertexWithoutIdentity(Graph graph, String typeName, Id typedInstanceId,
String typeName,
Id typedInstanceId,
Set<String> superTypeNames) { Set<String> superTypeNames) {
final Vertex vertexWithoutIdentity = graph.addVertex(null); final Vertex vertexWithoutIdentity = graph.addVertex(null);
...@@ -69,34 +66,28 @@ public final class GraphHelper { ...@@ -69,34 +66,28 @@ public final class GraphHelper {
// add super types // add super types
for (String superTypeName : superTypeNames) { for (String superTypeName : superTypeNames) {
((TitanVertex) vertexWithoutIdentity).addProperty( ((TitanVertex) vertexWithoutIdentity).addProperty(Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName);
Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName);
} }
// add version information // add version information
vertexWithoutIdentity.setProperty(Constants.VERSION_PROPERTY_KEY, typedInstanceId.version); vertexWithoutIdentity.setProperty(Constants.VERSION_PROPERTY_KEY, typedInstanceId.version);
// add timestamp information // add timestamp information
vertexWithoutIdentity.setProperty( vertexWithoutIdentity.setProperty(Constants.TIMESTAMP_PROPERTY_KEY, System.currentTimeMillis());
Constants.TIMESTAMP_PROPERTY_KEY, System.currentTimeMillis());
return vertexWithoutIdentity; return vertexWithoutIdentity;
} }
public static Edge addEdge(TitanGraph titanGraph, Vertex fromVertex, Vertex toVertex, public static Edge addEdge(TitanGraph titanGraph, Vertex fromVertex, Vertex toVertex, String edgeLabel) {
String edgeLabel) { LOG.debug("Adding edge for {} -> label {} -> {}", fromVertex, edgeLabel, toVertex);
LOG.debug("Adding edge for {} -> label {} -> {}",
fromVertex, edgeLabel, toVertex);
return titanGraph.addEdge(null, fromVertex, toVertex, edgeLabel); return titanGraph.addEdge(null, fromVertex, toVertex, edgeLabel);
} }
public static Vertex findVertexByGUID(TitanGraph titanGraph, public static Vertex findVertexByGUID(TitanGraph titanGraph, String value) {
String value) {
LOG.debug("Finding vertex for key={}, value={}", Constants.GUID_PROPERTY_KEY, value); LOG.debug("Finding vertex for key={}, value={}", Constants.GUID_PROPERTY_KEY, value);
GraphQuery query = titanGraph.query() GraphQuery query = titanGraph.query().has(Constants.GUID_PROPERTY_KEY, value);
.has(Constants.GUID_PROPERTY_KEY, value);
Iterator<Vertex> results = query.vertices().iterator(); Iterator<Vertex> results = query.vertices().iterator();
// returning one since guid should be unique // returning one since guid should be unique
return results.hasNext() ? results.next() : null; return results.hasNext() ? results.next() : null;
...@@ -105,20 +96,15 @@ public final class GraphHelper { ...@@ -105,20 +96,15 @@ public final class GraphHelper {
public static String vertexString(final Vertex vertex) { public static String vertexString(final Vertex vertex) {
StringBuilder properties = new StringBuilder(); StringBuilder properties = new StringBuilder();
for (String propertyKey : vertex.getPropertyKeys()) { for (String propertyKey : vertex.getPropertyKeys()) {
properties.append(propertyKey) properties.append(propertyKey).append("=").append(vertex.getProperty(propertyKey)).append(", ");
.append("=").append(vertex.getProperty(propertyKey))
.append(", ");
} }
return "v[" + vertex.getId() + "], Properties[" + properties + "]"; return "v[" + vertex.getId() + "], Properties[" + properties + "]";
} }
public static String edgeString(final Edge edge) { public static String edgeString(final Edge edge) {
return "e[" + edge.getLabel() + "], [" return "e[" + edge.getLabel() + "], [" + edge.getVertex(Direction.OUT) + " -> " + edge.getLabel() + " -> "
+ edge.getVertex(Direction.OUT) + edge.getVertex(Direction.IN) + "]";
+ " -> " + edge.getLabel() + " -> "
+ edge.getVertex(Direction.IN)
+ "]";
} }
/* /*
......
...@@ -32,8 +32,7 @@ public class ClassStore extends HierarchicalTypeStore { ...@@ -32,8 +32,7 @@ public class ClassStore extends HierarchicalTypeStore {
final ArrayList<ImmutableList<String>> traitNamesStore; final ArrayList<ImmutableList<String>> traitNamesStore;
final ClassType classType; final ClassType classType;
public ClassStore(MemRepository repository, ClassType hierarchicalType) public ClassStore(MemRepository repository, ClassType hierarchicalType) throws RepositoryException {
throws RepositoryException {
super(repository, hierarchicalType); super(repository, hierarchicalType);
classType = hierarchicalType; classType = hierarchicalType;
traitNamesStore = new ArrayList<ImmutableList<String>>(); traitNamesStore = new ArrayList<ImmutableList<String>>();
...@@ -64,8 +63,7 @@ public class ClassStore extends HierarchicalTypeStore { ...@@ -64,8 +63,7 @@ public class ClassStore extends HierarchicalTypeStore {
String typeName = typeNameList.get(pos); String typeName = typeNameList.get(pos);
if (typeName != hierarchicalType.getName()) { if (typeName != hierarchicalType.getName()) {
throw new RepositoryException( throw new RepositoryException(
String.format("Invalid Id (incorrect typeName, type is %s) : %s", String.format("Invalid Id (incorrect typeName, type is %s) : %s", typeName, id));
typeName, id));
} }
return true; return true;
......
...@@ -60,13 +60,11 @@ public abstract class HierarchicalTypeStore { ...@@ -60,13 +60,11 @@ public abstract class HierarchicalTypeStore {
*/ */
ReentrantReadWriteLock lock; ReentrantReadWriteLock lock;
HierarchicalTypeStore(MemRepository repository, HierarchicalType hierarchicalType) HierarchicalTypeStore(MemRepository repository, HierarchicalType hierarchicalType) throws RepositoryException {
throws RepositoryException {
this.hierarchicalType = (IConstructableType) hierarchicalType; this.hierarchicalType = (IConstructableType) hierarchicalType;
this.repository = repository; this.repository = repository;
ImmutableMap.Builder<AttributeInfo, IAttributeStore> b ImmutableMap.Builder<AttributeInfo, IAttributeStore> b =
= new ImmutableBiMap.Builder<AttributeInfo, new ImmutableBiMap.Builder<AttributeInfo, IAttributeStore>();
IAttributeStore>();
typeNameList = Lists.newArrayList((String) null); typeNameList = Lists.newArrayList((String) null);
ImmutableList<AttributeInfo> l = hierarchicalType.immediateAttrs; ImmutableList<AttributeInfo> l = hierarchicalType.immediateAttrs;
for (AttributeInfo i : l) { for (AttributeInfo i : l) {
...@@ -74,8 +72,7 @@ public abstract class HierarchicalTypeStore { ...@@ -74,8 +72,7 @@ public abstract class HierarchicalTypeStore {
} }
attrStores = b.build(); attrStores = b.build();
ImmutableList.Builder<HierarchicalTypeStore> b1 ImmutableList.Builder<HierarchicalTypeStore> b1 = new ImmutableList.Builder<HierarchicalTypeStore>();
= new ImmutableList.Builder<HierarchicalTypeStore>();
Set<String> allSuperTypeNames = hierarchicalType.getAllSuperTypeNames(); Set<String> allSuperTypeNames = hierarchicalType.getAllSuperTypeNames();
for (String s : allSuperTypeNames) { for (String s : allSuperTypeNames) {
b1.add(repository.getStore(s)); b1.add(repository.getStore(s));
......
...@@ -29,8 +29,7 @@ public interface IAttributeStore { ...@@ -29,8 +29,7 @@ public interface IAttributeStore {
* @param instance * @param instance
* @throws RepositoryException * @throws RepositoryException
*/ */
void store(int pos, IConstructableType type, StructInstance instance) void store(int pos, IConstructableType type, StructInstance instance) throws RepositoryException;
throws RepositoryException;
/** /**
* load the Instance with the value from position 'pos' for the attribute. * load the Instance with the value from position 'pos' for the attribute.
......
...@@ -129,9 +129,8 @@ public class MemRepository implements IRepository { ...@@ -129,9 +129,8 @@ public class MemRepository implements IRepository {
*/ */
for (Id oldId : discoverInstances.idToNewIdMap.keySet()) { for (Id oldId : discoverInstances.idToNewIdMap.keySet()) {
if (!discoverInstances.idToInstanceMap.containsKey(oldId)) { if (!discoverInstances.idToInstanceMap.containsKey(oldId)) {
throw new RepositoryException(String.format("Invalid Object Graph: " + throw new RepositoryException(String.format("Invalid Object Graph: "
"Encountered an unassignedId %s that is not associated with an Instance", + "Encountered an unassignedId %s that is not associated with an Instance", oldId));
oldId));
} }
} }
...@@ -140,18 +139,14 @@ public class MemRepository implements IRepository { ...@@ -140,18 +139,14 @@ public class MemRepository implements IRepository {
* - create a ITypedReferenceableInstance. * - create a ITypedReferenceableInstance.
* replace any old References ( ids or object references) with new Ids. * replace any old References ( ids or object references) with new Ids.
*/ */
List<ITypedReferenceableInstance> newInstances List<ITypedReferenceableInstance> newInstances = new ArrayList<ITypedReferenceableInstance>();
= new ArrayList<ITypedReferenceableInstance>();
ITypedReferenceableInstance retInstance = null; ITypedReferenceableInstance retInstance = null;
Set<ClassType> classTypes = new TreeSet<ClassType>(); Set<ClassType> classTypes = new TreeSet<ClassType>();
Set<TraitType> traitTypes = new TreeSet<TraitType>(); Set<TraitType> traitTypes = new TreeSet<TraitType>();
for (IReferenceableInstance transientInstance : discoverInstances.idToInstanceMap for (IReferenceableInstance transientInstance : discoverInstances.idToInstanceMap.values()) {
.values()) {
try { try {
ClassType cT = typeSystem ClassType cT = typeSystem.getDataType(ClassType.class, transientInstance.getTypeName());
.getDataType(ClassType.class, transientInstance.getTypeName()); ITypedReferenceableInstance newInstance = cT.convert(transientInstance, Multiplicity.REQUIRED);
ITypedReferenceableInstance newInstance = cT
.convert(transientInstance, Multiplicity.REQUIRED);
newInstances.add(newInstance); newInstances.add(newInstance);
classTypes.add(cT); classTypes.add(cT);
...@@ -172,8 +167,7 @@ public class MemRepository implements IRepository { ...@@ -172,8 +167,7 @@ public class MemRepository implements IRepository {
} catch (AtlasException me) { } catch (AtlasException me) {
throw new RepositoryException( throw new RepositoryException(
String.format("Failed to create Instance(id = %s", String.format("Failed to create Instance(id = %s", transientInstance.getId()), me);
transientInstance.getId()), me);
} }
} }
...@@ -237,8 +231,7 @@ public class MemRepository implements IRepository { ...@@ -237,8 +231,7 @@ public class MemRepository implements IRepository {
return retInstance; return retInstance;
} }
public ITypedReferenceableInstance update(ITypedReferenceableInstance i) public ITypedReferenceableInstance update(ITypedReferenceableInstance i) throws RepositoryException {
throws RepositoryException {
throw new RepositoryException("not implemented"); throw new RepositoryException("not implemented");
} }
...@@ -267,8 +260,7 @@ public class MemRepository implements IRepository { ...@@ -267,8 +260,7 @@ public class MemRepository implements IRepository {
* - load instance traits * - load instance traits
* - add to GraphWalker * - add to GraphWalker
*/ */
ITypedReferenceableInstance getDuringWalk(Id id, ObjectGraphWalker walker) ITypedReferenceableInstance getDuringWalk(Id id, ObjectGraphWalker walker) throws RepositoryException {
throws RepositoryException {
ClassStore cS = getClassStore(id.getTypeName()); ClassStore cS = getClassStore(id.getTypeName());
if (cS == null) { if (cS == null) {
throw new RepositoryException(String.format("Unknown Class %s", id.getTypeName())); throw new RepositoryException(String.format("Unknown Class %s", id.getTypeName()));
......
...@@ -67,22 +67,18 @@ public class ReplaceIdWithInstance implements ObjectGraphWalker.NodeProcessor { ...@@ -67,22 +67,18 @@ public class ReplaceIdWithInstance implements ObjectGraphWalker.NodeProcessor {
convertToInstances((ImmutableCollection) nd.value, nd.aInfo.multiplicity, aT)); convertToInstances((ImmutableCollection) nd.value, nd.aInfo.multiplicity, aT));
} else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) { } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType(); DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType();
nd.instance.set(nd.attributeName, nd.instance.set(nd.attributeName, convertToInstances((ImmutableMap) nd.value, nd.aInfo.multiplicity, mT));
convertToInstances((ImmutableMap) nd.value, nd.aInfo.multiplicity, mT));
} }
} }
ImmutableCollection<?> convertToInstances(ImmutableCollection<?> val, ImmutableCollection<?> convertToInstances(ImmutableCollection<?> val, Multiplicity m, DataTypes.ArrayType arrType)
Multiplicity m, DataTypes.ArrayType arrType)
throws AtlasException { throws AtlasException {
if (val == null || if (val == null || arrType.getElemType().getTypeCategory() != DataTypes.TypeCategory.CLASS) {
arrType.getElemType().getTypeCategory() != DataTypes.TypeCategory.CLASS) {
return val; return val;
} }
ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder();
: ImmutableList.builder();
Iterator it = val.iterator(); Iterator it = val.iterator();
while (it.hasNext()) { while (it.hasNext()) {
Object elem = it.next(); Object elem = it.next();
...@@ -97,13 +93,11 @@ public class ReplaceIdWithInstance implements ObjectGraphWalker.NodeProcessor { ...@@ -97,13 +93,11 @@ public class ReplaceIdWithInstance implements ObjectGraphWalker.NodeProcessor {
return b.build(); return b.build();
} }
ImmutableMap<?, ?> convertToInstances(ImmutableMap val, Multiplicity m, ImmutableMap<?, ?> convertToInstances(ImmutableMap val, Multiplicity m, DataTypes.MapType mapType)
DataTypes.MapType mapType)
throws AtlasException { throws AtlasException {
if (val == null || if (val == null || (mapType.getKeyType().getTypeCategory() != DataTypes.TypeCategory.CLASS
(mapType.getKeyType().getTypeCategory() != DataTypes.TypeCategory.CLASS && && mapType.getValueType().getTypeCategory() != DataTypes.TypeCategory.CLASS)) {
mapType.getValueType().getTypeCategory() != DataTypes.TypeCategory.CLASS)) {
return val; return val;
} }
ImmutableMap.Builder b = ImmutableMap.builder(); ImmutableMap.Builder b = ImmutableMap.builder();
......
...@@ -65,8 +65,7 @@ public class StructStore extends AttributeStores.AbstractAttributeStore implemen ...@@ -65,8 +65,7 @@ public class StructStore extends AttributeStores.AbstractAttributeStore implemen
} }
@Override @Override
protected void store(StructInstance instance, int colPos, String attrName, protected void store(StructInstance instance, int colPos, String attrName, Map<String, Object> m) {
Map<String, Object> m) {
m.put(attrName, instance.structs[colPos]); m.put(attrName, instance.structs[colPos]);
} }
......
...@@ -29,8 +29,7 @@ public class TraitStore extends HierarchicalTypeStore { ...@@ -29,8 +29,7 @@ public class TraitStore extends HierarchicalTypeStore {
final ArrayList<String> classNameStore; final ArrayList<String> classNameStore;
public TraitStore(MemRepository repository, TraitType hierarchicalType) public TraitStore(MemRepository repository, TraitType hierarchicalType) throws RepositoryException {
throws RepositoryException {
super(repository, hierarchicalType); super(repository, hierarchicalType);
classNameStore = new ArrayList<>(); classNameStore = new ArrayList<>();
} }
......
...@@ -25,8 +25,8 @@ import com.thinkaurelius.titan.core.TitanGraph; ...@@ -25,8 +25,8 @@ import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphProvider; import org.apache.atlas.repository.graph.GraphProvider;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
...@@ -81,7 +81,7 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -81,7 +81,7 @@ public class GraphBackedTypeStore implements ITypeStore {
LOG.debug("Processing {}.{} in type store", dataType.getTypeCategory(), dataType.getName()); LOG.debug("Processing {}.{} in type store", dataType.getTypeCategory(), dataType.getName());
switch (dataType.getTypeCategory()) { switch (dataType.getTypeCategory()) {
case ENUM: case ENUM:
storeInGraph((EnumType)dataType); storeInGraph((EnumType) dataType);
break; break;
case STRUCT: case STRUCT:
...@@ -93,8 +93,8 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -93,8 +93,8 @@ public class GraphBackedTypeStore implements ITypeStore {
case TRAIT: case TRAIT:
case CLASS: case CLASS:
HierarchicalType type = (HierarchicalType) dataType; HierarchicalType type = (HierarchicalType) dataType;
storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), type.immediateAttrs,
type.immediateAttrs, type.superTypes); type.superTypes);
break; break;
default: //Ignore primitive/collection types as they are covered under references default: //Ignore primitive/collection types as they are covered under references
...@@ -132,8 +132,7 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -132,8 +132,7 @@ public class GraphBackedTypeStore implements ITypeStore {
} }
private void storeInGraph(TypeSystem typeSystem, DataTypes.TypeCategory category, String typeName, private void storeInGraph(TypeSystem typeSystem, DataTypes.TypeCategory category, String typeName,
ImmutableList<AttributeInfo> attributes, ImmutableList<String> superTypes) throws ImmutableList<AttributeInfo> attributes, ImmutableList<String> superTypes) throws AtlasException {
AtlasException {
Vertex vertex = createVertex(category, typeName); Vertex vertex = createVertex(category, typeName);
List<String> attrNames = new ArrayList<>(); List<String> attrNames = new ArrayList<>();
if (attributes != null) { if (attributes != null) {
...@@ -161,8 +160,8 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -161,8 +160,8 @@ public class GraphBackedTypeStore implements ITypeStore {
} }
//Add edges for complex attributes //Add edges for complex attributes
private void addReferencesForAttribute(TypeSystem typeSystem, Vertex vertex, AttributeInfo attribute) throws private void addReferencesForAttribute(TypeSystem typeSystem, Vertex vertex, AttributeInfo attribute)
AtlasException { throws AtlasException {
ImmutableList<String> coreTypes = typeSystem.getCoreTypes(); ImmutableList<String> coreTypes = typeSystem.getCoreTypes();
List<IDataType> attrDataTypes = new ArrayList<>(); List<IDataType> attrDataTypes = new ArrayList<>();
IDataType attrDataType = attribute.dataType(); IDataType attrDataType = attribute.dataType();
...@@ -193,7 +192,8 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -193,7 +192,8 @@ public class GraphBackedTypeStore implements ITypeStore {
break; break;
default: default:
throw new IllegalArgumentException("Attribute cannot reference instances of type : " + attrDataType.getTypeCategory()); throw new IllegalArgumentException(
"Attribute cannot reference instances of type : " + attrDataType.getTypeCategory());
} }
for (IDataType attrType : attrDataTypes) { for (IDataType attrType : attrDataTypes) {
......
...@@ -94,6 +94,7 @@ public interface MetadataService { ...@@ -94,6 +94,7 @@ public interface MetadataService {
void updateEntity(String guid, String property, String value) throws AtlasException; void updateEntity(String guid, String property, String value) throws AtlasException;
// Trait management functions // Trait management functions
/** /**
* Gets the list of trait names for a given entity represented by a guid. * Gets the list of trait names for a given entity represented by a guid.
* *
...@@ -110,8 +111,7 @@ public interface MetadataService { ...@@ -110,8 +111,7 @@ public interface MetadataService {
* @param traitInstanceDefinition trait instance that needs to be added to entity * @param traitInstanceDefinition trait instance that needs to be added to entity
* @throws AtlasException * @throws AtlasException
*/ */
void addTrait(String guid, void addTrait(String guid, String traitInstanceDefinition) throws AtlasException;
String traitInstanceDefinition) throws AtlasException;
/** /**
* Deletes a given trait from an existing entity represented by a guid. * Deletes a given trait from an existing entity represented by a guid.
...@@ -120,6 +120,5 @@ public interface MetadataService { ...@@ -120,6 +120,5 @@ public interface MetadataService {
* @param traitNameToBeDeleted name of the trait * @param traitNameToBeDeleted name of the trait
* @throws AtlasException * @throws AtlasException
*/ */
void deleteTrait(String guid, void deleteTrait(String guid, String traitNameToBeDeleted) throws AtlasException;
String traitNameToBeDeleted) throws AtlasException;
} }
...@@ -94,44 +94,31 @@ public final class TestUtils { ...@@ -94,44 +94,31 @@ public final class TestUtils {
new EnumTypeDefinition("OrgLevel", new EnumValue("L1", 1), new EnumValue("L2", 2)); new EnumTypeDefinition("OrgLevel", new EnumValue("L1", 1), new EnumValue("L2", 2));
ts.defineEnumType(orgLevelEnum); ts.defineEnumType(orgLevelEnum);
StructTypeDefinition addressDetails = createStructTypeDef("Address", StructTypeDefinition addressDetails =
createRequiredAttrDef("street", DataTypes.STRING_TYPE), createStructTypeDef("Address", createRequiredAttrDef("street", DataTypes.STRING_TYPE),
createRequiredAttrDef("city", DataTypes.STRING_TYPE)); createRequiredAttrDef("city", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> deptTypeDef = HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", ImmutableList.<String>of(),
createClassTypeDef("Department", ImmutableList.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
String.format("array<%s>", "Person"), Multiplicity.COLLECTION, true, true, "department"));
"department")
);
HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", ImmutableList.<String>of(),
ImmutableList.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
createOptionalAttrDef("orgLevel", ts.getDataType(EnumType.class, "OrgLevel")), createOptionalAttrDef("orgLevel", ts.getDataType(EnumType.class, "OrgLevel")),
createOptionalAttrDef("address", "Address"), createOptionalAttrDef("address", "Address"),
new AttributeDefinition("department", new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
"Department", Multiplicity.REQUIRED, false, "employees"), new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"));
new AttributeDefinition("manager",
"Manager", Multiplicity.OPTIONAL, false, "subordinates") HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager", ImmutableList.of("Person"),
); new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
false, "manager"));
HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager",
ImmutableList.of("Person"), HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
new AttributeDefinition("subordinates", createTraitTypeDef("SecurityClearance", ImmutableList.<String>of(),
String.format("array<%s>", "Person"), Multiplicity.COLLECTION, false, createRequiredAttrDef("level", DataTypes.INT_TYPE));
"manager")
); ts.defineTypes(ImmutableList.of(addressDetails), ImmutableList.of(securityClearanceTypeDef),
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = createTraitTypeDef(
"SecurityClearance",
ImmutableList.<String>of(),
createRequiredAttrDef("level", DataTypes.INT_TYPE)
);
ts.defineTypes(ImmutableList.of(addressDetails),
ImmutableList.of(securityClearanceTypeDef),
ImmutableList.of(deptTypeDef, personTypeDef, managerTypeDef)); ImmutableList.of(deptTypeDef, personTypeDef, managerTypeDef));
} }
......
...@@ -95,8 +95,7 @@ public class GraphBackedDiscoveryServiceTest { ...@@ -95,8 +95,7 @@ public class GraphBackedDiscoveryServiceTest {
Bindings bindings = engine.createBindings(); Bindings bindings = engine.createBindings();
bindings.put("g", titanGraph); bindings.put("g", titanGraph);
String hiveGraphFile = FileUtils.getTempDirectory().getPath() String hiveGraphFile = FileUtils.getTempDirectory().getPath() + File.separator + System.nanoTime() + ".gson";
+ File.separator + System.nanoTime() + ".gson";
System.out.println("hiveGraphFile = " + hiveGraphFile); System.out.println("hiveGraphFile = " + hiveGraphFile);
HiveTitanSample.writeGson(hiveGraphFile); HiveTitanSample.writeGson(hiveGraphFile);
bindings.put("hiveGraphFile", hiveGraphFile); bindings.put("hiveGraphFile", hiveGraphFile);
...@@ -164,71 +163,56 @@ public class GraphBackedDiscoveryServiceTest { ...@@ -164,71 +163,56 @@ public class GraphBackedDiscoveryServiceTest {
System.out.println("search result = " + r); System.out.println("search result = " + r);
// Property Query: list all Person names // Property Query: list all Person names
r = discoveryService r = discoveryService.searchByGremlin("g.V.filter{it.typeName == 'Person'}.'Person.name'.toList()");
.searchByGremlin("g.V.filter{it.typeName == 'Person'}.'Person.name'.toList()");
System.out.println("search result = " + r); System.out.println("search result = " + r);
} }
@DataProvider(name = "dslQueriesProvider") @DataProvider(name = "dslQueriesProvider")
private Object[][] createDSLQueries() { private Object[][] createDSLQueries() {
return new String[][] { return new String[][]{{"from DB"}, {"DB"}, {"DB where DB.name=\"Reporting\""}, {"DB DB.name = \"Reporting\""},
{"from DB"}, {"DB where DB.name=\"Reporting\" select name, owner"}, {"DB has name"}, {"DB, Table"},
{"DB"},
{"DB where DB.name=\"Reporting\""},
{"DB DB.name = \"Reporting\""},
{"DB where DB.name=\"Reporting\" select name, owner"},
{"DB has name"},
{"DB, Table"},
{"DB is JdbcAccess"}, {"DB is JdbcAccess"},
/* /*
{"DB, LoadProcess has name"}, {"DB, LoadProcess has name"},
{"DB as db1, Table where db1.name = \"Reporting\""}, {"DB as db1, Table where db1.name = \"Reporting\""},
{"DB where DB.name=\"Reporting\" and DB.createTime < " + System.currentTimeMillis()}, {"DB where DB.name=\"Reporting\" and DB.createTime < " + System.currentTimeMillis()},
*/ */
{"from Table"}, {"from Table"}, {"Table"}, {"Table is Dimension"}, {"Column where Column isa PII"},
{"Table"},
{"Table is Dimension"},
{"Column where Column isa PII"},
{"View is Dimension"}, {"View is Dimension"},
/*{"Column where Column isa PII select Column.name"},*/ /*{"Column where Column isa PII select Column.name"},*/
{"Column select Column.name"}, {"Column select Column.name"}, {"Column select name"}, {"Column where Column.name=\"customer_id\""},
{"Column select name"}, {"from Table select Table.name"}, {"DB where (name = \"Reporting\")"},
{"Column where Column.name=\"customer_id\""},
{"from Table select Table.name"},
{"DB where (name = \"Reporting\")"},
{"DB where (name = \"Reporting\") select name as _col_0, owner as _col_1"}, {"DB where (name = \"Reporting\") select name as _col_0, owner as _col_1"},
{"DB where DB is JdbcAccess"}, {"DB where DB is JdbcAccess"}, {"DB where DB has name"}, {"DB Table"}, {"DB where DB has name"},
{"DB where DB has name"},
{"DB Table"},
{"DB where DB has name"},
{"DB as db1 Table where (db1.name = \"Reporting\")"}, {"DB as db1 Table where (db1.name = \"Reporting\")"},
{"DB where (name = \"Reporting\") select name as _col_0, (createTime + 1) as _col_1 "}, {"DB where (name = \"Reporting\") select name as _col_0, (createTime + 1) as _col_1 "},
/* /*
todo: does not work todo: does not work
{"DB where (name = \"Reporting\") and ((createTime + 1) > 0)"}, {"DB where (name = \"Reporting\") and ((createTime + 1) > 0)"},
{"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") select db1.name as dbName, tab.name as tabName"}, {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") select db1.name
{"DB as db1 Table as tab where ((db1.createTime + 1) > 0) or (db1.name = \"Reporting\") select db1.name as dbName, tab.name as tabName"}, as dbName, tab.name as tabName"},
{"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner select db1.name as dbName, tab.name as tabName"}, {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) or (db1.name = \"Reporting\") select db1.name
{"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner select db1.name as dbName, tab.name as tabName"}, as dbName, tab.name as tabName"},
{"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner
select db1.name as dbName, tab.name as tabName"},
{"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner
select db1.name as dbName, tab.name as tabName"},
*/ */
// trait searches // trait searches
{"Dimension"}, {"Dimension"},
/*{"Fact"}, - todo: does not work*/ /*{"Fact"}, - todo: does not work*/
{"JdbcAccess"}, {"JdbcAccess"}, {"ETL"}, {"Metric"}, {"PII"},
{"ETL"},
{"Metric"},
{"PII"},
// Lineage // Lineage
{"Table LoadProcess outputTable"}, {"Table LoadProcess outputTable"}, {"Table loop (LoadProcess outputTable)"},
{"Table loop (LoadProcess outputTable)"},
{"Table as _loop0 loop (LoadProcess outputTable) withPath"}, {"Table as _loop0 loop (LoadProcess outputTable) withPath"},
{"Table as src loop (LoadProcess outputTable) as dest select src.name as srcTable, dest.name as destTable withPath"}, {"Table as src loop (LoadProcess outputTable) as dest select src.name as srcTable, dest.name as "
{"Table as t, sd, Column as c where t.name=\"sales_fact\" select c.name as colName, c.dataType as colType"}, + "destTable withPath"},
{"Table where name='sales_fact', db where name='Reporting'"} {"Table as t, sd, Column as c where t.name=\"sales_fact\" select c.name as colName, c.dataType as "
}; + "colType"},
{"Table where name='sales_fact', db where name='Reporting'"}};
} }
@Test (dataProvider = "dslQueriesProvider") @Test(dataProvider = "dslQueriesProvider")
public void testSearchByDSLQueries(String dslQuery) throws Exception { public void testSearchByDSLQueries(String dslQuery) throws Exception {
System.out.println("Executing dslQuery = " + dslQuery); System.out.println("Executing dslQuery = " + dslQuery);
String jsonResults = discoveryService.searchByDSL(dslQuery); String jsonResults = discoveryService.searchByDSL(dslQuery);
...@@ -254,14 +238,10 @@ public class GraphBackedDiscoveryServiceTest { ...@@ -254,14 +238,10 @@ public class GraphBackedDiscoveryServiceTest {
@DataProvider(name = "invalidDslQueriesProvider") @DataProvider(name = "invalidDslQueriesProvider")
private Object[][] createInvalidDSLQueries() { private Object[][] createInvalidDSLQueries() {
return new String[][] { return new String[][]{{"from Unknown"}, {"Unknown"}, {"Unknown is Blah"},};
{"from Unknown"},
{"Unknown"},
{"Unknown is Blah"},
};
} }
@Test (dataProvider = "invalidDslQueriesProvider", expectedExceptions = DiscoveryException.class) @Test(dataProvider = "invalidDslQueriesProvider", expectedExceptions = DiscoveryException.class)
public void testSearchByDSLInvalidQueries(String dslQuery) throws Exception { public void testSearchByDSLInvalidQueries(String dslQuery) throws Exception {
System.out.println("Executing dslQuery = " + dslQuery); System.out.println("Executing dslQuery = " + dslQuery);
discoveryService.searchByDSL(dslQuery); discoveryService.searchByDSL(dslQuery);
...@@ -289,17 +269,16 @@ public class GraphBackedDiscoveryServiceTest { ...@@ -289,17 +269,16 @@ public class GraphBackedDiscoveryServiceTest {
* D(d) extends C * D(d) extends C
*/ */
private void createTypesWithMultiLevelInheritance() throws Exception { private void createTypesWithMultiLevelInheritance() throws Exception {
HierarchicalTypeDefinition A = createClassTypeDef("A", null, HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
createRequiredAttrDef("a", DataTypes.INT_TYPE));
HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableList.of("A"), HierarchicalTypeDefinition B =
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createClassTypeDef("C", ImmutableList.of("B"), HierarchicalTypeDefinition C =
createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createClassTypeDef("C", ImmutableList.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createClassTypeDef("D", ImmutableList.of("C"), HierarchicalTypeDefinition D =
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createClassTypeDef("D", ImmutableList.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
TypeSystem.getInstance().defineClassTypes(A, B, C, D); TypeSystem.getInstance().defineClassTypes(A, B, C, D);
} }
...@@ -312,8 +291,7 @@ public class GraphBackedDiscoveryServiceTest { ...@@ -312,8 +291,7 @@ public class GraphBackedDiscoveryServiceTest {
instance.set("a", 1); instance.set("a", 1);
ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, "D"); ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, "D");
ITypedReferenceableInstance typedInstance = ITypedReferenceableInstance typedInstance = deptType.convert(instance, Multiplicity.REQUIRED);
deptType.convert(instance, Multiplicity.REQUIRED);
repositoryService.createEntity(typedInstance); repositoryService.createEntity(typedInstance);
} }
......
...@@ -50,12 +50,11 @@ public abstract class BaseTest { ...@@ -50,12 +50,11 @@ public abstract class BaseTest {
public static final String STRUCT_TYPE_1 = "t1"; public static final String STRUCT_TYPE_1 = "t1";
public static final String STRUCT_TYPE_2 = "t2"; public static final String STRUCT_TYPE_2 = "t2";
public static final String TEST_DATE = "2014-12-11T02:35:58.440Z"; public static final String TEST_DATE = "2014-12-11T02:35:58.440Z";
public static final long TEST_DATE_IN_LONG=1418265358440L; public static final long TEST_DATE_IN_LONG = 1418265358440L;
protected IRepository repo; protected IRepository repo;
public static Struct createStruct() throws AtlasException { public static Struct createStruct() throws AtlasException {
StructType structType = (StructType) TypeSystem.getInstance() StructType structType = (StructType) TypeSystem.getInstance().getDataType(StructType.class, STRUCT_TYPE_1);
.getDataType(StructType.class, STRUCT_TYPE_1);
Struct s = new Struct(structType.getName()); Struct s = new Struct(structType.getName());
s.set("a", 1); s.set("a", 1);
s.set("b", true); s.set("b", true);
...@@ -70,8 +69,7 @@ public abstract class BaseTest { ...@@ -70,8 +69,7 @@ public abstract class BaseTest {
s.set("k", new BigDecimal(1)); s.set("k", new BigDecimal(1));
s.set("l", new Date(1418265358440L)); s.set("l", new Date(1418265358440L));
s.set("m", Lists.<Integer>asList(Integer.valueOf(1), new Integer[]{Integer.valueOf(1)})); s.set("m", Lists.<Integer>asList(Integer.valueOf(1), new Integer[]{Integer.valueOf(1)}));
s.set("n", Lists.<BigDecimal>asList(BigDecimal.valueOf(1.1), s.set("n", Lists.<BigDecimal>asList(BigDecimal.valueOf(1.1), new BigDecimal[]{BigDecimal.valueOf(1.1)}));
new BigDecimal[]{BigDecimal.valueOf(1.1)}));
Map<String, Double> hm = Maps.<String, Double>newHashMap(); Map<String, Double> hm = Maps.<String, Double>newHashMap();
hm.put("a", 1.0); hm.put("a", 1.0);
hm.put("b", 2.0); hm.put("b", 2.0);
...@@ -94,9 +92,8 @@ public abstract class BaseTest { ...@@ -94,9 +92,8 @@ public abstract class BaseTest {
ts.reset(); ts.reset();
repo = new MemRepository(ts); repo = new MemRepository(ts);
StructType structType = ts.defineStructType(STRUCT_TYPE_1, StructType structType =
true, ts.defineStructType(STRUCT_TYPE_1, true, TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE), TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE), TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE),
...@@ -109,18 +106,16 @@ public abstract class BaseTest { ...@@ -109,18 +106,16 @@ public abstract class BaseTest {
TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE), TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE),
TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE), TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE),
TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)),
TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), TypesUtil
TypesUtil.createOptionalAttrDef("o", .createOptionalAttrDef("o",
ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE))); ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)));
StructType recursiveStructType = ts.defineStructType(STRUCT_TYPE_2, StructType recursiveStructType =
true, ts.defineStructType(STRUCT_TYPE_2, true, TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("s", STRUCT_TYPE_2)); TypesUtil.createOptionalAttrDef("s", STRUCT_TYPE_2));
} }
protected Map<String, IDataType> defineTraits(HierarchicalTypeDefinition... tDefs) protected Map<String, IDataType> defineTraits(HierarchicalTypeDefinition... tDefs) throws AtlasException {
throws AtlasException {
return getTypeSystem().defineTraitTypes(tDefs); return getTypeSystem().defineTraitTypes(tDefs);
} }
...@@ -135,45 +130,33 @@ public abstract class BaseTest { ...@@ -135,45 +130,33 @@ public abstract class BaseTest {
*/ */
protected void defineDeptEmployeeTypes(TypeSystem ts) throws AtlasException { protected void defineDeptEmployeeTypes(TypeSystem ts) throws AtlasException {
HierarchicalTypeDefinition<ClassType> deptTypeDef = HierarchicalTypeDefinition<ClassType> deptTypeDef = TypesUtil
TypesUtil.createClassTypeDef("Department", ImmutableList.<String>of(), .createClassTypeDef("Department", ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", String.format("array<%s>", "Person"), new AttributeDefinition("employees", String.format("array<%s>", "Person"),
Multiplicity.COLLECTION, true, "department") Multiplicity.COLLECTION, true, "department"));
); HierarchicalTypeDefinition<ClassType> personTypeDef = TypesUtil
HierarchicalTypeDefinition<ClassType> personTypeDef = .createClassTypeDef("Person", ImmutableList.<String>of(),
TypesUtil.createClassTypeDef("Person", ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("department", new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
"Department", Multiplicity.REQUIRED, false, "employees"), new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"));
new AttributeDefinition("manager", HierarchicalTypeDefinition<ClassType> managerTypeDef = TypesUtil
"Manager", Multiplicity.OPTIONAL, false, "subordinates") .createClassTypeDef("Manager", ImmutableList.<String>of("Person"),
); new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
HierarchicalTypeDefinition<ClassType> managerTypeDef = Multiplicity.COLLECTION, false, "manager"));
TypesUtil.createClassTypeDef("Manager",
ImmutableList.<String>of("Person"), HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = TypesUtil
new AttributeDefinition("subordinates", .createTraitTypeDef("SecurityClearance", ImmutableList.<String>of(),
String.format("array<%s>", "Person"), TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
Multiplicity.COLLECTION, false, "manager")
);
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
TypesUtil.createTraitTypeDef("SecurityClearance",
ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)
);
ts.defineTypes(ImmutableList.<StructTypeDefinition>of(), ts.defineTypes(ImmutableList.<StructTypeDefinition>of(),
ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(securityClearanceTypeDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(securityClearanceTypeDef),
ImmutableList.<HierarchicalTypeDefinition<ClassType>>of(deptTypeDef, personTypeDef, ImmutableList.<HierarchicalTypeDefinition<ClassType>>of(deptTypeDef, personTypeDef, managerTypeDef));
managerTypeDef));
ImmutableList<HierarchicalType> types = ImmutableList
ImmutableList<HierarchicalType> types = ImmutableList.of( .of(ts.getDataType(HierarchicalType.class, "SecurityClearance"),
ts.getDataType(HierarchicalType.class, "SecurityClearance"), ts.getDataType(ClassType.class, "Department"), ts.getDataType(ClassType.class, "Person"),
ts.getDataType(ClassType.class, "Department"), ts.getDataType(ClassType.class, "Manager"));
ts.getDataType(ClassType.class, "Person"),
ts.getDataType(ClassType.class, "Manager")
);
repo.defineTypes(types); repo.defineTypes(types);
......
...@@ -55,26 +55,16 @@ public class EnumTest extends BaseTest { ...@@ -55,26 +55,16 @@ public class EnumTest extends BaseTest {
} }
void defineEnums(TypeSystem ts) throws AtlasException { void defineEnums(TypeSystem ts) throws AtlasException {
ts.defineEnumType("HiveObjectType", ts.defineEnumType("HiveObjectType", new EnumValue("GLOBAL", 1), new EnumValue("DATABASE", 2),
new EnumValue("GLOBAL", 1), new EnumValue("TABLE", 3), new EnumValue("PARTITION", 4), new EnumValue("COLUMN", 5));
new EnumValue("DATABASE", 2),
new EnumValue("TABLE", 3),
new EnumValue("PARTITION", 4),
new EnumValue("COLUMN", 5));
ts.defineEnumType("PrincipalType", ts.defineEnumType("PrincipalType", new EnumValue("USER", 1), new EnumValue("ROLE", 2),
new EnumValue("USER", 1),
new EnumValue("ROLE", 2),
new EnumValue("GROUP", 3)); new EnumValue("GROUP", 3));
ts.defineEnumType("TxnState", ts.defineEnumType("TxnState", new EnumValue("COMMITTED", 1), new EnumValue("ABORTED", 2),
new EnumValue("COMMITTED", 1),
new EnumValue("ABORTED", 2),
new EnumValue("OPEN", 3)); new EnumValue("OPEN", 3));
ts.defineEnumType("LockLevel", ts.defineEnumType("LockLevel", new EnumValue("DB", 1), new EnumValue("TABLE", 2),
new EnumValue("DB", 1),
new EnumValue("TABLE", 2),
new EnumValue("PARTITION", 3)); new EnumValue("PARTITION", 3));
} }
...@@ -93,8 +83,7 @@ public class EnumTest extends BaseTest { ...@@ -93,8 +83,7 @@ public class EnumTest extends BaseTest {
s.set("k", new BigDecimal(1)); s.set("k", new BigDecimal(1));
s.set("l", new Date(1418265358440L)); s.set("l", new Date(1418265358440L));
s.set("m", Lists.asList(1, new Integer[]{1})); s.set("m", Lists.asList(1, new Integer[]{1}));
s.set("n", s.set("n", Lists.asList(BigDecimal.valueOf(1.1), new BigDecimal[]{BigDecimal.valueOf(1.1)}));
Lists.asList(BigDecimal.valueOf(1.1), new BigDecimal[]{BigDecimal.valueOf(1.1)}));
Map<String, Double> hm = Maps.newHashMap(); Map<String, Double> hm = Maps.newHashMap();
hm.put("a", 1.0); hm.put("a", 1.0);
hm.put("b", 2.0); hm.put("b", 2.0);
...@@ -118,65 +107,54 @@ public class EnumTest extends BaseTest { ...@@ -118,65 +107,54 @@ public class EnumTest extends BaseTest {
} }
protected ClassType defineClassTypeWithEnum(TypeSystem ts) throws AtlasException { protected ClassType defineClassTypeWithEnum(TypeSystem ts) throws AtlasException {
return ts.defineClassType(TypesUtil.createClassTypeDef("t4", return ts.defineClassType(TypesUtil.createClassTypeDef("t4", ImmutableList.<String>of(),
ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE), TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE), TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE), TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE),
TypesUtil.createOptionalAttrDef("enum1", TypesUtil.createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")),
ts.getDataType(EnumType.class, "HiveObjectType")),
TypesUtil.createOptionalAttrDef("e", DataTypes.INT_TYPE), TypesUtil.createOptionalAttrDef("e", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("f", DataTypes.INT_TYPE), TypesUtil.createOptionalAttrDef("f", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("g", DataTypes.LONG_TYPE), TypesUtil.createOptionalAttrDef("g", DataTypes.LONG_TYPE),
TypesUtil.createOptionalAttrDef("enum2", TypesUtil.createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")),
ts.getDataType(EnumType.class, "PrincipalType")),
TypesUtil.createOptionalAttrDef("h", DataTypes.FLOAT_TYPE), TypesUtil.createOptionalAttrDef("h", DataTypes.FLOAT_TYPE),
TypesUtil.createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE), TypesUtil.createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE),
TypesUtil.createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE), TypesUtil.createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE),
TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE), TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE),
TypesUtil TypesUtil.createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")),
.createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")),
TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE), TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE),
TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)),
TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)),
TypesUtil.createOptionalAttrDef("o", TypesUtil.createOptionalAttrDef("o", ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)), TypesUtil.createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel"))));
TypesUtil.createOptionalAttrDef("enum4",
ts.getDataType(EnumType.class, "LockLevel"))));
} }
@Test @Test
public void testStruct() throws AtlasException { public void testStruct() throws AtlasException {
TypeSystem ts = getTypeSystem(); TypeSystem ts = getTypeSystem();
defineEnums(ts); defineEnums(ts);
StructType structType = ts.defineStructType("t3", StructType structType =
true, ts.defineStructType("t3", true, TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE), TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE), TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE),
TypesUtil.createOptionalAttrDef("enum1", TypesUtil.createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")),
ts.getDataType(EnumType.class, "HiveObjectType")),
TypesUtil.createOptionalAttrDef("e", DataTypes.INT_TYPE), TypesUtil.createOptionalAttrDef("e", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("f", DataTypes.INT_TYPE), TypesUtil.createOptionalAttrDef("f", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("g", DataTypes.LONG_TYPE), TypesUtil.createOptionalAttrDef("g", DataTypes.LONG_TYPE),
TypesUtil.createOptionalAttrDef("enum2", TypesUtil.createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")),
ts.getDataType(EnumType.class, "PrincipalType")),
TypesUtil.createOptionalAttrDef("h", DataTypes.FLOAT_TYPE), TypesUtil.createOptionalAttrDef("h", DataTypes.FLOAT_TYPE),
TypesUtil.createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE), TypesUtil.createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE),
TypesUtil.createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE), TypesUtil.createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE),
TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE), TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE),
TypesUtil TypesUtil.createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")),
.createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")),
TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE), TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE),
TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)),
TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), TypesUtil
TypesUtil.createOptionalAttrDef("o", .createOptionalAttrDef("o",
ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)), ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
TypesUtil.createOptionalAttrDef("enum4", TypesUtil.createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel")));
ts.getDataType(EnumType.class, "LockLevel")));
Struct s = createStructWithEnum("t3"); Struct s = createStructWithEnum("t3");
ITypedStruct typedS = structType.convert(s, Multiplicity.REQUIRED); ITypedStruct typedS = structType.convert(s, Multiplicity.REQUIRED);
......
...@@ -44,43 +44,36 @@ import java.util.List; ...@@ -44,43 +44,36 @@ import java.util.List;
public class InstanceE2ETest extends BaseTest { public class InstanceE2ETest extends BaseTest {
protected List<HierarchicalTypeDefinition> createHiveTypes(TypeSystem typeSystem) protected List<HierarchicalTypeDefinition> createHiveTypes(TypeSystem typeSystem) throws AtlasException {
throws AtlasException {
ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>(); ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>();
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil
TypesUtil.createClassTypeDef("hive_database", .createClassTypeDef("hive_database", ImmutableList.<String>of(),
ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
typeDefinitions.add(databaseTypeDefinition); typeDefinitions.add(databaseTypeDefinition);
HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil.createClassTypeDef( HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil
"hive_table", .createClassTypeDef("hive_table", ImmutableList.<String>of(),
ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE),
new AttributeDefinition("hive_database", new AttributeDefinition("hive_database", "hive_database", Multiplicity.REQUIRED, false,
"hive_database", Multiplicity.REQUIRED, false, "hive_database")); "hive_database"));
typeDefinitions.add(tableTypeDefinition); typeDefinitions.add(tableTypeDefinition);
HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil.createTraitTypeDef( HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil
"hive_fetl", .createTraitTypeDef("hive_fetl", ImmutableList.<String>of(),
ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)); TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
typeDefinitions.add(fetlTypeDefinition); typeDefinitions.add(fetlTypeDefinition);
typeSystem.defineTypes( typeSystem.defineTypes(ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(fetlTypeDefinition),
ImmutableList.<StructTypeDefinition>of(),
ImmutableList.of(fetlTypeDefinition),
ImmutableList.of(databaseTypeDefinition, tableTypeDefinition)); ImmutableList.of(databaseTypeDefinition, tableTypeDefinition));
return typeDefinitions; return typeDefinitions;
} }
protected Referenceable createHiveTableReferenceable() protected Referenceable createHiveTableReferenceable() throws AtlasException {
throws AtlasException {
Referenceable databaseInstance = new Referenceable("hive_database"); Referenceable databaseInstance = new Referenceable("hive_database");
databaseInstance.set("name", "hive_database"); databaseInstance.set("name", "hive_database");
databaseInstance.set("description", "foo database"); databaseInstance.set("description", "foo database");
...@@ -99,8 +92,7 @@ public class InstanceE2ETest extends BaseTest { ...@@ -99,8 +92,7 @@ public class InstanceE2ETest extends BaseTest {
return tableInstance; return tableInstance;
} }
protected ITypedReferenceableInstance createHiveTableInstance(TypeSystem typeSystem) protected ITypedReferenceableInstance createHiveTableInstance(TypeSystem typeSystem) throws AtlasException {
throws AtlasException {
ClassType tableType = typeSystem.getDataType(ClassType.class, "hive_table"); ClassType tableType = typeSystem.getDataType(ClassType.class, "hive_table");
return tableType.convert(createHiveTableReferenceable(), Multiplicity.REQUIRED); return tableType.convert(createHiveTableReferenceable(), Multiplicity.REQUIRED);
} }
...@@ -112,8 +104,7 @@ public class InstanceE2ETest extends BaseTest { ...@@ -112,8 +104,7 @@ public class InstanceE2ETest extends BaseTest {
createHiveTypes(ts); createHiveTypes(ts);
String jsonStr = TypesSerialization$.MODULE$ String jsonStr = TypesSerialization$.MODULE$.toJson(ts, ImmutableList.of("hive_database", "hive_table"));
.toJson(ts, ImmutableList.of("hive_database", "hive_table"));
System.out.println(jsonStr); System.out.println(jsonStr);
TypesDef typesDef1 = TypesSerialization$.MODULE$.fromJson(jsonStr); TypesDef typesDef1 = TypesSerialization$.MODULE$.fromJson(jsonStr);
...@@ -121,8 +112,7 @@ public class InstanceE2ETest extends BaseTest { ...@@ -121,8 +112,7 @@ public class InstanceE2ETest extends BaseTest {
ts.reset(); ts.reset();
ts.defineTypes(typesDef1); ts.defineTypes(typesDef1);
jsonStr = TypesSerialization$.MODULE$ jsonStr = TypesSerialization$.MODULE$.toJson(ts, ImmutableList.of("hive_database", "hive_table"));
.toJson(ts, ImmutableList.of("hive_database", "hive_table"));
System.out.println(jsonStr); System.out.println(jsonStr);
} }
......
...@@ -38,8 +38,7 @@ public class StructTest extends BaseTest { ...@@ -38,8 +38,7 @@ public class StructTest extends BaseTest {
public void setup() throws Exception { public void setup() throws Exception {
super.setup(); super.setup();
structType = (StructType) getTypeSystem().getDataType(StructType.class, STRUCT_TYPE_1); structType = (StructType) getTypeSystem().getDataType(StructType.class, STRUCT_TYPE_1);
recursiveStructType = (StructType) getTypeSystem() recursiveStructType = (StructType) getTypeSystem().getDataType(StructType.class, STRUCT_TYPE_2);
.getDataType(StructType.class, STRUCT_TYPE_2);
} }
@Test @Test
......
...@@ -65,15 +65,13 @@ public class TraitTest extends BaseTest { ...@@ -65,15 +65,13 @@ public class TraitTest extends BaseTest {
*/ */
@Test @Test
public void test1() throws AtlasException { public void test1() throws AtlasException {
HierarchicalTypeDefinition A = createTraitTypeDef("A", null, HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"), HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableList.<String>of("A"), HierarchicalTypeDefinition C =
createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createTraitTypeDef("C", ImmutableList.<String>of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"), HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
...@@ -155,15 +153,13 @@ public class TraitTest extends BaseTest { ...@@ -155,15 +153,13 @@ public class TraitTest extends BaseTest {
@Test @Test
public void testRandomOrder() throws AtlasException { public void testRandomOrder() throws AtlasException {
HierarchicalTypeDefinition A = createTraitTypeDef("A", null, HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"), HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableList.<String>of("A"), HierarchicalTypeDefinition C =
createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createTraitTypeDef("C", ImmutableList.<String>of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"), HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
......
...@@ -23,8 +23,8 @@ import com.tinkerpop.blueprints.Direction; ...@@ -23,8 +23,8 @@ import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.GraphTransaction;
import org.apache.atlas.RepositoryMetadataModule; import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.TestUtils; import org.apache.atlas.TestUtils;
import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graph.GraphHelper;
...@@ -80,7 +80,7 @@ public class GraphBackedTypeStoreTest { ...@@ -80,7 +80,7 @@ public class GraphBackedTypeStoreTest {
} }
} }
@Test (dependsOnMethods = "testStore") @Test(dependsOnMethods = "testStore")
public void testRestore() throws Exception { public void testRestore() throws Exception {
TypesDef types = typeStore.restore(); TypesDef types = typeStore.restore();
......
...@@ -67,8 +67,7 @@ public class Referenceable extends Struct implements IReferenceableInstance { ...@@ -67,8 +67,7 @@ public class Referenceable extends Struct implements IReferenceableInstance {
* @param values * @param values
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public Referenceable(String guid, String typeName, Map<String, Object> values, public Referenceable(String guid, String typeName, Map<String, Object> values, List<String> _traitNames,
List<String> _traitNames,
Map<String, IStruct> _traits) { Map<String, IStruct> _traits) {
super(typeName, values); super(typeName, values);
id = new Id(guid, 0, typeName); id = new Id(guid, 0, typeName);
......
...@@ -31,8 +31,7 @@ public class DownCastStructInstance implements IStruct { ...@@ -31,8 +31,7 @@ public class DownCastStructInstance implements IStruct {
public final DownCastFieldMapping fieldMapping; public final DownCastFieldMapping fieldMapping;
public final IStruct backingInstance; public final IStruct backingInstance;
public DownCastStructInstance(String typeName, DownCastFieldMapping fieldMapping, public DownCastStructInstance(String typeName, DownCastFieldMapping fieldMapping, IStruct backingInstance) {
IStruct backingInstance) {
this.typeName = typeName; this.typeName = typeName;
this.fieldMapping = fieldMapping; this.fieldMapping = fieldMapping;
this.backingInstance = backingInstance; this.backingInstance = backingInstance;
...@@ -60,7 +59,7 @@ public class DownCastStructInstance implements IStruct { ...@@ -60,7 +59,7 @@ public class DownCastStructInstance implements IStruct {
@Override @Override
public Map<String, Object> getValuesMap() throws AtlasException { public Map<String, Object> getValuesMap() throws AtlasException {
Map<String,Object> m = new HashMap<>(); Map<String, Object> m = new HashMap<>();
for (String attr : fieldMapping.fieldNameMap.keySet()) { for (String attr : fieldMapping.fieldNameMap.keySet()) {
m.put(attr, get(attr)); m.put(attr, get(attr));
} }
......
...@@ -70,8 +70,7 @@ public class Id implements ITypedReferenceableInstance { ...@@ -70,8 +70,7 @@ public class Id implements ITypedReferenceableInstance {
} }
public String toString() { public String toString() {
return String return String.format("(type: %s, id: %s)", className, isUnassigned() ? "<unassigned>" : "" + id);
.format("(type: %s, id: %s)", className, isUnassigned() ? "<unassigned>" : "" + id);
} }
public String getClassName() { public String getClassName() {
...@@ -88,14 +87,24 @@ public class Id implements ITypedReferenceableInstance { ...@@ -88,14 +87,24 @@ public class Id implements ITypedReferenceableInstance {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Id id1 = (Id) o; Id id1 = (Id) o;
if (version != id1.version) return false; if (version != id1.version) {
if (!className.equals(id1.className)) return false; return false;
if (!id.equals(id1.id)) return false; }
if (!className.equals(id1.className)) {
return false;
}
if (!id.equals(id1.id)) {
return false;
}
return true; return true;
} }
......
...@@ -59,8 +59,7 @@ public class MapIds implements ObjectGraphWalker.NodeProcessor { ...@@ -59,8 +59,7 @@ public class MapIds implements ObjectGraphWalker.NodeProcessor {
} }
} else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) { } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
DataTypes.ArrayType aT = (DataTypes.ArrayType) nd.aInfo.dataType(); DataTypes.ArrayType aT = (DataTypes.ArrayType) nd.aInfo.dataType();
Object v = aT Object v = aT.mapIds((ImmutableCollection) nd.value, nd.aInfo.multiplicity, idToNewIdMap);
.mapIds((ImmutableCollection) nd.value, nd.aInfo.multiplicity, idToNewIdMap);
nd.instance.set(nd.attributeName, v); nd.instance.set(nd.attributeName, v);
} else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) { } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType(); DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType();
......
...@@ -40,20 +40,12 @@ public class ReferenceableInstance extends StructInstance implements ITypedRefer ...@@ -40,20 +40,12 @@ public class ReferenceableInstance extends StructInstance implements ITypedRefer
private Id id; private Id id;
public ReferenceableInstance(Id id, String dataTypeName, FieldMapping fieldMapping, public ReferenceableInstance(Id id, String dataTypeName, FieldMapping fieldMapping, boolean[] nullFlags,
boolean[] nullFlags, boolean[] bools, byte[] bytes, short[] shorts, int[] ints, long[] longs, float[] floats, double[] doubles,
boolean[] bools, byte[] bytes, short[] shorts, int[] ints, BigDecimal[] bigDecimals, BigInteger[] bigIntegers, Date[] dates, String[] strings,
long[] longs, ImmutableList<Object>[] arrays, ImmutableMap<Object, Object>[] maps, StructInstance[] structs,
float[] floats, double[] doubles, BigDecimal[] bigDecimals, ReferenceableInstance[] referenceableInstances, Id[] ids, ImmutableMap<String, ITypedStruct> traits) {
BigInteger[] bigIntegers, Date[] dates, String[] strings, super(dataTypeName, fieldMapping, nullFlags, bools, bytes, shorts, ints, longs, floats, doubles, bigDecimals,
ImmutableList<Object>[] arrays,
ImmutableMap<Object, Object>[] maps,
StructInstance[] structs,
ReferenceableInstance[] referenceableInstances,
Id[] ids,
ImmutableMap<String, ITypedStruct> traits) {
super(dataTypeName, fieldMapping, nullFlags, bools, bytes, shorts, ints, longs, floats,
doubles, bigDecimals,
bigIntegers, dates, strings, arrays, maps, structs, referenceableInstances, ids); bigIntegers, dates, strings, arrays, maps, structs, referenceableInstances, ids);
this.id = id; this.id = id;
this.traits = traits; this.traits = traits;
......
...@@ -35,15 +35,14 @@ public final class AttributeDefinition { ...@@ -35,15 +35,14 @@ public final class AttributeDefinition {
*/ */
public final String reverseAttributeName; public final String reverseAttributeName;
public AttributeDefinition(String name, String dataTypeName, Multiplicity multiplicity, public AttributeDefinition(String name, String dataTypeName, Multiplicity multiplicity, boolean isComposite,
boolean isComposite, String reverseAttributeName) { String reverseAttributeName) {
this(name, dataTypeName, multiplicity, isComposite, false, true, reverseAttributeName); this(name, dataTypeName, multiplicity, isComposite, false, true, reverseAttributeName);
} }
public AttributeDefinition(String name, String dataTypeName, public AttributeDefinition(String name, String dataTypeName, Multiplicity multiplicity, boolean isComposite,
Multiplicity multiplicity, boolean isComposite, boolean isUnique, boolean isUnique, boolean isIndexable, String reverseAttributeName) {
boolean isIndexable, String reverseAttributeName) {
this.name = ParamChecker.notEmpty(name, "Attribute name"); this.name = ParamChecker.notEmpty(name, "Attribute name");
this.dataTypeName = ParamChecker.notEmpty(dataTypeName, "Attribute type"); this.dataTypeName = ParamChecker.notEmpty(dataTypeName, "Attribute type");
this.multiplicity = multiplicity; this.multiplicity = multiplicity;
...@@ -55,21 +54,37 @@ public final class AttributeDefinition { ...@@ -55,21 +54,37 @@ public final class AttributeDefinition {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AttributeDefinition that = (AttributeDefinition) o; AttributeDefinition that = (AttributeDefinition) o;
if (isComposite != that.isComposite) return false; if (isComposite != that.isComposite) {
if (isUnique != that.isUnique) return false;
if (isIndexable != that.isIndexable) return false;
if (!dataTypeName.equals(that.dataTypeName)) return false;
if (!multiplicity.equals(that.multiplicity)) return false;
if (!name.equals(that.name)) return false;
if (reverseAttributeName != null
? !reverseAttributeName.equals(that.reverseAttributeName)
: that.reverseAttributeName != null)
return false; return false;
}
if (isUnique != that.isUnique) {
return false;
}
if (isIndexable != that.isIndexable) {
return false;
}
if (!dataTypeName.equals(that.dataTypeName)) {
return false;
}
if (!multiplicity.equals(that.multiplicity)) {
return false;
}
if (!name.equals(that.name)) {
return false;
}
if (reverseAttributeName != null ? !reverseAttributeName.equals(that.reverseAttributeName) :
that.reverseAttributeName != null) {
return false;
}
return true; return true;
} }
......
...@@ -39,8 +39,9 @@ public class AttributeInfo { ...@@ -39,8 +39,9 @@ public class AttributeInfo {
AttributeInfo(TypeSystem t, AttributeDefinition def, Map<String, IDataType> tempTypes) throws AtlasException { AttributeInfo(TypeSystem t, AttributeDefinition def, Map<String, IDataType> tempTypes) throws AtlasException {
this.name = def.name; this.name = def.name;
this.dataType = (tempTypes != null && tempTypes.containsKey(def.dataTypeName)) ? this.dataType =
tempTypes.get(def.dataTypeName) : t.getDataType(IDataType.class, def.dataTypeName); (tempTypes != null && tempTypes.containsKey(def.dataTypeName)) ? tempTypes.get(def.dataTypeName) :
t.getDataType(IDataType.class, def.dataTypeName);
this.multiplicity = def.multiplicity; this.multiplicity = def.multiplicity;
this.isComposite = def.isComposite; this.isComposite = def.isComposite;
this.isUnique = def.isUnique; this.isUnique = def.isUnique;
......
...@@ -53,8 +53,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -53,8 +53,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
infoToNameMap = null; infoToNameMap = null;
} }
ClassType(TypeSystem typeSystem, String name, ImmutableList<String> superTypes, ClassType(TypeSystem typeSystem, String name, ImmutableList<String> superTypes, AttributeInfo... fields)
AttributeInfo... fields)
throws AtlasException { throws AtlasException {
super(typeSystem, ClassType.class, name, superTypes, fields); super(typeSystem, ClassType.class, name, superTypes, fields);
infoToNameMap = TypeUtils.buildAttrInfoToNameMap(fieldMapping); infoToNameMap = TypeUtils.buildAttrInfoToNameMap(fieldMapping);
...@@ -71,8 +70,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -71,8 +70,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
if (isSubType(cType.getName())) { if (isSubType(cType.getName())) {
return; return;
} }
throw new AtlasException( throw new AtlasException(String.format("Id %s is not valid for class %s", id, getName()));
String.format("Id %s is not valid for class %s", id, getName()));
} }
} }
...@@ -84,8 +82,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -84,8 +82,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
} }
@Override @Override
public ITypedReferenceableInstance convert(Object val, Multiplicity m) public ITypedReferenceableInstance convert(Object val, Multiplicity m) throws AtlasException {
throws AtlasException {
if (val != null) { if (val != null) {
if (val instanceof ITypedReferenceableInstance) { if (val instanceof ITypedReferenceableInstance) {
...@@ -122,9 +119,9 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -122,9 +119,9 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
id = r.getId(); id = r.getId();
} }
ITypedReferenceableInstance tr = r != null ? ITypedReferenceableInstance tr =
createInstanceWithTraits(id, r, r.getTraits().toArray(new String[0])) r != null ? createInstanceWithTraits(id, r, r.getTraits().toArray(new String[0])) :
: createInstance(id); createInstance(id);
if (id != null && id.isAssigned()) { if (id != null && id.isAssigned()) {
return tr; return tr;
...@@ -134,8 +131,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -134,8 +131,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
String attrKey = e.getKey(); String attrKey = e.getKey();
AttributeInfo i = e.getValue(); AttributeInfo i = e.getValue();
Object aVal = s.get(attrKey); Object aVal = s.get(attrKey);
if (aVal != null && if (aVal != null && i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
if (!i.isComposite) { if (!i.isComposite) {
aVal = ((IReferenceableInstance) aVal).getId(); aVal = ((IReferenceableInstance) aVal).getId();
} }
...@@ -164,25 +160,21 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -164,25 +160,21 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
@Override @Override
public ITypedReferenceableInstance createInstance() throws AtlasException { public ITypedReferenceableInstance createInstance() throws AtlasException {
return createInstance((String[])null); return createInstance((String[]) null);
} }
public ITypedReferenceableInstance createInstance(String... traitNames) public ITypedReferenceableInstance createInstance(String... traitNames) throws AtlasException {
throws AtlasException {
return createInstance(null, traitNames); return createInstance(null, traitNames);
} }
public ITypedReferenceableInstance createInstance(Id id, String... traitNames) public ITypedReferenceableInstance createInstance(Id id, String... traitNames) throws AtlasException {
throws AtlasException {
return createInstanceWithTraits(id, null, traitNames); return createInstanceWithTraits(id, null, traitNames);
} }
public ITypedReferenceableInstance createInstanceWithTraits(Id id, Referenceable r, public ITypedReferenceableInstance createInstanceWithTraits(Id id, Referenceable r, String... traitNames)
String... traitNames)
throws AtlasException { throws AtlasException {
ImmutableMap.Builder<String, ITypedStruct> b ImmutableMap.Builder<String, ITypedStruct> b = new ImmutableBiMap.Builder<String, ITypedStruct>();
= new ImmutableBiMap.Builder<String, ITypedStruct>();
if (traitNames != null) { if (traitNames != null) {
for (String t : traitNames) { for (String t : traitNames) {
TraitType tType = typeSystem.getDataType(TraitType.class, t); TraitType tType = typeSystem.getDataType(TraitType.class, t);
...@@ -193,9 +185,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -193,9 +185,7 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
} }
} }
return new ReferenceableInstance(id == null ? new Id(getName()) : id, return new ReferenceableInstance(id == null ? new Id(getName()) : id, getName(), fieldMapping,
getName(),
fieldMapping,
new boolean[fieldMapping.fields.size()], new boolean[fieldMapping.fields.size()],
fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools], fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools],
fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes], fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes],
...@@ -204,23 +194,19 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -204,23 +194,19 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs], fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs],
fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats], fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats],
fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles], fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles],
fieldMapping.numBigDecimals == 0 ? null fieldMapping.numBigDecimals == 0 ? null : new BigDecimal[fieldMapping.numBigDecimals],
: new BigDecimal[fieldMapping.numBigDecimals],
fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts], fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts],
fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates], fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates],
fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings], fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings],
fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays], fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays],
fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps], fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps],
fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs], fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs],
fieldMapping.numReferenceables == 0 ? null fieldMapping.numReferenceables == 0 ? null : new ReferenceableInstance[fieldMapping.numReferenceables],
: new ReferenceableInstance[fieldMapping.numReferenceables], fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables], b.build());
fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables],
b.build());
} }
@Override @Override
public void output(IReferenceableInstance s, Appendable buf, String prefix) public void output(IReferenceableInstance s, Appendable buf, String prefix) throws AtlasException {
throws AtlasException {
fieldMapping.output(s, buf, prefix); fieldMapping.output(s, buf, prefix);
} }
......
...@@ -62,8 +62,7 @@ public class DataTypes { ...@@ -62,8 +62,7 @@ public class DataTypes {
} }
public static String mapTypeName(String keyTypeName, String valueTypeName) { public static String mapTypeName(String keyTypeName, String valueTypeName) {
return String.format("%s%s,%s%s", MAP_TYPE_PREFIX, return String.format("%s%s,%s%s", MAP_TYPE_PREFIX, keyTypeName, valueTypeName, MAP_TYPE_SUFFIX);
keyTypeName, valueTypeName, MAP_TYPE_SUFFIX);
} }
public static String mapTypeName(IDataType keyType, IDataType valueType) { public static String mapTypeName(IDataType keyType, IDataType valueType) {
...@@ -433,8 +432,8 @@ public class DataTypes { ...@@ -433,8 +432,8 @@ public class DataTypes {
@Override @Override
public void output(Date val, Appendable buf, String prefix) throws AtlasException { public void output(Date val, Appendable buf, String prefix) throws AtlasException {
TypeUtils.outputVal(val == null ? "<null>" : TypeUtils.outputVal(val == null ? "<null>" : TypeSystem.getInstance().getDateFormat().format(val), buf,
TypeSystem.getInstance().getDateFormat().format(val), buf, prefix); prefix);
} }
public Date nullValue() { public Date nullValue() {
...@@ -502,19 +501,18 @@ public class DataTypes { ...@@ -502,19 +501,18 @@ public class DataTypes {
it = (Iterator) val; it = (Iterator) val;
} }
if (it != null) { if (it != null) {
ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder();
: ImmutableList.builder();
while (it.hasNext()) { while (it.hasNext()) {
b.add(elemType.convert(it.next(), b.add(elemType.convert(it.next(),
TypeSystem.getInstance().allowNullsInCollections() TypeSystem.getInstance().allowNullsInCollections() ? Multiplicity.OPTIONAL :
? Multiplicity.OPTIONAL : Multiplicity.REQUIRED)); Multiplicity.REQUIRED));
} }
return m.isUnique ? b.build().asList() : b.build(); return m.isUnique ? b.build().asList() : b.build();
} else { } else {
try { try {
return ImmutableList.of(elemType.convert(val, return ImmutableList.of(elemType.convert(val,
TypeSystem.getInstance().allowNullsInCollections() TypeSystem.getInstance().allowNullsInCollections() ? Multiplicity.OPTIONAL :
? Multiplicity.OPTIONAL : Multiplicity.REQUIRED)); Multiplicity.REQUIRED));
} catch (Exception e) { } catch (Exception e) {
throw new ValueConversionException(this, val, e); throw new ValueConversionException(this, val, e);
} }
...@@ -526,15 +524,13 @@ public class DataTypes { ...@@ -526,15 +524,13 @@ public class DataTypes {
return null; return null;
} }
public ImmutableCollection<?> mapIds(ImmutableCollection<?> val, Multiplicity m, public ImmutableCollection<?> mapIds(ImmutableCollection<?> val, Multiplicity m, Map<Id, Id> transientToNewIds)
Map<Id, Id> transientToNewIds)
throws AtlasException { throws AtlasException {
if (val == null || elemType.getTypeCategory() != TypeCategory.CLASS) { if (val == null || elemType.getTypeCategory() != TypeCategory.CLASS) {
return val; return val;
} }
ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder();
: ImmutableList.builder();
Iterator it = val.iterator(); Iterator it = val.iterator();
while (it.hasNext()) { while (it.hasNext()) {
Object elem = it.next(); Object elem = it.next();
...@@ -600,11 +596,10 @@ public class DataTypes { ...@@ -600,11 +596,10 @@ public class DataTypes {
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry e = it.next(); Map.Entry e = it.next();
b.put(keyType.convert(e.getKey(), b.put(keyType.convert(e.getKey(),
TypeSystem.getInstance().allowNullsInCollections() TypeSystem.getInstance().allowNullsInCollections() ? Multiplicity.OPTIONAL :
? Multiplicity.OPTIONAL : Multiplicity.REQUIRED), Multiplicity.REQUIRED), valueType.convert(e.getValue(),
valueType.convert(e.getValue(), TypeSystem.getInstance().allowNullsInCollections() ? Multiplicity.OPTIONAL :
TypeSystem.getInstance().allowNullsInCollections() Multiplicity.REQUIRED));
? Multiplicity.OPTIONAL : Multiplicity.REQUIRED));
} }
return b.build(); return b.build();
} else { } else {
...@@ -617,12 +612,11 @@ public class DataTypes { ...@@ -617,12 +612,11 @@ public class DataTypes {
return null; return null;
} }
public ImmutableMap<?, ?> mapIds(ImmutableMap val, Multiplicity m, public ImmutableMap<?, ?> mapIds(ImmutableMap val, Multiplicity m, Map<Id, Id> transientToNewIds)
Map<Id, Id> transientToNewIds)
throws AtlasException { throws AtlasException {
if (val == null || (keyType.getTypeCategory() != TypeCategory.CLASS && if (val == null || (keyType.getTypeCategory() != TypeCategory.CLASS
valueType.getTypeCategory() != TypeCategory.CLASS)) { && valueType.getTypeCategory() != TypeCategory.CLASS)) {
return val; return val;
} }
ImmutableMap.Builder b = ImmutableMap.builder(); ImmutableMap.Builder b = ImmutableMap.builder();
......
...@@ -30,8 +30,7 @@ public class DownCastFieldMapping { ...@@ -30,8 +30,7 @@ public class DownCastFieldMapping {
this.fieldNameMap = fieldNameMap; this.fieldNameMap = fieldNameMap;
} }
public void set(DownCastStructInstance s, String attrName, Object val) public void set(DownCastStructInstance s, String attrName, Object val) throws AtlasException {
throws AtlasException {
String mappedNm = fieldNameMap.get(attrName); String mappedNm = fieldNameMap.get(attrName);
if (mappedNm == null) { if (mappedNm == null) {
......
...@@ -54,13 +54,13 @@ public class EnumType extends AbstractDataType<EnumValue> { ...@@ -54,13 +54,13 @@ public class EnumType extends AbstractDataType<EnumValue> {
if (val != null) { if (val != null) {
EnumValue e = null; EnumValue e = null;
if (val instanceof EnumValue) { if (val instanceof EnumValue) {
e = valueMap.get(((EnumValue)val).value); e = valueMap.get(((EnumValue) val).value);
} else if ( val instanceof Integer || val instanceof BigInt) { } else if (val instanceof Integer || val instanceof BigInt) {
e = ordinalMap.get(val); e = ordinalMap.get(val);
} else if ( val instanceof String) { } else if (val instanceof String) {
e = valueMap.get(val); e = valueMap.get(val);
} else if ( val instanceof Number ) { } else if (val instanceof Number) {
e = ordinalMap.get(((Number)val).intValue()); e = ordinalMap.get(((Number) val).intValue());
} }
if (e == null) { if (e == null) {
......
...@@ -34,13 +34,21 @@ public final class EnumTypeDefinition { ...@@ -34,13 +34,21 @@ public final class EnumTypeDefinition {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EnumTypeDefinition that = (EnumTypeDefinition) o; EnumTypeDefinition that = (EnumTypeDefinition) o;
if (!Arrays.equals(enumValues, that.enumValues)) return false; if (!Arrays.equals(enumValues, that.enumValues)) {
if (!name.equals(that.name)) return false; return false;
}
if (!name.equals(that.name)) {
return false;
}
return true; return true;
} }
......
...@@ -32,13 +32,21 @@ public class EnumValue { ...@@ -32,13 +32,21 @@ public class EnumValue {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EnumValue enumValue = (EnumValue) o; EnumValue enumValue = (EnumValue) o;
if (ordinal != enumValue.ordinal) return false; if (ordinal != enumValue.ordinal) {
if (!value.equals(enumValue.value)) return false; return false;
}
if (!value.equals(enumValue.value)) {
return false;
}
return true; return true;
} }
......
...@@ -47,12 +47,9 @@ public class FieldMapping { ...@@ -47,12 +47,9 @@ public class FieldMapping {
public final int numReferenceables; public final int numReferenceables;
public FieldMapping(Map<String, AttributeInfo> fields, Map<String, Integer> fieldPos, public FieldMapping(Map<String, AttributeInfo> fields, Map<String, Integer> fieldPos,
Map<String, Integer> fieldNullPos, int numBools, int numBytes, Map<String, Integer> fieldNullPos, int numBools, int numBytes, int numShorts, int numInts, int numLongs,
int numShorts, int numFloats, int numDoubles, int numBigInts, int numBigDecimals, int numDates, int numStrings,
int numInts, int numLongs, int numFloats, int numDoubles, int numBigInts, int numArrays, int numMaps, int numStructs, int numReferenceables) {
int numBigDecimals,
int numDates, int numStrings, int numArrays, int numMaps, int numStructs,
int numReferenceables) {
this.fields = fields; this.fields = fields;
this.fieldPos = fieldPos; this.fieldPos = fieldPos;
this.fieldNullPos = fieldNullPos; this.fieldNullPos = fieldNullPos;
...@@ -73,8 +70,7 @@ public class FieldMapping { ...@@ -73,8 +70,7 @@ public class FieldMapping {
this.numReferenceables = numReferenceables; this.numReferenceables = numReferenceables;
} }
protected void outputFields(IStruct s, Appendable buf, String fieldPrefix) protected void outputFields(IStruct s, Appendable buf, String fieldPrefix) throws AtlasException {
throws AtlasException {
for (Map.Entry<String, AttributeInfo> e : fields.entrySet()) { for (Map.Entry<String, AttributeInfo> e : fields.entrySet()) {
String attrName = e.getKey(); String attrName = e.getKey();
AttributeInfo i = e.getValue(); AttributeInfo i = e.getValue();
...@@ -104,8 +100,7 @@ public class FieldMapping { ...@@ -104,8 +100,7 @@ public class FieldMapping {
TypeUtils.outputVal("}", buf, prefix); TypeUtils.outputVal("}", buf, prefix);
} }
public void output(IReferenceableInstance s, Appendable buf, String prefix) public void output(IReferenceableInstance s, Appendable buf, String prefix) throws AtlasException {
throws AtlasException {
if (s == null) { if (s == null) {
TypeUtils.outputVal("<null>\n", buf, ""); TypeUtils.outputVal("<null>\n", buf, "");
return; return;
......
...@@ -36,16 +36,13 @@ public class HierarchicalTypeDefinition<T extends HierarchicalType> extends Stru ...@@ -36,16 +36,13 @@ public class HierarchicalTypeDefinition<T extends HierarchicalType> extends Stru
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public HierarchicalTypeDefinition(String hierarchicalMetaTypeName, public HierarchicalTypeDefinition(String hierarchicalMetaTypeName, String typeName, String[] superTypes,
String typeName, String[] superTypes, AttributeDefinition[] attributeDefinitions) throws ClassNotFoundException {
AttributeDefinition[] attributeDefinitions) this((Class<T>) Class.forName(hierarchicalMetaTypeName), typeName, ImmutableList.copyOf(superTypes),
throws ClassNotFoundException { attributeDefinitions);
this((Class<T>) Class.forName(hierarchicalMetaTypeName),
typeName, ImmutableList.copyOf(superTypes), attributeDefinitions);
} }
public HierarchicalTypeDefinition(Class<T> hierarchicalMetaType, public HierarchicalTypeDefinition(Class<T> hierarchicalMetaType, String typeName, ImmutableList<String> superTypes,
String typeName, ImmutableList<String> superTypes,
AttributeDefinition[] attributeDefinitions) { AttributeDefinition[] attributeDefinitions) {
super(typeName, false, attributeDefinitions); super(typeName, false, attributeDefinitions);
hierarchicalMetaTypeName = hierarchicalMetaType.getName(); hierarchicalMetaTypeName = hierarchicalMetaType.getName();
...@@ -54,14 +51,24 @@ public class HierarchicalTypeDefinition<T extends HierarchicalType> extends Stru ...@@ -54,14 +51,24 @@ public class HierarchicalTypeDefinition<T extends HierarchicalType> extends Stru
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
if (!super.equals(o)) return false; }
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
HierarchicalTypeDefinition that = (HierarchicalTypeDefinition) o; HierarchicalTypeDefinition that = (HierarchicalTypeDefinition) o;
if (!hierarchicalMetaTypeName.equals(that.hierarchicalMetaTypeName)) return false; if (!hierarchicalMetaTypeName.equals(that.hierarchicalMetaTypeName)) {
if (!superTypes.equals(that.superTypes)) return false; return false;
}
if (!superTypes.equals(that.superTypes)) {
return false;
}
return true; return true;
} }
......
...@@ -31,6 +31,7 @@ public final class Multiplicity { ...@@ -31,6 +31,7 @@ public final class Multiplicity {
public final int lower; public final int lower;
public final int upper; public final int upper;
public final boolean isUnique; public final boolean isUnique;
public Multiplicity(int lower, int upper, boolean isUnique) { public Multiplicity(int lower, int upper, boolean isUnique) {
assert lower >= 0; assert lower >= 0;
assert upper >= 1; assert upper >= 1;
...@@ -46,14 +47,24 @@ public final class Multiplicity { ...@@ -46,14 +47,24 @@ public final class Multiplicity {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Multiplicity that = (Multiplicity) o; Multiplicity that = (Multiplicity) o;
if (isUnique != that.isUnique) return false; if (isUnique != that.isUnique) {
if (lower != that.lower) return false; return false;
if (upper != that.upper) return false; }
if (lower != that.lower) {
return false;
}
if (upper != that.upper) {
return false;
}
return true; return true;
} }
......
...@@ -39,8 +39,7 @@ public class ObjectGraphTraversal implements Iterator<ObjectGraphTraversal.Insta ...@@ -39,8 +39,7 @@ public class ObjectGraphTraversal implements Iterator<ObjectGraphTraversal.Insta
final TypeSystem typeSystem; final TypeSystem typeSystem;
Set<Id> processedIds; Set<Id> processedIds;
public ObjectGraphTraversal(TypeSystem typeSystem, IReferenceableInstance start) public ObjectGraphTraversal(TypeSystem typeSystem, IReferenceableInstance start) throws AtlasException {
throws AtlasException {
this.typeSystem = typeSystem; this.typeSystem = typeSystem;
queue = new LinkedList<InstanceTuple>(); queue = new LinkedList<InstanceTuple>();
processedIds = new HashSet<Id>(); processedIds = new HashSet<Id>();
...@@ -56,8 +55,8 @@ public class ObjectGraphTraversal implements Iterator<ObjectGraphTraversal.Insta ...@@ -56,8 +55,8 @@ public class ObjectGraphTraversal implements Iterator<ObjectGraphTraversal.Insta
IDataType keyType = ((DataTypes.MapType) dT).getKeyType(); IDataType keyType = ((DataTypes.MapType) dT).getKeyType();
IDataType valueType = ((DataTypes.MapType) dT).getKeyType(); IDataType valueType = ((DataTypes.MapType) dT).getKeyType();
processMap(keyType, valueType, val); processMap(keyType, valueType, val);
} else if (dT.getTypeCategory() == DataTypes.TypeCategory.STRUCT || } else if (dT.getTypeCategory() == DataTypes.TypeCategory.STRUCT
dT.getTypeCategory() == DataTypes.TypeCategory.TRAIT) { || dT.getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
processStruct(val); processStruct(val);
} else if (dT.getTypeCategory() == DataTypes.TypeCategory.CLASS) { } else if (dT.getTypeCategory() == DataTypes.TypeCategory.CLASS) {
processReferenceableInstance(val); processReferenceableInstance(val);
...@@ -66,8 +65,8 @@ public class ObjectGraphTraversal implements Iterator<ObjectGraphTraversal.Insta ...@@ -66,8 +65,8 @@ public class ObjectGraphTraversal implements Iterator<ObjectGraphTraversal.Insta
} }
void processMap(IDataType keyType, IDataType valueType, Object val) throws AtlasException { void processMap(IDataType keyType, IDataType valueType, Object val) throws AtlasException {
if (keyType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE && if (keyType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE
valueType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE) { && valueType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE) {
return; return;
} }
......
...@@ -47,13 +47,11 @@ public class ObjectGraphWalker { ...@@ -47,13 +47,11 @@ public class ObjectGraphWalker {
final NodeProcessor nodeProcessor; final NodeProcessor nodeProcessor;
Set<Id> processedIds; Set<Id> processedIds;
public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor) public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor) throws AtlasException {
throws AtlasException {
this(typeSystem, nodeProcessor, (IReferenceableInstance) null); this(typeSystem, nodeProcessor, (IReferenceableInstance) null);
} }
public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor, public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor, IReferenceableInstance start)
IReferenceableInstance start)
throws AtlasException { throws AtlasException {
this.typeSystem = typeSystem; this.typeSystem = typeSystem;
this.nodeProcessor = nodeProcessor; this.nodeProcessor = nodeProcessor;
...@@ -65,8 +63,7 @@ public class ObjectGraphWalker { ...@@ -65,8 +63,7 @@ public class ObjectGraphWalker {
} }
public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor, public ObjectGraphWalker(TypeSystem typeSystem, NodeProcessor nodeProcessor,
List<? extends IReferenceableInstance> roots) List<? extends IReferenceableInstance> roots) throws AtlasException {
throws AtlasException {
this.typeSystem = typeSystem; this.typeSystem = typeSystem;
this.nodeProcessor = nodeProcessor; this.nodeProcessor = nodeProcessor;
queue = new LinkedList<IReferenceableInstance>(); queue = new LinkedList<IReferenceableInstance>();
...@@ -96,8 +93,8 @@ public class ObjectGraphWalker { ...@@ -96,8 +93,8 @@ public class ObjectGraphWalker {
IDataType keyType = ((DataTypes.MapType) dT).getKeyType(); IDataType keyType = ((DataTypes.MapType) dT).getKeyType();
IDataType valueType = ((DataTypes.MapType) dT).getKeyType(); IDataType valueType = ((DataTypes.MapType) dT).getKeyType();
visitMap(keyType, valueType, val); visitMap(keyType, valueType, val);
} else if (dT.getTypeCategory() == DataTypes.TypeCategory.STRUCT || } else if (dT.getTypeCategory() == DataTypes.TypeCategory.STRUCT
dT.getTypeCategory() == DataTypes.TypeCategory.TRAIT) { || dT.getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
visitStruct(val); visitStruct(val);
} else if (dT.getTypeCategory() == DataTypes.TypeCategory.CLASS) { } else if (dT.getTypeCategory() == DataTypes.TypeCategory.CLASS) {
visitReferenceableInstance(val); visitReferenceableInstance(val);
...@@ -106,8 +103,8 @@ public class ObjectGraphWalker { ...@@ -106,8 +103,8 @@ public class ObjectGraphWalker {
} }
void visitMap(IDataType keyType, IDataType valueType, Object val) throws AtlasException { void visitMap(IDataType keyType, IDataType valueType, Object val) throws AtlasException {
if (keyType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE && if (keyType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE
valueType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE) { && valueType.getTypeCategory() == DataTypes.TypeCategory.PRIMITIVE) {
return; return;
} }
......
...@@ -28,8 +28,7 @@ import java.util.LinkedHashMap; ...@@ -28,8 +28,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class StructType extends AbstractDataType<IStruct> public class StructType extends AbstractDataType<IStruct> implements IConstructableType<IStruct, ITypedStruct> {
implements IConstructableType<IStruct, ITypedStruct> {
public final TypeSystem typeSystem; public final TypeSystem typeSystem;
public final String name; public final String name;
...@@ -50,13 +49,11 @@ public class StructType extends AbstractDataType<IStruct> ...@@ -50,13 +49,11 @@ public class StructType extends AbstractDataType<IStruct>
this.handler = null; this.handler = null;
} }
protected StructType(TypeSystem typeSystem, String name, protected StructType(TypeSystem typeSystem, String name, ImmutableList<String> superTypes, AttributeInfo... fields)
ImmutableList<String> superTypes, AttributeInfo... fields)
throws AtlasException { throws AtlasException {
this.typeSystem = typeSystem; this.typeSystem = typeSystem;
this.name = name; this.name = name;
this.fieldMapping = constructFieldMapping(superTypes, this.fieldMapping = constructFieldMapping(superTypes, fields);
fields);
infoToNameMap = TypeUtils.buildAttrInfoToNameMap(this.fieldMapping); infoToNameMap = TypeUtils.buildAttrInfoToNameMap(this.fieldMapping);
this.numFields = this.fieldMapping.fields.size(); this.numFields = this.fieldMapping.fields.size();
this.handler = new TypedStructHandler(this); this.handler = new TypedStructHandler(this);
...@@ -71,8 +68,7 @@ public class StructType extends AbstractDataType<IStruct> ...@@ -71,8 +68,7 @@ public class StructType extends AbstractDataType<IStruct>
return name; return name;
} }
protected FieldMapping constructFieldMapping(ImmutableList<String> superTypes, protected FieldMapping constructFieldMapping(ImmutableList<String> superTypes, AttributeInfo... fields)
AttributeInfo... fields)
throws AtlasException { throws AtlasException {
Map<String, AttributeInfo> fieldsMap = new LinkedHashMap<String, AttributeInfo>(); Map<String, AttributeInfo> fieldsMap = new LinkedHashMap<String, AttributeInfo>();
...@@ -97,9 +93,7 @@ public class StructType extends AbstractDataType<IStruct> ...@@ -97,9 +93,7 @@ public class StructType extends AbstractDataType<IStruct>
for (AttributeInfo i : fields) { for (AttributeInfo i : fields) {
if (fieldsMap.containsKey(i.name)) { if (fieldsMap.containsKey(i.name)) {
throw new AtlasException( throw new AtlasException(
String.format( String.format("Struct defintion cannot contain multiple fields with the same " + "name %s",
"Struct defintion cannot contain multiple fields with the same " +
"name %s",
i.name)); i.name));
} }
fieldsMap.put(i.name, i); fieldsMap.put(i.name, i);
...@@ -146,8 +140,8 @@ public class StructType extends AbstractDataType<IStruct> ...@@ -146,8 +140,8 @@ public class StructType extends AbstractDataType<IStruct>
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) { } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
fieldPos.put(i.name, numMaps); fieldPos.put(i.name, numMaps);
numMaps++; numMaps++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT || } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT
i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) { || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
fieldPos.put(i.name, numStructs); fieldPos.put(i.name, numStructs);
numStructs++; numStructs++;
} else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) { } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
...@@ -158,23 +152,8 @@ public class StructType extends AbstractDataType<IStruct> ...@@ -158,23 +152,8 @@ public class StructType extends AbstractDataType<IStruct>
} }
} }
return new FieldMapping(fieldsMap, return new FieldMapping(fieldsMap, fieldPos, fieldNullPos, numBools, numBytes, numShorts, numInts, numLongs,
fieldPos, numFloats, numDoubles, numBigInts, numBigDecimals, numDates, numStrings, numArrays, numMaps, numStructs,
fieldNullPos,
numBools,
numBytes,
numShorts,
numInts,
numLongs,
numFloats,
numDoubles,
numBigInts,
numBigDecimals,
numDates,
numStrings,
numArrays,
numMaps,
numStructs,
numReferenceables); numReferenceables);
} }
......
...@@ -42,13 +42,21 @@ public class StructTypeDefinition { ...@@ -42,13 +42,21 @@ public class StructTypeDefinition {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
StructTypeDefinition that = (StructTypeDefinition) o; StructTypeDefinition that = (StructTypeDefinition) o;
if (!Arrays.equals(attributeDefinitions, that.attributeDefinitions)) return false; if (!Arrays.equals(attributeDefinitions, that.attributeDefinitions)) {
if (!typeName.equals(that.typeName)) return false; return false;
}
if (!typeName.equals(that.typeName)) {
return false;
}
return true; return true;
} }
......
...@@ -35,15 +35,13 @@ public class TraitType extends HierarchicalType<TraitType, IStruct> ...@@ -35,15 +35,13 @@ public class TraitType extends HierarchicalType<TraitType, IStruct>
/** /**
* Used when creating a TraitType, to support recursive Structs. * Used when creating a TraitType, to support recursive Structs.
*/ */
TraitType(TypeSystem typeSystem, String name, ImmutableList<String> superTraits, TraitType(TypeSystem typeSystem, String name, ImmutableList<String> superTraits, int numFields) {
int numFields) {
super(typeSystem, TraitType.class, name, superTraits, numFields); super(typeSystem, TraitType.class, name, superTraits, numFields);
handler = null; handler = null;
infoToNameMap = null; infoToNameMap = null;
} }
TraitType(TypeSystem typeSystem, String name, ImmutableList<String> superTraits, TraitType(TypeSystem typeSystem, String name, ImmutableList<String> superTraits, AttributeInfo... fields)
AttributeInfo... fields)
throws AtlasException { throws AtlasException {
super(typeSystem, TraitType.class, name, superTraits, fields); super(typeSystem, TraitType.class, name, superTraits, fields);
handler = new TypedStructHandler(this); handler = new TypedStructHandler(this);
......
...@@ -36,13 +36,11 @@ public class TypeUtils { ...@@ -36,13 +36,11 @@ public class TypeUtils {
public static final String NAME_REGEX = "[a-zA-z][a-zA-Z0-9_]*"; public static final String NAME_REGEX = "[a-zA-z][a-zA-Z0-9_]*";
public static final Pattern NAME_PATTERN = Pattern.compile(NAME_REGEX); public static final Pattern NAME_PATTERN = Pattern.compile(NAME_REGEX);
public static final Pattern ARRAY_TYPE_NAME_PATTERN = Pattern public static final Pattern ARRAY_TYPE_NAME_PATTERN = Pattern.compile(String.format("array<(%s)>", NAME_REGEX));
.compile(String.format("array<(%s)>", NAME_REGEX));
public static final Pattern MAP_TYPE_NAME_PATTERN = public static final Pattern MAP_TYPE_NAME_PATTERN =
Pattern.compile(String.format("map<(%s),(%s)>", NAME_REGEX, NAME_REGEX)); Pattern.compile(String.format("map<(%s),(%s)>", NAME_REGEX, NAME_REGEX));
public static void outputVal(String val, Appendable buf, String prefix) public static void outputVal(String val, Appendable buf, String prefix) throws AtlasException {
throws AtlasException {
try { try {
buf.append(prefix).append(val); buf.append(prefix).append(val);
} catch (IOException ie) { } catch (IOException ie) {
...@@ -73,14 +71,14 @@ public class TypeUtils { ...@@ -73,14 +71,14 @@ public class TypeUtils {
return ImmutableMap.copyOf(b); return ImmutableMap.copyOf(b);
} }
public static TypesDef getTypesDef(ImmutableList<EnumTypeDefinition> enums, ImmutableList<StructTypeDefinition> structs, public static TypesDef getTypesDef(ImmutableList<EnumTypeDefinition> enums,
ImmutableList<HierarchicalTypeDefinition<TraitType>> traits, ImmutableList<StructTypeDefinition> structs, ImmutableList<HierarchicalTypeDefinition<TraitType>> traits,
ImmutableList<HierarchicalTypeDefinition<ClassType>> classes) { ImmutableList<HierarchicalTypeDefinition<ClassType>> classes) {
return new TypesDef(JavaConversions.asScalaBuffer(enums), JavaConversions.asScalaBuffer(structs), return new TypesDef(JavaConversions.asScalaBuffer(enums), JavaConversions.asScalaBuffer(structs),
JavaConversions.asScalaBuffer(traits), JavaConversions.asScalaBuffer(classes)); JavaConversions.asScalaBuffer(traits), JavaConversions.asScalaBuffer(classes));
} }
protected static class Pair<L,R> { protected static class Pair<L, R> {
protected L left; protected L left;
protected R right; protected R right;
......
...@@ -68,8 +68,7 @@ public class TypedStructHandler { ...@@ -68,8 +68,7 @@ public class TypedStructHandler {
} }
} }
return ts; return ts;
} else if (val instanceof StructInstance && } else if (val instanceof StructInstance && ((StructInstance) val).getTypeName() == structType.getName()) {
((StructInstance) val).getTypeName() == structType.getName()) {
return (StructInstance) val; return (StructInstance) val;
} else { } else {
throw new ValueConversionException(structType, val); throw new ValueConversionException(structType, val);
...@@ -86,9 +85,7 @@ public class TypedStructHandler { ...@@ -86,9 +85,7 @@ public class TypedStructHandler {
} }
public ITypedStruct createInstance() { public ITypedStruct createInstance() {
return new StructInstance(structType.getName(), return new StructInstance(structType.getName(), fieldMapping, new boolean[fieldMapping.fields.size()],
fieldMapping,
new boolean[fieldMapping.fields.size()],
fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools], fieldMapping.numBools == 0 ? null : new boolean[fieldMapping.numBools],
fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes], fieldMapping.numBytes == 0 ? null : new byte[fieldMapping.numBytes],
fieldMapping.numShorts == 0 ? null : new short[fieldMapping.numShorts], fieldMapping.numShorts == 0 ? null : new short[fieldMapping.numShorts],
...@@ -96,18 +93,15 @@ public class TypedStructHandler { ...@@ -96,18 +93,15 @@ public class TypedStructHandler {
fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs], fieldMapping.numLongs == 0 ? null : new long[fieldMapping.numLongs],
fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats], fieldMapping.numFloats == 0 ? null : new float[fieldMapping.numFloats],
fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles], fieldMapping.numDoubles == 0 ? null : new double[fieldMapping.numDoubles],
fieldMapping.numBigDecimals == 0 ? null fieldMapping.numBigDecimals == 0 ? null : new BigDecimal[fieldMapping.numBigDecimals],
: new BigDecimal[fieldMapping.numBigDecimals],
fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts], fieldMapping.numBigInts == 0 ? null : new BigInteger[fieldMapping.numBigInts],
fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates], fieldMapping.numDates == 0 ? null : new Date[fieldMapping.numDates],
fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings], fieldMapping.numStrings == 0 ? null : new String[fieldMapping.numStrings],
fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays], fieldMapping.numArrays == 0 ? null : new ImmutableList[fieldMapping.numArrays],
fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps], fieldMapping.numMaps == 0 ? null : new ImmutableMap[fieldMapping.numMaps],
fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs], fieldMapping.numStructs == 0 ? null : new StructInstance[fieldMapping.numStructs],
fieldMapping.numReferenceables == 0 ? null fieldMapping.numReferenceables == 0 ? null : new ReferenceableInstance[fieldMapping.numReferenceables],
: new ReferenceableInstance[fieldMapping.numReferenceables], fieldMapping.numReferenceables == 0 ? null : new Id[fieldMapping.numReferenceables]);
fieldMapping.numReferenceables == 0 ? null
: new Id[fieldMapping.numReferenceables]);
} }
public void output(IStruct s, Appendable buf, String prefix) throws AtlasException { public void output(IStruct s, Appendable buf, String prefix) throws AtlasException {
......
...@@ -27,19 +27,16 @@ public class ValueConversionException extends AtlasException { ...@@ -27,19 +27,16 @@ public class ValueConversionException extends AtlasException {
} }
public ValueConversionException(IDataType typ, Object val, Throwable t) { public ValueConversionException(IDataType typ, Object val, Throwable t) {
super(String super(String.format("Cannot convert value '%s' to datatype %s", val.toString(), typ.getName()), t);
.format("Cannot convert value '%s' to datatype %s", val.toString(), typ.getName()),
t);
} }
public ValueConversionException(IDataType typ, Object val, String msg) { public ValueConversionException(IDataType typ, Object val, String msg) {
super(String.format("Cannot convert value '%s' to datatype %s because: %s", super(String
val.toString(), typ.getName(), msg)); .format("Cannot convert value '%s' to datatype %s because: %s", val.toString(), typ.getName(), msg));
} }
public ValueConversionException(String typeName, Object val, String msg) { public ValueConversionException(String typeName, Object val, String msg) {
super(String.format("Cannot convert value '%s' to datatype %s because: %s", super(String.format("Cannot convert value '%s' to datatype %s because: %s", val.toString(), typeName, msg));
val.toString(), typeName, msg));
} }
protected ValueConversionException(String msg) { protected ValueConversionException(String msg) {
......
...@@ -37,40 +37,32 @@ public class TypesUtil { ...@@ -37,40 +37,32 @@ public class TypesUtil {
private TypesUtil() { private TypesUtil() {
} }
public static AttributeDefinition createOptionalAttrDef(String name, public static AttributeDefinition createOptionalAttrDef(String name, IDataType dataType) {
IDataType dataType) { return new AttributeDefinition(name, dataType.getName(), Multiplicity.OPTIONAL, false, null);
return new AttributeDefinition(name, dataType.getName(),
Multiplicity.OPTIONAL, false, null);
} }
public static AttributeDefinition createOptionalAttrDef(String name, public static AttributeDefinition createOptionalAttrDef(String name, String dataType) {
String dataType) {
return new AttributeDefinition(name, dataType, Multiplicity.OPTIONAL, false, null); return new AttributeDefinition(name, dataType, Multiplicity.OPTIONAL, false, null);
} }
public static AttributeDefinition createRequiredAttrDef(String name, public static AttributeDefinition createRequiredAttrDef(String name, String dataType) {
String dataType) {
return new AttributeDefinition(name, dataType, Multiplicity.REQUIRED, false, null); return new AttributeDefinition(name, dataType, Multiplicity.REQUIRED, false, null);
} }
public static AttributeDefinition createUniqueRequiredAttrDef(String name, public static AttributeDefinition createUniqueRequiredAttrDef(String name, IDataType dataType) {
IDataType dataType) { return new AttributeDefinition(name, dataType.getName(), Multiplicity.REQUIRED, false, true, true, null);
return new AttributeDefinition(name, dataType.getName(),
Multiplicity.REQUIRED, false, true, true, null);
} }
public static AttributeDefinition createRequiredAttrDef(String name, public static AttributeDefinition createRequiredAttrDef(String name, IDataType dataType) {
IDataType dataType) { return new AttributeDefinition(name, dataType.getName(), Multiplicity.REQUIRED, false, null);
return new AttributeDefinition(name, dataType.getName(),
Multiplicity.REQUIRED, false, null);
} }
public static EnumTypeDefinition createEnumTypeDef(String name, EnumValue... enumValues) { public static EnumTypeDefinition createEnumTypeDef(String name, EnumValue... enumValues) {
return new EnumTypeDefinition(name, enumValues); return new EnumTypeDefinition(name, enumValues);
} }
public static HierarchicalTypeDefinition<TraitType> createTraitTypeDef( public static HierarchicalTypeDefinition<TraitType> createTraitTypeDef(String name,
String name, ImmutableList<String> superTypes, AttributeDefinition... attrDefs) { ImmutableList<String> superTypes, AttributeDefinition... attrDefs) {
return new HierarchicalTypeDefinition<>(TraitType.class, name, superTypes, attrDefs); return new HierarchicalTypeDefinition<>(TraitType.class, name, superTypes, attrDefs);
} }
...@@ -78,8 +70,8 @@ public class TypesUtil { ...@@ -78,8 +70,8 @@ public class TypesUtil {
return new StructTypeDefinition(name, attrDefs); return new StructTypeDefinition(name, attrDefs);
} }
public static HierarchicalTypeDefinition<ClassType> createClassTypeDef( public static HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name,
String name, ImmutableList<String> superTypes, AttributeDefinition... attrDefs) { ImmutableList<String> superTypes, AttributeDefinition... attrDefs) {
return new HierarchicalTypeDefinition<>(ClassType.class, name, superTypes, attrDefs); return new HierarchicalTypeDefinition<>(ClassType.class, name, superTypes, attrDefs);
} }
} }
...@@ -62,38 +62,26 @@ public class SerializationJavaTest extends BaseTest { ...@@ -62,38 +62,26 @@ public class SerializationJavaTest extends BaseTest {
TypeSystem ts = getTypeSystem(); TypeSystem ts = getTypeSystem();
HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", ImmutableList.<String>of(),
ImmutableList.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
String.format("array<%s>", "Person"), Multiplicity.COLLECTION, true, true, "department"));
"department") HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", ImmutableList.<String>of(),
);
HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person",
ImmutableList.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("department", new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
"Department", Multiplicity.REQUIRED, false, "employees"), new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"));
new AttributeDefinition("manager", HierarchicalTypeDefinition<ClassType> managerTypeDef =
"Manager", Multiplicity.OPTIONAL, false, "subordinates") createClassTypeDef("Manager", ImmutableList.<String>of("Person"),
); new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager", Multiplicity.COLLECTION, false, "manager"));
ImmutableList.<String>of("Person"),
new AttributeDefinition("subordinates", HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
String.format("array<%s>", "Person"), Multiplicity.COLLECTION, false, createTraitTypeDef("SecurityClearance", ImmutableList.<String>of(),
"manager") createRequiredAttrDef("level", DataTypes.INT_TYPE));
);
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = createTraitTypeDef(
"SecurityClearance",
ImmutableList.<String>of(),
createRequiredAttrDef("level", DataTypes.INT_TYPE)
);
ts.defineTypes(ImmutableList.<StructTypeDefinition>of(), ts.defineTypes(ImmutableList.<StructTypeDefinition>of(),
ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(securityClearanceTypeDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(securityClearanceTypeDef),
ImmutableList.<HierarchicalTypeDefinition<ClassType>>of(deptTypeDef, personTypeDef, ImmutableList.<HierarchicalTypeDefinition<ClassType>>of(deptTypeDef, personTypeDef, managerTypeDef));
managerTypeDef));
Referenceable hrDept = new Referenceable("Department"); Referenceable hrDept = new Referenceable("Department");
Referenceable john = new Referenceable("Person"); Referenceable john = new Referenceable("Person");
...@@ -155,11 +143,9 @@ public class SerializationJavaTest extends BaseTest { ...@@ -155,11 +143,9 @@ public class SerializationJavaTest extends BaseTest {
public void testTrait() throws AtlasException { public void testTrait() throws AtlasException {
TypeSystem ts = getTypeSystem(); TypeSystem ts = getTypeSystem();
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = createTraitTypeDef( HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
"SecurityClearance2", createTraitTypeDef("SecurityClearance2", ImmutableList.<String>of(),
ImmutableList.<String>of(), createRequiredAttrDef("level", DataTypes.INT_TYPE));
createRequiredAttrDef("level", DataTypes.INT_TYPE)
);
ts.defineTypes(ImmutableList.<StructTypeDefinition>of(), ts.defineTypes(ImmutableList.<StructTypeDefinition>of(),
ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(securityClearanceTypeDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(securityClearanceTypeDef),
......
...@@ -37,11 +37,10 @@ public abstract class BaseTest { ...@@ -37,11 +37,10 @@ public abstract class BaseTest {
public static final String STRUCT_TYPE_1 = "t1"; public static final String STRUCT_TYPE_1 = "t1";
public static final String STRUCT_TYPE_2 = "t2"; public static final String STRUCT_TYPE_2 = "t2";
public static final String TEST_DATE = "2014-12-11T02:35:58.440Z"; public static final String TEST_DATE = "2014-12-11T02:35:58.440Z";
public static final long TEST_DATE_IN_LONG=1418265358440L; public static final long TEST_DATE_IN_LONG = 1418265358440L;
public static Struct createStruct() throws AtlasException { public static Struct createStruct() throws AtlasException {
StructType structType = TypeSystem.getInstance().getDataType( StructType structType = TypeSystem.getInstance().getDataType(StructType.class, STRUCT_TYPE_1);
StructType.class, STRUCT_TYPE_1);
Struct s = new Struct(structType.getName()); Struct s = new Struct(structType.getName());
s.set("a", 1); s.set("a", 1);
s.set("b", true); s.set("b", true);
...@@ -56,8 +55,7 @@ public abstract class BaseTest { ...@@ -56,8 +55,7 @@ public abstract class BaseTest {
s.set("k", new BigDecimal(1)); s.set("k", new BigDecimal(1));
s.set("l", new Date(1418265358440L)); s.set("l", new Date(1418265358440L));
s.set("m", Lists.asList(1, new Integer[]{1})); s.set("m", Lists.asList(1, new Integer[]{1}));
s.set("n", Lists.asList(BigDecimal.valueOf(1.1), s.set("n", Lists.asList(BigDecimal.valueOf(1.1), new BigDecimal[]{BigDecimal.valueOf(1.1)}));
new BigDecimal[]{BigDecimal.valueOf(1.1)}));
Map<String, Double> hm = Maps.newHashMap(); Map<String, Double> hm = Maps.newHashMap();
hm.put("a", 1.0); hm.put("a", 1.0);
hm.put("b", 2.0); hm.put("b", 2.0);
...@@ -74,9 +72,8 @@ public abstract class BaseTest { ...@@ -74,9 +72,8 @@ public abstract class BaseTest {
TypeSystem ts = TypeSystem.getInstance(); TypeSystem ts = TypeSystem.getInstance();
ts.reset(); ts.reset();
StructType structType = ts.defineStructType(STRUCT_TYPE_1, StructType structType =
true, ts.defineStructType(STRUCT_TYPE_1, true, TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE), TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE), TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE),
...@@ -89,26 +86,24 @@ public abstract class BaseTest { ...@@ -89,26 +86,24 @@ public abstract class BaseTest {
TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE), TypesUtil.createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE),
TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE), TypesUtil.createOptionalAttrDef("l", DataTypes.DATE_TYPE),
TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), TypesUtil.createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)),
TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), TypesUtil.createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), TypesUtil
TypesUtil.createOptionalAttrDef("o", .createOptionalAttrDef("o",
ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE))); ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)));
System.out.println("defined structType = " + structType); System.out.println("defined structType = " + structType);
StructType recursiveStructType = ts.defineStructType(STRUCT_TYPE_2, StructType recursiveStructType =
true, ts.defineStructType(STRUCT_TYPE_2, true, TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE),
TypesUtil.createOptionalAttrDef("s", STRUCT_TYPE_2)); TypesUtil.createOptionalAttrDef("s", STRUCT_TYPE_2));
System.out.println("defined recursiveStructType = " + recursiveStructType); System.out.println("defined recursiveStructType = " + recursiveStructType);
} }
protected Map<String, IDataType> defineTraits(HierarchicalTypeDefinition... tDefs) protected Map<String, IDataType> defineTraits(HierarchicalTypeDefinition... tDefs) throws AtlasException {
throws AtlasException {
return getTypeSystem().defineTraitTypes(tDefs); return getTypeSystem().defineTraitTypes(tDefs);
} }
protected Map<String, IDataType> defineClasses( protected Map<String, IDataType> defineClasses(HierarchicalTypeDefinition<ClassType>... classDefs)
HierarchicalTypeDefinition<ClassType>... classDefs) throws AtlasException { throws AtlasException {
return getTypeSystem().defineClassTypes(classDefs); return getTypeSystem().defineClassTypes(classDefs);
} }
...@@ -123,47 +118,30 @@ public abstract class BaseTest { ...@@ -123,47 +118,30 @@ public abstract class BaseTest {
protected void defineDeptEmployeeTypes(TypeSystem ts) throws AtlasException { protected void defineDeptEmployeeTypes(TypeSystem ts) throws AtlasException {
HierarchicalTypeDefinition<ClassType> deptTypeDef = TypesUtil HierarchicalTypeDefinition<ClassType> deptTypeDef = TypesUtil
.createClassTypeDef("Department", .createClassTypeDef("Department", ImmutableList.<String>of(),
ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", new AttributeDefinition("employees", String.format("array<%s>", "Person"),
String.format("array<%s>", "Person"), Multiplicity.COLLECTION, true, Multiplicity.COLLECTION, true, "department"));
"department") HierarchicalTypeDefinition<ClassType> personTypeDef = TypesUtil
); .createClassTypeDef("Person", ImmutableList.<String>of(),
HierarchicalTypeDefinition<ClassType> personTypeDef = TypesUtil.createClassTypeDef("Person",
ImmutableList.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("department", new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
"Department", Multiplicity.REQUIRED, false, "employees"), new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"));
new AttributeDefinition("manager", HierarchicalTypeDefinition<ClassType> managerTypeDef = TypesUtil
"Manager", Multiplicity.OPTIONAL, false, "subordinates") .createClassTypeDef("Manager", ImmutableList.of("Person"),
); new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
HierarchicalTypeDefinition<ClassType> managerTypeDef = Multiplicity.COLLECTION, false, "manager"));
TypesUtil.createClassTypeDef("Manager",
ImmutableList.of("Person"), HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = TypesUtil
new AttributeDefinition("subordinates", .createTraitTypeDef("SecurityClearance", ImmutableList.<String>of(),
String.format("array<%s>", "Person"), TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
Multiplicity.COLLECTION, false, "manager")
); ts.defineTypes(ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(securityClearanceTypeDef),
ImmutableList.of(deptTypeDef, personTypeDef, managerTypeDef));
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
TypesUtil.createTraitTypeDef( ImmutableList.of(ts.getDataType(HierarchicalType.class, "SecurityClearance"),
"SecurityClearance", ts.getDataType(ClassType.class, "Department"), ts.getDataType(ClassType.class, "Person"),
ImmutableList.<String>of(), ts.getDataType(ClassType.class, "Manager"));
TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)
);
ts.defineTypes(ImmutableList.<StructTypeDefinition>of(),
ImmutableList.of(securityClearanceTypeDef),
ImmutableList.of(deptTypeDef, personTypeDef,
managerTypeDef));
ImmutableList.of(
ts.getDataType(HierarchicalType.class, "SecurityClearance"),
ts.getDataType(ClassType.class, "Department"),
ts.getDataType(ClassType.class, "Person"),
ts.getDataType(ClassType.class, "Manager")
);
} }
protected Referenceable createDeptEg1(TypeSystem ts) throws AtlasException { protected Referenceable createDeptEg1(TypeSystem ts) throws AtlasException {
......
...@@ -48,26 +48,16 @@ public class EnumTest extends BaseTest { ...@@ -48,26 +48,16 @@ public class EnumTest extends BaseTest {
} }
void defineEnums(TypeSystem ts) throws AtlasException { void defineEnums(TypeSystem ts) throws AtlasException {
ts.defineEnumType("HiveObjectType", ts.defineEnumType("HiveObjectType", new EnumValue("GLOBAL", 1), new EnumValue("DATABASE", 2),
new EnumValue("GLOBAL", 1), new EnumValue("TABLE", 3), new EnumValue("PARTITION", 4), new EnumValue("COLUMN", 5));
new EnumValue("DATABASE", 2),
new EnumValue("TABLE", 3), ts.defineEnumType("PrincipalType", new EnumValue("USER", 1), new EnumValue("ROLE", 2),
new EnumValue("PARTITION", 4),
new EnumValue("COLUMN", 5));
ts.defineEnumType("PrincipalType",
new EnumValue("USER", 1),
new EnumValue("ROLE", 2),
new EnumValue("GROUP", 3)); new EnumValue("GROUP", 3));
ts.defineEnumType("TxnState", ts.defineEnumType("TxnState", new EnumValue("COMMITTED", 1), new EnumValue("ABORTED", 2),
new EnumValue("COMMITTED", 1),
new EnumValue("ABORTED", 2),
new EnumValue("OPEN", 3)); new EnumValue("OPEN", 3));
ts.defineEnumType("LockLevel", ts.defineEnumType("LockLevel", new EnumValue("DB", 1), new EnumValue("TABLE", 2),
new EnumValue("DB", 1),
new EnumValue("TABLE", 2),
new EnumValue("PARTITION", 3)); new EnumValue("PARTITION", 3));
} }
...@@ -86,8 +76,7 @@ public class EnumTest extends BaseTest { ...@@ -86,8 +76,7 @@ public class EnumTest extends BaseTest {
s.set("k", new BigDecimal(1)); s.set("k", new BigDecimal(1));
s.set("l", new Date(1418265358440L)); s.set("l", new Date(1418265358440L));
s.set("m", Lists.asList(1, new Integer[]{1})); s.set("m", Lists.asList(1, new Integer[]{1}));
s.set("n", s.set("n", Lists.asList(BigDecimal.valueOf(1.1), new BigDecimal[]{BigDecimal.valueOf(1.1)}));
Lists.asList(BigDecimal.valueOf(1.1), new BigDecimal[]{BigDecimal.valueOf(1.1)}));
Map<String, Double> hm = Maps.newHashMap(); Map<String, Double> hm = Maps.newHashMap();
hm.put("a", 1.0); hm.put("a", 1.0);
hm.put("b", 2.0); hm.put("b", 2.0);
...@@ -111,15 +100,13 @@ public class EnumTest extends BaseTest { ...@@ -111,15 +100,13 @@ public class EnumTest extends BaseTest {
} }
protected ClassType defineClassTypeWithEnum(TypeSystem ts) throws AtlasException { protected ClassType defineClassTypeWithEnum(TypeSystem ts) throws AtlasException {
return ts.defineClassType(createClassTypeDef("t4", return ts.defineClassType(
ImmutableList.<String>of(), createClassTypeDef("t4", ImmutableList.<String>of(), createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE), createOptionalAttrDef("d", DataTypes.SHORT_TYPE),
createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")), createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")),
createOptionalAttrDef("e", DataTypes.INT_TYPE), createOptionalAttrDef("e", DataTypes.INT_TYPE), createOptionalAttrDef("f", DataTypes.INT_TYPE),
createOptionalAttrDef("f", DataTypes.INT_TYPE),
createOptionalAttrDef("g", DataTypes.LONG_TYPE), createOptionalAttrDef("g", DataTypes.LONG_TYPE),
createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")), createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")),
createOptionalAttrDef("h", DataTypes.FLOAT_TYPE), createOptionalAttrDef("h", DataTypes.FLOAT_TYPE),
...@@ -130,8 +117,7 @@ public class EnumTest extends BaseTest { ...@@ -130,8 +117,7 @@ public class EnumTest extends BaseTest {
createOptionalAttrDef("l", DataTypes.DATE_TYPE), createOptionalAttrDef("l", DataTypes.DATE_TYPE),
createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)),
createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)),
createOptionalAttrDef("o", createOptionalAttrDef("o", ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel")))); createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel"))));
} }
...@@ -139,27 +125,21 @@ public class EnumTest extends BaseTest { ...@@ -139,27 +125,21 @@ public class EnumTest extends BaseTest {
public void testStruct() throws AtlasException { public void testStruct() throws AtlasException {
TypeSystem ts = getTypeSystem(); TypeSystem ts = getTypeSystem();
defineEnums(ts); defineEnums(ts);
StructType structType = ts.defineStructType("t3", StructType structType = ts.defineStructType("t3", true, createRequiredAttrDef("a", DataTypes.INT_TYPE),
true, createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE), createOptionalAttrDef("d", DataTypes.SHORT_TYPE),
createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")), createOptionalAttrDef("enum1", ts.getDataType(EnumType.class, "HiveObjectType")),
createOptionalAttrDef("e", DataTypes.INT_TYPE), createOptionalAttrDef("e", DataTypes.INT_TYPE), createOptionalAttrDef("f", DataTypes.INT_TYPE),
createOptionalAttrDef("f", DataTypes.INT_TYPE),
createOptionalAttrDef("g", DataTypes.LONG_TYPE), createOptionalAttrDef("g", DataTypes.LONG_TYPE),
createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")), createOptionalAttrDef("enum2", ts.getDataType(EnumType.class, "PrincipalType")),
createOptionalAttrDef("h", DataTypes.FLOAT_TYPE), createOptionalAttrDef("h", DataTypes.FLOAT_TYPE), createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE),
createOptionalAttrDef("i", DataTypes.DOUBLE_TYPE),
createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE), createOptionalAttrDef("j", DataTypes.BIGINTEGER_TYPE),
createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE), createOptionalAttrDef("k", DataTypes.BIGDECIMAL_TYPE),
createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")), createOptionalAttrDef("enum3", ts.getDataType(EnumType.class, "TxnState")),
createOptionalAttrDef("l", DataTypes.DATE_TYPE), createOptionalAttrDef("l", DataTypes.DATE_TYPE),
createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)), createOptionalAttrDef("m", ts.defineArrayType(DataTypes.INT_TYPE)),
createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), createOptionalAttrDef("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)),
createOptionalAttrDef("o", createOptionalAttrDef("o", ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)),
createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel"))); createOptionalAttrDef("enum4", ts.getDataType(EnumType.class, "LockLevel")));
Struct s = createStructWithEnum("t3"); Struct s = createStructWithEnum("t3");
......
...@@ -34,8 +34,7 @@ public class StructTest extends BaseTest { ...@@ -34,8 +34,7 @@ public class StructTest extends BaseTest {
public void setup() throws Exception { public void setup() throws Exception {
super.setup(); super.setup();
structType = getTypeSystem().getDataType(StructType.class, STRUCT_TYPE_1); structType = getTypeSystem().getDataType(StructType.class, STRUCT_TYPE_1);
recursiveStructType = getTypeSystem() recursiveStructType = getTypeSystem().getDataType(StructType.class, STRUCT_TYPE_2);
.getDataType(StructType.class, STRUCT_TYPE_2);
} }
@Test @Test
......
...@@ -63,15 +63,13 @@ public class TraitTest extends BaseTest { ...@@ -63,15 +63,13 @@ public class TraitTest extends BaseTest {
*/ */
@Test @Test
public void test1() throws AtlasException { public void test1() throws AtlasException {
HierarchicalTypeDefinition A = createTraitTypeDef("A", null, HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"), HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableList.<String>of("A"), HierarchicalTypeDefinition C =
createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createTraitTypeDef("C", ImmutableList.<String>of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"), HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
...@@ -79,11 +77,12 @@ public class TraitTest extends BaseTest { ...@@ -79,11 +77,12 @@ public class TraitTest extends BaseTest {
TraitType DType = (TraitType) getTypeSystem().getDataType(TraitType.class, "D"); TraitType DType = (TraitType) getTypeSystem().getDataType(TraitType.class, "D");
// for(String aName : DType.fieldMapping().fields.keySet()) { // for(String aName : DType.fieldMapping().fields.keySet()) {
// System.out.println(String.format("nameToQualifiedName.put(\"%s\", \"%s\");", aName, DType.getQualifiedName(aName))); // System.out.println(String.format("nameToQualifiedName.put(\"%s\", \"%s\");", aName, DType
// } // .getQualifiedName(aName)));
// }
Map<String,String> nameToQualifiedName = new HashMap(); Map<String, String> nameToQualifiedName = new HashMap();
{ {
nameToQualifiedName.put("d", "D.d"); nameToQualifiedName.put("d", "D.d");
nameToQualifiedName.put("b", "B.b"); nameToQualifiedName.put("b", "B.b");
...@@ -172,15 +171,13 @@ public class TraitTest extends BaseTest { ...@@ -172,15 +171,13 @@ public class TraitTest extends BaseTest {
@Test @Test
public void testRandomOrder() throws AtlasException { public void testRandomOrder() throws AtlasException {
HierarchicalTypeDefinition A = createTraitTypeDef("A", null, HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"), HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.<String>of("A"),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableList.<String>of("A"), HierarchicalTypeDefinition C =
createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createTraitTypeDef("C", ImmutableList.<String>of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"), HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
......
...@@ -51,11 +51,10 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -51,11 +51,10 @@ public class TypeInheritanceTest extends BaseTest {
*/ */
@Test @Test
public void testSimpleInheritance() throws AtlasException { public void testSimpleInheritance() throws AtlasException {
HierarchicalTypeDefinition A = createClassTypeDef("A", null, HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
createRequiredAttrDef("a", DataTypes.INT_TYPE));
HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableList.of("A"), HierarchicalTypeDefinition B =
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
defineClasses(A, B); defineClasses(A, B);
...@@ -80,12 +79,11 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -80,12 +79,11 @@ public class TypeInheritanceTest extends BaseTest {
*/ */
@Test @Test
public void testSimpleInheritanceWithOverrides() throws AtlasException { public void testSimpleInheritanceWithOverrides() throws AtlasException {
HierarchicalTypeDefinition A = createClassTypeDef("A", null, HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("b", DataTypes.BOOLEAN_TYPE)); createRequiredAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableList.of("A"), HierarchicalTypeDefinition B =
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
defineClasses(A, B); defineClasses(A, B);
...@@ -114,17 +112,16 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -114,17 +112,16 @@ public class TypeInheritanceTest extends BaseTest {
*/ */
@Test @Test
public void testMultiLevelInheritance() throws AtlasException { public void testMultiLevelInheritance() throws AtlasException {
HierarchicalTypeDefinition A = createClassTypeDef("A", null, HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
createRequiredAttrDef("a", DataTypes.INT_TYPE));
HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableList.of("A"), HierarchicalTypeDefinition B =
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createClassTypeDef("C", ImmutableList.of("B"), HierarchicalTypeDefinition C =
createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createClassTypeDef("C", ImmutableList.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createClassTypeDef("D", ImmutableList.of("C"), HierarchicalTypeDefinition D =
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createClassTypeDef("D", ImmutableList.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
defineClasses(A, B, C, D); defineClasses(A, B, C, D);
...@@ -167,17 +164,15 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -167,17 +164,15 @@ public class TypeInheritanceTest extends BaseTest {
*/ */
@Test @Test
public void testDiamondInheritance() throws AtlasException { public void testDiamondInheritance() throws AtlasException {
HierarchicalTypeDefinition A = createTraitTypeDef("A", null, HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE),
createRequiredAttrDef("a", DataTypes.INT_TYPE), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
HierarchicalTypeDefinition B = createTraitTypeDef("B", ImmutableList.of("A"),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableList.of("A"),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.of("B", "C"),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
HierarchicalTypeDefinition B =
createTraitTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C =
createTraitTypeDef("C", ImmutableList.of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D =
createTraitTypeDef("D", ImmutableList.of("B", "C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
defineTraits(A, B, C, D); defineTraits(A, B, C, D);
......
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