use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.
the class FileDeviceController method makeNfsAceFromDB.
/**
* Convert list of NfsACE to list of DB object for ACL
*
* @param nfsAcls
* list of the NfsACE object
* @param dbNfsAclTemp
* converted DB object List
*/
private void makeNfsAceFromDB(List<NfsACE> nfsAcls, List<NFSShareACL> dbNfsAclTemp) {
for (NFSShareACL nfsShareACL : dbNfsAclTemp) {
NfsACE nfsAce = new NfsACE();
String permission = nfsShareACL.getPermissions();
if (permission != null && !permission.isEmpty()) {
nfsAce.setPermissions(permission);
}
String domain = nfsShareACL.getDomain();
if (domain != null && !domain.isEmpty()) {
nfsAce.setDomain(domain);
}
String permissionType = nfsShareACL.getPermissionType();
nfsAce.setPermissionType(FileControllerConstants.NFS_FILE_PERMISSION_TYPE_ALLOW);
if (permissionType != null && !permissionType.isEmpty()) {
nfsAce.setPermissionType(permissionType);
}
String type = nfsShareACL.getType();
if (type != null && !type.isEmpty()) {
nfsAce.setType(type);
}
String user = nfsShareACL.getUser();
if (user != null && !user.isEmpty()) {
nfsAce.setUser(user);
}
nfsAcls.add(nfsAce);
}
}
use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.
the class FileDeviceController method deleteNFSAcls.
@Override
public void deleteNFSAcls(URI storage, URI fsURI, String subDir, String opId) throws InternalException {
ControllerUtils.setThreadLocalLogData(fsURI, opId);
FileObject fsObj = null;
FileDeviceInputOutput args = new FileDeviceInputOutput();
FileShare fs = null;
Snapshot snapshotObj = null;
boolean isFile = false;
try {
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
args.setSubDirectory(subDir);
_log.info("FileDeviceController::deleteNFSAcls Recieved Nfs ACL DELETE Operation ");
// File
if (URIUtil.isType(fsURI, FileShare.class)) {
isFile = true;
fs = _dbClient.queryObject(FileShare.class, fsURI);
fsObj = fs;
args.addFSFileObject(fs);
args.setFileSystemPath(fs.getPath());
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
} else {
// Snapshot
snapshotObj = _dbClient.queryObject(Snapshot.class, fsURI);
fsObj = snapshotObj;
fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
args.addFileShare(fs);
args.setFileSystemPath(fs.getPath());
args.addSnapshotFileObject(snapshotObj);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
}
args.setFileOperation(isFile);
args.setOpId(opId);
List<NfsACE> aceDeleteList = new ArrayList<NfsACE>();
List<NFSShareACL> dbNfsAclTemp = queryAllNfsACLInDB(fs, subDir, args);
makeNfsAceFromDB(aceDeleteList, dbNfsAclTemp);
args.setNfsAclsToDelete(aceDeleteList);
// Do the Operation on device.
BiosCommandResult result = getDevice(storageObj.getSystemType()).deleteNfsACLs(storageObj, args);
if (result.isCommandSuccess()) {
// Update Database
if (!dbNfsAclTemp.isEmpty()) {
for (NFSShareACL nfsShareACL : dbNfsAclTemp) {
nfsShareACL.setInactive(true);
}
_dbClient.updateObject(dbNfsAclTemp);
}
}
if (result.getCommandPending()) {
return;
}
// Audit & Update the task status
OperationTypeEnum auditType = null;
auditType = (isFile) ? OperationTypeEnum.DELETE_FILE_SYSTEM_NFS_ACL : OperationTypeEnum.DELETE_FILE_SNAPSHOT_NFS_ACL;
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
// Monitoring - Event Processing
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
if (isFile) {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), fs, storageObj);
} else {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), snapshotObj, fs, storageObj);
}
_dbClient.updateObject(fsObj);
} catch (Exception e) {
String[] params = { storage.toString(), fsURI.toString() };
_log.error("Unable to Delete ACL on file system or snapshot: storage {}, FS/snapshot URI {}", params, e);
_log.error("{}, {} ", e.getMessage(), e);
updateTaskStatus(opId, fsObj, e);
}
}
use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.
the class FileDeviceController method updateNFSACLsInDB.
/**
* Update the DB object, this method need to be called after the success of
* back end command
*
* @param param
* object of NfsACLUpdateParams
* @param fs
* FileShare object
* @param args
* FileDeviceInputOutput object
*/
private void updateNFSACLsInDB(NfsACLUpdateParams param, FileShare fs, FileDeviceInputOutput args) {
try {
// Create new Acls
List<NfsACE> aceAdd = param.getAcesToAdd();
if (aceAdd != null && !aceAdd.isEmpty()) {
for (NfsACE ace : aceAdd) {
NFSShareACL dbNfsAcl = new NFSShareACL();
dbNfsAcl.setId(URIUtil.createId(NFSShareACL.class));
copyToPersistNfsACL(ace, dbNfsAcl, fs, args);
_log.info("Storing new acl in DB: {}", dbNfsAcl);
_dbClient.createObject(dbNfsAcl);
}
}
// Modify existing acls
List<NfsACE> aceModify = param.getAcesToModify();
if (aceModify != null && !aceModify.isEmpty()) {
for (NfsACE ace : aceModify) {
NFSShareACL dbNfsAcl = new NFSShareACL();
copyToPersistNfsACL(ace, dbNfsAcl, fs, args);
NFSShareACL dbNfsAclTemp = getExistingNfsAclFromDB(dbNfsAcl, args.getFileOperation());
if (dbNfsAclTemp != null) {
dbNfsAcl.setId(dbNfsAclTemp.getId());
_log.info("Modifying acl in DB: {}", dbNfsAcl);
_dbClient.updateObject(dbNfsAcl);
}
}
}
List<NfsACE> aceDelete = param.getAcesToDelete();
if (aceDelete != null && !aceDelete.isEmpty()) {
for (NfsACE ace : aceDelete) {
NFSShareACL dbNfsAcl = new NFSShareACL();
copyToPersistNfsACL(ace, dbNfsAcl, fs, args);
NFSShareACL dbNfsAclTemp = getExistingNfsAclFromDB(dbNfsAcl, args.getFileOperation());
if (dbNfsAclTemp != null) {
dbNfsAcl.setId(dbNfsAclTemp.getId());
dbNfsAcl.setInactive(true);
_log.info("Marking acl inactive in DB: {}", dbNfsAcl);
_dbClient.updateObject(dbNfsAcl);
}
}
}
} catch (Exception e) {
_log.error("Error While executing CRUD Operations {}", e);
}
}
use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.
the class FileDeviceController method getExistingNfsAclFromDB.
/**
* Get the DB object to modify it
*
* @param dbShareAcl
* the DB object which need to be searched
* @param isFile
* it is file or snapshot operation
* @return
*/
private NFSShareACL getExistingNfsAclFromDB(NFSShareACL dbShareAcl, boolean isFile) {
NFSShareACL acl = null;
String index = null;
URIQueryResultList result = new URIQueryResultList();
if (isFile) {
index = dbShareAcl.getFileSystemNfsACLIndex();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileSystemNfsACLConstraint(index), result);
} else {
index = dbShareAcl.getSnapshotNfsACLIndex();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotNfsACLConstraint(index), result);
}
Iterator<URI> it = result.iterator();
while (it.hasNext()) {
acl = _dbClient.queryObject(NFSShareACL.class, it.next());
if (acl != null && !acl.getInactive()) {
_log.info("Existing ACE found in DB: {}", acl);
return acl;
}
}
return null;
}
use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.
the class FileDeviceController method queryAllNfsACLInDB.
/**
* To get all the ACLs of File System or a mention subDir.
*
* @param fs
* File System
* @param subDir
* Sub directory
* @return List of NFS ACL present in DB.
*/
private List<NFSShareACL> queryAllNfsACLInDB(FileShare fs, String subDir, FileDeviceInputOutput args) {
List<NFSShareACL> allNfsShareAcl = null;
List<NFSShareACL> returnNfsShareAcl = null;
List<NFSShareACL> fsNfsShareAcl = new ArrayList<NFSShareACL>();
List<NFSShareACL> subDirNfsShareAcl = new ArrayList<NFSShareACL>();
_log.info("Querying all Nfs File System ACL Using FsId {}", fs.getId());
try {
ContainmentConstraint containmentConstraint = null;
if (args.getFileOperation()) {
containmentConstraint = ContainmentConstraint.Factory.getFileNfsAclsConstraint(fs.getId());
} else {
containmentConstraint = ContainmentConstraint.Factory.getSnapshotNfsAclsConstraint(args.getSnapshotId());
}
allNfsShareAcl = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, NFSShareACL.class, containmentConstraint);
} catch (Exception e) {
_log.error("Error while querying {}", e);
}
returnNfsShareAcl = fsNfsShareAcl;
String absolutefsPath = fs.getPath();
String absoluteDirPath = "";
if (subDir != null && !subDir.isEmpty()) {
absoluteDirPath = absolutefsPath + "/" + subDir;
returnNfsShareAcl = subDirNfsShareAcl;
}
for (NFSShareACL nfsAcl : allNfsShareAcl) {
if (nfsAcl.getFileSystemPath().equals(absoluteDirPath)) {
subDirNfsShareAcl.add(nfsAcl);
} else if (nfsAcl.getFileSystemPath().equals(absolutefsPath)) {
fsNfsShareAcl.add(nfsAcl);
}
}
return returnNfsShareAcl;
}
Aggregations