Search in sources :

Example 81 with BlockObject

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

the class ExternalBlockStorageDevice method doRestoreFromGroupClone.

@Override
public void doRestoreFromGroupClone(StorageSystem storageSystem, List<URI> cloneVolumes, TaskCompleter taskCompleter) {
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = null;
    List<Volume> clones = dbClient.queryObject(Volume.class, cloneVolumes);
    _log.info("Restore from group clone on storage system {}, clones: {} .", storageSystem.getNativeId(), clones.toString());
    try {
        Map<VolumeClone, Volume> driverCloneToCloneMap = new HashMap<>();
        List<VolumeClone> driverClones = new ArrayList<>();
        for (Volume clone : clones) {
            BlockObject sourceVolume = BlockObject.fetch(dbClient, clone.getAssociatedSourceVolume());
            VolumeClone driverClone = new VolumeClone();
            driverClone.setStorageSystemId(storageSystem.getNativeId());
            driverClone.setNativeId(clone.getNativeId());
            driverClone.setParentId(sourceVolume.getNativeId());
            driverClone.setConsistencyGroup(clone.getReplicationGroupInstance());
            driverClones.add(driverClone);
            driverCloneToCloneMap.put(driverClone, clone);
        }
        // Call driver
        task = driver.restoreFromClone(Collections.unmodifiableList(driverClones));
        if (!isTaskInTerminalState(task.getStatus())) {
            // If the task is not in a terminal state and will be completed asynchronously
            // create a job to monitor the progress of the request and update the clone
            // volume replica state and call the completer as appropriate based on the result
            // of the request.
            RestoreFromGroupCloneExternalDeviceJob job = new RestoreFromGroupCloneExternalDeviceJob(storageSystem.getId(), cloneVolumes, task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            for (Map.Entry<VolumeClone, Volume> entry : driverCloneToCloneMap.entrySet()) {
                VolumeClone driverClone = entry.getKey();
                Volume clone = entry.getValue();
                ExternalDeviceUtils.updateRestoredClone(clone, driverClone, dbClient, false);
            }
            String msg = String.format("doRestoreFromGroupClone -- Restore from group clone: %s .", task.getMessage());
            _log.info(msg);
            dbClient.updateObject(clones);
            taskCompleter.ready(dbClient);
        } else {
            String msg = String.format("Failed to restore from group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
            _log.error(msg);
            ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromGroupClone", msg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String msg = String.format("Failed to restore from group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
        _log.error(msg, e);
        ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromGroupClone", msg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RestoreFromGroupCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromGroupCloneExternalDeviceJob) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject)

Example 82 with BlockObject

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

the class ExternalDeviceExportOperations method prepareVolumes.

/**
 * Prepare new driver volumes for driver export request (Ex. in context of create a new export mask,
 * or add new volumes to the existing mask).
 *
 * @param storage
 *            storage sytem
 * @param volumeURIHLUs
 *            mapping of volume uri to volume hlu
 * @param driverVolumes
 *            driver volumes (output)
 * @param driverVolumeToHLUMap
 *            map of driver volumes to hlu values
 * @param volumeNativeIdToUriMap
 *            map of volume native id to uri
 */
private void prepareVolumes(StorageSystem storage, VolumeURIHLU[] volumeURIHLUs, List<StorageVolume> driverVolumes, Map<String, String> driverVolumeToHLUMap, Map<String, URI> volumeNativeIdToUriMap) {
    for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
        URI volumeURI = volumeURIHLU.getVolumeURI();
        BlockObject volume = (BlockObject) dbClient.queryObject(volumeURI);
        StorageVolume driverVolume = createDriverVolume(storage, volume);
        driverVolumes.add(driverVolume);
        // We send volume lun number to driver in decimal format.
        Integer decimalHLU;
        if (volumeURIHLU.getHLU().equals(ExportGroup.LUN_UNASSIGNED_STR)) {
            // cannot parse "ffffffff" with
            // Integer.parseInt(volumeURIHLU.getHLU(),
            // 16),
            // got "NumberFormatException". Looks as
            // Java error ???
            decimalHLU = ExportGroup.LUN_UNASSIGNED;
        } else {
            decimalHLU = Integer.parseInt(volumeURIHLU.getHLU(), 16);
        }
        driverVolumeToHLUMap.put(driverVolume.getNativeId(), decimalHLU.toString());
        volumeNativeIdToUriMap.put(driverVolume.getNativeId(), volumeURI);
    }
    log.info("prepareVolumes: volume-HLU pairs for driver: {}", driverVolumeToHLUMap);
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 83 with BlockObject

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

the class HDSCloneOperations method createSingleClone.

/**
 * 1. Find ReplicationGroup objId from Device Manager
 * 2. Check dummy Host Group available on Storage System. if not available create a dummy Host Group name.
 * 3. Create a secondary volume and add dummy host group on it.
 * 4. create a SI pair
 *
 * Note that if createInactive is false, then a subsequent step in the
 * full copy creation workflow will do a wait for synchronization. This
 * will split the pair, which makes the clone active.
 *
 * @param storageSystem {@link StorageSystem}
 * @param sourceVolumeURI {@link URI}
 * @param cloneVolumeURI {@link URI}
 * @param createInactive {@link Boolean}
 * @param taskCompleter {@link TaskCompleter}
 */
@Override
public void createSingleClone(StorageSystem storageSystem, URI sourceVolumeURI, URI cloneVolumeURI, Boolean createInactive, TaskCompleter taskCompleter) {
    log.info("START createSingleClone operation");
    Volume cloneVolume = null;
    try {
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        HDSApiProtectionManager hdsApiProtectionManager = hdsApiClient.getHdsApiProtectionManager();
        String replicationGroupObjectID = hdsApiClient.getHdsApiProtectionManager().getReplicationGroupObjectId();
        if (replicationGroupObjectID == null) {
            log.error("Unable to find replication group information/pair management server for pair configuration");
            throw HDSException.exceptions.replicationGroupNotAvailable();
        }
        cloneVolume = dbClient.queryObject(Volume.class, cloneVolumeURI);
        hdsProtectionOperations.createSecondaryVolumeForClone(storageSystem, sourceVolumeURI, cloneVolume);
        // Need to fetch clone volume from db to get volume's nativeId
        cloneVolume = dbClient.queryObject(Volume.class, cloneVolumeURI);
        hdsProtectionOperations.addDummyLunPath(hdsApiClient, cloneVolume);
        BlockObject source = BlockObject.fetch(dbClient, sourceVolumeURI);
        String pairName = hdsProtectionOperations.generatePairName(source, cloneVolume);
        log.info("Pair Name :{}", pairName);
        ReplicationInfo replicationInfo = hdsApiProtectionManager.createShadowImagePair(replicationGroupObjectID, pairName, HDSUtils.getSystemArrayType(storageSystem), HDSUtils.getSystemSerialNumber(storageSystem), source.getNativeId(), cloneVolume.getNativeId(), storageSystem.getModel());
        log.info("Replication Info object :{}", replicationInfo.toXMLString());
        log.info("createInactive :{}", createInactive);
        cloneVolume.setSyncActive(false);
        cloneVolume.setReplicaState(ReplicationState.INACTIVE.name());
        dbClient.persistObject(cloneVolume);
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceVolumeURI, cloneVolumeURI);
        log.error(errorMsg, e);
        Volume clone = dbClient.queryObject(Volume.class, cloneVolumeURI);
        if (clone != null) {
            clone.setInactive(true);
            dbClient.persistObject(clone);
        }
        ServiceError serviceError = DeviceControllerErrors.hds.methodFailed("createSingleClone", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) HDSApiProtectionManager(com.emc.storageos.hds.api.HDSApiProtectionManager) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException)

Example 84 with BlockObject

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

the class HDSExportOperations method getVolumeLunMap.

/**
 * @param volumeURIHLUs
 * @return
 * @throws Exception
 */
private Map<String, String> getVolumeLunMap(String systemId, String hsdObjectID, VolumeURIHLU[] volumeURIHLUs, HDSApiExportManager exportMgr) throws Exception {
    List<FreeLun> freeLunList = exportMgr.getFreeLUNInfo(systemId, hsdObjectID);
    log.info("There are {} freeLUN's available for HSD Id {}", freeLunList.size(), hsdObjectID);
    Map<String, String> volumeHLUMap = new HashMap<String, String>();
    int i = 0;
    String lun = null;
    for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
        BlockObject volume = BlockObject.fetch(dbClient, volumeURIHLU.getVolumeURI());
        if (null == volumeURIHLU.getHLU() || "-1".equalsIgnoreCase(volumeURIHLU.getHLU())) {
            if (i < freeLunList.size()) {
                FreeLun freeLun = freeLunList.get(i);
                lun = freeLun.getLun();
                log.info("HLU is unassigned for volume {} and assinging lun {} from array.", volumeURIHLU.getVolumeURI(), lun);
                i++;
            } else {
                // received request to create more volumes than the free luns available on the array.
                log.info("No free LUN's available on HSD {}", hsdObjectID);
                throw HDSException.exceptions.unableToProcessRequestDueToUnavailableFreeLUNs();
            }
        } else {
            log.info("HLU {} is assigned for volume {} and using the free lun from array.", volumeURIHLU.getHLU(), volumeURIHLU.getVolumeURI());
            lun = volumeURIHLU.getHLU();
        }
        volumeHLUMap.put(volume.getNativeId(), lun);
    }
    return volumeHLUMap;
}
Also used : FreeLun(com.emc.storageos.hds.model.FreeLun) HashMap(java.util.HashMap) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) BlockObject(com.emc.storageos.db.client.model.BlockObject) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 85 with BlockObject

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

the class HDSExportOperations method updateVolumeHLUInfo.

/**
 * Updates the HLU information in the exportmask.
 *
 * @param volumeURIHLUs
 * @param pathList
 * @param exportMask
 */
private void updateVolumeHLUInfo(VolumeURIHLU[] volumeURIHLUs, List<Path> pathList, ExportMask exportMask) {
    if (null != exportMask.getVolumes() && !exportMask.getVolumes().isEmpty()) {
        Map<String, URI> deviceIdToURI = new HashMap<String, URI>();
        Map<URI, Integer> hluMap = new HashMap<URI, Integer>();
        for (VolumeURIHLU vuh : volumeURIHLUs) {
            BlockObject volume = BlockObject.fetch(dbClient, vuh.getVolumeURI());
            exportMask.addToUserCreatedVolumes(volume);
            deviceIdToURI.put(volume.getNativeId(), volume.getId());
        }
        if (!deviceIdToURI.isEmpty()) {
            for (Path path : pathList) {
                if (deviceIdToURI.containsKey(path.getDevNum())) {
                    URI volumeURI = deviceIdToURI.get(path.getDevNum());
                    log.info("updating volume {} info in exportmask.", volumeURI);
                    hluMap.put(volumeURI, Integer.parseInt(path.getLun()));
                }
            }
            exportMask.addVolumes(hluMap);
        } else {
            log.error("No HLU's found for the volumes.");
        }
    }
}
Also used : Path(com.emc.storageos.hds.model.Path) HashMap(java.util.HashMap) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Aggregations

BlockObject (com.emc.storageos.db.client.model.BlockObject)341 URI (java.net.URI)222 ArrayList (java.util.ArrayList)152 Volume (com.emc.storageos.db.client.model.Volume)141 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)109 NamedURI (com.emc.storageos.db.client.model.NamedURI)82 HashMap (java.util.HashMap)82 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)69 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)65 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)60 ExportMask (com.emc.storageos.db.client.model.ExportMask)56 HashSet (java.util.HashSet)56 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)45 CIMObjectPath (javax.cim.CIMObjectPath)44 Initiator (com.emc.storageos.db.client.model.Initiator)43 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 List (java.util.List)40 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)38 StringSet (com.emc.storageos.db.client.model.StringSet)36