Search in sources :

Example 31 with VplexMirror

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

the class VPlexBlockServiceApiImpl method deactivateMirror.

/**
 * {@inheritDoc}
 */
@Override
public TaskList deactivateMirror(StorageSystem vplexStorageSystem, URI mirrorURI, String taskId, String deleteType) {
    TaskList taskList = new TaskList();
    try {
        VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, mirrorURI);
        Volume sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
        Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, mirror.getId().toString());
        taskList.getTaskList().add(toTask(sourceVolume, Arrays.asList(mirror), taskId, op));
        if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
            s_logger.info("Perform ViPR-only delete for VPLEX mirrors %s", mirrorURI);
            // Perform any database cleanup that is required.
            cleanupForViPROnlyMirrorDelete(Arrays.asList(mirrorURI));
            // Mark them inactive.
            _dbClient.markForDeletion(_dbClient.queryObject(VplexMirror.class, mirrorURI));
            // We must get the volume from the DB again, to properly update the status.
            sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
            op = sourceVolume.getOpStatus().get(taskId);
            op.ready("VPLEX continuous copy succesfully deleted from ViPR");
            sourceVolume.getOpStatus().updateTaskStatus(taskId, op);
            _dbClient.updateObject(sourceVolume);
        } else {
            List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
            // Add a descriptor for each of the associated volumes.There will be only one associated volume
            if (mirror.getAssociatedVolumes() != null) {
                for (String assocVolId : mirror.getAssociatedVolumes()) {
                    Volume assocVolume = _dbClient.queryObject(Volume.class, URI.create(assocVolId));
                    if (assocVolume != null && !assocVolume.getInactive() && assocVolume.getNativeId() != null) {
                        // In order to add descriptor for the the backend volumes that needs to be
                        // deleted we are checking for volume nativeId as well, because its possible
                        // that we were not able to create backend volume due to SMIS communication
                        // and rollback didn't clean up VplexMirror and its associated volumes in
                        // database. So in such a case nativeId will be null and we just want to skip
                        // sending this volume to SMIS, else it fails with null reference when user
                        // attempts to cleanup this failed mirror.
                        VolumeDescriptor assocDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, assocVolume.getStorageController(), assocVolume.getId(), null, null);
                        descriptors.add(assocDesc);
                    }
                }
            }
            VPlexController controller = getController();
            controller.deactivateMirror(vplexStorageSystem.getId(), mirror.getId(), descriptors, taskId);
        }
    } catch (ControllerException e) {
        String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
        s_logger.error(errorMsg, e);
        for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(errorMsg);
            _dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, e);
        }
    } catch (Exception e) {
        String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
        s_logger.error(errorMsg, e);
        ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(sc.getMessage());
            _dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, sc);
        }
    }
    return taskList;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) VPlexController(com.emc.storageos.vplexcontroller.VPlexController) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) VplexMirror(com.emc.storageos.db.client.model.VplexMirror)

Example 32 with VplexMirror

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

the class VPlexBlockServiceApiImpl method addDescriptorsForVplexMirrors.

public void addDescriptorsForVplexMirrors(List<VolumeDescriptor> descriptors, Volume vplexVolume) {
    if (vplexVolume.getMirrors() != null && vplexVolume.getMirrors().isEmpty() == false) {
        for (String mirrorId : vplexVolume.getMirrors()) {
            VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, URI.create(mirrorId));
            if (mirror != null && !mirror.getInactive()) {
                if (null != mirror.getAssociatedVolumes()) {
                    for (String assocVolumeId : mirror.getAssociatedVolumes()) {
                        Volume volume = _dbClient.queryObject(Volume.class, URI.create(assocVolumeId));
                        if (volume != null && !volume.getInactive()) {
                            VolumeDescriptor volDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, volume.getStorageController(), URI.create(assocVolumeId), null, null);
                            descriptors.add(volDesc);
                        }
                    }
                }
            }
        }
    }
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) Volume(com.emc.storageos.db.client.model.Volume) VplexMirror(com.emc.storageos.db.client.model.VplexMirror)

Example 33 with VplexMirror

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

the class BlockService method validateContinuousCopyName.

private void validateContinuousCopyName(String name, Integer count, Volume sourceVolume) {
    if (sourceVolume.getMirrors() == null || sourceVolume.getMirrors().isEmpty()) {
        return;
    }
    boolean vplexVolume = checkIfVolumeIsForVplex(sourceVolume.getId());
    List<String> dupList = new ArrayList<String>();
    for (String mirrorURI : sourceVolume.getMirrors()) {
        if (vplexVolume) {
            VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, URI.create(mirrorURI));
            if (!mirror.getInactive() && ((count > 1 && mirror.getLabel().matches("^" + name + "\\-\\d+$")) || (count == 1 && name.equals(mirror.getLabel())))) {
                dupList.add(mirror.getLabel());
            }
        } else {
            BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(mirrorURI));
            if (null != mirror && !mirror.getInactive() && ((count > 1 && mirror.getLabel().matches("^" + name + "\\-\\d+$")) || (count == 1 && name.equals(mirror.getLabel())))) {
                dupList.add(mirror.getLabel());
            }
        }
    }
    if (!dupList.isEmpty()) {
        throw APIException.badRequests.blockSourceAlreadyHasContinuousCopiesOfSameName(dupList);
    }
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) ArrayList(java.util.ArrayList) VplexMirror(com.emc.storageos.db.client.model.VplexMirror)

Example 34 with VplexMirror

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

the class BlockService method stopVplexMirrors.

/**
 * Stop the specified vplex mirror(s) for the source volume
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param copyID
 *            Copy volume ID, none specified stops all copies
 *
 * @return TaskList
 */
private TaskList stopVplexMirrors(URI id, URI copyID) {
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    Volume sourceVolume = queryVolumeResource(id);
    ArgValidator.checkEntity(sourceVolume, id, true);
    StringSet mirrors = sourceVolume.getMirrors();
    if (mirrors == null || mirrors.isEmpty()) {
        throw APIException.badRequests.invalidParameterVolumeHasNoContinuousCopies(sourceVolume.getId());
    }
    ArrayList<URI> mirrorList = null;
    if (copyID != null) {
        ArgValidator.checkFieldUriType(copyID, VplexMirror.class, "copyID");
        VplexMirror mirror = queryVplexMirror(copyID);
        ArgValidator.checkEntity(mirror, copyID, true);
        if (!mirror.getSource().getURI().equals(id)) {
            throw APIException.badRequests.invalidParameterBlockCopyDoesNotBelongToVolume(copyID, id);
        } else {
            mirrorList = new ArrayList();
            mirrorList.add(mirror.getId());
        }
    }
    String task = UUID.randomUUID().toString();
    BlockServiceApi blockServiceApi;
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, sourceVolume.getStorageController());
    blockServiceApi = getBlockServiceImpl(DiscoveredDataObject.Type.vplex.name());
    return blockServiceApi.stopNativeContinuousCopies(storageSystem, sourceVolume, mirrorList, task);
}
Also used : MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 35 with VplexMirror

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

the class BlockService method getNativeContinuousCopies.

/**
 * List volume mirrors
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Volume to list mirrors
 *
 * @brief List volume mirrors
 * @return Volume mirror response containing a list of mirror identifiers
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public MirrorList getNativeContinuousCopies(@PathParam("id") URI id) {
    MirrorList list = new MirrorList();
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    Volume sourceVolume = queryVolumeResource(id);
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    StringSet sourceVolumeMirrors = sourceVolume.getMirrors();
    if (sourceVolumeMirrors == null || sourceVolumeMirrors.isEmpty()) {
        return list;
    }
    for (String uriStr : sourceVolumeMirrors) {
        if (vplexVolume) {
            VplexMirror vplexMirror = _dbClient.queryObject(VplexMirror.class, URI.create(uriStr));
            if (vplexMirror == null || vplexMirror.getInactive()) {
                _log.warn("Stale mirror {} found for volume {}", uriStr, sourceVolume.getId());
                continue;
            }
            list.getMirrorList().add(toNamedRelatedResource(vplexMirror));
        } else {
            BlockMirror blockMirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
            if (blockMirror == null || blockMirror.getInactive()) {
                _log.warn("Stale mirror {} found for volume {}", uriStr, sourceVolume.getId());
                continue;
            }
            list.getMirrorList().add(toNamedRelatedResource(blockMirror));
        }
    }
    return list;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) MirrorList(com.emc.storageos.model.block.MirrorList) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

VplexMirror (com.emc.storageos.db.client.model.VplexMirror)36 Volume (com.emc.storageos.db.client.model.Volume)31 NamedURI (com.emc.storageos.db.client.model.NamedURI)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 URI (java.net.URI)15 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 URISyntaxException (java.net.URISyntaxException)12 ArrayList (java.util.ArrayList)12 StringSet (com.emc.storageos.db.client.model.StringSet)11 VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)11 WorkflowException (com.emc.storageos.workflow.WorkflowException)11 IOException (java.io.IOException)11 VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)10 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)8 VolumeDescriptor (com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor)7 HashMap (java.util.HashMap)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5