Search in sources :

Example 6 with BlockHostAccess

use of com.emc.storageos.vnxe.models.BlockHostAccess in project coprhd-controller by CoprHD.

the class VNXUnityUnManagedObjectDiscoverer method createUnManagedVolume.

/**
 * Creates a new UnManagedVolume with the given arguments.
 *
 * @param unManagedVolumeNativeGuid
 * @param lun
 * @param system
 * @param pool
 * @param dbClient
 * @param hostVolumeMap
 *            hosts and exported volumes map
 * @return
 */
private UnManagedVolume createUnManagedVolume(UnManagedVolume unManagedVolume, String unManagedVolumeNativeGuid, VNXeLun lun, StorageSystem system, StoragePool pool, DbClient dbClient, Map<String, List<UnManagedVolume>> hostVolumeMap) {
    boolean created = false;
    if (null == unManagedVolume) {
        unManagedVolume = new UnManagedVolume();
        unManagedVolume.setId(URIUtil.createId(UnManagedVolume.class));
        unManagedVolume.setNativeGuid(unManagedVolumeNativeGuid);
        unManagedVolume.setStorageSystemUri(system.getId());
        unManagedVolume.setStoragePoolUri(pool.getId());
        created = true;
    }
    unManagedVolume.setLabel(lun.getName());
    StringSetMap unManagedVolumeInformation = new StringSetMap();
    Map<String, String> unManagedVolumeCharacteristics = new HashMap<String, String>();
    Boolean isVolumeExported = false;
    if (lun.getHostAccess() != null && !lun.getHostAccess().isEmpty()) {
        // clear the previous unmanaged export masks, initiators if any. The latest export masks will be updated
        // later.
        unManagedVolume.getUnmanagedExportMasks().clear();
        unManagedVolume.getInitiatorNetworkIds().clear();
        unManagedVolume.getInitiatorUris().clear();
        for (BlockHostAccess access : lun.getHostAccess()) {
            int accessMask = access.getAccessMask();
            if (accessMask == BlockHostAccess.HostLUNAccessEnum.BOTH.getValue() || accessMask == BlockHostAccess.HostLUNAccessEnum.PRODUCTION.getValue()) {
                isVolumeExported = true;
                String hostId = access.getHost().getId();
                List<UnManagedVolume> exportedVolumes = hostVolumeMap.get(hostId);
                if (exportedVolumes == null) {
                    exportedVolumes = new ArrayList<UnManagedVolume>();
                    hostVolumeMap.put(hostId, exportedVolumes);
                }
                exportedVolumes.add(unManagedVolume);
            }
        }
    }
    unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_VOLUME_EXPORTED.toString(), isVolumeExported.toString());
    unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_NONRP_EXPORTED.toString(), Boolean.FALSE.toString());
    unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_RECOVERPOINT_ENABLED.toString(), Boolean.FALSE.toString());
    StringSet deviceLabel = new StringSet();
    deviceLabel.add(lun.getName());
    unManagedVolumeInformation.put(SupportedVolumeInformation.DEVICE_LABEL.toString(), deviceLabel);
    String volumeWWN = lun.getWwn().replaceAll(":", "");
    unManagedVolume.setWwn(volumeWWN);
    StringSet systemTypes = new StringSet();
    systemTypes.add(system.getSystemType());
    StringSet provCapacity = new StringSet();
    provCapacity.add(String.valueOf(lun.getSizeTotal()));
    unManagedVolumeInformation.put(SupportedVolumeInformation.PROVISIONED_CAPACITY.toString(), provCapacity);
    StringSet allocatedCapacity = new StringSet();
    allocatedCapacity.add(String.valueOf(lun.getSizeAllocated()));
    unManagedVolumeInformation.put(SupportedVolumeInformation.ALLOCATED_CAPACITY.toString(), allocatedCapacity);
    unManagedVolumeInformation.put(SupportedVolumeInformation.SYSTEM_TYPE.toString(), systemTypes);
    StringSet nativeId = new StringSet();
    nativeId.add(lun.getId());
    unManagedVolumeInformation.put(SupportedVolumeInformation.NATIVE_ID.toString(), nativeId);
    unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_INGESTABLE.toString(), Boolean.TRUE.toString());
    unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_THINLY_PROVISIONED.toString(), lun.getIsThinEnabled().toString());
    if (null != pool) {
        unManagedVolume.setStoragePoolUri(pool.getId());
        StringSet pools = new StringSet();
        pools.add(pool.getId().toString());
        unManagedVolumeInformation.put(SupportedVolumeInformation.STORAGE_POOL.toString(), pools);
        StringSet driveTypes = pool.getSupportedDriveTypes();
        if (null != driveTypes) {
            unManagedVolumeInformation.put(SupportedVolumeInformation.DISK_TECHNOLOGY.toString(), driveTypes);
        }
        StringSet matchedVPools = DiscoveryUtils.getMatchedVirtualPoolsForPool(dbClient, pool.getId(), unManagedVolumeCharacteristics.get(SupportedVolumeCharacterstics.IS_THINLY_PROVISIONED.toString()), unManagedVolume);
        log.debug("Matched Pools : {}", Joiner.on("\t").join(matchedVPools));
        if (null == matchedVPools || matchedVPools.isEmpty()) {
            // clear all existing supported vpools.
            unManagedVolume.getSupportedVpoolUris().clear();
        } else {
            // replace with new StringSet
            unManagedVolume.getSupportedVpoolUris().replace(matchedVPools);
            log.info("Replaced Pools : {}", Joiner.on("\t").join(unManagedVolume.getSupportedVpoolUris()));
        }
    }
    unManagedVolume.setVolumeInformation(unManagedVolumeInformation);
    if (unManagedVolume.getVolumeCharacterstics() == null) {
        unManagedVolume.setVolumeCharacterstics(new StringMap());
    }
    unManagedVolume.getVolumeCharacterstics().replace(unManagedVolumeCharacteristics);
    // clear the mask to HLU map. Fresh data gets persisted during UnManagedExportMask discovery
    if (unManagedVolume.getVolumeInformation().get(SupportedVolumeInformation.HLU_TO_EXPORT_MASK_NAME_MAP.name()) != null) {
        unManagedVolume.getVolumeInformation().get(SupportedVolumeInformation.HLU_TO_EXPORT_MASK_NAME_MAP.name()).clear();
    }
    if (created) {
        unManagedVolumesInsert.add(unManagedVolume);
    } else {
        unManagedVolumesUpdate.add(unManagedVolume);
    }
    return unManagedVolume;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 7 with BlockHostAccess

use of com.emc.storageos.vnxe.models.BlockHostAccess in project coprhd-controller by CoprHD.

the class VNXUnityArrayAffinityDiscoverer method getHostURIs.

/**
 * Find host URIs that a LUN is exported to
 *
 * @param lun
 * @param apiClient
 * @param dbClient
 * @param hostIdToHostURIMap
 * @return set of host URIs
 */
private Set<URI> getHostURIs(VNXeLun lun, VNXeApiClient apiClient, DbClient dbClient, Map<String, URI> hostIdToHostURIMap) {
    Set<URI> hostURIs = new HashSet<URI>();
    List<BlockHostAccess> accesses = lun.getHostAccess();
    if (accesses != null && !accesses.isEmpty()) {
        for (BlockHostAccess access : accesses) {
            if (access != null) {
                VNXeBase hostId = access.getHost();
                if (hostId != null) {
                    hostURIs.add(getHostURI(apiClient, hostId.getId(), dbClient, hostIdToHostURIMap));
                }
            }
        }
    }
    return hostURIs;
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) URI(java.net.URI) HashSet(java.util.HashSet) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess)

Example 8 with BlockHostAccess

use of com.emc.storageos.vnxe.models.BlockHostAccess in project coprhd-controller by CoprHD.

the class VNXeApiClient method unexportSnap.

/**
 * Unexport a snapshot
 *
 * @param hostId - The host id
 * @param snapId - The snap id
 */
public void unexportSnap(String hostId, String snapId) {
    _logger.info("Unexporting snap: {}", snapId);
    String parentLunId = null;
    String groupId = null;
    boolean detach = false;
    if (!_khClient.isUnity()) {
        VNXeLunSnap lunSnap = getLunSnapshot(snapId);
        if (lunSnap == null) {
            _logger.info("Could not find lun snap in the vxne: {}", snapId);
            throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun snap: " + snapId);
        }
        if (lunSnap.getIsAttached()) {
            _logger.info("Detaching the snap: {}", snapId);
            detachLunSnap(snapId);
            detach = true;
        }
        parentLunId = lunSnap.getLun().getId();
    } else {
        Snap snap = getSnapshot(snapId);
        if (snap == null) {
            _logger.info("Could not find snap in the vxn unity: {}", snapId);
            throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun snap: " + snapId);
        }
        VNXeBase snapGroup = snap.getSnapGroup();
        parentLunId = snap.getLun().getId();
        if (snapGroup == null && (snap.isAttached())) {
            _logger.info("Detaching the snap: {}", snapId);
            detachSnap(snapId);
            detach = true;
        } else if (snapGroup != null && snap.isAttached()) {
            _logger.info("Detaching the snap: {}", snapId);
            groupId = snapGroup.getId();
            detachSnap(groupId);
            detach = true;
        }
    }
    VNXeLun parentLun = getLun(parentLunId);
    List<BlockHostAccess> hostAccesses = parentLun.getHostAccess();
    if (hostAccesses == null || hostAccesses.isEmpty()) {
        _logger.info("No block host access found for the snap: {}", snapId);
        return;
    }
    List<BlockHostAccess> changedHostAccessList = new ArrayList<BlockHostAccess>();
    /*
         * we have to detach the snap in order to unexport any host. we need to reattach the snap
         * after the unexport if the snap is still exported to any other hosts.
         */
    boolean needReattach = false;
    for (BlockHostAccess hostAccess : hostAccesses) {
        int accessMask = hostAccess.getAccessMask();
        if (hostId.equals(hostAccess.getHost().getId())) {
            if (accessMask == HostLUNAccessEnum.BOTH.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.PRODUCTION.getValue());
            } else if (accessMask == HostLUNAccessEnum.SNAPSHOT.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.NOACCESS.getValue());
            }
        } else if (detach && !needReattach && (accessMask == HostLUNAccessEnum.BOTH.getValue() || accessMask == HostLUNAccessEnum.SNAPSHOT.getValue())) {
            needReattach = true;
        }
        changedHostAccessList.add(hostAccess);
    }
    if (changedHostAccessList.isEmpty()) {
        // the removing hosts are not exported
        _logger.info("The unexport hosts were not exported.");
        return;
    }
    if (!needReattach && detach && groupId != null) {
        // Check if there are other exported snaps in the snap group
        String cgId = parentLun.getStorageResource().getId();
        if (cgId != null && !cgId.isEmpty()) {
            BlockLunRequests lunReq = new BlockLunRequests(_khClient);
            List<VNXeLun> luns = lunReq.getLunsInLunGroup(cgId);
            for (VNXeLun cgLun : luns) {
                if (cgLun.getId().equals(parentLun.getId())) {
                    continue;
                }
                List<BlockHostAccess> hostAccess = cgLun.getHostAccess();
                if (hostAccess == null) {
                    continue;
                }
                for (BlockHostAccess hostA : hostAccess) {
                    int mask = hostA.getAccessMask();
                    if (mask == HostLUNAccessEnum.BOTH.getValue() || mask == HostLUNAccessEnum.SNAPSHOT.getValue()) {
                        needReattach = true;
                        break;
                    }
                }
                if (needReattach) {
                    break;
                }
            }
        } else {
            _logger.warn(String.format("The storage resource id is empty for the lun ", parentLun.getName()));
        }
    }
    LunParam lunParam = new LunParam();
    lunParam.setHostAccess(changedHostAccessList);
    LunModifyParam modifyParam = new LunModifyParam();
    modifyParam.setLunParameters(lunParam);
    int type = parentLun.getType();
    if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
        // if standalone lun
        BlockLunRequests lunReq = new BlockLunRequests(_khClient);
        lunReq.modifyLunSync(modifyParam, parentLun.getStorageResource().getId());
    } else {
        // lun in a lun group
        modifyParam.setLun(new VNXeBase(parentLun.getId()));
        List<LunModifyParam> list = new ArrayList<LunModifyParam>();
        list.add(modifyParam);
        LunGroupModifyParam groupParam = new LunGroupModifyParam();
        groupParam.setLunModify(list);
        if (!_khClient.isUnity()) {
            LunGroupRequests lunGroupReq = new LunGroupRequests(_khClient);
            lunGroupReq.modifyLunGroupSync(parentLun.getStorageResource().getId(), groupParam);
        } else {
            ConsistencyGroupRequests cgReq = new ConsistencyGroupRequests(_khClient);
            cgReq.modifyConsistencyGroupSync(parentLun.getStorageResource().getId(), groupParam);
        }
    }
    if (needReattach) {
        if (!_khClient.isUnity()) {
            attachLunSnap(snapId);
        } else {
            if (groupId == null) {
                attachSnap(snapId);
            } else {
                attachSnap(groupId);
            }
        }
    }
    _logger.info("Done unexporting lun: {}", snapId);
}
Also used : ArrayList(java.util.ArrayList) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeFileSystemSnap(com.emc.storageos.vnxe.models.VNXeFileSystemSnap) VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) Snap(com.emc.storageos.vnxe.models.Snap) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunParam(com.emc.storageos.vnxe.models.LunParam) BlockLunRequests(com.emc.storageos.vnxe.requests.BlockLunRequests) LunGroupRequests(com.emc.storageos.vnxe.requests.LunGroupRequests) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) HostLunModifyParam(com.emc.storageos.vnxe.models.HostLunModifyParam) LunModifyParam(com.emc.storageos.vnxe.models.LunModifyParam)

Example 9 with BlockHostAccess

use of com.emc.storageos.vnxe.models.BlockHostAccess in project coprhd-controller by CoprHD.

the class VNXeApiClient method unexportLun.

/**
 * remove the hosts from the hostAccess list from the lun
 *
 * @param host
 * @param lunId
 */
public void unexportLun(String hostId, String lunId) {
    _logger.info("Unexporting lun: {}", lunId);
    if (!checkLunExists(lunId)) {
        _logger.info("The lun {} does not exist, do nothing", lunId);
        return;
    }
    VNXeLun lun = getLun(lunId);
    if (lun == null) {
        _logger.info("Could not find lun in the vxne: {}", lunId);
        return;
    }
    List<BlockHostAccess> hostAccesses = lun.getHostAccess();
    if (hostAccesses == null || hostAccesses.isEmpty()) {
        _logger.info("No block host access found for the lun: {}", lunId);
        return;
    }
    List<BlockHostAccess> changedHostAccessList = new ArrayList<BlockHostAccess>();
    for (BlockHostAccess hostAccess : hostAccesses) {
        if (hostId.equals(hostAccess.getHost().getId())) {
            if (hostAccess.getAccessMask() == HostLUNAccessEnum.BOTH.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.SNAPSHOT.getValue());
            } else if (hostAccess.getAccessMask() == HostLUNAccessEnum.PRODUCTION.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.NOACCESS.getValue());
            }
        }
        changedHostAccessList.add(hostAccess);
    }
    if (changedHostAccessList.isEmpty()) {
        // the removing hosts are not exported
        _logger.info("The unexport hosts were not exported.");
        return;
    }
    LunParam lunParam = new LunParam();
    lunParam.setHostAccess(changedHostAccessList);
    LunModifyParam modifyParam = new LunModifyParam();
    modifyParam.setLunParameters(lunParam);
    int type = lun.getType();
    if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
        // if standalone lun
        BlockLunRequests lunReq = new BlockLunRequests(_khClient);
        lunReq.modifyLunSync(modifyParam, lun.getStorageResource().getId());
    } else {
        // lun in a lun group
        modifyParam.setLun(new VNXeBase(lunId));
        List<LunModifyParam> list = new ArrayList<LunModifyParam>();
        list.add(modifyParam);
        LunGroupModifyParam groupParam = new LunGroupModifyParam();
        groupParam.setLunModify(list);
        if (!_khClient.isUnity()) {
            LunGroupRequests lunGroupReq = new LunGroupRequests(_khClient);
            lunGroupReq.modifyLunGroupSync(lun.getStorageResource().getId(), groupParam);
        } else {
            ConsistencyGroupRequests cgReq = new ConsistencyGroupRequests(_khClient);
            cgReq.modifyConsistencyGroupSync(lun.getStorageResource().getId(), groupParam);
        }
    }
    _logger.info("Done unexporting lun: {}", lunId);
}
Also used : ArrayList(java.util.ArrayList) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunParam(com.emc.storageos.vnxe.models.LunParam) BlockLunRequests(com.emc.storageos.vnxe.requests.BlockLunRequests) LunGroupRequests(com.emc.storageos.vnxe.requests.LunGroupRequests) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) HostLunModifyParam(com.emc.storageos.vnxe.models.HostLunModifyParam) LunModifyParam(com.emc.storageos.vnxe.models.LunModifyParam)

Example 10 with BlockHostAccess

use of com.emc.storageos.vnxe.models.BlockHostAccess in project coprhd-controller by CoprHD.

the class VNXeApiClient method createLunsInConsistencyGroup.

/**
 * Create multiple volumes in a lun group
 *
 * @param names
 * @param poolId
 * @param size
 * @param isThin
 * @param tieringPolicy
 * @param cgId
 * @return
 */
public VNXeCommandJob createLunsInConsistencyGroup(List<String> names, String poolId, Long size, boolean isThin, String tieringPolicy, String cgId) {
    _logger.info("creating luns in the consistencyGroup group: {}", cgId);
    LunGroupModifyParam param = new LunGroupModifyParam();
    List<LunCreateParam> lunCreates = new ArrayList<LunCreateParam>();
    boolean isPolicyOn = false;
    FastVPParam fastVP = new FastVPParam();
    if (tieringPolicy != null && !tieringPolicy.isEmpty()) {
        TieringPolicyEnum tierValue = TieringPolicyEnum.valueOf(tieringPolicy);
        if (tierValue != null) {
            fastVP.setTieringPolicy(tierValue.getValue());
            isPolicyOn = true;
        }
    }
    StorageResourceRequest cgRequest = new StorageResourceRequest(_khClient);
    StorageResource cg = cgRequest.get(cgId);
    for (String lunName : names) {
        LunParam lunParam = new LunParam();
        lunParam.setIsThinEnabled(isThin);
        lunParam.setSize(size);
        lunParam.setPool(new VNXeBase(poolId));
        List<BlockHostAccess> hostAccesses = cg.getBlockHostAccess();
        if (hostAccesses != null && !hostAccesses.isEmpty()) {
            for (BlockHostAccess hostAccess : hostAccesses) {
                hostAccess.setAccessMask(HostLUNAccessEnum.NOACCESS.getValue());
            }
            lunParam.setHostAccess(hostAccesses);
        }
        LunCreateParam createParam = new LunCreateParam();
        createParam.setName(lunName);
        createParam.setLunParameters(lunParam);
        if (isPolicyOn) {
            lunParam.setFastVPParameters(fastVP);
        }
        lunCreates.add(createParam);
    }
    param.setLunCreate(lunCreates);
    ConsistencyGroupRequests req = new ConsistencyGroupRequests(_khClient);
    return req.modifyConsistencyGroupAsync(cgId, param);
}
Also used : StorageResource(com.emc.storageos.vnxe.models.StorageResource) FastVPParam(com.emc.storageos.vnxe.models.FastVPParam) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ArrayList(java.util.ArrayList) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) TieringPolicyEnum(com.emc.storageos.vnxe.models.StorageResource.TieringPolicyEnum) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunParam(com.emc.storageos.vnxe.models.LunParam) StorageResourceRequest(com.emc.storageos.vnxe.requests.StorageResourceRequest) DeleteStorageResourceRequest(com.emc.storageos.vnxe.requests.DeleteStorageResourceRequest) LunCreateParam(com.emc.storageos.vnxe.models.LunCreateParam)

Aggregations

BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)10 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)8 ArrayList (java.util.ArrayList)6 LunGroupModifyParam (com.emc.storageos.vnxe.models.LunGroupModifyParam)5 LunParam (com.emc.storageos.vnxe.models.LunParam)5 ConsistencyGroupRequests (com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)5 HostLunModifyParam (com.emc.storageos.vnxe.models.HostLunModifyParam)4 LunModifyParam (com.emc.storageos.vnxe.models.LunModifyParam)4 VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)4 BlockLunRequests (com.emc.storageos.vnxe.requests.BlockLunRequests)4 LunGroupRequests (com.emc.storageos.vnxe.requests.LunGroupRequests)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 StringMap (com.emc.storageos.db.client.model.StringMap)3 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)3 HashMap (java.util.HashMap)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)2 HostLun (com.emc.storageos.vnxe.models.HostLun)2 Snap (com.emc.storageos.vnxe.models.Snap)2