Search in sources :

Example 41 with VNXeCommandJob

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

the class VNXeApiClient method createNfsShareForSnap.

/**
 * Create Nfs share for snapshot
 *
 * @param snapId
 *            snapshot id
 * @param endpoints
 *            hosts
 * @param access
 *            READ, WRITE, ROOT
 * @param path
 * @param exportKey
 * @return VNXeCommandJob
 * @throws VNXeException
 */
public VNXeCommandJob createNfsShareForSnap(String snapId, List<String> roEndpoints, List<String> rwEndpoints, List<String> rootEndpoints, AccessEnum access, String path, String shareName, String comments) throws VNXeException {
    _logger.info("creating nfs share for the snap: " + snapId);
    NfsShareRequests request = new NfsShareRequests(_khClient);
    String softwareVersion = getBasicSystemInfo().getSoftwareVersion();
    FileSystemSnapRequests req = new FileSystemSnapRequests(_khClient, softwareVersion);
    VNXeFileSystemSnap snapshot = req.getFileSystemSnap(snapId, softwareVersion);
    if (snapshot == null) {
        _logger.info("Could not find snapshot in the vxne");
        throw VNXeException.exceptions.vnxeCommandFailed("Could not find snapshot in the vnxe for: " + snapId);
    }
    NfsShareCreateForSnapParam nfsCreateParam = new NfsShareCreateForSnapParam();
    VNXeBase snap = new VNXeBase(snapId);
    if (!VNXeUtils.isHigherVersion(softwareVersion, VNXeConstants.VNXE_BASE_SOFT_VER)) {
        nfsCreateParam.setFilesystemSnap(snap);
    } else {
        nfsCreateParam.setSnap(snap);
    }
    List<VNXeBase> roHosts = getHosts(roEndpoints);
    List<VNXeBase> rwHosts = getHosts(rwEndpoints);
    List<VNXeBase> rootHosts = getHosts(rootEndpoints);
    VNXeCommandJob job = null;
    VNXeNfsShare nfsShareFound = request.findSnapNfsShare(snapId, shareName, softwareVersion);
    if (nfsShareFound == null) {
        // new export
        nfsCreateParam.setReadOnlyHosts(roHosts);
        nfsCreateParam.setReadWriteHosts(rwHosts);
        nfsCreateParam.setRootAccessHosts(rootHosts);
        nfsCreateParam.setName(shareName);
        nfsCreateParam.setPath(path);
        if (comments != null) {
            nfsCreateParam.setDescription(comments);
        }
        request.unsetQueryParameters();
        job = request.createShareForSnapshot(nfsCreateParam);
    } else {
        String nfsShareId = nfsShareFound.getId();
        NFSShareDefaultAccessEnum nfsShareDefaultAccess = nfsShareFound.getDefaultAccess();
        NfsShareModifyForShareParam nfsModifyParam = new NfsShareModifyForShareParam();
        List<VNXeBase> hosts = new ArrayList<VNXeBase>();
        nfsModifyParam.setReadOnlyHosts(roHosts);
        nfsModifyParam.setReadWriteHosts(rwHosts);
        nfsModifyParam.setRootAccessHosts(rootHosts);
        if (comments != null) {
            nfsModifyParam.setDescription(comments);
        }
        if (access == null) {
            if (nfsShareFound != null) {
                hosts.addAll(nfsShareFound.getNoAccessHosts());
                hosts.addAll(nfsShareFound.getRootAccessHosts());
                hosts.addAll(nfsShareFound.getReadWriteHosts());
                hosts.addAll(nfsShareFound.getReadOnlyHosts());
            }
            if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.ROOT)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setRootAccessHosts(hosts);
                } else {
                    nfsModifyParam.setRootAccessHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READONLY)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setReadOnlyHosts(hosts);
                } else {
                    nfsModifyParam.setReadOnlyHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READWRITE)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setReadWriteHosts(hosts);
                } else {
                    nfsModifyParam.setReadWriteHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.NONE)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setNoAccessHosts(hosts);
                } else {
                    nfsModifyParam.setNoAccessHosts(null);
                }
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            }
        }
        request.unsetQueryParameters();
        job = request.modifyShareForSnapshot(nfsShareId, nfsModifyParam);
    }
    return job;
}
Also used : VNXeFileSystemSnap(com.emc.storageos.vnxe.models.VNXeFileSystemSnap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileSystemSnapRequests(com.emc.storageos.vnxe.requests.FileSystemSnapRequests) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) NfsShareRequests(com.emc.storageos.vnxe.requests.NfsShareRequests) NFSShareDefaultAccessEnum(com.emc.storageos.vnxe.models.NfsShareParam.NFSShareDefaultAccessEnum) NfsShareModifyForShareParam(com.emc.storageos.vnxe.models.NfsShareModifyForShareParam) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) ArrayList(java.util.ArrayList) NfsShareCreateForSnapParam(com.emc.storageos.vnxe.models.NfsShareCreateForSnapParam)

Example 42 with VNXeCommandJob

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

the class VNXUnityCreateCGSnapshotJob 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();
            String snapGroupId = output.getId();
            List<Snap> snaps = vnxeApiClient.getSnapshotsBySnapGroup(snapGroupId);
            // 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 (Snap snap : snaps) {
                String lunId = snap.getLun().getId();
                BlockSnapshot snapshot = volumeToSnapMap.get(lunId);
                snapshot.setNativeId(snap.getId());
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                snapshot.setDeviceLabel(snap.getName());
                snapshot.setReplicationGroupInstance(snapGroupId);
                snapshot.setIsSyncActive(true);
                snapshot.setInactive(false);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(snap.getAttachedWWN());
                snapshot.setAllocatedCapacity(snap.getSize());
                snapshot.setProvisionedCapacity(snap.getSize());
                if (readOnly) {
                    snapshot.setIsReadOnly(readOnly);
                }
                _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s (%3$s). Associated lun is %4$s", snapshot.getId().toString(), snap.getId(), snapshot.getLabel(), lunId));
                dbClient.updateObject(snapshot);
            }
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            dbClient.updateObject(snapshots);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXUntiyCreateCGSnapshotJob", e);
        setErrorStatus("Encountered an internal error during group 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) 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) Snap(com.emc.storageos.vnxe.models.Snap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 43 with VNXeCommandJob

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

the class VNXeSnapshotOperation method restoreGroupSnapshots.

@Override
public void restoreGroupSnapshots(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        VNXeLunGroupSnap lunGroupSnap = apiClient.getLunGroupSnapshot(snapshotObj.getReplicationGroupInstance());
        // Error out if the snapshot is attached
        if (lunGroupSnap.getIsAttached()) {
            _log.error("Snapshot {})is attached and cannot be used for restore", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshot.toString());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreLunGroupSnap(lunGroupSnap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (VNXeException e) {
        _log.error("Restore group snapshot got the exception", e);
        taskCompleter.error(_dbClient, e);
    } catch (Exception ex) {
        _log.error("Restore group snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeBlockRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockRestoreSnapshotJob) VNXeException(com.emc.storageos.vnxe.VNXeException) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 44 with VNXeCommandJob

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

the class VNXeSnapshotOperation method deleteSingleVolumeSnapshot.

@Override
public void deleteSingleVolumeSnapshot(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        VNXeLunSnap lunSnap = apiClient.getLunSnapshot(snap.getNativeId());
        if (lunSnap != null) {
            VNXeCommandJob job = apiClient.deleteLunSnap(lunSnap.getId());
            if (job != null) {
                ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockDeleteSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
            }
        } else {
            // Perhaps, it's already been deleted or was deleted on the array.
            // In that case, we'll just say all is well, so that this operation
            // is idempotent.
            snap.setInactive(true);
            snap.setIsSyncActive(false);
            _dbClient.updateObject(snap);
            taskCompleter.ready(_dbClient);
        }
    } catch (VNXeException e) {
        _log.error("Delete volume snapshot got the exception", e);
        taskCompleter.error(_dbClient, e);
    } catch (Exception ex) {
        _log.error("Delete volume snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteSnapshot", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeBlockDeleteSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockDeleteSnapshotJob) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 45 with VNXeCommandJob

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

the class VNXeSnapshotOperation method restoreSingleVolumeSnapshot.

@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        VNXeLunSnap lunSnap = apiClient.getLunSnapshot(snapshotObj.getNativeId());
        // Error out if the snapshot is attached
        if (lunSnap.getIsAttached()) {
            _log.error("Snapshot {})is attached and cannot be used for restore", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshot.toString());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreLunSnap(lunSnap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (VNXeException e) {
        _log.error("Restore snapshot got the exception", e);
        taskCompleter.error(_dbClient, e);
    } catch (Exception ex) {
        _log.error("Restore snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeBlockRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockRestoreSnapshotJob) VNXeException(com.emc.storageos.vnxe.VNXeException) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)73 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)48 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)41 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)40 VNXeException (com.emc.storageos.vnxe.VNXeException)40 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)40 ControllerException (com.emc.storageos.volumecontroller.ControllerException)30 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)24 Snapshot (com.emc.storageos.db.client.model.Snapshot)18 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)18 ArrayList (java.util.ArrayList)18 FileShare (com.emc.storageos.db.client.model.FileShare)17 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)16 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)16 Volume (com.emc.storageos.db.client.model.Volume)13 URI (java.net.URI)10 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)9 FileExport (com.emc.storageos.db.client.model.FileExport)8 FileShareExport (com.emc.storageos.volumecontroller.FileShareExport)8 DbClient (com.emc.storageos.db.client.DbClient)7