use of com.emc.storageos.db.client.model.FileObject 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.db.client.model.FileObject in project coprhd-controller by CoprHD.
the class VNXFileCommApi method deleteAllExportsAndShares.
private XMLApiResult deleteAllExportsAndShares(StorageSystem system, StorageHADomain dataMover, FileShare fs, Snapshot snapshot) {
FSExportMap exports;
SMBShareMap shares;
XMLApiResult result = new XMLApiResult();
result.setCommandSuccess();
String fileId = fs.getId().toString();
FileObject fObj = fs;
_log.info("deleteAllExportsAndShares for {} {}", fs.getName(), snapshot);
boolean fileOperation = false;
if (snapshot == null) {
// FileShare operation
_log.info("deleteAllExportsAndShares FileShare delete operation");
exports = fs.getFsExports();
shares = fs.getSMBFileShares();
fileOperation = true;
fObj = fs;
} else {
_log.info("deleteAllExportsAndShares Snapshot delete operation");
exports = snapshot.getFsExports();
shares = snapshot.getSMBFileShares();
fObj = snapshot;
fileId = snapshot.getId().toString();
}
int exportsToUnExport = 0;
Set<String> keys = new HashSet();
if (exports != null) {
exportsToUnExport = exports.size();
keys = exports.keySet();
}
int noOfShares = 0;
if (shares != null) {
noOfShares = shares.size();
}
_log.info("Number of NFS exports {} SMB Shares found {} for File/Snapshot Id {}", new Object[] { exportsToUnExport, noOfShares, fileId });
// To avoid concurrent modification exceptions
Set<String> exportKeys = new HashSet();
exportKeys.addAll(keys);
FileDeviceInputOutput args = new FileDeviceInputOutput();
args.setFileOperation(fileOperation);
args.addFSFileObject(fs);
if (fileOperation) {
args.setFileOperation(true);
args.addFSFileObject(fs);
} else {
args.setFileOperation(false);
args.addFSFileObject(fs);
args.addSnapshot(snapshot);
}
for (String key : exportKeys) {
FileExport exp = exports.get(key);
VNXFileExport fileExport = new VNXFileExport(exp.getClients(), exp.getStoragePortName(), exp.getPath(), exp.getSecurityType(), exp.getPermissions(), exp.getRootUserMapping(), exp.getProtocol(), exp.getStoragePort(), exp.getSubDirectory(), exp.getComments());
fileExport.setStoragePort(fs.getStoragePort().toString());
boolean deleteMount = false;
if (exportsToUnExport == 1 && noOfShares == 0 && fileOperation) {
deleteMount = true;
}
XMLApiResult status = doUnexport(system, fileExport, args, deleteMount);
if (!status.isCommandSuccess()) {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
return result;
} else {
fObj.getFsExports().remove(key);
_log.info("Export removed : " + key);
exportsToUnExport--;
}
// Persist the object after exports removed
_dbClient.persistObject(fObj);
}
// Now Let Handle SMB/CIFS Shares
keys = new HashSet<>();
int noOfSharesToDelete = 0;
if (shares != null) {
keys = shares.keySet();
noOfSharesToDelete = keys.size();
}
int noOfExports = 0;
if (exports != null) {
noOfExports = exports.size();
}
_log.info("Number of CIFS/SMB Shares {} NFS Exports found {} for File/Snapshot Id {}", new Object[] { noOfSharesToDelete, noOfExports, fileId });
// To avoid concurrent modification exceptions
Set<String> shareKeys = new HashSet();
shareKeys.addAll(keys);
for (String key : shareKeys) {
SMBFileShare share = shares.get(key);
_log.info("Delete SMB/CIFS Share {} from FS/Snapshot {}", share.getName(), fileId);
boolean deleteMount = false;
if (noOfSharesToDelete == 1 && noOfExports == 0 && fileOperation) {
deleteMount = true;
}
XMLApiResult status = doDeleteShare(system, dataMover, share.getName(), fs.getMountPath(), deleteMount, args);
if (!status.isCommandSuccess()) {
_log.info("SMBFileShare deletion failed key {} : {} ", key, share.getName());
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
return result;
} else {
fObj.getSMBFileShares().remove(key);
_log.info("SMBFileShare removed : " + key);
noOfSharesToDelete--;
}
// Persist the object after SMBShares removed
_dbClient.persistObject(fObj);
}
return result;
}
use of com.emc.storageos.db.client.model.FileObject in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method deleteShare.
@Override
public void deleteShare(URI storage, URI uri, FileSMBShare fileSMBShare, String opId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Deleting file system: %s CIFS share: %s ", uri, fileSMBShare.getName());
successMessage = String.format("Deleting file system: %s CIFS share: %s finished succesfully.", uri, fileSMBShare.getName());
opName = ResourceOperationTypeEnum.DELETE_FILE_SYSTEM_SHARE.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Deleting file system snapshot: %s CIFS share: %s ", uri, fileSMBShare.getName());
successMessage = String.format("Deleting file system snapshot: %s CIFS share: %s finished succesfully.", uri, fileSMBShare.getName());
opName = ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, DELETE_FILESYSTEM_CIFS_SHARE_WF_NAME, false, opId, completer);
String sharedeleteStep = workflow.createStepId();
Object[] args = new Object[] { storage, uri, fileSMBShare };
_fileDeviceController.createMethod(workflow, null, DELETE_FILESYSTEM_SHARE_METHOD, sharedeleteStep, stepDescription, storage, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Deleting file system snapshot: %s CIFS share: %s failed.", uri, fileSMBShare.getName()), ex);
ServiceError serviceError = DeviceControllerException.errors.deleteCIFSShareFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.db.client.model.FileObject in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method updateExportRules.
@Override
public void updateExportRules(URI storage, URI uri, FileExportUpdateParams param, boolean unmountExport, String opId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Updating file system : %s export rules: %s", uri, param.toString());
successMessage = String.format("Updating file system : %s export rules: %s finished successfully.", uri, param.toString());
opName = ResourceOperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SYSTEM.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Updating file system : %s export rules: %s", uri, param.toString());
successMessage = String.format("Updating file system : %s export rules: %s finished successfully.", uri, param.toString());
opName = ResourceOperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SNAPSHOT.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_FILESYSTEM_EXPORT_RULES_WF_NAME, false, opId, completer);
String waitFor = null;
// Check if the export should be unmounted before deleting
if (unmountExport) {
// get all the mounts and generate steps for unmounting them
List<MountInfo> mountList = _fileDeviceController.getMountedExports(uri, param.getSubDir(), param);
for (MountInfo mount : mountList) {
Object[] args = new Object[] { mount.getHostId(), mount.getFsId(), mount.getMountPath() };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, UNMOUNT_FILESYSTEM_EXPORT_METHOD, null, "Unmounting path:" + mount.getMountPath(), storage, args);
}
} else if (URIUtil.isType(uri, FileShare.class)) {
// Check if the export rule is mounted and throw an error if mounted
Object[] args = new Object[] { uri, param };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, VERIFY_MOUNT_DEPENDENCIES_METHOD, null, "Verifying mount dependencies", storage, args);
}
Object[] args = new Object[] { storage, uri, param };
_fileDeviceController.createMethod(workflow, waitFor, UPDATE_FILESYSTEM_EXPORT_RULES_METHOD, null, stepDescription, storage, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Updating file system : %s export rules: %s failed.", uri, param.toString()), ex);
ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.db.client.model.FileObject in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method createCIFSShare.
@Override
public void createCIFSShare(URI storageSystem, URI uri, FileSMBShare smbShare, String taskId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, taskId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Creating CIFS share for file system : %s, share name: %s ", uri, smbShare.getName());
successMessage = String.format("Creating CIFS share for file system : %s, share name: %s finished succesfully.", uri, smbShare.getName());
opName = ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_SHARE.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, taskId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Creating CIFS share for file system snapshot : %s, share name: %s ", uri, smbShare.getName());
successMessage = String.format("Creating CIFS share for file system : %s, share name: %s finished succesfully.", uri, smbShare.getName());
opName = ResourceOperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, CREATE_FILESYSTEM_CIFS_SHARE_WF_NAME, false, taskId, completer);
String shareStep = workflow.createStepId();
Object[] args = new Object[] { storageSystem, uri, smbShare };
_fileDeviceController.createMethod(workflow, null, CREATE_FILESYSTEM_SHARE_METHOD, shareStep, stepDescription, storageSystem, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Creating CIFS share for file system : %s, share name: %s failed.", uri, smbShare.getName()), ex);
ServiceError serviceError = DeviceControllerException.errors.createFileSharesFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
Aggregations