use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDeviceTest method testFileShareCreateNegative.
/**
* Tests that we rollback file share create in case when file share quota set fails.
*
* @throws Exception
*/
@Test
public void testFileShareCreateNegative() throws Exception {
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel("neTest");
// set negative capacity to force failure of quota creation
fs.setCapacity(-102400L);
FileDeviceInputOutput args = new FileDeviceInputOutput();
args.addStoragePool(_pool);
args.addFSFileObject(fs);
Assert.assertTrue("doCreateFS was expected to fail due to negative quota in the test.", _unity.doCreateFS(_device, args).getCommandStatus().equals(Operation.Status.error.name()));
// verify that doCreate() was rolled back
// check that file share does not exist
// try to get list of shares for directory which we tried to create
VNXeApiClient apiclient = _unity.getVnxUnityClient(_device);
try {
apiclient.getFileSystemByFSName(args.getFileObjMountPath());
Assert.assertTrue("File share create rollback failed, fs path: " + args.getFileObjMountPath(), true);
} catch (VNXeException uex) {
System.out.println("testFileShareCreateNegative --- rollback success: " + uex.getCause());
}
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDeviceTest method testSnapshotDelete.
/**
* Tests snapshot delete with existing SMB shares and NFS exports.
*
* @throws Exception
*/
@Test
public void testSnapshotDelete() throws Exception {
// create FS to use
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel("test");
fs.setCapacity(102400L);
FileDeviceInputOutput args = new FileDeviceInputOutput();
args.addStoragePool(_pool);
args.addFSFileObject(fs);
Assert.assertTrue("doCreateFS failed", _unity.doCreateFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
// create snap
Snapshot snap = new Snapshot();
snap.setId(URIUtil.createId(Snapshot.class));
snap.setLabel("test_snap");
args.addSnapshotFileObject(snap);
Assert.assertTrue("doSnapshotFS failed", _unity.doSnapshotFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
// share snap with SMB
SMBFileShare smbFileShare = new SMBFileShare("TestSMBShare", "Share created by unit test.", "allow", "change", -1);
Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("SMB share doShare() failed, share not added to snap", snap.getSMBFileShares().keySet().contains(smbFileShare.getName()));
Assert.assertTrue("SMB share doShare() failed, number of shares does not match", snap.getSMBFileShares().keySet().size() == 1);
// add additional share
SMBFileShare smbFileShare01 = new SMBFileShare("TestSMBShare01", "Share created by unit test.", "allow", "change", -1);
Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare01).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("SMB share doShare() failed, share not added to snap", snap.getSMBFileShares().keySet().contains(smbFileShare01.getName()));
Assert.assertTrue("SMB share doShare() failed, number of shares does not match", snap.getSMBFileShares().keySet().size() == 2);
// add additional share
SMBFileShare smbFileShare02 = new SMBFileShare("TestSMBShare02", "Share created by unit test.", "allow", "change", -1);
Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare02).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("SMB share doShare() failed, share not added to snap", snap.getSMBFileShares().keySet().contains(smbFileShare02.getName()));
Assert.assertTrue("SMB share doShare() failed, number of shares does not match", snap.getSMBFileShares().keySet().size() == 3);
// export snap
List<String> clients = new ArrayList<String>();
clients.add(client1);
FileExport export1 = new FileExport(clients, "", "sys", "root", "nobody", "nfs");
Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export1)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doExport failed, export not added to snapshot", snap.getFsExports().keySet().size() == 1);
// add client to the same export
clients.add(client2);
FileExport export2 = new FileExport(clients, "", "sys", "root", "nobody", "nfs");
Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export1)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doExport failed, export not added to snapshot", snap.getFsExports().keySet().size() == 1);
// create a new export
clients = new ArrayList<String>();
clients.add(client3);
clients.add(client4);
FileExport export3 = new FileExport(clients, "", "sys", "rw", "nobody", "nfs");
Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export3)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doExport failed, export not added to snapshot", snap.getFsExports().keySet().size() == 2);
// delete snap
Assert.assertTrue("doDeleteSnapshot failed", _unity.doDeleteSnapshot(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
VNXeApiClient apiclient = _unity.getVnxUnityClient(_device);
try {
apiclient.getFileSystemByFSName(args.getFileObjMountPath());
Assert.assertTrue("Snapshot delete failed: " + args.getFileObjMountPath(), false);
} catch (VNXeException uex) {
System.out.println("doDeleteSnapshot --- delete snapshot success: " + uex.getCause());
}
// delete file system
Assert.assertTrue("doDeleteFS failed", _unity.doDeleteFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
try {
apiclient.getFileSystemByFSName(args.getFsMountPath());
Assert.assertTrue("FS delete failed: " + args.getFsMountPath(), false);
} catch (VNXeException uex) {
System.out.println("doDeleteFS --- delete FS success: " + uex.getCause());
}
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDeviceTest method testFileSystemDelete.
/**
* Tests file system delete with existing smb shares and nfs exports.
*
* @throws Exception
*/
@Test
public void testFileSystemDelete() throws Exception {
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel("test");
fs.setCapacity(102400L);
FileDeviceInputOutput args = new FileDeviceInputOutput();
args.addStoragePool(_pool);
args.addFSFileObject(fs);
Assert.assertTrue("doCreateFS failed", _unity.doCreateFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
// share file system with SMB
SMBFileShare smbFileShare = new SMBFileShare("TestSMBShare", "Share created by unit test.", "allow", "change", -1);
Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("SMB share doShare() failed, share not added to FS", fs.getSMBFileShares().keySet().contains(smbFileShare.getName()));
Assert.assertTrue("SMB share doShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 1);
// add additional share
SMBFileShare smbFileShare01 = new SMBFileShare("TestSMBShare01", "Share created by unit test.", "allow", "change", -1);
Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare01).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("SMB share doShare() failed, share not added to FS", fs.getSMBFileShares().keySet().contains(smbFileShare01.getName()));
Assert.assertTrue("SMB share doShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 2);
// add additional share
SMBFileShare smbFileShare02 = new SMBFileShare("TestSMBShare02", "Share created by unit test.", "allow", "change", -1);
Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare02).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("SMB share doShare() failed, share not added to FS", fs.getSMBFileShares().keySet().contains(smbFileShare02.getName()));
Assert.assertTrue("SMB share doShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 3);
// delete one SMB share for FS
Assert.assertTrue("SMB share doDeleteShare() failed", _unity.doDeleteShare(_device, args, smbFileShare).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertFalse("SMB share doDeleteShare() failed, share was not deleted from FS", fs.getSMBFileShares().keySet().contains(smbFileShare.getName()));
Assert.assertTrue("SMB share doDeleteShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 2);
// export
List<String> clients = new ArrayList<String>();
clients.add(client1);
FileExport export1 = new FileExport(clients, "port1", "sys", "root", "nobody", "nfs");
Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export1)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doExport failed, export not added to FS", fs.getFsExports().keySet().size() == 1);
// add client
clients.add(client2);
FileExport export2 = new FileExport(clients, "port1", "sys", "root", "nobody", "nfs");
Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export2)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doExport failed, export not added to FS", fs.getFsExports().keySet().size() == 1);
// create a new export
clients = new ArrayList<String>();
clients.add(client3);
FileExport export3 = new FileExport(clients, "port1", "sys", "rw", "root", "nfs");
Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export3)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doExport failed, export not added to FS", fs.getFsExports().keySet().size() == 2);
// delete
Assert.assertTrue("doDeleteFs failed", _unity.doDeleteFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
VNXeApiClient apiclient = _unity.getVnxUnityClient(_device);
try {
apiclient.getFileSystemByFSName(args.getFsLabel());
Assert.assertTrue("File system delete failed: " + args.getFsLabel(), false);
} catch (VNXeException uex) {
System.out.println("doDeleteFS --- delete FS success: " + uex.getCause());
}
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class FileDeviceController method unexport.
@Override
public void unexport(URI storage, URI fileUri, List<FileShareExport> exports, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fileUri, 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(fileUri, FileShare.class)) {
isFile = true;
fs = _dbClient.queryObject(FileShare.class, fileUri);
setVirtualNASinArgs(fs.getVirtualNAS(), args);
fsObj = fs;
args.addFSFileObject(fs);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
} else {
snapshotObj = _dbClient.queryObject(Snapshot.class, fileUri);
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);
_log.info("Export details... ");
List<FileExport> fileExports = new ArrayList<FileExport>();
List<FileExportRule> exportRules = new ArrayList<FileExportRule>();
if (exports != null) {
for (FileShareExport fileShareExport : exports) {
FileExport fileExport = fileShareExport.getFileExport();
fileExports.add(fileExport);
_log.info("FileExport:" + fileExport.getClients() + ":" + fileExport.getStoragePortName() + ":" + fileExport.getStoragePort() + ":" + fileExport.getRootUserMapping() + ":" + fileExport.getPermissions() + ":" + fileExport.getProtocol() + ":" + fileExport.getSecurityType() + ":" + fileExport.getMountPoint() + ":" + fileExport.getMountPath() + ":" + fileExport.getPath());
_log.info("FileShareExport: " + fileExport.getFileExportKey());
// Per New Model : Lets create the Export Rules, So these will not get missed.
FileExportRule rule = getFileExportRule(fileUri, fileExport, args);
exportRules.add(rule);
}
} else {
_log.info("Exports are null");
}
WorkflowStepCompleter.stepExecuting(opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doUnexport(storageObj, args, fileExports);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
// Set status
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
OperationTypeEnum auditType = (isFile) ? OperationTypeEnum.UNEXPORT_FILE_SYSTEM : OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT;
if (result.isCommandSuccess()) {
// Remove Export
for (FileExport fileExport : fileExports) {
fsObj.getFsExports().remove(fileExport.getFileExportKey());
_log.info("FileShareExport removed : " + fileExport.getFileExportKey());
}
// Query Existing Export rule and if found set to delete.
for (FileExportRule rule : exportRules) {
URIQueryResultList dbresult = new URIQueryResultList();
if (!args.getFileOperation() && rule.getSnapshotExportIndex() != null) {
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotExportRuleConstraint(rule.getSnapshotExportIndex()), dbresult);
} else if (rule.getFsExportIndex() != null) {
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileExportRuleConstraint(rule.getFsExportIndex()), dbresult);
}
Iterator<URI> it = dbresult.iterator();
while (it.hasNext()) {
if (dbresult.iterator().hasNext()) {
rule = _dbClient.queryObject(FileExportRule.class, it.next());
if (rule != null && !rule.getInactive()) {
_log.info("Existing DB Model found {}", rule);
rule.setInactive(true);
_dbClient.updateObject(rule);
break;
}
}
}
}
FSExportMap exportsMap = fsObj.getFsExports();
List<FileExport> fsExports = new ArrayList<FileExport>(exportsMap.values());
if (isFile) {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fsExports), fs, storageObj);
} else {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fsExports), 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(), fileUri.toString(), e.getMessage() };
_log.error("Unable to unexport file system or snapshot: storage {}, FS/snapshot URI {}: {}", params);
for (FileShareExport fsExport : exports) {
_log.error("{} ", fsExport);
}
updateTaskStatus(opId, fsObj, e);
if (URIUtil.isType(fileUri, FileShare.class)) {
if ((fs != null) && (storageObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
}
} else {
if ((fs != null) && (storageObj != null) && (snapshotObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
}
}
}
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class FileDeviceController method restoreFS.
@Override
public void restoreFS(URI storage, URI fs, URI snapshot, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fs, opId);
StorageSystem storageObj = null;
FileShare fsObj = null;
Snapshot snapshotObj = null;
FileDeviceInputOutput args = new FileDeviceInputOutput();
Operation op = null;
try {
String[] params = { storage.toString(), snapshot.toString(), fs.toString() };
_log.info("Restore FS: {} {} {}", params);
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
fsObj = _dbClient.queryObject(FileShare.class, fs);
snapshotObj = _dbClient.queryObject(Snapshot.class, snapshot);
args.addFileShare(fsObj);
args.addSnapshot(snapshotObj);
args.setOpId(opId);
WorkflowStepCompleter.stepExecuting(opId);
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doRestoreFS(storageObj, args);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
op = result.toOperation();
snapshotObj.getOpStatus().updateTaskStatus(opId, op);
fsObj.getOpStatus().updateTaskStatus(opId, op);
_dbClient.updateObject(fsObj);
_dbClient.updateObject(snapshotObj);
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
recordFileDeviceOperation(_dbClient, OperationTypeEnum.RESTORE_FILE_SNAPSHOT, result.isCommandSuccess(), eventMsg, "", fsObj, snapshot);
} catch (Exception e) {
String[] params = { storage.toString(), fs.toString(), snapshot.toString(), e.getMessage() };
_log.error("Unable to restore file system from snapshot: storage {}, FS {}, snapshot {}: {}", params);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
updateTaskStatus(opId, snapshotObj, e);
if ((fsObj != null) && (snapshotObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.RESTORE_FILE_SNAPSHOT, false, e.getMessage(), "", fsObj, snapshotObj);
}
}
if ((op != null) && (!(op.getStatus().equalsIgnoreCase(Operation.Status.error.name())))) {
try {
// Synchronize snapshot list in DB with the list on the device
syncSnapshotList(storageObj, fsObj, args);
} catch (Exception ex) {
String[] params = { storage.toString(), fs.toString(), snapshot.toString() };
_log.warn("Restore succeeded but failed to sync snapshot list in DB with list on the device: storage {}, FS {}, snapshot {}", params);
}
}
}
Aggregations