use of com.emc.storageos.model.file.NfsACE 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.model.file.NfsACE 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.model.file.NfsACE 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.model.file.NfsACE in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method addStepsToReplicateNFSACLs.
/**
* Child workflow for replicating source file system NFS ACL to target system.
*
* @param systemTarget
* - URI of target StorageSystem where source CIFS shares has to be replicated.
* @param fsURI
* -URI of the source FileSystem
* @param taskId
*/
public void addStepsToReplicateNFSACLs(URI systemTarget, URI fsURI, String taskId) {
s_logger.info("Generating steps for Replicating NFS ACLs to Target Cluster");
FileNfsACLUpdateParams params = null;
FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
FileShare targetFileShare = null;
Workflow workflow = null;
try {
FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
} else {
targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
}
workflow = this._workflowService.getNewWorkflow(this, REPLICATE_NFS_ACLS_TO_TARGET_WF_NAME, false, taskId, completer);
Map<String, List<NfsACE>> sourceFSACLMap = FileOrchestrationUtils.queryNFSACL(sourceFileShare, s_dbClient);
Map<String, List<NfsACE>> targetFSACLMap = FileOrchestrationUtils.queryNFSACL(targetFileShare, s_dbClient);
if (!sourceFSACLMap.isEmpty() && targetFSACLMap.isEmpty()) {
// target share doesn't have any ACLs but corresponding share on source does have ACL
s_logger.info("Target NFS doesn't have any ACL but corresponding NFS on source does have ACL.");
for (String fsPath : sourceFSACLMap.keySet()) {
List<NfsACE> aclToAdd = null;
params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(fsPath, sourceFileShare);
aclToAdd = sourceFSACLMap.get(fsPath);
params.setAcesToAdd(aclToAdd);
s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
}
} else if (!targetFSACLMap.isEmpty() && sourceFSACLMap.isEmpty()) {
s_logger.info("Source NFS doesn't have any ACL but corresponding NFS on target has ACL.");
for (String fsPath : targetFSACLMap.keySet()) {
List<NfsACE> aclToDelete = null;
params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(fsPath, targetFileShare);
aclToDelete = targetFSACLMap.get(fsPath);
// TO FIX COP-26361 DU case
// params.setAcesToDelete(aclToDelete);
s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
}
} else if (!sourceFSACLMap.isEmpty() && !targetFSACLMap.isEmpty()) {
// both source and target FS have some ACL
for (String sourceFSACLPath : sourceFSACLMap.keySet()) {
List<NfsACE> aclToAdd = new ArrayList<NfsACE>();
List<NfsACE> aclToDelete = new ArrayList<NfsACE>();
List<NfsACE> aclToModify = new ArrayList<NfsACE>();
// Segregate source and target NFS ACL
params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(sourceFSACLPath, sourceFileShare);
List<NfsACE> sourceNFSACL = sourceFSACLMap.get(sourceFSACLPath);
if (sourceNFSACL == null) {
sourceNFSACL = new ArrayList<NfsACE>();
}
String subDir = params.getSubDir();
String targetFSACLPath = targetFileShare.getPath();
if (subDir != null) {
targetFSACLPath += "/" + subDir;
}
List<NfsACE> targetNFSACL = targetFSACLMap.get(targetFSACLPath);
if (targetNFSACL == null) {
targetNFSACL = new ArrayList<NfsACE>();
}
HashMap<String, NfsACE> sourceUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(sourceNFSACL);
HashMap<String, NfsACE> targetUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(targetNFSACL);
// ACL To Add
for (String sourceACEUser : sourceUserToNFSACLMap.keySet()) {
if (targetUserToNFSACLMap.get(sourceACEUser) == null) {
NfsACE nfsACE = sourceUserToNFSACLMap.get(sourceACEUser);
aclToAdd.add(nfsACE);
}
}
// ACL To Delete
for (String targetACEUser : targetUserToNFSACLMap.keySet()) {
if (sourceUserToNFSACLMap.get(targetACEUser) == null) {
aclToDelete.add(targetUserToNFSACLMap.get(targetACEUser));
}
}
// ACL to Modify
targetNFSACL.removeAll(aclToDelete);
sourceNFSACL.removeAll(aclToAdd);
sourceUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(sourceNFSACL);
targetUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(targetNFSACL);
for (String sourceACEUser : sourceUserToNFSACLMap.keySet()) {
NfsACE targetACE = targetUserToNFSACLMap.get(sourceACEUser);
NfsACE sourceACE = sourceUserToNFSACLMap.get(sourceACEUser);
if (targetACE != null && (!targetACE.getPermissions().equals(sourceACE.getPermissions()) || !targetACE.getPermissionType().equals(sourceACE.getPermissionType()))) {
targetACE.setPermissions(sourceACE.getPermissions());
targetACE.setPermissionType(sourceACE.getPermissionType());
aclToModify.add(targetACE);
}
}
if (!aclToAdd.isEmpty()) {
params.setAcesToAdd(aclToAdd);
}
if (!aclToDelete.isEmpty()) {
// TO FIX COP-26361 DU case
// params.setAcesToDelete(aclToDelete);
}
if (!aclToModify.isEmpty()) {
params.setAcesToModify(aclToModify);
}
if (!params.retrieveAllACL().isEmpty()) {
s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
}
}
}
String successMessage = String.format("Replicating source file system : %s, NFS ACL to target file system finished successfully", sourceFileShare.getLabel());
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error("Could not replicate source filesystem NFS ACL : " + fsURI, ex);
String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
ServiceError serviceError = DeviceControllerException.errors.updateFileShareNFSACLFailed(fsURI.toString(), opName, ex);
completer.error(s_dbClient, this._locker, serviceError);
}
}
use of com.emc.storageos.model.file.NfsACE in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method getUserToNFSACEMap.
public static HashMap<String, NfsACE> getUserToNFSACEMap(List<NfsACE> nfsACL) {
HashMap<String, NfsACE> aclMap = new HashMap<String, NfsACE>();
if (nfsACL != null && !nfsACL.isEmpty()) {
String user = null;
String domain = null;
for (NfsACE ace : nfsACL) {
domain = ace.getDomain();
user = ace.getUser();
user = domain == null ? "null+" + user : domain + "+" + user;
if (user != null && !user.isEmpty()) {
aclMap.put(user, ace);
}
}
}
return aclMap;
}
Aggregations