use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class DefaultMetadataService method createOrUpdateTypes.
private JSONObject createOrUpdateTypes(OperationType opType, String typeDefinition, boolean isUpdate) throws AtlasException {
typeDefinition = ParamChecker.notEmpty(typeDefinition, "type definition");
TypesDef typesDef = validateTypeDefinition(opType, typeDefinition);
try {
final TypeSystem.TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(typesDef, isUpdate);
final Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
try {
/* Create indexes first so that if index creation fails then we rollback
the typesystem and also do not persist the graph
*/
if (isUpdate) {
onTypesUpdated(typesAdded);
} else {
onTypesAdded(typesAdded);
}
typeStore.store(transientTypeSystem, ImmutableList.copyOf(typesAdded.keySet()));
typeSystem.commitTypes(typesAdded);
} catch (Throwable t) {
throw new AtlasException("Unable to persist types ", t);
}
return new JSONObject() {
{
put(AtlasClient.TYPES, typesAdded.keySet());
}
};
} catch (JSONException e) {
LOG.error("Unable to create response for types={}", typeDefinition, e);
throw new AtlasException("Unable to create response ", e);
}
}
use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class DefaultMetadataService method onChange.
@Override
public void onChange(ChangedTypeDefs changedTypeDefs) throws AtlasBaseException {
// All we need here is a restore of the type-system
LOG.info("TypeSystem reset invoked by TypeRegistry changes");
try {
TypesDef typesDef = typeStore.restore();
typeSystem.reset();
TypeSystem.TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(typesDef, false);
Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
LOG.info("Number of types got from transient type system: {}", typesAdded.size());
typeSystem.commitTypes(typesAdded);
} catch (AtlasException e) {
LOG.error("Failed to restore type-system after TypeRegistry changes", e);
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
}
}
use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class StoreBackedTypeCache method onTypeFault.
/**
* Check the type store for the requested type.
* If found in the type store, the type and any required super and attribute types
* are loaded from the type store, and added to the cache.
*/
@Override
public IDataType onTypeFault(String typeName) throws AtlasException {
// Type is not cached - check the type store.
// Any super and attribute types needed by the requested type
// which are not cached will also be loaded from the store.
Context context = new Context();
TypesDef typesDef = getTypeFromStore(typeName, context);
if (typesDef.isEmpty()) {
// Type not found in the type store.
return null;
}
// Add all types that were loaded from the store to the cache.
TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(context.getTypesDef(), false);
Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded();
putAll(typesAdded.values());
return typesAdded.get(typeName);
}
use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class DefaultMetadataService method restoreTypeSystem.
private void restoreTypeSystem() throws AtlasException {
LOG.info("Restoring type system from the store");
TypesDef typesDef = typeStore.restore();
refreshCache(typesDef);
LOG.info("Restored type system from the store");
}
use of org.apache.atlas.typesystem.TypesDef in project incubator-atlas by apache.
the class ClassTest method testSerDeWithDescription.
@Test
public void testSerDeWithDescription() throws Exception {
HierarchicalTypeDefinition<ClassType> clsType = TypesUtil.createClassTypeDef("Random", "Random-description", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE));
TypesDef typesDef = getTypesDef(clsType);
String json = TypesSerialization.toJson(typesDef);
System.out.println("json " + json);
TypesSerialization.fromJson(json);
}
Aggregations