Search in sources :

Example 1 with VNXeLun

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

the class VNXUnityUnManagedObjectDiscoverer 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 = getVnxUnityClient(accessProfile);
    unManagedVolumesInsert = new ArrayList<UnManagedVolume>();
    unManagedVolumesUpdate = new ArrayList<UnManagedVolume>();
    unManagedCGToUpdateMap = new HashMap<String, UnManagedConsistencyGroup>();
    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);
        Map<String, List<UnManagedVolume>> hostVolumesMap = new HashMap<String, List<UnManagedVolume>>();
        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, hostVolumesMap);
            unManagedVolumesReturnedFromProvider.add(unManagedVolume.getId());
            Boolean isVolumeInCG = lun.getType() == VNXeApiClient.GENERIC_STORAGE_LUN_TYPE ? true : false;
            String cgId = null;
            if (isVolumeInCG) {
                cgId = lun.getStorageResource().getId();
                addObjectToUnManagedConsistencyGroup(apiClient, unManagedVolume, cgId, storageSystem, dbClient);
            } else {
                // Make sure the unManagedVolume object does not contain CG information from previous discovery
                unManagedVolume.getVolumeCharacterstics().put(SupportedVolumeCharacterstics.IS_VOLUME_ADDED_TO_CONSISTENCYGROUP.toString(), Boolean.FALSE.toString());
                // set the uri of the unmanaged CG in the unmanaged volume object to empty
                unManagedVolume.getVolumeInformation().put(SupportedVolumeInformation.UNMANAGED_CONSISTENCY_GROUP_URI.toString(), "");
            }
            // Discover snaps
            Integer snapCount = lun.getSnapCount();
            boolean hasSnap = false;
            if (snapCount > 0) {
                List<Snap> snaps = apiClient.getSnapshotsForLun(lun.getId());
                if (snaps != null && !snaps.isEmpty()) {
                    StringSet parentMatchedVPools = unManagedVolume.getSupportedVpoolUris();
                    StringSet discoveredSnaps = discoverVolumeSnaps(storageSystem, snaps, unManagedVolumeNatvieGuid, parentMatchedVPools, apiClient, dbClient, hostVolumesMap, lun, isVolumeInCG, cgId);
                    if (discoveredSnaps != null && !discoveredSnaps.isEmpty()) {
                        hasSnap = true;
                        unManagedVolume.getVolumeCharacterstics().put(SupportedVolumeCharacterstics.HAS_REPLICAS.toString(), Boolean.TRUE.toString());
                        StringSetMap unManagedVolumeInformation = unManagedVolume.getVolumeInformation();
                        if (unManagedVolumeInformation.containsKey(SupportedVolumeInformation.SNAPSHOTS.toString())) {
                            // replace with new StringSet
                            unManagedVolumeInformation.get(SupportedVolumeInformation.SNAPSHOTS.toString()).replace(discoveredSnaps);
                            log.info("Replaced snaps :" + Joiner.on("\t").join(unManagedVolumeInformation.get(SupportedVolumeInformation.SNAPSHOTS.toString())));
                        } else {
                            unManagedVolumeInformation.put(SupportedVolumeInformation.SNAPSHOTS.toString(), discoveredSnaps);
                        }
                    }
                }
            }
            if (!hasSnap) {
                // no snap
                unManagedVolume.getVolumeCharacterstics().put(SupportedVolumeCharacterstics.HAS_REPLICAS.toString(), Boolean.FALSE.toString());
                StringSetMap unManagedVolumeInformation = unManagedVolume.getVolumeInformation();
                if (unManagedVolumeInformation != null && unManagedVolumeInformation.containsKey(SupportedVolumeInformation.SNAPSHOTS.toString())) {
                    // replace with empty string set doesn't work, hence added explicit code to remove all
                    unManagedVolumeInformation.get(SupportedVolumeInformation.SNAPSHOTS.toString()).clear();
                }
            }
        }
        if (!unManagedCGToUpdateMap.isEmpty()) {
            unManagedCGToUpdate = new ArrayList<UnManagedConsistencyGroup>(unManagedCGToUpdateMap.values());
            partitionManager.updateAndReIndexInBatches(unManagedCGToUpdate, unManagedCGToUpdate.size(), dbClient, UNMANAGED_CONSISTENCY_GROUP);
            unManagedCGToUpdate.clear();
        }
        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);
        // Process those active unmanaged consistency group objects available in database but not in newly
        // discovered items, to mark them
        // inactive.
        DiscoveryUtils.performUnManagedConsistencyGroupsBookKeeping(storageSystem, allCurrentUnManagedCgURIs, dbClient, partitionManager);
        // Next discover the unmanaged export masks
        discoverUnmanagedExportMasks(storageSystem.getId(), hostVolumesMap, apiClient, dbClient, partitionManager);
    } else {
        log.info("There are no luns found on the system: {}", storageSystem.getId());
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StoragePool(com.emc.storageos.db.client.model.StoragePool) UnManagedConsistencyGroup(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedConsistencyGroup) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) Snap(com.emc.storageos.vnxe.models.Snap) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with VNXeLun

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

the class VNXeBlockSnapshotCreateJob 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());
        if (_status == JobStatus.SUCCESS) {
            _logger.info(String.format("Post-processing successful snap creation task:%s. Expected: snapshot.size() = 1; Actual: snapshots.size() = %d", getTaskCompleter().getOpId(), snapshots.size()));
            StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            BlockSnapshot snapshot = snapshots.get(0);
            Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
            snapshot.setNativeId(output.getId());
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
            snapshot.setIsSyncActive(true);
            snapshot.setInactive(false);
            snapshot.setCreationTime(Calendar.getInstance());
            if (vnxeApiClient.isUnityClient()) {
                Snap snap = vnxeApiClient.getSnapshot(output.getId());
                snapshot.setDeviceLabel(snap.getName());
                snapshot.setAllocatedCapacity(snap.getSize());
                snapshot.setProvisionedCapacity(snap.getSize());
            } else {
                VNXeLunSnap vnxeLunSnap = vnxeApiClient.getLunSnapshot(output.getId());
                VNXeLun lun = vnxeApiClient.getLun(vnxeLunSnap.getLun().getId());
                snapshot.setDeviceLabel(vnxeLunSnap.getName());
                snapshot.setAllocatedCapacity(lun.getSnapsSizeAllocated());
                snapshot.setProvisionedCapacity(lun.getSnapsSize());
            }
            _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s. Associated volume is %3$s (%4$s)", snapshot.getId().toString(), output.getId(), volume.getNativeId(), volume.getLabel()));
            dbClient.updateObject(snapshot);
            getTaskCompleter().ready(dbClient);
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            BlockSnapshot snapshot = snapshots.get(0);
            snapshot.setInactive(true);
            dbClient.updateObject(snapshot);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockSnapshotCreateJob", e);
        setErrorStatus("Encountered an internal error during volume snapshot create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) Snap(com.emc.storageos.vnxe.models.Snap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) 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 3 with VNXeLun

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

the class VNXeCreateVolumesJob method processVolumesinConsistencyGroup.

private void processVolumesinConsistencyGroup(VNXeApiClient apiClient, List<URI> volIds, DbClient dbClient, StringBuilder logMsgBuilder, Calendar creationTime) throws IOException {
    BlockConsistencyGroup group = null;
    for (URI volId : volIds) {
        Volume volume = dbClient.queryObject(Volume.class, volId);
        // Honor that the job failed and do not commit the volume, which would make it active again.
        if (volume.getInactive()) {
            if (logMsgBuilder.length() != 0) {
                logMsgBuilder.append("\n");
            }
            logMsgBuilder.append(String.format("Create volume job failed and volume set to inactive. Volume was likely created successfully and will be left on the array for ingestion. NativeId: %s, URI: %s", volume.getNativeId(), getTaskCompleter().getId()));
            return;
        }
        volume.setCreationTime(creationTime);
        if (group == null) {
            group = dbClient.queryObject(BlockConsistencyGroup.class, volume.getConsistencyGroup());
        }
        String cgId = null;
        if (apiClient.isUnityClient()) {
            String cgName = volume.getReplicationGroupInstance();
            cgId = apiClient.getConsistencyGroupIdByName(cgName);
        } else {
            cgId = group.getCgNameOnStorageSystem(volume.getStorageController());
        }
        VNXeLun vnxeLun = apiClient.getLunByLunGroup(cgId, volume.getNativeGuid());
        if (vnxeLun != null) {
            updateVolume(volume, vnxeLun, dbClient);
            dbClient.updateObject(volume);
            if (logMsgBuilder.length() != 0) {
                logMsgBuilder.append("\n");
            }
            logMsgBuilder.append(String.format("Created volume successfully .. NativeId: %s, URI: %s", vnxeLun.getId(), volId.toString()));
        } else {
            _logger.error("Could not find the lun:{} in the array", volume.getNativeGuid());
        }
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) URI(java.net.URI) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 4 with VNXeLun

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

the class VNXeCreateVolumesJob method processVolume.

private void processVolume(VNXeApiClient apiClient, String nativeId, URI volumeId, DbClient dbClient, StringBuilder logMsgBuilder, Calendar creationTime) throws IOException, DeviceControllerException {
    Volume volume = dbClient.queryObject(Volume.class, volumeId);
    // Honor that the job failed and do not commit the volume, which would make it active again.
    if (volume.getInactive()) {
        if (logMsgBuilder.length() != 0) {
            logMsgBuilder.append("\n");
        }
        logMsgBuilder.append(String.format("Create volume job failed and volume set to inactive. Volume was likely created successfully and will be left on the array for ingestion. NativeId: %s, URI: %s", nativeId, getTaskCompleter().getId()));
        return;
    }
    volume.setCreationTime(creationTime);
    VNXeLun vnxeLun = apiClient.getLun(nativeId);
    if (vnxeLun != null) {
        updateVolume(volume, vnxeLun, dbClient);
        if (logMsgBuilder.length() != 0) {
            logMsgBuilder.append("\n");
        }
        logMsgBuilder.append(String.format("Created volume successfully .. NativeId: %s, URI: %s", nativeId, volumeId.toString()));
    } else {
        _logger.error("Could not find the lun: {} in the array", nativeId);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun)

Example 5 with VNXeLun

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

the class VNXeBlockRestoreSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        _logger.info(String.format("Updating status of job %s to %s", opId, _status.name()));
        URI snapId = getTaskCompleter().getId();
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapId);
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS && snapshotObj != null) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            // get the id of the backup snapshot created before restore operation
            String backUpSnapId = output.getBackup().getId();
            if (snapshotObj.getConsistencyGroup() != null) {
                VNXeLunGroupSnap backupSnap = vnxeApiClient.getLunGroupSnapshot(backUpSnapId);
                List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(backupSnap.getStorageResource().getId());
                // Create a snapshot corresponding to the backup snap for each volume in the consistency group
                URI cgID = snapshotObj.getConsistencyGroup();
                List<Volume> cgVolumes = getCGVolumes(cgID.toString(), dbClient);
                final List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
                Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
                for (Volume vol : cgVolumes) {
                    final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
                    newSnap.setOpStatus(new OpStatusMap());
                    snapshotList.add(newSnap);
                    volumeToSnapMap.put(vol.getNativeId(), newSnap);
                }
                // Add vnxe information to the new snapshots
                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(backUpSnapId);
                    snapshot.setReplicationGroupInstance(backUpSnapId);
                    processSnapshot(snapshot, storage, groupLun, dbClient);
                }
                dbClient.createObject(snapshotList);
            } else {
                VNXeLunSnap backupSnap = vnxeApiClient.getLunSnapshot(backUpSnapId);
                VNXeLun lun = vnxeApiClient.getLun(backupSnap.getLun().getId());
                Volume vol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
                final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
                newSnap.setNativeId(backUpSnapId);
                processSnapshot(newSnap, storage, lun, dbClient);
            }
            getTaskCompleter().ready(dbClient);
        } else if (_status == JobStatus.FAILED && snapshotObj != null) {
            _logger.info(String.format("Task %s failed to restore volume snapshot: %s", opId, snapshotObj.getLabel()));
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockRestoreSnapshotJob", e);
        setErrorStatus("Encountered an internal error during snapshot restore 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) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) 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)

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