Search in sources :

Example 41 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method doShare.

@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    // Snapshot Share operation is not supported by ISILON.
    if (args.getFileOperation() == false) {
        return BiosCommandResult.createErrorResult(DeviceControllerErrors.isilon.unSupportedOperation(SHARE_OP_NAME));
    }
    try {
        _log.info("IsilonFileStorageDevice doShare() - start");
        IsilonApi isi = getIsilonDevice(storage);
        isiShare(isi, args, smbFileShare);
        _log.info("IsilonFileStorageDevice doShare() - complete");
        return BiosCommandResult.createSuccessfulResult();
    } catch (IsilonException e) {
        _log.error("doShare failed.", e);
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception e) {
        _log.error("doShare failed.", e);
        // convert this to a ServiceError and create/or reuse a service
        // code
        ServiceError serviceError = DeviceControllerErrors.isilon.unableToCreateFileShare();
        return BiosCommandResult.createErrorResult(serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 42 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method deleteShareACLs.

@Override
public BiosCommandResult deleteShareACLs(StorageSystem storage, FileDeviceInputOutput args) {
    IsilonApi isi = getIsilonDevice(storage);
    processAclsForShare(isi, args, null);
    BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
    return result;
}
Also used : BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi)

Example 43 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method extraShareACLFromArray.

/**
 * Get the Share ACL which are present in array but not in CoprHD Database.
 *
 * @param storage
 * @param args
 * @return Map with domain+ group or username with ShareACL
 */
private Map<String, ShareACL> extraShareACLFromArray(StorageSystem storage, FileDeviceInputOutput args) {
    // get all Share ACL from CoprHD data base
    List<ShareACL> existingDBShareACL = args.getExistingShareAcls();
    Map<String, ShareACL> arrayShareACLMap = new HashMap<>();
    // get the all the Share ACL from the storage system.
    IsilonApi isi = getIsilonDevice(storage);
    String zoneName = getZoneName(args.getvNAS());
    IsilonSMBShare share = null;
    if (zoneName != null) {
        share = isi.getShare(args.getShareName(), zoneName);
    } else {
        share = isi.getShare(args.getShareName());
    }
    if (share != null) {
        List<Permission> permissions = share.getPermissions();
        for (Permission perm : permissions) {
            if (perm.getPermissionType().equalsIgnoreCase(Permission.PERMISSION_TYPE_ALLOW)) {
                ShareACL shareACL = new ShareACL();
                shareACL.setPermission(perm.getPermission());
                String userAndDomain = perm.getTrustee().getName();
                String[] trustees = new String[2];
                trustees = userAndDomain.split("\\\\");
                String trusteesType = perm.getTrustee().getType();
                if (trustees.length > 1) {
                    shareACL.setDomain(trustees[0]);
                    if (trusteesType.equals("group")) {
                        shareACL.setGroup(trustees[1]);
                    } else {
                        shareACL.setUser(trustees[1]);
                    }
                } else {
                    if (trusteesType.equals("group")) {
                        shareACL.setGroup(trustees[0]);
                    } else {
                        shareACL.setUser(trustees[0]);
                    }
                }
                arrayShareACLMap.put(perm.getTrustee().getName(), shareACL);
            }
        }
        for (Iterator iterator = existingDBShareACL.iterator(); iterator.hasNext(); ) {
            ShareACL shareACL = (ShareACL) iterator.next();
            String key = "";
            String domain = "";
            String user = shareACL.getUser();
            String group = shareACL.getGroup();
            if (shareACL.getDomain() != null && !shareACL.getDomain().isEmpty()) {
                domain = shareACL.getDomain() + "\\";
            }
            if (user != null && !user.isEmpty()) {
                key = domain + user;
            } else if (group != null && !group.isEmpty()) {
                key = domain + group;
            }
            if (arrayShareACLMap.containsKey(key)) {
                arrayShareACLMap.remove(key);
            }
        }
    }
    return arrayShareACLMap;
}
Also used : HashMap(java.util.HashMap) IsilonSMBShare(com.emc.storageos.isilon.restapi.IsilonSMBShare) Permission(com.emc.storageos.isilon.restapi.IsilonSMBShare.Permission) Iterator(java.util.Iterator) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) ShareACL(com.emc.storageos.model.file.ShareACL)

Example 44 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method deleteExportRules.

@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    List<ExportRule> allExports = args.getExistingDBExportRules();
    String subDir = args.getSubDirectory();
    boolean allDirs = args.isAllDir();
    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 {
        IsilonApi isi = getIsilonDevice(storage);
        String zoneName = getZoneName(args.getvNAS());
        if (allDirs) {
            // 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) {
                _log.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
                if (zoneName != null) {
                    isi.deleteExport(rule.getDeviceExportId(), zoneName);
                } else {
                    isi.deleteExport(rule.getDeviceExportId());
                }
            }
        } 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) {
                _log.info("Delete IsilonExport id for path {} f containing subdirectory {}", rule.getDeviceExportId() + ":" + rule.getExportPath(), subDir);
                String fsExportPathWithSub = args.getFsPath() + "/" + subDir;
                if (rule.getExportPath().equalsIgnoreCase(fsExportPathWithSub)) {
                    _log.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
                    if (zoneName != null) {
                        isi.deleteExport(rule.getDeviceExportId(), zoneName);
                    } else {
                        isi.deleteExport(rule.getDeviceExportId());
                    }
                }
            }
        } 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");
            for (ExportRule rule : allExports) {
                if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
                    _log.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
                    if (zoneName != null) {
                        isi.deleteExport(rule.getDeviceExportId(), zoneName);
                    } else {
                        isi.deleteExport(rule.getDeviceExportId());
                    }
                }
            }
        }
    } catch (IsilonException ie) {
        _log.info("Exception: {}", ie);
        throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
    }
    _log.info("IsilonFileStorageDevice exportFS {} - complete", args.getFsId());
    result.setCommandSuccess(true);
    result.setCommandStatus(Operation.Status.ready.name());
    return result;
}
Also used : BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ExportRule(com.emc.storageos.model.file.ExportRule) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 45 with IsilonApi

use of com.emc.storageos.isilon.restapi.IsilonApi in project coprhd-controller by CoprHD.

the class IsilonFileStorageDevice method updateShareACLs.

@Override
public BiosCommandResult updateShareACLs(StorageSystem storage, FileDeviceInputOutput args) {
    // Requested Share ACL
    List<ShareACL> aclsToAdd = args.getShareAclsToAdd();
    List<ShareACL> aclsToDelete = args.getShareAclsToDelete();
    List<ShareACL> aclsToModify = args.getShareAclsToModify();
    Map<String, ShareACL> arrayExtraShareACL = null;
    try {
        boolean cifsSidEnable = customConfigHandler.getComputedCustomConfigBooleanValue(CustomConfigConstants.ISILON_USER_TO_SID_MAPPING_FOR_CIFS_SHARE_ENABLED, storage.getSystemType(), null);
        // add the new Share ACL from the array into the add request.
        if (cifsSidEnable) {
            arrayExtraShareACL = extraShareACLBySidFromArray(storage, args);
        } else {
            arrayExtraShareACL = extraShareACLFromArray(storage, args);
        }
        _log.info("Number of extra ACLs found on array  is: {}", arrayExtraShareACL.size());
        if (!arrayExtraShareACL.isEmpty()) {
            if (aclsToAdd != null) {
                // now add the remaining Share ACL
                aclsToAdd.addAll(arrayExtraShareACL.values());
            } else {
                // if add acl is null then create a new Share ACL and add
                aclsToAdd = new ArrayList<ShareACL>();
                aclsToAdd.addAll(arrayExtraShareACL.values());
                // update the args so new acl get persisted in CoprHD DB.
                args.setShareAclsToAdd(aclsToAdd);
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        _log.error("Not able to fetch latest Share ACL from backend array.", e);
    }
    // Get existing Acls for the share
    List<ShareACL> aclsToProcess = args.getExistingShareAcls();
    _log.info("Share name : {}", args.getShareName());
    // Process Acls
    _log.info("Number of existing ACLs found {}", aclsToProcess.size());
    // Process ACLs to add
    aclsToProcess.addAll(aclsToAdd);
    // Process ACLs to modify
    for (ShareACL existingAcl : aclsToProcess) {
        String domainOfExistingAce = existingAcl.getDomain();
        if (domainOfExistingAce == null) {
            domainOfExistingAce = "";
        }
        for (ShareACL aclToModify : aclsToModify) {
            String domainOfmodifiedAce = aclToModify.getDomain();
            if (domainOfmodifiedAce == null) {
                domainOfmodifiedAce = "";
            }
            if (aclToModify.getUser() != null && existingAcl.getUser() != null) {
                if (domainOfExistingAce.concat(existingAcl.getUser()).equalsIgnoreCase(domainOfmodifiedAce.concat(aclToModify.getUser()))) {
                    existingAcl.setPermission(aclToModify.getPermission());
                }
            }
            if (aclToModify.getGroup() != null && existingAcl.getGroup() != null) {
                if (domainOfExistingAce.concat(existingAcl.getGroup()).equalsIgnoreCase(domainOfmodifiedAce.concat(aclToModify.getGroup()))) {
                    existingAcl.setPermission(aclToModify.getPermission());
                }
            }
        }
    }
    // Process ACLs to delete
    for (ShareACL aclToDelete : aclsToDelete) {
        String domainOfDeleteAce = aclToDelete.getDomain();
        if (domainOfDeleteAce == null) {
            domainOfDeleteAce = "";
        }
        for (Iterator<ShareACL> iterator = aclsToProcess.iterator(); iterator.hasNext(); ) {
            ShareACL existingAcl = iterator.next();
            String domainOfExistingAce = existingAcl.getDomain();
            if (domainOfExistingAce == null) {
                domainOfExistingAce = "";
            }
            if (aclToDelete.getUser() != null && existingAcl.getUser() != null) {
                if (domainOfDeleteAce.concat(aclToDelete.getUser()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getUser()))) {
                    iterator.remove();
                }
            }
            if (aclToDelete.getGroup() != null && existingAcl.getGroup() != null) {
                if (domainOfDeleteAce.concat(aclToDelete.getGroup()).equalsIgnoreCase(domainOfExistingAce.concat(existingAcl.getGroup()))) {
                    iterator.remove();
                }
            }
        }
    }
    // Process new ACLs
    IsilonApi isi = getIsilonDevice(storage);
    processAclsForShare(isi, args, aclsToProcess);
    BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
    return result;
}
Also used : BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) ShareACL(com.emc.storageos.model.file.ShareACL) IsilonException(com.emc.storageos.isilon.restapi.IsilonException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException)

Aggregations

IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)81 IsilonException (com.emc.storageos.isilon.restapi.IsilonException)64 URISyntaxException (java.net.URISyntaxException)31 URI (java.net.URI)22 IsilonCollectionException (com.emc.storageos.plugins.metering.isilon.IsilonCollectionException)21 ArrayList (java.util.ArrayList)18 IsilonSyncPolicy (com.emc.storageos.isilon.restapi.IsilonSyncPolicy)14 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)12 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 IOException (java.io.IOException)12 JSONException (org.codehaus.jettison.json.JSONException)12 FileShare (com.emc.storageos.db.client.model.FileShare)11 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)11 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)10 HashMap (java.util.HashMap)10 ControllerException (com.emc.storageos.volumecontroller.ControllerException)9 Test (org.junit.Test)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7