/** * Create an instance of {@link TransientTypeSystem} with the types defined in the {@link TypesDef}. * * As part of this, a set of verifications are run on the types defined. * @param typesDef The new list of types to be created or updated. * @param isUpdate True, if types are updated, false otherwise. * @return {@link TransientTypeSystem} that holds the newly added types. * @throws AtlasException */ public TransientTypeSystem createTransientTypeSystem(TypesDef typesDef, boolean isUpdate) throws AtlasException { ImmutableList<EnumTypeDefinition> enumDefs = ImmutableList.copyOf(typesDef.enumTypesAsJavaList()); ImmutableList<StructTypeDefinition> structDefs = ImmutableList.copyOf(typesDef.structTypesAsJavaList()); ImmutableList<HierarchicalTypeDefinition<TraitType>> traitDefs = ImmutableList.copyOf(typesDef.traitTypesAsJavaList()); ImmutableList<HierarchicalTypeDefinition<ClassType>> classDefs = ImmutableList.copyOf(typesDef.classTypesAsJavaList()); TransientTypeSystem transientTypeSystem = new TransientTypeSystem(enumDefs, structDefs, traitDefs, classDefs); transientTypeSystem.verifyTypes(isUpdate); return transientTypeSystem; }
private <U extends HierarchicalType> U constructHierarchicalType(Class<U> cls, HierarchicalTypeDefinition<U> def) throws AtlasException { AttributeInfo[] infos = new AttributeInfo[def.attributeDefinitions.length]; for (int i = 0; i < def.attributeDefinitions.length; i++) { infos[i] = constructAttributeInfo(def.attributeDefinitions[i]); } try { Constructor<U> cons = cls.getDeclaredConstructor(TypeSystem.class, String.class, String.class, String.class, ImmutableSet.class, AttributeInfo[].class); U type = cons.newInstance(this, def.typeName, def.typeDescription, def.typeVersion, def.superTypes, infos); transientTypes.put(def.typeName, type); return type; } catch (Exception e) { e.printStackTrace(); throw new AtlasException(String.format("Cannot construct Type of MetaType %s - %s", cls.getName(), def.typeName), e); } }
private void orderAndConstructTypes() throws AtlasException { List<TraitType> traitTypes = new ArrayList<>(); for (String traitTypeName : traitNameToDefMap.keySet()) { traitTypes.add(getDataType(TraitType.class, traitTypeName)); } traitTypes = HierarchicalTypeDependencySorter.sortTypes(traitTypes); List<ClassType> classTypes = new ArrayList<>(); for (String classTypeName : classNameToDefMap.keySet()) { classTypes.add(getDataType(ClassType.class, classTypeName)); } classTypes = HierarchicalTypeDependencySorter.sortTypes(classTypes); for (StructTypeDefinition structDef : structDefs) { constructStructureType(structDef); } for (TraitType traitType : traitTypes) { constructHierarchicalType(TraitType.class, traitNameToDefMap.get(traitType.getName())); } for (ClassType classType : classTypes) { constructHierarchicalType(ClassType.class, classNameToDefMap.get(classType.getName())); } }
@Override public IDataType getDataType(String name) throws AtlasException { if (transientTypes != null) { if (transientTypes.containsKey(name)) { return transientTypes.get(name); } /* * is this an Array Type? */ String arrElemType = TypeUtils.parseAsArrayType(name); if (arrElemType != null) { IDataType dT = defineArrayType(getDataType(IDataType.class, arrElemType)); return dT; } /* * is this a Map Type? */ String[] mapType = TypeUtils.parseAsMapType(name); if (mapType != null) { IDataType dT = defineMapType(getDataType(IDataType.class, mapType[0]), getDataType(IDataType.class, mapType[1])); return dT; } } return TypeSystem.this.getDataType(name); }
@Override public IDataType getDataType(String name) throws AtlasException { if (transientTypes != null) { if (transientTypes.containsKey(name)) { return transientTypes.get(name); } /* * is this an Array Type? */ String arrElemType = TypeUtils.parseAsArrayType(name); if (arrElemType != null) { IDataType dT = defineArrayType(getDataType(IDataType.class, arrElemType)); return dT; } /* * is this a Map Type? */ String[] mapType = TypeUtils.parseAsMapType(name); if (mapType != null) { IDataType dT = defineMapType(getDataType(IDataType.class, mapType[0]), getDataType(IDataType.class, mapType[1])); return dT; } } return TypeSystem.this.getDataType(name); }
private void orderAndConstructTypes() throws AtlasException { List<TraitType> traitTypes = new ArrayList<>(); for (String traitTypeName : traitNameToDefMap.keySet()) { traitTypes.add(getDataType(TraitType.class, traitTypeName)); } traitTypes = HierarchicalTypeDependencySorter.sortTypes(traitTypes); List<ClassType> classTypes = new ArrayList<>(); for (String classTypeName : classNameToDefMap.keySet()) { classTypes.add(getDataType(ClassType.class, classTypeName)); } classTypes = HierarchicalTypeDependencySorter.sortTypes(classTypes); for (StructTypeDefinition structDef : structDefs) { constructStructureType(structDef); } for (TraitType traitType : traitTypes) { constructHierarchicalType(TraitType.class, traitNameToDefMap.get(traitType.getName())); } for (ClassType classType : classTypes) { constructHierarchicalType(ClassType.class, classNameToDefMap.get(classType.getName())); } }
/** * Create an instance of {@link TransientTypeSystem} with the types defined in the {@link TypesDef}. * * As part of this, a set of verifications are run on the types defined. * @param typesDef The new list of types to be created or updated. * @param isUpdate True, if types are updated, false otherwise. * @return {@link TransientTypeSystem} that holds the newly added types. * @throws AtlasException */ public TransientTypeSystem createTransientTypeSystem(TypesDef typesDef, boolean isUpdate) throws AtlasException { ImmutableList<EnumTypeDefinition> enumDefs = ImmutableList.copyOf(typesDef.enumTypesAsJavaList()); ImmutableList<StructTypeDefinition> structDefs = ImmutableList.copyOf(typesDef.structTypesAsJavaList()); ImmutableList<HierarchicalTypeDefinition<TraitType>> traitDefs = ImmutableList.copyOf(typesDef.traitTypesAsJavaList()); ImmutableList<HierarchicalTypeDefinition<ClassType>> classDefs = ImmutableList.copyOf(typesDef.classTypesAsJavaList()); TransientTypeSystem transientTypeSystem = new TransientTypeSystem(enumDefs, structDefs, traitDefs, classDefs); transientTypeSystem.verifyTypes(isUpdate); return transientTypeSystem; }
private <U extends HierarchicalType> void validateSuperTypes(Class<U> cls, HierarchicalTypeDefinition<U> def) throws AtlasException { for (String superTypeName : def.superTypes) { IDataType dT = dataType(superTypeName); if (dT == null) { throw new AtlasException( String.format("Unknown superType %s in definition of type %s", superTypeName, def.typeName)); } if (!cls.isAssignableFrom(dT.getClass())) { throw new AtlasException( String.format("SuperType %s must be a %s, in definition of type %s", superTypeName, cls.getName(), def.typeName)); } } }
private <U extends HierarchicalType> U constructHierarchicalType(Class<U> cls, HierarchicalTypeDefinition<U> def) throws AtlasException { AttributeInfo[] infos = new AttributeInfo[def.attributeDefinitions.length]; for (int i = 0; i < def.attributeDefinitions.length; i++) { infos[i] = constructAttributeInfo(def.attributeDefinitions[i]); } try { Constructor<U> cons = cls.getDeclaredConstructor(TypeSystem.class, String.class, String.class, String.class, ImmutableSet.class, AttributeInfo[].class); U type = cons.newInstance(this, def.typeName, def.typeDescription, def.typeVersion, def.superTypes, infos); transientTypes.put(def.typeName, type); return type; } catch (Exception e) { e.printStackTrace(); throw new AtlasException(String.format("Cannot construct Type of MetaType %s - %s", cls.getName(), def.typeName), e); } }
private <U extends HierarchicalType> void validateSuperTypes(Class<U> cls, HierarchicalTypeDefinition<U> def) throws AtlasException { for (String superTypeName : def.superTypes) { IDataType dT = dataType(superTypeName); if (dT == null) { throw new AtlasException( String.format("Unknown superType %s in definition of type %s", superTypeName, def.typeName)); } if (!cls.isAssignableFrom(dT.getClass())) { throw new AtlasException( String.format("SuperType %s must be a %s, in definition of type %s", superTypeName, cls.getName(), def.typeName)); } } }
private void setupRecursiveTypes() throws AtlasException { for (AttributeInfo info : recursiveRefs) { info.setDataType(dataType(info.dataType().getName())); } for (DataTypes.ArrayType arrType : recursiveArrayTypes) { arrType.setElemType(dataType(arrType.getElemType().getName())); } for (DataTypes.MapType mapType : recursiveMapTypes) { mapType.setKeyType(dataType(mapType.getKeyType().getName())); mapType.setValueType(dataType(mapType.getValueType().getName())); } }
private StructType constructStructureType(StructTypeDefinition def) throws AtlasException { AttributeInfo[] infos = new AttributeInfo[def.attributeDefinitions.length]; for (int i = 0; i < def.attributeDefinitions.length; i++) { infos[i] = constructAttributeInfo(def.attributeDefinitions[i]); } StructType type = new StructType(this, def.typeName, def.typeDescription, def.typeVersion, infos); transientTypes.put(def.typeName, type); return type; }
public Map<String, IDataType> defineTypes(ImmutableList<EnumTypeDefinition> enumDefs, ImmutableList<StructTypeDefinition> structDefs, ImmutableList<HierarchicalTypeDefinition<TraitType>> traitDefs, ImmutableList<HierarchicalTypeDefinition<ClassType>> classDefs) throws AtlasException { TransientTypeSystem transientTypes = new TransientTypeSystem(enumDefs, structDefs, traitDefs, classDefs); return transientTypes.defineTypes(false); }
Map<String, IDataType> defineTypes(boolean update) throws AtlasException { verifyTypes(update); Map<String, IDataType> typesAdded = getTypesAdded(); commitTypes(typesAdded); return typesAdded; }
public Map<String, IDataType> updateTypes(TypesDef typesDef) throws AtlasException { ImmutableList<EnumTypeDefinition> enumDefs = ImmutableList.copyOf(typesDef.enumTypesAsJavaList()); ImmutableList<StructTypeDefinition> structDefs = ImmutableList.copyOf(typesDef.structTypesAsJavaList()); ImmutableList<HierarchicalTypeDefinition<TraitType>> traitDefs = ImmutableList.copyOf(typesDef.traitTypesAsJavaList()); ImmutableList<HierarchicalTypeDefinition<ClassType>> classDefs = ImmutableList.copyOf(typesDef.classTypesAsJavaList()); TransientTypeSystem transientTypes = new TransientTypeSystem(enumDefs, structDefs, traitDefs, classDefs); return transientTypes.defineTypes(true); }
public Map<String, IDataType> defineTraitTypes(HierarchicalTypeDefinition<TraitType>... traitDefs) throws AtlasException { TransientTypeSystem transientTypes = new TransientTypeSystem(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.copyOf(traitDefs), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); return transientTypes.defineTypes(false); }
private void validateAndSetupSuperTypes() throws AtlasException { for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) { validateSuperTypes(TraitType.class, traitDef); TraitType traitType = getDataType(TraitType.class, traitDef.typeName); traitType.setupSuperTypesGraph(); } for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) { validateSuperTypes(ClassType.class, classDef); ClassType classType = getDataType(ClassType.class, classDef.typeName); classType.setupSuperTypesGraph(); } }
private void setupRecursiveTypes() throws AtlasException { for (AttributeInfo info : recursiveRefs) { info.setDataType(dataType(info.dataType().getName())); } for (DataTypes.ArrayType arrType : recursiveArrayTypes) { arrType.setElemType(dataType(arrType.getElemType().getName())); } for (DataTypes.MapType mapType : recursiveMapTypes) { mapType.setKeyType(dataType(mapType.getKeyType().getName())); mapType.setValueType(dataType(mapType.getValueType().getName())); } }
public Map<String, IDataType> defineTraitTypes(HierarchicalTypeDefinition<TraitType>... traitDefs) throws AtlasException { TransientTypeSystem transientTypes = new TransientTypeSystem(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.copyOf(traitDefs), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); return transientTypes.defineTypes(false); }
private void validateAndSetupSuperTypes() throws AtlasException { for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) { validateSuperTypes(TraitType.class, traitDef); TraitType traitType = getDataType(TraitType.class, traitDef.typeName); traitType.setupSuperTypesGraph(); } for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) { validateSuperTypes(ClassType.class, classDef); ClassType classType = getDataType(ClassType.class, classDef.typeName); classType.setupSuperTypesGraph(); } }