Search in sources :

Example 16 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method createNtpShare.

/**
 * create NetApp share with right permissions
 *
 * @param StorageSystem mount path of the fileshare
 * @param args containing input/out arguments of filedevice
 * @param smbFileShare smbFileshare object
 * @param forceGroup Name of the group the fileshare belongs.
 * @return
 */
private Boolean createNtpShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare, String forceGroup) throws NetAppException {
    String shareId = null;
    String portGroup = findVfilerName(args.getFs());
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
    shareId = smbFileShare.getPath();
    _log.info("NetAppFileStorageDevice doShare for {} with id {}", shareId, args.getFileObjId());
    if (!nApi.doShare(shareId, smbFileShare.getName(), smbFileShare.getDescription(), smbFileShare.getMaxUsers(), smbFileShare.getPermission(), forceGroup)) {
        _log.info("NetAppFileStorageDevice doShare for {} with id {} - failed", shareId, args.getFileObjId());
        return false;
    } else {
        // share creation is successful,no need to set permission,clear the default one.
        List<CifsAcl> existingAcls = new ArrayList<CifsAcl>();
        CifsAcl defaultAcl = new CifsAcl();
        // By default NetApp share get everyone full access.
        defaultAcl.setUserName("everyone");
        defaultAcl.setAccess(CifsAccess.full);
        existingAcls.add(defaultAcl);
        nApi.deleteCIFSShareAcl(smbFileShare.getName(), existingAcls);
        smbFileShare.setNativeId(shareId);
        if (null != args.getFileObj()) {
            nApi.setQtreemode(args.getFsPath(), NTFS_QTREE_SETTING);
        }
        smbFileShare.setNetBIOSName(nApi.getNetBiosName());
        _log.info("NetAppFileStorageDevice doShare for {} with id {} - complete", shareId, args.getFileObjId());
        return true;
    }
}
Also used : CifsAcl(com.iwave.ext.netapp.model.CifsAcl) ArrayList(java.util.ArrayList) NetAppApi(com.emc.storageos.netapp.NetAppApi)

Example 17 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method doCreateQuotaDirectory.

// New Qtree methods
@Override
public BiosCommandResult doCreateQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args, QuotaDirectory qtree) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppFileStorageDevice doCreateQuotaDirectory - start");
        // Using NetApp terminology here
        String volName = args.getFsName();
        String qtreeName = args.getQuotaDirectoryName();
        Boolean oplocks = qtree.getOpLock();
        String securityStyle = qtree.getSecurityStyle();
        Long size = qtree.getSize();
        if (null == volName) {
            _log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
            serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (null == qtreeName) {
            _log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed:  Qtree name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
            serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (!validQuotaDirectoryPath(volName, qtreeName)) {
            _log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed:  Qtree name or path is too long");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
            serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_PATH_TOO_LONG);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        String portGroup = findVfilerName(args.getFs());
        _log.info("NetAppFileStorageDevice::NetAppFileStorageDevice - For FS: {}, vFiler: {}", volName, portGroup);
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        nApi.createQtree(qtreeName, volName, oplocks, securityStyle, size, portGroup);
        result = BiosCommandResult.createSuccessfulResult();
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed with a NetAppException", e);
        _log.info("NetAppFileStorageDevice::doCreateQuotaDirectory e.getLocalizedMessage(): {}", e.getLocalizedMessage());
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateQtree();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppApi(com.emc.storageos.netapp.NetAppApi) NetAppException(com.emc.storageos.netapp.NetAppException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 18 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method deleteExportRules.

@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
    List<ExportRule> allExports = args.getExistingDBExportRules();
    String subDir = args.getSubDirectory();
    boolean allDirs = args.isAllDir();
    FileShare fs = args.getFs();
    String exportPath;
    String subDirExportPath = "";
    subDir = args.getSubDirectory();
    if (!args.getFileOperation()) {
        exportPath = args.getSnapshotPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getSnapshotPath() + "/" + subDir;
        }
    } else {
        exportPath = args.getFs().getPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getFs().getPath() + "/" + subDir;
        }
    }
    _log.info("exportPath : {}", exportPath);
    args.setExportPath(exportPath);
    _log.info("Number of existing exports found {}", allExports.size());
    try {
        if (allDirs) {
            Set<String> allPaths = new HashSet<String>();
            // ALL EXPORTS
            _log.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
            for (ExportRule rule : allExports) {
                allPaths.add(rule.getExportPath());
            }
            for (String path : allPaths) {
                _log.info("deleting export path : {} ", path);
                nApi.deleteNFSExport(path);
            }
        } else if (subDir != null && !subDir.isEmpty()) {
            // Filter for a specific Sub Directory export
            _log.info("Deleting all subdir exports rules at ViPR and  sub directory export at device {}", subDir);
            for (ExportRule rule : allExports) {
                if (rule.getExportPath().endsWith("/" + subDir)) {
                    nApi.deleteNFSExport(subDirExportPath);
                    break;
                }
            }
        } else {
            // Filter for No SUBDIR - main export rules with no sub dirs
            _log.info("Deleting all export rules  from DB and export at device not included sub dirs");
            nApi.deleteNFSExport(exportPath);
        }
    } catch (NetAppException e) {
        _log.info("Exception:" + e.getMessage());
        throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
    }
    _log.info("NetAppFileStorageDevice exportFS {} - complete", args.getFsId());
    result.setCommandSuccess(true);
    result.setCommandStatus(Operation.Status.ready.name());
    return result;
}
Also used : FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) NetAppException(com.emc.storageos.netapp.NetAppException) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ExportRule(com.emc.storageos.model.file.ExportRule) NetAppApi(com.emc.storageos.netapp.NetAppApi) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Example 19 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method rollbackShareACLs.

private BiosCommandResult rollbackShareACLs(StorageSystem storage, FileDeviceInputOutput args, List<ShareACL> existingList) {
    BiosCommandResult result = new BiosCommandResult();
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
    try {
        // We can have multiple ace added/modified in one put call ,some of them can fail due to some reason.
        // In case of failure, to make it consistent in vipr db and NetApp share, delete all currently
        // added and modified ace and revert it to old acl.
        _log.info("NetAppFileStorageDevice::Rolling back update ACL by trying delete ACL for share {}", args.getShareName());
        List<ShareACL> aclsToClear = new ArrayList<ShareACL>();
        aclsToClear.addAll(args.getShareAclsToAdd());
        aclsToClear.addAll(args.getShareAclsToModify());
        forceDeleteShareAcl(nApi, args.getShareName(), aclsToClear);
        _log.info("NetAppFileStorageDevice::Adding back old ACL to Share {}", args.getShareName());
        forceAddShareAcl(nApi, args.getShareName(), existingList);
        result = BiosCommandResult.createSuccessfulResult();
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::Roll Back of ACL failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToUpdateCIFSShareAcl();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ArrayList(java.util.ArrayList) NetAppApi(com.emc.storageos.netapp.NetAppApi) ShareACL(com.emc.storageos.model.file.ShareACL) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 20 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method doSnapshotFS.

@Override
public BiosCommandResult doSnapshotFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppFileStorageDevice doSnapshotFS - start");
        if (null == args.getFsName()) {
            _log.error("NetAppFileStorageDevice::doSnapshotFS failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
            serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (null == args.getSnapshotName()) {
            _log.error("NetAppFileStorageDevice::doSnapshotFS failed:  Snapshot name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
            serviceError.setMessage(FileSystemConstants.FS_ERR_SNAPSHOT_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        boolean failedStatus = false;
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
        if (!nApi.createSnapshot(args.getFsName(), args.getSnapshotName())) {
            failedStatus = true;
        }
        if (failedStatus == true) {
            _log.error("NetAppFileStorageDevice doSnapshotFS {} - failed", args.getFsId());
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
            serviceError.setMessage(genDetailedMessage("doSnapshotFS", args.getFsName()));
            result = BiosCommandResult.createErrorResult(serviceError);
        } else {
            _log.info("doSnapshotFS - Snapshot, {}  was successfully created for filesystem, {} ", args.getSnapshotName(), args.getFsName());
            // Set snapshot Path and MountPath information
            args.setSnapshotMountPath(getSnapshotMountPath(args.getFsMountPath(), args.getSnapshotName()));
            args.setSnapshotPath(getSnapshotPath(args.getFsPath(), args.getSnapshotName()));
            args.setSnapNativeId(args.getSnapshotName());
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doSnapshotFS failed with a NetAppException", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::doSnapshotFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppApi(com.emc.storageos.netapp.NetAppApi) NetAppException(com.emc.storageos.netapp.NetAppException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Aggregations

NetAppApi (com.emc.storageos.netapp.NetAppApi)32 NetAppException (com.emc.storageos.netapp.NetAppException)26 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)18 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)18 ArrayList (java.util.ArrayList)15 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)14 ControllerException (com.emc.storageos.volumecontroller.ControllerException)14 HashMap (java.util.HashMap)11 URI (java.net.URI)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 NetAppFileCollectionException (com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)7 IOException (java.io.IOException)7 Map (java.util.Map)7 FileShare (com.emc.storageos.db.client.model.FileShare)6 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 VFilerInfo (com.iwave.ext.netapp.VFilerInfo)6 StringMap (com.emc.storageos.db.client.model.StringMap)5