Search in sources :

Example 96 with BlockObject

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

the class ExternalBlockStorageDevice method doCreateClone.

@Override
public void doCreateClone(StorageSystem storageSystem, URI volume, URI clone, Boolean createInactive, TaskCompleter taskCompleter) {
    Volume cloneObject = null;
    DriverTask task = null;
    try {
        cloneObject = dbClient.queryObject(Volume.class, clone);
        BlockObject sourceVolume = BlockObject.fetch(dbClient, volume);
        VolumeClone driverClone = new VolumeClone();
        if (sourceVolume instanceof Volume) {
            driverClone.setSourceType(VolumeClone.SourceType.VOLUME);
        } else if (sourceVolume instanceof BlockSnapshot) {
            driverClone.setSourceType(VolumeClone.SourceType.SNAPSHOT);
        } else {
            cloneObject.setInactive(true);
            dbClient.updateObject(cloneObject);
            String errorMsg = String.format("doCreateClone -- Failed to create volume clone: unexpected source type %s .", sourceVolume.getClass().getSimpleName());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
            taskCompleter.error(dbClient, serviceError);
            return;
        }
        // Prepare driver clone
        driverClone.setParentId(sourceVolume.getNativeId());
        driverClone.setStorageSystemId(storageSystem.getNativeId());
        driverClone.setDisplayName(cloneObject.getLabel());
        driverClone.setRequestedCapacity(cloneObject.getCapacity());
        driverClone.setThinlyProvisioned(cloneObject.getThinlyProvisioned());
        // Call driver
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        List<VolumeClone> driverClones = new ArrayList<>();
        driverClones.add(driverClone);
        task = driver.createVolumeClone(Collections.unmodifiableList(driverClones), null);
        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 and call the completer as appropriate based on the result of the request.
            CreateVolumeCloneExternalDeviceJob job = new CreateVolumeCloneExternalDeviceJob(storageSystem.getId(), clone, task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            // Update clone
            String msg = String.format("doCreateClone -- Created volume clone: %s .", task.getMessage());
            _log.info(msg);
            VolumeClone driverCloneResult = driverClones.get(0);
            ExternalDeviceUtils.updateNewlyCreatedClone(cloneObject, driverCloneResult, dbClient);
            taskCompleter.ready(dbClient);
        } else {
            cloneObject.setInactive(true);
            dbClient.updateObject(cloneObject);
            String errorMsg = String.format("doCreateClone -- Failed to create volume clone: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        if (cloneObject != null) {
            cloneObject.setInactive(true);
            dbClient.updateObject(cloneObject);
        }
        _log.error("Failed to create volume clone. ", e);
        ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        try {
            if (task == null || isTaskInTerminalState(task.getStatus())) {
                StoragePool dbPool = dbClient.queryObject(StoragePool.class, cloneObject.getPool());
                updateStoragePoolCapacity(dbPool, storageSystem, Collections.singletonList(clone), dbClient);
            }
        } catch (Exception ex) {
            _log.error("Failed to update storage pool {} after create clone operation completion.", cloneObject.getPool(), ex);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) 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) CreateVolumeCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateVolumeCloneExternalDeviceJob) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 97 with BlockObject

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

the class BlockSnapshotSessionRestoreWorkflowCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    URI snapSessionURI = getId();
    try {
        if (_updateOpStatus) {
            BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
            List<BlockObject> allSources = getAllSources(snapSession, dbClient);
            BlockObject sourceObj = allSources.get(0);
            // Record the results.
            recordBlockSnapshotSessionOperation(dbClient, OperationTypeEnum.RESTORE_SNAPSHOT_SESSION, status, snapSession, sourceObj);
            // Update the status map of the snapshot session.
            switch(status) {
                case error:
                    setErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId(), coded);
                    break;
                case ready:
                    setReadyOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId());
                    break;
                case suspended_error:
                    setSuspendedErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId(), coded);
                    break;
                case suspended_no_error:
                    setSuspendedNoErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId());
                    break;
                default:
                    String errMsg = String.format("Unexpected status %s for completer for task %s", status.name(), getOpId());
                    s_logger.info(errMsg);
                    throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
            }
        }
        s_logger.info("Done restore snapshot session task {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for restore snapshot session task {}", getOpId(), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 98 with BlockObject

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

the class BlockSnapshotSessionUnlinkTargetsWorkflowCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    URI snapSessionURI = getId();
    try {
        BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
        List<BlockObject> allSources = getAllSources(snapSession, dbClient);
        BlockObject sourceObj = allSources.get(0);
        // Record the results.
        recordBlockSnapshotSessionOperation(dbClient, _opType, status, snapSession, sourceObj);
        // Update the status map of the snapshot session.
        switch(status) {
            case error:
                setErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
                break;
            case ready:
                setReadyOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
                break;
            case suspended_error:
                setSuspendedErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
                break;
            case suspended_no_error:
                setSuspendedNoErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
                break;
            default:
                String errMsg = String.format("Unexpected status %s for completer for task %s", status.name(), getOpId());
                s_logger.info(errMsg);
                throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
        }
        s_logger.info("Done unlink targets from snapshot session task {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for unlink targets from snapshot session task {}", getOpId(), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 99 with BlockObject

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

the class ExportMaskAddVolumeCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
        ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
        if (exportMask == null) {
            _log.warn("Export mask was null for task {}", getOpId());
            return;
        }
        if (shouldUpdateDatabase(status)) {
            for (URI volumeURI : _volumes) {
                BlockObject volume = BlockObject.fetch(dbClient, volumeURI);
                _log.info(String.format("Done ExportMaskAddVolume - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
                exportMask.removeFromExistingVolumes(volume);
                exportMask.addToUserCreatedVolumes(volume);
            }
            exportMask.setCreatedBySystem(true);
            ExportMaskUtils.setExportMaskResource(dbClient, exportGroup, exportMask);
            exportMask.addVolumes(_volumeMap);
            if (getExportGroups() != null && !getExportGroups().isEmpty()) {
                List<ExportGroup> egs = dbClient.queryObject(ExportGroup.class, getExportGroups());
                for (ExportGroup eg : egs) {
                    eg.addExportMask(exportMask.getId());
                    ExportUtils.reconcileHLUs(dbClient, eg, exportMask, _volumeMap);
                }
                dbClient.updateObject(egs);
            } else {
                exportGroup.addExportMask(exportMask.getId());
                ExportUtils.reconcileHLUs(dbClient, exportGroup, exportMask, _volumeMap);
                dbClient.updateObject(exportGroup);
            }
            dbClient.updateObject(exportMask);
            updatePortGroupVolumeCount(exportMask.getPortGroup(), dbClient);
            // on rollback if subsequent steps in the workflow fail.
            if (_forgetStepId != null) {
                @SuppressWarnings("unchecked") Set<URI> maskedVolumeURIs = (Set<URI>) WorkflowService.getInstance().loadWorkflowData(_forgetStepId, "forget");
                if (maskedVolumeURIs == null) {
                    maskedVolumeURIs = new HashSet<>();
                    maskedVolumeURIs.addAll(_volumes);
                } else {
                    maskedVolumeURIs.addAll(_volumes);
                }
                WorkflowService.getInstance().storeWorkflowData(_forgetStepId, "forget", maskedVolumeURIs);
            }
        }
    } catch (Exception e) {
        _log.error(String.format("Failed updating status for ExportMaskAddVolume - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Set(java.util.Set) HashSet(java.util.HashSet) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 100 with BlockObject

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

the class ExportMaskCreateCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
        ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
        if (exportMask != null && status == Operation.Status.ready) {
            List<Initiator> initiators = dbClient.queryObject(Initiator.class, _initiatorURIs);
            exportMask.addInitiators(initiators);
            StorageSystem system = dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice());
            exportMask.addToUserCreatedInitiators(initiators);
            exportMask.addVolumes(_volumeMap);
            if (Type.xtremio.toString().equalsIgnoreCase(system.getSystemType())) {
                // XtremIO case, wwn's are updated only during export.
                // Clean up the existing volumes in export Mask which will have dummy wwns after provisioning.
                // The code below this method addToUserCreatedVolumes adds back the volumes with right wwns.
                _log.info("Cleaning existing xtremio volumes with dummy wwns");
                exportMask.getUserAddedVolumes().clear();
            }
            for (URI boURI : _volumeMap.keySet()) {
                BlockObject blockObject = BlockObject.fetch(dbClient, boURI);
                exportMask.addToUserCreatedVolumes(blockObject);
                // CTRL-11544: Set the hlu in the export group too
                if (exportMask.getCreatedBySystem() && exportMask.getVolumes() != null) {
                    String hlu = exportMask.getVolumes().get(boURI.toString());
                    exportGroup.addVolume(boURI, Integer.parseInt(hlu));
                }
            }
            ExportUtils.reconcileHLUs(dbClient, exportGroup, exportMask, _volumeMap);
            dbClient.updateObject(exportMask);
            exportGroup.addExportMask(exportMask.getId());
            dbClient.updateObject(exportGroup);
            updatePortGroupVolumeCount(exportMask.getPortGroup(), dbClient);
        }
        _log.info(String.format("Done ExportMaskCreate - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
    } catch (Exception e) {
        _log.error(String.format("Failed updating status for ExportMaskCreate - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

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