Search in sources :

Example 6 with FSExportMap

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

the class FileService method failoverProtection.

/**
 * Request to failover the protection link associated with the param.copyID.
 *
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source fileshare
 * @param param
 *            FileReplicationParam to failover to
 *
 * @brief Failover the fileShare protection link
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failover")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failoverProtection(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.FAILOVER.toString());
    TaskResourceRep taskResp = null;
    StoragePort storageportNFS = null;
    StoragePort storageportCIFS = null;
    TaskList taskList = new TaskList();
    String task = UUID.randomUUID().toString();
    FileShare fs = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER);
    op.setDescription("failover source file system to target system");
    boolean replicateConfiguration = param.isReplicateConfiguration();
    if (replicateConfiguration) {
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(fs.getMirrorfsTargets());
        FileShare targetFileShare = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        SMBShareMap smbShareMap = fs.getSMBFileShares();
        if (smbShareMap != null) {
            storageportCIFS = _fileScheduler.placeFileShareExport(targetFileShare, StorageProtocol.File.CIFS.name(), null);
        }
        FSExportMap nfsExportMap = fs.getFsExports();
        if (nfsExportMap != null) {
            storageportNFS = _fileScheduler.placeFileShareExport(targetFileShare, StorageProtocol.File.NFS.name(), null);
        }
    }
    FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
    try {
        fileServiceApi.failoverFileShare(id, storageportNFS, storageportCIFS, replicateConfiguration, task);
    } catch (InternalException e) {
        if (_log.isErrorEnabled()) {
            _log.error("", e);
        }
        FileShare fileShare = _dbClient.queryObject(FileShare.class, fs.getId());
        op = fs.getOpStatus().get(task);
        op.error(e);
        fileShare.getOpStatus().updateTaskStatus(task, op);
        _dbClient.updateObject(fs);
        throw e;
    }
    taskResp = toTask(fs, task, op);
    taskList.getTaskList().add(taskResp);
    return taskList;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) TaskList(com.emc.storageos.model.TaskList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) 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 FSExportMap

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

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

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

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

the class ExportVerificationUtility method isFileSystemExported.

private boolean isFileSystemExported() {
    FileObject fileObject = null;
    if (fs != null) {
        fileObject = fs;
    } else {
        fileObject = snapshot;
    }
    String path = fileObject.getPath();
    String subDirectory = param.getSubDir();
    if (subDirectory != null && !subDirectory.equalsIgnoreCase("null") && subDirectory.length() > 0) {
        // Add subdirectory to the path as this is a subdirectory export
        path += "/" + subDirectory;
    }
    FSExportMap exportMap = fileObject.getFsExports();
    if (exportMap != null) {
        Iterator<String> it = fileObject.getFsExports().keySet().iterator();
        while (it.hasNext()) {
            String fsExpKey = it.next();
            FileExport fileExport = fileObject.getFsExports().get(fsExpKey);
            if (fileExport.getPath().equalsIgnoreCase(path)) {
                _log.info("File system path: {} is exported", path);
                return true;
            }
        }
    }
    _log.info("File system path: {} is not exported", path);
    return false;
}
Also used : FileExport(com.emc.storageos.db.client.model.FileExport) FileObject(com.emc.storageos.db.client.model.FileObject) FSExportMap(com.emc.storageos.db.client.model.FSExportMap)

Aggregations

FSExportMap (com.emc.storageos.db.client.model.FSExportMap)46 FileExport (com.emc.storageos.db.client.model.FileExport)33 ArrayList (java.util.ArrayList)22 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)20 FileShare (com.emc.storageos.db.client.model.FileShare)18 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 Snapshot (com.emc.storageos.db.client.model.Snapshot)11 URI (java.net.URI)11 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)9 WorkflowException (com.emc.storageos.workflow.WorkflowException)7 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 FileShareExport (com.emc.storageos.volumecontroller.FileShareExport)6 List (java.util.List)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)5