Search in sources :

Example 6 with DbSchema

use of com.emc.storageos.db.common.schema.DbSchema in project coprhd-controller by CoprHD.

the class DbSchemasDiff method removeIgnoredSchemas.

private void removeIgnoredSchemas(List<DbSchema> schemas, String[] ignoredPkgs) {
    Iterator<DbSchema> iterator = schemas.iterator();
    boolean found = false;
    while (iterator.hasNext()) {
        DbSchema schema = iterator.next();
        found = false;
        for (String pkg : ignoredPkgs) {
            if (schema.getType().startsWith(pkg)) {
                found = true;
                break;
            }
        }
        if (found) {
            // remove the schema that should not be checked
            iterator.remove();
        }
    }
}
Also used : DbSchema(com.emc.storageos.db.common.schema.DbSchema)

Example 7 with DbSchema

use of com.emc.storageos.db.common.schema.DbSchema in project coprhd-controller by CoprHD.

the class DbSchemaCheckerTest method testGeoNewAnnotationOnExistingField.

@Test
public void testGeoNewAnnotationOnExistingField() {
    DbSchema srcGeoSchema = new DataObjectSchema(GeoClassUT.class);
    srcSchemas.addSchema(srcGeoSchema);
    tgtSchema = new DataObjectSchema(GeoNewAnnotationOnExistingField.class);
    tgtSchema.setType(srcSchema.getType());
    tgtSchemas.addSchema(tgtSchema);
    tgtSchemas.addSchema(srcSchema);
    DbSchemasDiff diff = new DbSchemasDiff(srcSchemas, tgtSchemas);
    // Adding index on existing field of Geo object is not allowed
    Assert.assertFalse(diff.isUpgradable());
    Assert.assertTrue(diff.isChanged());
}
Also used : DataObjectSchema(com.emc.storageos.db.common.schema.DataObjectSchema) DbSchema(com.emc.storageos.db.common.schema.DbSchema) DbSchemasDiff(com.emc.storageos.db.common.diff.DbSchemasDiff) Test(org.junit.Test)

Example 8 with DbSchema

use of com.emc.storageos.db.common.schema.DbSchema 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");
}
Also used : DbSchema(com.emc.storageos.db.common.schema.DbSchema) AnnotationValue(com.emc.storageos.db.common.schema.AnnotationValue) FieldInfo(com.emc.storageos.db.common.schema.FieldInfo) AnnotationType(com.emc.storageos.db.common.schema.AnnotationType)

Example 9 with DbSchema

use of com.emc.storageos.db.common.schema.DbSchema in project coprhd-controller by CoprHD.

the class DbSchemaChecker method genGeoDiffs.

/**
 * Filter out all the non-geo db schemas from the spec and generate a diff
 * Note that some CFs might have been migrated from local db to geo db
 * So we need to grab a latest list of geo schemas from the current schema first.
 *
 * @param spec the db schema spec generated from the baseline file
 * @param geoSchemas the latest list of geo schemas from the current DbSchemas object
 * @return
 */
private static DbSchemasDiff genGeoDiffs(DbSchemas spec, List<DbSchema> geoSchemas) {
    // prepare a list of geo schema names
    List<String> geoSchemaNames = new ArrayList<>();
    for (DbSchema geoSchema : geoSchemas) {
        geoSchemaNames.add(geoSchema.getName());
    }
    List<DbSchema> specSchemaList = new ArrayList<>();
    for (DbSchema schema : spec.getSchemas()) {
        if (geoSchemaNames.contains(schema.getName())) {
            specSchemaList.add(schema);
        }
    }
    return new DbSchemasDiff(new DbSchemas(specSchemaList), new DbSchemas(geoSchemas));
}
Also used : DbSchema(com.emc.storageos.db.common.schema.DbSchema) ArrayList(java.util.ArrayList) DbSchemasDiff(com.emc.storageos.db.common.diff.DbSchemasDiff) DbSchemas(com.emc.storageos.db.common.schema.DbSchemas)

Example 10 with DbSchema

use of com.emc.storageos.db.common.schema.DbSchema 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

DbSchema (com.emc.storageos.db.common.schema.DbSchema)10 DbSchemasDiff (com.emc.storageos.db.common.diff.DbSchemasDiff)6 DataObjectSchema (com.emc.storageos.db.common.schema.DataObjectSchema)6 Test (org.junit.Test)5 DbKeyspace (com.emc.storageos.db.client.model.DbKeyspace)1 TimeSeries (com.emc.storageos.db.client.model.TimeSeries)1 TimeSeriesSerializer (com.emc.storageos.db.client.model.TimeSeriesSerializer)1 AnnotationType (com.emc.storageos.db.common.schema.AnnotationType)1 AnnotationValue (com.emc.storageos.db.common.schema.AnnotationValue)1 DataPointSchema (com.emc.storageos.db.common.schema.DataPointSchema)1 DbSchemas (com.emc.storageos.db.common.schema.DbSchemas)1 FieldInfo (com.emc.storageos.db.common.schema.FieldInfo)1 TimeSeriesSchema (com.emc.storageos.db.common.schema.TimeSeriesSchema)1 ArrayList (java.util.ArrayList)1