use of com.emc.storageos.vnx.xmlapi.VNXException 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.VNXException 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.VNXException 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