Search in sources :

Example 21 with Migration

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Migration(com.emc.storageos.db.client.model.Migration) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 22 with Migration

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Migration(com.emc.storageos.db.client.model.Migration) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 23 with Migration

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) MigrationTaskCompleter(com.emc.storageos.vplexcontroller.completers.MigrationTaskCompleter) Migration(com.emc.storageos.db.client.model.Migration) VolumeInfo(com.emc.storageos.vplex.api.clientdata.VolumeInfo) VPlexVirtualVolumeInfo(com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo) Date(java.util.Date) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VPlexMigrationInfo(com.emc.storageos.vplex.api.VPlexMigrationInfo) VPlexMigrationJob(com.emc.storageos.vplexcontroller.job.VPlexMigrationJob) Volume(com.emc.storageos.db.client.model.Volume) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) SimpleDateFormat(java.text.SimpleDateFormat) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 24 with Migration

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Migration(com.emc.storageos.db.client.model.Migration) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 25 with Migration

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;
}
Also used : VPlexMigrationInfo(com.emc.storageos.vplex.api.VPlexMigrationInfo) DbClient(com.emc.storageos.db.client.DbClient) Volume(com.emc.storageos.db.client.model.Volume) Migration(com.emc.storageos.db.client.model.Migration) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) URISyntaxException(java.net.URISyntaxException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

Migration (com.emc.storageos.db.client.model.Migration)33 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)22 URI (java.net.URI)22 Volume (com.emc.storageos.db.client.model.Volume)20 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 URISyntaxException (java.net.URISyntaxException)17 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)16 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)16 ControllerException (com.emc.storageos.volumecontroller.ControllerException)16 VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)16 WorkflowException (com.emc.storageos.workflow.WorkflowException)16 IOException (java.io.IOException)16 NamedURI (com.emc.storageos.db.client.model.NamedURI)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 ArrayList (java.util.ArrayList)10 VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)9 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)8 HashMap (java.util.HashMap)8 VolumeDescriptor (com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor)7