Search in sources :

Example 1 with MigrationStatus

use of com.emc.storageos.coordinator.client.model.MigrationStatus in project coprhd-controller by CoprHD.

the class MigrationHandlerImpl method run.

/**
 */
@Override
public boolean run() throws DatabaseException {
    Date startTime = new Date();
    // set state to migration_init and wait for all nodes to reach this state
    setDbConfig(DbConfigConstants.MIGRATION_INIT);
    targetVersion = service.getVersion();
    statusChecker.setVersion(targetVersion);
    statusChecker.setServiceName(service.getName());
    // dbsvc will wait for all dbsvc, and geodbsvc waits for all geodbsvc.
    statusChecker.waitForAllNodesMigrationInit();
    if (schemaUtil.isStandby()) {
        String currentSchemaVersion = coordinator.getCurrentDbSchemaVersion();
        if (!StringUtils.equals(currentSchemaVersion, targetVersion)) {
            // no migration on standby site
            log.info("Migration does not run on standby. Change current version to {}", targetVersion);
            schemaUtil.setCurrentVersion(targetVersion);
        }
        return true;
    }
    if (schemaUtil.isGeoDbsvc()) {
        boolean schemaVersionChanged = isDbSchemaVersionChanged();
        // scan and update cassandra schema
        checkGeoDbSchema();
        // no migration procedure for geosvc, just wait till migration is done on one of the
        // dbsvcs
        log.warn("Migration is not supported for Geodbsvc. Wait till migration is done");
        statusChecker.waitForMigrationDone();
        // Update vdc version
        if (schemaVersionChanged) {
            schemaUtil.insertOrUpdateVdcVersion(dbClient, true);
        }
        return true;
    } else {
        // for dbsvc, we have to wait till all geodbsvc becomes migration_init since we might
        // need to copy geo-replicated resources from local to geo db.
        statusChecker.waitForAllNodesMigrationInit(Constants.GEODBSVC_NAME);
    }
    InterProcessLock lock = null;
    String currentSchemaVersion = null;
    int retryCount = 0;
    while (retryCount < MAX_MIGRATION_RETRY) {
        log.debug("Migration handlers - Start. Trying to grab lock ...");
        try {
            // grab global lock for migration
            lock = getLock(DB_MIGRATION_LOCK);
            // make sure we haven't finished the migration on another node already
            MigrationStatus status = coordinator.getMigrationStatus();
            if (status != null) {
                if (status == MigrationStatus.DONE) {
                    log.info("DB migration is done already. Skipping...");
                    if (null == getPersistedSchema(targetVersion)) {
                        persistSchema(targetVersion, DbSchemaChecker.marshalSchemas(currentSchema, null));
                    }
                    return true;
                } else if (status == MigrationStatus.FAILED) {
                    log.error("DB migration is done already with status:{}. ", status);
                    return false;
                }
            }
            schemaUtil.setMigrationStatus(MigrationStatus.RUNNING);
            // we expect currentSchemaVersion to be set
            currentSchemaVersion = coordinator.getCurrentDbSchemaVersion();
            if (currentSchemaVersion == null) {
                throw new IllegalStateException("Schema version not set");
            }
            // figure out our source and target versions
            DbSchemas persistedSchema = getPersistedSchema(currentSchemaVersion);
            if (isSchemaMissed(persistedSchema, currentSchemaVersion, targetVersion)) {
                throw new IllegalStateException("Schema definition not found for version " + currentSchemaVersion);
            }
            if (isFreshInstall(persistedSchema, currentSchemaVersion, targetVersion)) {
                log.info("saving schema of version {} to db", currentSchemaVersion);
                persistedSchema = currentSchema;
                persistSchema(currentSchemaVersion, DbSchemaChecker.marshalSchemas(persistedSchema, null));
            }
            // check if we have a schema upgrade to deal with
            if (!currentSchemaVersion.equals(targetVersion)) {
                log.info("Start scanning and creating new column families");
                schemaUtil.checkCf(true);
                log.info("Scanning and creating new column families succeed");
                DbSchemasDiff diff = new DbSchemasDiff(persistedSchema, currentSchema, ignoredPkgs);
                if (diff.isChanged()) {
                    // log the changes
                    dumpChanges(diff);
                    if (!diff.isUpgradable()) {
                        // we should never be here, but, if we are here, throw an IllegalStateException and stop
                        // To Do - dump the problematic diffs here
                        log.error("schema diff details: {}", DbSchemaChecker.marshalSchemasDiff(diff));
                        throw new IllegalStateException("schema not upgradable.");
                    }
                }
                log.info("Starting migration callbacks from {} to {}", currentSchemaVersion, targetVersion);
                // we need to check point the progress of these callbacks as they are run,
                // so we can resume from where we left off in case of restarts/errors
                String checkpoint = schemaUtil.getMigrationCheckpoint();
                if (checkpoint != null) {
                    log.info("Migration checkpoint found for {}", checkpoint);
                }
                // run all migration callbacks
                runMigrationCallbacks(diff, checkpoint);
                log.info("Done migration callbacks");
                persistSchema(targetVersion, DbSchemaChecker.marshalSchemas(currentSchema, null));
                schemaUtil.dropUnusedCfsIfExists();
                // set current version in zk
                schemaUtil.setCurrentVersion(targetVersion);
                log.info("current schema version is updated to {}", targetVersion);
            }
            schemaUtil.setMigrationStatus(MigrationStatus.DONE);
            // Remove migration checkpoint after done
            schemaUtil.removeMigrationCheckpoint();
            removeMigrationFailInfoIfExist();
            log.debug("Migration handler - Done.");
            return true;
        } catch (Exception e) {
            if (e instanceof MigrationCallbackException) {
                markMigrationFailure(startTime, currentSchemaVersion, e);
            } else if (isUnRetryableException(e)) {
                markMigrationFailure(startTime, currentSchemaVersion, e);
                return false;
            } else {
                log.warn("Retryable exception during migration ", e);
                retryCount++;
                lastException = e;
            }
        } finally {
            if (lock != null) {
                try {
                    lock.release();
                } catch (Exception ignore) {
                    log.debug("lock release failed");
                }
            }
        }
        sleepBeforeRetry();
    }
    // while -- not done
    markMigrationFailure(startTime, currentSchemaVersion, lastException);
    return false;
}
Also used : MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) DbSchemasDiff(com.emc.storageos.db.common.diff.DbSchemasDiff) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DbSchemas(com.emc.storageos.db.common.schema.DbSchemas) MigrationStatus(com.emc.storageos.coordinator.client.model.MigrationStatus) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) FatalCoordinatorException(com.emc.storageos.coordinator.exceptions.FatalCoordinatorException) FatalDatabaseException(com.emc.storageos.db.exceptions.FatalDatabaseException)

Example 2 with MigrationStatus

use of com.emc.storageos.coordinator.client.model.MigrationStatus in project coprhd-controller by CoprHD.

the class Main method main.

/**
 * Zkutils entry method.
 *
 * @param args
 *            command and arguments.
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        usage();
        return;
    }
    Command cmd;
    try {
        cmd = Command.valueOf(args[0].trim().toUpperCase());
    } catch (IllegalArgumentException e) {
        System.err.println("Invalid command " + args[0]);
        usage();
        return;
    }
    try {
        switch(cmd) {
            case PATH:
                if (args.length < 2) {
                    throw new IllegalArgumentException("The path substring is missing");
                }
                processZkCmdArgs(args);
                initZkCmdHandler(host, port, withData);
                zkCmdHandler.printNodes(path);
                break;
            case SET:
                if (args.length < 2) {
                    throw new IllegalArgumentException("The path and/or data substring is missing");
                }
                processZkCmdArgs(args);
                initZkCmdHandler(host, port, withData);
                zkCmdHandler.setNodeData(path);
                break;
            case EPHEMERAL:
                processZkCmdArgs(args);
                initZkCmdHandler(host, port, withData);
                zkCmdHandler.printEphemeralNodes();
                break;
            case ROLLBACK_DATA_REVISION:
                if (args.length > 1) {
                    throw new IllegalArgumentException("Invalid paramerters");
                }
                System.out.println(rollbackWarnMessage);
                System.out.print("Do you still want to continue [y/n]:");
                Scanner userInput = new Scanner(System.in);
                String answer = userInput.nextLine();
                if (answer == null || !answer.equals("y")) {
                    System.out.println("You have aborted rollback operation");
                    System.exit(1);
                }
                initZkCmdHandler(host, port, withData);
                zkCmdHandler.rollbackDataRevision();
                break;
            case TUNE_DR_CONFIG:
                if (args.length != 3) {
                    throw new IllegalArgumentException("Invalid parameters");
                }
                String key = args[1] != null ? args[1].trim() : "";
                String value = args[2] != null ? args[2].trim() : "";
                if (key.isEmpty() || value.isEmpty()) {
                    throw new IllegalArgumentException("Invalid parameters");
                }
                processZkCmdArgs(args);
                initZkCmdHandler(host, port, withData);
                zkCmdHandler.tuneDrConfig(key, value);
                break;
            case GETLASTVALIDZXID:
                if (args.length > 1) {
                    throw new IllegalArgumentException("Invalid parameters");
                }
                initZkTxnHandler();
                zkTxnHandler.getLastValidZxid();
                break;
            case TRUNCATETXNLOG:
                if (args.length > 2) {
                    throw new IllegalArgumentException("Invalid parameters");
                }
                initZkTxnHandler();
                boolean success = false;
                if (args.length < 2) {
                    success = zkTxnHandler.truncateToZxid();
                } else {
                    success = zkTxnHandler.truncateToZxid(args[1]);
                }
                if (!success) {
                    System.exit(1);
                }
                break;
            case LOCK:
                processLockCmdArgs(args);
                initLockCmdHandler();
                lockCmdHandler.aquireUpgradeLocks();
                // because using the non-persistent lock, need exit manually
                System.out.println("If you want to upgrade, " + "Please kill this thread and use 'release' command");
                break;
            case HOLD:
                processLockCmdArgs(args);
                initLockCmdHandler();
                lockCmdHandler.aquireUpgradeLockByLoop();
                System.out.println("If you want to continue, Please use 'release' command");
                stop();
                break;
            case RELEASE:
                processLockCmdArgs(args);
                initLockCmdHandler();
                lockCmdHandler.releaseAllLocks();
                stop();
                break;
            case INFO:
                processLockCmdArgs(args);
                initLockCmdHandler();
                lockCmdHandler.getUpgradeLockOwner();
                stop();
                break;
            case RESET:
                MigrationStatus status = processServiceCmdArgs(args);
                initServiceCmdHandler();
                serviceCmdHandler.resetMigrationStatus(status);
                break;
            case GETKEYANDCERT:
                if (args.length > 1) {
                    throw new IllegalArgumentException("Invalid parameters");
                }
                initKeystoreCmdHandler();
                keystoreCmdHandler.getViPRKey();
                System.out.println();
                keystoreCmdHandler.getViPRCertificate();
                break;
            case EXPORTKEYSTORE:
                if (args.length > 1) {
                    throw new IllegalArgumentException("Invalid parameters");
                }
                initKeystoreCmdHandler();
                try {
                    keystoreCmdHandler.exportKeystore();
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    System.err.println("Exception e=" + e);
                    System.exit(1);
                }
                break;
            default:
                throw new IllegalArgumentException("Invalid command");
        }
    } catch (Exception e) {
        System.err.println("Exception e=" + e);
        usage();
    } finally {
        if (!cmd.equals(Command.LOCK)) {
            stop();
        }
    }
}
Also used : Scanner(java.util.Scanner) MigrationStatus(com.emc.storageos.coordinator.client.model.MigrationStatus) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException)

Example 3 with MigrationStatus

use of com.emc.storageos.coordinator.client.model.MigrationStatus in project coprhd-controller by CoprHD.

the class ServiceConfigCmdHandler method resetMigrationStatus.

/**
 * Reset Migration status from specific status
 *
 * @param status
 *            specific status
 */
public void resetMigrationStatus(MigrationStatus status) {
    MigrationStatus nowStatus = coordinator.getMigrationStatus();
    if (nowStatus != null && nowStatus.equals(status)) {
        log.info("Reset Migration status from {}.", nowStatus);
        coordinator.removeServiceConfiguration(coordinator.getSiteId(), getMigrationConfiguration());
        nowStatus = coordinator.getMigrationStatus();
        log.info("After reseting, the status is {}.", nowStatus);
        if (nowStatus == null) {
            System.out.println("Reset Migration status Successfully.");
        } else {
            System.out.println("Fail to reset Migration status.");
            log.error("Fail to reset Migration status.");
        }
    } else {
        log.error("The Migration status is {}, not specific {}.", nowStatus, status);
        System.out.println(String.format("The Migration status is %s, not %s.", nowStatus, status));
    }
}
Also used : MigrationStatus(com.emc.storageos.coordinator.client.model.MigrationStatus)

Example 4 with MigrationStatus

use of com.emc.storageos.coordinator.client.model.MigrationStatus in project coprhd-controller by CoprHD.

the class StubCoordinatorClientImpl method getMigrationStatus.

@Override
public MigrationStatus getMigrationStatus() {
    Configuration config = queryConfiguration(getVersionedDbConfigPath(Constants.DBSVC_NAME, getTargetDbSchemaVersion()), GLOBAL_ID);
    if (config == null || config.getConfig(MIGRATION_STATUS) == null) {
        return null;
    }
    MigrationStatus status = MigrationStatus.valueOf(config.getConfig(MIGRATION_STATUS));
    return status;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) MigrationStatus(com.emc.storageos.coordinator.client.model.MigrationStatus)

Example 5 with MigrationStatus

use of com.emc.storageos.coordinator.client.model.MigrationStatus in project coprhd-controller by CoprHD.

the class CoordinatorClientImpl method getMigrationStatus.

public MigrationStatus getMigrationStatus() {
    log.debug("getMigrationStatus: target version: \"{}\"", getTargetDbSchemaVersion());
    // TODO support geodbsvc
    Configuration config = queryConfiguration(_zkConnection.getSiteId(), getVersionedDbConfigPath(Constants.DBSVC_NAME, getTargetDbSchemaVersion()), GLOBAL_ID);
    if (config == null || config.getConfig(MIGRATION_STATUS) == null) {
        log.debug("config is null");
        return null;
    }
    MigrationStatus status = MigrationStatus.valueOf(config.getConfig(MIGRATION_STATUS));
    log.debug("status: {}", status);
    return status;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) MigrationStatus(com.emc.storageos.coordinator.client.model.MigrationStatus)

Aggregations

MigrationStatus (com.emc.storageos.coordinator.client.model.MigrationStatus)6 Configuration (com.emc.storageos.coordinator.common.Configuration)2 Site (com.emc.storageos.coordinator.client.model.Site)1 SiteState (com.emc.storageos.coordinator.client.model.SiteState)1 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)1 FatalCoordinatorException (com.emc.storageos.coordinator.exceptions.FatalCoordinatorException)1 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)1 DbSchemasDiff (com.emc.storageos.db.common.diff.DbSchemasDiff)1 DbSchemas (com.emc.storageos.db.common.schema.DbSchemas)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 FatalDatabaseException (com.emc.storageos.db.exceptions.FatalDatabaseException)1 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)1 IOException (java.io.IOException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 Scanner (java.util.Scanner)1 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)1