use of com.emc.storageos.db.client.model.UpgradeAllowed in project coprhd-controller by CoprHD.
the class MigrationHandlerImpl method generateDefaultMigrationCallbacks.
/**
* Determines the default migration callbacks for a class and field and returns a list of handlers
*
* @param annotationTypes
* @return
*/
private List<BaseDefaultMigrationCallback> generateDefaultMigrationCallbacks(List<AnnotationType> annotationTypes) {
List<BaseDefaultMigrationCallback> callbacks = new ArrayList<BaseDefaultMigrationCallback>();
for (AnnotationType annoType : annotationTypes) {
Class<? extends Annotation> annoClass = annoType.getAnnoClass();
if (annoClass.isAnnotationPresent(UpgradeAllowed.class)) {
UpgradeAllowed upgrAnno = annoClass.getAnnotation(UpgradeAllowed.class);
Class<? extends BaseDefaultMigrationCallback> callback = upgrAnno.migrationCallback();
// skip geo migration callback
if (callback == GeoDbMigrationCallback.class) {
log.info("skip geo db migration callback:{} since we don't support it now", callback.getCanonicalName());
continue;
}
String className = annoType.getCfClass().getCanonicalName();
String fieldName = annoType.getFieldName();
String annotationType = annoType.getType();
try {
BaseDefaultMigrationCallback callbackInst = callback.newInstance();
callbackInst.setName(String.format("%s:%s:%s:%s", callback.getSimpleName(), className, fieldName, annotationType));
callbackInst.setCfClass(annoType.getCfClass());
callbackInst.setFieldName(annoType.getFieldName());
callbackInst.setAnnotation(annoType.getAnnotation());
callbackInst.setInternalDbClient(dbClient);
callbacks.add(callbackInst);
} catch (InstantiationException e) {
log.error("Failed to generate default migration callback ", e);
throw DatabaseException.fatals.failedDuringUpgrade("Failed for new index " + annotationType + " on " + className + "." + fieldName, e);
} catch (IllegalAccessException e) {
log.error("Failed to generate default migration callback ", e);
throw DatabaseException.fatals.failedDuringUpgrade("Failed for new index " + annotationType + " on " + className + "." + fieldName, e);
}
}
}
// Sort callbacks to determine execution order
Collections.sort(callbacks, new Comparator<BaseDefaultMigrationCallback>() {
@Override
public int compare(BaseDefaultMigrationCallback obj1, BaseDefaultMigrationCallback obj2) {
return obj1.getName().compareTo(obj2.getName());
}
});
log.info("Get default migration callbacks in the following order {}", getCallbackNames(callbacks).toString());
return callbacks;
}
Aggregations