Search in sources :

Example 6 with FileShare

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

the class FileDeviceController method resetReplicationFileSystemsRelation.

protected void resetReplicationFileSystemsRelation(FilePolicy filePolicy, PolicyStorageResource policyResource) {
    URI storageSystem = policyResource.getStorageSystem();
    String policyPath = policyResource.getResourcePath();
    // Remove the source - target relationship
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name())) {
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getStorageDeviceFileshareConstraint(storageSystem);
        List<FileShare> fileshares = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileShare.class, containmentConstraint);
        List<FileShare> modifiedFileshares = new ArrayList<>();
        for (FileShare fileshare : fileshares) {
            // should be decoupled!!!
            if (fileshare.getNativeId().startsWith(policyPath)) {
                if (fileshare.getPersonality() != null && fileshare.getPersonality().equalsIgnoreCase(PersonalityTypes.SOURCE.toString())) {
                    fileshare.setMirrorStatus(NullColumnValueGetter.getNullStr());
                    fileshare.setAccessState(NullColumnValueGetter.getNullStr());
                    fileshare.setPersonality(NullColumnValueGetter.getNullStr());
                    if (fileshare.getMirrorfsTargets() != null && !fileshare.getMirrorfsTargets().isEmpty()) {
                        StringSet targets = fileshare.getMirrorfsTargets();
                        for (String strTargetFs : targets) {
                            FileShare targetFs = _dbClient.queryObject(FileShare.class, URI.create(strTargetFs));
                            targetFs.setMirrorStatus(NullColumnValueGetter.getNullStr());
                            targetFs.setAccessState(NullColumnValueGetter.getNullStr());
                            targetFs.setParentFileShare(NullColumnValueGetter.getNullNamedURI());
                            targetFs.setPersonality(NullColumnValueGetter.getNullStr());
                            modifiedFileshares.add(targetFs);
                        }
                        targets.clear();
                        fileshare.setMirrorfsTargets(targets);
                    }
                }
                modifiedFileshares.add(fileshare);
            }
        }
        if (!modifiedFileshares.isEmpty()) {
            _dbClient.updateObject(modifiedFileshares);
        }
    }
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 7 with FileShare

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

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

the class FileDeviceController method expandFS.

@Override
public void expandFS(URI storage, URI uri, long newFSsize, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(uri, opId);
    FileShare fs = null;
    try {
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        fs = _dbClient.queryObject(FileShare.class, uri);
        args.addFSFileObject(fs);
        StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
        args.addStoragePool(pool);
        args.setFileOperation(true);
        args.setNewFSCapacity(newFSsize);
        args.setOpId(opId);
        // work flow and we need to add TaskCompleter(TBD for vnxfile)
        WorkflowStepCompleter.stepExecuting(opId);
        // Acquire lock for VNXFILE Storage System
        acquireStepLock(storageObj, opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doExpandFS(storageObj, args);
        if (result.getCommandPending()) {
            // async operation
            return;
        }
        if (result.isCommandSuccess()) {
            _log.info("FileSystem old capacity :" + args.getFsCapacity() + ":Expanded Size:" + args.getNewFSCapacity());
            args.setFsCapacity(args.getNewFSCapacity());
            _log.info("FileSystem new capacity :" + args.getFsCapacity());
            WorkflowStepCompleter.stepSucceded(opId);
        } else if (!result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        // Set status
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        fs.getOpStatus().updateTaskStatus(opId, result.toOperation());
        _dbClient.updateObject(fs);
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.EXPAND_FILE_SYSTEM, result.isCommandSuccess(), eventMsg, "", fs, String.valueOf(newFSsize));
    } catch (Exception e) {
        String[] params = { storage.toString(), uri.toString(), String.valueOf(newFSsize), e.getMessage() };
        _log.error("Unable to expand file system: storage {}, FS URI {}, size {}: {}", params);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        updateTaskStatus(opId, fs, e);
        if (fs != null) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.EXPAND_FILE_SYSTEM, false, e.getMessage(), "", fs, String.valueOf(newFSsize));
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 9 with FileShare

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

the class FileDeviceController method reduceFS.

@Override
public void reduceFS(URI storage, URI uri, long newFSsize, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(uri, opId);
    FileShare fs = null;
    StoragePool pool = null;
    StorageSystem storageObj = null;
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    try {
        fs = _dbClient.queryObject(FileShare.class, uri);
        pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        args.addFSFileObject(fs);
        args.addStoragePool(pool);
        args.setFileOperation(true);
        args.setNewFSCapacity(newFSsize);
        args.setOpId(opId);
        // work flow and we need to add TaskCompleter
        WorkflowStepCompleter.stepExecuting(opId);
        acquireStepLock(storageObj, opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doReduceFS(storageObj, args);
        if (result.getCommandPending()) {
            // async operation
            return;
        }
        if (result.isCommandSuccess()) {
            _log.info("FileSystem old capacity :" + args.getFsCapacity() + ":Reduced Size:" + args.getNewFSCapacity());
            args.setFsCapacity(args.getNewFSCapacity());
            WorkflowStepCompleter.stepSucceded(opId);
        } else if (!result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        // Set status
        fs.getOpStatus().updateTaskStatus(opId, result.toOperation());
        _dbClient.updateObject(fs);
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.REDUCE_FILE_SYSTEM, result.isCommandSuccess(), eventMsg, "", fs, String.valueOf(newFSsize));
    } catch (Exception e) {
        String[] params = { storage.toString(), uri.toString(), String.valueOf(newFSsize), e.getMessage() };
        _log.error("Unable to reduce file system: storage {}, FS URI {}, size {}: {}", params);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        updateTaskStatus(opId, fs, e);
        if (fs != null) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.REDUCE_FILE_SYSTEM, false, e.getMessage(), "", fs, String.valueOf(newFSsize));
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 10 with FileShare

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

the class FileDeviceController method deleteQuotaDirectory.

@Override
public void deleteQuotaDirectory(URI storage, URI quotaDir, URI fs, String task) throws ControllerException {
    FileShare fsObj = null;
    QuotaDirectory quotaDirObj = null;
    try {
        String[] params = { storage.toString(), quotaDir.toString(), fs.toString() };
        _log.info("FileDeviceController::deleteQuotaDirectory: storage : {}, quotadir : {}, fs : {}", params);
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        args.addFSFileObject(fsObj);
        args.addQuotaDirectory(quotaDirObj);
        args.setOpId(task);
        FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
        BiosCommandResult result = nasDevice.doDeleteQuotaDirectory(storageObj, args);
        if (result.getCommandPending()) {
            return;
        }
        fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        String fsName = fsObj.getName();
        quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsName));
        if (!result.isCommandSuccess()) {
            _log.error("FileDeviceController::deleteQuotaDirectory: command is not successfull");
        } else {
            // If delete operation is successful, then remove obj from ViPR db by setting inactive=true
            quotaDirObj.setInactive(true);
        }
        // save the task status in db
        _dbClient.updateObject(quotaDirObj);
        _dbClient.updateObject(fsObj);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        _log.debug("FileDeviceController::deleteQuotaDirectory: After deleteQuotaDirectory created and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM_QUOTA_DIR, result.isCommandSuccess(), eventMsg, "", quotaDirObj, fsObj);
    } catch (Exception e) {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString(), e.getMessage() };
        _log.error("FileDeviceController::deleteQuotaDirectory: Unable to create file system quota dir: storage {}, FS {}, quotadir {}: {}", params);
        updateTaskStatus(task, fsObj, e);
        updateTaskStatus(task, quotaDirObj, e);
        if ((fsObj != null) && (quotaDirObj != null)) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM_QUOTA_DIR, false, e.getMessage(), "", quotaDirObj, fsObj);
        }
    }
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) FileStorageDevice(com.emc.storageos.volumecontroller.FileStorageDevice) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

FileShare (com.emc.storageos.db.client.model.FileShare)289 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 URI (java.net.URI)93 ArrayList (java.util.ArrayList)79 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)73 ControllerException (com.emc.storageos.volumecontroller.ControllerException)65 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)61 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)57 Operation (com.emc.storageos.db.client.model.Operation)56 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)56 URISyntaxException (java.net.URISyntaxException)56 Path (javax.ws.rs.Path)56 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)52 Produces (javax.ws.rs.Produces)51 Snapshot (com.emc.storageos.db.client.model.Snapshot)50 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)49 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)45 WorkflowException (com.emc.storageos.workflow.WorkflowException)42 NamedURI (com.emc.storageos.db.client.model.NamedURI)36