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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations