Search in sources :

Example 46 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class BlockMirrorServiceApiImpl method stopNativeContinuousCopies.

@Override
public TaskList stopNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, List<URI> mirrors, String taskId) throws ControllerException {
    TaskList taskList = new TaskList();
    List<URI> copiesToStop = null;
    List<BlockMirror> copies = null;
    Map<BlockMirror, Volume> groupMirrorSourceMap = null;
    boolean isCG = sourceVolume.isInCG();
    if (isCG) {
        if (mirrors == null) {
            for (String uriStr : sourceVolume.getMirrors()) {
                BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
                if (!mirror.getInactive()) {
                    groupMirrorSourceMap = getGroupMirrorSourceMap(mirror, sourceVolume);
                    // only process one mirror group
                    break;
                }
            }
        } else {
            groupMirrorSourceMap = getGroupMirrorSourceMap(mirrors.get(0), sourceVolume);
        }
        if (groupMirrorSourceMap == null || groupMirrorSourceMap.isEmpty()) {
            Operation op = new Operation();
            op.ready();
            op.setResourceType(ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
            op.setMessage("No continuous copy can be detached");
            _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
            taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
            return taskList;
        }
        copiesToStop = new ArrayList<URI>(transform(groupMirrorSourceMap.keySet(), FCTN_MIRROR_TO_URI));
    } else {
        List<BlockMirror> blockMirrors = null;
        if (mirrors != null) {
            blockMirrors = new ArrayList<BlockMirror>();
            for (URI mirrorURI : mirrors) {
                BlockMirror blockMirror = _dbClient.queryObject(BlockMirror.class, mirrorURI);
                blockMirrors.add(blockMirror);
            }
        }
        copiesToStop = getCopiesToStop(blockMirrors, sourceVolume);
        // Ensure we don't attempt to stop any lingering inactive copies
        removeIf(copiesToStop, isMirrorInactivePredicate());
        if (copiesToStop.size() == 0) {
            Operation op = new Operation();
            op.ready();
            op.setResourceType(ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
            op.setMessage("No continuous copy can be detached");
            _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
            taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
            return taskList;
        }
    }
    copies = _dbClient.queryObject(BlockMirror.class, copiesToStop);
    // Stopped copies will be promoted to regular block volumes
    List<URI> promotees = preparePromotedVolumes(copies, taskList, taskId);
    if (!isCG) {
        String mirrorTargetCommaDelimList = Joiner.on(',').join(copiesToStop);
        Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR, mirrorTargetCommaDelimList);
        taskList.getTaskList().add(toTask(sourceVolume, copies, taskId, op));
    } else {
        populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
    }
    BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
    try {
        controller.detachNativeContinuousCopies(storageSystem.getId(), copiesToStop, promotees, taskId);
    } catch (ControllerException ce) {
        String errorMsg = format("Failed to stop continuous copies for volume %s: %s", sourceVolume.getId(), ce.getMessage());
        List<Volume> volumes = _dbClient.queryObject(Volume.class, promotees);
        for (Volume volume : volumes) {
            volume.setInactive(true);
        }
        _dbClient.persistObject(volumes);
        _log.error(errorMsg, ce);
        for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(errorMsg);
            _dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, ce);
        }
        throw ce;
    }
    return taskList;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) FCTN_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI) URI(java.net.URI) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) Volume(com.emc.storageos.db.client.model.Volume) List(java.util.List) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 47 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class BlockSnapshotService method activate.

/**
 * Call will activate this snapshot, essentially establishing the synchronization
 * between the source and target. The "heavy lifting" of getting the snapshot
 * to the point where it can be activated should have been done by the create.
 *
 * @prereq Create snapshot as inactive
 * @param id [required] - the URN of a ViPR block snapshot to restore from
 * @brief Activate snapshot
 * @return TaskResourceRep - Task resource object for tracking this operation
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
@Path("/{id}/activate")
public TaskResourceRep activate(@PathParam("id") URI id) {
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT);
    ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
    BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
    // Get the block service API implementation for the snapshot parent volume.
    Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
    // Make sure that we don't have some pending
    // operation against the parent volume
    checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), Arrays.asList(parentVolume));
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
    BlockController controller = getController(BlockController.class, device.getSystemType());
    String task = UUID.randomUUID().toString();
    // another request to activate it again.
    if (snapshot.getIsSyncActive()) {
        op.ready("Snapshot is already active");
        _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
        return toTask(snapshot, task, op);
    }
    _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
    List<URI> snapshotList = new ArrayList<URI>();
    if (!NullColumnValueGetter.isNullURI(snapshot.getConsistencyGroup())) {
        List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
        for (BlockSnapshot snap : snapshots) {
            snapshotList.add(snap.getId());
        }
    } else {
        snapshotList.add(id);
    }
    // If the volume is under protection
    if (snapshot.getEmName() != null) {
        // RP snapshots cannot be activated so throw exception
        throw new ServiceCodeException(API_BAD_REQUEST, "RecoverPoint snapshots cannot be activated.", null);
    } else {
        controller.activateSnapshot(device.getId(), snapshotList, task);
    }
    auditOp(OperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
    return toTask(snapshot, task, op);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockController(com.emc.storageos.volumecontroller.BlockController) MapBlockSnapshot(com.emc.storageos.api.mapper.functions.MapBlockSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 48 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class AbstractBlockServiceApiImpl method resynchronizeSnapshot.

/**
 * Resynchronize the passed snapshot from its parent volume.
 *
 * @param snapshot
 *            The snapshot to be resynchronized
 * @param parentVolume
 *            The volume to be resynchronized from.
 * @param taskId
 *            The unique task identifier.
 */
@Override
public void resynchronizeSnapshot(BlockSnapshot snapshot, Volume parentVolume, String taskId) {
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
    BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
    controller.resyncSnapshot(storageSystem.getId(), parentVolume.getId(), snapshot.getId(), Boolean.TRUE, taskId);
}
Also used : BlockController(com.emc.storageos.volumecontroller.BlockController) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

BlockController (com.emc.storageos.volumecontroller.BlockController)48 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 Operation (com.emc.storageos.db.client.model.Operation)23 URI (java.net.URI)23 ArrayList (java.util.ArrayList)20 TaskList (com.emc.storageos.model.TaskList)16 Produces (javax.ws.rs.Produces)15 Volume (com.emc.storageos.db.client.model.Volume)13 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)13 Path (javax.ws.rs.Path)13 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 Consumes (javax.ws.rs.Consumes)12 POST (javax.ws.rs.POST)11 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)10 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 NamedURI (com.emc.storageos.db.client.model.NamedURI)8 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)8 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)8 Controller (com.emc.storageos.Controller)7 DiscoveredObjectTaskScheduler (com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler)7