Commit 3cdd9f57 by Shwetha GS

ATLAS-474 Server does not start if the type is updated with same super type…

ATLAS-474 Server does not start if the type is updated with same super type class information (dkantor via shwethags)
parent 046ff52b
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.atlas.falcon.model; package org.apache.atlas.falcon.model;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.addons.ModelDefinitionDump; import org.apache.atlas.addons.ModelDefinitionDump;
...@@ -117,7 +119,7 @@ public class FalconDataModelGenerator { ...@@ -117,7 +119,7 @@ public class FalconDataModelGenerator {
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, FalconDataTypes.FALCON_PROCESS_ENTITY.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, FalconDataTypes.FALCON_PROCESS_ENTITY.getName(), null,
ImmutableList.of(AtlasClient.PROCESS_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.PROCESS_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(FalconDataTypes.FALCON_PROCESS_ENTITY.getName(), definition); classTypeDefinitions.put(FalconDataTypes.FALCON_PROCESS_ENTITY.getName(), definition);
LOG.debug("Created definition for {}", FalconDataTypes.FALCON_PROCESS_ENTITY.getName()); LOG.debug("Created definition for {}", FalconDataTypes.FALCON_PROCESS_ENTITY.getName());
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.atlas.hive.model; package org.apache.atlas.hive.model;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.addons.ModelDefinitionDump; import org.apache.atlas.addons.ModelDefinitionDump;
...@@ -212,7 +214,7 @@ public class HiveDataModelGenerator { ...@@ -212,7 +214,7 @@ public class HiveDataModelGenerator {
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_STORAGEDESC.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_STORAGEDESC.getName(), null,
ImmutableList.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(HiveDataTypes.HIVE_STORAGEDESC.getName(), definition); classTypeDefinitions.put(HiveDataTypes.HIVE_STORAGEDESC.getName(), definition);
LOG.debug("Created definition for " + HiveDataTypes.HIVE_STORAGEDESC.getName()); LOG.debug("Created definition for " + HiveDataTypes.HIVE_STORAGEDESC.getName());
} }
...@@ -247,7 +249,7 @@ public class HiveDataModelGenerator { ...@@ -247,7 +249,7 @@ public class HiveDataModelGenerator {
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_DB.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_DB.getName(), null,
ImmutableList.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(HiveDataTypes.HIVE_DB.getName(), definition); classTypeDefinitions.put(HiveDataTypes.HIVE_DB.getName(), definition);
LOG.debug("Created definition for " + HiveDataTypes.HIVE_DB.getName()); LOG.debug("Created definition for " + HiveDataTypes.HIVE_DB.getName());
} }
...@@ -274,7 +276,7 @@ public class HiveDataModelGenerator { ...@@ -274,7 +276,7 @@ public class HiveDataModelGenerator {
new AttributeDefinition(COMMENT, DataTypes.STRING_TYPE.getName(), Multiplicity.OPTIONAL, false, null),}; new AttributeDefinition(COMMENT, DataTypes.STRING_TYPE.getName(), Multiplicity.OPTIONAL, false, null),};
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_COLUMN.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_COLUMN.getName(), null,
ImmutableList.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(HiveDataTypes.HIVE_COLUMN.getName(), definition); classTypeDefinitions.put(HiveDataTypes.HIVE_COLUMN.getName(), definition);
LOG.debug("Created definition for " + HiveDataTypes.HIVE_COLUMN.getName()); LOG.debug("Created definition for " + HiveDataTypes.HIVE_COLUMN.getName());
} }
...@@ -295,7 +297,7 @@ public class HiveDataModelGenerator { ...@@ -295,7 +297,7 @@ public class HiveDataModelGenerator {
new AttributeDefinition(HiveDataModelGenerator.PARAMETERS, STRING_MAP_TYPE.getName(), Multiplicity.OPTIONAL, false, null),}; new AttributeDefinition(HiveDataModelGenerator.PARAMETERS, STRING_MAP_TYPE.getName(), Multiplicity.OPTIONAL, false, null),};
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_PARTITION.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_PARTITION.getName(), null,
ImmutableList.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.REFERENCEABLE_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(HiveDataTypes.HIVE_PARTITION.getName(), definition); classTypeDefinitions.put(HiveDataTypes.HIVE_PARTITION.getName(), definition);
LOG.debug("Created definition for " + HiveDataTypes.HIVE_PARTITION.getName()); LOG.debug("Created definition for " + HiveDataTypes.HIVE_PARTITION.getName());
} }
...@@ -329,7 +331,7 @@ public class HiveDataModelGenerator { ...@@ -329,7 +331,7 @@ public class HiveDataModelGenerator {
null),}; null),};
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_TABLE.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_TABLE.getName(), null,
ImmutableList.of("DataSet"), attributeDefinitions); ImmutableSet.of("DataSet"), attributeDefinitions);
classTypeDefinitions.put(HiveDataTypes.HIVE_TABLE.getName(), definition); classTypeDefinitions.put(HiveDataTypes.HIVE_TABLE.getName(), definition);
LOG.debug("Created definition for " + HiveDataTypes.HIVE_TABLE.getName()); LOG.debug("Created definition for " + HiveDataTypes.HIVE_TABLE.getName());
} }
...@@ -368,7 +370,7 @@ public class HiveDataModelGenerator { ...@@ -368,7 +370,7 @@ public class HiveDataModelGenerator {
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_PROCESS.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, HiveDataTypes.HIVE_PROCESS.getName(), null,
ImmutableList.of(AtlasClient.PROCESS_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.PROCESS_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(HiveDataTypes.HIVE_PROCESS.getName(), definition); classTypeDefinitions.put(HiveDataTypes.HIVE_PROCESS.getName(), definition);
LOG.debug("Created definition for " + HiveDataTypes.HIVE_PROCESS.getName()); LOG.debug("Created definition for " + HiveDataTypes.HIVE_PROCESS.getName());
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.atlas.sqoop.model; package org.apache.atlas.sqoop.model;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.addons.ModelDefinitionDump; import org.apache.atlas.addons.ModelDefinitionDump;
...@@ -131,7 +133,7 @@ public class SqoopDataModelGenerator { ...@@ -131,7 +133,7 @@ public class SqoopDataModelGenerator {
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, SqoopDataTypes.SQOOP_DBDATASTORE.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, SqoopDataTypes.SQOOP_DBDATASTORE.getName(), null,
ImmutableList.of(AtlasClient.DATA_SET_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.DATA_SET_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(SqoopDataTypes.SQOOP_DBDATASTORE.getName(), definition); classTypeDefinitions.put(SqoopDataTypes.SQOOP_DBDATASTORE.getName(), definition);
LOG.debug("Created definition for " + SqoopDataTypes.SQOOP_DBDATASTORE.getName()); LOG.debug("Created definition for " + SqoopDataTypes.SQOOP_DBDATASTORE.getName());
} }
...@@ -150,7 +152,7 @@ public class SqoopDataModelGenerator { ...@@ -150,7 +152,7 @@ public class SqoopDataModelGenerator {
HierarchicalTypeDefinition<ClassType> definition = HierarchicalTypeDefinition<ClassType> definition =
new HierarchicalTypeDefinition<>(ClassType.class, SqoopDataTypes.SQOOP_PROCESS.getName(), null, new HierarchicalTypeDefinition<>(ClassType.class, SqoopDataTypes.SQOOP_PROCESS.getName(), null,
ImmutableList.of(AtlasClient.PROCESS_SUPER_TYPE), attributeDefinitions); ImmutableSet.of(AtlasClient.PROCESS_SUPER_TYPE), attributeDefinitions);
classTypeDefinitions.put(SqoopDataTypes.SQOOP_PROCESS.getName(), definition); classTypeDefinitions.put(SqoopDataTypes.SQOOP_PROCESS.getName(), definition);
LOG.debug("Created definition for " + SqoopDataTypes.SQOOP_PROCESS.getName()); LOG.debug("Created definition for " + SqoopDataTypes.SQOOP_PROCESS.getName());
} }
......
...@@ -11,6 +11,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset ...@@ -11,6 +11,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset
ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags) ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags)
ALL CHANGES: ALL CHANGES:
ATLAS-474 Server does not start if the type is updated with same super type class information (dkantor via shwethags)
ATLAS-555 Tag creation from UI fails due to missing description attribute (guptaneeru via shwethags) ATLAS-555 Tag creation from UI fails due to missing description attribute (guptaneeru via shwethags)
ATLAS-522 Support Alter table commands (sumasai via shwethags) ATLAS-522 Support Alter table commands (sumasai via shwethags)
ATLAS-512 Decouple currently integrating components from availability of Atlas service for raising metadata events ( yhemanth via sumasai) ATLAS-512 Decouple currently integrating components from availability of Atlas service for raising metadata events ( yhemanth via sumasai)
......
...@@ -19,15 +19,18 @@ ...@@ -19,15 +19,18 @@
package org.apache.atlas.repository.typestore; package org.apache.atlas.repository.typestore;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.thinkaurelius.titan.core.TitanGraph; 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.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.GraphTransaction; import org.apache.atlas.GraphTransaction;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphHelper;
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;
import org.apache.atlas.typesystem.types.AttributeDefinition; import org.apache.atlas.typesystem.types.AttributeDefinition;
...@@ -51,8 +54,10 @@ import org.slf4j.Logger; ...@@ -51,8 +54,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
@Singleton @Singleton
public class GraphBackedTypeStore implements ITypeStore { public class GraphBackedTypeStore implements ITypeStore {
...@@ -83,7 +88,7 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -83,7 +88,7 @@ public class GraphBackedTypeStore implements ITypeStore {
case STRUCT: case STRUCT:
StructType structType = (StructType) dataType; StructType structType = (StructType) dataType;
storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), dataType.getDescription(), storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), dataType.getDescription(),
ImmutableList.copyOf(structType.infoToNameMap.keySet()), ImmutableList.<String>of()); ImmutableList.copyOf(structType.infoToNameMap.keySet()), ImmutableSet.<String>of());
break; break;
case TRAIT: case TRAIT:
...@@ -123,14 +128,12 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -123,14 +128,12 @@ public class GraphBackedTypeStore implements ITypeStore {
return PROPERTY_PREFIX + parent + "." + child; return PROPERTY_PREFIX + parent + "." + child;
} }
private String getEdgeLabel(String parent, String child) { String getEdgeLabel(String parent, String child) {
return PROPERTY_PREFIX + "edge." + parent + "." + child; return PROPERTY_PREFIX + "edge." + parent + "." + child;
} }
private void storeInGraph(TypeSystem typeSystem, DataTypes.TypeCategory category, String typeName, private void storeInGraph(TypeSystem typeSystem, DataTypes.TypeCategory category, String typeName, String typeDescription,
String typeDescription, ImmutableList<AttributeInfo> attributes, ImmutableList<AttributeInfo> attributes, ImmutableSet<String> superTypes) throws AtlasException {
ImmutableList<String> superTypes)
throws AtlasException {
Vertex vertex = createVertex(category, typeName, typeDescription); Vertex vertex = createVertex(category, typeName, typeDescription);
List<String> attrNames = new ArrayList<>(); List<String> attrNames = new ArrayList<>();
if (attributes != null) { if (attributes != null) {
...@@ -203,6 +206,15 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -203,6 +206,15 @@ public class GraphBackedTypeStore implements ITypeStore {
} }
private void addEdge(Vertex fromVertex, Vertex toVertex, String label) { private void addEdge(Vertex fromVertex, Vertex toVertex, String label) {
Iterable<Edge> edges = GraphHelper.getOutGoingEdgesByLabel(fromVertex, label);
// ATLAS-474: Check if this type system edge already exists, to avoid duplicates.
for (Edge edge : edges) {
if (edge.getVertex(Direction.IN).equals(toVertex)) {
LOG.debug("Edge from {} to {} with label {} already exists",
toString(fromVertex), toString(toVertex), label);
return;
}
}
LOG.debug("Adding edge from {} to {} with label {}", toString(fromVertex), toString(toVertex), label); LOG.debug("Adding edge from {} to {} with label {}", toString(fromVertex), toString(toVertex), label);
titanGraph.addEdge(null, fromVertex, toVertex, label); titanGraph.addEdge(null, fromVertex, toVertex, label);
} }
...@@ -236,7 +248,7 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -236,7 +248,7 @@ public class GraphBackedTypeStore implements ITypeStore {
break; break;
case CLASS: case CLASS:
ImmutableList<String> superTypes = getSuperTypes(vertex); ImmutableSet<String> superTypes = getSuperTypes(vertex);
attributes = getAttributes(vertex, typeName); attributes = getAttributes(vertex, typeName);
classTypes.add(new HierarchicalTypeDefinition(ClassType.class, typeName, typeDescription, superTypes, attributes)); classTypes.add(new HierarchicalTypeDefinition(ClassType.class, typeName, typeDescription, superTypes, attributes));
break; break;
...@@ -266,14 +278,14 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -266,14 +278,14 @@ public class GraphBackedTypeStore implements ITypeStore {
return new EnumTypeDefinition(typeName, typeDescription, enumValues.toArray(new EnumValue[enumValues.size()])); return new EnumTypeDefinition(typeName, typeDescription, enumValues.toArray(new EnumValue[enumValues.size()]));
} }
private ImmutableList<String> getSuperTypes(Vertex vertex) { private ImmutableSet<String> getSuperTypes(Vertex vertex) {
List<String> superTypes = new ArrayList<>(); Set<String> superTypes = new HashSet<>();
Iterator<Edge> edges = vertex.getEdges(Direction.OUT, SUPERTYPE_EDGE_LABEL).iterator(); Iterator<Edge> edges = vertex.getEdges(Direction.OUT, SUPERTYPE_EDGE_LABEL).iterator();
while (edges.hasNext()) { while (edges.hasNext()) {
Edge edge = edges.next(); Edge edge = edges.next();
superTypes.add((String) edge.getVertex(Direction.IN).getProperty(Constants.TYPENAME_PROPERTY_KEY)); superTypes.add((String) edge.getVertex(Direction.IN).getProperty(Constants.TYPENAME_PROPERTY_KEY));
} }
return ImmutableList.copyOf(superTypes); return ImmutableSet.copyOf(superTypes);
} }
private AttributeDefinition[] getAttributes(Vertex vertex, String typeName) throws AtlasException { private AttributeDefinition[] getAttributes(Vertex vertex, String typeName) throws AtlasException {
...@@ -302,7 +314,7 @@ public class GraphBackedTypeStore implements ITypeStore { ...@@ -302,7 +314,7 @@ public class GraphBackedTypeStore implements ITypeStore {
* @param typeName * @param typeName
* @return vertex * @return vertex
*/ */
private Vertex findVertex(DataTypes.TypeCategory category, String typeName) { Vertex findVertex(DataTypes.TypeCategory category, String typeName) {
LOG.debug("Finding vertex for {}.{}", category, typeName); LOG.debug("Finding vertex for {}.{}", category, typeName);
Iterator results = titanGraph.query().has(Constants.TYPENAME_PROPERTY_KEY, typeName).vertices().iterator(); Iterator results = titanGraph.query().has(Constants.TYPENAME_PROPERTY_KEY, typeName).vertices().iterator();
......
...@@ -20,6 +20,7 @@ package org.apache.atlas.services; ...@@ -20,6 +20,7 @@ package org.apache.atlas.services;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provider; import com.google.inject.Provider;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
...@@ -136,17 +137,17 @@ public class DefaultMetadataService implements MetadataService { ...@@ -136,17 +137,17 @@ public class DefaultMetadataService implements MetadataService {
@InterfaceAudience.Private @InterfaceAudience.Private
private void createSuperTypes() throws AtlasException { private void createSuperTypes() throws AtlasException {
HierarchicalTypeDefinition<ClassType> infraType = TypesUtil HierarchicalTypeDefinition<ClassType> infraType = TypesUtil
.createClassTypeDef(AtlasClient.INFRASTRUCTURE_SUPER_TYPE, ImmutableList.<String>of(), NAME_ATTRIBUTE, .createClassTypeDef(AtlasClient.INFRASTRUCTURE_SUPER_TYPE, ImmutableSet.<String>of(), NAME_ATTRIBUTE,
DESCRIPTION_ATTRIBUTE); DESCRIPTION_ATTRIBUTE);
createType(infraType); createType(infraType);
HierarchicalTypeDefinition<ClassType> datasetType = TypesUtil HierarchicalTypeDefinition<ClassType> datasetType = TypesUtil
.createClassTypeDef(AtlasClient.DATA_SET_SUPER_TYPE, ImmutableList.<String>of(), NAME_ATTRIBUTE, .createClassTypeDef(AtlasClient.DATA_SET_SUPER_TYPE, ImmutableSet.<String>of(), NAME_ATTRIBUTE,
DESCRIPTION_ATTRIBUTE); DESCRIPTION_ATTRIBUTE);
createType(datasetType); createType(datasetType);
HierarchicalTypeDefinition<ClassType> processType = TypesUtil HierarchicalTypeDefinition<ClassType> processType = TypesUtil
.createClassTypeDef(AtlasClient.PROCESS_SUPER_TYPE, ImmutableList.<String>of(), NAME_ATTRIBUTE, .createClassTypeDef(AtlasClient.PROCESS_SUPER_TYPE, ImmutableSet.<String>of(), NAME_ATTRIBUTE,
DESCRIPTION_ATTRIBUTE, DESCRIPTION_ATTRIBUTE,
new AttributeDefinition("inputs", DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE), new AttributeDefinition("inputs", DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE),
Multiplicity.OPTIONAL, false, null), Multiplicity.OPTIONAL, false, null),
...@@ -155,7 +156,7 @@ public class DefaultMetadataService implements MetadataService { ...@@ -155,7 +156,7 @@ public class DefaultMetadataService implements MetadataService {
createType(processType); createType(processType);
HierarchicalTypeDefinition<ClassType> referenceableType = TypesUtil HierarchicalTypeDefinition<ClassType> referenceableType = TypesUtil
.createClassTypeDef(AtlasClient.REFERENCEABLE_SUPER_TYPE, ImmutableList.<String>of(), .createClassTypeDef(AtlasClient.REFERENCEABLE_SUPER_TYPE, ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, TypesUtil.createUniqueRequiredAttrDef(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
DataTypes.STRING_TYPE)); DataTypes.STRING_TYPE));
createType(referenceableType); createType(referenceableType);
......
...@@ -19,8 +19,10 @@ package org.apache.atlas; ...@@ -19,8 +19,10 @@ package org.apache.atlas;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.util.TitanCleanup; import com.thinkaurelius.titan.core.util.TitanCleanup;
import org.apache.atlas.repository.MetadataRepository; import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer; import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.repository.graph.GraphProvider; import org.apache.atlas.repository.graph.GraphProvider;
...@@ -44,6 +46,7 @@ import org.apache.atlas.typesystem.types.utils.TypesUtil; ...@@ -44,6 +46,7 @@ import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -116,7 +119,7 @@ public class BaseHiveRepositoryTest { ...@@ -116,7 +119,7 @@ public class BaseHiveRepositoryTest {
HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil
.createClassTypeDef(HIVE_TABLE_TYPE, ImmutableList.of("DataSet"), .createClassTypeDef(HIVE_TABLE_TYPE, ImmutableSet.of("DataSet"),
attrDef("owner", DataTypes.STRING_TYPE), attrDef("owner", DataTypes.STRING_TYPE),
attrDef("createTime", DataTypes.DATE_TYPE), attrDef("createTime", DataTypes.DATE_TYPE),
attrDef("lastAccessTime", DataTypes.LONG_TYPE), attrDef("tableType", DataTypes.STRING_TYPE), attrDef("lastAccessTime", DataTypes.LONG_TYPE), attrDef("tableType", DataTypes.STRING_TYPE),
...@@ -129,7 +132,7 @@ public class BaseHiveRepositoryTest { ...@@ -129,7 +132,7 @@ public class BaseHiveRepositoryTest {
Multiplicity.COLLECTION, true, null)); Multiplicity.COLLECTION, true, null));
HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil
.createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableList.of("Process"), .createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableSet.of("Process"),
attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE), attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE),
attrDef("endTime", DataTypes.LONG_TYPE), attrDef("endTime", DataTypes.LONG_TYPE),
attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
......
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
package org.apache.atlas; package org.apache.atlas;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter; import com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter;
import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
...@@ -104,12 +106,12 @@ public final class TestUtils { ...@@ -104,12 +106,12 @@ public final class TestUtils {
createStructTypeDef("Address", "Address"+_description, createRequiredAttrDef("street", DataTypes.STRING_TYPE), createStructTypeDef("Address", "Address"+_description, createRequiredAttrDef("street", DataTypes.STRING_TYPE),
createRequiredAttrDef("city", DataTypes.STRING_TYPE)); createRequiredAttrDef("city", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", "Department"+_description, ImmutableList.<String>of(), HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", "Department"+_description, ImmutableSet.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION, new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
true, "department")); true, "department"));
HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", "Person"+_description, ImmutableList.<String>of(), HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", "Person"+_description, ImmutableSet.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
createOptionalAttrDef("orgLevel", "OrgLevel"), createOptionalAttrDef("orgLevel", "OrgLevel"),
createOptionalAttrDef("address", "Address"), createOptionalAttrDef("address", "Address"),
...@@ -117,12 +119,12 @@ public final class TestUtils { ...@@ -117,12 +119,12 @@ public final class TestUtils {
new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"), new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"),
new AttributeDefinition("mentor", "Person", Multiplicity.OPTIONAL, false, null)); new AttributeDefinition("mentor", "Person", Multiplicity.OPTIONAL, false, null));
HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager", "Manager"+_description, ImmutableList.of("Person"), HierarchicalTypeDefinition<ClassType> managerTypeDef = createClassTypeDef("Manager", "Manager"+_description, ImmutableSet.of("Person"),
new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), Multiplicity.COLLECTION, new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
false, "manager")); false, "manager"));
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableList.<String>of(), createTraitTypeDef("SecurityClearance", "SecurityClearance"+_description, ImmutableSet.<String>of(),
createRequiredAttrDef("level", DataTypes.INT_TYPE)); createRequiredAttrDef("level", DataTypes.INT_TYPE));
ts.defineTypes(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails), ts.defineTypes(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails),
...@@ -201,13 +203,13 @@ public final class TestUtils { ...@@ -201,13 +203,13 @@ public final class TestUtils {
public static TypesDef defineHiveTypes() { public static TypesDef defineHiveTypes() {
String _description = "_description"; String _description = "_description";
HierarchicalTypeDefinition<ClassType> superTypeDefinition = HierarchicalTypeDefinition<ClassType> superTypeDefinition =
createClassTypeDef(SUPER_TYPE_NAME, ImmutableList.<String>of(), createClassTypeDef(SUPER_TYPE_NAME, ImmutableSet.<String>of(),
createOptionalAttrDef("namespace", DataTypes.STRING_TYPE), createOptionalAttrDef("namespace", DataTypes.STRING_TYPE),
createOptionalAttrDef("cluster", DataTypes.STRING_TYPE), createOptionalAttrDef("cluster", DataTypes.STRING_TYPE),
createOptionalAttrDef("colo", DataTypes.STRING_TYPE)); createOptionalAttrDef("colo", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = HierarchicalTypeDefinition<ClassType> databaseTypeDefinition =
createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE + _description,ImmutableList.of(SUPER_TYPE_NAME), createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE + _description,ImmutableSet.of(SUPER_TYPE_NAME),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
createOptionalAttrDef("created", DataTypes.DATE_TYPE), createOptionalAttrDef("created", DataTypes.DATE_TYPE),
createRequiredAttrDef("description", DataTypes.STRING_TYPE)); createRequiredAttrDef("description", DataTypes.STRING_TYPE));
...@@ -223,7 +225,7 @@ public final class TestUtils { ...@@ -223,7 +225,7 @@ public final class TestUtils {
EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", "tableType" + _description, values); EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", "tableType" + _description, values);
HierarchicalTypeDefinition<ClassType> columnsDefinition = HierarchicalTypeDefinition<ClassType> columnsDefinition =
createClassTypeDef(COLUMN_TYPE, ImmutableList.<String>of(), createClassTypeDef(COLUMN_TYPE, ImmutableSet.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
createRequiredAttrDef("type", DataTypes.STRING_TYPE)); createRequiredAttrDef("type", DataTypes.STRING_TYPE));
...@@ -245,7 +247,7 @@ public final class TestUtils { ...@@ -245,7 +247,7 @@ public final class TestUtils {
HierarchicalTypeDefinition<ClassType> storageDescClsDef = HierarchicalTypeDefinition<ClassType> storageDescClsDef =
new HierarchicalTypeDefinition<>(ClassType.class, STORAGE_DESC_TYPE, STORAGE_DESC_TYPE + _description, new HierarchicalTypeDefinition<>(ClassType.class, STORAGE_DESC_TYPE, STORAGE_DESC_TYPE + _description,
ImmutableList.of(SUPER_TYPE_NAME), attributeDefinitions); ImmutableSet.of(SUPER_TYPE_NAME), attributeDefinitions);
AttributeDefinition[] partClsAttributes = new AttributeDefinition[]{ AttributeDefinition[] partClsAttributes = new AttributeDefinition[]{
new AttributeDefinition("values", DataTypes.arrayTypeName(DataTypes.STRING_TYPE.getName()), new AttributeDefinition("values", DataTypes.arrayTypeName(DataTypes.STRING_TYPE.getName()),
...@@ -263,10 +265,10 @@ public final class TestUtils { ...@@ -263,10 +265,10 @@ public final class TestUtils {
HierarchicalTypeDefinition<ClassType> partClsDef = HierarchicalTypeDefinition<ClassType> partClsDef =
new HierarchicalTypeDefinition<>(ClassType.class, "partition_class_type", "partition_class_type" + _description, new HierarchicalTypeDefinition<>(ClassType.class, "partition_class_type", "partition_class_type" + _description,
ImmutableList.of(SUPER_TYPE_NAME), partClsAttributes); ImmutableSet.of(SUPER_TYPE_NAME), partClsAttributes);
HierarchicalTypeDefinition<ClassType> tableTypeDefinition = HierarchicalTypeDefinition<ClassType> tableTypeDefinition =
createClassTypeDef(TABLE_TYPE, TABLE_TYPE + _description, ImmutableList.of(SUPER_TYPE_NAME), createClassTypeDef(TABLE_TYPE, TABLE_TYPE + _description, ImmutableSet.of(SUPER_TYPE_NAME),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
createRequiredAttrDef("description", DataTypes.STRING_TYPE), createRequiredAttrDef("description", DataTypes.STRING_TYPE),
createRequiredAttrDef("type", DataTypes.STRING_TYPE), createRequiredAttrDef("type", DataTypes.STRING_TYPE),
...@@ -306,14 +308,14 @@ public final class TestUtils { ...@@ -306,14 +308,14 @@ public final class TestUtils {
new AttributeDefinition("databaseComposite", DATABASE_TYPE, Multiplicity.OPTIONAL, true, null)); new AttributeDefinition("databaseComposite", DATABASE_TYPE, Multiplicity.OPTIONAL, true, null));
HierarchicalTypeDefinition<TraitType> piiTypeDefinition = HierarchicalTypeDefinition<TraitType> piiTypeDefinition =
createTraitTypeDef(PII, PII + _description, ImmutableList.<String>of()); createTraitTypeDef(PII, PII + _description, ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> classificationTypeDefinition = HierarchicalTypeDefinition<TraitType> classificationTypeDefinition =
createTraitTypeDef(CLASSIFICATION, CLASSIFICATION + _description, ImmutableList.<String>of(), createTraitTypeDef(CLASSIFICATION, CLASSIFICATION + _description, ImmutableSet.<String>of(),
createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> fetlClassificationTypeDefinition = HierarchicalTypeDefinition<TraitType> fetlClassificationTypeDefinition =
createTraitTypeDef("fetl" + CLASSIFICATION, "fetl" + CLASSIFICATION + _description, ImmutableList.of(CLASSIFICATION), createTraitTypeDef("fetl" + CLASSIFICATION, "fetl" + CLASSIFICATION + _description, ImmutableSet.of(CLASSIFICATION),
createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
return TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), return TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
......
...@@ -18,8 +18,9 @@ ...@@ -18,8 +18,9 @@
package org.apache.atlas.discovery; package org.apache.atlas.discovery;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import org.apache.atlas.BaseHiveRepositoryTest; import org.apache.atlas.BaseHiveRepositoryTest;
import org.apache.atlas.RepositoryMetadataModule; import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.TestUtils; import org.apache.atlas.TestUtils;
...@@ -45,6 +46,7 @@ import org.testng.annotations.Guice; ...@@ -45,6 +46,7 @@ import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -305,13 +307,13 @@ public class GraphBackedDiscoveryServiceTest extends BaseHiveRepositoryTest { ...@@ -305,13 +307,13 @@ public class GraphBackedDiscoveryServiceTest extends BaseHiveRepositoryTest {
HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE)); HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
HierarchicalTypeDefinition B = HierarchicalTypeDefinition B =
createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = HierarchicalTypeDefinition C =
createClassTypeDef("C", ImmutableList.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createClassTypeDef("C", ImmutableSet.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = HierarchicalTypeDefinition D =
createClassTypeDef("D", ImmutableList.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createClassTypeDef("D", ImmutableSet.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
TypeSystem.getInstance().defineClassTypes(A, B, C, D); TypeSystem.getInstance().defineClassTypes(A, B, C, D);
} }
......
...@@ -18,10 +18,8 @@ ...@@ -18,10 +18,8 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.util.TitanCleanup; import com.thinkaurelius.titan.core.util.TitanCleanup;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
...@@ -61,7 +59,6 @@ import javax.inject.Inject; ...@@ -61,7 +59,6 @@ import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -163,12 +160,12 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest { ...@@ -163,12 +160,12 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest {
public void testDeleteEntitiesWithCompositeMapReference() throws Exception { public void testDeleteEntitiesWithCompositeMapReference() throws Exception {
// Define type for map value. // Define type for map value.
HierarchicalTypeDefinition<ClassType> mapValueDef = TypesUtil.createClassTypeDef("CompositeMapValue", HierarchicalTypeDefinition<ClassType> mapValueDef = TypesUtil.createClassTypeDef("CompositeMapValue",
ImmutableList.<String>of(), ImmutableSet.<String>of(),
TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE)); TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE));
// Define type with map where the value is a composite class reference to MapValue. // Define type with map where the value is a composite class reference to MapValue.
HierarchicalTypeDefinition<ClassType> mapOwnerDef = TypesUtil.createClassTypeDef("CompositeMapOwner", HierarchicalTypeDefinition<ClassType> mapOwnerDef = TypesUtil.createClassTypeDef("CompositeMapOwner",
ImmutableList.<String>of(), ImmutableSet.<String>of(),
new AttributeDefinition("map", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(), new AttributeDefinition("map", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(),
"CompositeMapValue"), Multiplicity.OPTIONAL, true, null)); "CompositeMapValue"), Multiplicity.OPTIONAL, true, null));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
...@@ -342,11 +339,11 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest { ...@@ -342,11 +339,11 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest {
public void testDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes() throws Exception { public void testDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes() throws Exception {
// Define class types. // Define class types.
HierarchicalTypeDefinition<ClassType> structTargetDef = TypesUtil.createClassTypeDef("StructTarget", HierarchicalTypeDefinition<ClassType> structTargetDef = TypesUtil.createClassTypeDef("StructTarget",
ImmutableList.<String>of(), TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE)); ImmutableSet.<String>of(), TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> traitTargetDef = TypesUtil.createClassTypeDef("TraitTarget", HierarchicalTypeDefinition<ClassType> traitTargetDef = TypesUtil.createClassTypeDef("TraitTarget",
ImmutableList.<String>of(), TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE)); ImmutableSet.<String>of(), TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> structContainerDef = TypesUtil.createClassTypeDef("StructContainer", HierarchicalTypeDefinition<ClassType> structContainerDef = TypesUtil.createClassTypeDef("StructContainer",
ImmutableList.<String>of(), TypesUtil.createOptionalAttrDef("struct", "TestStruct")); ImmutableSet.<String>of(), TypesUtil.createOptionalAttrDef("struct", "TestStruct"));
// Define struct and trait types which have a unidirectional array reference // Define struct and trait types which have a unidirectional array reference
// to a class type. // to a class type.
...@@ -355,7 +352,7 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest { ...@@ -355,7 +352,7 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest {
new AttributeDefinition("nestedStructs", DataTypes.arrayTypeName("NestedStruct"), Multiplicity.OPTIONAL, false, null)); new AttributeDefinition("nestedStructs", DataTypes.arrayTypeName("NestedStruct"), Multiplicity.OPTIONAL, false, null));
StructTypeDefinition nestedStructDef = TypesUtil.createStructTypeDef("NestedStruct", StructTypeDefinition nestedStructDef = TypesUtil.createStructTypeDef("NestedStruct",
TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE)); TypesUtil.createOptionalAttrDef("attr1", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> traitDef = TypesUtil.createTraitTypeDef("TestTrait", ImmutableList.<String>of(), HierarchicalTypeDefinition<TraitType> traitDef = TypesUtil.createTraitTypeDef("TestTrait", ImmutableSet.<String>of(),
new AttributeDefinition("target", DataTypes.arrayTypeName("TraitTarget"), Multiplicity.OPTIONAL, false, null)); new AttributeDefinition("target", DataTypes.arrayTypeName("TraitTarget"), Multiplicity.OPTIONAL, false, null));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(structDef, nestedStructDef), TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(structDef, nestedStructDef),
...@@ -476,13 +473,13 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest { ...@@ -476,13 +473,13 @@ public class GraphBackedMetadataRepositoryDeleteEntitiesTest {
public void testDisconnectMapReferenceFromClassType() throws Exception { public void testDisconnectMapReferenceFromClassType() throws Exception {
// Define type for map value. // Define type for map value.
HierarchicalTypeDefinition<ClassType> mapValueDef = TypesUtil.createClassTypeDef("MapValue", HierarchicalTypeDefinition<ClassType> mapValueDef = TypesUtil.createClassTypeDef("MapValue",
ImmutableList.<String>of(), ImmutableSet.<String>of(),
new AttributeDefinition("biMapOwner", "MapOwner", Multiplicity.OPTIONAL, false, "biMap")); new AttributeDefinition("biMapOwner", "MapOwner", Multiplicity.OPTIONAL, false, "biMap"));
// Define type with unidirectional and bidirectional map references, // Define type with unidirectional and bidirectional map references,
// where the map value is a class reference to MapValue. // where the map value is a class reference to MapValue.
HierarchicalTypeDefinition<ClassType> mapOwnerDef = TypesUtil.createClassTypeDef("MapOwner", HierarchicalTypeDefinition<ClassType> mapOwnerDef = TypesUtil.createClassTypeDef("MapOwner",
ImmutableList.<String>of(), ImmutableSet.<String>of(),
new AttributeDefinition("map", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(), new AttributeDefinition("map", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(),
"MapValue"), Multiplicity.OPTIONAL, false, null), "MapValue"), Multiplicity.OPTIONAL, false, null),
new AttributeDefinition("biMap", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(), new AttributeDefinition("biMap", DataTypes.mapTypeName(DataTypes.STRING_TYPE.getName(),
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.atlas.repository.graph; package org.apache.atlas.repository.graph;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.util.TitanCleanup; import com.thinkaurelius.titan.core.util.TitanCleanup;
import com.tinkerpop.blueprints.Compare; import com.tinkerpop.blueprints.Compare;
...@@ -274,7 +275,7 @@ public class GraphBackedMetadataRepositoryTest { ...@@ -274,7 +275,7 @@ public class GraphBackedMetadataRepositoryTest {
final String traitName = "P_I_I"; final String traitName = "P_I_I";
HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
.createTraitTypeDef(traitName, ImmutableList.<String>of(), .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
TraitType traitType = typeSystem.defineTraitType(piiTrait); TraitType traitType = typeSystem.defineTraitType(piiTrait);
ITypedStruct traitInstance = traitType.createInstance(); ITypedStruct traitInstance = traitType.createInstance();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.atlas.repository.typestore; package org.apache.atlas.repository.typestore;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.util.TitanCleanup; import com.thinkaurelius.titan.core.util.TitanCleanup;
import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Direction;
...@@ -34,6 +35,7 @@ import org.apache.atlas.typesystem.TypesDef; ...@@ -34,6 +35,7 @@ import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.types.AttributeDefinition; import org.apache.atlas.typesystem.types.AttributeDefinition;
import org.apache.atlas.typesystem.types.ClassType; import org.apache.atlas.typesystem.types.ClassType;
import org.apache.atlas.typesystem.types.DataTypes; import org.apache.atlas.typesystem.types.DataTypes;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.atlas.typesystem.types.EnumType; import org.apache.atlas.typesystem.types.EnumType;
import org.apache.atlas.typesystem.types.EnumTypeDefinition; import org.apache.atlas.typesystem.types.EnumTypeDefinition;
import org.apache.atlas.typesystem.types.EnumValue; import org.apache.atlas.typesystem.types.EnumValue;
...@@ -52,6 +54,9 @@ import org.testng.annotations.Guice; ...@@ -52,6 +54,9 @@ import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -168,11 +173,11 @@ public class GraphBackedTypeStoreTest { ...@@ -168,11 +173,11 @@ public class GraphBackedTypeStoreTest {
createOptionalAttrDef("state", DataTypes.STRING_TYPE)); createOptionalAttrDef("state", DataTypes.STRING_TYPE));
//Add supertype //Add supertype
HierarchicalTypeDefinition<ClassType> superTypeDef = createClassTypeDef("Division", ImmutableList.<String>of(), HierarchicalTypeDefinition<ClassType> superTypeDef = createClassTypeDef("Division", ImmutableSet.<String>of(),
createOptionalAttrDef("dname", DataTypes.STRING_TYPE)); createOptionalAttrDef("dname", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", "Department"+_description, HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", "Department"+_description,
ImmutableList.of(superTypeDef.typeName), createRequiredAttrDef("name", DataTypes.STRING_TYPE), ImmutableSet.of(superTypeDef.typeName), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION, new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
true, "department")); true, "department"));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails), TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails),
...@@ -182,6 +187,16 @@ public class GraphBackedTypeStoreTest { ...@@ -182,6 +187,16 @@ public class GraphBackedTypeStoreTest {
Map<String, IDataType> typesAdded = ts.updateTypes(typesDef); Map<String, IDataType> typesAdded = ts.updateTypes(typesDef);
typeStore.store(ts, ImmutableList.copyOf(typesAdded.keySet())); typeStore.store(ts, ImmutableList.copyOf(typesAdded.keySet()));
// ATLAS-474: verify that type update did not write duplicate edges to the type store.
if (typeStore instanceof GraphBackedTypeStore) {
GraphBackedTypeStore gbTypeStore = (GraphBackedTypeStore) typeStore;
Vertex typeVertex = gbTypeStore.findVertex(TypeCategory.CLASS, "Department");
int edgeCount = countOutgoingEdges(typeVertex, GraphBackedTypeStore.SUPERTYPE_EDGE_LABEL);
Assert.assertEquals(edgeCount, 1);
edgeCount = countOutgoingEdges(typeVertex, gbTypeStore.getEdgeLabel("Department", "employees"));
Assert.assertEquals(edgeCount, 1, "Should only be 1 edge for employees attribute on Department type vertex");
}
//Validate the updated types //Validate the updated types
TypesDef types = typeStore.restore(); TypesDef types = typeStore.restore();
ts.reset(); ts.reset();
...@@ -204,4 +219,62 @@ public class GraphBackedTypeStoreTest { ...@@ -204,4 +219,62 @@ public class GraphBackedTypeStoreTest {
Assert.assertTrue(deptType.superTypes.contains(superTypeDef.typeName)); Assert.assertTrue(deptType.superTypes.contains(superTypeDef.typeName));
Assert.assertNotNull(ts.getDataType(ClassType.class, superTypeDef.typeName)); Assert.assertNotNull(ts.getDataType(ClassType.class, superTypeDef.typeName));
} }
@Test(dependsOnMethods = "testTypeUpdate")
public void testAddSecondSuperType() throws Exception {
// Add a second supertype to Department class
HierarchicalTypeDefinition<ClassType> superTypeDef2 = createClassTypeDef("SuperClass2", ImmutableSet.<String>of(),
createOptionalAttrDef("name", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department",
ImmutableSet.of("Division", superTypeDef2.typeName), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
true, "department"));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
ImmutableList.of(deptTypeDef, superTypeDef2));
ts.updateTypes(typesDef);
typeStore.store(ts, ImmutableList.of(superTypeDef2.typeName, deptTypeDef.typeName));
// ATLAS-474: verify that type update did not write duplicate edges to the type store.
if (typeStore instanceof GraphBackedTypeStore) {
GraphBackedTypeStore gbTypeStore = (GraphBackedTypeStore) typeStore;
Vertex typeVertex = gbTypeStore.findVertex(TypeCategory.CLASS, "Department");
// There should now be 2 super type outgoing edges on the Department type vertex.
int edgeCount = countOutgoingEdges(typeVertex, GraphBackedTypeStore.SUPERTYPE_EDGE_LABEL);
Assert.assertEquals(edgeCount, 2);
// There should still be 1 outgoing edge for the employees attribute.
edgeCount = countOutgoingEdges(typeVertex, gbTypeStore.getEdgeLabel("Department", "employees"));
Assert.assertEquals(edgeCount, 1);
}
// Verify Department now has 2 super types.
TypesDef types = typeStore.restore();
for (HierarchicalTypeDefinition<ClassType> classTypeDef : types.classTypesAsJavaList()) {
if (classTypeDef.typeName.equals("Department")) {
Assert.assertEquals(classTypeDef.superTypes.size(), 2);
Assert.assertTrue(classTypeDef.superTypes.containsAll(
Arrays.asList("Division", superTypeDef2.typeName)));
break;
}
}
ts.reset();
Map<String, IDataType> typesMap = ts.defineTypes(types);
IDataType dataType = typesMap.get(deptTypeDef.typeName);
Assert.assertTrue(dataType instanceof ClassType);
ClassType deptType = (ClassType) dataType;
Assert.assertEquals(deptType.superTypes.size(), 2);
Assert.assertTrue(deptType.superTypes.containsAll(
Arrays.asList("Division", superTypeDef2.typeName)));
}
private int countOutgoingEdges(Vertex typeVertex, String edgeLabel) {
Iterable<Edge> outGoingEdgesByLabel = GraphHelper.getOutGoingEdgesByLabel(typeVertex, edgeLabel);
int edgeCount = 0;
for (Iterator<Edge> iterator = outGoingEdgesByLabel.iterator(); iterator.hasNext();) {
iterator.next();
edgeCount++;
}
return edgeCount;
}
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.atlas.service; package org.apache.atlas.service;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.util.TitanCleanup; import com.thinkaurelius.titan.core.util.TitanCleanup;
...@@ -802,14 +803,14 @@ public class DefaultMetadataServiceTest { ...@@ -802,14 +803,14 @@ public class DefaultMetadataServiceTest {
public void testTypeUpdateWithReservedAttributes() throws AtlasException, JSONException { public void testTypeUpdateWithReservedAttributes() throws AtlasException, JSONException {
String typeName = "test_type_"+ RandomStringUtils.randomAlphanumeric(10); String typeName = "test_type_"+ RandomStringUtils.randomAlphanumeric(10);
HierarchicalTypeDefinition<ClassType> typeDef = TypesUtil.createClassTypeDef( HierarchicalTypeDefinition<ClassType> typeDef = TypesUtil.createClassTypeDef(
typeName, ImmutableList.<String>of(), typeName, ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE)); TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE));
TypesDef typesDef = new TypesDef(typeDef, false); TypesDef typesDef = new TypesDef(typeDef, false);
JSONObject type = metadataService.createType(TypesSerialization.toJson(typesDef)); JSONObject type = metadataService.createType(TypesSerialization.toJson(typesDef));
Assert.assertNotNull(type.get(AtlasClient.TYPES)); Assert.assertNotNull(type.get(AtlasClient.TYPES));
HierarchicalTypeDefinition<ClassType> updatedTypeDef = TypesUtil.createClassTypeDef( HierarchicalTypeDefinition<ClassType> updatedTypeDef = TypesUtil.createClassTypeDef(
typeName, ImmutableList.<String>of(), typeName, ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE),
TypesUtil.createOptionalAttrDef("test_type_invalid_attribute$", DataTypes.STRING_TYPE)); TypesUtil.createOptionalAttrDef("test_type_invalid_attribute$", DataTypes.STRING_TYPE));
TypesDef updatedTypesDef = new TypesDef(updatedTypeDef, false); TypesDef updatedTypesDef = new TypesDef(updatedTypeDef, false);
......
...@@ -21,6 +21,7 @@ package org.apache.atlas.typesystem.types; ...@@ -21,6 +21,7 @@ package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IReferenceableInstance;
...@@ -48,12 +49,12 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc ...@@ -48,12 +49,12 @@ public class ClassType extends HierarchicalType<ClassType, IReferenceableInstanc
public final Map<AttributeInfo, List<String>> infoToNameMap; public final Map<AttributeInfo, List<String>> infoToNameMap;
ClassType(TypeSystem typeSystem, String name, String description, ImmutableList<String> superTypes, int numFields) { ClassType(TypeSystem typeSystem, String name, String description, ImmutableSet<String> superTypes, int numFields) {
super(typeSystem, ClassType.class, name, description, superTypes, numFields); super(typeSystem, ClassType.class, name, description, superTypes, numFields);
infoToNameMap = null; infoToNameMap = null;
} }
ClassType(TypeSystem typeSystem, String name, String description, ImmutableList<String> superTypes, AttributeInfo... fields) ClassType(TypeSystem typeSystem, String name, String description, ImmutableSet<String> superTypes, AttributeInfo... fields)
throws AtlasException { throws AtlasException {
super(typeSystem, ClassType.class, name, description, superTypes, fields); super(typeSystem, ClassType.class, name, description, superTypes, fields);
infoToNameMap = TypeUtils.buildAttrInfoToNameMap(fieldMapping); infoToNameMap = TypeUtils.buildAttrInfoToNameMap(fieldMapping);
......
...@@ -20,6 +20,8 @@ package org.apache.atlas.typesystem.types; ...@@ -20,6 +20,8 @@ package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.persistence.DownCastStructInstance; import org.apache.atlas.typesystem.persistence.DownCastStructInstance;
...@@ -51,13 +53,13 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -51,13 +53,13 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
public final Class<ST> superTypeClass; public final Class<ST> superTypeClass;
public final FieldMapping fieldMapping; public final FieldMapping fieldMapping;
public final int numFields; public final int numFields;
public final ImmutableList<String> superTypes; public final ImmutableSet<String> superTypes;
public final ImmutableList<AttributeInfo> immediateAttrs; public final ImmutableList<AttributeInfo> immediateAttrs;
public final ImmutableMap<String, String> attributeNameToType; public final ImmutableMap<String, String> attributeNameToType;
protected ImmutableMap<String, List<Path>> superTypePaths; protected ImmutableMap<String, List<Path>> superTypePaths;
protected ImmutableMap<String, Path> pathNameToPathMap; protected ImmutableMap<String, Path> pathNameToPathMap;
HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, ImmutableList<String> superTypes, HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, ImmutableSet<String> superTypes,
int numFields) { int numFields) {
this(typeSystem, superTypeClass, name, null, superTypes, numFields); this(typeSystem, superTypeClass, name, null, superTypes, numFields);
} }
...@@ -65,7 +67,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -65,7 +67,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
/** /**
* Used when creating a Type, to support recursive Structs. * Used when creating a Type, to support recursive Structs.
*/ */
HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, String description, ImmutableList<String> superTypes, HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, String description, ImmutableSet<String> superTypes,
int numFields) { int numFields) {
super(name, description); super(name, description);
this.typeSystem = typeSystem; this.typeSystem = typeSystem;
...@@ -77,11 +79,11 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -77,11 +79,11 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
this.attributeNameToType = null; this.attributeNameToType = null;
} }
HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, ImmutableList<String> superTypes, HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, ImmutableSet<String> superTypes,
AttributeInfo... fields) throws AtlasException { AttributeInfo... fields) throws AtlasException {
this(typeSystem, superTypeClass, name, null, superTypes, fields); this(typeSystem, superTypeClass, name, null, superTypes, fields);
} }
HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, String description, ImmutableList<String> superTypes, HierarchicalType(TypeSystem typeSystem, Class<ST> superTypeClass, String name, String description, ImmutableSet<String> superTypes,
AttributeInfo... fields) throws AtlasException { AttributeInfo... fields) throws AtlasException {
super(name, description); super(name, description);
this.typeSystem = typeSystem; this.typeSystem = typeSystem;
...@@ -90,7 +92,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -90,7 +92,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
this.fieldMapping = p.left; this.fieldMapping = p.left;
this.attributeNameToType = p.right; this.attributeNameToType = p.right;
this.numFields = this.fieldMapping.fields.size(); this.numFields = this.fieldMapping.fields.size();
this.superTypes = superTypes == null ? ImmutableList.<String>of() : superTypes; this.superTypes = superTypes == null ? ImmutableSet.<String>of() : superTypes;
this.immediateAttrs = ImmutableList.copyOf(fields); this.immediateAttrs = ImmutableList.copyOf(fields);
} }
...@@ -136,7 +138,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -136,7 +138,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
setupSuperTypesGraph(superTypes); setupSuperTypesGraph(superTypes);
} }
private void setupSuperTypesGraph(ImmutableList<String> superTypes) throws AtlasException { private void setupSuperTypesGraph(ImmutableSet<String> superTypes) throws AtlasException {
Map<String, List<Path>> superTypePaths = new HashMap<String, List<Path>>(); Map<String, List<Path>> superTypePaths = new HashMap<String, List<Path>>();
Map<String, Path> pathNameToPathMap = new HashMap<String, Path>(); Map<String, Path> pathNameToPathMap = new HashMap<String, Path>();
Queue<Path> queue = new LinkedList<Path>(); Queue<Path> queue = new LinkedList<Path>();
...@@ -157,7 +159,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -157,7 +159,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
typePaths.add(currentPath); typePaths.add(currentPath);
} }
ImmutableList<String> sTs = superType == this ? superTypes : superType.superTypes; ImmutableSet<String> sTs = superType == this ? superTypes : superType.superTypes;
if (sTs != null) { if (sTs != null) {
for (String sT : sTs) { for (String sT : sTs) {
...@@ -171,7 +173,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -171,7 +173,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
} }
protected Pair<FieldMapping, ImmutableMap<String, String>> constructFieldMapping(ImmutableList<String> superTypes, protected Pair<FieldMapping, ImmutableMap<String, String>> constructFieldMapping(ImmutableSet<String> superTypes,
AttributeInfo... fields) throws AtlasException { AttributeInfo... fields) throws AtlasException {
Map<String, AttributeInfo> fieldsMap = new LinkedHashMap(); Map<String, AttributeInfo> fieldsMap = new LinkedHashMap();
...@@ -479,7 +481,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A ...@@ -479,7 +481,7 @@ public abstract class HierarchicalType<ST extends HierarchicalType, T> extends A
throw new RuntimeException(me); throw new RuntimeException(me);
} }
if (t.superTypes != null) { if (t.superTypes != null) {
ImmutableList<String> sTs = t.superTypes; ImmutableSet<String> sTs = t.superTypes;
for (String sT : sTs) { for (String sT : sTs) {
String nm = sT + "." + p.pathName; String nm = sT + "." + p.pathName;
pathQueue.add(pathNameToPathMap.get(nm)); pathQueue.add(pathNameToPathMap.get(nm));
......
...@@ -19,11 +19,13 @@ ...@@ -19,11 +19,13 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.classification.InterfaceAudience; import org.apache.atlas.classification.InterfaceAudience;
public class HierarchicalTypeDefinition<T extends HierarchicalType> extends StructTypeDefinition { public class HierarchicalTypeDefinition<T extends HierarchicalType> extends StructTypeDefinition {
public final ImmutableList<String> superTypes; public final ImmutableSet<String> superTypes;
public final String hierarchicalMetaTypeName; public final String hierarchicalMetaTypeName;
/** /**
...@@ -39,15 +41,15 @@ public class HierarchicalTypeDefinition<T extends HierarchicalType> extends Stru ...@@ -39,15 +41,15 @@ public class HierarchicalTypeDefinition<T extends HierarchicalType> extends Stru
@InterfaceAudience.Private @InterfaceAudience.Private
public HierarchicalTypeDefinition(String hierarchicalMetaTypeName, String typeName, String typeDescription, String[] superTypes, public HierarchicalTypeDefinition(String hierarchicalMetaTypeName, String typeName, String typeDescription, String[] superTypes,
AttributeDefinition[] attributeDefinitions) throws ClassNotFoundException { AttributeDefinition[] attributeDefinitions) throws ClassNotFoundException {
this((Class<T>) Class.forName(hierarchicalMetaTypeName), typeName, typeDescription, ImmutableList.copyOf(superTypes), this((Class<T>) Class.forName(hierarchicalMetaTypeName), typeName, typeDescription, ImmutableSet.copyOf(superTypes),
attributeDefinitions); attributeDefinitions);
} }
public HierarchicalTypeDefinition(Class<T> hierarchicalMetaType, String typeName, String typeDescription, ImmutableList<String> superTypes, public HierarchicalTypeDefinition(Class<T> hierarchicalMetaType, String typeName, String typeDescription, ImmutableSet<String> superTypes,
AttributeDefinition[] attributeDefinitions) { AttributeDefinition[] attributeDefinitions) {
super(typeName, typeDescription, false, attributeDefinitions); super(typeName, typeDescription, false, attributeDefinitions);
hierarchicalMetaTypeName = hierarchicalMetaType.getName(); hierarchicalMetaTypeName = hierarchicalMetaType.getName();
this.superTypes = superTypes == null ? ImmutableList.<String>of() : superTypes; this.superTypes = superTypes == null ? ImmutableSet.<String>of() : superTypes;
} }
@Override @Override
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.ITypedStruct;
...@@ -34,13 +35,13 @@ public class TraitType extends HierarchicalType<TraitType, IStruct> ...@@ -34,13 +35,13 @@ public class TraitType extends HierarchicalType<TraitType, IStruct>
public final Map<AttributeInfo, List<String>> infoToNameMap; public final Map<AttributeInfo, List<String>> infoToNameMap;
private final TypedStructHandler handler; private final TypedStructHandler handler;
TraitType(TypeSystem typeSystem, String name, String description, ImmutableList<String> superTraits, int numFields) { TraitType(TypeSystem typeSystem, String name, String description, ImmutableSet<String> superTraits, int numFields) {
super(typeSystem, TraitType.class, name, description, superTraits, numFields); super(typeSystem, TraitType.class, name, description, superTraits, numFields);
handler = null; handler = null;
infoToNameMap = null; infoToNameMap = null;
} }
TraitType(TypeSystem typeSystem, String name, String description, ImmutableList<String> superTraits, AttributeInfo... fields) TraitType(TypeSystem typeSystem, String name, String description, ImmutableSet<String> superTraits, AttributeInfo... fields)
throws AtlasException { throws AtlasException {
super(typeSystem, TraitType.class, name, description, superTraits, fields); super(typeSystem, TraitType.class, name, description, superTraits, fields);
handler = new TypedStructHandler(this); handler = new TypedStructHandler(this);
......
...@@ -20,7 +20,9 @@ package org.apache.atlas.typesystem.types; ...@@ -20,7 +20,9 @@ package org.apache.atlas.typesystem.types;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.classification.InterfaceAudience; import org.apache.atlas.classification.InterfaceAudience;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
...@@ -28,12 +30,12 @@ import org.apache.atlas.typesystem.exception.TypeExistsException; ...@@ -28,12 +30,12 @@ import org.apache.atlas.typesystem.exception.TypeExistsException;
import org.apache.atlas.typesystem.exception.TypeNotFoundException; import org.apache.atlas.typesystem.exception.TypeNotFoundException;
import javax.inject.Singleton; import javax.inject.Singleton;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -44,7 +46,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -44,7 +46,7 @@ import java.util.concurrent.ConcurrentHashMap;
@InterfaceAudience.Private @InterfaceAudience.Private
public class TypeSystem { public class TypeSystem {
private static final TypeSystem INSTANCE = new TypeSystem(); private static final TypeSystem INSTANCE = new TypeSystem();
private static ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal() { private static ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal<SimpleDateFormat>() {
@Override @Override
public SimpleDateFormat initialValue() { public SimpleDateFormat initialValue() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
...@@ -426,14 +428,7 @@ public class TypeSystem { ...@@ -426,14 +428,7 @@ public class TypeSystem {
private <U extends HierarchicalType> void validateSuperTypes(Class<U> cls, HierarchicalTypeDefinition<U> def) private <U extends HierarchicalType> void validateSuperTypes(Class<U> cls, HierarchicalTypeDefinition<U> def)
throws AtlasException { throws AtlasException {
Set<String> s = new HashSet<>(); for (String superTypeName : def.superTypes) {
ImmutableList<String> superTypes = def.superTypes;
for (String superTypeName : superTypes) {
if (s.contains(superTypeName)) {
throw new AtlasException(
String.format("Type %s extends superType %s multiple times", def.typeName, superTypeName));
}
IDataType dT = dataType(superTypeName); IDataType dT = dataType(superTypeName);
...@@ -448,7 +443,6 @@ public class TypeSystem { ...@@ -448,7 +443,6 @@ public class TypeSystem {
String.format("SuperType %s must be a %s, in definition of type %s", superTypeName, String.format("SuperType %s must be a %s, in definition of type %s", superTypeName,
cls.getName(), def.typeName)); cls.getName(), def.typeName));
} }
s.add(superTypeName);
} }
} }
...@@ -520,7 +514,7 @@ public class TypeSystem { ...@@ -520,7 +514,7 @@ public class TypeSystem {
} }
try { try {
Constructor<U> cons = cls.getDeclaredConstructor(TypeSystem.class, String.class, String.class, ImmutableList.class, Constructor<U> cons = cls.getDeclaredConstructor(TypeSystem.class, String.class, String.class, ImmutableSet.class,
AttributeInfo[].class); AttributeInfo[].class);
U type = cons.newInstance(this, def.typeName, def.typeDescription, def.superTypes, infos); U type = cons.newInstance(this, def.typeName, def.typeDescription, def.superTypes, infos);
transientTypes.put(def.typeName, type); transientTypes.put(def.typeName, type);
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.atlas.typesystem.types.utils; package org.apache.atlas.typesystem.types.utils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.types.AttributeDefinition; import org.apache.atlas.typesystem.types.AttributeDefinition;
import org.apache.atlas.typesystem.types.ClassType; import org.apache.atlas.typesystem.types.ClassType;
...@@ -29,6 +31,7 @@ import org.apache.atlas.typesystem.types.IDataType; ...@@ -29,6 +31,7 @@ import org.apache.atlas.typesystem.types.IDataType;
import org.apache.atlas.typesystem.types.Multiplicity; import org.apache.atlas.typesystem.types.Multiplicity;
import org.apache.atlas.typesystem.types.StructTypeDefinition; import org.apache.atlas.typesystem.types.StructTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import scala.collection.JavaConversions; import scala.collection.JavaConversions;
/** /**
...@@ -64,12 +67,12 @@ public class TypesUtil { ...@@ -64,12 +67,12 @@ public class TypesUtil {
} }
public static HierarchicalTypeDefinition<TraitType> createTraitTypeDef(String name, public static HierarchicalTypeDefinition<TraitType> createTraitTypeDef(String name,
ImmutableList<String> superTypes, AttributeDefinition... attrDefs) { ImmutableSet<String> superTypes, AttributeDefinition... attrDefs) {
return createTraitTypeDef(name, null, superTypes, attrDefs); return createTraitTypeDef(name, null, superTypes, attrDefs);
} }
public static HierarchicalTypeDefinition<TraitType> createTraitTypeDef(String name, String description, public static HierarchicalTypeDefinition<TraitType> createTraitTypeDef(String name, String description,
ImmutableList<String> superTypes, AttributeDefinition... attrDefs) { ImmutableSet<String> superTypes, AttributeDefinition... attrDefs) {
return new HierarchicalTypeDefinition<>(TraitType.class, name, description, superTypes, attrDefs); return new HierarchicalTypeDefinition<>(TraitType.class, name, description, superTypes, attrDefs);
} }
...@@ -82,12 +85,12 @@ public class TypesUtil { ...@@ -82,12 +85,12 @@ public class TypesUtil {
} }
public static HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name, public static HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name,
ImmutableList<String> superTypes, AttributeDefinition... attrDefs) { ImmutableSet<String> superTypes, AttributeDefinition... attrDefs) {
return createClassTypeDef(name, null, superTypes, attrDefs); return createClassTypeDef(name, null, superTypes, attrDefs);
} }
public static HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name, String description, public static HierarchicalTypeDefinition<ClassType> createClassTypeDef(String name, String description,
ImmutableList<String> superTypes, AttributeDefinition... attrDefs) { ImmutableSet<String> superTypes, AttributeDefinition... attrDefs) {
return new HierarchicalTypeDefinition<>(ClassType.class, name, description, superTypes, attrDefs); return new HierarchicalTypeDefinition<>(ClassType.class, name, description, superTypes, attrDefs);
} }
......
...@@ -22,10 +22,10 @@ import com.google.common.collect.ImmutableList ...@@ -22,10 +22,10 @@ import com.google.common.collect.ImmutableList
import org.apache.atlas.typesystem.TypesDef import org.apache.atlas.typesystem.TypesDef
import org.apache.atlas.typesystem.types._ import org.apache.atlas.typesystem.types._
import org.apache.atlas.typesystem.types.utils.TypesUtil import org.apache.atlas.typesystem.types.utils.TypesUtil
import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ArrayBuffer
import scala.language.{dynamics, implicitConversions, postfixOps} import scala.language.{dynamics, implicitConversions, postfixOps}
import scala.util.DynamicVariable import scala.util.DynamicVariable
import com.google.common.collect.ImmutableSet
object TypesBuilder { object TypesBuilder {
...@@ -158,14 +158,14 @@ class TypesBuilder { ...@@ -158,14 +158,14 @@ class TypesBuilder {
val attrs = new ArrayBuffer[Attr]() val attrs = new ArrayBuffer[Attr]()
context.withValue(context.value.copy(currentTypeAttrs = attrs)){f} context.withValue(context.value.copy(currentTypeAttrs = attrs)){f}
context.value.classes += context.value.classes +=
TypesUtil.createClassTypeDef(name, ImmutableList.copyOf[String](superTypes.toArray), attrs.map(_.getDef):_*) TypesUtil.createClassTypeDef(name, ImmutableSet.copyOf[String](superTypes.toArray), attrs.map(_.getDef):_*)
} }
def _trait(name : String, superTypes : List[String] = List())(f : => Unit): Unit = { def _trait(name : String, superTypes : List[String] = List())(f : => Unit): Unit = {
val attrs = new ArrayBuffer[Attr]() val attrs = new ArrayBuffer[Attr]()
context.withValue(context.value.copy(currentTypeAttrs = attrs)){f} context.withValue(context.value.copy(currentTypeAttrs = attrs)){f}
context.value.traits += context.value.traits +=
TypesUtil.createTraitTypeDef(name, ImmutableList.copyOf[String](superTypes.toArray), attrs.map(_.getDef):_*) TypesUtil.createTraitTypeDef(name, ImmutableSet.copyOf[String](superTypes.toArray), attrs.map(_.getDef):_*)
val v = context.value val v = context.value
v.traits.size v.traits.size
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.apache.atlas.typesystem.json package org.apache.atlas.typesystem.json
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableList
import org.apache.atlas.AtlasException import org.apache.atlas.AtlasException
import org.apache.atlas.typesystem.TypesDef import org.apache.atlas.typesystem.TypesDef
...@@ -28,6 +27,7 @@ import org.apache.atlas.typesystem.types._ ...@@ -28,6 +27,7 @@ import org.apache.atlas.typesystem.types._
import org.json4s.JsonAST.JString import org.json4s.JsonAST.JString
import org.json4s._ import org.json4s._
import org.json4s.native.Serialization._ import org.json4s.native.Serialization._
import com.google.common.collect.ImmutableSet
/** /**
...@@ -58,13 +58,13 @@ object TypesSerialization { ...@@ -58,13 +58,13 @@ object TypesSerialization {
def toJsonValue(typ: IDataType[_])(implicit formats: Formats): JValue = { def toJsonValue(typ: IDataType[_])(implicit formats: Formats): JValue = {
typ.getTypeCategory match { typ.getTypeCategory match {
case TypeCategory.CLASS => { case TypeCategory.CLASS => {
Extraction.decompose(convertClassTypeToHierarchicalTypeDefintion(typ.asInstanceOf[ClassType])) Extraction.decompose(convertClassTypeToHierarchicalTypeDefinition(typ.asInstanceOf[ClassType]))
} }
case TypeCategory.STRUCT => { case TypeCategory.STRUCT => {
Extraction.decompose(convertStructTypeToStructDef(typ.asInstanceOf[StructType])) Extraction.decompose(convertStructTypeToStructDef(typ.asInstanceOf[StructType]))
} }
case TypeCategory.TRAIT => { case TypeCategory.TRAIT => {
Extraction.decompose(convertTraitTypeToHierarchicalTypeDefintion(typ.asInstanceOf[TraitType])) Extraction.decompose(convertTraitTypeToHierarchicalTypeDefinition(typ.asInstanceOf[TraitType]))
} }
case TypeCategory.ENUM => { case TypeCategory.ENUM => {
Extraction.decompose(convertEnumTypeToEnumTypeDef(typ.asInstanceOf[EnumType])) Extraction.decompose(convertEnumTypeToEnumTypeDef(typ.asInstanceOf[EnumType]))
...@@ -141,14 +141,14 @@ object TypesSerialization { ...@@ -141,14 +141,14 @@ object TypesSerialization {
new StructTypeDefinition(st.name, st.description, aDefs.toArray) new StructTypeDefinition(st.name, st.description, aDefs.toArray)
} }
private def convertTraitTypeToHierarchicalTypeDefintion(tt: TraitType): HierarchicalTypeDefinition[TraitType] = { private def convertTraitTypeToHierarchicalTypeDefinition(tt: TraitType): HierarchicalTypeDefinition[TraitType] = {
val aDefs: Iterable[AttributeDefinition] = val aDefs: Iterable[AttributeDefinition] =
tt.immediateAttrs.map(convertAttributeInfoToAttributeDef(_)) tt.immediateAttrs.map(convertAttributeInfoToAttributeDef(_))
new HierarchicalTypeDefinition[TraitType](classOf[TraitType], tt.name, tt.description, tt.superTypes, aDefs.toArray) new HierarchicalTypeDefinition[TraitType](classOf[TraitType], tt.name, tt.description, tt.superTypes, aDefs.toArray)
} }
private def convertClassTypeToHierarchicalTypeDefintion(tt: ClassType): HierarchicalTypeDefinition[ClassType] = { private def convertClassTypeToHierarchicalTypeDefinition(tt: ClassType): HierarchicalTypeDefinition[ClassType] = {
val aDefs: Iterable[AttributeDefinition] = val aDefs: Iterable[AttributeDefinition] =
tt.immediateAttrs.map(convertAttributeInfoToAttributeDef(_)) tt.immediateAttrs.map(convertAttributeInfoToAttributeDef(_))
...@@ -173,8 +173,8 @@ object TypesSerialization { ...@@ -173,8 +173,8 @@ object TypesSerialization {
case typ: MapType => () case typ: MapType => ()
case typ: EnumType => enumTypes = enumTypes :+ convertEnumTypeToEnumTypeDef(typ) case typ: EnumType => enumTypes = enumTypes :+ convertEnumTypeToEnumTypeDef(typ)
case typ: StructType => structTypes = structTypes :+ convertStructTypeToStructDef(typ) case typ: StructType => structTypes = structTypes :+ convertStructTypeToStructDef(typ)
case typ: TraitType => traitTypes = traitTypes :+ convertTraitTypeToHierarchicalTypeDefintion(typ) case typ: TraitType => traitTypes = traitTypes :+ convertTraitTypeToHierarchicalTypeDefinition(typ)
case typ: ClassType => classTypes = classTypes :+ convertClassTypeToHierarchicalTypeDefintion(typ) case typ: ClassType => classTypes = classTypes :+ convertClassTypeToHierarchicalTypeDefinition(typ)
} }
TypesDef(enumTypes, structTypes, traitTypes, classTypes) TypesDef(enumTypes, structTypes, traitTypes, classTypes)
...@@ -232,7 +232,7 @@ trait TypeHelpers { ...@@ -232,7 +232,7 @@ trait TypeHelpers {
def createTraitTypeDef(name: String, description: Option[String], superTypes: Seq[String], attrDefs: AttributeDefinition*): def createTraitTypeDef(name: String, description: Option[String], superTypes: Seq[String], attrDefs: AttributeDefinition*):
HierarchicalTypeDefinition[TraitType] = { HierarchicalTypeDefinition[TraitType] = {
val sts = ImmutableList.copyOf(superTypes.toArray) val sts = ImmutableSet.copyOf(superTypes.toArray)
return new HierarchicalTypeDefinition[TraitType](classOf[TraitType], name, description.getOrElse(null), return new HierarchicalTypeDefinition[TraitType](classOf[TraitType], name, description.getOrElse(null),
sts, attrDefs.toArray) sts, attrDefs.toArray)
} }
...@@ -244,7 +244,7 @@ trait TypeHelpers { ...@@ -244,7 +244,7 @@ trait TypeHelpers {
def createClassTypeDef(name: String, description: Option[String], superTypes: Seq[String], attrDefs: AttributeDefinition*): def createClassTypeDef(name: String, description: Option[String], superTypes: Seq[String], attrDefs: AttributeDefinition*):
HierarchicalTypeDefinition[ClassType] = { HierarchicalTypeDefinition[ClassType] = {
val sts = ImmutableList.copyOf(superTypes.toArray) val sts = ImmutableSet.copyOf(superTypes.toArray)
return new HierarchicalTypeDefinition[ClassType](classOf[ClassType], name, description.getOrElse(null), return new HierarchicalTypeDefinition[ClassType](classOf[ClassType], name, description.getOrElse(null),
sts, attrDefs.toArray) sts, attrDefs.toArray)
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.atlas.typesystem.json; package org.apache.atlas.typesystem.json;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.ITypedInstance; import org.apache.atlas.typesystem.ITypedInstance;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
...@@ -63,21 +65,21 @@ public class SerializationJavaTest extends BaseTest { ...@@ -63,21 +65,21 @@ public class SerializationJavaTest extends BaseTest {
TypeSystem ts = getTypeSystem(); TypeSystem ts = getTypeSystem();
HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", ImmutableList.<String>of(), HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", ImmutableSet.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION, new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION,
true, "department")); true, "department"));
HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", ImmutableList.<String>of(), HierarchicalTypeDefinition<ClassType> personTypeDef = createClassTypeDef("Person", ImmutableSet.<String>of(),
createRequiredAttrDef("name", DataTypes.STRING_TYPE), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates")); new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"));
HierarchicalTypeDefinition<ClassType> managerTypeDef = HierarchicalTypeDefinition<ClassType> managerTypeDef =
createClassTypeDef("Manager", ImmutableList.<String>of("Person"), createClassTypeDef("Manager", ImmutableSet.<String>of("Person"),
new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
Multiplicity.COLLECTION, false, "manager")); Multiplicity.COLLECTION, false, "manager"));
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
createTraitTypeDef("SecurityClearance", ImmutableList.<String>of(), createTraitTypeDef("SecurityClearance", ImmutableSet.<String>of(),
createRequiredAttrDef("level", DataTypes.INT_TYPE)); createRequiredAttrDef("level", DataTypes.INT_TYPE));
ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
...@@ -145,7 +147,7 @@ public class SerializationJavaTest extends BaseTest { ...@@ -145,7 +147,7 @@ public class SerializationJavaTest extends BaseTest {
TypeSystem ts = getTypeSystem(); TypeSystem ts = getTypeSystem();
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef =
createTraitTypeDef("SecurityClearance2", ImmutableList.<String>of(), createTraitTypeDef("SecurityClearance2", ImmutableSet.<String>of(),
createRequiredAttrDef("level", DataTypes.INT_TYPE)); createRequiredAttrDef("level", DataTypes.INT_TYPE));
ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
......
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.Struct;
...@@ -118,22 +120,22 @@ public abstract class BaseTest { ...@@ -118,22 +120,22 @@ 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", ImmutableList.<String>of(), .createClassTypeDef("Department", ImmutableSet.<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 = TypesUtil
.createClassTypeDef("Person", ImmutableList.<String>of(), .createClassTypeDef("Person", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates")); new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"));
HierarchicalTypeDefinition<ClassType> managerTypeDef = TypesUtil HierarchicalTypeDefinition<ClassType> managerTypeDef = TypesUtil
.createClassTypeDef("Manager", ImmutableList.of("Person"), .createClassTypeDef("Manager", ImmutableSet.of("Person"),
new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
Multiplicity.COLLECTION, false, "manager")); Multiplicity.COLLECTION, false, "manager"));
HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = TypesUtil HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = TypesUtil
.createTraitTypeDef("SecurityClearance", ImmutableList.<String>of(), .createTraitTypeDef("SecurityClearance", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)); TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
......
...@@ -29,6 +29,7 @@ import org.testng.annotations.BeforeMethod; ...@@ -29,6 +29,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
public class ClassTest extends HierarchicalTypeTest<ClassType> { public class ClassTest extends HierarchicalTypeTest<ClassType> {
...@@ -78,7 +79,7 @@ public class ClassTest extends HierarchicalTypeTest<ClassType> { ...@@ -78,7 +79,7 @@ public class ClassTest extends HierarchicalTypeTest<ClassType> {
@Test @Test
public void testSerDeWithoutDescription() throws Exception { public void testSerDeWithoutDescription() throws Exception {
HierarchicalTypeDefinition<ClassType> clsType = TypesUtil HierarchicalTypeDefinition<ClassType> clsType = TypesUtil
.createClassTypeDef("Random", ImmutableList.<String>of(), .createClassTypeDef("Random", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE));
TypesDef typesDef = getTypesDef(clsType); TypesDef typesDef = getTypesDef(clsType);
...@@ -90,7 +91,7 @@ public class ClassTest extends HierarchicalTypeTest<ClassType> { ...@@ -90,7 +91,7 @@ public class ClassTest extends HierarchicalTypeTest<ClassType> {
@Test @Test
public void testSerDeWithDescription() throws Exception { public void testSerDeWithDescription() throws Exception {
HierarchicalTypeDefinition<ClassType> clsType = TypesUtil HierarchicalTypeDefinition<ClassType> clsType = TypesUtil
.createClassTypeDef("Random", "Random-description", ImmutableList.<String>of(), .createClassTypeDef("Random", "Random-description", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE));
TypesDef typesDef = getTypesDef(clsType); TypesDef typesDef = getTypesDef(clsType);
String json = TypesSerialization.toJson(typesDef); String json = TypesSerialization.toJson(typesDef);
...@@ -103,7 +104,7 @@ public class ClassTest extends HierarchicalTypeTest<ClassType> { ...@@ -103,7 +104,7 @@ public class ClassTest extends HierarchicalTypeTest<ClassType> {
} }
@Override @Override
protected HierarchicalTypeDefinition<ClassType> getTypeDefinition(String name, ImmutableList<String> superTypes, protected HierarchicalTypeDefinition<ClassType> getTypeDefinition(String name, ImmutableSet<String> superTypes,
AttributeDefinition... attributes) { AttributeDefinition... attributes) {
return new HierarchicalTypeDefinition(ClassType.class, name, null, superTypes, attributes); return new HierarchicalTypeDefinition(ClassType.class, name, null, superTypes, attributes);
} }
......
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance;
...@@ -143,7 +145,7 @@ public class EnumTest extends BaseTest { ...@@ -143,7 +145,7 @@ public class EnumTest extends BaseTest {
protected ClassType defineClassTypeWithEnum(TypeSystem ts) throws AtlasException { protected ClassType defineClassTypeWithEnum(TypeSystem ts) throws AtlasException {
return ts.defineClassType( return ts.defineClassType(
createClassTypeDef("t4", ImmutableList.<String>of(), createRequiredAttrDef("a", DataTypes.INT_TYPE), createClassTypeDef("t4", ImmutableSet.<String>of(), 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),
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.testng.Assert; import org.testng.Assert;
...@@ -38,7 +39,7 @@ public abstract class HierarchicalTypeTest<T extends HierarchicalType> extends T ...@@ -38,7 +39,7 @@ public abstract class HierarchicalTypeTest<T extends HierarchicalType> extends T
//Add super type with optional attribute //Add super type with optional attribute
HierarchicalTypeDefinition superType = HierarchicalTypeDefinition superType =
getTypeDefinition(newName(), TypesUtil.createOptionalAttrDef("s", DataTypes.INT_TYPE)); getTypeDefinition(newName(), TypesUtil.createOptionalAttrDef("s", DataTypes.INT_TYPE));
classType = getTypeDefinition(classType.typeName, ImmutableList.of(superType.typeName), classType = getTypeDefinition(classType.typeName, ImmutableSet.of(superType.typeName),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE)); TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE));
ts.updateTypes(getTypesDef(superType, classType)); ts.updateTypes(getTypesDef(superType, classType));
...@@ -47,7 +48,7 @@ public abstract class HierarchicalTypeTest<T extends HierarchicalType> extends T ...@@ -47,7 +48,7 @@ public abstract class HierarchicalTypeTest<T extends HierarchicalType> extends T
HierarchicalTypeDefinition superTypeRequired = HierarchicalTypeDefinition superTypeRequired =
getTypeDefinition(newName(), TypesUtil.createRequiredAttrDef("s", DataTypes.INT_TYPE)); getTypeDefinition(newName(), TypesUtil.createRequiredAttrDef("s", DataTypes.INT_TYPE));
classType = getTypeDefinition(classType.typeName, classType = getTypeDefinition(classType.typeName,
ImmutableList.of(superTypeRequired.typeName, superType.typeName), ImmutableSet.of(superTypeRequired.typeName, superType.typeName),
TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE)); TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE));
try { try {
ts.updateTypes(getTypesDef(superTypeRequired, classType)); ts.updateTypes(getTypesDef(superTypeRequired, classType));
...@@ -69,7 +70,7 @@ public abstract class HierarchicalTypeTest<T extends HierarchicalType> extends T ...@@ -69,7 +70,7 @@ public abstract class HierarchicalTypeTest<T extends HierarchicalType> extends T
@Override @Override
protected abstract HierarchicalTypeDefinition<T> getTypeDefinition(String name, AttributeDefinition... attributes); protected abstract HierarchicalTypeDefinition<T> getTypeDefinition(String name, AttributeDefinition... attributes);
protected abstract HierarchicalTypeDefinition<T> getTypeDefinition(String name, ImmutableList<String> superTypes, protected abstract HierarchicalTypeDefinition<T> getTypeDefinition(String name, ImmutableSet<String> superTypes,
AttributeDefinition... attributes); AttributeDefinition... attributes);
@Override @Override
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.ITypedStruct;
...@@ -68,11 +70,11 @@ public class TraitTest extends HierarchicalTypeTest<TraitType> { ...@@ -68,11 +70,11 @@ public class TraitTest extends HierarchicalTypeTest<TraitType> {
HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE), HierarchicalTypeDefinition A = createTraitTypeDef("A", null, 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", ImmutableSet.<String>of("A"),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = HierarchicalTypeDefinition C =
createTraitTypeDef("C", ImmutableList.<String>of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createTraitTypeDef("C", ImmutableSet.<String>of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"), HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableSet.<String>of("B", "C"),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
defineTraits(A, B, C, D); defineTraits(A, B, C, D);
...@@ -176,11 +178,11 @@ public class TraitTest extends HierarchicalTypeTest<TraitType> { ...@@ -176,11 +178,11 @@ public class TraitTest extends HierarchicalTypeTest<TraitType> {
HierarchicalTypeDefinition A = createTraitTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE), HierarchicalTypeDefinition A = createTraitTypeDef("A", null, 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", ImmutableSet.<String>of("A"),
createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableList.<String>of("A"), HierarchicalTypeDefinition C = createTraitTypeDef("C", ImmutableSet.<String>of("A"),
createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableList.<String>of("B", "C"), HierarchicalTypeDefinition D = createTraitTypeDef("D", ImmutableSet.<String>of("B", "C"),
createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
defineTraits(B, D, A, C); defineTraits(B, D, A, C);
...@@ -224,7 +226,7 @@ public class TraitTest extends HierarchicalTypeTest<TraitType> { ...@@ -224,7 +226,7 @@ public class TraitTest extends HierarchicalTypeTest<TraitType> {
} }
@Override @Override
protected HierarchicalTypeDefinition<TraitType> getTypeDefinition(String name, ImmutableList<String> superTypes, protected HierarchicalTypeDefinition<TraitType> getTypeDefinition(String name, ImmutableSet<String> superTypes,
AttributeDefinition... attributes) { AttributeDefinition... attributes) {
return new HierarchicalTypeDefinition(TraitType.class, name, null, superTypes, attributes); return new HierarchicalTypeDefinition(TraitType.class, name, null, superTypes, attributes);
} }
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedInstance; import org.apache.atlas.typesystem.ITypedInstance;
...@@ -54,7 +55,7 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -54,7 +55,7 @@ public class TypeInheritanceTest extends BaseTest {
HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE)); HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
HierarchicalTypeDefinition B = HierarchicalTypeDefinition B =
createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
defineClasses(A, B); defineClasses(A, B);
...@@ -83,7 +84,7 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -83,7 +84,7 @@ public class TypeInheritanceTest extends BaseTest {
createRequiredAttrDef("b", DataTypes.BOOLEAN_TYPE)); createRequiredAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition B = HierarchicalTypeDefinition B =
createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
defineClasses(A, B); defineClasses(A, B);
...@@ -115,13 +116,13 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -115,13 +116,13 @@ public class TypeInheritanceTest extends BaseTest {
HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE)); HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
HierarchicalTypeDefinition B = HierarchicalTypeDefinition B =
createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = HierarchicalTypeDefinition C =
createClassTypeDef("C", ImmutableList.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createClassTypeDef("C", ImmutableSet.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = HierarchicalTypeDefinition D =
createClassTypeDef("D", ImmutableList.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createClassTypeDef("D", ImmutableSet.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
defineClasses(A, B, C, D); defineClasses(A, B, C, D);
...@@ -168,11 +169,11 @@ public class TypeInheritanceTest extends BaseTest { ...@@ -168,11 +169,11 @@ public class TypeInheritanceTest extends BaseTest {
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 = HierarchicalTypeDefinition B =
createTraitTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); createTraitTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
HierarchicalTypeDefinition C = HierarchicalTypeDefinition C =
createTraitTypeDef("C", ImmutableList.of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); createTraitTypeDef("C", ImmutableSet.of("A"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
HierarchicalTypeDefinition D = HierarchicalTypeDefinition D =
createTraitTypeDef("D", ImmutableList.of("B", "C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); createTraitTypeDef("D", ImmutableSet.of("B", "C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
defineTraits(A, B, C, D); defineTraits(A, B, C, D);
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
...@@ -26,9 +28,12 @@ import org.testng.Assert; ...@@ -26,9 +28,12 @@ import org.testng.Assert;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import scala.actors.threadpool.Arrays; import scala.actors.threadpool.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef; import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef; import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createStructTypeDef; import static org.apache.atlas.typesystem.types.utils.TypesUtil.createStructTypeDef;
...@@ -68,7 +73,7 @@ public class TypeSystemTest extends BaseTest { ...@@ -68,7 +73,7 @@ public class TypeSystemTest extends BaseTest {
typeName = "trait_type"; typeName = "trait_type";
typeDescription = typeName + description; typeDescription = typeName + description;
HierarchicalTypeDefinition<TraitType> trait = TypesUtil HierarchicalTypeDefinition<TraitType> trait = TypesUtil
.createTraitTypeDef(typeName, typeDescription, ImmutableList.<String>of(), .createTraitTypeDef(typeName, typeDescription, ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
getTypeSystem().defineTraitType(trait); getTypeSystem().defineTraitType(trait);
Assert.assertTrue(getTypeSystem().getTypeNames().contains(typeName)); Assert.assertTrue(getTypeSystem().getTypeNames().contains(typeName));
...@@ -79,7 +84,7 @@ public class TypeSystemTest extends BaseTest { ...@@ -79,7 +84,7 @@ public class TypeSystemTest extends BaseTest {
typeName = "class_type"; typeName = "class_type";
typeDescription = typeName + description; typeDescription = typeName + description;
HierarchicalTypeDefinition<ClassType> classType = TypesUtil HierarchicalTypeDefinition<ClassType> classType = TypesUtil
.createClassTypeDef(typeName, typeDescription, ImmutableList.<String>of(), .createClassTypeDef(typeName, typeDescription, ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
getTypeSystem().defineClassType(classType); getTypeSystem().defineClassType(classType);
Assert.assertTrue(getTypeSystem().getTypeNames().contains(typeName)); Assert.assertTrue(getTypeSystem().getTypeNames().contains(typeName));
...@@ -107,20 +112,20 @@ public class TypeSystemTest extends BaseTest { ...@@ -107,20 +112,20 @@ public class TypeSystemTest extends BaseTest {
@Test @Test
public void testGetTraitsNames() throws Exception { public void testGetTraitsNames() throws Exception {
HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil
.createTraitTypeDef("Classification", ImmutableList.<String>of(), .createTraitTypeDef("Classification", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> piiTrait = HierarchicalTypeDefinition<TraitType> piiTrait =
TypesUtil.createTraitTypeDef("PII", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("PII", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> phiTrait = HierarchicalTypeDefinition<TraitType> phiTrait =
TypesUtil.createTraitTypeDef("PHI", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("PHI", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> pciTrait = HierarchicalTypeDefinition<TraitType> pciTrait =
TypesUtil.createTraitTypeDef("PCI", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("PCI", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> soxTrait = HierarchicalTypeDefinition<TraitType> soxTrait =
TypesUtil.createTraitTypeDef("SOX", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("SOX", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> secTrait = HierarchicalTypeDefinition<TraitType> secTrait =
TypesUtil.createTraitTypeDef("SEC", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("SEC", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> financeTrait = HierarchicalTypeDefinition<TraitType> financeTrait =
TypesUtil.createTraitTypeDef("Finance", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("Finance", ImmutableSet.<String>of());
getTypeSystem().defineTypes(ImmutableList.<EnumTypeDefinition>of(), getTypeSystem().defineTypes(ImmutableList.<EnumTypeDefinition>of(),
ImmutableList.<StructTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
...@@ -152,11 +157,11 @@ public class TypeSystemTest extends BaseTest { ...@@ -152,11 +157,11 @@ public class TypeSystemTest extends BaseTest {
createStructTypeDef(structName, createRequiredAttrDef(attrType, DataTypes.STRING_TYPE)); createStructTypeDef(structName, createRequiredAttrDef(attrType, DataTypes.STRING_TYPE));
String className = random(); String className = random();
HierarchicalTypeDefinition<ClassType> classType = createClassTypeDef(className, ImmutableList.<String>of(), HierarchicalTypeDefinition<ClassType> classType = createClassTypeDef(className, ImmutableSet.<String>of(),
createRequiredAttrDef(attrType, DataTypes.STRING_TYPE)); createRequiredAttrDef(attrType, DataTypes.STRING_TYPE));
String traitName = random(); String traitName = random();
HierarchicalTypeDefinition<TraitType> traitType = createTraitTypeDef(traitName, ImmutableList.<String>of(), HierarchicalTypeDefinition<TraitType> traitType = createTraitTypeDef(traitName, ImmutableSet.<String>of(),
createRequiredAttrDef(attrType, DataTypes.INT_TYPE)); createRequiredAttrDef(attrType, DataTypes.INT_TYPE));
ts.defineTypes(ImmutableList.of(orgLevelEnum), ImmutableList.of(structType), ts.defineTypes(ImmutableList.of(orgLevelEnum), ImmutableList.of(structType),
...@@ -165,9 +170,9 @@ public class TypeSystemTest extends BaseTest { ...@@ -165,9 +170,9 @@ public class TypeSystemTest extends BaseTest {
@Test @Test
public void testHierarchy() throws AtlasException { public void testHierarchy() throws AtlasException {
HierarchicalTypeDefinition<ClassType> a = TypesUtil.createClassTypeDef("a", ImmutableList.<String>of()); HierarchicalTypeDefinition<ClassType> a = TypesUtil.createClassTypeDef("a", ImmutableSet.<String>of());
HierarchicalTypeDefinition<ClassType> b = TypesUtil.createClassTypeDef("B", ImmutableList.of("a")); HierarchicalTypeDefinition<ClassType> b = TypesUtil.createClassTypeDef("B", ImmutableSet.of("a"));
HierarchicalTypeDefinition<ClassType> c = TypesUtil.createClassTypeDef("C", ImmutableList.of("B")); HierarchicalTypeDefinition<ClassType> c = TypesUtil.createClassTypeDef("C", ImmutableSet.of("B"));
TypeSystem ts = getTypeSystem(); TypeSystem ts = getTypeSystem();
ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
...@@ -192,18 +197,18 @@ public class TypeSystemTest extends BaseTest { ...@@ -192,18 +197,18 @@ public class TypeSystemTest extends BaseTest {
HierarchicalTypeDefinition<TraitType> trait_A = createTraitTypeDef("trait_A", null, HierarchicalTypeDefinition<TraitType> trait_A = createTraitTypeDef("trait_A", null,
createRequiredAttrDef("t_A", DataTypes.STRING_TYPE)); createRequiredAttrDef("t_A", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> trait_B = createTraitTypeDef("trait_B", ImmutableList.<String>of("trait_A"), HierarchicalTypeDefinition<TraitType> trait_B = createTraitTypeDef("trait_B", ImmutableSet.<String>of("trait_A"),
createRequiredAttrDef("t_B", DataTypes.STRING_TYPE)); createRequiredAttrDef("t_B", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> trait_C = createTraitTypeDef("trait_C", ImmutableList.<String>of("trait_A"), HierarchicalTypeDefinition<TraitType> trait_C = createTraitTypeDef("trait_C", ImmutableSet.<String>of("trait_A"),
createRequiredAttrDef("t_C", DataTypes.STRING_TYPE)); createRequiredAttrDef("t_C", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> trait_D = createTraitTypeDef("trait_D", ImmutableList.<String>of("trait_B", "trait_C"), HierarchicalTypeDefinition<TraitType> trait_D = createTraitTypeDef("trait_D", ImmutableSet.<String>of("trait_B", "trait_C"),
createRequiredAttrDef("t_D", DataTypes.STRING_TYPE)); createRequiredAttrDef("t_D", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> class_A = createClassTypeDef("class_A", null, HierarchicalTypeDefinition<ClassType> class_A = createClassTypeDef("class_A", null,
createRequiredAttrDef("c_A", DataTypes.STRING_TYPE)); createRequiredAttrDef("c_A", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> class_B = createClassTypeDef("class_B", ImmutableList.<String>of("class_A"), HierarchicalTypeDefinition<ClassType> class_B = createClassTypeDef("class_B", ImmutableSet.<String>of("class_A"),
createRequiredAttrDef("c_B", DataTypes.STRING_TYPE)); createRequiredAttrDef("c_B", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> class_C = createClassTypeDef("class_C", ImmutableList.<String>of("class_B"), HierarchicalTypeDefinition<ClassType> class_C = createClassTypeDef("class_C", ImmutableSet.<String>of("class_B"),
createRequiredAttrDef("c_C", DataTypes.STRING_TYPE)); createRequiredAttrDef("c_C", DataTypes.STRING_TYPE));
ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(struct_A, struct_B), ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(struct_A, struct_B),
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
package org.apache.atlas.typesystem.types; package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
...@@ -74,14 +76,14 @@ public class ValidationTest { ...@@ -74,14 +76,14 @@ public class ValidationTest {
public void testClassType(String name) { public void testClassType(String name) {
AttributeDefinition value = TypesUtil.createRequiredAttrDef("name", "type"); AttributeDefinition value = TypesUtil.createRequiredAttrDef("name", "type");
; ;
TypesUtil.createClassTypeDef(name, ImmutableList.of("super"), value); TypesUtil.createClassTypeDef(name, ImmutableSet.of("super"), value);
} }
@Test(dataProvider = "classTypeData", expectedExceptions = {IllegalArgumentException.class}) @Test(dataProvider = "classTypeData", expectedExceptions = {IllegalArgumentException.class})
public void testTraitType(String name) { public void testTraitType(String name) {
AttributeDefinition value = TypesUtil.createRequiredAttrDef("name", "type"); AttributeDefinition value = TypesUtil.createRequiredAttrDef("name", "type");
; ;
TypesUtil.createTraitTypeDef(name, ImmutableList.of("super"), value); TypesUtil.createTraitTypeDef(name, ImmutableSet.of("super"), value);
} }
@Test @Test
...@@ -89,15 +91,15 @@ public class ValidationTest { ...@@ -89,15 +91,15 @@ public class ValidationTest {
AttributeDefinition attribute = TypesUtil.createRequiredAttrDef("name", "type"); AttributeDefinition attribute = TypesUtil.createRequiredAttrDef("name", "type");
//class with no attributes //class with no attributes
TypesUtil.createClassTypeDef("name", ImmutableList.of("super")); TypesUtil.createClassTypeDef("name", ImmutableSet.of("super"));
//class with no super types //class with no super types
TypesUtil.createClassTypeDef("name", ImmutableList.<String>of(), attribute); TypesUtil.createClassTypeDef("name", ImmutableSet.<String>of(), attribute);
//trait with no attributes //trait with no attributes
TypesUtil.createTraitTypeDef("name", ImmutableList.of("super")); TypesUtil.createTraitTypeDef("name", ImmutableSet.of("super"));
//trait with no super types //trait with no super types
TypesUtil.createTraitTypeDef("name", ImmutableList.<String>of(), attribute); TypesUtil.createTraitTypeDef("name", ImmutableSet.<String>of(), attribute);
} }
} }
...@@ -28,6 +28,7 @@ import org.json4s.native.Serialization.{write => swrite, _} ...@@ -28,6 +28,7 @@ import org.json4s.native.Serialization.{write => swrite, _}
import org.json4s.{NoTypeHints, _} import org.json4s.{NoTypeHints, _}
import org.testng.Assert import org.testng.Assert
import org.testng.annotations.{BeforeMethod,Test} import org.testng.annotations.{BeforeMethod,Test}
import com.google.common.collect.ImmutableSet
class SerializationTest extends BaseTest { class SerializationTest extends BaseTest {
...@@ -81,13 +82,13 @@ class SerializationTest extends BaseTest { ...@@ -81,13 +82,13 @@ class SerializationTest extends BaseTest {
TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE), TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE),
TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE)) TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE))
val B: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef( val B: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef(
"B", ImmutableList.of[String]("A"), "B", ImmutableSet.of[String]("A"),
TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)) TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE))
val C: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef( val C: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef(
"C", ImmutableList.of[String]("A"), "C", ImmutableSet.of[String]("A"),
TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE)) TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE))
val D: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef( val D: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef(
"D", ImmutableList.of[String]("B", "C"), "D", ImmutableSet.of[String]("B", "C"),
TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE)) TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE))
defineTraits(A, B, C, D) defineTraits(A, B, C, D)
...@@ -130,21 +131,21 @@ class SerializationTest extends BaseTest { ...@@ -130,21 +131,21 @@ class SerializationTest extends BaseTest {
def defineHRTypes(ts: TypeSystem) : Unit = { def defineHRTypes(ts: TypeSystem) : Unit = {
val deptTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef( val deptTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef(
"Department", "Department",
ImmutableList.of[String], ImmutableSet.of[String],
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"))
val personTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef( val personTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef(
"Person", ImmutableList.of[String], "Person", ImmutableSet.of[String],
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"),
new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates")) new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates"))
val managerTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef( val managerTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef(
"Manager", ImmutableList.of[String]("Person"), "Manager", ImmutableSet.of[String]("Person"),
new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), new AttributeDefinition("subordinates", String.format("array<%s>", "Person"),
Multiplicity.COLLECTION, false, "manager")) Multiplicity.COLLECTION, false, "manager"))
val securityClearanceTypeDef: HierarchicalTypeDefinition[TraitType] = val securityClearanceTypeDef: HierarchicalTypeDefinition[TraitType] =
TypesUtil.createTraitTypeDef("SecurityClearance", ImmutableList.of[String], TypesUtil.createTraitTypeDef("SecurityClearance", ImmutableSet.of[String],
TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)) TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE))
ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition], ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition],
......
...@@ -20,6 +20,8 @@ package org.apache.atlas.examples; ...@@ -20,6 +20,8 @@ package org.apache.atlas.examples;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
...@@ -37,7 +39,6 @@ import org.apache.atlas.typesystem.types.IDataType; ...@@ -37,7 +39,6 @@ import org.apache.atlas.typesystem.types.IDataType;
import org.apache.atlas.typesystem.types.Multiplicity; import org.apache.atlas.typesystem.types.Multiplicity;
import org.apache.atlas.typesystem.types.StructTypeDefinition; import org.apache.atlas.typesystem.types.StructTypeDefinition;
import org.apache.atlas.typesystem.types.TraitType; import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.TypeUtils;
import org.apache.atlas.typesystem.types.utils.TypesUtil; import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
...@@ -143,7 +144,7 @@ public class QuickStart { ...@@ -143,7 +144,7 @@ public class QuickStart {
attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE)); attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil
.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableList.of("DataSet"), .createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableSet.of("DataSet"),
new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null),
new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null), new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null),
attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE),
...@@ -155,7 +156,7 @@ public class QuickStart { ...@@ -155,7 +156,7 @@ public class QuickStart {
Multiplicity.COLLECTION, true, null)); Multiplicity.COLLECTION, true, null));
HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil
.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, ImmutableList.of("Process"), .createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, ImmutableSet.of("Process"),
attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE), attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE),
attrDef("endTime", DataTypes.LONG_TYPE), attrDef("endTime", DataTypes.LONG_TYPE),
attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
......
...@@ -18,10 +18,11 @@ ...@@ -18,10 +18,11 @@
package org.apache.atlas.notification; package org.apache.atlas.notification;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.notification.entity.EntityNotification; import org.apache.atlas.notification.entity.EntityNotification;
import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.IStruct;
...@@ -42,6 +43,7 @@ import org.testng.annotations.Test; ...@@ -42,6 +43,7 @@ import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -181,7 +183,7 @@ public class EntityNotificationIT extends BaseResourceIT { ...@@ -181,7 +183,7 @@ public class EntityNotificationIT extends BaseResourceIT {
private void createTrait(String traitName, String ... superTraitNames) throws Exception { private void createTrait(String traitName, String ... superTraitNames) throws Exception {
HierarchicalTypeDefinition<TraitType> trait = HierarchicalTypeDefinition<TraitType> trait =
TypesUtil.createTraitTypeDef(traitName, ImmutableList.copyOf(superTraitNames)); TypesUtil.createTraitTypeDef(traitName, ImmutableSet.copyOf(superTraitNames));
String traitDefinitionJSON = TypesSerialization$.MODULE$.toJson(trait, true); String traitDefinitionJSON = TypesSerialization$.MODULE$.toJson(trait, true);
LOG.debug("Trait definition = " + traitDefinitionJSON); LOG.debug("Trait definition = " + traitDefinitionJSON);
......
...@@ -20,11 +20,14 @@ package org.apache.atlas.web.resources; ...@@ -20,11 +20,14 @@ package org.apache.atlas.web.resources;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig;
import kafka.consumer.ConsumerTimeoutException; import kafka.consumer.ConsumerTimeoutException;
import org.apache.atlas.ApplicationProperties; import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
...@@ -62,6 +65,7 @@ import org.testng.annotations.BeforeClass; ...@@ -62,6 +65,7 @@ import org.testng.annotations.BeforeClass;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import java.util.List; import java.util.List;
/** /**
...@@ -158,7 +162,7 @@ public abstract class BaseResourceIT { ...@@ -158,7 +162,7 @@ public abstract class BaseResourceIT {
EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", values); EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", values);
HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil
.createClassTypeDef(HIVE_TABLE_TYPE, ImmutableList.of("DataSet"), .createClassTypeDef(HIVE_TABLE_TYPE, ImmutableSet.of("DataSet"),
attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE),
attrDef("lastAccessTime", DataTypes.DATE_TYPE), attrDef("lastAccessTime", DataTypes.DATE_TYPE),
attrDef("temporary", DataTypes.BOOLEAN_TYPE), attrDef("temporary", DataTypes.BOOLEAN_TYPE),
...@@ -170,7 +174,7 @@ public abstract class BaseResourceIT { ...@@ -170,7 +174,7 @@ public abstract class BaseResourceIT {
new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null)); new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null));
HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil
.createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableList.of("Process"), .createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableSet.of("Process"),
attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.INT_TYPE), attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.INT_TYPE),
attrDef("endTime", DataTypes.LONG_TYPE), attrDef("endTime", DataTypes.LONG_TYPE),
attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
...@@ -179,20 +183,20 @@ public abstract class BaseResourceIT { ...@@ -179,20 +183,20 @@ public abstract class BaseResourceIT {
attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED)); attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED));
HierarchicalTypeDefinition<TraitType> classificationTrait = TypesUtil HierarchicalTypeDefinition<TraitType> classificationTrait = TypesUtil
.createTraitTypeDef("classification", ImmutableList.<String>of(), .createTraitTypeDef("classification", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> piiTrait = HierarchicalTypeDefinition<TraitType> piiTrait =
TypesUtil.createTraitTypeDef("pii", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("pii", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> phiTrait = HierarchicalTypeDefinition<TraitType> phiTrait =
TypesUtil.createTraitTypeDef("phi", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("phi", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> pciTrait = HierarchicalTypeDefinition<TraitType> pciTrait =
TypesUtil.createTraitTypeDef("pci", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("pci", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> soxTrait = HierarchicalTypeDefinition<TraitType> soxTrait =
TypesUtil.createTraitTypeDef("sox", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("sox", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> secTrait = HierarchicalTypeDefinition<TraitType> secTrait =
TypesUtil.createTraitTypeDef("sec", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> financeTrait = HierarchicalTypeDefinition<TraitType> financeTrait =
TypesUtil.createTraitTypeDef("finance", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDefinition),
ImmutableList.of(structTypeDefinition), ImmutableList.of(structTypeDefinition),
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
...@@ -190,7 +191,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -190,7 +191,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testEntityDefinitionAcrossTypeUpdate() throws Exception { public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
//create type //create type
HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil
.createClassTypeDef(randomString(), ImmutableList.<String>of(), .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE));
serviceClient.createType(TypesSerialization.toJson(typeDefinition, false)); serviceClient.createType(TypesSerialization.toJson(typeDefinition, false));
...@@ -200,7 +201,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -200,7 +201,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String guid = serviceClient.createEntity(instance).getString(0); String guid = serviceClient.createEntity(instance).getString(0);
//update type - add attribute //update type - add attribute
typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, ImmutableList.<String>of(), typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE)); TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE));
TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
...@@ -423,7 +424,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -423,7 +424,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private String addNewType() throws Exception { private String addNewType() throws Exception {
String typeName = "test" + randomString(); String typeName = "test" + randomString();
HierarchicalTypeDefinition<ClassType> testTypeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> testTypeDefinition = TypesUtil
.createClassTypeDef(typeName, ImmutableList.<String>of(), .createClassTypeDef(typeName, ImmutableSet.<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));
...@@ -455,7 +456,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -455,7 +456,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testAddTrait() throws Exception { public void testAddTrait() throws Exception {
traitName = "PII_Trait" + randomString(); traitName = "PII_Trait" + randomString();
HierarchicalTypeDefinition<TraitType> piiTrait = HierarchicalTypeDefinition<TraitType> piiTrait =
TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of()); TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true); String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON); LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON);
createType(traitDefinitionAsJSON); createType(traitDefinitionAsJSON);
...@@ -499,7 +500,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -499,7 +500,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testAddTraitWithAttribute() throws Exception { public void testAddTraitWithAttribute() throws Exception {
final String traitName = "PII_Trait" + randomString(); final String traitName = "PII_Trait" + randomString();
HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
.createTraitTypeDef(traitName, ImmutableList.<String>of(), .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true); String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON); LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON);
...@@ -544,7 +545,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -544,7 +545,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testAddTraitWithNoRegistration() throws Exception { public void testAddTraitWithNoRegistration() throws Exception {
final String traitName = "PII_Trait" + randomString(); final String traitName = "PII_Trait" + randomString();
HierarchicalTypeDefinition<TraitType> piiTrait = HierarchicalTypeDefinition<TraitType> piiTrait =
TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of()); TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true); String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON); LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON);
...@@ -601,7 +602,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -601,7 +602,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
final String guid = tableId._getId(); final String guid = tableId._getId();
final String traitName = "PII_Trait" + randomString(); final String traitName = "PII_Trait" + randomString();
HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
.createTraitTypeDef(traitName, ImmutableList.<String>of(), .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true); String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
createType(traitDefinitionAsJSON); createType(traitDefinitionAsJSON);
...@@ -632,7 +633,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -632,7 +633,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String attrValue = random(); String attrValue = random();
HierarchicalTypeDefinition<ClassType> classTypeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> classTypeDefinition = TypesUtil
.createClassTypeDef(classType, ImmutableList.<String>of(), .createClassTypeDef(classType, ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef(attrName, DataTypes.STRING_TYPE)); TypesUtil.createUniqueRequiredAttrDef(attrName, DataTypes.STRING_TYPE));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
......
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.typesystem.Referenceable; import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct; import org.apache.atlas.typesystem.Struct;
...@@ -42,6 +44,7 @@ import org.testng.annotations.Test; ...@@ -42,6 +44,7 @@ import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
/** /**
...@@ -155,25 +158,25 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT { ...@@ -155,25 +158,25 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
private void createTypes() throws Exception { private void createTypes() throws Exception {
HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil
.createClassTypeDef("dsl_test_type", ImmutableList.<String>of(), .createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil
.createTraitTypeDef("Classification", ImmutableList.<String>of(), .createTraitTypeDef("Classification", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE)); TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> piiTrait = HierarchicalTypeDefinition<TraitType> piiTrait =
TypesUtil.createTraitTypeDef("PII_TYPE", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("PII_TYPE", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> phiTrait = HierarchicalTypeDefinition<TraitType> phiTrait =
TypesUtil.createTraitTypeDef("PHI", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("PHI", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> pciTrait = HierarchicalTypeDefinition<TraitType> pciTrait =
TypesUtil.createTraitTypeDef("PCI", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("PCI", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> soxTrait = HierarchicalTypeDefinition<TraitType> soxTrait =
TypesUtil.createTraitTypeDef("SOX", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("SOX", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> secTrait = HierarchicalTypeDefinition<TraitType> secTrait =
TypesUtil.createTraitTypeDef("SEC", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("SEC", ImmutableSet.<String>of());
HierarchicalTypeDefinition<TraitType> financeTrait = HierarchicalTypeDefinition<TraitType> financeTrait =
TypesUtil.createTraitTypeDef("Finance", ImmutableList.<String>of()); TypesUtil.createTraitTypeDef("Finance", ImmutableSet.<String>of());
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
ImmutableList ImmutableList
......
...@@ -19,8 +19,10 @@ ...@@ -19,8 +19,10 @@
package org.apache.atlas.web.resources; package org.apache.atlas.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasClient;
import org.apache.atlas.typesystem.TypesDef; import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.json.TypesSerialization; import org.apache.atlas.typesystem.json.TypesSerialization;
...@@ -44,6 +46,7 @@ import org.testng.annotations.Test; ...@@ -44,6 +46,7 @@ import org.testng.annotations.Test;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -92,7 +95,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -92,7 +95,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testUpdate() throws Exception { public void testUpdate() throws Exception {
HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil
.createClassTypeDef(randomString(), ImmutableList.<String>of(), .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE));
List<String> typesCreated = serviceClient.createType(TypesSerialization.toJson(typeDefinition, false)); List<String> typesCreated = serviceClient.createType(TypesSerialization.toJson(typeDefinition, false));
Assert.assertEquals(typesCreated.size(), 1); Assert.assertEquals(typesCreated.size(), 1);
...@@ -100,11 +103,11 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -100,11 +103,11 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
//Add super type //Add super type
HierarchicalTypeDefinition<ClassType> superTypeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> superTypeDefinition = TypesUtil
.createClassTypeDef(randomString(), ImmutableList.<String>of(), .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
TypesUtil.createOptionalAttrDef("sname", DataTypes.STRING_TYPE)); TypesUtil.createOptionalAttrDef("sname", DataTypes.STRING_TYPE));
typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName,
ImmutableList.of(superTypeDefinition.typeName), ImmutableSet.of(superTypeDefinition.typeName),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE)); TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE));
TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
...@@ -206,7 +209,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -206,7 +209,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
for (String traitName : traitNames) { for (String traitName : traitNames) {
HierarchicalTypeDefinition<TraitType> traitTypeDef = HierarchicalTypeDefinition<TraitType> traitTypeDef =
TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of()); TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
String json = TypesSerialization$.MODULE$.toJson(traitTypeDef, true); String json = TypesSerialization$.MODULE$.toJson(traitTypeDef, true);
createType(json); createType(json);
} }
...@@ -218,13 +221,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -218,13 +221,13 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>(); ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>();
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil
.createClassTypeDef("database", ImmutableList.<String>of(), .createClassTypeDef("database", ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("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 HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil
.createClassTypeDef("table", ImmutableList.<String>of(), .createClassTypeDef("table", ImmutableSet.<String>of(),
TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE),
TypesUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)), TypesUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)),
...@@ -236,7 +239,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -236,7 +239,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
typeDefinitions.add(tableTypeDefinition); typeDefinitions.add(tableTypeDefinition);
HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil
.createTraitTypeDef("fetl", ImmutableList.<String>of(), .createTraitTypeDef("fetl", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)); TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
typeDefinitions.add(fetlTypeDefinition); typeDefinitions.add(fetlTypeDefinition);
......
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