use of com.emc.storageos.model.file.NfsACE in project coprhd-controller by CoprHD.
the class NfsACLUtility method getNfsAclFromDB.
/**
* This function return all the ACL in the DB in the format of xml Object
*
* @param allDirs if true function will return complete list of ACL including its SubDir
* @return list of NFS ACLs.
*/
public NfsACLs getNfsAclFromDB(boolean allDirs) {
NfsACLs acls = new NfsACLs();
List<NfsACL> nfsAclList = new ArrayList<NfsACL>();
Map<String, List<NfsACE>> nfsAclMap = new HashMap<String, List<NfsACE>>();
_log.info("Sub-directory {} and allDirs {}", this.subDir, allDirs);
// Query All ACl Specific to a File System.
List<NFSShareACL> nfsAcls = queryDBSFileNfsACLs(allDirs);
_log.info("Number of existing ACL found : {} ", nfsAcls.size());
// Group the ACLs based on file system path!!!
for (NFSShareACL nfsAcl : nfsAcls) {
String fsPath = nfsAcl.getFileSystemPath();
List<NfsACE> nfsAceList = nfsAclMap.get(fsPath);
if (nfsAceList == null) {
nfsAceList = new ArrayList<NfsACE>();
}
NfsACE ace = getNFSAce(nfsAcl);
nfsAceList.add(ace);
nfsAclMap.put(fsPath, nfsAceList);
}
// Convert all ACE to ACLs!!
for (Map.Entry<String, List<NfsACE>> pathAcls : nfsAclMap.entrySet()) {
String mountPath = pathAcls.getKey();
NfsACL nfsAcl = new NfsACL(mountPath, pathAcls.getValue());
if (mountPath.length() > fs.getPath().length()) {
nfsAcl.setSubDir(mountPath.substring(fs.getPath().length() + 1));
}
nfsAclList.add(nfsAcl);
}
if (!nfsAclList.isEmpty()) {
acls.setNfsACLs(nfsAclList);
}
return acls;
}
use of com.emc.storageos.model.file.NfsACE in project coprhd-controller by CoprHD.
the class NfsACLUtility method getNFSAce.
/**
* This function is to convert DB object into NfsACE object
*
* @param orig provided DB object
* @return the REST representation of NFS ACE
*/
private NfsACE getNFSAce(NFSShareACL orig) {
NfsACE dest = new NfsACE();
dest.setDomain(orig.getDomain());
dest.setPermissions(orig.getPermissions());
dest.setPermissionType(FileControllerConstants.NFS_FILE_PERMISSION_TYPE_ALLOW);
if (orig.getPermissionType() != null && !orig.getPermissionType().isEmpty()) {
dest.setPermissionType(orig.getPermissionType());
}
dest.setType(REQUEST_PARAM_USER);
if (orig.getType() != null && !orig.getType().isEmpty()) {
dest.setType(orig.getType());
}
dest.setUser(orig.getUser());
return dest;
}
use of com.emc.storageos.model.file.NfsACE in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method updateNfsACLs.
@Override
public BiosCommandResult updateNfsACLs(StorageSystem storage, FileDeviceInputOutput args) {
try {
// read nameToSid flag from controller config.
Boolean sidEnable = customConfigHandler.getComputedCustomConfigBooleanValue(CustomConfigConstants.ISILON_USER_TO_SID_MAPPING_FOR_NFS_ENABLED, storage.getSystemType(), null);
// get sid mapping based on Controller config and it belong to VirtualNAS.
if (sidEnable && args.getvNAS() != null) {
updateSidInfoForNfsACE(args, storage);
}
IsilonNFSACL isilonAcl = new IsilonNFSACL();
ArrayList<Acl> aclCompleteList = new ArrayList<Acl>();
List<NfsACE> aceToAdd = args.getNfsAclsToAdd();
for (NfsACE nfsACE : aceToAdd) {
Acl acl = getIsilonAclFromNfsACE(nfsACE);
acl.setOp("add");
aclCompleteList.add(acl);
}
List<NfsACE> aceToModify = args.getNfsAclsToModify();
for (NfsACE nfsACE : aceToModify) {
Acl acl = getIsilonAclFromNfsACE(nfsACE);
acl.setOp("replace");
aclCompleteList.add(acl);
}
List<NfsACE> aceToDelete = args.getNfsAclsToDelete();
for (NfsACE nfsACE : aceToDelete) {
Acl acl = getIsilonAclFromNfsACE(nfsACE);
acl.setOp("delete");
aclCompleteList.add(acl);
}
isilonAcl.setAction("update");
isilonAcl.setAuthoritative("acl");
isilonAcl.setAcl(aclCompleteList);
String path = args.getFileSystemPath();
if (args.getSubDirectory() != null && !args.getSubDirectory().isEmpty()) {
path = path + "/" + args.getSubDirectory();
}
// Process new ACLs
IsilonApi isi = getIsilonDevice(storage);
_log.info("Calling Isilon API: modify NFS Acl for {}, acl {}", args.getFileSystemPath(), isilonAcl);
isi.modifyNFSACL(path, isilonAcl);
_log.info("End updateNfsACLs");
BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
return result;
} catch (IsilonException e) {
_log.error("updateNfsACLs failed ", e);
return BiosCommandResult.createErrorResult(e);
} catch (Exception e) {
_log.error("updateNfsACLs failed ", e);
final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL.toString(), e.getMessage());
return BiosCommandResult.createErrorResult(serviceCoded);
}
}
use of com.emc.storageos.model.file.NfsACE in project coprhd-controller by CoprHD.
the class FileSystems method saveNfsAce.
@FlashException(referrer = { "fileSystem" })
public static void saveNfsAce(NfsACLForm nfsACL) {
String name = params.get("name");
String type = params.get("type");
String domain = params.get("domain");
String subDir = params.get("subDir");
String fsMountPath = params.get("fsMountPath");
String fileSystemId = params.get("fileSystemId");
Set<String> permissions = nfsACL.permissions;
String permissionType = nfsACL.permissionType;
String strPer = "";
nfsACL.validate("nfsACL");
if (Validation.hasErrors()) {
Common.handleError();
}
for (String permission : permissions) {
strPer = strPer + permission.toLowerCase() + ",";
}
strPer = strPer.substring(0, strPer.length() - 1);
List<NfsACE> aces = Lists.newArrayList();
NfsACE nfsAce = new NfsACE();
nfsAce.setType(type.toLowerCase());
nfsAce.setUser(name);
nfsAce.setPermissions(strPer);
nfsAce.setPermissionType(permissionType);
if (domain != null && !"".equals(domain) && !"null".equals(domain)) {
nfsAce.setDomain(domain);
}
aces.add(nfsAce);
FileNfsACLUpdateParams input = new FileNfsACLUpdateParams();
input.setAcesToModify(aces);
if (subDir != null && !"null".equals(subDir)) {
input.setSubDir(subDir);
}
ViPRCoreClient client = BourneUtil.getViprClient();
client.fileSystems().updateNfsACL(uri(fileSystemId), input);
listNfsAcl(fileSystemId, fsMountPath, subDir);
}
use of com.emc.storageos.model.file.NfsACE in project coprhd-controller by CoprHD.
the class FileSystems method createNfsAclParams.
private static FileNfsACLUpdateParams createNfsAclParams(String formData) {
String[] uiAcls = formData.split(",");
List<NfsACE> aces = Lists.newArrayList();
for (String uiAce : uiAcls) {
String[] uiData = uiAce.split("~~~");
String uiType = uiData[0];
String uiName = uiData[1];
String uiDomain = uiData[2];
String uiPermissions = uiData[3];
String uiPermissiontype = uiData[4];
NfsACE nfsAce = new NfsACE();
nfsAce.setUser(uiName);
if (uiDomain != null && !"".equals(uiDomain) && !"null".equals(uiDomain)) {
nfsAce.setDomain(uiDomain);
}
if (uiType != null && !"".equals(uiType) && !"null".equals(uiType)) {
nfsAce.setType(uiType);
}
if (uiPermissions != null && !"".equals(uiPermissions) && !"null".equals(uiPermissions)) {
nfsAce.setPermissions(uiPermissions.replaceAll("/", ","));
}
nfsAce.setPermissionType(uiPermissiontype);
aces.add(nfsAce);
}
FileNfsACLUpdateParams input = new FileNfsACLUpdateParams();
input.setAcesToAdd(aces);
return input;
}
Aggregations