use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class FileSnapshotService method export.
/**
* Add file share snapshot export.
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR Snapshot
* @param param
* File system export parameters
* @brief Create file snapshot export
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep export(@PathParam("id") URI id, FileSystemExportParam param) throws InternalException {
_log.info("Snapshot Export request recieved {}", id);
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
Snapshot snap = queryResource(id);
ArgValidator.checkEntity(snap, id, true);
if (!param.getPermissions().equals(FileShareExport.Permissions.ro.name())) {
throw APIException.badRequests.snapshotExportPermissionReadOnly();
}
ArgValidator.checkFieldValueFromEnum(param.getSecurityType(), "type", EnumSet.allOf(FileShareExport.SecurityTypes.class));
ArgValidator.checkFieldValueFromEnum(param.getProtocol(), "protocol", EnumSet.allOf(StorageProtocol.File.class));
ArgValidator.checkSubDirName("sub_directory", param.getSubDirectory());
FileService.validateIpInterfacesRegistered(param.getEndpoints(), _dbClient);
FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
// Locate storage port for exporting file snap
// We use file system in the call since file snap belongs to the same neighbourhood as its parent file system
StoragePort sport = _fileScheduler.placeFileShareExport(fs, param.getProtocol(), param.getEndpoints());
String path = snap.getPath();
String mountPath = snap.getMountPath();
_log.info("Check whether there is a NFS Export already for the path {}", path);
FSExportMap exportMap = snap.getFsExports();
if (exportMap != null) {
Iterator it = snap.getFsExports().keySet().iterator();
boolean exportExists = false;
while (it.hasNext()) {
String fsExpKey = (String) it.next();
FileExport fileExport = snap.getFsExports().get(fsExpKey);
_log.info("Snap export key {} does it exist ? {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
if (fileExport.getPath().equalsIgnoreCase(path)) {
exportExists = true;
_log.info("Snap export key {} exist {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
break;
}
}
if (exportExists) {
throw APIException.badRequests.snapshotHasExistingExport();
}
}
verifyFileSnapshotExports(snap, param, path);
FileShareExport export = new FileShareExport(param.getEndpoints(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol(), sport.getPortGroup(), sport.getPortNetworkId(), path, mountPath, param.getSubDirectory(), param.getComments());
_log.info("FileSnapExport --- FileSnap id: " + id + ", Clients: " + export.getClients() + ", StoragePort:" + sport.getPortName() + ", StoragePort :" + export.getStoragePort() + ", SecurityType: " + export.getSecurityType() + ", Permissions: " + export.getPermissions() + ", Root user mapping: " + export.getRootUserMapping() + ",Protocol: " + export.getProtocol() + ",path:" + export.getPath() + ",mountPath:" + export.getMountPath());
Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.EXPORT_FILE_SNAPSHOT);
FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.export(device.getId(), snap.getId(), Arrays.asList(export), task);
auditOp(OperationTypeEnum.EXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), device.getId().toString(), export.getClients(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol());
return toTask(snap, task, op);
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class FileSnapshotService method verifyFileSnapshotExports.
private void verifyFileSnapshotExports(Snapshot snap, FileSystemExportParam param, String path) {
FSExportMap snapExports = snap.getFsExports();
URI id = snap.getId();
if (null != snapExports) {
Iterator<FileExport> it = snapExports.values().iterator();
while (it.hasNext()) {
FileExport fileExport = it.next();
// If no key found then it should process as it is.
boolean isAlreadyExportedToSameEndpoint = false;
if (fileExport.getPath().equals(path)) {
List<String> availableEndpoints = fileExport.getClients();
List<String> providedEndpoints = param.getEndpoints();
for (String providedEndpoint : providedEndpoints) {
if (availableEndpoints.contains(providedEndpoint)) {
isAlreadyExportedToSameEndpoint = true;
break;
}
}
if (isAlreadyExportedToSameEndpoint) {
_log.info(String.format("Existing Export params for Snapshot id: %1$s, SecurityType: %2$s, " + "Permissions: %3$s, Root user mapping: %4$s, ", id, fileExport.getSecurityType(), fileExport.getPermissions(), fileExport.getRootUserMapping()));
_log.info(String.format("Recieved Export params for Snapshot id: %1$s, SecurityType: %2$s, " + "Permissions: %3$s, Root user mapping: %4$s, ", id, param.getSecurityType(), param.getPermissions(), param.getRootUserMapping()));
if (!fileExport.getPermissions().equals(param.getPermissions())) {
throw APIException.badRequests.updatingSnapshotExportNotAllowed("permissions");
}
if (!fileExport.getSecurityType().equals(param.getSecurityType())) {
throw APIException.badRequests.updatingSnapshotExportNotAllowed("type");
}
if (!fileExport.getRootUserMapping().equals(param.getRootUserMapping())) {
throw APIException.badRequests.updatingSnapshotExportNotAllowed("root_user");
}
}
}
}
}
}
use of com.emc.storageos.db.client.model.FileExport 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.db.client.model.FileExport 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.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class PropertySetterUtil method convertUnManagedExportMapToManaged.
/**
* extract value from a String Set
* This method is used, to get value from a StringSet of size 1.
*
* @param key
* @param volumeInformation
* @return String
*/
public static FSExportMap convertUnManagedExportMapToManaged(UnManagedFSExportMap unManagedFSExportMap, StoragePort storagePort, StorageHADomain dataMover) {
FSExportMap fsExportMap = new FSExportMap();
if (unManagedFSExportMap == null) {
return fsExportMap;
}
for (UnManagedFSExport export : unManagedFSExportMap.values()) {
FileExport fsExport = new FileExport();
if (null != export.getIsilonId()) {
fsExport.setIsilonId(export.getIsilonId());
}
if (null != export.getNativeId()) {
fsExport.setNativeId(export.getNativeId());
}
if (null != storagePort) {
fsExport.setStoragePort(storagePort.getPortName());
if ((export.getMountPath() != null) && (export.getMountPath().length() > 0)) {
fsExport.setMountPoint(ExportUtils.getFileMountPoint(storagePort.getPortNetworkId(), export.getMountPath()));
} else {
fsExport.setMountPoint(ExportUtils.getFileMountPoint(storagePort.getPortNetworkId(), export.getPath()));
}
} else if (null != export.getStoragePort()) {
fsExport.setStoragePort(export.getStoragePort());
if (null != export.getMountPoint()) {
fsExport.setMountPoint(export.getMountPoint());
}
}
if (null != dataMover) {
fsExport.setStoragePortName(dataMover.getName());
} else if (null != storagePort) {
fsExport.setStoragePortName(storagePort.getPortName());
} else if (null != export.getStoragePortName()) {
fsExport.setStoragePortName(export.getStoragePortName());
}
if (null != export.getMountPath()) {
fsExport.setMountPath(export.getMountPath());
}
fsExport.setPath(export.getPath());
fsExport.setPermissions(export.getPermissions());
fsExport.setProtocol(export.getProtocol());
fsExport.setRootUserMapping(export.getRootUserMapping());
fsExport.setSecurityType(export.getSecurityType());
fsExport.setClients(export.getClients());
fsExportMap.put(fsExport.getFileExportKey(), fsExport);
}
return fsExportMap;
}
Aggregations