Search in sources :

Example 16 with VNXeLun

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

the class VNXeUnManagedObjectDiscoverer method discoverUnManagedVolumes.

public void discoverUnManagedVolumes(AccessProfile accessProfile, DbClient dbClient, CoordinatorClient coordinator, PartitionManager partitionManager) throws Exception {
    log.info("Started discovery of UnManagedVolumes for system {}", accessProfile.getSystemId());
    VNXeApiClient apiClient = getVnxeClient(accessProfile);
    unManagedVolumesInsert = new ArrayList<UnManagedVolume>();
    unManagedVolumesUpdate = new ArrayList<UnManagedVolume>();
    StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
    List<VNXeLun> luns = apiClient.getAllLuns();
    if (luns != null && !luns.isEmpty()) {
        Map<String, StoragePool> pools = getStoragePoolMap(storageSystem, dbClient);
        for (VNXeLun lun : luns) {
            UnManagedVolume unManagedVolume = null;
            String managedVolumeNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), lun.getId());
            if (null != DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, managedVolumeNativeGuid)) {
                log.info("Skipping volume {} as it is already managed by ViPR", managedVolumeNativeGuid);
            }
            StoragePool storagePool = getStoragePoolOfUnManagedObject(lun.getPool().getId(), storageSystem, pools);
            if (null == storagePool) {
                log.error("Skipping unmanaged volume discovery as the volume {} storage pool doesn't exist in ViPR", lun.getId());
                continue;
            }
            String unManagedVolumeNatvieGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingVolume(storageSystem.getNativeGuid(), lun.getId());
            unManagedVolume = DiscoveryUtils.checkUnManagedVolumeExistsInDB(dbClient, unManagedVolumeNatvieGuid);
            unManagedVolume = createUnManagedVolume(unManagedVolume, unManagedVolumeNatvieGuid, lun, storageSystem, storagePool, dbClient);
            unManagedVolumesReturnedFromProvider.add(unManagedVolume.getId());
        }
        if (!unManagedVolumesInsert.isEmpty()) {
            partitionManager.insertInBatches(unManagedVolumesInsert, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_VOLUME);
        }
        if (!unManagedVolumesUpdate.isEmpty()) {
            partitionManager.updateAndReIndexInBatches(unManagedVolumesUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_VOLUME);
        }
        // Process those active unmanaged volume objects available in database but not in newly discovered items, to mark them inactive.
        DiscoveryUtils.markInActiveUnManagedVolumes(storageSystem, unManagedVolumesReturnedFromProvider, dbClient, partitionManager);
    } else {
        log.info("There are no luns found on the system: {}", storageSystem.getId());
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 17 with VNXeLun

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

the class VNXeBlockCreateCGSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        BlockSnapshotCreateCompleter completer = (BlockSnapshotCreateCompleter) getTaskCompleter();
        List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, completer.getSnapshotURIs());
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            // get the luns belonging to the lun group
            String lunGroupSnapId = output.getId();
            VNXeLunGroupSnap groupSnap = vnxeApiClient.getLunGroupSnapshot(lunGroupSnapId);
            List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(groupSnap.getStorageResource().getId());
            // Create mapping of volume.nativeDeviceId to BlockSnapshot object
            Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
            for (BlockSnapshot snapshot : snapshots) {
                Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
                volumeToSnapMap.put(volume.getNativeId(), snapshot);
            }
            for (VNXeLun groupLun : groupLuns) {
                BlockSnapshot snapshot = volumeToSnapMap.get(groupLun.getId());
                if (snapshot == null) {
                    _logger.info("No snapshot found for the vnxe lun - ", groupLun.getId());
                    continue;
                }
                snapshot.setNativeId(output.getId());
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                snapshot.setDeviceLabel(groupLun.getName());
                snapshot.setReplicationGroupInstance(lunGroupSnapId);
                snapshot.setIsSyncActive(true);
                snapshot.setInactive(false);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(groupLun.getSnapWwn());
                snapshot.setAllocatedCapacity(groupLun.getSnapsSizeAllocated());
                snapshot.setProvisionedCapacity(groupLun.getSnapsSize());
                _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s (%3$s). Associated lun is %4$s (%5$s)", snapshot.getId().toString(), output.getId(), snapshot.getLabel(), groupLun.getId(), groupLun.getName()));
                dbClient.persistObject(snapshot);
            }
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            dbClient.persistObject(snapshots);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockCreateCGSnapshotJob", e);
        setErrorStatus("Encountered an internal error during group snapshot create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 18 with VNXeLun

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

the class VNXeExpandVolumeJob method updateVolume.

/**
 * update Volume after expanded in VNXe
 *
 * @param volumeObj volume in vipr
 * @param dbClient DbClient
 * @param logMsgBuilder string builder for logging
 * @param vnxeApiClient VNXeApiClient
 */
private void updateVolume(Volume volumeObj, DbClient dbClient, StringBuilder logMsgBuilder, VNXeApiClient vnxeApiClient) {
    VNXeLun vnxeLun = null;
    vnxeLun = vnxeApiClient.getLun(volumeObj.getNativeId());
    if (vnxeLun != null) {
        volumeObj.setCapacity(vnxeLun.getSizeTotal());
        volumeObj.setAllocatedCapacity(vnxeLun.getSizeAllocated());
        volumeObj.setProvisionedCapacity(vnxeLun.getSizeTotal());
        logMsgBuilder.append(String.format("Expand volume successfully for NativeId: %s, URI: %s", volumeObj.getNativeId(), getTaskCompleter().getId()));
        dbClient.updateObject(volumeObj);
    } else {
        logMsgBuilder.append("Could not find corresponding volume in the VNXe, using the resource ID: ");
        logMsgBuilder.append(volumeObj.getNativeId());
    }
}
Also used : VNXeLun(com.emc.storageos.vnxe.models.VNXeLun)

Example 19 with VNXeLun

use of com.emc.storageos.vnxe.models.VNXeLun 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 20 with VNXeLun

use of com.emc.storageos.vnxe.models.VNXeLun 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)

Aggregations

VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)22 ArrayList (java.util.ArrayList)9 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)7 BlockLunRequests (com.emc.storageos.vnxe.requests.BlockLunRequests)7 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 Volume (com.emc.storageos.db.client.model.Volume)5 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)5 HostLunModifyParam (com.emc.storageos.vnxe.models.HostLunModifyParam)5 LunGroupModifyParam (com.emc.storageos.vnxe.models.LunGroupModifyParam)5 LunModifyParam (com.emc.storageos.vnxe.models.LunModifyParam)5 LunParam (com.emc.storageos.vnxe.models.LunParam)5 ConsistencyGroupRequests (com.emc.storageos.vnxe.requests.ConsistencyGroupRequests)5 LunGroupRequests (com.emc.storageos.vnxe.requests.LunGroupRequests)5 HashMap (java.util.HashMap)5 StoragePool (com.emc.storageos.db.client.model.StoragePool)4 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)4 HostLun (com.emc.storageos.vnxe.models.HostLun)4 Snap (com.emc.storageos.vnxe.models.Snap)4 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)4 VNXeLunGroupSnap (com.emc.storageos.vnxe.models.VNXeLunGroupSnap)4