Search in sources :

Example 36 with FileDeviceInputOutput

use of com.emc.storageos.volumecontroller.FileDeviceInputOutput 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 37 with FileDeviceInputOutput

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

the class FileDeviceController method snapshotFS.

@Override
public void snapshotFS(URI storage, URI snapshot, URI fs, String task) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fs, task);
    FileShare fsObj = null;
    Snapshot snapshotObj = null;
    try {
        String[] params = { storage.toString(), snapshot.toString(), fs.toString() };
        _log.info("Snapshot FS: storage : {}, snapshot : {}, fs : {}", params);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        snapshotObj = _dbClient.queryObject(Snapshot.class, snapshot);
        args.addFileShare(fsObj);
        args.addSnapshot(snapshotObj);
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, fsObj.getPool());
        args.addStoragePool(storagePool);
        args.setOpId(task);
        // Acquire lock for VNXFILE Storage System
        acquireStepLock(storageObj, task);
        WorkflowStepCompleter.stepExecuting(task);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doSnapshotFS(storageObj, args);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(task, result.getServiceCoded());
        }
        snapshotObj.setCreationTime(Calendar.getInstance());
        fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        snapshotObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        snapshotObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, snapshotObj));
        // Incase error, set the snapshot to inactive state.
        if (!result.isCommandSuccess()) {
            _log.error("Snapshot create command is not successfull, so making object to inactive");
            snapshotObj.setInactive(true);
        }
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(task);
        }
        _dbClient.updateObject(snapshotObj);
        _dbClient.updateObject(fsObj);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_SNAPSHOT, result.isCommandSuccess(), eventMsg, "", snapshotObj, fsObj);
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(task, serviceError);
        String[] params = { storage.toString(), fs.toString(), snapshot.toString(), e.getMessage() };
        _log.error("Unable to create file system snapshot: storage {}, FS {}, snapshot {}: {}", params);
        updateTaskStatus(task, fsObj, e);
        updateTaskStatus(task, snapshotObj, e);
        if ((fsObj != null) && (snapshotObj != null)) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fsObj);
        }
    }
}
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) 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 38 with FileDeviceInputOutput

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

the class FileDeviceController method assignFileSnapshotPolicyToVirtualPools.

@Override
public void assignFileSnapshotPolicyToVirtualPools(URI storageSystemURI, URI vNASURI, URI filePolicyToAssign, URI vpoolURI, String opId) throws ControllerException {
    StorageSystem storageObj = null;
    FilePolicy filePolicy = null;
    VirtualNAS vNAS = null;
    VirtualPool vpool = null;
    try {
        WorkflowStepCompleter.stepExecuting(opId);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        storageObj = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
        filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
        vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
        if (vNASURI != null) {
            vNAS = _dbClient.queryObject(VirtualNAS.class, vNASURI);
            args.setvNAS(vNAS);
        }
        args.setFileProtectionPolicy(filePolicy);
        args.setVPool(vpool);
        _log.info("Assigning file snapshot policy: {} to vpool: {}", filePolicyToAssign, vpoolURI);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).checkFilePolicyExistsOrCreate(storageObj, args);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(opId);
        }
    } 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) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) 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 39 with FileDeviceInputOutput

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

the class FileDeviceController method applyFilePolicy.

@Override
public void applyFilePolicy(URI storage, URI sourceFS, URI policyURI, String taskId) throws ControllerException {
    FileShare fsObj = null;
    StorageSystem storageObj = null;
    try {
        fsObj = _dbClient.queryObject(FileShare.class, sourceFS);
        VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fsObj.getVirtualPool());
        Project project = _dbClient.queryObject(Project.class, fsObj.getProject());
        TenantOrg tenantOrg = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg());
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, policyURI);
        args.setOpId(taskId);
        args.addFSFileObject(fsObj);
        args.setVPool(vpool);
        args.setTenantOrg(tenantOrg);
        args.setProject(project);
        args.setFileProtectionPolicy(filePolicy);
        setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
        WorkflowStepCompleter.stepExecuting(taskId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doApplyFilePolicy(storageObj, args);
        if (result.getCommandPending()) {
            return;
        } else if (result.isCommandSuccess()) {
            _log.info("File policy: {} applied successfully", filePolicy.getFilePolicyName());
            WorkflowStepCompleter.stepSucceded(taskId);
        } else {
            WorkflowStepCompleter.stepFailed(taskId, result.getServiceCoded());
        }
    } catch (Exception e) {
        _log.error("Unable to apply file policy: {} to file system: {}", policyURI, fsObj.getId());
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(taskId, serviceError);
        updateTaskStatus(taskId, fsObj, e);
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) 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 40 with FileDeviceInputOutput

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

the class FileDeviceController method updateStorageSystemFileProtectionPolicy.

@Override
public void updateStorageSystemFileProtectionPolicy(URI storage, URI policy, URI policyRes, FilePolicyUpdateParam policyUpdateParam, String opId) throws InternalException {
    ControllerUtils.setThreadLocalLogData(policy, opId);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    try {
        FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, policy);
        PolicyStorageResource policyResource = _dbClient.queryObject(PolicyStorageResource.class, policyRes);
        if (filePolicy != null && policyResource != null) {
            StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
            _log.info("Updating File protection ile Policy  {}", policy);
            args.setFileProtectionPolicy(filePolicy);
            args.setPolicyStorageResource(policyResource);
            args.setFileProtectionPolicyUpdateParam(policyUpdateParam);
            args.setFileOperation(true);
            args.setOpId(opId);
            // Do the Operation on device.
            BiosCommandResult result = getDevice(storageObj.getSystemType()).updateStorageSystemFileProtectionPolicy(storageObj, args);
            if (!result.isCommandSuccess() && !result.getCommandPending()) {
                WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
            }
            if (result.isCommandSuccess()) {
                WorkflowStepCompleter.stepSucceded(opId);
            }
        } else {
            throw DeviceControllerException.exceptions.invalidObjectNull();
        }
    } 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