Search in sources :

Example 11 with FileDeviceInputOutput

use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.

the class FileDeviceController method deleteExportRules.

@Override
public void deleteExportRules(URI storage, URI fileUri, boolean allDirs, String subDir, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fileUri, opId);
    FileObject fsObj = null;
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    FileShare fs = null;
    Snapshot snapshotObj = null;
    StorageSystem storageObj = null;
    boolean isFile = false;
    try {
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        // File
        if (URIUtil.isType(fileUri, FileShare.class)) {
            isFile = true;
            fs = _dbClient.queryObject(FileShare.class, fileUri);
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
            fsObj = fs;
            args.addFSFileObject(fs);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
            args.setAllDir(allDirs);
            args.setSubDirectory(subDir);
        } else {
            // Snapshot
            snapshotObj = _dbClient.queryObject(Snapshot.class, fileUri);
            fsObj = snapshotObj;
            fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
            args.addFileShare(fs);
            args.addSnapshotFileObject(snapshotObj);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
            args.setAllDir(true);
            args.setSubDirectory(null);
        }
        args.setFileOperation(isFile);
        args.setOpId(opId);
        List<ExportRule> existingExportRules = queryExports(args);
        args.setExistingDBExportRules(existingExportRules);
        // Do the Operation on device.
        _log.info("Delete Export Rules : request received for {}, with allDirs : {}, subDir : {}", new Object[] { fs.getId(), allDirs, subDir });
        acquireStepLock(storageObj, opId);
        WorkflowStepCompleter.stepExecuting(opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).deleteExportRules(storageObj, args);
        if (result.isCommandSuccess()) {
            // Update Database
            doDeleteExportRulesFromDB(allDirs, subDir, args);
            doDeleteExportsFromFSObjMap(allDirs, subDir, args);
            WorkflowStepCompleter.stepSucceded(opId);
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        // Audit & Update the task status
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
        if (isFile) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, result.isCommandSuccess(), eventMsg, "", fs, storageObj);
        } else {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, result.isCommandSuccess(), eventMsg, "", snapshotObj, fs, storageObj);
        }
        _dbClient.updateObject(fsObj);
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        String[] params = { storage.toString(), fileUri.toString() };
        _log.error("Unable to export file system or snapshot: storage {}, FS/snapshot URI {}", params);
        if ((fsObj != null) && (storageObj != null)) {
            if (URIUtil.isType(fileUri, FileShare.class)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
            } else {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
            }
        }
        updateTaskStatus(opId, fsObj, e);
    }
}
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) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 12 with FileDeviceInputOutput

use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.

the class FileDeviceController method modifyFS.

@Override
public void modifyFS(URI storage, URI pooluri, URI fsuri, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fsuri, opId);
    FileShare fs = null;
    try {
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        fs = _dbClient.queryObject(FileShare.class, fsuri);
        args.addFSFileObject(fs);
        StoragePool pool = _dbClient.queryObject(StoragePool.class, pooluri);
        args.addStoragePool(pool);
        args.setFileOperation(true);
        args.setOpId(opId);
        WorkflowStepCompleter.stepExecuting(opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doModifyFS(storageObj, args);
        if (result.getCommandPending()) {
            // async operation
            return;
        }
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(opId);
            _log.info("FileSystem updated " + " with Soft Limit: " + args.getFsSoftLimit() + ", Notification Limit: " + args.getFsNotificationLimit() + ", Soft Grace: " + args.getFsSoftGracePeriod());
        }
        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.UPDATE_FILE_SYSTEM, result.isCommandSuccess(), eventMsg, "", fs);
    } catch (Exception e) {
        _log.error("Unable to update file system: FS URI {}", fs.getId());
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        updateTaskStatus(opId, fs, e);
        if (fs != null) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.UPDATE_FILE_SYSTEM, false, e.getMessage(), "", fs);
        }
    }
}
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 13 with FileDeviceInputOutput

use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.

the class FileDeviceController method createQuotaDirectory.

@Override
public void createQuotaDirectory(URI storage, FileShareQuotaDirectory quotaDir, URI fs, String task) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fs, task);
    FileShare fsObj = null;
    QuotaDirectory quotaDirObj = null;
    try {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString() };
        _log.info("FileDeviceController::createQtree: create QuotaDirectory: storage : {}, quotaDir : {}, fs : {}", params);
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        URI qtreeURI = quotaDir.getId();
        quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, qtreeURI);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        // Set up args
        args.addFileShare(fsObj);
        args.addQuotaDirectory(quotaDirObj);
        args.setOpId(task);
        FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
        BiosCommandResult result = nasDevice.doCreateQuotaDirectory(storageObj, args, quotaDirObj);
        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));
        // In case of an error, set the quotaDir to an 'inactive' state.
        if (!result.isCommandSuccess()) {
            quotaDirObj.setInactive(true);
            _log.error("FileDeviceController::createQtree: QuotaDirectory create command is not successfull");
        }
        _dbClient.updateObject(quotaDirObj);
        _dbClient.updateObject(fsObj);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        _log.debug("FileDeviceController::createQtree: After QuotaDirectory created and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_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::createQtree: Unable to create file system quotaDir: storage {}, FS {}, snapshot {}: {}", params);
        // remove from DB
        if (quotaDirObj != null) {
            quotaDirObj.setInactive(true);
            _dbClient.updateObject(quotaDirObj);
        }
        updateTaskStatus(task, fsObj, e);
        updateTaskStatus(task, quotaDirObj, e);
        if ((fsObj != null) && (quotaDirObj != null)) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_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) URI(java.net.URI) 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 14 with FileDeviceInputOutput

use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.

the class FileDeviceController method updateNFSAcl.

@Override
public void updateNFSAcl(URI storage, URI fsURI, NfsACLUpdateParams param, String opId) throws InternalException {
    ControllerUtils.setThreadLocalLogData(fsURI, opId);
    FileObject fsObj = null;
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    FileShare fs = null;
    Snapshot snapshotObj = null;
    boolean isFile = false;
    try {
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        args.setSubDirectory(param.getSubDir());
        args.setAllNfsAcls(param);
        _log.info("Controller Recieved NfsACLUpdateParams {}", param);
        // File
        if (URIUtil.isType(fsURI, FileShare.class)) {
            isFile = true;
            fs = _dbClient.queryObject(FileShare.class, fsURI);
            fsObj = fs;
            args.addFSFileObject(fs);
            args.setFileSystemPath(fs.getPath());
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
        } else {
            // Snapshot
            snapshotObj = _dbClient.queryObject(Snapshot.class, fsURI);
            fsObj = snapshotObj;
            fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            args.addFileShare(fs);
            args.setFileSystemPath(fs.getPath());
            args.addSnapshotFileObject(snapshotObj);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
        }
        if (fs.getVirtualNAS() != null) {
            VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, fs.getVirtualNAS());
            if (vNas != null && !vNas.getInactive()) {
                args.setvNAS(vNas);
            }
        }
        args.setFileOperation(isFile);
        args.setOpId(opId);
        // Do the Operation on device.
        BiosCommandResult result = getDevice(storageObj.getSystemType()).updateNfsACLs(storageObj, args);
        if (result.isCommandSuccess()) {
            // Update Database
            updateNFSACLsInDB(param, fs, args);
            WorkflowStepCompleter.stepSucceded(opId);
        }
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        // Audit & Update the task status
        OperationTypeEnum auditType = null;
        auditType = (isFile) ? OperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL : OperationTypeEnum.UPDATE_FILE_SNAPSHOT_NFS_ACL;
        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
        // Monitoring - Event Processing
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        if (isFile) {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), fs, storageObj);
        } else {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), snapshotObj, fs, storageObj);
        }
        _dbClient.updateObject(fsObj);
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        String[] params = { storage.toString(), fsURI.toString() };
        _log.error("Unable to set ACL on  file system or snapshot: storage {}, FS/snapshot URI {}", params, e);
        _log.error("{}, {} ", e.getMessage(), e);
        updateTaskStatus(opId, fsObj, e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) 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) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 15 with FileDeviceInputOutput

use of com.emc.storageos.volumecontroller.FileDeviceInputOutput in project coprhd-controller by CoprHD.

the class FileDeviceController method unassignFilePolicy.

/**
 * @param storage
 * @param filePolicy
 *            URI of the file policy to be applied
 * @param policyStorageResource
 * @param opId
 * @throws ControllerException
 */
public void unassignFilePolicy(URI storage, URI policyURI, URI policyStorageResource, String opId) throws ControllerException {
    StorageSystem storageObj = null;
    FilePolicy filePolicy = null;
    PolicyStorageResource policyRes = null;
    try {
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        filePolicy = _dbClient.queryObject(FilePolicy.class, policyURI);
        policyRes = _dbClient.queryObject(PolicyStorageResource.class, policyStorageResource);
        args.setFileProtectionPolicy(filePolicy);
        args.setPolicyStorageResource(policyRes);
        WorkflowStepCompleter.stepExecuting(opId);
        _log.info("Unassigning file policy: {} from resource: {}", policyURI.toString(), policyRes.getAppliedAt().toString());
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doUnassignFilePolicy(storageObj, args);
        if (result.getCommandPending()) {
            return;
        } else if (result.isCommandSuccess()) {
            // decouple the replication relation for the policy!!
            resetReplicationFileSystemsRelation(filePolicy, policyRes);
            filePolicy.removePolicyStorageResources(policyRes.getId());
            _dbClient.markForDeletion(policyRes);
            _dbClient.updateObject(filePolicy);
            _log.info("Unassigning file policy: {} from resource: {} finished successfully", policyURI.toString(), policyRes.getAppliedAt().toString());
            WorkflowStepCompleter.stepSucceded(opId);
        } else {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) 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

FileDeviceInputOutput (com.emc.storageos.volumecontroller.FileDeviceInputOutput)48 FileShare (com.emc.storageos.db.client.model.FileShare)33 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)33 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)32 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)32 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)32 ControllerException (com.emc.storageos.volumecontroller.ControllerException)32 WorkflowException (com.emc.storageos.workflow.WorkflowException)32 URISyntaxException (java.net.URISyntaxException)32 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)25 StoragePool (com.emc.storageos.db.client.model.StoragePool)16 Snapshot (com.emc.storageos.db.client.model.Snapshot)15 FileObject (com.emc.storageos.db.client.model.FileObject)14 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)11 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)10 OperationTypeEnum (com.emc.storageos.services.OperationTypeEnum)9 FileExport (com.emc.storageos.db.client.model.FileExport)7