Search in sources :

Example 1 with NfsACLs

use of com.emc.storageos.model.file.NfsACLs 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;
}
Also used : NfsACLs(com.emc.storageos.model.file.NfsACLs) NfsACL(com.emc.storageos.model.file.NfsACL) NfsACE(com.emc.storageos.model.file.NfsACE) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL)

Example 2 with NfsACLs

use of com.emc.storageos.model.file.NfsACLs in project coprhd-controller by CoprHD.

the class FileSystems method getNfsACLs.

/**
 * Gets the NFS ACLs for the given file system by ID.
 * <p>
 * API Call: <tt>GET /file/filesystems/{id}/acl?subDir=subDirId</tt>
 *
 * @param id
 *            the ID of the file system.
 * @param subDir
 *            the subDir to get list of ACLS associated.
 * @return the list of NFS ACLs for the given file system.
 */
public List<NfsACL> getNfsACLs(URI id, String subDir) {
    Properties queryParam = new Properties();
    NfsACLs response;
    if (subDir != null && !"null".equals(subDir)) {
        queryParam.setProperty("subDir", subDir);
        response = client.get(NfsACLs.class, getNfsACLsUrl(), queryParam, id);
    } else {
        response = client.get(NfsACLs.class, getNfsACLsUrl(), id);
    }
    return defaultList(response.getNfsACLs());
}
Also used : NfsACLs(com.emc.storageos.model.file.NfsACLs) Properties(java.util.Properties)

Example 3 with NfsACLs

use of com.emc.storageos.model.file.NfsACLs in project coprhd-controller by CoprHD.

the class FileSystems method getAllNfsACLs.

/**
 * Gets the all NFS ACLs for the given file system by ID.
 * <p>
 * API Call: <tt>GET /file/filesystems/{id}/acl?allDir=true</tt>
 *
 * @param id
 *            the ID of the file system.
 *
 * @return the list of NFS ACLs for the given file system.
 */
public List<NfsACL> getAllNfsACLs(URI id) {
    Properties queryParam = new Properties();
    queryParam.setProperty("allDirs", "true");
    NfsACLs response = client.get(NfsACLs.class, getNfsACLsUrl(), queryParam, id);
    return defaultList(response.getNfsACLs());
}
Also used : NfsACLs(com.emc.storageos.model.file.NfsACLs) Properties(java.util.Properties)

Example 4 with NfsACLs

use of com.emc.storageos.model.file.NfsACLs in project coprhd-controller by CoprHD.

the class FileService method getFileShareACLs.

/**
 * GET all ACLs for a fileSystem
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param allDirs
 *            all directory within a fileSystem
 * @param subDir
 *            sub-directory within a fileSystem
 * @brief List the ACLs for a file system
 * @return list of ACLs for file system.
 * @throws InternalException
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/acl")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public NfsACLs getFileShareACLs(@PathParam("id") URI id, @QueryParam("allDirs") boolean allDirs, @QueryParam("subDir") String subDir) {
    _log.info("Request recieved for Acl  with Id : {}  allDirs : {} subDir : {}", new Object[] { id, allDirs, subDir });
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    // Check for VirtualPool whether it has NFS v4 enabled
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    if (!vpool.getProtocols().contains(StorageProtocol.File.NFSv4.name())) {
        // Throw an error
        throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool does not support " + StorageProtocol.File.NFSv4.name() + " protocol");
    }
    // Get All ACLs of FS from data base and group them based on path!!
    NfsACLUtility util = new NfsACLUtility(_dbClient, fs, null, subDir);
    NfsACLs acls = util.getNfsAclFromDB(allDirs);
    if (acls.getNfsACLs() != null && !acls.getNfsACLs().isEmpty()) {
        _log.info("Found {} Acl rules for filesystem {}", acls.getNfsACLs().size(), fs.getId());
    } else {
        _log.info("No Acl rules found for filesystem  {}", fs.getId());
    }
    return acls;
}
Also used : NfsACLs(com.emc.storageos.model.file.NfsACLs) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NfsACLUtility(com.emc.storageos.api.service.impl.resource.utils.NfsACLUtility) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

NfsACLs (com.emc.storageos.model.file.NfsACLs)4 Properties (java.util.Properties)2 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)1 NfsACLUtility (com.emc.storageos.api.service.impl.resource.utils.NfsACLUtility)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 NFSShareACL (com.emc.storageos.db.client.model.NFSShareACL)1 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 NfsACE (com.emc.storageos.model.file.NfsACE)1 NfsACL (com.emc.storageos.model.file.NfsACL)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1