Search in sources :

Example 6 with FileExport

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

the class FileService method export.

/**
 * Export file system.
 *
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param param
 *            File system export parameters
 * @param id
 *            the URN of a ViPR File system
 * @brief Create file export
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep export(@PathParam("id") URI id, FileSystemExportParam param) throws InternalException {
    _log.info("Export request recieved {}", id);
    // check file System
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    ArgValidator.checkFieldValueFromEnum(param.getPermissions(), "permissions", EnumSet.allOf(FileShareExport.Permissions.class));
    _log.info("Export security type {}", param.getSecurityType());
    for (String sectype : param.getSecurityType().split(",")) {
        ArgValidator.checkFieldValueFromEnum(sectype.trim(), "type", EnumSet.allOf(FileShareExport.SecurityTypes.class));
    }
    ArgValidator.checkFieldValueFromEnum(param.getProtocol(), "protocol", EnumSet.allOf(StorageProtocol.File.class));
    validateIpInterfacesRegistered(param.getEndpoints(), _dbClient);
    FileShare fs = queryResource(id);
    String task = UUID.randomUUID().toString();
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    // Check for VirtualPool whether it has NFS enabled
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    if (!vpool.getProtocols().contains(StorageProtocol.File.NFS.name()) && !vpool.getProtocols().contains(StorageProtocol.File.NFSv4.name())) {
        // Throw an error
        throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool doesn't support " + StorageProtocol.File.NFS.name() + " or " + StorageProtocol.File.NFSv4 + " protocol");
    }
    // locate storage port for exporting file System
    StoragePort sport = _fileScheduler.placeFileShareExport(fs, param.getProtocol(), param.getEndpoints());
    String path = fs.getPath();
    String mountPath = fs.getMountPath();
    String subDirectory = param.getSubDirectory();
    if (ArgValidator.checkSubDirName("sub_directory", param.getSubDirectory())) {
        // Add subdirectory to the path as this is a subdirectory export
        path += "/" + param.getSubDirectory();
        mountPath += "/" + param.getSubDirectory();
    }
    FSExportMap exportMap = fs.getFsExports();
    if (exportMap != null) {
        Iterator it = fs.getFsExports().keySet().iterator();
        boolean exportExists = false;
        while (it.hasNext()) {
            String fsExpKey = (String) it.next();
            FileExport fileExport = fs.getFsExports().get(fsExpKey);
            if (fileExport.getPath().equalsIgnoreCase(path)) {
                exportExists = true;
                break;
            }
        }
        if (exportExists) {
            throw APIException.badRequests.fileSystemHasExistingExport();
        }
    }
    String rootUserMapping = param.getRootUserMapping();
    if (rootUserMapping != null) {
        rootUserMapping = rootUserMapping.toLowerCase();
    }
    // check for bypassDnsCheck flag. If null then set to false
    Boolean dnsCheck = param.getBypassDnsCheck();
    if (dnsCheck == null) {
        dnsCheck = false;
    }
    FileShareExport export = new FileShareExport(param.getEndpoints(), param.getSecurityType(), param.getPermissions(), rootUserMapping, param.getProtocol(), sport.getPortGroup(), sport.getPortNetworkId(), path, mountPath, subDirectory, param.getComments(), dnsCheck);
    _log.info(String.format("FileShareExport --- FileShare id: %1$s, Clients: %2$s, StoragePort: %3$s, SecurityType: %4$s, " + "Permissions: %5$s, Root user mapping: %6$s, Protocol: %7$s, path: %8$s, mountPath: %9$s, SubDirectory: %10$s ,byPassDnsCheck: %11$s", id, export.getClients(), sport.getPortName(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getProtocol(), export.getPath(), export.getMountPath(), export.getSubDirectory(), export.getBypassDnsCheck()));
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.EXPORT_FILE_SYSTEM);
    op.setDescription("Filesystem export");
    FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.export(device.getId(), fs.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.EXPORT_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), export.getClients(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol());
    return toTask(fs, task, op);
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) SecurityTypes(com.emc.storageos.volumecontroller.FileShareExport.SecurityTypes) DefaultPermissions(com.emc.storageos.security.authorization.DefaultPermissions) Permissions(com.emc.storageos.volumecontroller.FileShareExport.Permissions) Iterator(java.util.Iterator) FileExport(com.emc.storageos.db.client.model.FileExport) 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 7 with FileExport

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

the class FileService method verifyExports.

/**
 * Since, Modifying an export is not allowed
 * This method verifies the existing export params with the new one issued to modify.
 *
 * @param fs
 * @param param
 */
private void verifyExports(FileShare fs, FileExportUpdateParam param, String permissions, String securityType, String rootUserMapping, String path) {
    // Check to see if th permission passed in is valid
    Boolean allowedPermission = false;
    for (Permissions me : Permissions.values()) {
        if (me.name().equalsIgnoreCase(permissions)) {
            allowedPermission = true;
            break;
        }
    }
    if (!allowedPermission) {
        throw APIException.badRequests.invalidPermissionType(permissions);
    }
    // Check to see if the Security Type passed in is valid
    Boolean allowedsecurityType = false;
    for (SecurityTypes secType : SecurityTypes.values()) {
        if (secType.name().equalsIgnoreCase(securityType)) {
            allowedsecurityType = true;
            break;
        }
    }
    if (!allowedsecurityType) {
        throw APIException.badRequests.invalidSecurityType(securityType);
    }
    FSExportMap fsExports = fs.getFsExports();
    URI id = fs.getId();
    if (null != fsExports) {
        Iterator<FileExport> it = fs.getFsExports().values().iterator();
        while (it.hasNext()) {
            FileExport fileExport = it.next();
            // If no key found then it should process as it is.
            boolean isAlreadyExportedToSameEndpoint = false;
            if (fileExport.getPath().equals(path)) {
                List<String> availableEndpoints = fileExport.getClients();
                List<String> providedEndpoints = param.getAdd();
                for (String providedEndpoint : providedEndpoints) {
                    if (availableEndpoints.contains(providedEndpoint)) {
                        isAlreadyExportedToSameEndpoint = true;
                        break;
                    }
                }
                if (isAlreadyExportedToSameEndpoint) {
                    _log.info(String.format("Existing Export params for FileShare id: %1$s,  SecurityType: %2$s, " + "Permissions: %3$s, Root user mapping: %4$s, ", id, fileExport.getSecurityType(), fileExport.getPermissions(), fileExport.getRootUserMapping()));
                    _log.info(String.format("Recieved Export params for FileShare id: %1$s,  SecurityType: %2$s, " + "Permissions: %3$s, Root user mapping: %4$s, ", id, securityType, permissions, rootUserMapping));
                    if (!fileExport.getPermissions().equals(permissions)) {
                        throw APIException.badRequests.updatingFileSystemExportNotAllowed("permission");
                    }
                    if (!fileExport.getSecurityType().equals(securityType)) {
                        throw APIException.badRequests.updatingFileSystemExportNotAllowed("security type");
                    }
                    if (!fileExport.getRootUserMapping().equals(rootUserMapping)) {
                        throw APIException.badRequests.updatingFileSystemExportNotAllowed("root user mapping");
                    }
                }
            }
        }
    }
}
Also used : SecurityTypes(com.emc.storageos.volumecontroller.FileShareExport.SecurityTypes) DefaultPermissions(com.emc.storageos.security.authorization.DefaultPermissions) Permissions(com.emc.storageos.volumecontroller.FileShareExport.Permissions) FileExport(com.emc.storageos.db.client.model.FileExport) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 8 with FileExport

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

the class FileSnapshotService method getFileSystemSnapshotExportList.

/**
 * @Deprecated use {id}/export instead
 *             Get file share snapshots exports
 * @param id
 *            the URN of a ViPR Snapshot
 * @brief List file snapshot exports.This method is deprecated.
 *        <p>
 *        Use /file/snapshots/{id}/export instead.
 * @return List of file share snapshot exports
 */
@Deprecated
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSystemExportList getFileSystemSnapshotExportList(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snapshot = queryResource(id);
    FileSystemExportList fileExportListResponse = new FileSystemExportList();
    if (snapshot.getInactive()) {
        return fileExportListResponse;
    }
    // Get export map from snapshot
    FSExportMap exportMap = snapshot.getFsExports();
    Collection<FileExport> fileExports = new ArrayList<FileExport>();
    if (exportMap != null) {
        fileExports = exportMap.values();
    }
    // Process each export from the map and its data to exports in response list.
    for (FileExport fileExport : fileExports) {
        FileSystemExportParam fileExportParam = new FileSystemExportParam();
        fileExportParam.setEndpoints(fileExport.getClients());
        fileExportParam.setSecurityType(fileExport.getSecurityType());
        fileExportParam.setPermissions(fileExport.getPermissions());
        fileExportParam.setRootUserMapping(fileExport.getRootUserMapping());
        fileExportParam.setProtocol(fileExport.getProtocol());
        fileExportParam.setMountPoint(fileExport.getMountPoint());
        fileExportListResponse.getExportList().add(fileExportParam);
    }
    return fileExportListResponse;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileSystemExportParam(com.emc.storageos.model.file.FileSystemExportParam) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 9 with FileExport

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

the class FileQuotaDirectoryService method quotaDirectoryHasExportsOrShares.

/**
 * This method verifies the file system quota directory has any exports or shares
 *
 * @param fs - file system on which the QD present
 * @param quotaName - name of the QD
 * @return true - if there are any exports or shares, false otherwise.
 */
private boolean quotaDirectoryHasExportsOrShares(FileShare fs, String quotaName) {
    FSExportMap fsExportMap = fs.getFsExports();
    // Verify for NFS exports on quota directory
    if (fsExportMap != null && !fsExportMap.isEmpty()) {
        // check the quota directory is exported
        for (FileExport fileExport : fsExportMap.values()) {
            if (quotaName.equals(fileExport.getSubDirectory()) && fileExport.getPath().endsWith(quotaName)) {
                _log.info("quota directory {} on fs {} has NFS exports", quotaName, fs.getLabel());
                return true;
            }
        }
    }
    // Verify for CIFS shares on quota directory
    SMBShareMap smbShareMap = fs.getSMBFileShares();
    if (smbShareMap != null && !smbShareMap.isEmpty()) {
        for (SMBFileShare smbFileShare : smbShareMap.values()) {
            // check for quota name in native fs path
            if (smbFileShare.getPath().endsWith("/" + quotaName)) {
                _log.info("quota directory {} on fs {} has CIFS shares", quotaName, fs.getLabel());
                return true;
            }
        }
    }
    return false;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileExport(com.emc.storageos.db.client.model.FileExport) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FSExportMap(com.emc.storageos.db.client.model.FSExportMap)

Example 10 with FileExport

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

the class ComputeSystemControllerImpl method addStepsForIpInterfaceFileShares.

public String addStepsForIpInterfaceFileShares(Workflow workflow, String waitFor, URI hostId, URI ipId) {
    List<FileShare> fileShares = ComputeSystemHelper.getFileSharesByHost(_dbClient, hostId);
    IpInterface ipinterface = _dbClient.queryObject(IpInterface.class, ipId);
    List<String> endpoints = Arrays.asList(ipinterface.getIpAddress());
    for (FileShare fileShare : fileShares) {
        if (fileShare != null && fileShare.getFsExports() != null) {
            for (FileExport fileExport : fileShare.getFsExports().values()) {
                if (fileExport != null && fileExport.getClients() != null) {
                    if (fileExportContainsEndpoint(fileExport, endpoints)) {
                        StorageSystem device = _dbClient.queryObject(StorageSystem.class, fileShare.getStorageDevice());
                        List<String> clients = fileExport.getClients();
                        clients.removeAll(endpoints);
                        fileExport.setStoragePort(fileShare.getStoragePort().toString());
                        FileShareExport export = new FileShareExport(clients, fileExport.getSecurityType(), fileExport.getPermissions(), fileExport.getRootUserMapping(), fileExport.getProtocol(), fileExport.getStoragePortName(), fileExport.getStoragePort(), fileExport.getPath(), fileExport.getMountPath(), "", "");
                        if (clients.isEmpty()) {
                            _log.info("Unexporting file share " + fileShare.getId());
                            waitFor = workflow.createStep(UNEXPORT_FILESHARE_STEP, String.format("Unexport fileshare %s", fileShare.getId()), waitFor, fileShare.getId(), fileShare.getId().toString(), this.getClass(), unexportFileShareMethod(device.getId(), device.getSystemType(), fileShare.getId(), export), null, null);
                        } else {
                            _log.info("Updating export for file share " + fileShare.getId());
                            waitFor = workflow.createStep(UPDATE_FILESHARE_EXPORT_STEP, String.format("Update fileshare export %s", fileShare.getId()), waitFor, fileShare.getId(), fileShare.getId().toString(), this.getClass(), updateFileShareMethod(device.getId(), device.getSystemType(), fileShare.getId(), export), null, null);
                        }
                    }
                }
            }
        }
    }
    return waitFor;
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) IpInterface(com.emc.storageos.db.client.model.IpInterface) FileExport(com.emc.storageos.db.client.model.FileExport) FileShare(com.emc.storageos.db.client.model.FileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

FileExport (com.emc.storageos.db.client.model.FileExport)66 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)33 ArrayList (java.util.ArrayList)32 FileShare (com.emc.storageos.db.client.model.FileShare)31 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)29 Snapshot (com.emc.storageos.db.client.model.Snapshot)21 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)20 FileShareExport (com.emc.storageos.volumecontroller.FileShareExport)18 ControllerException (com.emc.storageos.volumecontroller.ControllerException)17 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)16 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)14 VNXeException (com.emc.storageos.vnxe.VNXeException)12 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)11 URI (java.net.URI)10 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)8 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)8 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)8 FileObject (com.emc.storageos.db.client.model.FileObject)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7