use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class MemRepository method defineTypes.
public void defineTypes(List<HierarchicalType> types) throws RepositoryException {
List<TraitType> tTypes = new ArrayList<>();
List<ClassType> cTypes = new ArrayList<>();
for (HierarchicalType h : types) {
if (h.getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
tTypes.add((TraitType) h);
} else {
cTypes.add((ClassType) h);
}
}
tTypes = HierarchicalTypeDependencySorter.sortTypes(tTypes);
cTypes = HierarchicalTypeDependencySorter.sortTypes(cTypes);
for (TraitType tT : tTypes) {
defineTrait(tT);
}
for (ClassType cT : cTypes) {
defineClass(cT);
}
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class EntityDiscoveryJerseyResourceIT method createTypes.
private void createTypes() throws Exception {
HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil.createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil.createTraitTypeDef("Classification", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(classificationTraitDefinition), ImmutableList.of(dslTestTypeDefinition));
createType(typesDef);
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphHelper method getCompositeVertices.
/**
* Get the GUIDs and vertices for all composite entities owned/contained by the specified root entity AtlasVertex.
* The graph is traversed from the root entity through to the leaf nodes of the containment graph.
*
* @param entityVertex the root entity vertex
* @return set of VertexInfo for all composite entities
* @throws AtlasException
*/
public Set<VertexInfo> getCompositeVertices(AtlasVertex entityVertex) throws AtlasException {
Set<VertexInfo> result = new HashSet<>();
Stack<AtlasVertex> vertices = new Stack<>();
vertices.push(entityVertex);
while (vertices.size() > 0) {
AtlasVertex vertex = vertices.pop();
String typeName = GraphHelper.getTypeName(vertex);
String guid = GraphHelper.getGuid(vertex);
Id.EntityState state = GraphHelper.getState(vertex);
if (state == Id.EntityState.DELETED) {
//If the reference vertex is marked for deletion, skip it
continue;
}
result.add(new VertexInfo(guid, vertex, typeName));
ClassType classType = typeSystem.getDataType(ClassType.class, typeName);
for (AttributeInfo attributeInfo : classType.fieldMapping().fields.values()) {
if (!attributeInfo.isComposite) {
continue;
}
String edgeLabel = GraphHelper.getEdgeLabel(classType, attributeInfo);
switch(attributeInfo.dataType().getTypeCategory()) {
case CLASS:
AtlasEdge edge = getEdgeForLabel(vertex, edgeLabel);
if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
AtlasVertex compositeVertex = edge.getInVertex();
vertices.push(compositeVertex);
}
break;
case ARRAY:
IDataType elementType = ((DataTypes.ArrayType) attributeInfo.dataType()).getElemType();
DataTypes.TypeCategory elementTypeCategory = elementType.getTypeCategory();
if (elementTypeCategory != TypeCategory.CLASS) {
continue;
}
Iterator<AtlasEdge> edges = getOutGoingEdgesByLabel(vertex, edgeLabel);
if (edges != null) {
while (edges.hasNext()) {
edge = edges.next();
if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
AtlasVertex compositeVertex = edge.getInVertex();
vertices.push(compositeVertex);
}
}
}
break;
case MAP:
DataTypes.MapType mapType = (DataTypes.MapType) attributeInfo.dataType();
DataTypes.TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
if (valueTypeCategory != TypeCategory.CLASS) {
continue;
}
String propertyName = GraphHelper.getQualifiedFieldName(classType, attributeInfo.name);
List<String> keys = vertex.getProperty(propertyName, List.class);
if (keys != null) {
for (String key : keys) {
String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
edge = getEdgeForLabel(vertex, mapEdgeLabel);
if (edge != null && GraphHelper.getState(edge) == Id.EntityState.ACTIVE) {
AtlasVertex compositeVertex = edge.getInVertex();
vertices.push(compositeVertex);
}
}
}
break;
default:
}
}
}
return result;
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class GraphToTypedInstanceMapper method mapGraphToTypedInstance.
public ITypedReferenceableInstance mapGraphToTypedInstance(String guid, AtlasVertex instanceVertex) throws AtlasException {
if (LOG.isDebugEnabled()) {
//place to add a check to see if there are any places that were missed.
if (RequestContext.get().getInstanceV1(guid) != null) {
LOG.warn("Looking up previously cached guid at: ", new Exception());
}
LOG.debug("Mapping graph root vertex {} to typed instance for guid {}", instanceVertex, guid);
}
String typeName = GraphHelper.getSingleValuedProperty(instanceVertex, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class);
List<String> traits = GraphHelper.getTraitNames(instanceVertex);
String state = GraphHelper.getStateAsString(instanceVertex);
String createdBy = GraphHelper.getCreatedByAsString(instanceVertex);
String modifiedBy = GraphHelper.getModifiedByAsString(instanceVertex);
Date createdTime = new Date(GraphHelper.getCreatedTime(instanceVertex));
Date modifiedTime = new Date(GraphHelper.getModifiedTime(instanceVertex));
AtlasSystemAttributes systemAttributes = new AtlasSystemAttributes(createdBy, modifiedBy, createdTime, modifiedTime);
if (LOG.isDebugEnabled()) {
LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime);
}
Id id = new Id(guid, Integer.parseInt(String.valueOf(GraphHelper.getProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY))), typeName, state);
if (LOG.isDebugEnabled()) {
LOG.debug("Created id {} for instance type {}", id, typeName);
}
ClassType classType = typeSystem.getDataType(ClassType.class, typeName);
ITypedReferenceableInstance typedInstance = classType.createInstance(id, systemAttributes, traits.toArray(new String[traits.size()]));
mapVertexToInstance(instanceVertex, typedInstance, classType.fieldMapping().fields);
mapVertexToInstanceTraits(instanceVertex, typedInstance, traits);
RequestContext.get().cache(typedInstance);
return typedInstance;
}
use of org.apache.atlas.typesystem.types.ClassType in project incubator-atlas by apache.
the class StoreBackedTypeCacheTest method testGetClassType.
@Test
public void testGetClassType() throws Exception {
for (Map.Entry<String, ClassType> typeEntry : classTypesToTest.entrySet()) {
// Not cached yet
Assert.assertFalse(typeCache.isCachedInMemory(typeEntry.getKey()));
IDataType dataType = ts.getDataType(IDataType.class, typeEntry.getKey());
// Verify the type is now cached.
Assert.assertTrue(typeCache.isCachedInMemory(typeEntry.getKey()));
Assert.assertTrue(dataType instanceof ClassType);
ClassType cachedType = (ClassType) dataType;
// Verify that get() also loaded and cached any dependencies of this type from the type store.
verifyHierarchicalType(cachedType, typeEntry.getValue());
}
}
Aggregations