Search in sources :

Example 1 with IsilonExport

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

the class IsilonFileStorageDevice method setIsilonExport.

private IsilonExport setIsilonExport(ExportRule expRule) {
    // String permissions, List<String> securityType, String root_user,
    // String mountPath, String comments) {
    _log.info("setIsilonExport called with {}", expRule.toString());
    String mountPath = expRule.getExportPath();
    String comments = "";
    String root_user = expRule.getAnon();
    IsilonExport newIsilonExport = new IsilonExport();
    newIsilonExport.addPath(mountPath);
    newIsilonExport.setComment(comments);
    int roHosts = 0;
    int rwHosts = 0;
    int rootHosts = 0;
    // Empty list of clients means --- all clients.
    if (expRule.getReadOnlyHosts() != null) {
        newIsilonExport.addClients(new ArrayList<String>(expRule.getReadOnlyHosts()));
        roHosts = expRule.getReadOnlyHosts().size();
        newIsilonExport.addReadOnlyClients(new ArrayList<String>(expRule.getReadOnlyHosts()));
    }
    if (expRule.getReadWriteHosts() != null) {
        newIsilonExport.addClients(new ArrayList<String>(expRule.getReadWriteHosts()));
        rwHosts = expRule.getReadWriteHosts().size();
        newIsilonExport.addReadWriteClients(new ArrayList<String>(expRule.getReadWriteHosts()));
    }
    if (expRule.getRootHosts() != null) {
        newIsilonExport.addClients(new ArrayList<String>(expRule.getRootHosts()));
        rootHosts = expRule.getRootHosts().size();
        newIsilonExport.addRootClients(new ArrayList<String>(expRule.getRootHosts()));
    }
    // set security type
    // Need to use "unix" instead of "sys" . Isilon requires "unix", not
    // "sys".
    // input export may contain one or more security types in a string separated by comma.
    ArrayList<String> secFlavors = new ArrayList<>();
    for (String securityType : expRule.getSecFlavor().split(",")) {
        securityType = securityType.trim();
        if (securityType.equals(FileShareExport.SecurityTypes.sys.name())) {
            securityType = "unix";
        }
        secFlavors.add(securityType);
    }
    newIsilonExport.setSecurityFlavors(secFlavors);
    newIsilonExport.setMapRoot(root_user);
    newIsilonExport.resetReadOnly();
    if (roHosts > 0 && rwHosts == 0 && rootHosts == 0) {
        // RO Export
        newIsilonExport.setReadOnly();
    }
    _log.info("setIsilonExport completed with creating {}", newIsilonExport.toString());
    return newIsilonExport;
}
Also used : IsilonExport(com.emc.storageos.isilon.restapi.IsilonExport) ArrayList(java.util.ArrayList) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Example 2 with IsilonExport

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

the class IsilonFileStorageDevice method isiExport.

/**
 * Create isilon exports
 *
 * @param isi
 *            IsilonApi object
 * @param args
 *            FileDeviceInputOutput object
 * @param exports
 *            new exports to add
 * @throws IsilonException
 */
private void isiExport(IsilonApi isi, FileDeviceInputOutput args, List<FileExport> exports) throws IsilonException {
    // process and export each NFSExport independently.
    for (FileExport fileExport : exports) {
        // create and set IsilonExport instance from NFSExport
        String permissions = fileExport.getPermissions();
        Set<String> orderedSecTypes = new TreeSet<String>();
        for (String securityType : fileExport.getSecurityType().split(",")) {
            securityType = securityType.trim();
            orderedSecTypes.add(securityType);
        }
        Iterator<String> orderedList = orderedSecTypes.iterator();
        String strCSSecurityType = orderedList.next().toString();
        while (orderedList.hasNext()) {
            strCSSecurityType += "," + orderedList.next().toString();
        }
        String root_user = fileExport.getRootUserMapping();
        String storagePortName = fileExport.getStoragePortName();
        String storagePort = fileExport.getStoragePort();
        String protocol = fileExport.getProtocol();
        String path = fileExport.getPath();
        String mountPath = fileExport.getMountPath();
        String comments = fileExport.getComments();
        String subDirectory = fileExport.getSubDirectory();
        List<String> securityTypes = new ArrayList<String>(orderedSecTypes);
        IsilonExport newIsilonExport = setIsilonExport(fileExport, permissions, securityTypes, root_user, mountPath, comments);
        _log.info("IsilonExport:" + fileExport.getClients() + ":" + fileExport.getStoragePortName() + ":" + fileExport.getStoragePort() + ":" + fileExport.getRootUserMapping() + ":" + fileExport.getPermissions() + ":" + fileExport.getProtocol() + ":" + fileExport.getSecurityType() + ":" + fileExport.getMountPoint() + ":" + fileExport.getPath() + ":" + fileExport.getSubDirectory() + ":" + fileExport.getComments());
        // Initialize exports map, if its not already initialized
        if (args.getFileObjExports() == null) {
            args.initFileObjExports();
        }
        String accessZoneName = getZoneName(args.getvNAS());
        // Create/update export in Isilon.
        String exportKey = fileExport.getFileExportKey();
        // If export with the given key does not exist, we create a new
        // export in Isilon and add it to the exports map.
        // In the other case, when export with a given key already exists in
        // Isilon, we need to overwrite endpoints in the current
        // export with endpoints in the
        // new export.
        FileExport fExport = args.getFileObjExports().get(exportKey);
        // check Isilon to verify if export does not exist.
        IsilonExport currentIsilonExport = null;
        if (fExport != null) {
            if (accessZoneName != null) {
                currentIsilonExport = isi.getExport(fExport.getIsilonId(), accessZoneName);
            } else {
                currentIsilonExport = isi.getExport(fExport.getIsilonId());
            }
        }
        if (fExport == null || currentIsilonExport == null) {
            // There is no Isilon export. Create Isilon export and set it
            // the map.
            String id = null;
            if (accessZoneName != null) {
                _log.debug("Export will be created in zone: {}", accessZoneName);
                id = isi.createExport(newIsilonExport, accessZoneName, args.getBypassDnsCheck());
            } else {
                id = isi.createExport(newIsilonExport, args.getBypassDnsCheck());
            }
            // set file export data and add it to the export map
            fExport = new FileExport(newIsilonExport.getClients(), storagePortName, mountPath, strCSSecurityType, permissions, root_user, protocol, storagePort, path, mountPath, subDirectory, comments);
            fExport.setIsilonId(id);
        } else {
            // There is export in Isilon with the given id.
            // Overwrite this export with a new set of clients.
            // We overwrite only clients element in exports. Isilon API does
            // not use read_only_clients, read_write_clients or
            // root_clients.
            List<String> newClients = newIsilonExport.getClients();
            newIsilonExport.setClients(new ArrayList<String>(newClients));
            // modify current export in isilon.
            if (accessZoneName != null) {
                isi.modifyExport(fExport.getIsilonId(), accessZoneName, newIsilonExport, args.getBypassDnsCheck());
            } else {
                isi.modifyExport(fExport.getIsilonId(), newIsilonExport, args.getBypassDnsCheck());
            }
            // update clients
            fExport.setClients(newIsilonExport.getClients());
        }
        args.getFileObjExports().put(exportKey, fExport);
    }
}
Also used : IsilonExport(com.emc.storageos.isilon.restapi.IsilonExport) TreeSet(java.util.TreeSet) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList)

Example 3 with IsilonExport

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

the class IsilonFileStorageDevice method doesNFSExportExistsForFSPath.

private boolean doesNFSExportExistsForFSPath(StorageSystem storageSystem, String isilonAccessZone, String path) throws IsilonCollectionException {
    URI storageSystemId = storageSystem.getId();
    String resumeToken = null;
    try {
        _log.info("Checking NFS export for path {}  on Isilon storage system: {} in access zone {} - start", path, storageSystem.getLabel(), isilonAccessZone);
        IsilonApi isilonApi = getIsilonDevice(storageSystem);
        do {
            IsilonApi.IsilonList<IsilonExport> isilonExports = isilonApi.listExports(resumeToken, isilonAccessZone);
            List<IsilonExport> exports = isilonExports.getList();
            for (IsilonExport exp : exports) {
                if (exp.getPaths() == null || exp.getPaths().isEmpty()) {
                    _log.info("Ignoring export {} as it is not having any path", exp);
                    continue;
                }
                // Ignore Export with multiple paths
                if (exp.getPaths().size() > 1) {
                    _log.info("Isilon Export: {} has multiple paths. So ingnore it.", exp);
                    continue;
                }
                String exportPath = exp.getPaths().get(0);
                if (exportPath.equals(path)) {
                    _log.info("Found NFS export with path {} on Ision: {} in access zone: {}", path, storageSystem.getLabel(), isilonAccessZone);
                    return true;
                }
            }
            resumeToken = isilonExports.getToken();
        } while (resumeToken != null);
        _log.info("NFS export not found with path {} on Ision: {} in access zone: {}", path, storageSystem.getLabel(), isilonAccessZone);
        return false;
    } catch (IsilonException ie) {
        _log.error("doesNFSExportExistsForFSPath failed. Storage system: {}", storageSystemId, ie);
        IsilonCollectionException ice = new IsilonCollectionException("doesNFSExportExistsForFSPath failed. Storage system: " + storageSystemId);
        ice.initCause(ie);
        throw ice;
    } catch (Exception e) {
        _log.error("doesNFSExportExistsForFSPath failed. Storage system: {}", storageSystemId, e);
        IsilonCollectionException ice = new IsilonCollectionException("doesNFSExportExistsForFSPath failed. Storage system: " + storageSystemId);
        ice.initCause(e);
        throw ice;
    }
}
Also used : IsilonExport(com.emc.storageos.isilon.restapi.IsilonExport) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) 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 4 with IsilonExport

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

the class IsilonCommunicationInterface method getIsilonExport.

private IsilonExport getIsilonExport(IsilonApi isilonApi, Integer expId, String zoneName) {
    IsilonExport exp = null;
    try {
        _log.debug("call getIsilonExport for {} ", expId);
        if (expId != null) {
            exp = isilonApi.getExport(expId.toString(), zoneName);
            _log.debug("call getIsilonExport {}", exp.toString());
        }
    } catch (Exception e) {
        _log.error("Exception while getting Export for {}", expId);
    }
    return exp;
}
Also used : IsilonExport(com.emc.storageos.isilon.restapi.IsilonExport) IsilonException(com.emc.storageos.isilon.restapi.IsilonException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException)

Example 5 with IsilonExport

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

the class IsilonCommunicationInterface method populateDbMetricsAz.

/**
 * process dbmetrics for total count and capacity
 *
 * @param azName
 * @param isilonApi
 * @param dbMetrics
 */
private void populateDbMetricsAz(final IsilonAccessZone accessZone, IsilonApi isilonApi, StringMap dbMetrics) {
    long totalProvCap = 0L;
    long totalFsCount = 0L;
    String resumeToken = null;
    String zoneName = accessZone.getName();
    String baseDirPath = accessZone.getPath() + "/";
    // filesystems count & used Capacity
    IsilonList<IsilonSmartQuota> quotas = null;
    do {
        quotas = isilonApi.listQuotas(resumeToken, baseDirPath);
        if (quotas != null && !quotas.getList().isEmpty()) {
            for (IsilonSmartQuota quota : quotas.getList()) {
                totalProvCap = totalProvCap + quota.getUsagePhysical();
                totalFsCount++;
            }
        }
        resumeToken = quotas.getToken();
    } while (resumeToken != null);
    // create a list of access zone for which base dir is not same as system access zone.
    // we get all snapshot list at once. baseDirPaths list is used to
    // find snaphot belong to which access zone.
    List<String> baseDirPaths = null;
    if (accessZone.isSystem() == true) {
        List<IsilonAccessZone> isilonAccessZoneList = isilonApi.getAccessZones(resumeToken);
        baseDirPaths = new ArrayList<String>();
        for (IsilonAccessZone isiAccessZone : isilonAccessZoneList) {
            if (!baseDirPath.equals(IFS_ROOT + "/")) {
                baseDirPaths.add(isiAccessZone.getPath() + "/");
            }
        }
    }
    // snapshots count & snap capacity
    resumeToken = null;
    IsilonList<IsilonSnapshot> snapshots = null;
    do {
        snapshots = isilonApi.listSnapshots(resumeToken);
        if (snapshots != null && !snapshots.getList().isEmpty()) {
            if (!baseDirPath.equals(IFS_ROOT + "/")) {
                // if it is not system access zone then compare
                // with fs path with base dir path
                _log.info("access zone base directory path {}", baseDirPath);
                for (IsilonSnapshot isilonSnap : snapshots.getList()) {
                    if (isilonSnap.getPath().startsWith(baseDirPath)) {
                        totalProvCap = totalProvCap + Long.valueOf(isilonSnap.getSize());
                        totalFsCount++;
                    }
                }
            } else {
                // process the snapshots for system access zone
                boolean snapSystem = true;
                for (IsilonSnapshot isilonSnap : snapshots.getList()) {
                    snapSystem = true;
                    // first check fs path with user defined AZ's paths
                    if (baseDirPaths != null && !baseDirPaths.isEmpty()) {
                        for (String basePath : baseDirPaths) {
                            if (isilonSnap.getPath().startsWith(basePath)) {
                                snapSystem = false;
                                break;
                            }
                        }
                    }
                    // it then it is belongs to access zone with basedir same as system access zone.
                    if (snapSystem) {
                        totalProvCap = totalProvCap + Long.valueOf(isilonSnap.getSize());
                        totalFsCount++;
                        _log.info("Access zone base directory path: {}", accessZone.getPath());
                    }
                }
            }
            resumeToken = snapshots.getToken();
        }
    } while (resumeToken != null);
    if (totalProvCap > 0) {
        totalProvCap = (totalProvCap / KB_IN_BYTES);
    }
    _log.info("Total fs Count {} for access zone : {}", String.valueOf(totalFsCount), accessZone.getName());
    _log.info("Total fs Capacity {} for access zone : {}", String.valueOf(totalProvCap), accessZone.getName());
    // get total exports
    int nfsExportsCount = 0;
    int cifsSharesCount = 0;
    resumeToken = null;
    IsilonList<IsilonExport> isilonNfsExports = null;
    do {
        isilonNfsExports = isilonApi.listExports(resumeToken, zoneName);
        if (isilonNfsExports != null) {
            nfsExportsCount = nfsExportsCount + isilonNfsExports.size();
            resumeToken = isilonNfsExports.getToken();
        }
    } while (resumeToken != null);
    _log.info("Total NFS exports {} for access zone : {}", String.valueOf(nfsExportsCount), accessZone.getName());
    // get cifs exports for given access zone
    resumeToken = null;
    IsilonList<IsilonSMBShare> isilonCifsExports = null;
    do {
        isilonCifsExports = isilonApi.listShares(resumeToken, zoneName);
        if (isilonCifsExports != null) {
            cifsSharesCount = cifsSharesCount + isilonCifsExports.size();
            resumeToken = isilonCifsExports.getToken();
        }
    } while (resumeToken != null);
    _log.info("Total CIFS sharess {} for access zone : {}", String.valueOf(cifsSharesCount), accessZone.getName());
    if (dbMetrics == null) {
        dbMetrics = new StringMap();
    }
    // set total nfs and cifs exports for give AZ
    dbMetrics.put(MetricsKeys.totalNfsExports.name(), String.valueOf(nfsExportsCount));
    dbMetrics.put(MetricsKeys.totalCifsShares.name(), String.valueOf(cifsSharesCount));
    // set total fs objects and their sum of capacity for give AZ
    dbMetrics.put(MetricsKeys.storageObjects.name(), String.valueOf(totalFsCount));
    dbMetrics.put(MetricsKeys.usedStorageCapacity.name(), String.valueOf(totalProvCap));
    Long maxExports = MetricsKeys.getLong(MetricsKeys.maxNFSExports, dbMetrics) + MetricsKeys.getLong(MetricsKeys.maxCifsShares, dbMetrics);
    Long maxStorObjs = MetricsKeys.getLong(MetricsKeys.maxStorageObjects, dbMetrics);
    Long maxCapacity = MetricsKeys.getLong(MetricsKeys.maxStorageCapacity, dbMetrics);
    Long totalExports = Long.valueOf(nfsExportsCount + cifsSharesCount);
    // setting overLoad factor (true or false)
    String overLoaded = FALSE;
    if (totalExports >= maxExports || totalProvCap >= maxCapacity || totalFsCount >= maxStorObjs) {
        overLoaded = TRUE;
    }
    double percentageLoadExports = 0.0;
    // percentage calculator
    if (totalExports > 0.0) {
        percentageLoadExports = ((double) (totalExports) / maxExports) * 100;
    }
    double percentageLoadStorObj = ((double) (totalProvCap) / maxCapacity) * 100;
    double percentageLoad = (percentageLoadExports + percentageLoadStorObj) / 2;
    dbMetrics.put(MetricsKeys.percentLoad.name(), String.valueOf(percentageLoad));
    dbMetrics.put(MetricsKeys.overLoaded.name(), overLoaded);
    return;
}
Also used : IsilonExport(com.emc.storageos.isilon.restapi.IsilonExport) StringMap(com.emc.storageos.db.client.model.StringMap) IsilonSmartQuota(com.emc.storageos.isilon.restapi.IsilonSmartQuota) IsilonAccessZone(com.emc.storageos.isilon.restapi.IsilonAccessZone) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) IsilonSMBShare(com.emc.storageos.isilon.restapi.IsilonSMBShare) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot)

Aggregations

IsilonExport (com.emc.storageos.isilon.restapi.IsilonExport)13 ArrayList (java.util.ArrayList)8 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)3 IsilonException (com.emc.storageos.isilon.restapi.IsilonException)3 ExportRule (com.emc.storageos.model.file.ExportRule)3 IsilonCollectionException (com.emc.storageos.plugins.metering.isilon.IsilonCollectionException)3 URISyntaxException (java.net.URISyntaxException)3 HashSet (java.util.HashSet)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 UnManagedFileExportRule (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 IOException (java.io.IOException)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 JSONException (org.codehaus.jettison.json.JSONException)2 FileExport (com.emc.storageos.db.client.model.FileExport)1