Search in sources :

Example 41 with SMBFileShare

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

the class VNXUnityFileStorageDeviceTest method testSnapshotDelete.

/**
 * Tests snapshot delete with existing SMB shares and NFS exports.
 *
 * @throws Exception
 */
@Test
public void testSnapshotDelete() throws Exception {
    // create FS to use
    FileShare fs = new FileShare();
    fs.setId(URIUtil.createId(FileShare.class));
    fs.setLabel("test");
    fs.setCapacity(102400L);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    args.addStoragePool(_pool);
    args.addFSFileObject(fs);
    Assert.assertTrue("doCreateFS failed", _unity.doCreateFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
    // create snap
    Snapshot snap = new Snapshot();
    snap.setId(URIUtil.createId(Snapshot.class));
    snap.setLabel("test_snap");
    args.addSnapshotFileObject(snap);
    Assert.assertTrue("doSnapshotFS failed", _unity.doSnapshotFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
    // share snap with SMB
    SMBFileShare smbFileShare = new SMBFileShare("TestSMBShare", "Share created by unit test.", "allow", "change", -1);
    Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("SMB share doShare() failed, share not added to snap", snap.getSMBFileShares().keySet().contains(smbFileShare.getName()));
    Assert.assertTrue("SMB share doShare() failed, number of shares does not match", snap.getSMBFileShares().keySet().size() == 1);
    // add additional share
    SMBFileShare smbFileShare01 = new SMBFileShare("TestSMBShare01", "Share created by unit test.", "allow", "change", -1);
    Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare01).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("SMB share doShare() failed, share not added to snap", snap.getSMBFileShares().keySet().contains(smbFileShare01.getName()));
    Assert.assertTrue("SMB share doShare() failed, number of shares does not match", snap.getSMBFileShares().keySet().size() == 2);
    // add additional share
    SMBFileShare smbFileShare02 = new SMBFileShare("TestSMBShare02", "Share created by unit test.", "allow", "change", -1);
    Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare02).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("SMB share doShare() failed, share not added to snap", snap.getSMBFileShares().keySet().contains(smbFileShare02.getName()));
    Assert.assertTrue("SMB share doShare() failed, number of shares does not match", snap.getSMBFileShares().keySet().size() == 3);
    // export snap
    List<String> clients = new ArrayList<String>();
    clients.add(client1);
    FileExport export1 = new FileExport(clients, "", "sys", "root", "nobody", "nfs");
    Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export1)).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("doExport failed, export not added to snapshot", snap.getFsExports().keySet().size() == 1);
    // add client to the same export
    clients.add(client2);
    FileExport export2 = new FileExport(clients, "", "sys", "root", "nobody", "nfs");
    Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export1)).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("doExport failed, export not added to snapshot", snap.getFsExports().keySet().size() == 1);
    // create a new export
    clients = new ArrayList<String>();
    clients.add(client3);
    clients.add(client4);
    FileExport export3 = new FileExport(clients, "", "sys", "rw", "nobody", "nfs");
    Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export3)).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("doExport failed, export not added to snapshot", snap.getFsExports().keySet().size() == 2);
    // delete snap
    Assert.assertTrue("doDeleteSnapshot failed", _unity.doDeleteSnapshot(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
    VNXeApiClient apiclient = _unity.getVnxUnityClient(_device);
    try {
        apiclient.getFileSystemByFSName(args.getFileObjMountPath());
        Assert.assertTrue("Snapshot delete failed: " + args.getFileObjMountPath(), false);
    } catch (VNXeException uex) {
        System.out.println("doDeleteSnapshot --- delete snapshot success: " + uex.getCause());
    }
    // delete file system
    Assert.assertTrue("doDeleteFS failed", _unity.doDeleteFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
    try {
        apiclient.getFileSystemByFSName(args.getFsMountPath());
        Assert.assertTrue("FS delete failed: " + args.getFsMountPath(), false);
    } catch (VNXeException uex) {
        System.out.println("doDeleteFS --- delete FS success: " + uex.getCause());
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) ArrayList(java.util.ArrayList) FileExport(com.emc.storageos.db.client.model.FileExport) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) Test(org.junit.Test)

Example 42 with SMBFileShare

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

the class VNXUnityFileStorageDeviceTest method testFileSystemDelete.

/**
 * Tests file system delete with existing smb shares and nfs exports.
 *
 * @throws Exception
 */
@Test
public void testFileSystemDelete() throws Exception {
    FileShare fs = new FileShare();
    fs.setId(URIUtil.createId(FileShare.class));
    fs.setLabel("test");
    fs.setCapacity(102400L);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    args.addStoragePool(_pool);
    args.addFSFileObject(fs);
    Assert.assertTrue("doCreateFS failed", _unity.doCreateFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
    // share file system with SMB
    SMBFileShare smbFileShare = new SMBFileShare("TestSMBShare", "Share created by unit test.", "allow", "change", -1);
    Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("SMB share doShare() failed, share not added to FS", fs.getSMBFileShares().keySet().contains(smbFileShare.getName()));
    Assert.assertTrue("SMB share doShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 1);
    // add additional share
    SMBFileShare smbFileShare01 = new SMBFileShare("TestSMBShare01", "Share created by unit test.", "allow", "change", -1);
    Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare01).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("SMB share doShare() failed, share not added to FS", fs.getSMBFileShares().keySet().contains(smbFileShare01.getName()));
    Assert.assertTrue("SMB share doShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 2);
    // add additional share
    SMBFileShare smbFileShare02 = new SMBFileShare("TestSMBShare02", "Share created by unit test.", "allow", "change", -1);
    Assert.assertTrue("SMB share doShare() failed", _unity.doShare(_device, args, smbFileShare02).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("SMB share doShare() failed, share not added to FS", fs.getSMBFileShares().keySet().contains(smbFileShare02.getName()));
    Assert.assertTrue("SMB share doShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 3);
    // delete one SMB share for FS
    Assert.assertTrue("SMB share doDeleteShare() failed", _unity.doDeleteShare(_device, args, smbFileShare).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertFalse("SMB share doDeleteShare() failed, share was not deleted from FS", fs.getSMBFileShares().keySet().contains(smbFileShare.getName()));
    Assert.assertTrue("SMB share doDeleteShare() failed, number of shares does not match", fs.getSMBFileShares().keySet().size() == 2);
    // export
    List<String> clients = new ArrayList<String>();
    clients.add(client1);
    FileExport export1 = new FileExport(clients, "port1", "sys", "root", "nobody", "nfs");
    Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export1)).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("doExport failed, export not added to FS", fs.getFsExports().keySet().size() == 1);
    // add client
    clients.add(client2);
    FileExport export2 = new FileExport(clients, "port1", "sys", "root", "nobody", "nfs");
    Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export2)).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("doExport failed, export not added to FS", fs.getFsExports().keySet().size() == 1);
    // create a new export
    clients = new ArrayList<String>();
    clients.add(client3);
    FileExport export3 = new FileExport(clients, "port1", "sys", "rw", "root", "nfs");
    Assert.assertTrue("doExport failed", _unity.doExport(_device, args, Arrays.asList(export3)).getCommandStatus().equals(Operation.Status.ready.name()));
    Assert.assertTrue("doExport failed, export not added to FS", fs.getFsExports().keySet().size() == 2);
    // delete
    Assert.assertTrue("doDeleteFs failed", _unity.doDeleteFS(_device, args).getCommandStatus().equals(Operation.Status.ready.name()));
    VNXeApiClient apiclient = _unity.getVnxUnityClient(_device);
    try {
        apiclient.getFileSystemByFSName(args.getFsLabel());
        Assert.assertTrue("File system delete failed: " + args.getFsLabel(), false);
    } catch (VNXeException uex) {
        System.out.println("doDeleteFS --- delete FS success: " + uex.getCause());
    }
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) ArrayList(java.util.ArrayList) FileExport(com.emc.storageos.db.client.model.FileExport) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) Test(org.junit.Test)

Example 43 with SMBFileShare

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

the class CifsShareUtility method doesShareExist.

/**
 * Checks whether share exists in the file object
 *
 * @param fileObject fileshare or snapshot object
 * @param shareName name of the share
 * @return true if share exists in the SMBShareMap, false otherwise
 */
public static boolean doesShareExist(FileObject fileObject, String shareName) {
    SMBShareMap existingShares = fileObject.getSMBFileShares();
    if (existingShares != null && !existingShares.isEmpty()) {
        SMBFileShare existingShare = existingShares.get(shareName);
        if (existingShare != null) {
            _log.info("CIFS share: {}, exists in ", shareName, fileObject.getId());
            return true;
        }
    }
    _log.info("CIFS share: {}, does not exist in {}", shareName, fileObject.getId());
    return false;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 44 with SMBFileShare

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

the class FileDeviceController method share.

@Override
public void share(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("Create 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"));
        _log.info("Path {}", smbShare.getPath());
        // get db object for smb share
        SMBFileShare smbFileShare = smbShare.getSMBFileShare();
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        args.setOpId(opId);
        if (URIUtil.isType(uri, FileShare.class)) {
            fsObj = _dbClient.queryObject(FileShare.class, uri);
            fileObject = fsObj;
            args.addFSFileObject(fsObj);
            args.setFileOperation(true);
            setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
            // Acquire lock for VNXFILE Storage System
            WorkflowStepCompleter.stepExecuting(opId);
            acquireStepLock(storageObj, opId);
            BiosCommandResult result = getDevice(storageObj.getSystemType()).doShare(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);
            List<SMBFileShare> shares = new ArrayList<SMBFileShare>();
            shares.add(smbFileShare);
            if (result.isCommandSuccess()) {
                _log.info("File share created successfully");
                createDefaultACEForSMBShare(uri, smbShare, storageObj.getSystemType());
                WorkflowStepCompleter.stepSucceded(opId);
            }
            String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_SHARE, result.isCommandSuccess(), eventMsg, getShareNameExtensions(shares), fsObj, smbShare);
        } else {
            snapshotObj = _dbClient.queryObject(Snapshot.class, uri);
            fileObject = snapshotObj;
            args.addSnapshotFileObject(snapshotObj);
            fsObj = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            args.addFileShare(fsObj);
            args.setFileOperation(false);
            setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
            WorkflowStepCompleter.stepExecuting(opId);
            // Acquire lock for VNXFILE Storage System
            acquireStepLock(storageObj, opId);
            BiosCommandResult result = getDevice(storageObj.getSystemType()).doShare(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);
            List<SMBFileShare> shares = new ArrayList<SMBFileShare>();
            shares.add(smbFileShare);
            if (result.isCommandSuccess()) {
                _log.info("File snapshot share created successfully");
                WorkflowStepCompleter.stepSucceded(opId);
                createDefaultACEForSMBShare(uri, smbShare, storageObj.getSystemType());
            }
            String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE, result.isCommandSuccess(), eventMsg, getShareNameExtensions(shares), snapshotObj, fsObj, smbShare);
        }
    } catch (Exception e) {
        String[] params = { storage.toString(), uri.toString(), smbShare.getName(), e.getMessage() };
        _log.error("Unable to create file system or snapshot share: storage {}, FS/snapshot URI {}, SMB share {}: {}", params);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        updateTaskStatus(opId, fileObject, e);
        if (URIUtil.isType(uri, FileShare.class)) {
            if ((fsObj != null) && (storageObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_SHARE, false, e.getMessage(), "", fsObj, smbShare, storageObj);
            }
        } else {
            if ((fsObj != null) && (storageObj != null) && (snapshotObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE, false, e.getMessage(), "", snapshotObj, fsObj, smbShare, storageObj);
            }
        }
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 45 with SMBFileShare

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

the class FileDeviceController method createDefaultACEForSMBShare.

/**
 * Creates default share ACE for fileshares on VNXe, VXFile and Datadomain
 *
 * @param id
 *            URI of filesystem or snapshot
 * @param fileShare
 * @param storageType
 */
private void createDefaultACEForSMBShare(URI id, FileSMBShare fileShare, String storageType) {
    StorageSystem.Type storageSystemType = StorageSystem.Type.valueOf(storageType);
    if (storageSystemType.equals(Type.vnxe) || storageSystemType.equals(Type.vnxfile) || storageSystemType.equals(Type.datadomain)) {
        SMBFileShare share = fileShare.getSMBFileShare();
        CifsShareACL ace = new CifsShareACL();
        ace.setUser(FileControllerConstants.CIFS_SHARE_USER_EVERYONE);
        String permission = null;
        switch(share.getPermission()) {
            case "read":
                permission = FileControllerConstants.CIFS_SHARE_PERMISSION_READ;
                break;
            case "change":
                permission = FileControllerConstants.CIFS_SHARE_PERMISSION_CHANGE;
                break;
            case "full":
                permission = FileControllerConstants.CIFS_SHARE_PERMISSION_FULLCONTROL;
                break;
        }
        ace.setPermission(permission);
        ace.setId(URIUtil.createId(CifsShareACL.class));
        ace.setShareName(share.getName());
        if (URIUtil.isType(id, FileShare.class)) {
            ace.setFileSystemId(id);
        } else {
            ace.setSnapshotId(id);
        }
        _log.info("Creating default ACE for the share: {}", ace);
        _dbClient.createObject(ace);
    }
}
Also used : SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL)

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