Search in sources :

Example 16 with FileShare

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

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

the class FileDeviceController method addStepsForCreateFileSystems.

@Override
public String addStepsForCreateFileSystems(Workflow workflow, String waitFor, List<FileDescriptor> filesystems, String taskId) throws InternalException {
    if (filesystems != null && !filesystems.isEmpty()) {
        // create source filesystems
        List<FileDescriptor> sourceDescriptors = FileDescriptor.filterByType(filesystems, FileDescriptor.Type.FILE_DATA, FileDescriptor.Type.FILE_MIRROR_SOURCE);
        for (FileDescriptor sourceDescriptor : sourceDescriptors) {
            // create a step
            waitFor = workflow.createStep(CREATE_FILESYSTEMS_STEP, String.format("Creating File systems:%n%s", taskId), null, sourceDescriptor.getDeviceURI(), getDeviceType(sourceDescriptor.getDeviceURI()), this.getClass(), createFileSharesMethod(sourceDescriptor), rollbackMethodNullMethod(), null);
        }
        // create targetFileystems
        List<FileDescriptor> targetDescriptors = FileDescriptor.filterByType(filesystems, FileDescriptor.Type.FILE_MIRROR_TARGET);
        if (targetDescriptors != null && !targetDescriptors.isEmpty()) {
            for (FileDescriptor descriptor : targetDescriptors) {
                FileShare fileShare = _dbClient.queryObject(FileShare.class, descriptor.getFsURI());
                FileShare fileShareSource = _dbClient.queryObject(FileShare.class, fileShare.getParentFileShare().getURI());
                if (fileShare.getParentFileShare() != null) {
                    waitFor = workflow.createStep(CREATE_FILESYSTEMS_STEP, String.format("Creating Target File systems:%n%s", taskId), waitFor, descriptor.getDeviceURI(), getDeviceType(descriptor.getDeviceURI()), this.getClass(), createFileSharesMethod(descriptor), rollbackCreateFileSharesMethod(fileShareSource.getStorageDevice(), asList(fileShare.getParentFileShare().getURI()), sourceDescriptors), null);
                }
            }
        }
    }
    // find out which value we should return
    return waitFor = CREATE_FILESYSTEMS_STEP;
}
Also used : FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileDescriptor(com.emc.storageos.fileorchestrationcontroller.FileDescriptor)

Example 18 with FileShare

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

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

the class FileDeviceController method createReduceFileshareStep.

/**
 * Reduce File System Step
 *
 * @param workflow
 * @param waitFor
 * @param fileDescriptors
 * @param taskId
 * @return
 */
private String createReduceFileshareStep(Workflow workflow, String waitFor, List<FileDescriptor> fileDescriptors, String taskId) {
    _log.info("START Reduce file system");
    Map<URI, Long> filesharesToReduce = new HashMap<URI, Long>();
    for (FileDescriptor descriptor : fileDescriptors) {
        FileShare fileShare = _dbClient.queryObject(FileShare.class, descriptor.getFsURI());
        if (fileShare.getCapacity() != null && fileShare.getCapacity().longValue() != 0) {
            filesharesToReduce.put(fileShare.getId(), descriptor.getFileSize());
        }
    }
    Workflow.Method reduceMethod = null;
    for (Map.Entry<URI, Long> entry : filesharesToReduce.entrySet()) {
        _log.info("Creating WF step for Reduce FileShare for  {}", entry.getKey().toString());
        FileShare fileShareToReduce = _dbClient.queryObject(FileShare.class, entry.getKey());
        StorageSystem storage = _dbClient.queryObject(StorageSystem.class, fileShareToReduce.getStorageDevice());
        Long fileSize = entry.getValue();
        reduceMethod = reduceFileSharesMethod(storage.getId(), fileShareToReduce.getId(), fileSize);
        waitFor = workflow.createStep(REDUCE_FILESYSTEMS_STEP, String.format("Reduce FileShare %s", fileShareToReduce), waitFor, storage.getId(), storage.getSystemType(), getClass(), reduceMethod, null, null);
        _log.info("Creating workflow step {}", REDUCE_FILESYSTEMS_STEP);
    }
    return waitFor;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Workflow(com.emc.storageos.workflow.Workflow) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileDescriptor(com.emc.storageos.fileorchestrationcontroller.FileDescriptor) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 20 with FileShare

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

the class FileDeviceController method updateQuotaDirectory.

@Override
public void updateQuotaDirectory(URI storage, FileShareQuotaDirectory quotaDir, URI fs, String task) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fs, task);
    FileShare fsObj = null;
    StorageSystem storageObj = null;
    QuotaDirectory quotaDirObj = null;
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    try {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString() };
        _log.info("FileDeviceController::updateQtree:  storage : {}, fs : {}, quotaDir : {}", params);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
        if (null != quotaDir.getSize()) {
            quotaDirObj.setSize(quotaDir.getSize());
        }
        quotaDirObj.setSoftLimit(quotaDir.getSoftLimit());
        quotaDirObj.setSoftGrace(quotaDir.getSoftGrace());
        quotaDirObj.setNotificationLimit(quotaDir.getNotificationLimit());
        if (null != quotaDir.getOpLock()) {
            quotaDirObj.setOpLock(quotaDir.getOpLock());
        }
        if (null != quotaDir.getSecurityStyle()) {
            quotaDirObj.setSecurityStyle(quotaDir.getSecurityStyle());
        }
        // Set up args
        args.addFileShare(fsObj);
        args.addQuotaDirectory(quotaDirObj);
        args.setOpId(task);
        FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
        BiosCommandResult result = nasDevice.doUpdateQuotaDirectory(storageObj, args, quotaDirObj);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            _log.error("FileDeviceController::updateQtree: QuotaDirectory update command is not successful");
            // The quota object was already modified with changes.
            // if it fail to update the quota directory,
            // restore the object with the original quota directory!!!
            quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
        }
        quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsObj.getName()));
        fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        // save the task status into db
        _dbClient.updateObject(quotaDirObj);
        _dbClient.updateObject(fsObj);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        _log.debug("FileDeviceController::updateQtree: After QuotaDirectory updated and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.UPDATE_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::updateQtree: Unable to update file system quotaDir: storage {}, FS {}, snapshot {}: {}", params);
        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) 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