Search in sources :

Example 11 with OperationTypeEnum

use of com.emc.storageos.services.OperationTypeEnum in project coprhd-controller by CoprHD.

the class FileDeviceController method unassignFileSystemSnapshotPolicy.

@Override
public void unassignFileSystemSnapshotPolicy(URI storage, URI fsURI, URI policy, String opId) throws InternalException {
    ControllerUtils.setThreadLocalLogData(fsURI, opId);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    FileShare fs = null;
    try {
        fs = _dbClient.queryObject(FileShare.class, fsURI);
        SchedulePolicy fp = _dbClient.queryObject(SchedulePolicy.class, policy);
        if (fs != null && fp != null) {
            StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
            _log.info("Controller Recieved File Policy  {}", policy);
            args.addFSFileObject(fs);
            args.setFileSystemPath(fs.getPath());
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
            args.addFilePolicy(fp);
            args.setFileOperation(true);
            args.setOpId(opId);
            // Do the Operation on device.
            BiosCommandResult result = getDevice(storageObj.getSystemType()).unassignFilePolicy(storageObj, args);
            if (result.isCommandSuccess()) {
                // Update FS database
                StringSet fpolicies = fs.getFilePolicies();
                if (fpolicies != null && fpolicies.contains(policy.toString())) {
                    fpolicies.remove(policy.toString());
                    fs.setFilePolicies(fpolicies);
                }
                // Update SchedulePolicy database
                StringSet resources = fp.getAssignedResources();
                if (resources != null && resources.contains(fs.getId().toString())) {
                    resources.remove(fs.getId().toString());
                    fp.setAssignedResources(resources);
                }
            }
            if (result.getCommandPending()) {
                return;
            }
            // Audit & Update the task status
            OperationTypeEnum auditType = null;
            auditType = OperationTypeEnum.UNASSIGN_FILE_SYSTEM_SNAPSHOT_SCHEDULE;
            fs.getOpStatus().updateTaskStatus(opId, result.toOperation());
            // Monitoring - Event Processing
            String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), fs, fp);
            _dbClient.updateObject(fs);
            _dbClient.updateObject(fp);
        } else {
            throw DeviceControllerException.exceptions.invalidObjectNull();
        }
    } catch (Exception e) {
        String[] params = { storage.toString(), fsURI.toString(), e.getMessage() };
        _log.error("Unable to Unassign policy : storage {}, FS URI {},: Error {}", params);
        updateTaskStatus(opId, fs, e);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) StringSet(com.emc.storageos.db.client.model.StringSet) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) 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 12 with OperationTypeEnum

use of com.emc.storageos.services.OperationTypeEnum in project coprhd-controller by CoprHD.

the class FileDeviceController method updateExportRules.

@Override
public void updateExportRules(URI storage, URI fsURI, FileExportUpdateParams param, String opId) throws ControllerException {
    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.setAllExportRules(param);
        if (null != param.getBypassDnsCheck()) {
            args.setBypassDnsCheck(param.getBypassDnsCheck());
        } else {
            args.setBypassDnsCheck(false);
        }
        _log.info("Controller Recieved FileExportUpdateParams {}", param);
        // File
        if (URIUtil.isType(fsURI, FileShare.class)) {
            isFile = true;
            fs = _dbClient.queryObject(FileShare.class, fsURI);
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
            fsObj = fs;
            args.addFSFileObject(fs);
            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());
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
            args.addFileShare(fs);
            args.addSnapshotFileObject(snapshotObj);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
        }
        args.setFileOperation(isFile);
        args.setOpId(opId);
        // Query & Pass all Existing Exports
        args.setExistingDBExportRules(queryExports(args));
        // Acquire lock for VNXFILE Storage System
        acquireStepLock(storageObj, opId);
        WorkflowStepCompleter.stepExecuting(opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).updateExportRules(storageObj, args);
        if (result.isCommandSuccess()) {
            // Update Database
            doCRUDExports(param, fs, args);
            // Delete the Export Map, if there are no exports.
            if ((args.getFileObjExports() != null) && (queryExports(args).isEmpty())) {
                args.getFileObjExports().clear();
                _dbClient.updateObject(args.getFileObj());
            }
            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.EXPORT_FILE_SYSTEM : OperationTypeEnum.EXPORT_FILE_SNAPSHOT;
        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
        // Monitoring - Event Processing
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        if (isFile) {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportNewClientExtensions(param.retrieveAllExports()), fs, storageObj);
        } else {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportNewClientExtensions(param.retrieveAllExports()), 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 export file system or snapshot: storage {}, FS/snapshot URI {}", params, e);
        _log.error("{}, {} ", e.getMessage(), e);
        updateTaskStatus(opId, fsObj, e);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) 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) FileObject(com.emc.storageos.db.client.model.FileObject) 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

OperationTypeEnum (com.emc.storageos.services.OperationTypeEnum)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 FileShare (com.emc.storageos.db.client.model.FileShare)9 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)9 StoragePool (com.emc.storageos.db.client.model.StoragePool)9 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)9 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)9 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)9 ControllerException (com.emc.storageos.volumecontroller.ControllerException)9 FileDeviceInputOutput (com.emc.storageos.volumecontroller.FileDeviceInputOutput)9 WorkflowException (com.emc.storageos.workflow.WorkflowException)9 URISyntaxException (java.net.URISyntaxException)9 FileObject (com.emc.storageos.db.client.model.FileObject)7 Snapshot (com.emc.storageos.db.client.model.Snapshot)7 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 ArrayList (java.util.ArrayList)5 URI (java.net.URI)3 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)2 FileExport (com.emc.storageos.db.client.model.FileExport)2