use of com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException 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;
}
use of com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException in project coprhd-controller by CoprHD.
the class MigrationHandlerImpl method persistMigrationFailInfo.
private void persistMigrationFailInfo(Date startTime, Exception e) {
schemaUtil.setMigrationStatus(MigrationStatus.FAILED);
UpgradeFailureInfo failure = new UpgradeFailureInfo();
failure.setVersion(targetVersion);
failure.setStartTime(startTime);
if (e instanceof MigrationCallbackException) {
failure.setSuggestion(e.getMessage());
}
failure.setMessage(String.format("Upgrade to %s failed:%s", targetVersion, e.getClass().getName()));
List<String> callStack = new ArrayList<String>();
for (StackTraceElement t : e.getStackTrace()) {
callStack.add(t.toString());
}
failure.setCallStack(callStack);
coordinator.persistRuntimeState(Constants.UPGRADE_FAILURE_INFO, failure);
}
use of com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionMigration method process.
/**
* {@inheritDoc}
*/
@Override
public void process() throws MigrationCallbackException {
s_logger.info("Executing BlockSnapshotSession migration callback.");
try {
DbClient dbClient = getDbClient();
List<BlockSnapshotSession> snapshotSessions = new ArrayList<BlockSnapshotSession>();
Map<URI, Map<String, BlockSnapshotSession>> groupSessionMap = new HashMap<>();
List<URI> snapshotURIs = dbClient.queryByType(BlockSnapshot.class, true);
Iterator<BlockSnapshot> snapshotsIter = dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotURIs, true);
while (snapshotsIter.hasNext()) {
BlockSnapshot snapshot = snapshotsIter.next();
if (isSnapshotSessionSupported(snapshot)) {
// Check if this is a group snapshot.
URI cgURI = snapshot.getConsistencyGroup();
if (NullColumnValueGetter.isNullURI(cgURI)) {
// The storage system for the single volume snapshot supports
// snapshot sessions, then we need to prepare and create a
// snapshot session for that snapshot and add the snapshot as
// a linked target for the session.
BlockSnapshotSession snapshotSession = prepareSnapshotSession(snapshot);
snapshotSessions.add(snapshotSession);
} else {
// Create the group session if necessary and add the snapshot as a
// linked target for that group session.
String settingsInstance = snapshot.getSettingsInstance();
Map<String, BlockSnapshotSession> grpSnapshotSessions = groupSessionMap.get(cgURI);
if (grpSnapshotSessions != null) {
BlockSnapshotSession snapshotSession = grpSnapshotSessions.get(settingsInstance);
if (snapshotSession == null) {
snapshotSession = prepareSnapshotSession(snapshot);
grpSnapshotSessions.put(settingsInstance, snapshotSession);
snapshotSessions.add(snapshotSession);
} else {
StringSet linkedTargets = snapshotSession.getLinkedTargets();
linkedTargets.add(snapshot.getId().toString());
}
} else {
grpSnapshotSessions = new HashMap<String, BlockSnapshotSession>();
groupSessionMap.put(cgURI, grpSnapshotSessions);
BlockSnapshotSession snapshotSession = prepareSnapshotSession(snapshot);
grpSnapshotSessions.put(settingsInstance, snapshotSession);
snapshotSessions.add(snapshotSession);
}
}
}
}
if (!snapshotSessions.isEmpty()) {
dbClient.createObject(snapshotSessions);
}
} catch (Exception e) {
s_logger.error("Caught exception during BlockSnapshotSession migration", e);
}
}
use of com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException in project coprhd-controller by CoprHD.
the class CifsShareACLMigration method process.
@Override
public void process() throws MigrationCallbackException {
logger.info("Migration started");
DbClient dbClient = getDbClient();
try {
List<URI> fileSystemURIList = dbClient.queryByType(FileShare.class, true);
Iterator<FileShare> fileSystemList = dbClient.queryIterativeObjects(FileShare.class, fileSystemURIList, true);
while (fileSystemList.hasNext()) {
FileShare fs = fileSystemList.next();
SMBShareMap smbShareMap = fs.getSMBFileShares();
Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
if (smbShareMap != null) {
smbShares = smbShareMap.values();
for (SMBFileShare smbShare : smbShares) {
if (smbShare.getPermissionType().equalsIgnoreCase(PERMISSION_TYPE_ALLOW)) {
CifsShareACL acl = new CifsShareACL();
acl.setId(URIUtil.createId(CifsShareACL.class));
acl.setShareName(smbShare.getName());
acl.setPermission(smbShare.getPermission());
acl.setUser(USER_EVERYONE);
acl.setFileSystemId(fs.getId());
logger.debug("Persisting new ACE into DB: {}", acl);
dbClient.createObject(acl);
}
}
}
}
// File snapshots
List<URI> fileSnapshotURIList = dbClient.queryByType(Snapshot.class, true);
Iterator<Snapshot> fileSnapshotList = dbClient.queryIterativeObjects(Snapshot.class, fileSnapshotURIList, true);
while (fileSnapshotList.hasNext()) {
Snapshot snapshot = fileSnapshotList.next();
SMBShareMap smbShareMap = snapshot.getSMBFileShares();
Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
if (smbShareMap != null) {
smbShares = smbShareMap.values();
for (SMBFileShare smbShare : smbShares) {
if (smbShare.getPermissionType().equalsIgnoreCase(PERMISSION_TYPE_ALLOW)) {
CifsShareACL acl = new CifsShareACL();
acl.setId(URIUtil.createId(CifsShareACL.class));
acl.setShareName(smbShare.getName());
acl.setPermission(getFormattedPermissionText(smbShare.getPermission()));
acl.setUser(USER_EVERYONE);
acl.setSnapshotId(snapshot.getId());
logger.debug("Persisting new ACE into DB: {}", acl);
dbClient.createObject(acl);
}
}
}
}
logger.info("Migration completed successfully");
} catch (Exception e) {
logger.error("Exception occured while migrating cifs share access control settings");
logger.error(e.getMessage(), e);
}
}
use of com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException in project coprhd-controller by CoprHD.
the class CustomMigrationCallbackExample method validateHostLabelLength.
private void validateHostLabelLength() throws MigrationCallbackException {
try {
DbClient dbClient = this.getDbClient();
List<URI> hostIds = dbClient.queryByType(Host.class, true);
Iterator<Host> hosts = dbClient.queryIterativeObjects(Host.class, hostIds, true);
while (hosts.hasNext()) {
Host host = hosts.next();
if (host.getLabel() != null && host.getLabel().length() < MIN_LABEL_LENGTH) {
String errorMsg = String.format("%s failed: invalid label length %s(%s)", this.getName(), Host.class.getSimpleName(), host.getId().toString());
throw new MigrationCallbackException(errorMsg, new IllegalStateException());
}
}
} catch (Exception e) {
String errorMsg = String.format("%s encounter unexpected error %s", this.getName(), e.getMessage());
throw new MigrationCallbackException(errorMsg, e);
}
}
Aggregations