use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.
the class VPlexDeviceController method cancelMigrationStep.
public void cancelMigrationStep(URI vplexURI, URI migrationURI, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
Migration migration = getDataObject(Migration.class, migrationURI, _dbClient);
client.cancelMigrations(Arrays.asList(migration.getLabel()), true, true);
migration.setMigrationStatus(VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue());
_dbClient.updateObject(migration);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error("Exception cancelling migration: ", ex);
String opName = ResourceOperationTypeEnum.CANCEL_MIGRATION.getName();
ServiceError serviceError = VPlexApiException.errors.operateMigrationFailed(opName, ex);
WorkflowStepCompleter.stepFailed(stepId, serviceError);
}
}
use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.
the class VPlexDeviceController method resumeMigrationStep.
public void resumeMigrationStep(URI vplexURI, URI migrationURI, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
Migration migration = getDataObject(Migration.class, migrationURI, _dbClient);
client.resumeMigrations(Arrays.asList(migration.getLabel()));
migration.setMigrationStatus(VPlexMigrationInfo.MigrationStatus.IN_PROGRESS.getStatusValue());
_dbClient.updateObject(migration);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error("Exception resuming migration: ", ex);
String opName = ResourceOperationTypeEnum.RESUME_MIGRATION.getName();
ServiceError serviceError = VPlexApiException.errors.operateMigrationFailed(opName, ex);
WorkflowStepCompleter.stepFailed(stepId, serviceError);
}
}
use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.
the class VPlexDeviceController method migrateVirtualVolume.
/**
* Creates and starts a VPlex data migration for the passed virtual volume
* on the passed VPlex storage system. The passed target is a newly created
* backend volume to which the data will be migrated. The source for the
* data migration is the current backend volume for the virtual volume that
* is in the same varray as the passed target. The method also creates
* a migration job to monitor the progress of the migration. The workflow
* step will complete when the migration completes, at which point the
* migration is automatically committed.
*
* @param vplexURI
* The URI of the VPlex storage system.
* @param virtualVolumeURI
* The URI of the virtual volume.
* @param targetVolumeURI
* The URI of the migration target.
* @param migrationURI
* The URI of the migration.
* @param newNhURI
* The URI of the new varray for the virtual volume
* when a local virtual volume is being migrated to the other
* cluster, or null.
* @param stepId
* The workflow step identifier.
* @throws WorkflowException
*/
public void migrateVirtualVolume(URI vplexURI, URI virtualVolumeURI, URI targetVolumeURI, URI migrationURI, URI newNhURI, String stepId) throws WorkflowException {
_log.info("Migration {} using target {}", migrationURI, targetVolumeURI);
try {
// Update step state to executing.
WorkflowStepCompleter.stepExecuting(stepId);
// Initialize the step data. The step data indicates if we
// successfully started the migration and is used in
// rollback.
_workflowService.storeStepData(stepId, Boolean.FALSE);
// Get the virtual volume.
Volume virtualVolume = getDataObject(Volume.class, virtualVolumeURI, _dbClient);
String virtualVolumeName = virtualVolume.getDeviceLabel();
_log.info("Virtual volume name is {}", virtualVolumeName);
// Setup the native volume info for the migration target.
Volume migrationTarget = getDataObject(Volume.class, targetVolumeURI, _dbClient);
StorageSystem targetStorageSystem = getDataObject(StorageSystem.class, migrationTarget.getStorageController(), _dbClient);
_log.info("Storage system for migration target is {}", migrationTarget.getStorageController());
List<String> itls = VPlexControllerUtils.getVolumeITLs(migrationTarget);
VolumeInfo nativeVolumeInfo = new VolumeInfo(targetStorageSystem.getNativeGuid(), targetStorageSystem.getSystemType(), migrationTarget.getWWN().toUpperCase().replaceAll(":", ""), migrationTarget.getNativeId(), migrationTarget.getThinlyProvisioned().booleanValue(), itls);
// Get the migration associated with the target.
Migration migration = getDataObject(Migration.class, migrationURI, _dbClient);
// Determine the unique name for the migration. We identifying
// the migration source and target, using array serial number
// and volume native id, in the migration name. This was fine
// for VPlex extent migration, which has a max length of 63
// for the migration name. However, for remote migrations,
// which require VPlex device migration, the max length is much
// more restrictive, like 20 characters. So, we switched over
// timestamps.
StringBuilder migrationNameBuilder = new StringBuilder(MIGRATION_NAME_PREFIX);
DateFormat dateFormatter = new SimpleDateFormat(MIGRATION_NAME_DATE_FORMAT);
migrationNameBuilder.append(dateFormatter.format(new Date()));
String migrationName = migrationNameBuilder.toString();
migration.setLabel(migrationName);
_dbClient.updateObject(migration);
_log.info("Migration name is {}", migrationName);
// Get the VPlex API client.
StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexURI, _dbClient);
VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplexSystem, _dbClient);
_log.info("Got VPlex API client for VPlex {}", vplexURI);
// Get the configured migration speed
String speed = customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.MIGRATION_SPEED, vplexSystem.getSystemType(), null);
_log.info("Migration speed is {}", speed);
String transferSize = migrationSpeedToTransferSizeMap.get(speed);
// Make a call to the VPlex API client to migrate the virtual
// volume. Note that we need to do a remote migration when a
// local virtual volume is being migrated to the other VPlex
// cluster. If the passed new varray is not null, then
// this is the case.
Boolean isRemoteMigration = newNhURI != null;
// We support both device and extent migrations, however,
// when we don't know anything about the backend volumes
// we must use device migration.
Boolean useDeviceMigration = migration.getSource() == null;
List<VPlexMigrationInfo> migrationInfoList = client.migrateVirtualVolume(migrationName, virtualVolumeName, Arrays.asList(nativeVolumeInfo), isRemoteMigration, useDeviceMigration, true, true, transferSize);
_log.info("Started VPlex migration");
// We store step data indicating that the migration was successfully
// create and started. We will use this to determine the behavior
// on rollback. If we never got to the point that the migration
// was created and started, then there is no rollback to attempt
// on the VLPEX as the migrate API already tried to clean everything
// up on the VLPEX.
_workflowService.storeStepData(stepId, Boolean.TRUE);
// Initialize the migration info in the database.
VPlexMigrationInfo migrationInfo = migrationInfoList.get(0);
migration.setMigrationStatus(VPlexMigrationInfo.MigrationStatus.READY.getStatusValue());
migration.setPercentDone("0");
migration.setStartTime(migrationInfo.getStartTime());
_dbClient.updateObject(migration);
_log.info("Update migration info");
// Create a migration task completer and queue a job to monitor
// the migration progress. The completer will be invoked by the
// job when the migration completes.
MigrationTaskCompleter migrationCompleter = new MigrationTaskCompleter(migrationURI, stepId);
VPlexMigrationJob migrationJob = new VPlexMigrationJob(migrationCompleter);
migrationJob.setTimeoutTimeMsec(MINUTE_TO_MILLISECONDS * Long.valueOf(ControllerUtils.getPropertyValueFromCoordinator(coordinator, CONTROLLER_VPLEX_MIGRATION_TIMEOUT_MINUTES)));
ControllerServiceImpl.enqueueJob(new QueueJob(migrationJob));
_log.info("Queued job to monitor migration progress.");
} catch (VPlexApiException vae) {
_log.error("Exception migrating VPlex virtual volume: " + vae.getMessage(), vae);
WorkflowStepCompleter.stepFailed(stepId, vae);
} catch (Exception ex) {
_log.error("Exception migrating VPlex virtual volume: " + ex.getMessage(), ex);
String opName = ResourceOperationTypeEnum.MIGRATE_VIRTUAL_VOLUME.getName();
ServiceError serviceError = VPlexApiException.errors.migrateVirtualVolume(opName, ex);
WorkflowStepCompleter.stepFailed(stepId, serviceError);
}
}
use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.
the class VPlexDeviceController method deleteMigrationStep.
public void deleteMigrationStep(URI vplexURI, URI migrationURI, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
Migration migration = getDataObject(Migration.class, migrationURI, _dbClient);
client.removeMigrations(Arrays.asList(migration.getLabel()));
migration.setInactive(true);
_dbClient.updateObject(migration);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error("Exception deleting migration:", ex);
String opName = ResourceOperationTypeEnum.DELETE_MIGRATION.getName();
ServiceError serviceError = VPlexApiException.errors.operateMigrationFailed(opName, ex);
WorkflowStepCompleter.stepFailed(stepId, serviceError);
}
}
use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.
the class VPlexMigrationJob method poll.
/**
* {@inheritDoc}
*/
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
s_logger.debug("Polled migration job");
Migration migration = null;
StorageSystem vplexSystem = null;
try {
// Therefore, the default max retries is 240.
if (_maxRetries == null) {
if (trackingPeriodInMillis < MAX_TIME_FOR_SUCCESSFUL_STATUS_CHECK_MS) {
_maxRetries = new Integer(Math.round(MAX_TIME_FOR_SUCCESSFUL_STATUS_CHECK_MS / trackingPeriodInMillis));
} else {
_maxRetries = new Integer(1);
}
}
// Get the DB client from the job context.
DbClient dbClient = jobContext.getDbClient();
// Get the migration associated with this job.
migration = dbClient.queryObject(Migration.class, _taskCompleter.getId());
String migrationName = migration.getLabel();
s_logger.debug("Migration is {}", migration.getId());
// Get the virtual volume associated with the migration
// and then get the VPlex storage system for that virtual
// volume.
Volume virtualVolume = dbClient.queryObject(Volume.class, migration.getVolume());
s_logger.debug("Virtual volume is {}", virtualVolume.getId());
vplexSystem = dbClient.queryObject(StorageSystem.class, virtualVolume.getStorageController());
s_logger.debug("VPlex system is {}", vplexSystem.getId());
// Get the VPlex API client for this VPlex storage system
// and get the latest info for the migration.
VPlexApiClient vplexApiClient = VPlexControllerUtils.getVPlexAPIClient(jobContext.getVPlexApiFactory(), vplexSystem, dbClient);
s_logger.debug("Got VPlex APi Client");
VPlexMigrationInfo migrationInfo = vplexApiClient.getMigrationInfo(migrationName);
s_logger.debug("Got migration info from VPlex");
// Update the migration in the database to reflect the
// current status and percent done.
String migrationStatus = migrationInfo.getStatus();
s_logger.debug("Migration status is {}", migrationStatus);
migration.setMigrationStatus(migrationStatus);
int percentDone = getMigrationPercentDone(migrationInfo.getPercentageDone());
s_logger.debug("Migration percent done is {}", percentDone);
migration.setPercentDone(String.valueOf(percentDone));
dbClient.persistObject(migration);
// Update the job info.
_pollResult.setJobName(migrationName);
_pollResult.setJobId(virtualVolume.getId().toString());
_pollResult.setJobPercentComplete(percentDone);
s_logger.debug("Updated poll result");
// Examine the status.
if (VPlexMigrationInfo.MigrationStatus.COMPLETE.getStatusValue().equals(migrationStatus)) {
// Completed successfully
s_logger.info("Migration: {} completed sucessfully", migration.getId());
_status = JobStatus.SUCCESS;
} else if (VPlexMigrationInfo.MigrationStatus.COMMITTED.getStatusValue().equals(migrationStatus)) {
// The migration job completed and somehow it was committed
// outside the scope of the workflow that created the
// migration job. We return success here to ensure that there
// is no rollback in the workflow that could end up deleting
// the target volume of the migration.
s_logger.info("Migration: {} completed and was committed", migration.getId());
_status = JobStatus.SUCCESS;
} else if (VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue().equals(migrationStatus)) {
// The migration job was cancelled outside the scope of the
// workflow that created the migration job.
_errorDescription = "The migration was cancelled";
s_logger.info("Migration: {} was cancelled prior to completion", migration.getId());
_status = JobStatus.FAILED;
} else if (VPlexMigrationInfo.MigrationStatus.ERROR.getStatusValue().equals(migrationStatus)) {
// The migration failed.
_errorDescription = "The migration failed";
s_logger.error("Migration {} failed prior to completion", migration.getId());
_status = JobStatus.FAILED;
}
// We had a successful check of the status. Reset the retry
// count in case the job is still in progress and the next
// attempt to check the status fails.
_retryCount = 0;
} catch (Exception e) {
s_logger.error(String.format("Unexpected error getting status of migration %s on VPlex %s: %s", (migration != null ? migration.getId() : "null"), (vplexSystem != null ? vplexSystem.getId() : "null"), _errorDescription), e);
if (++_retryCount > _maxRetries) {
_errorDescription = e.getMessage();
_status = JobStatus.FAILED;
}
} finally {
s_logger.debug("Updating status {}", _status);
updateStatus(jobContext);
}
_pollResult.setJobStatus(_status);
_pollResult.setErrorDescription(_errorDescription);
return _pollResult;
}
Aggregations