Search in sources :

Example 1 with NfsACLUtility

use of com.emc.storageos.api.service.impl.resource.utils.NfsACLUtility in project coprhd-controller by CoprHD.

the class FileService method updateFileSystemAcls.

/**
 * Update existing file system ACL
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param param
 *            FileNfsACLUpdateParams
 * @brief Update file system ACL
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/acl")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateFileSystemAcls(@PathParam("id") URI id, FileNfsACLUpdateParams param) throws InternalException {
    // log input received.
    _log.info("Update FS ACL : request received for {}  with {}", id, param);
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(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");
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    String task = UUID.randomUUID().toString();
    String path = fs.getPath();
    _log.info("fileSystem  path {} ", path);
    Operation op = new Operation();
    try {
        _log.info("Sub Dir Provided {}", param.getSubDir());
        // Validate the input
        NfsACLUtility util = new NfsACLUtility(_dbClient, fs, null, param.getSubDir());
        util.verifyNfsACLs(param);
        _log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, param });
        op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL);
        op.setDescription("Filesystem NFS ACL update");
        controller.updateNFSAcl(device.getId(), fs.getId(), param, task);
        auditOp(OperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), param);
    } catch (BadRequestException e) {
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error Processing File System ACL Updates {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Error Processing File System ACL Updates  {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return toTask(fs, task, op);
}
Also used : FileController(com.emc.storageos.volumecontroller.FileController) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with NfsACLUtility

use of com.emc.storageos.api.service.impl.resource.utils.NfsACLUtility 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

MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)2 NfsACLUtility (com.emc.storageos.api.service.impl.resource.utils.NfsACLUtility)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)2 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Operation (com.emc.storageos.db.client.model.Operation)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 NfsACLs (com.emc.storageos.model.file.NfsACLs)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 FileController (com.emc.storageos.volumecontroller.FileController)1 URISyntaxException (java.net.URISyntaxException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1