use of com.emc.storageos.vnx.xmlapi.XMLApiResult 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.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileCommApi method doDeleteExport.
public XMLApiResult doDeleteExport(final StorageSystem system, String exportPath, FileDeviceInputOutput args, boolean deleteMount) {
XMLApiResult result = new XMLApiResult();
result.setCommandSuccess();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
_log.info("Delete VNX Export : {}", exportPath);
if (exportPath == null || (exportPath != null && exportPath.isEmpty())) {
_log.info("Invalid Export Path");
return result;
}
try {
updateAttributes(reqAttributeMap, system);
String moverId;
StorageHADomain dataMover = null;
String mountPath = "";
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();
mountPath = args.getFsMountPath();
_log.info("Using Mover Id {} to unexport FS mounted at {}", moverId, exportPath);
// Delete export from storage system.
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), exportPath).containsKey(exportPath)) {
// Delete the Export.
String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), exportPath);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
}
// we check for any exports and share exists and then run umount operation
if (result.isCommandSuccess() && getVNXFSDependencies(args.getFs(), false) <= 1) {
// Delete the mount
String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), mountPath, "NFS");
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
}
sshApi.clearConnParams();
} 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, exportPath);
if (dataMover.getVirtual()) {
isVdm = "true";
}
// Delete export from storage system.
reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverId);
reqAttributeMap.put(VNXFileConstants.MOUNT_PATH, exportPath);
reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
_provExecutor.setKeyMap(reqAttributeMap);
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), exportPath).containsKey(exportPath)) {
String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), exportPath);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
}
// Delete the Snapshot mount, only if No depending exports, shares for that snapshot.
if (result.isCommandSuccess() && getVNXFSDependencies(args.getFs(), true) <= 1) {
// Delete the mount
String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), exportPath, "NFS");
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
}
sshApi.clearConnParams();
}
} catch (Exception e) {
throw new VNXException("File Export Delete Exception: ", e);
}
return result;
}
use of com.emc.storageos.vnx.xmlapi.XMLApiResult 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.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileCommApi method doDeleteSnapshot.
public XMLApiResult doDeleteSnapshot(final StorageSystem system, final String snapId, String snapshotName, boolean deleteBaseline) throws VNXException {
_log.info("Delete VNX Snapshot id : {}", snapId);
XMLApiResult result = new XMLApiResult();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
try {
updateAttributes(reqAttributeMap, system);
reqAttributeMap.put(VNXFileConstants.SNAPSHOT_NAME, snapshotName);
reqAttributeMap.put(VNXFileConstants.SNAPSHOT_ID, snapId);
_provExecutor.setKeyMap(reqAttributeMap);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_DELETE_SNAP));
String cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
result.setCommandSuccess();
} else {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
}
} catch (Exception e) {
throw new VNXException("Failure", e);
}
return result;
}
use of com.emc.storageos.vnx.xmlapi.XMLApiResult 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;
}
Aggregations