use of com.emc.storageos.vnx.xmlapi.XMLApiResult 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.vnx.xmlapi.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileCommApi method createSnapshot.
public XMLApiResult createSnapshot(final StorageSystem system, final String fsName, final String snapshotName, final FileShare fileShare) throws VNXException {
_log.info("Create Snap for file sys : {} snap name : {}", fsName, snapshotName);
XMLApiResult result = new XMLApiResult();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
try {
// get the data mover
StorageHADomain dataMover = this.getDataMover(fileShare);
if (null != dataMover) {
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
Map<String, String> existingMounts = sshApi.getFsMountpathMap(dataMover.getAdapterName());
if (existingMounts.get(fileShare.getName()) == null) {
String mountCmdArgs = sshApi.formatMountCmd(dataMover.getAdapterName(), fileShare.getName(), fileShare.getMountPath());
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_MOUNT_CMD, mountCmdArgs);
_log.info("filesystem mount is successful for filesystem: {} mount path: {}", fileShare.getName(), fileShare.getMountPath());
}
} else {
Exception e = new Exception("VNX File snapshot creation failed because suitable Data mover to mount the File System not found");
throw VNXException.exceptions.createExportFailed("VNX File Snapshot create is Failed", e);
}
updateAttributes(reqAttributeMap, system);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_NAME, fsName);
reqAttributeMap.put(VNXFileConstants.SNAPSHOT_NAME, snapshotName);
_provExecutor.setKeyMap(reqAttributeMap);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_CREATE_SNAP));
String cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (cmdResult != null && cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
String snapId = (String) _provExecutor.getKeyMap().get(VNXFileConstants.SNAPSHOT_ID);
String fsysId = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FILESYSTEM_ID);
if (snapId != null) {
int fsId = Integer.parseInt(fsysId);
int snId = Integer.parseInt(snapId);
VNXSnapshot vnxSnap = new VNXSnapshot(snapshotName, -1, fsId);
vnxSnap.setId(snId);
result.setObject(vnxSnap);
result.setCommandSuccess();
} else {
result.setCommandFailed();
result.setMessage((String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_MSG));
}
} else {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_MSG);
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 VNXFileCommApi method createFileSystem.
public XMLApiResult createFileSystem(final StorageSystem system, final String fileSys, final String pool, final String dataMover, final Long size, final boolean virtualProvisioning, final String nativeFsId, final Map autoAtts) throws VNXException {
_log.info("Create VNX File System: {} on data mover {}", fileSys, dataMover);
XMLApiResult result = new XMLApiResult();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
try {
updateAttributes(reqAttributeMap, system);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_NAME, fileSys);
reqAttributeMap.put(VNXFileConstants.MOUNT_PATH, "/" + fileSys);
reqAttributeMap.put(VNXFileConstants.POOL_NAME, pool);
reqAttributeMap.put(VNXFileConstants.FS_INIT_SIZE, size);
reqAttributeMap.put(VNXFileConstants.MOVER_ID, dataMover);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_VIRTUAL_PROVISIONING, virtualProvisioning);
_provExecutor.setKeyMap(reqAttributeMap);
String cmdResult = VNXFileConstants.CMD_SUCCESS;
// CHeck for FSId provided
// If provided query the array for the FSId in use
// If in use error out
// if not in use create the FS thin or thick
Boolean foundFSwithId = false;
if (null != nativeFsId && !nativeFsId.isEmpty()) {
String fileSysId = nativeFsId;
_log.info("Query file system query with id {}.", fileSysId);
_provExecutor.getKeyMap().put(VNXFileConstants.FILESYSTEM_ID, fileSysId);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FSIDQUERY_FILE));
cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
fileSysId = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FILESYSTEM_ID);
foundFSwithId = (Boolean) _provExecutor.getKeyMap().get(VNXFileConstants.IS_FILESYSTEM_AVAILABLE_ON_ARRAY);
}
if (foundFSwithId) {
_log.info("There is a FileSystem exist with the id {} so fail the create.", fileSysId);
result.setCommandFailed();
result.setMessage("File System creation failed because a File System with exist with id " + nativeFsId);
return result;
} else {
_log.info("There is no FileSystem with the id {} so proceed with create.", fileSysId);
}
} else {
_log.info("FileSystem Id provided is null or empty so we will use system generated id");
}
// calculate the thin fs allocation size
String thinProvFsSizeMBs = THIN_PROVISIONED_FS_SIZE_MB;
if (virtualProvisioning) {
thinProvFsSizeMBs = getThinFSAllocSize(size, true).toString();
}
// FileSystem doesnt exist on the array, so now create it
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
String createFSCmd = sshApi.formatCreateFS(fileSys, FILE_SYSTEM_TYPE_DEF, thinProvFsSizeMBs, size.toString(), pool, "", virtualProvisioning, nativeFsId);
_log.info("parsed createFSCmd {}.", createFSCmd);
result = sshApi.executeSshRetry(VNXFileSshApi.NAS_FS, createFSCmd);
if (!result.isCommandSuccess()) {
cmdResult = VNXFileConstants.CMD_FAILURE;
}
if (cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
String fileSysId = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FILESYSTEM_ID);
int fsId = 0;
if (null == fileSysId || fileSysId.isEmpty()) {
// Since there was no error but the file system id was not found, query for id again.
_log.info("Second file system create query.");
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FSIDQUERY_FILE));
cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
fileSysId = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FILESYSTEM_ID);
if (null != fileSysId && !fileSysId.isEmpty()) {
fsId = Integer.parseInt(fileSysId);
}
}
} else {
fsId = Integer.parseInt(fileSysId);
}
if (0 < fsId) {
_log.info("VNX File System create success! ID: {}", fsId);
String fsType = (String) autoAtts.get(FILE_SYSTEM_TYPE_ATTRIBUTE);
String worm = (String) autoAtts.get(WORM_ATTRIBUTE);
VNXFileSystem newFs = new VNXFileSystem(fileSys, -1, pool, fsType, worm, dataMover, Long.toString(size), autoAtts);
result.setCommandSuccess();
newFs.setFsId(fsId);
result.setObject(newFs);
} else {
result.setCommandFailed();
result.setMessage("File System creation failed");
}
} else {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
}
} catch (Exception e) {
throw VNXException.exceptions.createFileSystemFailed(e.getMessage());
}
return result;
}
use of com.emc.storageos.vnx.xmlapi.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileCommApi method deleteAllQuotaDirs.
private XMLApiResult deleteAllQuotaDirs(StorageSystem system, StorageHADomain dataMover, FileShare fs) {
XMLApiResult result = new XMLApiResult();
result.setCommandSuccess();
_log.info("deleteAllQuotaDirs for {}", fs.getName());
try {
// Process for quota dir delete on this file share.
List<TreeQuota> quotaDirs = (List<TreeQuota>) _provExecutor.getKeyMap().get(VNXFileConstants.QUOTA_DIR_LIST);
if (quotaDirs != null && !quotaDirs.isEmpty() && dataMover != null) {
_log.info("Number of quota dirs found {} for a file system {}", quotaDirs.size(), fs.getName());
// In the process of delete file system, we are unmounting the FileSystem.
// In order to delete Quota Directory, file system should be mounted.
// we just mount the file system temporarily. if it was un-mounted.
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
Map<String, String> existingMounts = sshApi.getFsMountpathMap(dataMover.getAdapterName());
if (existingMounts.get(fs.getName()) == null) {
String mountCmdArgs = sshApi.formatMountCmd(dataMover.getAdapterName(), fs.getName(), fs.getMountPath());
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_MOUNT_CMD, mountCmdArgs);
}
for (TreeQuota quota : quotaDirs) {
if (quota != null) {
// exclude the "/" in the beginning of the
String quotaDirName = quota.getPath().substring(1);
// path.
XMLApiResult status = deleteQuotaDirectory(system, fs.getName(), quotaDirName, true, false);
if (!status.isCommandSuccess()) {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
return result;
}
}
}
}
return result;
} catch (Exception e) {
throw new VNXException("File system quota directory delete exception: ", e);
}
}
use of com.emc.storageos.vnx.xmlapi.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileCommApi method deleteFileSystem.
public XMLApiResult deleteFileSystem(final StorageSystem system, final String fileId, final String fileSys, final boolean isForceDelete, FileShare fs) throws VNXException {
_log.info("Delete VNX File System: fs id {}, Force Delete {}", fileId, isForceDelete);
XMLApiResult result = new XMLApiResult();
if (null == fileId || null == fileSys || fileId.trim().equals("") || fileSys.trim().equals("")) {
result.setCommandFailed();
result.setMessage("Invalid Input Parameters.");
return result;
}
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
try {
updateAttributes(reqAttributeMap, system);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_NAME, fileSys);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_ID, fileId);
_provExecutor.setKeyMap(reqAttributeMap);
// Before deleting check whether it is available or not on the array - This need to be done as part of
// deleting un-managed FS.
_provExecutor.setKeyMap(reqAttributeMap);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FSIDQUERY_FILE_DELETE));
boolean isFsAvailable = false;
_log.debug("Listing VNX File File Systems");
String cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (null != cmdResult && cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
isFsAvailable = (Boolean) _provExecutor.getKeyMap().get(VNXFileConstants.IS_FILESYSTEM_AVAILABLE_ON_ARRAY);
}
if (!isFsAvailable) {
_log.debug("File System **Not found on array which requested to delete.");
result.setCommandSuccess();
// No need to set Inactive and persist here as this will be done in upper layer(FileDeviceController)
}
if (isForceDelete) {
// handle snapshots
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FS_FORCE_DEL_FILE));
cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
StorageHADomain dataMover = getDataMover(fs);
if (cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
List<Checkpoint> snaps = (List<Checkpoint>) _provExecutor.getKeyMap().get(VNXFileConstants.SNAPSHOTS_LIST);
int numSnapshots = (snaps != null) ? snaps.size() : 0;
_log.info("Number of Snapshots found {} for a file system {}", numSnapshots, fileId);
if (snaps != null && !snaps.isEmpty()) {
for (Checkpoint checkpoint : snaps) {
_log.info("Deleting Snapshot having name {} - and id {}", checkpoint.getName(), checkpoint.getCheckpoint());
String nativeGuid = NativeGUIDGenerator.getNativeGuidforSnapshot(system, system.getSerialNumber(), checkpoint.getCheckpoint());
_log.info("NativeGuid {} built for snapshot {}", nativeGuid, checkpoint.getCheckpoint());
Snapshot snapshot = null;
List<URI> snapShotUris = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotNativeGuidConstraint(nativeGuid));
_log.info("{} Snapshots found with native guid : {} ", snapShotUris.size(), nativeGuid);
if (!snapShotUris.isEmpty()) {
_log.info("Retriving Snapshot using URI : {} ", snapShotUris.get(0));
snapshot = _dbClient.queryObject(Snapshot.class, snapShotUris.get(0));
}
if (snapshot != null) {
result = deleteAllExportsAndShares(system, dataMover, fs, snapshot);
XMLApiResult status = doDeleteSnapshot(system, checkpoint.getCheckpoint(), checkpoint.getName(), false);
if (!status.isCommandSuccess()) {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
return result;
}
}
}
}
// Delete All Quota directories of FileShare.
result = deleteAllQuotaDirs(system, dataMover, fs);
// Delete Exports/SMB Shares of FileShare
result = deleteAllExportsAndShares(system, dataMover, fs, null);
} else {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
return result;
}
}
if (isFsAvailable) {
_log.debug("File System found on array which requested to delete. Now, deleting on Array.");
// First unmount it
StorageHADomain dataMover = getDataMover(fs);
if (dataMover != null) {
Map<String, String> existingMounts = sshApi.getFsMountpathMap(dataMover.getAdapterName());
// is FS mount still exists?
if (existingMounts.get(fs.getName()) != null) {
// The File system is mounted and we need to unmount it before deleting it
String unMountCmd = sshApi.formatUnMountCmd(dataMover.getAdapterName(), fs.getMountPath(), "NFS");
_log.info("Unmount FS {}", unMountCmd);
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, unMountCmd);
}
} else {
_log.info("No need to Unmount FS {} since there is no mount info", fs.getMountPath());
}
_provExecutor.setKeyMap(reqAttributeMap);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FSDEL_FILE));
cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (null != cmdResult && 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("File system delete exception: ", e);
}
return result;
}
Aggregations