Search in sources :

Example 1 with FCTN_VPLEX_MIRROR_TO_URI

use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method startNativeContinuousCopies.

/**
 * {@inheritDoc}
 */
@Override
public TaskList startNativeContinuousCopies(StorageSystem vplexStorageSystem, Volume vplexVolume, VirtualPool sourceVirtualPool, VirtualPoolCapabilityValuesWrapper capabilities, NativeContinuousCopyCreate param, String taskId) throws ControllerException {
    // using the target volume of a block snapshot.
    if (VPlexUtil.isVolumeBuiltOnBlockSnapshot(_dbClient, vplexVolume)) {
        throw APIException.badRequests.mirrorNotAllowedVolumeIsExposedSnapshot(vplexVolume.getId().toString());
    }
    validateNotAConsistencyGroupVolume(vplexVolume, sourceVirtualPool);
    TaskList taskList = new TaskList();
    // Currently, For Vplex Local Volume this will create a single mirror and add it
    // to the vplex volume. For Vplex Distributed Volume this will create single mirror
    // on source and/or HA side and add it to the vplex volume. Two steps: first place
    // the mirror and then prepare the mirror.
    URI vplexStorageSystemURI = vplexVolume.getStorageController();
    // For VPLEX Local volume there will be only one associated volume entry in this set.
    StringSet associatedVolumeIds = vplexVolume.getAssociatedVolumes();
    if (associatedVolumeIds == null) {
        throw InternalServerErrorException.internalServerErrors.noAssociatedVolumesForVPLEXVolume(vplexVolume.forDisplay());
    }
    VirtualPool sourceMirrorVPool = null;
    // Set source mirror vpool
    if (!isNullOrEmpty(sourceVirtualPool.getMirrorVirtualPool()) && !NullColumnValueGetter.isNullURI(URI.create(sourceVirtualPool.getMirrorVirtualPool()))) {
        sourceMirrorVPool = _dbClient.queryObject(VirtualPool.class, URI.create(sourceVirtualPool.getMirrorVirtualPool()));
    }
    // Check if volume is distributed and if HA Mirror Vpool is also set
    VirtualPool haMirrorVPool = VPlexUtil.getHAMirrorVpool(sourceVirtualPool, associatedVolumeIds, _dbClient);
    // Map of backend volume and the mirror pool to target backend volume for the mirror
    Map<Volume, VirtualPool> backendVolumeToMirrorVpoolMap = new HashMap<Volume, VirtualPool>();
    if (associatedVolumeIds.size() > 1) {
        // If associatedVolumeIds size is greater than 1 then its a VPLEX Distributed Volume
        updateBackendVolumeToMirrorVpoolMap(vplexVolume, associatedVolumeIds, sourceVirtualPool, sourceMirrorVPool, haMirrorVPool, backendVolumeToMirrorVpoolMap);
    } else {
        // If we are here that means we need to create mirror for the VPLEX local volume
        for (String associatedVolumeId : associatedVolumeIds) {
            Volume associatedVolume = _dbClient.queryObject(Volume.class, URI.create(associatedVolumeId));
            if (associatedVolume != null) {
                backendVolumeToMirrorVpoolMap.put(associatedVolume, sourceMirrorVPool);
            }
        }
    }
    // Project is not passed in continuous copies call.
    // Implicit assumption to use same project as the source volume.
    Project project = _permissionsHelper.getObjectById(vplexVolume.getProject(), Project.class);
    Map<Volume, List<Recommendation>> backendvolumeToMirrorRecommendationMap = new HashMap<Volume, List<Recommendation>>();
    Map<Volume, VirtualArray> backendvolumeToMirrorVarrayMap = new HashMap<Volume, VirtualArray>();
    for (Volume backendVolume : backendVolumeToMirrorVpoolMap.keySet()) {
        URI backendVolumeVarrayURI = backendVolume.getVirtualArray();
        // Get the VPLEX cluster value from the varray
        String cluster = ConnectivityUtil.getVplexClusterForVarray(backendVolumeVarrayURI, vplexStorageSystemURI, _dbClient);
        if (cluster.equals(ConnectivityUtil.CLUSTER_UNKNOWN)) {
            throw InternalServerErrorException.internalServerErrors.noVplexClusterInfoForVarray(backendVolumeVarrayURI.toString(), vplexStorageSystemURI.toString());
        }
        VirtualPool backendVolumeVpool = _dbClient.queryObject(VirtualPool.class, backendVolume.getVirtualPool());
        VirtualPool mirrorVpool = backendVolumeToMirrorVpoolMap.get(backendVolume);
        // Get recommendations for the mirror placement
        List<Recommendation> volumeRecommendations = null;
        VirtualArray varray = null;
        if (mirrorVpool != null) {
            // If mirror vpool is provided try to get recommendations using the provided mirror vpool
            // Check if any of the varray for mirror vpool is same as that of the source volume varray.
            // If yes then get recommendations using that varray.
            StringSet mirrorVPoolVarrays = mirrorVpool.getVirtualArrays();
            boolean foundMatch = false;
            for (String mirrorVPoolVarrayId : mirrorVPoolVarrays) {
                if (mirrorVPoolVarrayId.equals(backendVolumeVarrayURI.toString())) {
                    varray = _dbClient.queryObject(VirtualArray.class, backendVolumeVarrayURI);
                    volumeRecommendations = _scheduler.getRecommendationsForMirrors(varray, project, backendVolumeVpool, mirrorVpool, capabilities, vplexStorageSystemURI, backendVolume.getStorageController(), cluster);
                    foundMatch = true;
                    break;
                }
            }
            if (!foundMatch) {
                s_logger.info("Mirror Vpool varray is different than the source vpool varray");
                // with the source volume VPLEX system.
                for (String mirrorVPoolVarrayId : mirrorVPoolVarrays) {
                    if (VPlexUtil.checkIfVarrayContainsSpecifiedVplexSystem(mirrorVPoolVarrayId, cluster, vplexStorageSystemURI, _dbClient)) {
                        varray = _dbClient.queryObject(VirtualArray.class, URI.create(mirrorVPoolVarrayId));
                        volumeRecommendations = _scheduler.getRecommendationsForMirrors(varray, project, backendVolumeVpool, mirrorVpool, capabilities, vplexStorageSystemURI, backendVolume.getStorageController(), cluster);
                        if (!volumeRecommendations.isEmpty()) {
                            foundMatch = true;
                            break;
                        } else {
                            s_logger.info("Tried to get recommemdations using varray {} {}. ", varray.getId(), varray.getLabel());
                        }
                    }
                }
            }
        } else {
            if (sourceVirtualPool.getHighAvailability().equals(VirtualPool.HighAvailabilityType.vplex_local.name())) {
                s_logger.info("Mirror vpool is not specified, use the source volume virtual pool and virtual array");
                // In case of Vplex local if mirror pool is not provided then we can use source vpool as mirror vpool.
                sourceMirrorVPool = backendVolumeVpool;
                mirrorVpool = backendVolumeVpool;
                backendVolumeToMirrorVpoolMap.put(backendVolume, sourceMirrorVPool);
                // Separate Mirror vpool is not provided so use the source volume vpool and varray for
                // getting recommendations.Here sourceVirtualPool and mirrorVPool will be same.
                varray = _dbClient.queryObject(VirtualArray.class, backendVolumeVarrayURI);
                volumeRecommendations = _scheduler.getRecommendationsForMirrors(varray, project, backendVolumeVpool, mirrorVpool, capabilities, vplexStorageSystemURI, backendVolume.getStorageController(), cluster);
            }
        }
        if (mirrorVpool == null) {
            throw APIException.badRequests.noMirrorVpoolForVplexVolume(vplexVolume.getLabel());
        }
        if (varray == null) {
            throw APIException.badRequests.noVarrayForMirrorVpoolWithExpectedVplex(mirrorVpool.getLabel(), vplexStorageSystem.getLabel(), cluster);
        }
        if (volumeRecommendations == null || volumeRecommendations.isEmpty()) {
            if (volumeRecommendations.isEmpty()) {
                StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, backendVolume.getStorageController());
                throw APIException.badRequests.noMatchingStoragePoolsForContinuousCopiesVpoolForVplex(varray.getLabel(), sourceMirrorVPool.getLabel(), storageSystem.getLabel());
            }
        }
        // Add mirror recommendations for the backend volume to the map
        backendvolumeToMirrorRecommendationMap.put(backendVolume, volumeRecommendations);
        backendvolumeToMirrorVarrayMap.put(backendVolume, varray);
    }
    // Prepare mirror.
    int varrayCount = 0;
    int volumeCounter = 1;
    // volumeCount will be always 1 for now
    int volumeCount = capabilities.getResourceCount();
    String volumeLabel = param.getName();
    List<URI> allVolumes = new ArrayList<URI>();
    List<URI> allMirrors = new ArrayList<URI>();
    List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
    // Currently only one local mirror is supported for the VPLEX local virtual volume
    List<VplexMirror> preparedMirrors = new ArrayList<VplexMirror>();
    for (Volume backendVolume : backendvolumeToMirrorRecommendationMap.keySet()) {
        List<Recommendation> volumeRecommendations = backendvolumeToMirrorRecommendationMap.get(backendVolume);
        VirtualArray varray = backendvolumeToMirrorVarrayMap.get(backendVolume);
        VirtualPool mirrorVpool = backendVolumeToMirrorVpoolMap.get(backendVolume);
        long thinVolumePreAllocationSize = 0;
        if (null != mirrorVpool.getThinVolumePreAllocationPercentage()) {
            thinVolumePreAllocationSize = VirtualPoolUtil.getThinVolumePreAllocationSize(mirrorVpool.getThinVolumePreAllocationPercentage(), vplexVolume.getCapacity());
        }
        for (Recommendation volumeRecommendation : volumeRecommendations) {
            VPlexRecommendation vplexRecommendation = (VPlexRecommendation) volumeRecommendation;
            StringBuilder mirrorLabelBuilder = new StringBuilder(volumeLabel);
            if (backendVolume.getVirtualArray().equals(vplexVolume.getVirtualArray())) {
                varrayCount = 0;
            } else {
                varrayCount = 1;
            }
            mirrorLabelBuilder.append('-').append(varrayCount);
            if (volumeCount > 1) {
                mirrorLabelBuilder.append('-').append(volumeCounter++);
            }
            // Create mirror object
            VplexMirror createdMirror = initializeMirror(vplexVolume, mirrorVpool, varray, mirrorLabelBuilder.toString(), thinVolumePreAllocationSize, _dbClient);
            preparedMirrors.add(createdMirror);
            Operation op = _dbClient.createTaskOpStatus(VplexMirror.class, createdMirror.getId(), taskId, ResourceOperationTypeEnum.ATTACH_VPLEX_LOCAL_MIRROR);
            s_logger.info("Prepared mirror {}", createdMirror.getId());
            allMirrors.add(createdMirror.getId());
            // Add descriptor for the mirror.
            VolumeDescriptor descriptor = new VolumeDescriptor(VolumeDescriptor.Type.VPLEX_LOCAL_MIRROR, vplexStorageSystemURI, createdMirror.getId(), null, capabilities);
            descriptors.add(descriptor);
            // Create backend volume object and add it to the VplexMirror created above.
            Volume volume = prepareVolume(createdMirror, backendVolume, mirrorVpool, varray, vplexRecommendation.getSourceStorageSystem(), vplexRecommendation.getSourceStoragePool(), mirrorLabelBuilder.toString(), thinVolumePreAllocationSize, capabilities, _dbClient);
            op = new Operation();
            op.setResourceType(ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
            _dbClient.createTaskOpStatus(Volume.class, volume.getId(), taskId, op);
            URI volumeId = volume.getId();
            allVolumes.add(volumeId);
            s_logger.info("Prepared volume {}", volumeId);
            // Add descriptor for the backend volume
            descriptor = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, vplexRecommendation.getSourceStorageSystem(), volumeId, vplexRecommendation.getSourceStoragePool(), capabilities);
            descriptors.add(descriptor);
        }
    }
    Collection<URI> mirrorTargetIds = Collections2.transform(preparedMirrors, FCTN_VPLEX_MIRROR_TO_URI);
    String mirrorTargetCommaDelimList = Joiner.on(',').join(mirrorTargetIds);
    Operation op = _dbClient.createTaskOpStatus(Volume.class, vplexVolume.getId(), taskId, ResourceOperationTypeEnum.ATTACH_VPLEX_LOCAL_MIRROR, mirrorTargetCommaDelimList);
    taskList.getTaskList().add(toTask(vplexVolume, preparedMirrors, taskId, op));
    try {
        VPlexController controller = getController();
        controller.attachContinuousCopies(vplexStorageSystem.getId(), descriptors, vplexVolume.getId(), taskId);
    } catch (InternalException e) {
        if (s_logger.isErrorEnabled()) {
            s_logger.error("Controller error", e);
        }
        String errMsg = String.format("Controller error: %s", e.getMessage());
        for (URI volumeURI : allVolumes) {
            _dbClient.error(Volume.class, volumeURI, taskId, e);
        }
        for (URI mirrorURI : allMirrors) {
            _dbClient.error(VplexMirror.class, mirrorURI, taskId, e);
        }
        for (TaskResourceRep volumeTask : taskList.getTaskList()) {
            volumeTask.setState(Operation.Status.error.name());
            volumeTask.setMessage(errMsg);
        }
        throw e;
    }
    return taskList;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) VPlexController(com.emc.storageos.vplexcontroller.VPlexController) HashMap(java.util.HashMap) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FCTN_VPLEX_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI) StringSet(com.emc.storageos.db.client.model.StringSet) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) VolumeGroupVolumeList(com.emc.storageos.model.application.VolumeGroupUpdateParam.VolumeGroupVolumeList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystemConnectivityList(com.emc.storageos.model.systems.StorageSystemConnectivityList) List(java.util.List) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) VPlexRecommendation(com.emc.storageos.volumecontroller.VPlexRecommendation) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) SRDFCopyRecommendation(com.emc.storageos.volumecontroller.SRDFCopyRecommendation) VolumeRecommendation(com.emc.storageos.api.service.impl.placement.VolumeRecommendation) VPlexRecommendation(com.emc.storageos.volumecontroller.VPlexRecommendation) Recommendation(com.emc.storageos.volumecontroller.Recommendation) SRDFRecommendation(com.emc.storageos.volumecontroller.SRDFRecommendation) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume)

Aggregations

VolumeRecommendation (com.emc.storageos.api.service.impl.placement.VolumeRecommendation)1 VolumeDescriptor (com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Operation (com.emc.storageos.db.client.model.Operation)1 Project (com.emc.storageos.db.client.model.Project)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 Volume (com.emc.storageos.db.client.model.Volume)1 VplexMirror (com.emc.storageos.db.client.model.VplexMirror)1 FCTN_STRING_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI)1 FCTN_VPLEX_MIRROR_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI)1 TaskList (com.emc.storageos.model.TaskList)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1