use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileDeviceController method snapshotFS.
@Override
public void snapshotFS(URI storage, URI snapshot, URI fs, String task) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fs, task);
FileShare fsObj = null;
Snapshot snapshotObj = null;
try {
String[] params = { storage.toString(), snapshot.toString(), fs.toString() };
_log.info("Snapshot FS: storage : {}, snapshot : {}, fs : {}", params);
FileDeviceInputOutput args = new FileDeviceInputOutput();
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
fsObj = _dbClient.queryObject(FileShare.class, fs);
snapshotObj = _dbClient.queryObject(Snapshot.class, snapshot);
args.addFileShare(fsObj);
args.addSnapshot(snapshotObj);
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, fsObj.getPool());
args.addStoragePool(storagePool);
args.setOpId(task);
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, task);
WorkflowStepCompleter.stepExecuting(task);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doSnapshotFS(storageObj, args);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(task, result.getServiceCoded());
}
snapshotObj.setCreationTime(Calendar.getInstance());
fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
snapshotObj.getOpStatus().updateTaskStatus(task, result.toOperation());
snapshotObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, snapshotObj));
// Incase error, set the snapshot to inactive state.
if (!result.isCommandSuccess()) {
_log.error("Snapshot create command is not successfull, so making object to inactive");
snapshotObj.setInactive(true);
}
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(task);
}
_dbClient.updateObject(snapshotObj);
_dbClient.updateObject(fsObj);
fsObj = _dbClient.queryObject(FileShare.class, fs);
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_SNAPSHOT, result.isCommandSuccess(), eventMsg, "", snapshotObj, fsObj);
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(task, serviceError);
String[] params = { storage.toString(), fs.toString(), snapshot.toString(), e.getMessage() };
_log.error("Unable to create file system snapshot: storage {}, FS {}, snapshot {}: {}", params);
updateTaskStatus(task, fsObj, e);
updateTaskStatus(task, snapshotObj, e);
if ((fsObj != null) && (snapshotObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fsObj);
}
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileDeviceController method snapshotsExistsOnFS.
private boolean snapshotsExistsOnFS(FileShare fs) {
URIQueryResultList snapIDList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(fs.getId()), snapIDList);
_log.info("getSnapshots: FS {}: {} ", fs.getId().toString(), snapIDList.toString());
List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapIDList);
if (snapList != null) {
_log.info(" No of Snapshots on FS {} ", snapList.size());
for (Snapshot snapshot : snapList) {
if (!snapshot.getInactive()) {
return true;
}
}
}
return false;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileDeviceController method updateShareACLs.
@Override
public void updateShareACLs(URI storage, URI fsURI, String shareName, CifsShareACLUpdateParams param, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fsURI, opId);
FileObject fsObj = null;
FileDeviceInputOutput args = new FileDeviceInputOutput();
FileShare fs = null;
Snapshot snapshotObj = null;
boolean isFile = false;
_log.info("Controller recieved request to update ACL of share {}: cifsShareACLUpdateParams {}", shareName, param);
try {
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
args.setAllShareAcls(param);
args.setShareName(shareName);
// File
if (URIUtil.isType(fsURI, FileShare.class)) {
isFile = true;
fs = _dbClient.queryObject(FileShare.class, fsURI);
setVirtualNASinArgs(fs.getVirtualNAS(), args);
fsObj = fs;
args.addFSFileObject(fs);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
} else {
// Snapshot
snapshotObj = _dbClient.queryObject(Snapshot.class, fsURI);
fsObj = snapshotObj;
fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
setVirtualNASinArgs(fs.getVirtualNAS(), args);
args.addFileShare(fs);
args.addSnapshotFileObject(snapshotObj);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
}
args.setFileOperation(isFile);
args.setOpId(opId);
// Query for existing ACLs
args.setExistingShareAcls(queryExistingShareAcls(args));
// Do the Operation on device.
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, opId);
WorkflowStepCompleter.stepExecuting(opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).updateShareACLs(storageObj, args);
if (result.isCommandSuccess()) {
// Update database
updateShareACLsInDB(param, fs, args);
WorkflowStepCompleter.stepSucceded(opId);
}
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
// Audit & Update the task status
OperationTypeEnum auditType = null;
auditType = (isFile) ? OperationTypeEnum.UPDATE_FILE_SYSTEM_SHARE_ACL : OperationTypeEnum.UPDATE_FILE_SNAPSHOT_SHARE_ACL;
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
// Monitoring - Event Processing
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
if (isFile) {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getNewACLExtensions(param.retrieveAllACLs()), fs, storageObj);
} else {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getNewACLExtensions(param.retrieveAllACLs()), snapshotObj, fs, storageObj);
}
_dbClient.updateObject(fsObj);
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
String[] logParams = { storage.toString(), fsURI.toString() };
_log.error("Unable to update share ACL for file system or snapshot: storage {}, FS/snapshot URI {}", logParams, e);
_log.error("{}, {} ", e.getMessage(), e);
updateTaskStatus(opId, fsObj, e);
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileDeviceController method recordFileDeviceOperation.
public static void recordFileDeviceOperation(DbClient dbClient, OperationTypeEnum opType, boolean opStatus, String evDesc, String extensions, Object... extParam) {
String evType;
if (evDesc == null || evDesc.isEmpty()) {
evDesc = opType.getDescription();
}
evType = opType.getEvType(opStatus);
String opStage = AuditLogManager.AUDITOP_END;
_log.info("opType: {} detail: {}", opType.toString(), evType + ':' + evDesc);
FileShare fs = null;
Snapshot snapshotObj = null;
QuotaDirectory quotaDirObj = null;
if (extParam[0] instanceof Snapshot) {
snapshotObj = (Snapshot) extParam[0];
fs = (FileShare) extParam[1];
recordSnapshotEvent(dbClient, snapshotObj, fs, evType, evDesc, extensions);
} else if (extParam[0] instanceof QuotaDirectory) {
quotaDirObj = (QuotaDirectory) extParam[0];
fs = (FileShare) extParam[1];
recordQuotaDirectoryEvent(dbClient, quotaDirObj, fs, evType, evDesc, extensions);
} else if (extParam[0] instanceof FileShare) {
fs = (FileShare) extParam[0];
recordFsEvent(dbClient, fs, evType, evDesc, extensions);
} else {
_log.error("unrecognized param list");
}
FileSMBShare smbShare = null;
switch(opType) {
case CREATE_FILE_SYSTEM:
auditFile(dbClient, opType, opStatus, opStage, fs.getLabel(), fs.getVirtualArray().toString(), (fs.getProject() != null) ? fs.getProject().toString() : null);
break;
case DELETE_FILE_SYSTEM:
auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((StorageSystem) extParam[1]).getId().toString());
break;
case DELETE_FILE_SNAPSHOT:
auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getId().toString(), ((StorageSystem) extParam[2]).getId().toString());
break;
case EXPORT_FILE_SYSTEM:
case UPDATE_EXPORT_RULES_FILE_SYSTEM:
case UPDATE_FILE_SYSTEM_SHARE_ACL:
case UNEXPORT_FILE_SYSTEM:
auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((StorageSystem) extParam[1]).getId().toString(), extensions);
break;
case EXPAND_FILE_SYSTEM:
case REDUCE_FILE_SYSTEM:
auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), extParam[1]);
break;
case CREATE_FILE_SYSTEM_SHARE:
case DELETE_FILE_SYSTEM_SHARE:
smbShare = (FileSMBShare) extParam[1];
auditFile(dbClient, opType, opStatus, opStage, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), fs.getId().toString());
break;
case RESTORE_FILE_SNAPSHOT:
URI snapshot = (URI) extParam[1];
auditFile(dbClient, opType, opStatus, opStage, snapshot, fs.getId().toString());
break;
case CREATE_FILE_SYSTEM_SNAPSHOT:
auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getLabel(), snapshotObj.getId(), fs.getId().toString());
break;
case EXPORT_FILE_SNAPSHOT:
case UPDATE_EXPORT_RULES_FILE_SNAPSHOT:
case UPDATE_FILE_SNAPSHOT_SHARE_ACL:
case UNEXPORT_FILE_SNAPSHOT:
auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getId().toString(), ((StorageSystem) extParam[2]).getId().toString(), extensions);
break;
case CREATE_FILE_SNAPSHOT_SHARE:
case DELETE_FILE_SNAPSHOT_SHARE:
smbShare = (FileSMBShare) extParam[2];
auditFile(dbClient, opType, opStatus, opStage, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), snapshotObj.getId().toString());
break;
case CREATE_FILE_SYSTEM_QUOTA_DIR:
case DELETE_FILE_SYSTEM_QUOTA_DIR:
case UPDATE_FILE_SYSTEM_QUOTA_DIR:
auditFile(dbClient, opType, opStatus, opStage, quotaDirObj.getLabel(), quotaDirObj.getId(), fs.getId().toString());
break;
case DELETE_FILE_SYSTEM_SHARE_ACL:
auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((StorageSystem) extParam[1]).getId().toString(), extensions);
break;
case DELETE_FILE_SNAPSHOT_SHARE_ACL:
auditFile(dbClient, opType, opStatus, opStage, snapshotObj.getId().toString(), ((StorageSystem) extParam[2]).getId().toString(), extensions);
break;
case ASSIGN_FILE_SYSTEM_SNAPSHOT_SCHEDULE:
case UNASSIGN_FILE_SYSTEM_SNAPSHOT_SCHEDULE:
auditFile(dbClient, opType, opStatus, opStage, fs.getId().toString(), ((SchedulePolicy) extParam[1]).getId().toString(), extensions);
break;
default:
_log.error("unrecognized fileshare operation type");
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileDeviceController method export.
@Override
public void export(URI storage, URI uri, List<FileShareExport> exports, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(uri, opId);
FileObject fsObj = null;
FileShare fs = null;
Snapshot snapshotObj = null;
StorageSystem storageObj = null;
try {
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
FileDeviceInputOutput args = new FileDeviceInputOutput();
boolean isFile = false;
if (URIUtil.isType(uri, FileShare.class)) {
isFile = true;
fs = _dbClient.queryObject(FileShare.class, uri);
fsObj = fs;
args.addFSFileObject(fs);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
setVirtualNASinArgs(fs.getVirtualNAS(), args);
} else {
snapshotObj = _dbClient.queryObject(Snapshot.class, uri);
fsObj = snapshotObj;
fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
args.addFileShare(fs);
args.addSnapshotFileObject(snapshotObj);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
setVirtualNASinArgs(fs.getVirtualNAS(), args);
}
args.setFileOperation(isFile);
args.setOpId(opId);
_log.info("Export details... ");
List<FileExport> fileExports = new ArrayList<FileExport>();
if (exports != null) {
for (FileShareExport fileShareExport : exports) {
args.setBypassDnsCheck(fileShareExport.getBypassDnsCheck());
FileExport fExport = fileShareExport.getFileExport();
fExport.setMountPoint(fileShareExport.getMountPath());
_log.info("FileExport:clients:" + fExport.getClients() + ":portName:" + fExport.getStoragePortName() + ":port:" + fExport.getStoragePort() + ":rootMapping:" + fExport.getRootUserMapping() + ":permissions:" + fExport.getPermissions() + ":protocol:" + fExport.getProtocol() + ":security:" + fExport.getSecurityType() + ":mountpoint:" + fExport.getMountPoint() + ":path:" + fExport.getPath() + ":comments:" + fExport.getComments() + ":subDirectory:" + fExport.getSubDirectory());
fileExports.add(fExport);
}
} else {
_log.info("Exports are null");
}
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, opId);
WorkflowStepCompleter.stepExecuting(opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doExport(storageObj, args, fileExports);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
// Set Mount path info for the exports
FSExportMap fsExports = fsObj.getFsExports();
// Per New model get the rules and see if any rules that are already saved and available.
List<FileExportRule> existingRules = queryFileExports(args);
if (null != fsExports) {
Iterator it = fsExports.keySet().iterator();
while (it.hasNext()) {
String fsExpKey = (String) it.next();
FileExport fileExport = fsObj.getFsExports().get(fsExpKey);
if ((fileExport.getMountPath() != null) && (fileExport.getMountPath().length() > 0)) {
fileExport.setMountPoint(ExportUtils.getFileMountPoint(fileExport.getStoragePort(), fileExport.getMountPath()));
} else {
fileExport.setMountPoint(ExportUtils.getFileMountPoint(fileExport.getStoragePort(), fileExport.getPath()));
}
_log.info("FileExport mountpath set to {} {}", fsExpKey, fileExport.getMountPoint());
// Per New Model of Export Rules Lets create the rule and save it as FileExportRule.
if (result.isCommandSuccess()) {
FileExportRule newRule = getFileExportRule(fsObj.getId(), fileExport, args);
_log.debug("ExportRule Constucted per expotkey {}, {}", fsExpKey, newRule);
if (existingRules != null && existingRules.isEmpty()) {
newRule.setId(URIUtil.createId(FileExportRule.class));
_log.info("No Existing rules available for this FS Export and so creating the rule now {}", newRule);
_dbClient.createObject(newRule);
} else {
_log.debug("Checking for existing rule(s) available for this export...");
boolean isRuleFound = false;
for (FileExportRule rule : existingRules) {
_log.debug("Available Export Rule {} - Matching with New Rule {}", rule, newRule);
if (newRule.getFsExportIndex() != null && rule.getFsExportIndex().equals(newRule.getFsExportIndex())) {
isRuleFound = true;
_log.info("Match Found : Skipping this rule as already available {}", newRule);
break;
}
}
if (!isRuleFound) {
_log.info("Creating new Export Rule {}", newRule);
newRule.setId(URIUtil.createId(FileExportRule.class));
_dbClient.createObject(newRule);
isRuleFound = false;
}
}
}
}
}
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
OperationTypeEnum auditType = null;
auditType = (isFile) ? OperationTypeEnum.EXPORT_FILE_SYSTEM : OperationTypeEnum.EXPORT_FILE_SNAPSHOT;
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
if (isFile) {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fileExports), fs, storageObj);
} else {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fileExports), snapshotObj, fs, storageObj);
}
_dbClient.updateObject(fsObj);
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
String[] params = { storage.toString(), uri.toString(), e.getMessage() };
_log.error("Unable to export file system or snapshot: storage {}, FS/snapshot URI {}: {}", params);
for (FileShareExport fsExport : exports) {
_log.error("{}", fsExport);
}
updateTaskStatus(opId, fsObj, e);
if (URIUtil.isType(uri, FileShare.class)) {
if ((fs != null) && (storageObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.EXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
}
} else {
if ((fs != null) && (storageObj != null) && (snapshotObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.EXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
}
}
}
}
Aggregations