use of com.emc.storageos.db.common.schema.AnnotationType in project coprhd-controller by CoprHD.
the class CollectionChangeTracker method isUpgradable.
public boolean isUpgradable() {
boolean returnVal = true;
if (!removedList.isEmpty()) {
for (T schema : removedList) {
// CustomMigrationCallback can be removed
if (clazz.equals(AnnotationType.class)) {
AnnotationType at = (AnnotationType) schema;
// type associated with it. Do string comparison instead.
if (CustomMigrationCallback.class.getCanonicalName().equals(at.getType())) {
log.info("CustomMigrationCallback {} has been removed", at.describe());
continue;
} else if (EnumType.class.getCanonicalName().equals(at.getType())) {
log.info("EnumType {} has been removed", at.describe());
continue;
}
if (at.canBeIgnore()) {
continue;
}
}
log.warn("An unsupported schema change has been made. {} has been removed.", schema.describe());
returnVal = false;
}
}
if (!duplicateList.isEmpty()) {
for (T schema : duplicateList) {
log.warn("An unsupported schema change has been made. Duplicate {} has been added", schema.describe());
}
returnVal = false;
}
for (S diff : diffs) {
if (!diff.isUpgradable()) {
returnVal = false;
}
}
if (clazz.equals(AnnotationType.class)) {
for (T element : newList) {
AnnotationType at = (AnnotationType) element;
Class cfClass = at.getCfClass();
// refuse adding any annotation (including index) on existing field
if (cfClass.isAnnotationPresent(DbKeyspace.class)) {
DbKeyspace keyspaceType = (DbKeyspace) cfClass.getAnnotation(DbKeyspace.class);
if (DbKeyspace.Keyspaces.GLOBAL.equals(keyspaceType.value())) {
log.warn("An unsupported geo schema change has been made. {} has been added", at.describe());
returnVal = false;
break;
}
}
// check UpgradeAllowed annotation for new annotations
if (!CustomMigrationCallback.class.isAssignableFrom(at.getAnnoClass()) && !at.getAnnoClass().isAnnotationPresent(UpgradeAllowed.class)) {
log.warn("An unsupported schema change has been made. {} has been added", at.describe());
returnVal = false;
break;
}
}
}
return returnVal;
}
use of com.emc.storageos.db.common.schema.AnnotationType 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;
}
use of com.emc.storageos.db.common.schema.AnnotationType in project coprhd-controller by CoprHD.
the class MigrationHandlerImpl method dumpChanges.
/**
* Dump schema changes we are processing to the log
*
* @param diff
*/
public void dumpChanges(DbSchemasDiff diff) {
log.info("Start dumping changes");
for (AnnotationValue newValue : diff.getNewAnnotationValues()) {
log.info("new annotation value for class {}, field {}," + " annotation type {}: {}={}", new Object[] { newValue.getCfClass().getSimpleName(), newValue.getFieldName(), newValue.getAnnoClass().getSimpleName(), newValue.getName(), newValue.getValue() });
}
for (FieldInfo newField : diff.getNewFields()) {
log.info("new field for class {}: {}", newField.getCfClass().getSimpleName(), newField.getName());
}
for (AnnotationType newAnno : diff.getNewClassAnnotations()) {
log.info("new class annotation for class {}: {}", newAnno.getCfClass().getSimpleName(), newAnno.getType());
}
for (AnnotationType newAnno : diff.getNewFieldAnnotations()) {
log.info("new field annotation for class {}, field {}: {}", new Object[] { newAnno.getCfClass().getSimpleName(), newAnno.getFieldName(), newAnno.getType() });
}
for (DbSchema schema : diff.getNewClasses()) {
log.info("new CF: {}", schema.getType());
}
log.info("Finish dumping changes");
}
Aggregations