use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class FileDeviceController method updateQuotaDirectory.
@Override
public void updateQuotaDirectory(URI storage, FileShareQuotaDirectory quotaDir, URI fs, String task) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fs, task);
FileShare fsObj = null;
StorageSystem storageObj = null;
QuotaDirectory quotaDirObj = null;
FileDeviceInputOutput args = new FileDeviceInputOutput();
try {
String[] params = { storage.toString(), fs.toString(), quotaDir.toString() };
_log.info("FileDeviceController::updateQtree: storage : {}, fs : {}, quotaDir : {}", params);
fsObj = _dbClient.queryObject(FileShare.class, fs);
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
if (null != quotaDir.getSize()) {
quotaDirObj.setSize(quotaDir.getSize());
}
quotaDirObj.setSoftLimit(quotaDir.getSoftLimit());
quotaDirObj.setSoftGrace(quotaDir.getSoftGrace());
quotaDirObj.setNotificationLimit(quotaDir.getNotificationLimit());
if (null != quotaDir.getOpLock()) {
quotaDirObj.setOpLock(quotaDir.getOpLock());
}
if (null != quotaDir.getSecurityStyle()) {
quotaDirObj.setSecurityStyle(quotaDir.getSecurityStyle());
}
// Set up args
args.addFileShare(fsObj);
args.addQuotaDirectory(quotaDirObj);
args.setOpId(task);
FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
BiosCommandResult result = nasDevice.doUpdateQuotaDirectory(storageObj, args, quotaDirObj);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
_log.error("FileDeviceController::updateQtree: QuotaDirectory update command is not successful");
// The quota object was already modified with changes.
// if it fail to update the quota directory,
// restore the object with the original quota directory!!!
quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
}
quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsObj.getName()));
fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
// save the task status into db
_dbClient.updateObject(quotaDirObj);
_dbClient.updateObject(fsObj);
fsObj = _dbClient.queryObject(FileShare.class, fs);
_log.debug("FileDeviceController::updateQtree: After QuotaDirectory updated and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR, result.isCommandSuccess(), eventMsg, "", quotaDirObj, fsObj);
} catch (Exception e) {
String[] params = { storage.toString(), fs.toString(), quotaDir.toString(), e.getMessage() };
_log.error("FileDeviceController::updateQtree: Unable to update file system quotaDir: storage {}, FS {}, snapshot {}: {}", params);
updateTaskStatus(task, fsObj, e);
updateTaskStatus(task, quotaDirObj, e);
if ((fsObj != null) && (quotaDirObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, false, e.getMessage(), "", quotaDirObj, fsObj);
}
}
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class FileDeviceController method delete.
@Override
public void delete(URI storage, URI pool, URI uri, boolean forceDelete, String deleteType, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(uri, opId);
StorageSystem storageObj = null;
FileObject fileObject = null;
FileShare fsObj = null;
Snapshot snapshotObj = null;
try {
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
String[] params = { storage.toString(), uri.toString(), String.valueOf(forceDelete), deleteType };
_log.info("Delete : storage : {}, URI : {}, forceDelete : {}, delete_type : {} ", params);
FileDeviceInputOutput args = new FileDeviceInputOutput();
boolean isFile = false;
args.setOpId(opId);
if (URIUtil.isType(uri, FileShare.class)) {
isFile = true;
args.setForceDelete(forceDelete);
fsObj = _dbClient.queryObject(FileShare.class, uri);
setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
fileObject = fsObj;
args.addFileShare(fsObj);
args.setFileOperation(isFile);
BiosCommandResult result;
WorkflowStepCompleter.stepExecuting(opId);
if (FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType) && !fsObj.getInactive()) {
result = BiosCommandResult.createSuccessfulResult();
} else {
if (!fsObj.getInactive()) {
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, opId);
result = getDevice(storageObj.getSystemType()).doDeleteFS(storageObj, args);
} else {
result = BiosCommandResult.createSuccessfulResult();
}
}
// In case of VNXe
if (result.getCommandPending()) {
return;
}
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
if (result.isCommandSuccess() && (FileControllerConstants.DeleteTypeEnum.FULL.toString().equalsIgnoreCase(deleteType))) {
fsObj.setInactive(true);
if (forceDelete) {
// Delete Snapshot and its references from DB
doDeleteSnapshotsFromDB(fsObj, true, null, args);
args.addQuotaDirectory(null);
// Delete Quota Directory from DB
doFSDeleteQuotaDirsFromDB(args);
// Delete CIFS Share ACLs from DB
deleteShareACLsFromDB(args);
// Delete Export Rules from DB
doDeleteExportRulesFromDB(true, null, args);
// Remove FileShare Reference from File Policy
doDeletePolicyReferenceFromDB(fsObj);
}
WorkflowStepCompleter.stepSucceded(opId);
} else if (!result.getCommandPending() && FileControllerConstants.DeleteTypeEnum.FULL.toString().equalsIgnoreCase(deleteType)) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess() && (FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType))) {
boolean snapshotsExist = snapshotsExistsOnFS(fsObj);
boolean quotaDirsExist = quotaDirectoriesExistsOnFS(fsObj);
boolean policyExists = fileProtectionPoliciesExistsOnFS(fsObj);
boolean fsCheck = getDevice(storageObj.getSystemType()).doCheckFSExists(storageObj, args);
if (fsCheck) {
String errMsg = null;
if (snapshotsExist) {
errMsg = new String("delete file system from ViPR database failed because snapshots exist for file system " + fsObj.getLabel() + " and once deleted the snapshot cannot be ingested into ViPR");
} else if (quotaDirsExist && !quotaDirectoryIngestionSupported(storageObj.getSystemType())) {
errMsg = new String("delete file system from ViPR database failed because quota directories exist for file system " + fsObj.getLabel() + " and once deleted the quota directory cannot be ingested into ViPR");
} else if (policyExists) {
errMsg = new String("delete file system from ViPR database failed because file protection policies exist for file system " + fsObj.getLabel() + " and once deleted the policy cannot be ingested into ViPR");
}
if (errMsg != null) {
_log.error(errMsg);
final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.DELETE_FILE_SYSTEM.toString(), errMsg);
result = BiosCommandResult.createErrorResult(serviceCoded);
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj, storageObj);
_dbClient.updateObject(fsObj);
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
return;
}
}
// Delete Snapshot and its references from DB
doDeleteSnapshotsFromDB(fsObj, true, null, args);
args.addQuotaDirectory(null);
doFSDeleteQuotaDirsFromDB(args);
deleteShareACLsFromDB(args);
doDeleteExportRulesFromDB(true, null, args);
// Remove FileShare Reference from File Policy
doDeletePolicyReferenceFromDB(fsObj);
SMBShareMap cifsSharesMap = fsObj.getSMBFileShares();
if (cifsSharesMap != null && !cifsSharesMap.isEmpty()) {
cifsSharesMap.clear();
}
fsObj.setInactive(true);
WorkflowStepCompleter.stepSucceded(opId);
} else if (!result.getCommandPending() && FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType)) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
_dbClient.updateObject(fsObj);
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj, storageObj);
} else {
snapshotObj = _dbClient.queryObject(Snapshot.class, uri);
fileObject = snapshotObj;
args.addSnapshot(snapshotObj);
fsObj = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
args.addFileShare(fsObj);
args.setFileOperation(isFile);
WorkflowStepCompleter.stepExecuting(opId);
// Acquire lock for VNXFILE Storage System
acquireStepLock(storageObj, opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doDeleteSnapshot(storageObj, args);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
snapshotObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
snapshotObj.setInactive(true);
// delete the corresponding export rules if available.
args.addSnapshot(snapshotObj);
doDeleteExportRulesFromDB(true, null, args);
}
_dbClient.updateObject(snapshotObj);
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT, result.isCommandSuccess(), "", "", snapshotObj, fsObj, storageObj);
}
} catch (Exception e) {
String[] params = { storage.toString(), uri.toString(), String.valueOf(forceDelete), e.getMessage() };
_log.error("Unable to delete file system or snapshot: storage {}, FS/snapshot {}, forceDelete {}: {}", params);
updateTaskStatus(opId, fileObject, e);
// work flow fail for fileshare delete
if (URIUtil.isType(uri, FileShare.class)) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
if (URIUtil.isType(uri, FileShare.class)) {
if ((fsObj != null) && (storageObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, false, e.getMessage(), "", fsObj, storageObj);
}
} else {
if ((fsObj != null) && (storageObj != null) && (snapshotObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fsObj, storageObj);
}
}
}
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method checkNewPolicyPathHasData.
/**
* Method to check if the path of the 'to be created' file policy on the target array contains data
*
* @param vpool
* @param project
* @param fs - Target Filesystem
* @param virtualNAS
* @param isi - Isilon Api Object
*/
private void checkNewPolicyPathHasData(VirtualPool vpool, Project project, FileShare fs, VirtualNAS virtualNAS, IsilonApi isi) {
if (fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.TARGET.name())) {
FileShare sourceFs = _dbClient.queryObject(FileShare.class, fs.getParentFileShare().getURI());
List<FilePolicy> replicationPolicies = FileOrchestrationUtils.getReplicationPolices(_dbClient, vpool, project, sourceFs);
if (replicationPolicies != null && !replicationPolicies.isEmpty()) {
if (replicationPolicies.size() > 1) {
_log.warn("More than one replication policy found {}", replicationPolicies.size());
throw DeviceControllerException.exceptions.failToCreateFileSystem(String.format("More than one replication policy found: %s for Fileshare %s", replicationPolicies.size(), sourceFs.getId()));
}
FilePolicy fileRepPolicy = replicationPolicies.get(0);
String policyPath = null;
FileDeviceInputOutput args = new FileDeviceInputOutput();
args.setVPool(vpool);
args.setProject(project);
args.setvNAS(virtualNAS);
policyPath = generatePathForPolicy(fileRepPolicy, fs, args);
// Add the suffix only for local replication policy at higher level
if (fileRepPolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.LOCAL.name()) && !FilePolicyApplyLevel.file_system.name().equalsIgnoreCase(fileRepPolicy.getApplyAt())) {
policyPath = policyPath + "_localTarget";
}
// Policy path on target array will be checked at all levels
_log.info("Check if Policy path has data on Target array: " + policyPath);
if (StringUtils.isNotEmpty(policyPath) && isi.existsDir(policyPath) && isi.fsDirHasData(policyPath)) {
_log.error("File system creation failed due to directory path {} already exists and contains data", policyPath);
throw DeviceControllerException.exceptions.failToCreateFileSystem(policyPath);
} else {
_log.info("Policy path doesn't exist on target array. Proceeding with policy creation");
}
}
}
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class BiosCommandResultTest method doCreateFS.
// In the default/public build, we do not have access to an isilon, so this test is off by default.
@Ignore
@Test
public void doCreateFS() 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.setVPool(createVPool());
args.addFSFileObject(fs);
final BiosCommandResult result = _isi.doCreateFS(_device, args);
Assert.assertEquals(Status.error.name(), result.getCommandStatus());
Assert.assertEquals(false, result.getCommandSuccess());
Assert.assertEquals(ServiceCode.ISILON_CONNECTION_ERROR, result.getServiceCoded().getServiceCode());
Assert.assertEquals("Unable to connect to isilon using url https://127.0.0.1:8080/", result.getMessage());
Assert.assertNotNull(result.getServiceCoded());
}
use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.
the class IsilonFileStorageDeviceTest method testSnapshots.
/**
* Tests snapshot create, smb share, nfs exports, snapshot delete.
*
* @throws Exception
*/
@Test
public void testSnapshots() 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", _isi.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", _isi.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", _isi.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", _isi.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", _isi.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);
// delete one SMB share for the snap
Assert.assertTrue("SMB share doDeleteShare() failed", _isi.doDeleteShare(_device, args, smbFileShare).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertFalse("SMB share doDeleteShare() failed, share was not deleted from snap", snap.getSMBFileShares().keySet().contains(smbFileShare.getName()));
Assert.assertTrue("SMB share doDeleteShare() failed, number of shares does not match", snap.getSMBFileShares().keySet().size() == 2);
// delete all SMB shares for snap
Assert.assertTrue("SMB share doDeleteShares() failed", _isi.doDeleteShares(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("SMB share doDeleteShares() failed, shares were not deleted from snap", snap.getSMBFileShares().isEmpty());
// export snap
List<String> clients = new ArrayList<String>();
clients.add(client1);
FileExport export1 = new FileExport(clients, "", "sys", "root", "nobody", "nfs");
Assert.assertTrue("doExport failed", _isi.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", _isi.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", _isi.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);
// unexport
Assert.assertTrue("doUnexport failed", _isi.doUnexport(_device, args, Arrays.asList(export1)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doUnexport failed, export not deleted from snapshot", snap.getFsExports().keySet().size() == 1);
Assert.assertTrue("doUnexport failed", _isi.doUnexport(_device, args, Arrays.asList(export3)).getCommandStatus().equals(Operation.Status.ready.name()));
Assert.assertTrue("doUnexport failed, export not deleted from snapshot", snap.getFsExports().keySet().isEmpty());
// delete snap
Assert.assertTrue("doDeleteSnapshot failed", _isi.doDeleteSnapshot(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
IsilonApi isilonApi = _isi.getIsilonDevice(_device);
try {
isilonApi.listDir(args.getFileObjMountPath(), null);
Assert.assertTrue("Snapshot delete failed: " + args.getFileObjMountPath(), false);
} catch (IsilonException iex) {
System.out.println("doDeleteSnapshot --- delete snapshot success: " + iex.getCause());
}
// delete file system
Assert.assertTrue("doDeleteFS failed", _isi.doDeleteFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
try {
isilonApi.listDir(args.getFsMountPath(), null);
Assert.assertTrue("FS delete failed: " + args.getFsMountPath(), false);
} catch (IsilonException iex) {
System.out.println("doDeleteFS --- delete FS success: " + iex.getCause());
}
}
Aggregations