use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXFileCommApi method doUnexport.
public XMLApiResult doUnexport(final StorageSystem system, VNXFileExport fileExport, FileDeviceInputOutput args, boolean deleteMount) throws VNXException {
_log.info("Unexport file sys mounted at : {}", fileExport.getMountPoint());
XMLApiResult result = new XMLApiResult();
result.setCommandSuccess();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
try {
updateAttributes(reqAttributeMap, system);
String moverId;
StorageHADomain dataMover = null;
if (args.getFileOperation()) {
StoragePort storagePort = _dbClient.queryObject(StoragePort.class, args.getFs().getStoragePort());
URI dataMoverId = storagePort.getStorageHADomain();
dataMover = _dbClient.queryObject(StorageHADomain.class, dataMoverId);
moverId = dataMover.getName();
String fsMountPath = args.getFsPath();
_log.info("Using Mover Id {} to unexport FS mounted at {}", moverId, fsMountPath);
// Retrieve export object from the DB. If there are multiple "ro",
// "rw", "root", and "access" endpoints, just remove this entry and update
// export properties on the array and in the DB
boolean thisEntryFound = false;
boolean moreEntries = false;
Set<String> keysToRemove = new HashSet<String>();
String exportEntryKey = FileExport.exportLookupKey(fileExport.getProtocol(), fileExport.getSecurityType(), fileExport.getPermissions(), fileExport.getRootUserMapping(), fileExport.getMountPoint());
FileExport export = args.getFileObjExports().get(exportEntryKey);
if (export != null) {
thisEntryFound = true;
keysToRemove.add(exportEntryKey);
}
Set<String> keys = args.getFileObjExports().keySet();
for (String key : keys) {
if ((fileExport.getMountPoint().equals(args.getFileObjExports().get(key).getPath())) && (!exportEntryKey.equalsIgnoreCase(key))) {
moreEntries = true;
break;
}
}
for (String key : keysToRemove) {
args.getFsExports().remove(key);
}
boolean deleteExportFromDevice = true;
if ((!thisEntryFound) || (moreEntries)) {
// Don't unexport, just update properties
deleteExportFromDevice = false;
}
if (deleteExportFromDevice) {
// Delete export from storage system.
String mntPoint = fileExport.getMountPoint();
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), mntPoint).containsKey(mntPoint)) {
String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), mntPoint);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
}
// As we already removed the export entry from Map, Check for any other dependents.
if (result.isCommandSuccess() && getVNXFSDependencies(args.getFs(), false) < 1) {
// Delete the mount
String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), fsMountPath, "NFS");
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
}
sshApi.clearConnParams();
} else {
// Just update export properties.
List<VNXFileExport> vnxExports = new ArrayList<VNXFileExport>();
keys = args.getFsExports().keySet();
for (String key : keys) {
FileExport exp = args.getFileObjExports().get(key);
VNXFileExport vnxExp = new VNXFileExport(exp.getClients(), exp.getStoragePortName(), exp.getPath(), exp.getSecurityType(), exp.getPermissions(), exp.getRootUserMapping(), exp.getProtocol(), exp.getStoragePort(), exp.getSubDirectory(), exp.getComments());
vnxExports.add(vnxExp);
}
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
String data = sshApi.formatExportCmd(dataMover.getAdapterName(), vnxExports, null, null);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
sshApi.clearConnParams();
if (result.isCommandSuccess()) {
result.setCommandSuccess();
} else {
result.setCommandFailed();
}
}
} else {
String isVdm = "false";
Snapshot snapshot = _dbClient.queryObject(Snapshot.class, args.getSnapshotId());
FileShare fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
StoragePort storagePort = _dbClient.queryObject(StoragePort.class, fileshare.getStoragePort());
URI dataMoverId = storagePort.getStorageHADomain();
dataMover = _dbClient.queryObject(StorageHADomain.class, dataMoverId);
moverId = dataMover.getName();
_log.info("Using Mover Id {} to unexport FS mounted at {}", moverId, fileExport.getMountPoint());
if (dataMover.getVirtual()) {
isVdm = "true";
}
// Delete export from storage system.
reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverId);
reqAttributeMap.put(VNXFileConstants.MOUNT_PATH, fileExport.getMountPoint());
reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
_provExecutor.setKeyMap(reqAttributeMap);
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
String mntPoint = fileExport.getMountPoint();
if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), mntPoint).containsKey(mntPoint)) {
String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), mntPoint);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
}
if (result.isCommandSuccess() && getVNXFSDependencies(fileshare, true) <= 1) {
// Delete the mount
String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), fileExport.getMountPoint(), "NFS");
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
}
sshApi.clearConnParams();
}
} catch (Exception e) {
throw new VNXException("File unexport exception: ", e);
}
return result;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXeStorageDevice method doRestoreFS.
@Override
public BiosCommandResult doRestoreFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_logger.info("restoring file system {} snap {} ", args.getFsName(), args.getSnapshotLabel());
VNXeApiClient apiClient = getVnxeClient(storage);
VNXeCommandJob job = null;
VNXeFSSnapshotTaskCompleter completer = null;
try {
job = apiClient.restoreFileSystemSnap(args.getSnapNativeId());
if (job != null) {
completer = new VNXeFSSnapshotTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeRestoreFileSystemSnapshotJob snapJob = new VNXeRestoreFileSystemSnapshotJob(job.getId(), storage.getId(), completer);
ControllerServiceImpl.enqueueJob(new QueueJob(snapJob));
} else {
_logger.error("No job returned from restoreFileSystemSnap");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("restoreSnapshotFileSystem", "No Job returned from restoreFileSystemSnap");
return BiosCommandResult.createErrorResult(error);
}
} catch (VNXeException e) {
_logger.error("Restore file system snapshot got the exception", e);
if (completer != null) {
completer.error(_dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Restore file system snpashot got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreFileSystemSnapshot", ex.getMessage());
if (completer != null) {
completer.error(_dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Restore filesystem snapshot job submitted - Array:%s, fileSystem: %s, snapshot: %s", storage.getSerialNumber(), args.getFsName(), args.getSnapshotLabel()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXeStorageDevice method doShare.
@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
_logger.info("creating smbShare: " + smbFileShare.getName());
VNXeApiClient apiClient = getVnxeClient(storage);
String permission = smbFileShare.getPermission();
String shareName = smbFileShare.getName();
String path = "/";
VNXeCommandJob job = null;
VNXeFileTaskCompleter completer = null;
FileSMBShare newShare = new FileSMBShare(smbFileShare);
String absolutePath = smbFileShare.getPath();
newShare.setStoragePortNetworkId(smbFileShare.getStoragePortNetworkId());
newShare.setStoragePortName(smbFileShare.getStoragePortName());
try {
if (args.getFileOperation()) {
if (newShare.isSubDirPath()) {
String basePath = args.getFsPath();
/*
* The below line will allow us to get the relative path of subdir
* For example: absolutePath = /vnxeShare1/subdir1
* Then, the below line will assign path = subdir
* VNXe takes the relative path of the sub-directory. Not the absolute path
*/
path = "/" + new File(basePath).toURI().relativize(new File(absolutePath).toURI()).getPath();
}
String fsNativeId = args.getFs().getNativeId();
_logger.info("Creating CIFS share for path {}", path);
job = apiClient.createCIFSShare(fsNativeId, shareName, permission, path);
if (job != null) {
newShare.setNetBIOSName(apiClient.getNetBios());
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
VNXeCreateShareJob createShareJob = new VNXeCreateShareJob(job.getId(), storage.getId(), completer, newShare, true);
ControllerServiceImpl.enqueueJob(new QueueJob(createShareJob));
} else {
_logger.error("No job returned from creaetCifsShare");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createShare", "No Job returned");
return BiosCommandResult.createErrorResult(error);
}
} else {
// create share for a snapshot
if (newShare.isSubDirPath()) {
String basePath = args.getSnapshotPath();
/*
* The below line will allow us to get the relative path of subdir
* For example: absolutePath = /vnxeShare1/subdir1
* Then, the below line will assign path = subdir
* VNXe takes the relative path of the sub-directory. Not the absolute path
*/
path = "/" + new File(basePath).toURI().relativize(new File(absolutePath).toURI()).getPath();
}
String fsNativeId = args.getFs().getNativeId();
String snapId = args.getSnapNativeId();
job = apiClient.createCifsShareForSnap(snapId, shareName, permission, path, fsNativeId);
if (job != null) {
newShare.setNetBIOSName(apiClient.getNetBios());
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeCreateShareJob createShareJob = new VNXeCreateShareJob(job.getId(), storage.getId(), completer, newShare, false);
ControllerServiceImpl.enqueueJob(new QueueJob(createShareJob));
} else {
_logger.error("No job returned from creaetCifsShare");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createShare", "No Job returned");
return BiosCommandResult.createErrorResult(error);
}
}
} catch (VNXeException e) {
_logger.error("Create share got the exception", e);
if (completer != null) {
completer.error(_dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("create share got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("create share", ex.getMessage());
if (completer != null) {
completer.error(_dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Create share job submitted - Array:%s, share: %s", storage.getSerialNumber(), smbFileShare.getName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class CifsShareACLMigration method process.
@Override
public void process() throws MigrationCallbackException {
logger.info("Migration started");
DbClient dbClient = getDbClient();
try {
List<URI> fileSystemURIList = dbClient.queryByType(FileShare.class, true);
Iterator<FileShare> fileSystemList = dbClient.queryIterativeObjects(FileShare.class, fileSystemURIList, true);
while (fileSystemList.hasNext()) {
FileShare fs = fileSystemList.next();
SMBShareMap smbShareMap = fs.getSMBFileShares();
Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
if (smbShareMap != null) {
smbShares = smbShareMap.values();
for (SMBFileShare smbShare : smbShares) {
if (smbShare.getPermissionType().equalsIgnoreCase(PERMISSION_TYPE_ALLOW)) {
CifsShareACL acl = new CifsShareACL();
acl.setId(URIUtil.createId(CifsShareACL.class));
acl.setShareName(smbShare.getName());
acl.setPermission(smbShare.getPermission());
acl.setUser(USER_EVERYONE);
acl.setFileSystemId(fs.getId());
logger.debug("Persisting new ACE into DB: {}", acl);
dbClient.createObject(acl);
}
}
}
}
// File snapshots
List<URI> fileSnapshotURIList = dbClient.queryByType(Snapshot.class, true);
Iterator<Snapshot> fileSnapshotList = dbClient.queryIterativeObjects(Snapshot.class, fileSnapshotURIList, true);
while (fileSnapshotList.hasNext()) {
Snapshot snapshot = fileSnapshotList.next();
SMBShareMap smbShareMap = snapshot.getSMBFileShares();
Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
if (smbShareMap != null) {
smbShares = smbShareMap.values();
for (SMBFileShare smbShare : smbShares) {
if (smbShare.getPermissionType().equalsIgnoreCase(PERMISSION_TYPE_ALLOW)) {
CifsShareACL acl = new CifsShareACL();
acl.setId(URIUtil.createId(CifsShareACL.class));
acl.setShareName(smbShare.getName());
acl.setPermission(getFormattedPermissionText(smbShare.getPermission()));
acl.setUser(USER_EVERYONE);
acl.setSnapshotId(snapshot.getId());
logger.debug("Persisting new ACE into DB: {}", acl);
dbClient.createObject(acl);
}
}
}
}
logger.info("Migration completed successfully");
} catch (Exception e) {
logger.error("Exception occured while migrating cifs share access control settings");
logger.error(e.getMessage(), e);
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDeviceTest 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", _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);
// delete one SMB share for the snap
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 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", _unity.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", _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);
// unexport
Assert.assertTrue("doUnexport failed", _unity.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", _unity.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", _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());
}
}
Aggregations