use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXeDeleteFileSystemSnapshotJob method updateStatus.
/**
* Called to update the job status when the file system snapshot delete job completes.
*
* @param jobContext The job context.
*/
@Override
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
URI snapId = getTaskCompleter().getId();
Snapshot snapshotObj = dbClient.queryObject(Snapshot.class, snapId);
URI fsUri = snapshotObj.getParent().getURI();
FileShare fsObj = dbClient.queryObject(FileShare.class, fsUri);
StorageSystem storageObj = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
String event = null;
if (_status == JobStatus.SUCCESS && snapshotObj != null) {
snapshotObj.setInactive(true);
dbClient.persistObject(snapshotObj);
event = String.format("Deleted file sytem snapshot %s successfully", snapshotObj.getName());
logMsgBuilder.append("\n");
logMsgBuilder.append(event);
} else if (_status == JobStatus.FAILED && snapshotObj != null) {
event = String.format("Task %s failed to delete file system snapshot: %s", opId, snapshotObj.getName());
logMsgBuilder.append("\n");
logMsgBuilder.append(event);
} else {
event = "File sytem snapshot has been deleted";
logMsgBuilder.append(String.format("Could not find the snapshot: %s", snapId));
}
_logger.info(logMsgBuilder.toString());
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT, _isSuccess, event, "", snapshotObj, fsObj, storageObj);
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXeDeleteFileSystemSnapshotJob", e);
setErrorStatus("Encountered an internal error during file system snapshot delete job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXeDeleteShareJob method updateStatus.
@Override
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
URI fsId = getTaskCompleter().getId();
FileShare fsObj = null;
Snapshot snapObj = null;
String event = null;
if (_status == JobStatus.SUCCESS) {
if (isFile) {
fsObj = dbClient.queryObject(FileShare.class, fsId);
updateFileSystem(vnxeApiClient, dbClient, fsObj);
} else {
snapObj = updateSnapshot(vnxeApiClient, dbClient);
fsObj = dbClient.queryObject(FileShare.class, snapObj.getParent());
}
event = String.format("Deleted file system smbShare successfully for URI: %s", getTaskCompleter().getId());
} else if (_status == JobStatus.FAILED) {
event = String.format("Task %s failed to delete file system sbmShare: %s", opId, smbShare.getName());
logMsgBuilder.append("\n");
logMsgBuilder.append(event);
}
_logger.info(logMsgBuilder.toString());
if (isFile) {
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM_SHARE, _isSuccess, event, smbShare.getName(), fsObj, smbShare);
} else {
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE, _isSuccess, event, smbShare.getName(), snapObj, fsObj, smbShare);
}
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXeCreateFileSystemSnapshotJob", e);
setErrorStatus("Encountered an internal error during file system snapshot create job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXeDeleteShareJob method updateSnapshot.
private Snapshot updateSnapshot(VNXeApiClient apiClient, DbClient dbClient) {
URI snapId = getTaskCompleter().getId();
Snapshot snapObj = dbClient.queryObject(Snapshot.class, snapId);
SMBShareMap shareMap = snapObj.getSMBFileShares();
if (shareMap == null) {
return snapObj;
}
shareMap.remove(smbShare.getName());
deleteShareACLsFromDB(dbClient, snapObj);
dbClient.persistObject(snapObj);
return snapObj;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXeExportFileSystemJob method updateStatus.
/**
* Called to update the job status when the export file system job completes.
*
* @param jobContext The job context.
*/
@Override
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
FileShare fsObj = null;
Snapshot snapObj = null;
URI objId = getTaskCompleter().getId();
StorageSystem storageObj = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
if (_status == JobStatus.SUCCESS) {
_isSuccess = true;
FileExport newExport = exportInfo.getFileExport();
newExport.setMountPoint(ExportUtils.getFileMountPoint(exportInfo.getStoragePort(), exportInfo.getMountPath()));
if (isFile) {
fsObj = dbClient.queryObject(FileShare.class, objId);
updateFSExport(fsObj, dbClient, vnxeApiClient, newExport);
} else {
snapObj = updateSnapExport(dbClient, vnxeApiClient, newExport);
fsObj = dbClient.queryObject(FileShare.class, snapObj.getParent().getURI());
}
} else if (_status == JobStatus.FAILED) {
// cleanupFSExport(fsObj, dbClient);
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to export file system: %s", opId, objId.toString()));
}
_logger.info(logMsgBuilder.toString());
if (isFile) {
fsObj = dbClient.queryObject(FileShare.class, objId);
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.EXPORT_FILE_SYSTEM, _isSuccess, logMsgBuilder.toString(), "", fsObj, storageObj);
} else {
snapObj = dbClient.queryObject(Snapshot.class, objId);
fsObj = dbClient.queryObject(FileShare.class, snapObj.getParent().getURI());
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.EXPORT_FILE_SNAPSHOT, _isSuccess, logMsgBuilder.toString(), "", snapObj, fsObj, storageObj);
}
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXeExportFIleSystemJob", e);
setErrorStatus("Encountered an internal error during file system export job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXeRestoreFileSystemSnapshotJob method syncSnapshots.
private void syncSnapshots(DbClient dbClient, FileShare fsObj, VNXeApiClient vnxeApiClient) {
// Retrieve all snapshots from DB that belong to this file system
URIQueryResultList results = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(fsObj.getId()), results);
// Setup snapshot name-object map
Map<String, Snapshot> snapshotsInDB = new ConcurrentHashMap<String, Snapshot>();
while (results.iterator().hasNext()) {
URI uri = results.iterator().next();
Snapshot snap = dbClient.queryObject(Snapshot.class, uri);
String nativeId = snap.getNativeId();
if (nativeId == null || nativeId.isEmpty()) {
// no nativeId set in the snap, remove it from db.
snap.setInactive(true);
dbClient.persistObject(snap);
_logger.info("No nativeId, removing the snapshot: {}", snap.getId());
continue;
} else {
snapshotsInDB.put(nativeId, snap);
}
}
// Retrieve list of valid snapshot names from the device
List<VNXeFileSystemSnap> snapshots = vnxeApiClient.getFileSystemSnaps(fsObj.getNativeId());
List<String> snapIdsOnDevice = new ArrayList<String>();
for (VNXeFileSystemSnap snap : snapshots) {
snapIdsOnDevice.add(snap.getId());
}
// Iterate through the snapshots in the DB and if name not found in
// the list returned by the device, mark snapshot in DB as inactive
Set<String> snapshotNativeIds = snapshotsInDB.keySet();
for (String snapshotId : snapshotNativeIds) {
if (!snapIdsOnDevice.contains(snapshotId)) {
_logger.info("Removing the snapshot: {}", snapshotId);
snapshotsInDB.get(snapshotId).setInactive(true);
dbClient.persistObject(snapshotsInDB.get(snapshotId));
}
}
// newly discovered snapshot to the DB.
for (VNXeFileSystemSnap snap : snapshots) {
if (!snapshotNativeIds.contains(snap.getId())) {
_logger.info("adding the snapshot: {}", snap.getId());
Snapshot newSnap = new Snapshot();
newSnap.setCreationTime(Calendar.getInstance());
newSnap.setId(URIUtil.createId(Snapshot.class));
newSnap.setParent(new NamedURI(fsObj.getId(), fsObj.getLabel()));
newSnap.setLabel(snap.getName());
newSnap.setOpStatus(new OpStatusMap());
newSnap.setProject(new NamedURI(fsObj.getProject().getURI(), fsObj.getProject().getName()));
newSnap.setNativeId(snap.getId());
try {
newSnap.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(dbClient, newSnap));
} catch (IOException e) {
_logger.info("Exception while setting snap's nativeGUID");
}
}
}
}
Aggregations