use of com.emc.storageos.vnx.xmlapi.VNXFileExport in project coprhd-controller by CoprHD.
the class VNXFileCommApi method doExport.
/**
* Performs an export for a VNX File array. If this is the first export of a file system path,
* then the path must be mounted on a data mover first. Also, if the root user mapping contains a
* user account name, then it must be converted into a UID.
*
* @param system
* @param exports
* @param fsName
* @param fsId
* @param firstExport
* @return
* @throws VNXException
*/
public XMLApiResult doExport(final StorageSystem system, StorageHADomain dataMover, List<VNXFileExport> exports, List<String> newPaths, FileObject fileObject, String fsId, boolean firstExport) throws VNXException {
VNXFileExport vnxExp = exports.get(0);
String port = vnxExp.getStoragePortName();
String storagePortNetworkId = vnxExp.getStoragePort();
_log.info("Export for {}, data mover {}", fileObject.getLabel(), port + ":" + storagePortNetworkId);
XMLApiResult result = new XMLApiResult();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
FileShare fs = null;
if (fileObject instanceof FileShare) {
fs = _dbClient.queryObject(FileShare.class, fileObject.getId());
}
String moverOrVdmId = "";
String moverOrVdmName = "";
String parentDMName = "";
String isVdm = "false";
try {
if (null == dataMover) {
result.setCommandFailed();
result.setMessage("Export failed: data mover or vdm not found.");
return result;
}
moverOrVdmId = dataMover.getName();
moverOrVdmName = dataMover.getAdapterName();
if (dataMover.getVirtual() != null && dataMover.getVirtual() == true) {
isVdm = "true";
parentDMName = getParentMoverName(dataMover.getParentHADomainURI());
}
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
Map<String, String> userInfo = sshApi.getUserInfo(parentDMName);
_log.info("Using Mover {} to export FS mounted at {}", moverOrVdmId + ":" + moverOrVdmName, exports.get(0).getMountPoint());
updateAttributes(reqAttributeMap, system);
reqAttributeMap.put(VNXFileConstants.DATAMOVER_ID, port);
reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverOrVdmId);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_ID, fsId);
reqAttributeMap.put(VNXFileConstants.DATAMOVER_NAME, moverOrVdmName);
reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
if (vnxExp.getComment() != null && !vnxExp.getComment().isEmpty()) {
reqAttributeMap.put(VNXFileConstants.TASK_DESCRIPTION, vnxExp.getComment());
}
Set<String> moverIds = new HashSet<String>();
moverIds.add(port);
reqAttributeMap.put(VNXFileConstants.MOVERLIST, moverIds);
_provExecutor.setKeyMap(reqAttributeMap);
if (firstExport) {
reqAttributeMap.put(VNXFileConstants.MOUNT_PATH, fs.getMountPath());
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FILE_EXPORT_MOUNT));
} else {
reqAttributeMap.put(VNXFileConstants.MOUNT_PATH, vnxExp.getMountPoint());
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FILE_EXPORT));
}
List<VNXCifsServer> cifsServers = (List<VNXCifsServer>) _provExecutor.getKeyMap().get(VNXFileConstants.CIFS_SERVERS);
if (cifsServers == null || cifsServers.isEmpty()) {
_log.info("No CIFS Servers retrieved for mover {} with id {}", moverOrVdmName, moverOrVdmId);
} else {
for (VNXCifsServer cifsServer : cifsServers) {
_log.debug("CIFServer:" + cifsServer.toString());
}
}
// Format and issue separate ssh api commands for each new file system and subdirectory
List<VNXFileExport> newExportEntries = new ArrayList<VNXFileExport>();
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
for (String newPath : newPaths) {
String netBios = null;
// Only set netbios for VDM CIFS exports
if (cifsServers != null && !cifsServers.isEmpty() && dataMover.getVirtual()) {
netBios = cifsServers.get(0).getName();
}
for (VNXFileExport export : exports) {
if (export.getMountPoint().equals(newPath)) {
export.setNetBios(netBios);
newExportEntries.add(export);
}
}
_log.info("Export info {} {}", moverOrVdmName, netBios);
// Check for existance of share by name
String shareNameCheckData = sshApi.formatCheckShareForExportCmd(moverOrVdmName, newExportEntries, userInfo, netBios);
if (shareNameCheckData != null) {
XMLApiResult shareNameCheckCommandResult = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, shareNameCheckData);
if (shareNameCheckCommandResult.isCommandSuccess()) {
_log.error("Export command failed for share name {}", newExportEntries.get(0).getExportName());
StringBuilder errorMessageBuilder = new StringBuilder();
errorMessageBuilder.append("Share by the name ");
errorMessageBuilder.append(newExportEntries.get(0).getExportName());
errorMessageBuilder.append(" Already exists on server ");
errorMessageBuilder.append(moverOrVdmName);
result.setCommandFailed();
result.setMessage(errorMessageBuilder.toString());
return result;
}
}
String data = sshApi.formatExportCmd(moverOrVdmName, newExportEntries, userInfo, netBios);
_log.info("Export command {}", data);
if (data != null) {
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
}
if (!result.isCommandSuccess()) {
if (firstExport) {
data = sshApi.formatUnMountCmd(moverOrVdmName, fs.getMountPath(), "NFS");
XMLApiResult unmountResult = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
if (!unmountResult.isCommandSuccess()) {
_log.warn("Unmounting the file system {} failed due to {}", fs.getId(), unmountResult.getMessage());
} else {
_log.info("Unmounted the file system {} successfully", fs.getId());
}
}
return result;
}
newExportEntries.clear();
}
sshApi.clearConnParams();
} catch (Exception e) {
throw VNXException.exceptions.createExportFailed(result.getMessage(), e);
}
_log.info("doExport result: " + result.getMessage());
return result;
}
use of com.emc.storageos.vnx.xmlapi.VNXFileExport 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.vnx.xmlapi.VNXFileExport in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doShare.
@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
_log.info("Call FileShare doShare");
boolean firstExport = false;
if (args.getFileObjShares() == null || args.getFileObjShares().isEmpty()) {
args.initFileObjShares();
}
firstExport = !(args.isFileShareMounted());
if (firstExport) {
_log.debug("First export: no existing file obj shares");
}
if (!args.getFileOperation()) {
firstExport = false;
}
String portName = smbFileShare.getPortGroup();
String path = smbFileShare.getPath();
if (path == null || path.length() == 0) {
if (args.getFileOperation()) {
path = args.getFsMountPath();
} else {
path = args.getSnapshotMountPath();
}
}
_log.debug("Data Mover: {}", portName);
_log.debug("Mount path: {}", path);
XMLApiResult result = null;
ApplicationContext context = null;
try {
List<String> clients = new ArrayList<String>();
VNXFileExport fileExport = new VNXFileExport(clients, portName, path, // no security type
"", smbFileShare.getPermission(), // root user mapping n/a for CIFS
"", VNXFileSshApi.VNX_CIFS, // Port information is never used for for CIFS or NFS exports.
"", // SUB DIR
"", // Comments -- TODO
"");
fileExport.setExportName(smbFileShare.getName());
fileExport.setComment(smbFileShare.getDescription());
fileExport.setMaxUsers(Integer.toString(smbFileShare.getMaxUsers()));
List<VNXFileExport> vnxExports = new ArrayList<VNXFileExport>();
vnxExports.add(fileExport);
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
// Get DataMover
StorageHADomain dm = this.getDataMover(args.getFs());
if (dm == null) {
Exception e = new Exception("VNX File Share creation Failed Data Mover not found");
throw VNXException.exceptions.createExportFailed("VNX File Share creation Failed Data Mover not found", e);
}
List<String> paths = new ArrayList<String>();
paths.add(path);
if (args.getFileOperation()) {
// Perform FileSystem export
result = vnxComm.doExport(storage, dm, vnxExports, paths, args.getFileObj(), args.getFsNativeId(), firstExport);
} else {
// perform Snapshot export
result = vnxComm.doExport(storage, dm, vnxExports, paths, args.getFileObj(), args.getSnapNativeId(), firstExport);
}
if ((result != null) && (result.isCommandSuccess())) {
// Set MountPoint
smbFileShare.setMountPoint(fileExport.getNetBios(), smbFileShare.getStoragePortNetworkId(), smbFileShare.getStoragePortName(), smbFileShare.getName());
args.getFileObjShares().put(smbFileShare.getName(), smbFileShare);
}
} catch (VNXException e) {
throw new DeviceControllerException(e);
} catch (NumberFormatException e) {
// Placeholder until real handling is determined.
throw new DeviceControllerException(e);
} finally {
clearContext(context);
}
BiosCommandResult cmdResult = null;
if (result.isCommandSuccess()) {
cmdResult = BiosCommandResult.createSuccessfulResult();
} else {
cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToCreateFileShare(result.getMessage()));
}
return cmdResult;
}
use of com.emc.storageos.vnx.xmlapi.VNXFileExport 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.vnx.xmlapi.VNXFileExport 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