Search in sources :

Example 76 with VolumeDescriptor

use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method createVolumeDescriptorsForNativeExpansion.

/**
 * Prep work before the call to orchestrator to create the volume descriptors for volume expand operation
 *
 * @param volumeURIs vplex volumes already prepared
 * @return list of volume descriptors
 */
private List<VolumeDescriptor> createVolumeDescriptorsForNativeExpansion(List<URI> volumeURIs) {
    List<Volume> preparedVolumes = _dbClient.queryObject(Volume.class, volumeURIs);
    List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
    // Package up the Volume descriptors
    for (Volume volume : preparedVolumes) {
        if (null == volume.getAssociatedVolumes() || volume.getAssociatedVolumes().isEmpty()) {
            s_logger.error("VPLEX volume {} has no backend volumes.", volume.forDisplay());
            throw InternalServerErrorException.internalServerErrors.noAssociatedVolumesForVPLEXVolume(volume.forDisplay());
        }
        for (String associatedVolumeStr : volume.getAssociatedVolumes()) {
            Volume associatedVolume = _dbClient.queryObject(Volume.class, URI.create(associatedVolumeStr));
            if (associatedVolume.isSRDFSource()) {
                // SRDF Source Volume
                SRDFBlockServiceApiImpl srdfApi = (SRDFBlockServiceApiImpl) BlockService.getBlockServiceImpl("srdf");
                List<VolumeDescriptor> srdfDescriptors = srdfApi.getVolumeDescriptorsForExpandVolume(associatedVolume, associatedVolume.getProvisionedCapacity());
                descriptors.addAll(srdfDescriptors);
                // Check to see if any of the SRDF targets are VPlex protected, and if so add them.
                List<VolumeDescriptor> srdfTargetDescriptors = VolumeDescriptor.filterByType(srdfDescriptors, VolumeDescriptor.Type.SRDF_TARGET);
                for (VolumeDescriptor targetDescriptor : srdfTargetDescriptors) {
                    Volume targetVolume = _dbClient.queryObject(Volume.class, targetDescriptor.getVolumeURI());
                    Volume vplexTargetVolume = VPlexSrdfUtil.getVplexVolumeFromSrdfVolume(_dbClient, targetVolume);
                    if (vplexTargetVolume != null) {
                        // Recursively add what is needed for the target vplex encapsulation.
                        List<VolumeDescriptor> vplexTargetDescriptors = createVolumeDescriptorsForNativeExpansion(Arrays.asList(vplexTargetVolume.getId()));
                        descriptors.addAll(vplexTargetDescriptors);
                    }
                }
            } else if (!NullColumnValueGetter.isNullNamedURI(associatedVolume.getSrdfParent())) {
                s_logger.info("Ignoring associated volume that is SRDF target: " + associatedVolume.getLabel());
            } else {
                // A nice, plain, simple backing volume
                VolumeDescriptor descriptor = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, associatedVolume.getStorageController(), associatedVolume.getId(), associatedVolume.getPool(), null, null, associatedVolume.getCapacity());
                descriptors.add(descriptor);
            }
        }
        // A descriptor for the top level Vplex virtual volume
        VolumeDescriptor desc = new VolumeDescriptor(VolumeDescriptor.Type.VPLEX_VIRT_VOLUME, volume.getStorageController(), volume.getId(), volume.getPool(), null, null, volume.getCapacity());
        descriptors.add(desc);
    }
    return descriptors;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList)

Example 77 with VolumeDescriptor

use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method expandVolume.

/**
 * {@inheritDoc}
 */
@Override
public void expandVolume(Volume vplexVolume, long newSize, String taskId) throws InternalException {
    URI vplexURI = vplexVolume.getStorageController();
    if (isNativeVolumeExpansionSupported(vplexVolume, newSize)) {
        // Expand the passed VPlex virtual volume by natively
        // expanding the backend volume(s).
        // TODO: At the moment, native expansion go via block orchestration controller. JIRA CTRL-5336 filed for this.
        // Expand via migration still follows the old way of doing things and this needs to be changed.
        s_logger.info("VPLEX volume {} will be expanded natively.", vplexVolume.getId());
        List<VolumeDescriptor> volumeDescriptors = createVolumeDescriptorsForNativeExpansion(Arrays.asList(vplexVolume.getId()));
        BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
        for (VolumeDescriptor volDesc : volumeDescriptors) {
            volDesc.setVolumeSize(newSize);
        }
        controller.expandVolume(volumeDescriptors, taskId);
    } else {
        // A list of the volumes satisfying the new size to
        // which the data on the current backend volumes
        // will be migrated.
        s_logger.info("VPLEX volume {} will be expanded by migration.", vplexVolume.getId());
        List<URI> newVolumes = new ArrayList<URI>();
        // A Map containing a migration for each new backend
        // volume
        Map<URI, URI> migrationMap = new HashMap<URI, URI>();
        // A map that specifies the storage pool in which
        // each new volume should be created.
        Map<URI, URI> poolVolumeMap = new HashMap<URI, URI>();
        // Get the VPlex system.
        StorageSystem vplexSystem = _permissionsHelper.getObjectById(vplexURI, StorageSystem.class);
        // Prepare the backend volume(s) for migration.
        StringSet assocVolumeIds = vplexVolume.getAssociatedVolumes();
        if (null == assocVolumeIds || assocVolumeIds.isEmpty()) {
            s_logger.error("VPLEX volume {} has no backend volumes.", vplexVolume.forDisplay());
            throw InternalServerErrorException.internalServerErrors.noAssociatedVolumesForVPLEXVolume(vplexVolume.forDisplay());
        }
        for (String assocVolumeId : assocVolumeIds) {
            Volume assocVolume = _permissionsHelper.getObjectById(URI.create(assocVolumeId), Volume.class);
            VirtualArray assocVolumeNH = _permissionsHelper.getObjectById(assocVolume.getVirtualArray(), VirtualArray.class);
            VirtualPool assocVolumeCos = _permissionsHelper.getObjectById(assocVolume.getVirtualPool(), VirtualPool.class);
            prepareBackendVolumeForMigration(vplexSystem, vplexVolume, assocVolume, assocVolumeNH, assocVolumeCos, newSize, taskId, newVolumes, migrationMap, poolVolumeMap);
        }
        // Use the VPlex controller to expand the passed VPlex virtual
        // volume by migrating the backend volume(s) to the migration
        // target(s) of the new size.
        VPlexController controller = getController();
        controller.expandVolumeUsingMigration(vplexURI, vplexVolume.getId(), newVolumes, migrationMap, poolVolumeMap, newSize, taskId);
    }
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) BlockOrchestrationController(com.emc.storageos.blockorchestrationcontroller.BlockOrchestrationController) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) VPlexController(com.emc.storageos.vplexcontroller.VPlexController) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) 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) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 78 with VolumeDescriptor

use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method getDescriptorsForVolumesToBeDeleted.

/**
 * {@inheritDoc}
 */
@Override
public List<VolumeDescriptor> getDescriptorsForVolumesToBeDeleted(URI systemURI, List<URI> volumeURIs, String deletionType) {
    List<VolumeDescriptor> volumeDescriptors = new ArrayList<VolumeDescriptor>();
    for (URI volumeURI : volumeURIs) {
        Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
        if (!volume.isVPlexVolume(_dbClient)) {
            // We can get invoked on a vplex backend volume (because of the vpool) when
            // trying to clean up failed deletions.
            BlockServiceApi apiImpl = volume.checkForSRDF() ? BlockService.getBlockServiceImpl("srdf") : BlockService.getBlockServiceImpl("default");
            List<URI> nonVplexVolumeIds = new ArrayList<URI>();
            nonVplexVolumeIds.add(volume.getId());
            List<VolumeDescriptor> nonVplexDescriptors = apiImpl.getDescriptorsForVolumesToBeDeleted(volume.getStorageController(), nonVplexVolumeIds, deletionType);
            volumeDescriptors.addAll(nonVplexDescriptors);
            continue;
        }
        // At this point we know we are a VPLEX volume
        VolumeDescriptor descriptor = new VolumeDescriptor(VolumeDescriptor.Type.VPLEX_VIRT_VOLUME, systemURI, volumeURI, null, null);
        volumeDescriptors.add(descriptor);
        // Add a descriptor for each of the associated volumes.
        if (!volume.isIngestedVolumeWithoutBackend(_dbClient) && (null != volume.getAssociatedVolumes())) {
            for (String assocVolId : volume.getAssociatedVolumes()) {
                Volume assocVolume = _dbClient.queryObject(Volume.class, URI.create(assocVolId));
                if (null != assocVolume && !assocVolume.getInactive() && assocVolume.getNativeId() != null) {
                    if (assocVolume.isSRDFSource()) {
                        // add that volume also.
                        for (String target : assocVolume.getSrdfTargets()) {
                            Volume targetVolume = _dbClient.queryObject(Volume.class, URI.create(target));
                            if (null != targetVolume) {
                                // Look for a Vplex volume fronting the target. If so add it.
                                List<Volume> vplexTargetVolumes = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, getVolumesByAssociatedId(targetVolume.getId().toString()));
                                for (Volume vplexTargetVolume : vplexTargetVolumes) {
                                    // There should only be one volume in list, ie. target only associated with
                                    // one Vplex volume
                                    VolumeDescriptor vplexTargetDescriptor = new VolumeDescriptor(VolumeDescriptor.Type.VPLEX_VIRT_VOLUME, vplexTargetVolume.getStorageController(), vplexTargetVolume.getId(), null, null);
                                    volumeDescriptors.add(vplexTargetDescriptor);
                                }
                            }
                        }
                        // Let the SRDF code fill in its own set of volume descriptors
                        List<URI> srdfVolumeIds = new ArrayList<URI>();
                        srdfVolumeIds.add(assocVolume.getId());
                        SRDFBlockServiceApiImpl srdfApi = (SRDFBlockServiceApiImpl) BlockService.getBlockServiceImpl("srdf");
                        List<VolumeDescriptor> srdfDescriptors = srdfApi.getDescriptorsForVolumesToBeDeleted(assocVolume.getStorageController(), srdfVolumeIds, deletionType);
                        volumeDescriptors.addAll(srdfDescriptors);
                    } else if (!NullColumnValueGetter.isNullNamedURI(assocVolume.getSrdfParent())) {
                        // SRDF target, caller needs to specify source
                        throw BadRequestException.badRequests.cannotDeleteSRDFTargetVolume(assocVolume.getLabel());
                    } else {
                        VolumeDescriptor assocDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, assocVolume.getStorageController(), assocVolume.getId(), null, null);
                        volumeDescriptors.add(assocDesc);
                    }
                }
            }
            // If there were any Vplex Mirrors, add a descriptors for them.
            addDescriptorsForVplexMirrors(volumeDescriptors, volume);
        }
    }
    return volumeDescriptors;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) 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)

Example 79 with VolumeDescriptor

use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method upgradeToDistributed.

/**
 * Upgrade a local VPLEX volume to a distributed VPLEX volume.
 *
 * @param vplexURI -- VPLEX System URI
 * @param vplexVolume -- VPlex volume (existing).
 * @param vpool -- Requested vpool.
 * @param taskId
 * @throws InternalException
 */
private void upgradeToDistributed(URI vplexURI, Volume vplexVolume, VirtualPool vpool, String transferSpeed, String taskId) throws InternalException {
    try {
        VirtualArray neighborhood = _dbClient.queryObject(VirtualArray.class, vplexVolume.getVirtualArray());
        Set<URI> vplexes = new HashSet<URI>();
        vplexes.add(vplexURI);
        if (null == vplexVolume.getAssociatedVolumes() || vplexVolume.getAssociatedVolumes().isEmpty()) {
            s_logger.error("VPLEX volume {} has no backend volumes.", vplexVolume.forDisplay());
            throw InternalServerErrorException.internalServerErrors.noAssociatedVolumesForVPLEXVolume(vplexVolume.forDisplay());
        }
        Iterator<String> assocIter = vplexVolume.getAssociatedVolumes().iterator();
        URI existingVolumeURI = new URI(assocIter.next());
        Volume existingVolume = _dbClient.queryObject(Volume.class, existingVolumeURI);
        if (existingVolume == null || existingVolume.getInactive() == true) {
            throw new ServiceCodeException(ServiceCode.UNFORSEEN_ERROR, "Existing volume inactive", new Object[] {});
        }
        VirtualPoolCapabilityValuesWrapper cosCapabilities = new VirtualPoolCapabilityValuesWrapper();
        cosCapabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, getVolumeCapacity(existingVolume));
        cosCapabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
        cosCapabilities.put(VirtualPoolCapabilityValuesWrapper.THIN_PROVISIONING, existingVolume.getThinlyProvisioned());
        // Get a recommendation.
        // Then create the volume.
        List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
        Volume createVolume = null;
        // Determine if the user requested a specific HA VirtualArray and an associated HA VirtualPool.
        VirtualArray requestedHaVarray = null;
        VirtualPool requestedHaVirtualPool = vpool;
        if (vpool.getHaVarrayVpoolMap() != null && !vpool.getHaVarrayVpoolMap().isEmpty()) {
            for (String haNH : vpool.getHaVarrayVpoolMap().keySet()) {
                if (haNH.equals(NullColumnValueGetter.getNullURI().toString())) {
                    continue;
                }
                requestedHaVarray = _dbClient.queryObject(VirtualArray.class, new URI(haNH));
                String haVirtualPool = vpool.getHaVarrayVpoolMap().get(haNH);
                if (haVirtualPool.equals(NullColumnValueGetter.getNullURI().toString())) {
                    continue;
                }
                requestedHaVirtualPool = _dbClient.queryObject(VirtualPool.class, new URI(haVirtualPool));
                break;
            }
        }
        // Get the recommendations and pick one.
        List<Recommendation> recommendations = getBlockScheduler().scheduleStorageForImport(neighborhood, vplexes, requestedHaVarray, requestedHaVirtualPool, cosCapabilities);
        if (recommendations.isEmpty()) {
            throw APIException.badRequests.noStorageFoundForVolumeMigration(requestedHaVirtualPool.getLabel(), requestedHaVarray.getLabel(), existingVolume.getId());
        }
        Recommendation recommendation = recommendations.get(0);
        VPlexRecommendation vplexRecommendation = (VPlexRecommendation) recommendation;
        if (false == vplexURI.equals(vplexRecommendation.getVPlexStorageSystem())) {
            APIException.badRequests.vplexPlacementError(vplexVolume.getId());
        }
        StorageSystem vplexSystem = _dbClient.queryObject(StorageSystem.class, vplexURI);
        Project vplexProject = getVplexProject(vplexSystem, _dbClient, _tenantsService);
        // Prepare the created volume.
        VirtualArray haVirtualArray = _dbClient.queryObject(VirtualArray.class, vplexRecommendation.getVirtualArray());
        createVolume = prepareVolumeForRequest(getVolumeCapacity(existingVolume), vplexProject, haVirtualArray, requestedHaVirtualPool, vplexRecommendation.getSourceStorageSystem(), vplexRecommendation.getSourceStoragePool(), vplexVolume.getLabel() + "-1", ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME, taskId, _dbClient);
        createVolume.addInternalFlags(Flag.INTERNAL_OBJECT);
        _dbClient.updateObject(createVolume);
        VolumeDescriptor desc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, createVolume.getStorageController(), createVolume.getId(), createVolume.getPool(), cosCapabilities);
        descriptors.add(desc);
        // Add a descriptor for the VPlex Virtual Volume.
        desc = new VolumeDescriptor(VolumeDescriptor.Type.VPLEX_VIRT_VOLUME, vplexVolume.getStorageController(), vplexVolume.getId(), vplexVolume.getPool(), cosCapabilities);
        descriptors.add(desc);
        // Now send the command to the controller.
        try {
            s_logger.info("Calling VPlex controller.");
            VPlexController controller = getController();
            controller.importVolume(vplexURI, descriptors, null, null, vpool.getId(), null, transferSpeed, Boolean.TRUE, taskId);
        // controller.importVolume(vplexURI, vpool.getId(),
        // null, null, /* no need to pass System Project/Tenant */
        // null, /* no import volume */
        // createVolume.getId(), vplexVolume.getId(), taskId);
        } catch (InternalException ex) {
            s_logger.error("ControllerException on upgradeToDistributed", ex);
            String errMsg = String.format("ControllerException: %s", ex.getMessage());
            Operation statusUpdate = new Operation(Operation.Status.error.name(), errMsg);
            _dbClient.updateTaskOpStatus(Volume.class, vplexVolume.getId(), taskId, statusUpdate);
            throw ex;
        }
    } catch (URISyntaxException ex) {
        s_logger.debug("URISyntaxException", ex);
    }
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) VPlexRecommendation(com.emc.storageos.volumecontroller.VPlexRecommendation) VPlexController(com.emc.storageos.vplexcontroller.VPlexController) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) URISyntaxException(java.net.URISyntaxException) 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) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) HashSet(java.util.HashSet) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 80 with VolumeDescriptor

use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor 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

VolumeDescriptor (com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor)117 Volume (com.emc.storageos.db.client.model.Volume)98 URI (java.net.URI)86 NamedURI (com.emc.storageos.db.client.model.NamedURI)77 ArrayList (java.util.ArrayList)77 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)38 HashMap (java.util.HashMap)38 StringSet (com.emc.storageos.db.client.model.StringSet)29 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)27 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)19 FCTN_STRING_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI)18 Workflow (com.emc.storageos.workflow.Workflow)18 ApplicationAddVolumeList (com.emc.storageos.volumecontroller.ApplicationAddVolumeList)17 ControllerException (com.emc.storageos.volumecontroller.ControllerException)17 List (java.util.List)17 BlockOrchestrationController (com.emc.storageos.blockorchestrationcontroller.BlockOrchestrationController)16 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)16 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)16 URISyntaxException (java.net.URISyntaxException)16 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)15