Search in sources :

Example 1 with FSExportMap

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

the class FileOrchestrationDeviceController method failbackFileSystem.

@Override
public void failbackFileSystem(URI fsURI, StoragePort nfsPort, StoragePort cifsPort, boolean replicateConfiguration, String taskId) throws ControllerException {
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    Workflow workflow = null;
    String stepDescription = null;
    try {
        FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
        FileShare targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        StorageSystem systemSource = s_dbClient.queryObject(StorageSystem.class, sourceFileShare.getStorageDevice());
        workflow = this._workflowService.getNewWorkflow(this, FAILBACK_FILESYSTEMS_WF_NAME, false, taskId, completer);
        // Failback from Target File System
        s_logger.info("Generating steps for Failback Source File System from Target");
        String failbackStep = workflow.createStepId();
        stepDescription = String.format("Failback to source file System : %s from target system : %s.", sourceFileShare.getName(), targetFileShare.getName());
        Workflow.Method failbackMethod = new Workflow.Method(FAILBACK_FILE_SYSTEM_METHOD, systemSource.getId(), sourceFileShare.getId());
        String waitForFailback = workflow.createStep(null, stepDescription, null, systemSource.getId(), systemSource.getSystemType(), getClass(), failbackMethod, null, failbackStep);
        // Replicate directory quota setting
        stepDescription = String.format("Replicating directory quota settings from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
        Workflow.Method replicateDirQuotaSettingsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_DIRECTORY_QUOTA_SETTINGS_METHOD, systemSource.getId(), targetFileShare.getId());
        String replicateDirQuotaSettingsStep = workflow.createStepId();
        workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateDirQuotaSettingsMethod, null, replicateDirQuotaSettingsStep);
        if (replicateConfiguration) {
            Map<String, List<NfsACE>> sourceNFSACL = FileOrchestrationUtils.queryNFSACL(sourceFileShare, s_dbClient);
            Map<String, List<NfsACE>> targetNFSACL = FileOrchestrationUtils.queryNFSACL(targetFileShare, s_dbClient);
            if (!sourceNFSACL.isEmpty() || !targetNFSACL.isEmpty()) {
                stepDescription = String.format("Replicating NFS ACL from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
                Workflow.Method replicateNFSACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_ACLS_METHOD, systemSource.getId(), targetFileShare.getId());
                String replicateNFSACLsStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateNFSACLsMethod, null, replicateNFSACLsStep);
            }
            // Replicate NFS export and rules to Target Cluster.
            FSExportMap targetnfsExportMap = targetFileShare.getFsExports();
            FSExportMap sourcenfsExportMap = sourceFileShare.getFsExports();
            if (!(targetnfsExportMap == null && sourcenfsExportMap == null)) {
                // Both source and target export map shouldn't be null
                stepDescription = String.format("Replicating NFS exports from target file system : %s to source file system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateNFSExportMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_METHOD, systemSource.getId(), targetFileShare.getId(), nfsPort);
                String replicateNFSExportStep = workflow.createStepId();
                String waitForExport = workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateNFSExportMethod, null, replicateNFSExportStep);
                stepDescription = String.format("Replicating NFS export rules from target file system : %s to source file system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateNFSExportRulesMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_RULE_METHOD, systemSource.getId(), targetFileShare.getId());
                String replicateNFSExportRulesStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForExport, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateNFSExportRulesMethod, null, replicateNFSExportRulesStep);
            }
            // Replicate CIFS shares and ACLs from Target File System to Source.
            SMBShareMap targetSMBShareMap = targetFileShare.getSMBFileShares();
            SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
            if (!(targetSMBShareMap == null && sourceSMBShareMap == null)) {
                // Both source and target share map shouldn't be null
                stepDescription = String.format("Replicating CIFS shares from target file system : %s to file source system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateCIFSShareMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARES_METHOD, systemSource.getId(), targetFileShare.getId(), cifsPort);
                String replicateCIFSShareStep = workflow.createStepId();
                String waitForShare = workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateCIFSShareMethod, null, replicateCIFSShareStep);
                stepDescription = String.format("Replicating CIFS share ACLs from target file system : %s to source file system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateCIFSShareACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARE_ACLS_METHOD, systemSource.getId(), targetFileShare.getId());
                String replicateCIFSShareACLsStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForShare, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateCIFSShareACLsMethod, null, replicateCIFSShareACLsStep);
            }
        }
        String successMessage = "Failback FileSystem successful for: " + sourceFileShare.getLabel();
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not failback filesystems: " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILBACK.getName();
        ServiceError serviceError = DeviceControllerException.errors.createFileSharesFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) 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) List(java.util.List) ArrayList(java.util.ArrayList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with FSExportMap

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

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

the class InternalFileResource method releaseFileSystemInternal.

/**
 * Release a file system from its current tenant & project for internal object usage
 *
 * @param id the URN of a ViPR file system to be released
 * @return the updated file system
 * @throws InternalException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/release")
public FileShareRestRep releaseFileSystemInternal(@PathParam("id") URI id) throws InternalException {
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = _fileService.queryResource(id);
    // and just return success down at the bottom
    if (!fs.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
        URI tenantURI = fs.getTenant().getURI();
        if (!_permissionsHelper.userHasGivenRole(getUserFromContext(), tenantURI, Role.TENANT_ADMIN)) {
            throw APIException.forbidden.onlyAdminsCanReleaseFileSystems(Role.TENANT_ADMIN.toString());
        }
        // we can't release a fs that has exports
        FSExportMap exports = fs.getFsExports();
        if ((exports != null) && (!exports.isEmpty())) {
            throw APIException.badRequests.cannotReleaseFileSystemExportExists(exports.keySet().toString());
        }
        // we can't release a fs that has shares
        SMBShareMap shares = fs.getSMBFileShares();
        if ((shares != null) && (!shares.isEmpty())) {
            throw APIException.badRequests.cannotReleaseFileSystemSharesExists(shares.keySet().toString());
        }
        // files systems with pending operations can't be released
        if (fs.getOpStatus() != null) {
            for (String opId : fs.getOpStatus().keySet()) {
                Operation op = fs.getOpStatus().get(opId);
                if (Operation.Status.pending.name().equals(op.getStatus())) {
                    throw APIException.badRequests.cannotReleaseFileSystemWithTasksPending();
                }
            }
        }
        // file systems with snapshots can't be released
        Integer snapCount = _fileService.getNumSnapshots(fs);
        if (snapCount > 0) {
            throw APIException.badRequests.cannotReleaseFileSystemSnapshotExists(snapCount);
        }
        TenantOrg rootTenant = _permissionsHelper.getRootTenant();
        // we can't release the file system to the root tenant if the root tenant has no access
        // to the filesystem's virtual pool
        ArgValidator.checkFieldNotNull(fs.getVirtualPool(), "virtualPool");
        VirtualPool virtualPool = _permissionsHelper.getObjectById(fs.getVirtualPool(), VirtualPool.class);
        ArgValidator.checkEntity(virtualPool, fs.getVirtualPool(), false);
        if (!_permissionsHelper.tenantHasUsageACL(rootTenant.getId(), virtualPool)) {
            throw APIException.badRequests.cannotReleaseFileSystemRootTenantLacksVPoolACL(virtualPool.getId().toString());
        }
        fs.setOriginalProject(fs.getProject().getURI());
        fs.setTenant(new NamedURI(rootTenant.getId(), fs.getLabel()));
        fs.setProject(new NamedURI(_internalProject.getId(), fs.getLabel()));
        fs.addInternalFlags(INTERNAL_FILESHARE_FLAGS);
        _dbClient.updateAndReindexObject(fs);
        // audit against the source project, not the new dummy internal project
        auditOp(OperationTypeEnum.RELEASE_FILE_SYSTEM, true, null, fs.getId().toString(), fs.getOriginalProject().toString());
    }
    return map(fs);
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 4 with FSExportMap

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

the class FileService method failbackProtection.

/**
 * Request to fail Back the protection link associated with the param.copyID.
 *
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source files hare
 * @param param
 *            FileReplicationParam to fail Back to
 *
 * @brief Fail Back 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/failback")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failbackProtection(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.FAILBACK.toString());
    TaskResourceRep taskResp = null;
    StoragePort storageportNFS = null;
    StoragePort storageportCIFS = null;
    TaskList taskList = new TaskList();
    String task = UUID.randomUUID().toString();
    FileShare sourceFileShare = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILBACK);
    op.setDescription("failback to source file system from target system");
    boolean replicateConfiguration = param.isReplicateConfiguration();
    if (replicateConfiguration) {
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
        FileShare targetFileShare = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        SMBShareMap smbShareMap = targetFileShare.getSMBFileShares();
        if (smbShareMap != null) {
            storageportCIFS = _fileScheduler.placeFileShareExport(sourceFileShare, StorageProtocol.File.CIFS.name(), null);
        }
        FSExportMap nfsExportMap = targetFileShare.getFsExports();
        if (nfsExportMap != null) {
            storageportNFS = _fileScheduler.placeFileShareExport(sourceFileShare, StorageProtocol.File.NFS.name(), null);
        }
    }
    FileServiceApi fileServiceApi = getFileShareServiceImpl(sourceFileShare, _dbClient);
    try {
        fileServiceApi.failbackFileShare(sourceFileShare.getId(), storageportNFS, storageportCIFS, replicateConfiguration, task);
    } catch (InternalException e) {
        if (_log.isErrorEnabled()) {
            _log.error("", e);
        }
        op = sourceFileShare.getOpStatus().get(task);
        op.error(e);
        sourceFileShare.getOpStatus().updateTaskStatus(task, op);
        _dbClient.updateObject(sourceFileShare);
        throw e;
    }
    taskResp = toTask(sourceFileShare, 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 5 with FSExportMap

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

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