Search in sources :

Example 1 with HostLun

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

the class VNXUnityArrayAffinityDiscoverer method getPreferredPoolMap.

/**
 * Construct pool to pool type map for a host
 *
 * @param system
 * @param hostId
 * @param apiClient
 * @param dbClient
 * @return pool to pool type map
 * @throws IOException
 */
private Map<String, String> getPreferredPoolMap(StorageSystem system, URI hostId, VNXeApiClient apiClient, DbClient dbClient) throws IOException {
    Map<String, String> preferredPoolMap = new HashMap<String, String>();
    Map<String, StoragePool> pools = getStoragePoolMap(system, dbClient);
    List<Initiator> allInitiators = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Initiator.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(hostId, Initiator.class, Constants.HOST));
    String vnxeHostId = null;
    for (Initiator initiator : allInitiators) {
        logger.info("Processing initiator {}", initiator.getLabel());
        String initiatorId = initiator.getInitiatorPort();
        if (Protocol.FC.name().equals(initiator.getProtocol())) {
            initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
        }
        // query VNX Unity initiator
        VNXeHostInitiator vnxeInitiator = apiClient.getInitiatorByWWN(initiatorId);
        if (vnxeInitiator != null) {
            VNXeBase parentHost = vnxeInitiator.getParentHost();
            if (parentHost != null) {
                vnxeHostId = parentHost.getId();
                break;
            }
        }
    }
    if (vnxeHostId == null) {
        logger.info("Host {} cannot be found on array", hostId);
        return preferredPoolMap;
    }
    // Get vnxeHost from vnxeHostId
    VNXeHost vnxeHost = apiClient.getHostById(vnxeHostId);
    List<VNXeBase> hostLunIds = vnxeHost.getHostLUNs();
    if (hostLunIds != null && !hostLunIds.isEmpty()) {
        for (VNXeBase hostLunId : hostLunIds) {
            HostLun hostLun = apiClient.getHostLun(hostLunId.getId());
            // get lun from from hostLun
            VNXeBase lunId = hostLun.getLun();
            if (lunId != null) {
                VNXeLun lun = apiClient.getLun(lunId.getId());
                if (lun != null) {
                    String nativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(system.getNativeGuid(), lun.getId());
                    if (DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, nativeGuid) != null) {
                        logger.info("Skipping volume {} as it is already managed by ViPR", nativeGuid);
                        continue;
                    }
                    StoragePool pool = getStoragePoolOfUnManagedObject(lun.getPool().getId(), system, pools);
                    if (pool != null) {
                        String exportType = isSharedLun(lun) ? ExportGroup.ExportGroupType.Cluster.name() : ExportGroup.ExportGroupType.Host.name();
                        ArrayAffinityDiscoveryUtils.addPoolToPreferredPoolMap(preferredPoolMap, pool.getId().toString(), exportType);
                    } else {
                        logger.error("Skipping volume {} as its storage pool doesn't exist in ViPR", lun.getId());
                    }
                }
            }
        }
    }
    return preferredPoolMap;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) HostLun(com.emc.storageos.vnxe.models.HostLun) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun)

Example 2 with HostLun

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

the class VNXUnityExportOperations method findHLUsForInitiators.

@Override
public Set<Integer> findHLUsForInitiators(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) {
    Set<Integer> usedHLUs = new HashSet<Integer>();
    try {
        Set<String> vnxeHostIds = new HashSet<String>();
        VNXeApiClient apiClient = getVnxeClient(storage);
        for (String initiatorName : initiatorNames) {
            initiatorName = Initiator.toPortNetworkId(initiatorName);
            URIQueryResultList initiatorResult = new URIQueryResultList();
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(initiatorName), initiatorResult);
            if (initiatorResult.iterator().hasNext()) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorResult.iterator().next());
                String initiatorId = initiator.getInitiatorPort();
                if (Protocol.FC.name().equals(initiator.getProtocol())) {
                    initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
                }
                // query VNX Unity initiator
                VNXeHostInitiator vnxeInitiator = apiClient.getInitiatorByWWN(initiatorId);
                if (vnxeInitiator != null) {
                    VNXeBase parentHost = vnxeInitiator.getParentHost();
                    if (parentHost != null) {
                        vnxeHostIds.add(parentHost.getId());
                    }
                }
            }
        }
        if (vnxeHostIds.isEmpty()) {
            log.info("No Host found on array for initiators {}", Joiner.on(',').join(initiatorNames));
        } else {
            log.info("Found matching hosts {} on array", vnxeHostIds);
            for (String vnxeHostId : vnxeHostIds) {
                // Get vnxeHost from vnxeHostId
                VNXeHost vnxeHost = apiClient.getHostById(vnxeHostId);
                List<VNXeBase> hostLunIds = vnxeHost.getHostLUNs();
                if (hostLunIds != null && !hostLunIds.isEmpty()) {
                    for (VNXeBase hostLunId : hostLunIds) {
                        HostLun hostLun = apiClient.getHostLun(hostLunId.getId());
                        log.info("Looking at Host Lun {}; Lun: {}, HLU: {}", hostLunId.getId(), hostLun.getLun(), hostLun.getHlu());
                        usedHLUs.add(hostLun.getHlu());
                    }
                }
            }
        }
        log.info(String.format("HLUs found for Initiators { %s }: %s", Joiner.on(',').join(initiatorNames), usedHLUs));
    } catch (Exception e) {
        String errMsg = "Encountered an error when attempting to query used HLUs for initiators: " + e.getMessage();
        log.error(errMsg, e);
        throw VNXeException.exceptions.hluRetrievalFailed(errMsg, e);
    }
    return usedHLUs;
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HostLun(com.emc.storageos.vnxe.models.HostLun) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VNXeException(com.emc.storageos.vnxe.VNXeException) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) HashSet(java.util.HashSet)

Example 3 with HostLun

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

the class HostLunRequestsTest method findHostLunTest.

@Test
public void findHostLunTest() {
    HostLunRequests req = new HostLunRequests(_client);
    HostLun hostLun = req.getHostLun("sv_1", "Host_4", HostLunRequests.ID_SEQUENCE_LUN);
    System.out.println(hostLun.getHlu());
}
Also used : HostLun(com.emc.storageos.vnxe.models.HostLun) Test(org.junit.Test)

Example 4 with HostLun

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

the class VNXeApiClient method exportLun.

/**
 * Export a lun for a given host
 *
 * @param host
 *            host
 * @param lunId
 *            lun id
 * @param newhlu
 *            HLU
 * @return
 * @throws VNXeException
 */
public VNXeExportResult exportLun(VNXeBase host, String lunId, Integer newhlu) throws VNXeException {
    _logger.info("Exporting lun: {}", lunId);
    VNXeLun lun = getLun(lunId);
    if (lun == null) {
        _logger.info("Could not find lun in the vxne: {}", lunId);
        throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun : " + lunId);
    }
    List<BlockHostAccess> hostAccesses = lun.getHostAccess();
    boolean lunHostAccessExists = false;
    if (hostAccesses == null) {
        hostAccesses = new ArrayList<BlockHostAccess>();
    } else {
        // already defined for the given host with a different access mask.
        for (BlockHostAccess hostAccess : hostAccesses) {
            String hostId = hostAccess.getHost().getId();
            if (hostId.equals(host.getId())) {
                if (hostAccess.getAccessMask() == HostLUNAccessEnum.SNAPSHOT.getValue()) {
                    hostAccess.setAccessMask(HostLUNAccessEnum.BOTH.getValue());
                    lunHostAccessExists = true;
                    break;
                } else if (hostAccess.getAccessMask() == HostLUNAccessEnum.NOACCESS.getValue()) {
                    hostAccess.setAccessMask(HostLUNAccessEnum.PRODUCTION.getValue());
                    lunHostAccessExists = true;
                    break;
                }
            }
        }
    }
    if (!lunHostAccessExists) {
        BlockHostAccess access = new BlockHostAccess();
        access.setHost(host);
        access.setAccessMask(BlockHostAccess.HostLUNAccessEnum.PRODUCTION.getValue());
        hostAccesses.add(access);
    }
    LunParam lunParam = new LunParam();
    lunParam.setHostAccess(hostAccesses);
    LunModifyParam exportParam = new LunModifyParam();
    exportParam.setLunParameters(lunParam);
    int type = lun.getType();
    if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
        // if standalone lun
        BlockLunRequests lunReq = new BlockLunRequests(_khClient);
        lunReq.modifyLunSync(exportParam, lun.getStorageResource().getId());
    } else {
        // lun in a lun group
        exportParam.setLun(new VNXeBase(lunId));
        List<LunModifyParam> list = new ArrayList<LunModifyParam>();
        list.add(exportParam);
        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);
        }
    }
    // get hlu
    HostLunRequests hostLunReq = new HostLunRequests(_khClient);
    HostLun hostLun = hostLunReq.getHostLun(lunId, host.getId(), HostLunRequests.ID_SEQUENCE_LUN);
    int hluResult = hostLun.getHlu();
    if (isUnityClient() && newhlu != null && newhlu.intValue() != -1) {
        _logger.info("Modify hlu");
        modifyHostLunHlu(host.getId(), hostLun.getId(), newhlu);
        hluResult = newhlu;
    }
    VNXeExportResult result = new VNXeExportResult();
    result.setHlu(hluResult);
    result.setLunId(lunId);
    result.setHostId(host.getId());
    result.setNewAccess(!lunHostAccessExists);
    _logger.info("Done exporting lun: {}", lunId);
    return result;
}
Also used : HostLunRequests(com.emc.storageos.vnxe.requests.HostLunRequests) ArrayList(java.util.ArrayList) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) HostLun(com.emc.storageos.vnxe.models.HostLun) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests) VNXeExportResult(com.emc.storageos.vnxe.models.VNXeExportResult) 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 5 with HostLun

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

the class VNXeApiClient method exportSnap.

/**
 * Export a snap for a given host
 *
 * @param host
 *            host
 * @param snapId
 *            snap id
 * @param newhlu
 *            HLU
 * @return
 * @throws VNXeException
 */
public VNXeExportResult exportSnap(VNXeBase host, String snapId, Integer newhlu) throws VNXeException {
    _logger.info("Exporting lun snap: {}", snapId);
    String parentLunId = null;
    VNXeLun parentLun = null;
    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("Attaching the snap: {}", snapId);
            attachLunSnap(snapId);
        }
        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("Attaching the snap: {}", snapId);
            attachSnap(snapId);
        } else if (snapGroup != null && (!snap.isAttached())) {
            String groupId = snapGroup.getId();
            attachSnap(groupId);
        }
    }
    // Get host access info of the parent lun
    parentLun = getLun(parentLunId);
    List<BlockHostAccess> hostAccesses = parentLun.getHostAccess();
    boolean snapHostAccessExists = false;
    if (hostAccesses == null) {
        hostAccesses = new ArrayList<BlockHostAccess>();
    } else {
        // already defined for the given host with a different access mask.
        for (BlockHostAccess hostAccess : hostAccesses) {
            String hostId = hostAccess.getHost().getId();
            if (hostId.equals(host.getId())) {
                if (hostAccess.getAccessMask() == HostLUNAccessEnum.PRODUCTION.getValue()) {
                    hostAccess.setAccessMask(HostLUNAccessEnum.BOTH.getValue());
                    snapHostAccessExists = true;
                    break;
                } else if (hostAccess.getAccessMask() == HostLUNAccessEnum.NOACCESS.getValue()) {
                    hostAccess.setAccessMask(HostLUNAccessEnum.SNAPSHOT.getValue());
                    snapHostAccessExists = true;
                    break;
                }
            }
        }
    }
    if (!snapHostAccessExists) {
        BlockHostAccess access = new BlockHostAccess();
        access.setHost(host);
        access.setAccessMask(BlockHostAccess.HostLUNAccessEnum.SNAPSHOT.getValue());
        hostAccesses.add(access);
    }
    LunParam lunParam = new LunParam();
    lunParam.setHostAccess(hostAccesses);
    LunModifyParam exportParam = new LunModifyParam();
    exportParam.setLunParameters(lunParam);
    int type = parentLun.getType();
    if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
        // if standalone lun
        BlockLunRequests lunReq = new BlockLunRequests(_khClient);
        lunReq.modifyLunSync(exportParam, parentLun.getStorageResource().getId());
    } else {
        // parent lun in a lun group
        exportParam.setLun(new VNXeBase(parentLun.getId()));
        List<LunModifyParam> list = new ArrayList<LunModifyParam>();
        list.add(exportParam);
        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);
        }
    }
    // get hlu
    HostLunRequests hostLunReq = new HostLunRequests(_khClient);
    HostLun hostLun = hostLunReq.getHostLun(parentLun.getId(), host.getId(), HostLunRequests.ID_SEQUENCE_SNAP);
    int hluResult = hostLun.getHlu();
    if (isUnityClient() && newhlu != null && newhlu.intValue() != -1) {
        _logger.info("Modify hlu");
        modifyHostLunHlu(host.getId(), hostLun.getId(), newhlu);
        hluResult = newhlu;
    }
    VNXeExportResult result = new VNXeExportResult();
    result.setHlu(hluResult);
    result.setHostId(host.getId());
    result.setNewAccess(!snapHostAccessExists);
    _logger.info("Done exporting lun snap: {}", snapId);
    return result;
}
Also used : HostLunRequests(com.emc.storageos.vnxe.requests.HostLunRequests) ArrayList(java.util.ArrayList) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) HostLun(com.emc.storageos.vnxe.models.HostLun) 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) VNXeExportResult(com.emc.storageos.vnxe.models.VNXeExportResult) 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)

Aggregations

HostLun (com.emc.storageos.vnxe.models.HostLun)10 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)7 VNXeHost (com.emc.storageos.vnxe.models.VNXeHost)5 VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)4 Initiator (com.emc.storageos.db.client.model.Initiator)3 VNXeHostInitiator (com.emc.storageos.vnxe.models.VNXeHostInitiator)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)2 HostLunModifyParam (com.emc.storageos.vnxe.models.HostLunModifyParam)2 LunGroupModifyParam (com.emc.storageos.vnxe.models.LunGroupModifyParam)2 LunModifyParam (com.emc.storageos.vnxe.models.LunModifyParam)2 LunParam (com.emc.storageos.vnxe.models.LunParam)2 Snap (com.emc.storageos.vnxe.models.Snap)2 VNXeExportResult (com.emc.storageos.vnxe.models.VNXeExportResult)2 BlockLunRequests (com.emc.storageos.vnxe.requests.BlockLunRequests)2 ConsistencyGroupRequests (com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)2 HostLunRequests (com.emc.storageos.vnxe.requests.HostLunRequests)2