Search in sources :

Example 1 with Resource3

use of com.emc.storageos.db.server.upgrade.util.models.updated2.Resource3 in project coprhd-controller by CoprHD.

the class Resource3NewFlagsInitializer method verify.

@Override
public void verify() {
    // Check Resource3
    List<URI> res3Keys = dbClient.queryByType(Resource3.class, false);
    Iterator<Resource3> res3Objs = dbClient.queryIterativeObjects(Resource3.class, res3Keys);
    Assert.assertTrue(res3Objs.hasNext());
    while (res3Objs.hasNext()) {
        Resource3 res3 = res3Objs.next();
        Assert.assertEquals(res3.getExtraFlags(), res3.getNewFlags());
    }
    // Check Resource6
    List<URI> res6Keys = dbClient.queryByType(Resource6.class, false);
    Iterator<Resource6> res6Objs = dbClient.queryIterativeObjects(Resource6.class, res6Keys);
    while (res6Objs.hasNext()) {
        Resource6 res6 = res6Objs.next();
        Assert.assertEquals(res6.getExtraFlags(), res6.getNewFlags());
        Assert.assertEquals(res6.getExtraFlags(), res6.getDupTestFlags());
    }
}
Also used : Resource6(com.emc.storageos.db.server.upgrade.util.models.updated2.Resource6) Resource3(com.emc.storageos.db.server.upgrade.util.models.updated2.Resource3) URI(java.net.URI)

Example 2 with Resource3

use of com.emc.storageos.db.server.upgrade.util.models.updated2.Resource3 in project coprhd-controller by CoprHD.

the class Resource3NewFlagsInitializer method process.

@Override
public void process() {
    DbClient dbClient = getDbClient();
    // check if we need to inject
    if (injectFault) {
        faultInjected = true;
        throw DatabaseException.retryables.operationFailed(new OperationException("Custom callback execuction error. Injected fault"));
    }
    // check if we need to inject
    if (injectFatalFault) {
        faultInjected = true;
        throw DatabaseException.fatals.failedDuringUpgrade("Injected fatal exception during upgrade", null);
    }
    // Check Resource3
    List<URI> res3Keys = dbClient.queryByType(Resource3.class, false);
    Iterator<Resource3> res3Objs = dbClient.queryIterativeObjects(Resource3.class, res3Keys);
    while (res3Objs.hasNext()) {
        Resource3 res3 = res3Objs.next();
        // Resource3FlagsInitializer should be executed first so extraFlags has value
        Long extraFlags = res3.getExtraFlags();
        if (extraFlags == null) {
            throw new IllegalStateException("Custom callback order error. Resource3FlagsInitializer should be executed first for Resource3.");
        }
        // Current value for new flag - should be zero always
        // Custom callback should be executed only once even referenced by many fields
        Long currentValue = res3.getNewFlags();
        if (currentValue != null) {
            throw new IllegalStateException("Custom callback order error. Resource3NewFlagsInitializer should not be executed twice.");
        }
        res3.setNewFlags(extraFlags);
        dbClient.persistObject(res3);
    }
    // Check Resource6
    List<URI> res6Keys = dbClient.queryByType(Resource6.class, false);
    Iterator<Resource6> res6Objs = dbClient.queryIterativeObjects(Resource6.class, res6Keys);
    while (res6Objs.hasNext()) {
        Resource6 res6 = res6Objs.next();
        // Resource3FlagsInitializer should be executed first so extraFlags has value
        Long extraFlags = res6.getExtraFlags();
        if (extraFlags == null) {
            throw new IllegalStateException("Custom callback order error. Resource3FlagsInitializer should be executed first for Resource6.");
        }
        // Current value for new flag - should be zero always
        // Custom callback should be executed only once even referenced by many fields
        Long currentValue = res6.getNewFlags();
        if (currentValue != null) {
            throw new IllegalStateException("Custom callback order error. Resource3NewFlagsInitializer should not be executed twice.");
        }
        res6.setNewFlags(extraFlags);
        res6.setDupTestFlags(extraFlags);
        dbClient.persistObject(res6);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) Resource6(com.emc.storageos.db.server.upgrade.util.models.updated2.Resource6) Resource3(com.emc.storageos.db.server.upgrade.util.models.updated2.Resource3) URI(java.net.URI) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException)

Aggregations

Resource3 (com.emc.storageos.db.server.upgrade.util.models.updated2.Resource3)2 Resource6 (com.emc.storageos.db.server.upgrade.util.models.updated2.Resource6)2 URI (java.net.URI)2 DbClient (com.emc.storageos.db.client.DbClient)1 OperationException (com.netflix.astyanax.connectionpool.exceptions.OperationException)1