Search in sources :

Example 66 with FileShare

use of com.emc.storageos.db.client.model.FileShare 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 67 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileService method getQuotaDirectoryList.

/**
 * Get list of quota directories for the specified file system.
 *
 * @param id
 *            the URN of a ViPR File system
 * @brief List file system quota directories
 * @return List of file system quota directories.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/quota-directories")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public QuotaDirectoryList getQuotaDirectoryList(@PathParam("id") URI id) {
    _log.info(String.format("Get list of quota directories for file system: %1$s", id));
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fileShare = queryResource(id);
    QuotaDirectoryList quotaDirList = new QuotaDirectoryList();
    if (fileShare.getInactive()) {
        return quotaDirList;
    }
    // Get SMB share map from file system
    List<QuotaDirectory> quotaDirs = queryDBQuotaDirectories(fileShare);
    // Process each share from the map and add its data to shares in response list.
    for (QuotaDirectory quotaDir : quotaDirs) {
        quotaDirList.getQuotaDirs().add(toNamedRelatedResource(quotaDir));
    }
    return quotaDirList;
}
Also used : QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) 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)

Example 68 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileSnapshotService method deleteSnapshotShareACL.

/**
 * Delete Snapshot Share ACL
 *
 * @param id
 *            the file system URI
 * @param shareName
 *            name of the share
 * @brief Delete a snapshot ACL
 * @return TaskResponse
 */
@DELETE
@Path("/{id}/shares/{shareName}/acl")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteSnapshotShareACL(@PathParam("id") URI id, @PathParam("shareName") String shareName) {
    // log input received.
    _log.info("Delete ACL of share: Request received for {}, of file snapshot {}", shareName, id);
    String taskId = UUID.randomUUID().toString();
    // Validate the snapshot id.
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    ArgValidator.checkFieldNotNull(shareName, "shareName");
    Snapshot snapshot = queryResource(id);
    ArgValidator.checkEntity(snapshot, id, isIdEmbeddedInURL(id));
    if (!CifsShareUtility.doesShareExist(snapshot, shareName)) {
        _log.error("CIFS share does not exist {}", shareName);
        throw APIException.notFound.invalidParameterObjectHasNoSuchShare(snapshot.getId(), shareName);
    }
    FileShare fs = _permissionsHelper.getObjectById(snapshot.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    CifsShareUtility.checkForUpdateShareACLOperationOnStorage(device.getSystemType(), OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE_ACL.name());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE_ACL);
    op.setDescription("Delete ACL of Snapshot Cifs share");
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.deleteShareACLs(device.getId(), snapshot.getId(), shareName, taskId);
    auditOp(OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE_ACL, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), device.getId().toString(), shareName);
    return toTask(snapshot, taskId, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 69 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileSnapshotService method share.

/**
 * Creates SMB file share.
 * <p>
 * Note: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @param param
 *            File system share parameters
 * @brief Create file snapshot SMB share
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep share(@PathParam("id") URI id, FileSystemShareParam param) throws InternalException {
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    ArgValidator.checkFieldNotNull(param.getShareName(), "name");
    ArgValidator.checkFieldNotEmpty(param.getShareName(), "name");
    Snapshot snap = queryResource(id);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    ArgValidator.checkEntity(snap, id, isIdEmbeddedInURL(id));
    // Let us make sure that a share with the same name does not already exist.
    String shareName = param.getShareName();
    if (CifsShareUtility.doesShareExist(snap, shareName)) {
        _log.error("CIFS share: {}, already exists", shareName);
        throw APIException.badRequests.duplicateEntityWithField("CIFS share", "name");
    }
    // If value of permission is not provided, set the value to read-only
    if (param.getPermission() == null || param.getPermission().isEmpty()) {
        param.setPermission(FileSMBShare.Permission.read.name());
    }
    if (!param.getPermission().equals(FileSMBShare.Permission.read.name())) {
        throw APIException.badRequests.snapshotSMBSharePermissionReadOnly();
    }
    // Locate storage port for sharing snapshot
    // Select IP port of the storage array, owning the parent file system, which belongs to the same varray as the
    // file system.
    // We use file system in the call since file snap belongs to the same neighbourhood as its parent file system
    StoragePort sport = _fileScheduler.placeFileShareExport(fs, StorageProtocol.File.CIFS.name(), null);
    // Check if maxUsers is "unlimited" and set it to -1 in this case.
    if (param.getMaxUsers().equalsIgnoreCase(FileService.UNLIMITED_USERS)) {
        param.setMaxUsers("-1");
    }
    String path = snap.getPath();
    _log.info("Path {}", path);
    _log.info("Param Share Name : {} SubDirectory : {}", param.getShareName(), param.getSubDirectory());
    boolean isSubDirPath = false;
    if (ArgValidator.checkSubDirName("subDirectory", param.getSubDirectory())) {
        path += "/" + param.getSubDirectory();
        isSubDirPath = true;
        _log.info("Sub-directory path {}", path);
    }
    FileSMBShare smbShare = new FileSMBShare(param.getShareName(), param.getDescription(), param.getPermissionType(), param.getPermission(), param.getMaxUsers(), null, path);
    smbShare.setStoragePortName(sport.getPortName());
    smbShare.setStoragePortNetworkId(sport.getPortNetworkId());
    smbShare.setStoragePortGroup(sport.getPortGroup());
    smbShare.setSubDirPath(isSubDirPath);
    _log.info(String.format("Create snapshot share --- Snap id: %1$s, Share name: %2$s, StoragePort: %3$s, PermissionType: %4$s, " + "Permissions: %5$s, Description: %6$s, maxUsers: %7$s", id, smbShare.getName(), sport.getPortName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getDescription(), smbShare.getMaxUsers()));
    _log.info("SMB share path: {}", smbShare.getPath());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE);
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.share(device.getId(), snap.getId(), smbShare, task);
    auditOp(OperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE, true, AuditLogManager.AUDITOP_BEGIN, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), snap.getId().toString());
    return toTask(snap, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileController(com.emc.storageos.volumecontroller.FileController) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 70 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class AbstractFileServiceApiImpl method reduceFileShareQuota.

/**
 * Reduce fileshare provision capacity
 * @param fileshare file share object
 * @param newSize - new fileshare size
 * @param taskId - task id
 * return
 */
@Override
public void reduceFileShareQuota(FileShare fileshare, Long newSize, String taskId) throws InternalException {
    FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
    final List<FileDescriptor> fileDescriptors = new ArrayList<FileDescriptor>();
    if (fileshare.getParentFileShare() != null && fileshare.getPersonality().equals(FileShare.PersonalityTypes.TARGET.name())) {
        throw APIException.badRequests.reduceMirrorFileSupportedOnlyOnSource(fileshare.getId());
    } else {
        List<String> targetfileUris = new ArrayList<String>();
        // if filesystem is target then throw exception
        if (fileshare.getMirrorfsTargets() != null && !fileshare.getMirrorfsTargets().isEmpty()) {
            targetfileUris.addAll(fileshare.getMirrorfsTargets());
        }
        FileDescriptor descriptor = new FileDescriptor(FileDescriptor.Type.FILE_DATA, fileshare.getStorageDevice(), fileshare.getId(), fileshare.getPool(), "", false, newSize);
        fileDescriptors.add(descriptor);
        // Prepare the descriptor for targets
        for (String target : targetfileUris) {
            FileShare targetFileShare = _dbClient.queryObject(FileShare.class, URI.create(target));
            descriptor = new FileDescriptor(FileDescriptor.Type.FILE_DATA, targetFileShare.getStorageDevice(), targetFileShare.getId(), targetFileShare.getPool(), "", false, newSize);
            fileDescriptors.add(descriptor);
        }
    }
    // place the reduce filesystem call in queue
    controller.reduceFileSystem(fileDescriptors, taskId);
}
Also used : FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) ArrayList(java.util.ArrayList) FileShare(com.emc.storageos.db.client.model.FileShare) FileDescriptor(com.emc.storageos.fileorchestrationcontroller.FileDescriptor)

Aggregations

FileShare (com.emc.storageos.db.client.model.FileShare)289 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 URI (java.net.URI)93 ArrayList (java.util.ArrayList)79 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)73 ControllerException (com.emc.storageos.volumecontroller.ControllerException)65 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)61 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)57 Operation (com.emc.storageos.db.client.model.Operation)56 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)56 URISyntaxException (java.net.URISyntaxException)56 Path (javax.ws.rs.Path)56 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)52 Produces (javax.ws.rs.Produces)51 Snapshot (com.emc.storageos.db.client.model.Snapshot)50 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)49 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)45 WorkflowException (com.emc.storageos.workflow.WorkflowException)42 NamedURI (com.emc.storageos.db.client.model.NamedURI)36