Search in sources :

Example 1 with VpoolRemoteCopyProtectionSettings

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

the class BlockService method validateVpoolCopyModeSetting.

private void validateVpoolCopyModeSetting(Volume srcVolume, String newCopyMode) {
    if (srcVolume != null) {
        URI virtualPoolURI = srcVolume.getVirtualPool();
        VirtualPool virtualPool = _dbClient.queryObject(VirtualPool.class, virtualPoolURI);
        if (virtualPool != null) {
            StringMap remoteCopySettingsMap = virtualPool.getProtectionRemoteCopySettings();
            if (remoteCopySettingsMap != null) {
                for (Map.Entry<URI, VpoolRemoteCopyProtectionSettings> entry : VirtualPool.getRemoteProtectionSettings(virtualPool, _dbClient).entrySet()) {
                    VpoolRemoteCopyProtectionSettings copySetting = entry.getValue();
                    if (!newCopyMode.equalsIgnoreCase(copySetting.getCopyMode())) {
                        throw APIException.badRequests.invalidCopyModeOp(newCopyMode, copySetting.getCopyMode());
                    }
                }
            }
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 2 with VpoolRemoteCopyProtectionSettings

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

the class BlockService method verifyVirtualPoolChangeSupportedForVolumeAndVirtualPool.

/**
 * Determines whether or not the passed VirtualPool change for the passed Volume is
 * supported. Throws a ServiceCodeException when the vpool change is not
 * supported.
 *
 * @param volume
 *            A reference to the volume.
 * @param newVpool
 *            A reference to the new VirtualPool.
 */
private void verifyVirtualPoolChangeSupportedForVolumeAndVirtualPool(Volume volume, VirtualPool newVpool) {
    // Currently, Vpool change is only supported for volumes on
    // VPlex storage systems and volumes (both regular and VPLEX i.e. RP+VPLEX) that are currently
    // unprotected by RP to a Vpool that has RP, as long as the source volume doesn't have to move.
    VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
    URI systemURI = volume.getStorageController();
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, systemURI);
    String systemType = system.getSystemType();
    StringBuffer notSuppReasonBuff = new StringBuffer();
    notSuppReasonBuff.setLength(0);
    /**
     * Do not support following vpool change operations for the volume part of application
     * 1. Move into Vplex
     * 2. Add RecoverPoint
     * 3. Remove RecoverPoint
     * 4. Add SRDF
     */
    if (volume.getApplication(_dbClient) != null) {
        // Move into VPLEX
        if (!VirtualPool.vPoolSpecifiesHighAvailability(currentVpool) && VirtualPool.vPoolSpecifiesHighAvailability(newVpool)) {
            notSuppReasonBuff.append("Non VPLEX volumes in applications cannot be moved into VPLEX pools");
            throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
        }
        // Add recoverPoint
        if (!VirtualPool.vPoolSpecifiesProtection(currentVpool) && VirtualPool.vPoolSpecifiesProtection(newVpool)) {
            notSuppReasonBuff.append("Non RP volumes in applications cannot be moved into RP pools");
            throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
        }
        // Remove RecoverPoint
        if (VirtualPool.vPoolSpecifiesProtection(currentVpool) && !VirtualPool.vPoolSpecifiesProtection(newVpool)) {
            notSuppReasonBuff.append("RP volumes in applications cannot be moved into non RP pools");
            throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
        }
        // Add SRDF
        if (!VirtualPool.vPoolSpecifiesSRDF(currentVpool) && VirtualPool.vPoolSpecifiesSRDF(newVpool)) {
            notSuppReasonBuff.append("volumes in applications cannot be moved into SRDF pools");
            throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
        }
    }
    // Check if an Export Path Params change.
    if (VirtualPoolChangeAnalyzer.isSupportedPathParamsChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
        ExportPathUpdater updater = new ExportPathUpdater(_dbClient);
        ExportPathParams newParam = new ExportPathParams(newVpool.getNumPaths(), newVpool.getMinPaths(), newVpool.getPathsPerInitiator());
        updater.validateChangePathParams(volume.getId(), newParam);
        _log.info("New VPool specifies an Export Path Params change");
        return;
    }
    // Check if it is an Auto-tiering policy change.
    notSuppReasonBuff.setLength(0);
    if (VirtualPoolChangeAnalyzer.isSupportedAutoTieringPolicyAndLimitsChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
        _log.info("New VPool specifies an Auto-tiering policy change");
        return;
    }
    if (VirtualPoolChangeAnalyzer.isSupportedReplicationModeChange(currentVpool, newVpool, notSuppReasonBuff)) {
        _log.info("New VPool specifies a replication mode change");
        return;
    }
    if (DiscoveredDataObject.Type.vplex.name().equals(systemType)) {
        _log.info("Volume is a VPlex virtual volume.");
        // the Vpool specifies a different grade of disk drives.
        if (!VirtualPool.vPoolSpecifiesHighAvailability(newVpool)) {
            _log.info("New VirtualPool does not specify VPlex high availability.");
            throw new ServiceCodeException(ServiceCode.API_VOLUME_VPOOL_CHANGE_DISRUPTIVE, "New VirtualPool {0} does not specify vplex high availability", new Object[] { newVpool.getId() });
        } else {
            notSuppReasonBuff.setLength(0);
            // can be exposed in the Migration Services catalog to support RP+VPLEX Data Migrations.
            if (volume.checkPersonality(Volume.PersonalityTypes.METADATA)) {
                if (VirtualPoolChangeAnalyzer.vpoolChangeRequiresMigration(currentVpool, newVpool)) {
                    verifyVPlexVolumeForDataMigration(volume, currentVpool, newVpool, _dbClient);
                    return;
                }
            }
            // if the request is trying to remove RP protection.
            if (volume.checkForRp() && VirtualPool.vPoolSpecifiesProtection(currentVpool) && !VirtualPool.vPoolSpecifiesProtection(newVpool)) {
                notSuppReasonBuff.setLength(0);
                if (!VirtualPoolChangeAnalyzer.isSupportedRPRemoveProtectionVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
                    throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
                }
            } else if (VirtualPool.vPoolSpecifiesRPVPlex(newVpool)) {
                notSuppReasonBuff.setLength(0);
                // Check to see if any of the operations for protected vpool to protected vpool changes are supported
                if (VirtualPool.vPoolSpecifiesRPVPlex(currentVpool)) {
                    if (VirtualPoolChangeAnalyzer.isSupportedRPVPlexMigrationVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff, null)) {
                        verifyVPlexVolumeForDataMigration(volume, currentVpool, newVpool, _dbClient);
                    } else if (!VirtualPoolChangeAnalyzer.isSupportedUpgradeToMetroPointVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
                        _log.warn("RP Change Protection VirtualPool change for volume is not supported: {}", notSuppReasonBuff.toString());
                        throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
                    }
                } else // Otherwise, check to see if we're trying to protect a VPLEX volume.
                if (!VirtualPoolChangeAnalyzer.isSupportedAddRPProtectionVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
                    _log.warn("RP+VPLEX VirtualPool change for volume is not supported: {}", notSuppReasonBuff.toString());
                    throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
                } else if (BlockFullCopyUtils.volumeHasFullCopySession(volume, _dbClient)) {
                    // Full copies not supported for RP protected volumes.
                    throw APIException.badRequests.volumeForRPVpoolChangeHasFullCopies(volume.getLabel());
                }
            } else {
                VirtualPoolChangeOperationEnum vplexVpoolChangeOperation = VirtualPoolChangeAnalyzer.getSupportedVPlexVolumeVirtualPoolChangeOperation(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff);
                if (vplexVpoolChangeOperation == null) {
                    _log.warn("VPlex volume VirtualPool change not supported {}", notSuppReasonBuff.toString());
                    throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
                } else if (VPlexUtil.isVolumeBuiltOnBlockSnapshot(_dbClient, volume)) {
                    // created using the target volume of a block snapshot.
                    throw APIException.badRequests.vpoolChangeNotAllowedVolumeIsExposedSnapshot(volume.getId().toString());
                } else if (vplexVpoolChangeOperation == VirtualPoolChangeOperationEnum.VPLEX_DATA_MIGRATION) {
                    verifyVPlexVolumeForDataMigration(volume, currentVpool, newVpool, _dbClient);
                }
            }
        }
    } else if (DiscoveredDataObject.Type.vmax.name().equals(systemType) || DiscoveredDataObject.Type.vnxblock.name().equals(systemType) || DiscoveredDataObject.Type.hds.name().equals(systemType) || DiscoveredDataObject.Type.xtremio.name().equals(systemType) || DiscoveredDataObject.Type.ibmxiv.name().equals(systemType) || DiscoveredDataObject.Type.unity.name().equals(systemType)) {
        if (VirtualPool.vPoolSpecifiesHighAvailability(newVpool)) {
            // VNX/VMAX import to VPLEX cases
            notSuppReasonBuff.setLength(0);
            if (!VirtualPoolChangeAnalyzer.isVPlexImport(volume, currentVpool, newVpool, notSuppReasonBuff) || (!VirtualPoolChangeAnalyzer.doesVplexVpoolContainVolumeStoragePool(volume, newVpool, notSuppReasonBuff))) {
                _log.warn("VNX/VMAX cos change for volume is not supported: {}", notSuppReasonBuff.toString());
                throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
            }
            if (volume.isVolumeExported(_dbClient)) {
                throw APIException.badRequests.cannotImportExportedVolumeToVplex(volume.getId());
            } else if (BlockFullCopyUtils.volumeHasFullCopySession(volume, _dbClient)) {
                // The backend would have a full copy, but the VPLEX volume would not.
                throw APIException.badRequests.volumeForVpoolChangeHasFullCopies(volume.getLabel());
            } else {
                // Can't be imported if it has snapshot sessions, because we
                // don't currently support these behind VPLEX.
                List<BlockSnapshotSession> snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(volume.getId()));
                if (!snapSessions.isEmpty()) {
                    throw APIException.badRequests.cannotImportVolumeWithSnapshotSessions(volume.getLabel());
                }
            }
        } else if (VirtualPool.vPoolSpecifiesProtection(newVpool)) {
            // VNX/VMAX import to RP cases (currently one)
            notSuppReasonBuff.setLength(0);
            if (!VirtualPoolChangeAnalyzer.isSupportedAddRPProtectionVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
                _log.warn("VirtualPool change to Add RP Protection for volume is not supported: {}", notSuppReasonBuff.toString());
                throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
            } else if (BlockFullCopyUtils.volumeHasFullCopySession(volume, _dbClient)) {
                // Full copies not supported for RP protected volumes.
                throw APIException.badRequests.volumeForRPVpoolChangeHasFullCopies(volume.getLabel());
            } else {
                // Can't add RP if it has snapshot sessions, because we
                // don't currently support these for RP protected volumes.
                List<BlockSnapshotSession> snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(volume.getId()));
                if (!snapSessions.isEmpty()) {
                    throw APIException.badRequests.volumeForRPVpoolChangeHasSnapshotSessions(volume.getLabel());
                }
            }
        } else if (VirtualPool.vPoolSpecifiesProtection(currentVpool) && !VirtualPool.vPoolSpecifiesProtection(newVpool)) {
            notSuppReasonBuff.setLength(0);
            if (!VirtualPoolChangeAnalyzer.isSupportedRPRemoveProtectionVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
                throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
            }
        } else if (VirtualPool.vPoolSpecifiesSRDF(newVpool)) {
            // VMAX import to SRDF cases (currently one)
            notSuppReasonBuff.setLength(0);
            if (!VirtualPoolChangeAnalyzer.isSupportedSRDFVolumeVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
                _log.warn("VMAX VirtualPool change for volume is not supported: {}", notSuppReasonBuff.toString());
                throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
            } else if (BlockFullCopyUtils.volumeHasFullCopySession(volume, _dbClient)) {
                // Full copy not supported for volumes with asynchronous copy mode.
                Map<URI, VpoolRemoteCopyProtectionSettings> remoteCopySettingsMap = VirtualPool.getRemoteProtectionSettings(newVpool, _dbClient);
                VpoolRemoteCopyProtectionSettings remoteCopyProtectionSettings = remoteCopySettingsMap.values().iterator().next();
                if (SupportedCopyModes.ASYNCHRONOUS.toString().equalsIgnoreCase(remoteCopyProtectionSettings.getCopyMode())) {
                    throw APIException.badRequests.volumeForSRDFVpoolChangeHasFullCopies(volume.getLabel());
                }
            }
        } else if (!NullColumnValueGetter.isNullNamedURI(volume.getSrdfParent()) || (volume.getSrdfTargets() != null && !volume.getSrdfTargets().isEmpty())) {
            // Cannot move SRDF Volume to non SRDF VPool
            throw APIException.badRequests.srdfVolumeVPoolChangeToNonSRDFVPoolNotSupported(volume.getId());
        } else if (VirtualPool.vPoolSpecifiesMirrors(newVpool, _dbClient)) {
            notSuppReasonBuff.setLength(0);
            if (!VirtualPoolChangeAnalyzer.isSupportedAddMirrorsVirtualPoolChange(volume, currentVpool, newVpool, _dbClient, notSuppReasonBuff)) {
                _log.warn("VirtualPool change to add continuous copies for volume {} is not supported: {}", volume.getId(), notSuppReasonBuff.toString());
                throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
            }
        } else {
            String errMsg = "there was an invalid property mismatch between source and target vPools.";
            _log.error(errMsg);
            notSuppReasonBuff.append(errMsg);
            throw APIException.badRequests.changeToVirtualPoolNotSupported(newVpool.getLabel(), notSuppReasonBuff.toString());
        }
    } else {
        _log.info("VirtualPool change volume is not a vplex, vmax or vnxblock volume");
        throw new ServiceCodeException(ServiceCode.API_VOLUME_VPOOL_CHANGE_DISRUPTIVE, "VirtualPool change is not supported for volume {0}", new Object[] { volume.getId() });
    }
}
Also used : ExportPathUpdater(com.emc.storageos.volumecontroller.placement.ExportPathUpdater) VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) VirtualPoolChangeOperationEnum(com.emc.storageos.model.vpool.VirtualPoolChangeOperationEnum) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) VirtualPoolChangeList(com.emc.storageos.model.vpool.VirtualPoolChangeList) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) MigrationList(com.emc.storageos.model.block.MigrationList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) MirrorList(com.emc.storageos.model.block.MirrorList) SnapshotList(com.emc.storageos.model.SnapshotList) BlockObject(com.emc.storageos.db.client.model.BlockObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams)

Example 3 with VpoolRemoteCopyProtectionSettings

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

the class BlockVirtualPoolService method getMatchingPoolsForVirtualPoolAttributes.

/**
 * Return the matching pools for a given set of VirtualPool attributes.
 * This API is useful for user to find the matching pools before creating a VirtualPool.
 *
 * @prereq none
 * @param param : VirtualPoolAttributeParam
 * @brief List matching pools for virtual pool properties
 * @return matching pools.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/matching-pools")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StoragePoolList getMatchingPoolsForVirtualPoolAttributes(BlockVirtualPoolParam param) {
    StoragePoolList poolList = new StoragePoolList();
    Map<URI, VpoolRemoteCopyProtectionSettings> remoteSettingsMap = new HashMap<URI, VpoolRemoteCopyProtectionSettings>();
    List<VpoolProtectionVarraySettings> protectionSettings = new ArrayList<VpoolProtectionVarraySettings>();
    Map<URI, VpoolProtectionVarraySettings> protectionSettingsMap = new HashMap<URI, VpoolProtectionVarraySettings>();
    VirtualPool vpool = prepareVirtualPool(param, remoteSettingsMap, protectionSettingsMap, protectionSettings);
    List<URI> storagePoolURIs = _dbClient.queryByType(StoragePool.class, true);
    List<StoragePool> allPools = _dbClient.queryObject(StoragePool.class, storagePoolURIs);
    StringBuffer errorMessage = new StringBuffer();
    List<StoragePool> matchedPools = ImplicitPoolMatcher.getMatchedPoolWithStoragePools(vpool, allPools, protectionSettingsMap, remoteSettingsMap, null, _dbClient, _coordinator, AttributeMatcher.VPOOL_MATCHERS, errorMessage);
    for (StoragePool pool : matchedPools) {
        poolList.getPools().add(toNamedRelatedResource(pool, pool.getNativeGuid()));
    }
    return poolList;
}
Also used : StoragePoolList(com.emc.storageos.model.pools.StoragePoolList) VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VpoolProtectionVarraySettings(com.emc.storageos.db.client.model.VpoolProtectionVarraySettings) VirtualPoolMapper.toBlockVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toBlockVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) 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 4 with VpoolRemoteCopyProtectionSettings

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

the class BlockVirtualPoolService method updateRemoteCopyVPool.

private void updateRemoteCopyVPool(VirtualPool virtualPool, BlockVirtualPoolProtectionUpdateParam param) {
    if (param.getRemoteCopies() != null) {
        StringMap remoteCopySettingsMap = virtualPool.getProtectionRemoteCopySettings();
        if (remoteCopySettingsMap == null) {
            remoteCopySettingsMap = new StringMap();
            virtualPool.setProtectionRemoteCopySettings(remoteCopySettingsMap);
        }
        // and an add, which is buggy in the StringMap.
        if (param.getRemoteCopies().getRemove() != null && !param.getRemoteCopies().getRemove().isEmpty() && param.getRemoteCopies().getAdd() != null && !param.getRemoteCopies().getAdd().isEmpty()) {
            Iterator<VirtualPoolRemoteProtectionVirtualArraySettingsParam> removeRemoteCopies = param.getRemoteCopies().getRemove().iterator();
            Iterator<VirtualPoolRemoteProtectionVirtualArraySettingsParam> addRemoteCopies = param.getRemoteCopies().getAdd().iterator();
            while (removeRemoteCopies.hasNext()) {
                VirtualPoolRemoteProtectionVirtualArraySettingsParam removeRemoteCopySettingsParam = removeRemoteCopies.next();
                while (addRemoteCopies.hasNext()) {
                    VirtualPoolRemoteProtectionVirtualArraySettingsParam addRemoteCopySettingsParam = addRemoteCopies.next();
                    // remote copy setting from the add/remove lists so they do not get processed individually.
                    if (removeRemoteCopySettingsParam.getVarray().toString().equals(addRemoteCopySettingsParam.getVarray().toString())) {
                        String remoteCopySettingsUri = remoteCopySettingsMap.get(addRemoteCopySettingsParam.getVarray().toString());
                        VpoolRemoteCopyProtectionSettings remoteSettingsObj = _dbClient.queryObject(VpoolRemoteCopyProtectionSettings.class, URI.create(remoteCopySettingsUri));
                        if (remoteSettingsObj != null) {
                            remoteSettingsObj.setVirtualPool(addRemoteCopySettingsParam.getVpool());
                            if (null != addRemoteCopySettingsParam.getRemoteCopyMode()) {
                                if (!CopyModes.lookup(addRemoteCopySettingsParam.getRemoteCopyMode())) {
                                    throw APIException.badRequests.invalidCopyMode(addRemoteCopySettingsParam.getRemoteCopyMode());
                                }
                                remoteSettingsObj.setCopyMode(addRemoteCopySettingsParam.getRemoteCopyMode());
                            }
                            _dbClient.persistObject(remoteSettingsObj);
                            // Only remove from the add list if the remote copy setting actually
                            // exists. We will still want to add it if it does not exist.
                            param.getRemoteCopies().getAdd().remove(addRemoteCopySettingsParam);
                        }
                        // Always remove the remote copy setting from the remove list
                        param.getRemoteCopies().getRemove().remove(removeRemoteCopySettingsParam);
                    }
                }
            }
        }
        if (param.getRemoteCopies().getRemove() != null && !param.getRemoteCopies().getRemove().isEmpty()) {
            for (VirtualPoolRemoteProtectionVirtualArraySettingsParam remoteSettings : param.getRemoteCopies().getRemove()) {
                if (remoteSettings.getVarray() != null && remoteCopySettingsMap.containsKey(remoteSettings.getVarray().toString())) {
                    String remoteCopySettingsUri = remoteCopySettingsMap.get(remoteSettings.getVarray().toString());
                    remoteCopySettingsMap.remove(remoteSettings.getVarray().toString());
                    VpoolRemoteCopyProtectionSettings remoteSettingsObj = _dbClient.queryObject(VpoolRemoteCopyProtectionSettings.class, URI.create(remoteCopySettingsUri));
                    remoteSettingsObj.setInactive(true);
                    _dbClient.persistObject(remoteSettingsObj);
                }
            }
        }
        if (param.getRemoteCopies().getAdd() != null && !param.getRemoteCopies().getAdd().isEmpty()) {
            List<VpoolRemoteCopyProtectionSettings> remoteSettingsList = new ArrayList<VpoolRemoteCopyProtectionSettings>();
            // already existing remote VArrays
            List<String> existingRemoteUris = new ArrayList<String>(remoteCopySettingsMap.keySet());
            for (VirtualPoolRemoteProtectionVirtualArraySettingsParam remoteSettings : param.getRemoteCopies().getAdd()) {
                // CTRL-275 fix
                VirtualArray remoteVArray = _dbClient.queryObject(VirtualArray.class, remoteSettings.getVarray());
                if (null == remoteVArray || remoteVArray.getInactive()) {
                    throw APIException.badRequests.inactiveRemoteVArrayDetected(remoteSettings.getVarray());
                }
                VpoolRemoteCopyProtectionSettings remoteCopySettingsParam = new VpoolRemoteCopyProtectionSettings();
                remoteSettingsList.add(remoteCopySettingsParam);
                remoteCopySettingsParam.setId(URIUtil.createId(VpoolRemoteCopyProtectionSettings.class));
                remoteCopySettingsParam.setVirtualArray(remoteSettings.getVarray());
                if (existingRemoteUris.contains(remoteSettings.getVarray().toString()) || remoteCopySettingsMap.containsKey(remoteSettings.getVarray().toString())) {
                    throw APIException.badRequests.duplicateRemoteSettingsDetected(remoteSettings.getVarray());
                }
                remoteCopySettingsMap.put(remoteSettings.getVarray().toString(), remoteCopySettingsParam.getId().toString());
                remoteCopySettingsParam.setVirtualPool(remoteSettings.getVpool());
                if (null != remoteSettings.getRemoteCopyMode()) {
                    if (!CopyModes.lookup(remoteSettings.getRemoteCopyMode())) {
                        throw APIException.badRequests.invalidCopyMode(remoteSettings.getRemoteCopyMode());
                    }
                    remoteCopySettingsParam.setCopyMode(remoteSettings.getRemoteCopyMode());
                }
            }
            _dbClient.createObject(remoteSettingsList);
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) VirtualPoolRemoteProtectionVirtualArraySettingsParam(com.emc.storageos.model.vpool.VirtualPoolRemoteProtectionVirtualArraySettingsParam) VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) ArrayList(java.util.ArrayList)

Example 5 with VpoolRemoteCopyProtectionSettings

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

the class BlockVirtualPoolService method createBlockVirtualPool.

/**
 * Creates a block store virtual pool
 *
 * @prereq none
 * @param param VirtualPool parameters
 * @brief Create block store virtual pool
 * @return VirtualPool details
 * @throws Exception
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public BlockVirtualPoolRestRep createBlockVirtualPool(BlockVirtualPoolParam param) throws DatabaseException {
    ArgValidator.checkFieldNotEmpty(param.getName(), VPOOL_NAME);
    checkForDuplicateName(param.getName(), VirtualPool.class);
    ArgValidator.checkFieldNotEmpty(param.getDescription(), VPOOL_DESCRIPTION);
    VirtualPoolUtil.validateBlockVirtualPoolCreateParams(param, _dbClient);
    Map<URI, VpoolRemoteCopyProtectionSettings> remoteSettingsMap = new HashMap<URI, VpoolRemoteCopyProtectionSettings>();
    List<VpoolProtectionVarraySettings> protectionSettings = new ArrayList<VpoolProtectionVarraySettings>();
    Map<URI, VpoolProtectionVarraySettings> protectionSettingsMap = new HashMap<URI, VpoolProtectionVarraySettings>();
    VirtualPool vpool = prepareVirtualPool(param, remoteSettingsMap, protectionSettingsMap, protectionSettings);
    // Set the underlying protection setting objects
    if (!protectionSettings.isEmpty()) {
        _dbClient.createObject(protectionSettings);
    }
    if (!remoteSettingsMap.isEmpty()) {
        _dbClient.createObject(new ArrayList(remoteSettingsMap.values()));
    }
    StringBuffer errorMessage = new StringBuffer();
    // update the implicit pools matching with this VirtualPool.
    ImplicitPoolMatcher.matchVirtualPoolWithAllStoragePools(vpool, _dbClient, _coordinator, errorMessage);
    Set<URI> allSrdfTargetVPools = SRDFUtils.fetchSRDFTargetVirtualPools(_dbClient);
    Set<URI> allRpTargetVPools = RPHelper.fetchRPTargetVirtualPools(_dbClient);
    if (null != vpool.getMatchedStoragePools() || null != vpool.getInvalidMatchedPools()) {
        ImplicitUnManagedObjectsMatcher.matchVirtualPoolsWithUnManagedVolumes(vpool, allSrdfTargetVPools, allRpTargetVPools, _dbClient, true);
    }
    _dbClient.createObject(vpool);
    // Creates a new QoS object in DB based on data from given Virtual Pool
    QosService.createQosSpecification(vpool, _dbClient);
    recordOperation(OperationTypeEnum.CREATE_VPOOL, VPOOL_CREATED_DESCRIPTION, vpool);
    return toBlockVirtualPool(_dbClient, vpool, VirtualPool.getProtectionSettings(vpool, _dbClient), VirtualPool.getRemoteProtectionSettings(vpool, _dbClient));
}
Also used : VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VpoolProtectionVarraySettings(com.emc.storageos.db.client.model.VpoolProtectionVarraySettings) VirtualPoolMapper.toBlockVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toBlockVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

VpoolRemoteCopyProtectionSettings (com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings)32 URI (java.net.URI)29 ArrayList (java.util.ArrayList)21 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)20 StringSet (com.emc.storageos.db.client.model.StringSet)15 NamedURI (com.emc.storageos.db.client.model.NamedURI)14 List (java.util.List)13 StringMap (com.emc.storageos.db.client.model.StringMap)12 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)11 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)11 StoragePool (com.emc.storageos.db.client.model.StoragePool)9 Volume (com.emc.storageos.db.client.model.Volume)8 Recommendation (com.emc.storageos.volumecontroller.Recommendation)8 SRDFRecommendation (com.emc.storageos.volumecontroller.SRDFRecommendation)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)7 SRDFCopyRecommendation (com.emc.storageos.volumecontroller.SRDFCopyRecommendation)6 Network (com.emc.storageos.db.client.model.Network)5