Search in sources :

Example 1 with DbKeyspace

use of com.emc.storageos.db.client.model.DbKeyspace 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;
}
Also used : DbKeyspace(com.emc.storageos.db.client.model.DbKeyspace) CustomMigrationCallback(com.emc.storageos.db.client.upgrade.CustomMigrationCallback) AnnotationType(com.emc.storageos.db.common.schema.AnnotationType)

Example 2 with DbKeyspace

use of com.emc.storageos.db.client.model.DbKeyspace in project coprhd-controller by CoprHD.

the class GeoDbMigrationCallback method process.

@Override
public void process() throws MigrationCallbackException {
    if (cfClass == null || annotation == null) {
        // this callback has not been set up; skip it.
        throw DatabaseException.fatals.failedDuringUpgrade("Unexpected state: callback not setup", null);
    }
    if (!annotation.annotationType().equals(DbKeyspace.class)) {
        throw DatabaseException.fatals.failedDuringUpgrade("Unexpected annotation: only support" + " @DbKeyspace", null);
    }
    String cfName = cfClass.getCanonicalName();
    if (!DataObject.class.isAssignableFrom(cfClass)) {
        throw DatabaseException.fatals.failedDuringUpgrade("Unexpected CF type: " + cfName, null);
    }
    // No need to do anything if the DbKeyspace is set to LOCAL
    DbKeyspace keyspace = (DbKeyspace) cfClass.getAnnotation(annotation.annotationType());
    if (keyspace.value().equals(DbKeyspace.Keyspaces.LOCAL)) {
        log.info("No need to do anything for CF {}", cfName);
        return;
    }
    log.info("Copying db records for class: {} from local db into geodb", cfName);
    try {
        getInternalDbClient().migrateToGeoDb(cfClass);
    } catch (Exception e) {
        log.error("GeoDbMigrationCallback migration failed", e);
        throw DatabaseException.fatals.failedDuringUpgrade("db schema migration error: failed" + "to migrate CF " + cfName + " into geodb", e);
    }
    log.info("migrate on global resource {} finished", cfClass.getSimpleName());
}
Also used : DbKeyspace(com.emc.storageos.db.client.model.DbKeyspace) DataObject(com.emc.storageos.db.client.model.DataObject) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 3 with DbKeyspace

use of com.emc.storageos.db.client.model.DbKeyspace in project coprhd-controller by CoprHD.

the class DbSchemaScanner method processClass.

@Override
protected void processClass(Class clazz) {
    DbSchema schema = null;
    if (DataObject.class.isAssignableFrom(clazz)) {
        if (_scannerInterceptor != null && _scannerInterceptor.isClassIgnored(clazz.getSimpleName())) {
            log.info("{} is ignored in schema due to interceptor", clazz.getSimpleName());
            return;
        }
        schema = new DataObjectSchema(clazz, _scannerInterceptor);
        if (clazz.isAnnotationPresent(DbKeyspace.class)) {
            DbKeyspace anno = (DbKeyspace) clazz.getAnnotation(DbKeyspace.class);
            if (DbKeyspace.Keyspaces.GLOBAL.equals(anno.value())) {
                geoSchemas.add(schema);
            }
        }
    } else if (TimeSeries.class.isAssignableFrom(clazz)) {
        schema = new TimeSeriesSchema(clazz);
    } else if (TimeSeriesSerializer.DataPoint.class.isAssignableFrom(clazz)) {
        schema = new DataPointSchema(clazz);
    } else {
        return;
    }
    schemas.addSchema(schema);
}
Also used : DbKeyspace(com.emc.storageos.db.client.model.DbKeyspace) DataObjectSchema(com.emc.storageos.db.common.schema.DataObjectSchema) TimeSeries(com.emc.storageos.db.client.model.TimeSeries) DbSchema(com.emc.storageos.db.common.schema.DbSchema) TimeSeriesSchema(com.emc.storageos.db.common.schema.TimeSeriesSchema) DataPointSchema(com.emc.storageos.db.common.schema.DataPointSchema) TimeSeriesSerializer(com.emc.storageos.db.client.model.TimeSeriesSerializer)

Aggregations

DbKeyspace (com.emc.storageos.db.client.model.DbKeyspace)3 DataObject (com.emc.storageos.db.client.model.DataObject)1 TimeSeries (com.emc.storageos.db.client.model.TimeSeries)1 TimeSeriesSerializer (com.emc.storageos.db.client.model.TimeSeriesSerializer)1 CustomMigrationCallback (com.emc.storageos.db.client.upgrade.CustomMigrationCallback)1 AnnotationType (com.emc.storageos.db.common.schema.AnnotationType)1 DataObjectSchema (com.emc.storageos.db.common.schema.DataObjectSchema)1 DataPointSchema (com.emc.storageos.db.common.schema.DataPointSchema)1 DbSchema (com.emc.storageos.db.common.schema.DbSchema)1 TimeSeriesSchema (com.emc.storageos.db.common.schema.TimeSeriesSchema)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)1