use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method isiDeleteExports.
/**
* Delete isilon export
*
* @param isi
* IsilonApi object
* @param exportMap
* exports to be deleted
* @throws IsilonException
*/
private void isiDeleteExports(IsilonApi isi, FileDeviceInputOutput args) throws IsilonException {
FSExportMap exportMap = null;
if (args.getFileOperation()) {
FileShare fileObj = args.getFs();
if (fileObj != null) {
exportMap = fileObj.getFsExports();
}
} else {
Snapshot snap = args.getFileSnapshot();
if (snap != null) {
exportMap = snap.getFsExports();
}
}
if (exportMap == null || exportMap.isEmpty()) {
return;
}
String zoneName = getZoneName(args.getvNAS());
Set<String> deletedExports = new HashSet<String>();
Iterator<Map.Entry<String, FileExport>> it = exportMap.entrySet().iterator();
try {
while (it.hasNext()) {
Map.Entry<String, FileExport> entry = it.next();
String key = entry.getKey();
FileExport fsExport = entry.getValue();
if (zoneName != null) {
isi.deleteExport(fsExport.getIsilonId(), zoneName);
} else {
isi.deleteExport(fsExport.getIsilonId());
}
// Safe removal from the backing map. Can not do this through
// iterator since this does not track changes and is not
// reflected in the database.
deletedExports.add(key);
}
} finally {
// remove exports from the map in database.
for (String key : deletedExports) {
exportMap.remove(key);
}
}
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doExport.
@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
_log.info("NetAppFileStorageDevice doExport - start");
// Verify inputs.
validateExportArgs(exportList);
List<String> rootHosts = new ArrayList<String>();
List<String> rwHosts = new ArrayList<String>();
List<String> roHosts = new ArrayList<String>();
if (args.getFileObjExports() == null || args.getFileObjExports().isEmpty()) {
args.initFileObjExports();
}
FSExportMap existingExpMap = args.getFileObjExports();
List<FileExport> existingExportList = new ArrayList<FileExport>();
FileExport existingExport = null;
Iterator<String> it = existingExpMap.keySet().iterator();
while (it.hasNext()) {
existingExport = existingExpMap.get(it.next());
_log.info("Existing export FileExport key : {} ", existingExport.getFileExportKey());
existingExportList.add(existingExport);
}
// If it's a sub-directory no need to take existing hosts.
boolean isSubDir = checkIfSubDirectory(args.getFsMountPath(), exportList.get(0).getMountPath());
if (isSubDir) {
existingExportList = null;
}
// TODO: Revisit once new Data Model for Exports is implemented.
Map<String, List<String>> existingHosts = null;
if ((null != existingExportList) && !existingExportList.isEmpty()) {
existingHosts = sortHostsFromCurrentExports(existingExportList);
}
if (null != existingHosts) {
if ((null != existingHosts.get(ROOT_HOSTS)) && !existingHosts.get(ROOT_HOSTS).isEmpty()) {
addNewHostsOnly(rootHosts, existingHosts.get(ROOT_HOSTS));
}
if ((null != existingHosts.get(RW_HOSTS)) && !existingHosts.get(RW_HOSTS).isEmpty()) {
addNewHostsOnly(rwHosts, existingHosts.get(RW_HOSTS));
}
if ((null != existingHosts.get(RO_HOSTS)) && !existingHosts.get(RO_HOSTS).isEmpty()) {
addNewHostsOnly(roHosts, existingHosts.get(RO_HOSTS));
}
}
BiosCommandResult result = new BiosCommandResult();
try {
for (int expCount = 0; expCount < exportList.size(); expCount++) {
FileExport export = exportList.get(expCount);
if (!(export.getMountPath().startsWith(VOL_ROOT_NO_SLASH))) {
export.setMountPath(VOL_ROOT_NO_SLASH + export.getMountPath());
}
FileExport fileExport = new FileExport(export.getClients(), export.getStoragePortName(), export.getMountPoint(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getProtocol(), export.getStoragePort(), export.getPath(), export.getMountPath(), export.getSubDirectory(), export.getComments());
args.getFileObjExports().put(fileExport.getFileExportKey(), fileExport);
String portGroup = null;
FileShare fileshare = null;
if (args.getFileOperation() == true) {
fileshare = args.getFs();
portGroup = findVfilerName(fileshare);
} else {
// Get the FS from the snapshot
URI snapShotUID = args.getSnapshotId();
Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapShotUID);
fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
// Now get the VFiler from the fileshare
portGroup = findVfilerName(fileshare);
}
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
List<String> endpointsList = export.getClients();
if (endpointsList == null) {
_log.error("NetAppFileStorageDevice::doExport {} failed: No endpoints specified", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_NO_ENDPOINTS_SPECIFIED);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
sortNewEndPoints(rootHosts, rwHosts, roHosts, endpointsList, export.getPermissions());
String root_user = export.getRootUserMapping();
String mountPath = export.getMountPath();
String exportPath = export.getPath();
if (!nApi.exportFS(exportPath, mountPath, rootHosts, rwHosts, roHosts, root_user, export.getSecurityType())) {
_log.error("NetAppFileStorageDevice::doExport {} failed", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(genDetailedMessage("doExport", args.getFsId().toString()));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
result = BiosCommandResult.createSuccessfulResult();
if ((args.getFileOperation() == true) && (isSubDir == false)) {
nApi.setQtreemode(exportPath, UNIX_QTREE_SETTING);
}
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doExport failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doExport failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
_log.info("NetAppFileStorageDevice::doExport {} - complete", args.getFsId());
return result;
}
use of com.emc.storageos.db.client.model.FileExport 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.FileExport in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method getVNXFileExports.
private List<VNXFileExport> getVNXFileExports(List<FileExport> exports) {
List<VNXFileExport> vnxExports = new ArrayList<VNXFileExport>();
for (FileExport exp : exports) {
_log.debug("Added export sec, perm {} {}", exp.getSecurityType(), exp.getPermissions());
_log.debug(" anon,path {} {}", exp.getRootUserMapping(), exp.getPath());
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);
}
return vnxExports;
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doExport.
@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
boolean firstExport = false;
if (args.getFileObjExports() == null || args.getFileObjExports().isEmpty()) {
args.initFileObjExports();
}
// mount the FileSystem
firstExport = !(args.isFileShareMounted());
if (firstExport) {
_log.debug("First export: no existing file exports");
}
// Mounting is only necessary for FileSystem and not snapshot for the first time export
if (!args.getFileOperation()) {
firstExport = false;
}
// Create a list of the new exports.
FSExportMap newExpList = new FSExportMap();
FSExportMap curExpList = args.getFileObjExports();
FileExport curExport = null;
FileExport newExport = null;
List<String> newPaths = new ArrayList<String>();
Iterator<String> it = curExpList.keySet().iterator();
while (it.hasNext()) {
curExport = curExpList.get(it.next());
newExport = new FileExport(curExport.getClients(), curExport.getStoragePortName(), ExportUtils.getFileMountPoint(curExport.getStoragePort(), curExport.getPath()), curExport.getSecurityType(), curExport.getPermissions(), curExport.getRootUserMapping(), curExport.getProtocol(), curExport.getStoragePort(), curExport.getPath(), curExport.getMountPath(), curExport.getSubDirectory(), curExport.getComments());
_log.info("FileExport key : {} ", newExport.getFileExportKey());
newExpList.put(newExport.getFileExportKey(), newExport);
}
for (FileExport exp : exportList) {
newExport = new FileExport(exp.getClients(), exp.getStoragePortName(), ExportUtils.getFileMountPoint(exp.getStoragePort(), exp.getPath()), exp.getSecurityType(), exp.getPermissions(), exp.getRootUserMapping(), exp.getProtocol(), exp.getStoragePort(), exp.getPath(), exp.getMountPath(), exp.getSubDirectory(), exp.getComments());
_log.info("FileExport key : {} ", newExport.getFileExportKey());
newExpList.put(newExport.getFileExportKey(), newExport);
if (!newPaths.contains(newExport.getPath())) {
newPaths.add(newExport.getPath());
}
}
XMLApiResult result = null;
ApplicationContext context = null;
try {
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
// Get DataMover Name and whether it is virtual
StorageHADomain dm = this.getDataMover(args.getFs());
if (dm == null) {
Exception e = new Exception("VNX File Export Failed Data Mover not found");
throw VNXException.exceptions.createExportFailed("VNX File Export Failed Data Mover not found", e);
}
List<VNXFileExport> vnxExports = getVNXFileExports(newExpList);
if (args.getFileOperation()) {
// Perform FileSystem export
result = vnxComm.doExport(storage, dm, vnxExports, newPaths, args.getFileObj(), args.getFsNativeId(), firstExport);
} else {
// perform Snapshot export
result = vnxComm.doExport(storage, dm, vnxExports, newPaths, args.getFileObj(), args.getSnapNativeId(), firstExport);
}
if (result.isCommandSuccess()) {
curExpList.putAll(newExpList);
}
} catch (VNXException e) {
throw VNXException.exceptions.createExportFailed("VNX File Export Failed", e);
} finally {
clearContext(context);
}
BiosCommandResult cmdResult = null;
if (result.isCommandSuccess()) {
cmdResult = BiosCommandResult.createSuccessfulResult();
} else {
cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToExportFileSystem(result.getMessage()));
}
return cmdResult;
}
Aggregations