Search in sources :

Example 1 with FileExport

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

the class FileShareExport method getFileExport.

public FileExport getFileExport() {
    // Convert the set of security types to a string separated by comma(,).
    Set<String> orderedSecTypes = new TreeSet<String>();
    Iterator<SecurityTypes> secIter = _securityType.iterator();
    while (secIter.hasNext()) {
        orderedSecTypes.add(secIter.next().toString());
    }
    Iterator<String> orderedList = orderedSecTypes.iterator();
    String securityTypes = orderedList.next().toString();
    while (orderedList.hasNext()) {
        securityTypes += "," + orderedList.next().toString();
    }
    FileExport fileExport = new FileExport(_clients, _storagePortName, _mountPath, securityTypes, _permissions.toString(), _rootUserMapping, _protocol.toString(), _storagePort, _path, _mountPath, _subDirectory, _comments);
    fileExport.setIsilonId(_isilonId);
    return fileExport;
}
Also used : TreeSet(java.util.TreeSet) FileExport(com.emc.storageos.db.client.model.FileExport)

Example 2 with FileExport

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

the class FileOrchestrationDeviceController method addStepsToReplicateNFSExports.

/**
 * Child workflow for replicating source file system NFS export to target.
 *
 * @param systemTarget
 *            - URI of target StorageSystem where source NFS shares has to be replicated.
 * @param fsURI
 *            -URI of the source FileSystem
 * @param nfsPort
 *            -StoragePort, NFS port of target File System where new export has to be created.
 * @param taskId
 */
public void addStepsToReplicateNFSExports(URI systemTarget, URI fsURI, StoragePort nfsPort, String taskId) {
    s_logger.info("Generating steps for Replicating NFS exports to Target Cluster");
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    Workflow workflow = null;
    FileShare targetFileShare = null;
    try {
        FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
        if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
            List<String> targetfileUris = new ArrayList<String>();
            targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
            targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        } else {
            targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
        }
        workflow = this._workflowService.getNewWorkflow(this, REPLICATE_NFS_EXPORT_TO_TARGET_WF_NAME, false, taskId, completer);
        FSExportMap sourceNFSExportMap = sourceFileShare.getFsExports();
        FSExportMap targetNFSExportMap = targetFileShare.getFsExports();
        if (targetNFSExportMap == null && sourceNFSExportMap != null) {
            // No export on target i.e create all source export on target
            List<FileExport> sourceNFSExports = new ArrayList<FileExport>(sourceNFSExportMap.values());
            createNFSExportOnTarget(workflow, systemTarget, sourceNFSExports, nfsPort, targetFileShare, sourceFileShare);
        } else if (sourceNFSExportMap != null && targetNFSExportMap != null) {
            // both source and target have some exports
            List<FileExport> sourceNFSExports = new ArrayList<FileExport>(sourceNFSExportMap.values());
            List<FileExport> targetNFSExports = new ArrayList<FileExport>(targetNFSExportMap.values());
            List<FileExport> targetNFSExportstoCreate = new ArrayList<FileExport>();
            // Creating new map since FSExportMap key contains path+sec+user
            HashMap<String, FileExport> sourceFileExportMap = FileOrchestrationUtils.getFileExportMap(sourceNFSExports);
            HashMap<String, FileExport> targetFileExportMap = FileOrchestrationUtils.getFileExportMap(targetNFSExports);
            String waitFor = null;
            // Check for export to create on target
            for (String exportPath : sourceFileExportMap.keySet()) {
                if (exportPath.equals(sourceFileShare.getPath())) {
                    if (targetFileExportMap.get(targetFileShare.getPath()) == null) {
                        targetNFSExportstoCreate.add(sourceFileExportMap.get(exportPath));
                    }
                } else {
                    ArrayList<String> subdirName = new ArrayList<String>();
                    subdirName.add(exportPath.split(sourceFileShare.getPath())[1]);
                    if (targetFileExportMap.get(targetFileShare.getPath() + subdirName.get(0)) == null) {
                        targetNFSExportstoCreate.add(sourceFileExportMap.get(exportPath));
                    }
                }
            }
            if (!targetNFSExportstoCreate.isEmpty()) {
                waitFor = createNFSExportOnTarget(workflow, systemTarget, targetNFSExportstoCreate, nfsPort, targetFileShare, sourceFileShare);
            }
            // Check for export to delete on target
            for (String exportPath : targetFileExportMap.keySet()) {
                String stepDescription = String.format("deleting NFS export : %s", exportPath);
                String exportdeletionStep = workflow.createStepId();
                if (exportPath.equals(targetFileShare.getPath())) {
                    if (sourceFileExportMap.get(sourceFileShare.getPath()) == null) {
                        Object[] args = new Object[] { systemTarget, targetFileShare.getId(), false, null };
                        waitFor = _fileDeviceController.createMethod(workflow, waitFor, DELETE_FILESYSTEM_EXPORT_METHOD, exportdeletionStep, stepDescription, systemTarget, args);
                    }
                } else {
                    ArrayList<String> subdirName = new ArrayList<String>();
                    subdirName.add(exportPath.split(targetFileShare.getPath())[1]);
                    if (sourceFileExportMap.get(sourceFileShare.getPath() + subdirName.get(0)) == null) {
                        Object[] args = new Object[] { systemTarget, targetFileShare.getId(), false, subdirName.get(0).substring(1) };
                        waitFor = _fileDeviceController.createMethod(workflow, waitFor, DELETE_FILESYSTEM_EXPORT_METHOD, exportdeletionStep, stepDescription, systemTarget, args);
                    }
                }
            }
        }
        String successMessage = String.format("Replicating source File System : %s NFS Exports to Target System finished successfully", sourceFileShare.getId());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem NFS Exports : " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) FileWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter) FileExport(com.emc.storageos.db.client.model.FileExport) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with FileExport

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

the class FileOrchestrationDeviceController method createNFSExportOnTarget.

private static String createNFSExportOnTarget(Workflow workflow, URI systemTarget, List<FileExport> nfsExportsToCreate, StoragePort nfsPort, FileShare targetFileShare, FileShare sourceFileShare) {
    String waitFor = null;
    for (FileExport nfsExport : nfsExportsToCreate) {
        FileShareExport fileNFSExport = new FileShareExport(nfsExport.getClients(), nfsExport.getSecurityType(), nfsExport.getPermissions(), nfsExport.getRootUserMapping(), nfsExport.getProtocol(), nfsPort.getPortName(), nfsPort.getPortNetworkId(), null);
        if (!sourceFileShare.getPath().equals(nfsExport.getPath())) {
            ArrayList<String> subdirName = new ArrayList<String>();
            subdirName.add(nfsExport.getPath().split(sourceFileShare.getPath())[1]);
            fileNFSExport.setMountPath(targetFileShare.getMountPath() + subdirName.get(0));
            fileNFSExport.setPath(targetFileShare.getMountPath() + subdirName.get(0));
        } else {
            fileNFSExport.setMountPath(targetFileShare.getMountPath());
            fileNFSExport.setPath(targetFileShare.getMountPath());
        }
        String stepDescription = String.format("creating NFS export : %s", fileNFSExport.getMountPath());
        String exportCreationStep = workflow.createStepId();
        Object[] args = new Object[] { systemTarget, targetFileShare.getId(), Arrays.asList(fileNFSExport) };
        waitFor = _fileDeviceController.createMethod(workflow, waitFor, CREATE_FILESYSTEM_EXPORT_METHOD, exportCreationStep, stepDescription, systemTarget, args);
    }
    return waitFor;
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) FileObject(com.emc.storageos.db.client.model.FileObject)

Example 4 with FileExport

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

the class FileService method updateExport.

/**
 * @Deprecated use @Path("/{id}/export") instead
 *
 *             Existing file system exports may have their list of endpoints updated. The permission, security, or
 *             root user
 *             mapping of an existing export may not be changed. In order to change one of these attributes, the
 *             export must be
 *             first deleted and then created with the new value.
 *
 * @param id
 *            the URN of a ViPR Project
 * @param protocol
 *            Protocol valid values - NFS,NFSv4,CIFS
 * @param securityType
 *            Security type valid values - sys,krb5,krb5i,krb5p
 * @param permissions
 *            Permissions valid values - ro,rw,root
 * @param rootUserMapping
 *            Root user mapping
 * @brief Update file system export.
 *        <p>
 *        Use /file/filesystems/{id}/export instead
 * @return Task resource representation
 * @throws InternalException
 */
@Deprecated
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports/{protocol},{secType},{perm},{root_mapping}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateExport(@PathParam("id") URI id, @PathParam("protocol") String protocol, @PathParam("secType") String securityType, @PathParam("perm") String permissions, @PathParam("root_mapping") String rootUserMapping, FileExportUpdateParam param) throws InternalException {
    _log.info("Export update request received {}", id);
    // Validate the input.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkFieldNotNull(protocol, "protocol");
    ArgValidator.checkFieldNotNull(securityType, "secType");
    ArgValidator.checkFieldNotNull(permissions, "perm");
    ArgValidator.checkFieldNotNull(rootUserMapping, "root_mapping");
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldNotEmpty(fs.getFsExports(), "exports");
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    String path = fs.getPath();
    _log.info("update export for path {} ", path);
    _log.info(String.format("securityType %1$s, permissions %2$s, rootMapping %3$s, protocol %4$s FileSystem %5$s", securityType, permissions, rootUserMapping, protocol, path));
    FileExport fExport = fs.getFsExports().get(FileExport.exportLookupKey(protocol, securityType, permissions, rootUserMapping, path));
    if (fExport == null) {
        throw APIException.badRequests.invalidParameterFileSystemNoSuchExport();
    }
    validateIpInterfacesRegistered(param.getAdd(), _dbClient);
    verifyExports(fs, param, permissions, securityType, rootUserMapping, path);
    String task = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.EXPORT_FILE_SYSTEM);
    // Update the list.
    List<String> clients = fExport.getClients();
    if (param.getAdd() != null) {
        for (String addEndpoint : param.getAdd()) {
            clients.add(addEndpoint);
        }
    }
    if (param.getRemove() != null) {
        for (String delEndpoint : param.getRemove()) {
            clients.remove(delEndpoint);
        }
    }
    FileShareExport export = new FileShareExport(clients, securityType, permissions, rootUserMapping, protocol, fExport.getStoragePortName(), fExport.getStoragePort(), path, fExport.getMountPath(), fExport.getSubDirectory(), param.getComments());
    controller.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(), securityType, permissions, rootUserMapping, protocol);
    return toTask(fs, task, op);
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) FileController(com.emc.storageos.volumecontroller.FileController) FileExport(com.emc.storageos.db.client.model.FileExport) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) 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 5 with FileExport

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

the class FileService method unexport.

/**
 * @Deprecated use @Path("/{id}/export") instead
 *
 *             <p>
 *             NOTE: This is an asynchronous operation.
 * @param id
 *            the URN of a ViPR Project
 * @param protocol
 *            Protocol valid values - NFS,NFSv4,CIFS
 * @param securityType
 *            Security type valid values - sys,krb5,krb5i,krb5p
 * @param permissions
 *            Permissions valid values - ro,rw,root
 * @param rootUserMapping
 *            Root user mapping
 * @brief Delete file system export.
 *        <p>
 *        Use /file/filesystems/{id}/export instead
 * @return Task resource representation
 * @throws InternalException
 */
@Deprecated
@DELETE
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports/{protocol},{secType},{perm},{root_mapping}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep unexport(@PathParam("id") URI id, @PathParam("protocol") String protocol, @PathParam("secType") String securityType, @PathParam("perm") String permissions, @PathParam("root_mapping") String rootUserMapping, @QueryParam("subDirectory") String subDirectory) throws InternalException {
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkFieldNotNull(protocol, "protocol");
    ArgValidator.checkFieldNotNull(securityType, "secType");
    ArgValidator.checkFieldNotNull(permissions, "perm");
    ArgValidator.checkFieldNotNull(rootUserMapping, "root_mapping");
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    String task = UUID.randomUUID().toString();
    if (fs.getFsExports() == null) {
        // No exports present. Return success.
        return getSuccessResponse(fs, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM, "Export does not exist");
    }
    if (fs.getStoragePort() == null) {
        // port associated with export, fail the operation
        return getFailureResponse(fs, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM, "No storage port associated with " + fs.getLabel());
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    String path = fs.getPath();
    String mountPath = fs.getMountPath();
    if (subDirectory != null && subDirectory.length() > 0) {
        // Add subdirectory to the path as this is a subdirectory export
        path += "/" + subDirectory;
        mountPath += "/" + subDirectory;
    }
    FileExport fExport = null;
    _log.info("unexport subdirectory passed value is {}", subDirectory);
    if (subDirectory != null) {
        _log.info("unexport subdirectory {} with path {} ", subDirectory, path);
        _log.info(String.format("securityType %1$s, permissions %2$s, rootMapping %3$s, protocol %4$s subDirectory %5$s", securityType, permissions, rootUserMapping, protocol, path));
        fExport = fs.getFsExports().get(FileExport.exportLookupKey(protocol, securityType, permissions, rootUserMapping, path));
    } else {
        _log.info("unexport FS  {} with path {} ", fs.getName(), path);
        _log.info(String.format("securityType %1$s, permissions %2$s, rootMapping %3$s, protocol %4$s FileSystem %5$s", securityType, permissions, rootUserMapping, protocol, path));
        fExport = fs.getFsExports().get(FileExport.exportLookupKey(protocol, securityType, permissions, rootUserMapping, path));
    }
    if (fExport == null) {
        // No export to unexport, return success.
        return getSuccessResponse(fs, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM, "Export does not exist");
    }
    fExport.setStoragePort(fs.getStoragePort().toString());
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM);
    op.setDescription("Filesystem unexport");
    // empty list for unexport
    List<String> endpoints = new ArrayList<String>();
    FileShareExport export = new FileShareExport(endpoints, securityType, permissions, rootUserMapping, protocol, fExport.getStoragePortName(), fExport.getStoragePort(), fExport.getPath());
    export.setIsilonId(fExport.getIsilonId());
    controller.unexport(device.getId(), fs.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.UNEXPORT_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), securityType, permissions, rootUserMapping, protocol);
    return toTask(fs, task, op);
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) FileController(com.emc.storageos.volumecontroller.FileController) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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