Search in sources :

Example 1 with SMBFileShare

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

the class FileDeviceController method deleteShare.

@Override
public void deleteShare(URI storage, URI uri, FileSMBShare smbShare, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(uri, opId);
    FileObject fileObject = null;
    StorageSystem storageObj = null;
    FileShare fsObj = null;
    Snapshot snapshotObj = null;
    try {
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        _log.info(String.format("Delete SMB share details --- name: %1$s, description: %2$s, permissionType: %3$s, permission: %4$s , maxUsers: %5$s ", smbShare.getName(), smbShare.getDescription(), smbShare.getPermissionType(), smbShare.getPermission(), (smbShare.getMaxUsers() > 0) ? smbShare.getMaxUsers() : "unlimited"));
        // get db object for smb share
        SMBFileShare smbFileShare = smbShare.getSMBFileShare();
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        args.setShareName(smbShare.getName());
        args.setOpId(opId);
        if (URIUtil.isType(uri, FileShare.class)) {
            fsObj = _dbClient.queryObject(FileShare.class, uri);
            setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
            fileObject = fsObj;
            args.addFSFileObject(fsObj);
            args.setFileOperation(true);
            // Acquire lock for VNXFILE Storage System
            acquireStepLock(storageObj, opId);
            WorkflowStepCompleter.stepExecuting(opId);
            BiosCommandResult result = getDevice(storageObj.getSystemType()).doDeleteShare(storageObj, args, smbFileShare);
            if (result.getCommandPending()) {
                return;
            }
            if (!result.isCommandSuccess() && !result.getCommandPending()) {
                WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
            }
            fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
            _dbClient.updateObject(fsObj);
            String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
            List<SMBFileShare> shares = null;
            if (result.isCommandSuccess()) {
                SMBShareMap shareMap = fsObj.getSMBFileShares();
                shares = new ArrayList<SMBFileShare>(shareMap.values());
                deleteShareACLsFromDB(args);
                WorkflowStepCompleter.stepSucceded(opId);
            } else {
                shares = new ArrayList<SMBFileShare>();
                shares.add(smbFileShare);
            }
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM_SHARE, result.isCommandSuccess(), eventMsg, getShareNameExtensions(shares), fsObj, smbShare);
        } else {
            snapshotObj = _dbClient.queryObject(Snapshot.class, uri);
            fileObject = snapshotObj;
            args.addSnapshotFileObject(snapshotObj);
            args.setFileOperation(false);
            // Acquire lock for VNXFILE Storage System
            acquireStepLock(storageObj, opId);
            WorkflowStepCompleter.stepExecuting(opId);
            BiosCommandResult result = getDevice(storageObj.getSystemType()).doDeleteShare(storageObj, args, smbFileShare);
            if (result.getCommandPending()) {
                return;
            }
            if (!result.isCommandSuccess() && !result.getCommandPending()) {
                WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
            }
            snapshotObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
            _dbClient.updateObject(snapshotObj);
            fsObj = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
            String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
            List<SMBFileShare> shares = null;
            if (result.isCommandSuccess()) {
                SMBShareMap shareMap = snapshotObj.getSMBFileShares();
                shares = new ArrayList<SMBFileShare>(shareMap.values());
                deleteShareACLsFromDB(args);
                WorkflowStepCompleter.stepSucceded(opId);
            } else {
                shares = new ArrayList<SMBFileShare>();
                shares.add(smbFileShare);
            }
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE, result.isCommandSuccess(), eventMsg, getShareNameExtensions(shares), snapshotObj, fsObj, smbShare);
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        String[] params = { storage.toString(), uri.toString(), smbShare.getName(), e.getMessage() };
        _log.error("Unable to delete file system or snapshot share: storage {}, FS/snapshot URI {}, SMB share {}: {}", params);
        updateTaskStatus(opId, fileObject, e);
        if (URIUtil.isType(uri, FileShare.class)) {
            if ((fsObj != null) && (storageObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM_SHARE, false, e.getMessage(), "", fsObj, smbShare, storageObj);
            }
        } else {
            if ((fsObj != null) && (storageObj != null) && (snapshotObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE, false, e.getMessage(), "", snapshotObj, fsObj, smbShare, storageObj);
            }
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) 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) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with SMBFileShare

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

the class FileDeviceController method getShareNameExtensions.

/**
 * Gets the list of SMB share names to be recorded as an extension in the
 * event for filesystem/snapshot share/deleteShare operations. The extension
 * is specified in the format:
 *
 * ExtensionName=name1, name2, ...,name3
 *
 * @param smbFileShares
 *            The list of file system SMB shares.
 *
 * @return extension names in the format as above
 */
private String getShareNameExtensions(List<SMBFileShare> smbFileShares) {
    StringBuilder strBuilder = new StringBuilder();
    strBuilder.append(RecordableBourneEvent.FS_SHARE_EXTENSION_NAME);
    strBuilder.append("=");
    int i = smbFileShares.size();
    for (SMBFileShare fileShare : smbFileShares) {
        strBuilder.append(fileShare.getName());
        i--;
        if (i > 0) {
            strBuilder.append(",");
        }
    }
    return strBuilder.toString();
}
Also used : SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Example 3 with SMBFileShare

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

the class FileOrchestrationDeviceController method createCIFSShareOnTarget.

private static void createCIFSShareOnTarget(Workflow workflow, URI systemTarget, List<SMBFileShare> smbShares, StoragePort cifsPort, FileShare targetFileShare, FileShare sourceFileShare) {
    for (SMBFileShare smbShare : smbShares) {
        FileSMBShare fileSMBShare = new FileSMBShare(smbShare);
        fileSMBShare.setStoragePortName(cifsPort.getPortName());
        fileSMBShare.setStoragePortNetworkId(cifsPort.getPortNetworkId());
        if (fileSMBShare.isSubDirPath()) {
            fileSMBShare.setPath(targetFileShare.getPath() + fileSMBShare.getPath().split(sourceFileShare.getPath())[1]);
        } else {
            fileSMBShare.setPath(targetFileShare.getPath());
        }
        String shareCreationStep = workflow.createStepId();
        String stepDescription = String.format("creating CIFS Share : %s, path : %s", fileSMBShare.getName(), fileSMBShare.getPath());
        Object[] args = new Object[] { systemTarget, targetFileShare.getId(), fileSMBShare };
        _fileDeviceController.createMethod(workflow, null, CREATE_FILESYSTEM_SHARE_METHOD, shareCreationStep, stepDescription, systemTarget, args);
    }
}
Also used : FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare)

Example 4 with SMBFileShare

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

the class FileOrchestrationDeviceController method deleteCIFSShareFromTarget.

private static void deleteCIFSShareFromTarget(Workflow workflow, URI systemTarget, List<SMBFileShare> smbShares, FileShare targetFileShare) {
    for (SMBFileShare smbShare : smbShares) {
        FileSMBShare fileSMBShare = new FileSMBShare(smbShare);
        String stepDescription = String.format("deleting CIFS share : %s, path : %s", fileSMBShare.getName(), fileSMBShare.getPath());
        String sharedeleteStep = workflow.createStepId();
        Object[] args = new Object[] { systemTarget, targetFileShare.getId(), fileSMBShare };
        _fileDeviceController.createMethod(workflow, null, DELETE_FILESYSTEM_SHARE_METHOD, sharedeleteStep, stepDescription, systemTarget, args);
    }
}
Also used : FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare)

Example 5 with SMBFileShare

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

the class FileService method getFileSystemShareList.

/**
 * Get list of SMB shares for the specified file system.
 *
 * @param id
 *            the URN of a ViPR File system
 * @brief List file system SMB shares
 * @return List of file system shares.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSystemShareList getFileSystemShareList(@PathParam("id") URI id) {
    _log.info(String.format("Get list of SMB file shares for file system: %1$s", id));
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fileShare = queryResource(id);
    FileSystemShareList fileShareListResponse = new FileSystemShareList();
    if (fileShare.getInactive()) {
        return fileShareListResponse;
    }
    SMBShareMap smbShareMap = fileShare.getSMBFileShares();
    Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
    if (smbShareMap != null) {
        smbShares = smbShareMap.values();
    }
    // Process each share from the map and add its data to shares in response list.
    for (SMBFileShare smbShare : smbShares) {
        SmbShareResponse shareParam = new SmbShareResponse();
        shareParam.setShareName(smbShare.getName());
        shareParam.setDescription(smbShare.getDescription());
        shareParam.setMaxUsers(Integer.toString(smbShare.getMaxUsers()));
        // Check for "unlimited"
        if (shareParam.getMaxUsers().equals("-1")) {
            shareParam.setMaxUsers(UNLIMITED_USERS);
        }
        shareParam.setPermissionType(smbShare.getPermissionType());
        shareParam.setPermission(smbShare.getPermission());
        shareParam.setMountPoint(smbShare.getMountPoint());
        shareParam.setPath(smbShare.getPath());
        fileShareListResponse.getShareList().add(shareParam);
    }
    return fileShareListResponse;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) ArrayList(java.util.ArrayList) SmbShareResponse(com.emc.storageos.model.file.SmbShareResponse) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) 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)

Aggregations

SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)46 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)26 FileShare (com.emc.storageos.db.client.model.FileShare)21 Snapshot (com.emc.storageos.db.client.model.Snapshot)16 ArrayList (java.util.ArrayList)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 ControllerException (com.emc.storageos.volumecontroller.ControllerException)13 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 FileSMBShare (com.emc.storageos.volumecontroller.FileSMBShare)9 URI (java.net.URI)9 FileExport (com.emc.storageos.db.client.model.FileExport)8 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)8 VNXeException (com.emc.storageos.vnxe.VNXeException)8 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)7 FileDeviceInputOutput (com.emc.storageos.volumecontroller.FileDeviceInputOutput)7 FileObject (com.emc.storageos.db.client.model.FileObject)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5