Search in sources :

Example 31 with Migration

use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.

the class MigrationService method migrateVolume.

/**
 * Performs a non-disruptive migration for the passed VPLEX virtual volume.
 * The backend volume of the VPLEX volume that is migrated is the backend
 * volume on the passed source storage system. The volume is migrated to the
 * passed target storage system, which must be connected to the same VPLEX
 * cluster as the source storage system.
 *
 * @prereq none
 *
 * @param migrateParam A reference to the migration parameters.
 * @deprecated Use the Change Virtual Pool API instead
 * @brief Perform a non-disruptive migration for a VPLEX volume.
 * @return A TaskResourceRep for the volume being migrated.
 * @throws InternalException
 */
@Deprecated
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_ADMIN })
public TaskResourceRep migrateVolume(MigrationParam migrateParam) throws InternalException {
    // Create a unique task id.
    String taskId = UUID.randomUUID().toString();
    s_logger.info("Migrate volume {} from storage system {} to storage system {}", new Object[] { migrateParam.getVolume(), migrateParam.getSrcStorageSystem(), migrateParam.getTgtStorageSystem() });
    // Verify the requested volume supports migration.
    Volume vplexVolume = verifyRequestedVolumeSupportsMigration(migrateParam.getVolume());
    s_logger.debug("Verfified requested volume");
    // Make sure that we don't have some pending
    // operation against the volume
    checkForPendingTasks(Arrays.asList(vplexVolume.getTenant().getURI()), Arrays.asList(vplexVolume));
    // Determine the backend volume of the requested VPlex volume that
    // is to be migrated. It is the volume on the passed source storage
    // system.
    Volume migrationSrc = getMigrationSource(vplexVolume, migrateParam.getSrcStorageSystem());
    s_logger.debug("Migration source is {}", migrationSrc.getId());
    // The project for the migration target will be the same as that
    // of the source.
    Project migrationTgtProject = _permissionsHelper.getObjectById(migrationSrc.getProject().getURI(), Project.class);
    s_logger.debug("Migration target project is {}", migrationTgtProject.getId());
    // The VirtualArray for the migration target will be the same as
    // that of the source.
    VirtualArray migrationTargetVarray = _permissionsHelper.getObjectById(migrationSrc.getVirtualArray(), VirtualArray.class);
    s_logger.debug("Migration target VirtualArray is {}", migrationTargetVarray.getId());
    // Verify the requested target storage system exists and
    // is a system to which the migration source volume can
    // be migrated.
    verifyTargetStorageSystemForMigration(migrateParam.getVolume(), vplexVolume.getStorageController(), migrateParam.getSrcStorageSystem(), migrateParam.getTgtStorageSystem());
    s_logger.debug("Verified target storage system {}", migrateParam.getTgtStorageSystem());
    // Get the VirtualPool for the migration target.
    VirtualPool migrationTgtCos = getVirtualPoolForMigrationTarget(migrateParam.getVirtualPool(), vplexVolume, migrationSrc);
    s_logger.debug("Migration target VirtualPool is {}", migrationTgtCos.getId());
    // Get the VPlex storage system for the virtual volume.
    URI vplexSystemURI = vplexVolume.getStorageController();
    Set<URI> requestedVPlexSystems = new HashSet<URI>();
    requestedVPlexSystems.add(vplexSystemURI);
    // Get a placement recommendation on the requested target storage
    // system connected to the VPlex storage system of the VPlex volume.
    VPlexScheduler vplexScheduler = _vplexBlockServiceApi.getBlockScheduler();
    VirtualPoolCapabilityValuesWrapper cosWrapper = new VirtualPoolCapabilityValuesWrapper();
    cosWrapper.put(VirtualPoolCapabilityValuesWrapper.SIZE, migrationSrc.getCapacity());
    cosWrapper.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
    List<Recommendation> recommendations = vplexScheduler.scheduleStorage(migrationTargetVarray, requestedVPlexSystems, migrateParam.getTgtStorageSystem(), migrationTgtCos, false, null, null, cosWrapper, migrationTgtProject, VpoolUse.ROOT, new HashMap<VpoolUse, List<Recommendation>>());
    if (recommendations.isEmpty()) {
        throw APIException.badRequests.noStorageFoundForVolumeMigration(migrationTgtCos.getLabel(), migrationTargetVarray.getLabel(), vplexVolume.getId());
    }
    s_logger.debug("Got recommendation for migration target");
    // There should be a single recommendation.
    Recommendation recommendation = recommendations.get(0);
    URI recommendedSystem = recommendation.getSourceStorageSystem();
    URI recommendedPool = recommendation.getSourceStoragePool();
    s_logger.debug("Recommendation storage system is {}", recommendedSystem);
    s_logger.debug("Recommendation storage pool is {}", recommendedPool);
    // Prepare the migration target.
    List<URI> migrationTgts = new ArrayList<URI>();
    Map<URI, URI> poolTgtMap = new HashMap<URI, URI>();
    Long size = _vplexBlockServiceApi.getVolumeCapacity(migrationSrc);
    Volume migrationTgt = VPlexBlockServiceApiImpl.prepareVolumeForRequest(size, migrationTgtProject, migrationTargetVarray, migrationTgtCos, recommendedSystem, recommendedPool, migrationSrc.getLabel(), ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME, taskId, _dbClient);
    URI migrationTgtURI = migrationTgt.getId();
    migrationTgts.add(migrationTgtURI);
    poolTgtMap.put(recommendedPool, migrationTgtURI);
    s_logger.debug("Prepared migration target volume {}", migrationTgtURI);
    // Prepare the migration.
    Map<URI, URI> migrationsMap = new HashMap<URI, URI>();
    Migration migration = _vplexBlockServiceApi.prepareMigration(migrateParam.getVolume(), migrationSrc.getId(), migrationTgt.getId(), taskId);
    migrationsMap.put(migrationTgtURI, migration.getId());
    s_logger.debug("Prepared migration {}", migration.getId());
    // Create a task for the virtual volume being migrated and set the
    // initial task state to pending.
    Operation op = _dbClient.createTaskOpStatus(Volume.class, vplexVolume.getId(), taskId, ResourceOperationTypeEnum.MIGRATE_BLOCK_VOLUME);
    TaskResourceRep task = toTask(vplexVolume, taskId, op);
    s_logger.debug("Created task for volume {}", migrateParam.getVolume());
    try {
        VPlexController controller = _vplexBlockServiceApi.getController();
        String successMsg = String.format("Migration succeeded for volume %s", migrateParam.getVolume());
        String failMsg = String.format("Migration failed for volume %s", migrateParam.getVolume());
        controller.migrateVolumes(vplexSystemURI, migrateParam.getVolume(), migrationTgts, migrationsMap, poolTgtMap, (migrateParam.getVirtualPool() != null ? migrateParam.getVirtualPool() : null), null, successMsg, failMsg, null, taskId, null);
        s_logger.debug("Got VPlex controller and created migration workflow");
    } catch (InternalException e) {
        s_logger.error("Controller Error", e);
        String errMsg = String.format("Controller Error: %s", e.getMessage());
        task.setState(Operation.Status.error.name());
        task.setMessage(errMsg);
        Operation opStatus = new Operation(Operation.Status.error.name(), errMsg);
        _dbClient.updateTaskOpStatus(Volume.class, task.getResource().getId(), taskId, opStatus);
        migrationTgt.setInactive(true);
        _dbClient.persistObject(migrationTgt);
        migration.setInactive(true);
        _dbClient.persistObject(migration);
        throw e;
    }
    return task;
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) VPlexController(com.emc.storageos.vplexcontroller.VPlexController) HashMap(java.util.HashMap) Migration(com.emc.storageos.db.client.model.Migration) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) List(java.util.List) ArrayList(java.util.ArrayList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) MigrationList(com.emc.storageos.model.block.MigrationList) HashSet(java.util.HashSet) VpoolUse(com.emc.storageos.api.service.impl.placement.VpoolUse) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Recommendation(com.emc.storageos.volumecontroller.Recommendation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) VPlexScheduler(com.emc.storageos.api.service.impl.placement.VPlexScheduler) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 32 with Migration

use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.

the class MigrationService method pauseMigration.

/**
 * Pause a migration that is in progress.
 *
 * @prereq The migration is in progress
 *
 * @param id the URN of a ViPR migration.
 *
 * @brief Pause a migration.
 * @return A TaskResourceRep
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/pause")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep pauseMigration(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Migration.class, "id");
    Migration migration = queryResource(id);
    if (!BulkList.MigrationFilter.isUserAuthorizedForMigration(migration, getUserFromContext(), _permissionsHelper)) {
        StorageOSUser user = getUserFromContext();
        throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
    }
    String status = migration.getMigrationStatus();
    String migrationName = migration.getLabel();
    if (status == null || status.isEmpty() || migrationName == null || migrationName.isEmpty()) {
        throw APIException.badRequests.migrationHasntStarted(id.toString());
    }
    if (status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.COMPLETE.getStatusValue()) || status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.ERROR.getStatusValue()) || status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.COMMITTED.getStatusValue()) || status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.CANCELLED.getStatusValue())) {
        throw APIException.badRequests.migrationCantBePaused(migrationName, status);
    }
    URI volId = migration.getVolume();
    Volume vplexVol = _dbClient.queryObject(Volume.class, volId);
    // Create a unique task id.
    String taskId = UUID.randomUUID().toString();
    // Create a task for the volume and set the
    // initial task state to pending.
    Operation op = _dbClient.createTaskOpStatus(Volume.class, volId, taskId, ResourceOperationTypeEnum.PAUSE_MIGRATION);
    TaskResourceRep task = toTask(vplexVol, taskId, op);
    if (status.equalsIgnoreCase(VPlexMigrationInfo.MigrationStatus.PAUSED.getStatusValue())) {
        // it has been paused.
        s_logger.info("Migration {} has been paused", id);
        op.ready();
        vplexVol.getOpStatus().createTaskStatus(taskId, op);
        _dbClient.persistObject(vplexVol);
        return task;
    }
    try {
        VPlexController controller = _vplexBlockServiceApi.getController();
        controller.pauseMigration(vplexVol.getStorageController(), id, taskId);
    } catch (InternalException e) {
        s_logger.error("Error", e);
        String errMsg = String.format("Error: %s", e.getMessage());
        task.setState(Operation.Status.error.name());
        task.setMessage(errMsg);
        op.error(e);
        vplexVol.getOpStatus().updateTaskStatus(taskId, op);
        _dbClient.persistObject(vplexVol);
    }
    return task;
}
Also used : VPlexController(com.emc.storageos.vplexcontroller.VPlexController) Volume(com.emc.storageos.db.client.model.Volume) Migration(com.emc.storageos.db.client.model.Migration) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 33 with Migration

use of com.emc.storageos.db.client.model.Migration in project coprhd-controller by CoprHD.

the class MigrationService method queryResource.

/**
 * {@inheritDoc}
 */
@Override
protected Migration queryResource(URI id) {
    ArgValidator.checkUri(id);
    Migration migration = _permissionsHelper.getObjectById(id, Migration.class);
    ArgValidator.checkEntityNotNull(migration, id, isIdEmbeddedInURL(id));
    return migration;
}
Also used : Migration(com.emc.storageos.db.client.model.Migration)

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