Search in sources :

Example 1 with IsilonSnapshot

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

the class IsilonFileStorageDevice method doesSnapshotExistsForFSPath.

private boolean doesSnapshotExistsForFSPath(StorageSystem storageSystem, String isilonAccessZone, String path) throws IsilonCollectionException {
    URI storageSystemId = storageSystem.getId();
    String resumeToken = null;
    try {
        _log.info("Checking snapshots for path {}  on Isilon storage system: {} in access zone {} - start", path, storageSystem.getLabel(), isilonAccessZone);
        IsilonApi isilonApi = getIsilonDevice(storageSystem);
        do {
            IsilonList<IsilonSnapshot> isilonSnapshots = isilonApi.listSnapshots(resumeToken, path);
            List<IsilonSnapshot> snpashots = isilonSnapshots.getList();
            for (IsilonSnapshot snapshot : snpashots) {
                if (snapshot.getPath() == null || snapshot.getPath().isEmpty()) {
                    _log.info("Ignoring snapshot {} as it is not having any path", snapshot);
                    continue;
                }
                if (snapshot.getPath().equals(path)) {
                    _log.info("Found snapshot on path {} in Ision: {}", path, storageSystem.getLabel());
                    return true;
                }
            }
            resumeToken = isilonSnapshots.getToken();
        } while (resumeToken != null);
        _log.info("Snapshots not found with path {} on Ision: {} in access zone: {}", path, storageSystem.getLabel(), isilonAccessZone);
        return false;
    } catch (IsilonException ie) {
        _log.error("doesSnapshotExistsForFSPath failed. Storage system: {}", storageSystemId, ie);
        IsilonCollectionException ice = new IsilonCollectionException("doesSnapshotExistsForFSPath failed. Storage system: " + storageSystemId);
        ice.initCause(ie);
        throw ice;
    } catch (Exception e) {
        _log.error("doesSnapshotExistsForFSPath failed. Storage system: {}", storageSystemId, e);
        IsilonCollectionException ice = new IsilonCollectionException("doesSnapshotExistsForFSPath failed. Storage system: " + storageSystemId);
        ice.initCause(e);
        throw ice;
    }
}
Also used : IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) 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 2 with IsilonSnapshot

use of com.emc.storageos.isilon.restapi.IsilonSnapshot 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)

Example 3 with IsilonSnapshot

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

the class IsilonFileStorageDevice method listSanpshotByPolicy.

@Override
public BiosCommandResult listSanpshotByPolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
    FilePolicy sp = args.getFileProtectionPolicy();
    FileShare fs = args.getFs();
    String snapshotScheduleName = sp.getFilePolicyName() + "_" + args.getFsName();
    if (sp.getPolicyStorageResources() != null && !sp.getPolicyStorageResources().isEmpty()) {
        for (String uriResource : sp.getPolicyStorageResources()) {
            PolicyStorageResource policyRes = _dbClient.queryObject(PolicyStorageResource.class, URI.create(uriResource));
            if (policyRes != null && policyRes.getStorageSystem().equals(storageObj.getId())) {
                snapshotScheduleName = policyRes.getPolicyNativeId();
                break;
            }
        }
    }
    IsilonApi isi = getIsilonDevice(storageObj);
    String resumeToken = null;
    try {
        do {
            IsilonList<IsilonSnapshot> snapshots = isi.listSnapshotsCreatedByPolicy(resumeToken, snapshotScheduleName);
            if (snapshots != null) {
                for (IsilonSnapshot islon_snap : snapshots.getList()) {
                    _log.info("file policy snapshot is  : " + islon_snap.getName());
                    Snapshot snap = new Snapshot();
                    snap.setLabel(islon_snap.getName());
                    snap.setMountPath(islon_snap.getPath());
                    snap.setName(islon_snap.getName());
                    snap.setId(URIUtil.createId(Snapshot.class));
                    snap.setOpStatus(new OpStatusMap());
                    snap.setProject(new NamedURI(fs.getProject().getURI(), islon_snap.getName()));
                    snap.setMountPath(getSnapshotPath(islon_snap.getPath(), islon_snap.getName()));
                    snap.setParent(new NamedURI(fs.getId(), islon_snap.getName()));
                    StringMap map = new StringMap();
                    Long createdTime = Long.parseLong(islon_snap.getCreated()) * SEC_IN_MILLI;
                    String expiresTime = "Never";
                    if (islon_snap.getExpires() != null && !islon_snap.getExpires().isEmpty()) {
                        Long expTime = Long.parseLong(islon_snap.getExpires()) * SEC_IN_MILLI;
                        expiresTime = expTime.toString();
                    }
                    map.put("created", createdTime.toString());
                    map.put("expires", expiresTime);
                    map.put("schedule", sp.getFilePolicyName());
                    snap.setExtensions(map);
                    _dbClient.updateObject(snap);
                }
                resumeToken = snapshots.getToken();
            }
        } while (resumeToken != null && !resumeToken.equalsIgnoreCase("null"));
    } catch (IsilonException e) {
        _log.error("listing snapshot by file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
    Task task = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), args.getOpId());
    // set task to completed and progress to 100 and store in DB, so waiting thread in apisvc can read it.
    task.ready();
    task.setProgress(100);
    _dbClient.updateObject(task);
    return BiosCommandResult.createSuccessfulResult();
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 4 with IsilonSnapshot

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

the class IsilonStatsRecorder method addUsageStat.

/**
 * Adds a Stat for usage from the IsilonQuota.
 *
 * @param quota
 * @param keyMap
 * @param fsNativeGuid native Guid of the file share
 * @param isilonApi
 * @return the stat
 */
public Stat addUsageStat(IsilonSmartQuota quota, Map<String, Object> keyMap, String fsNativeGuid, IsilonApi isilonApi) {
    Stat stat = zeroRecordGenerator.injectattr(keyMap, fsNativeGuid, FileShare.class);
    if (stat != null) {
        try {
            DbClient dbClient = (DbClient) keyMap.get(Constants.dbClient);
            stat.setTimeInMillis((Long) keyMap.get(Constants._TimeCollected));
            stat.setTimeCollected((Long) keyMap.get(Constants._TimeCollected));
            statsColumnInjector.injectColumns(stat, dbClient);
            long provisionedCapacity = 0L;
            Thresholds threshold = quota.getThresholds();
            if (threshold != null && threshold.getHard() != null) {
                provisionedCapacity = threshold.getHard();
            }
            stat.setProvisionedCapacity(provisionedCapacity);
            long usedCapacity = quota.getUsagePhysical();
            stat.setAllocatedCapacity(usedCapacity);
            URIQueryResultList snapURIList = new URIQueryResultList();
            dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(stat.getResourceId()), snapURIList);
            // Set snapshot count.
            // Set snapshot size. Get current data for snapshot size (snapshot size changes dynamically).
            int snapCount = 0;
            long fsSnapshotSize = 0;
            IsilonSnapshot isiSnap;
            for (URI snapURI : snapURIList) {
                Snapshot snap = dbClient.queryObject(Snapshot.class, snapURI);
                // Filter out deleted Snapshot
                if (snap != null && (!snap.getInactive())) {
                    String nativeId = snap.getNativeId();
                    try {
                        isiSnap = isilonApi.getSnapshot(nativeId);
                    } catch (IsilonException iex) {
                        _log.error(String.format("Stat: %s: can not get snapshot size for snapshot: %s", fsNativeGuid, nativeId), iex);
                        continue;
                    }
                    snapCount++;
                    fsSnapshotSize += Long.valueOf(isiSnap.getSize());
                }
            }
            stat.setSnapshotCount(snapCount);
            _log.debug(String.format("Stat: %s: snapshot count: %s", fsNativeGuid, snapCount));
            stat.setSnapshotCapacity(fsSnapshotSize);
            _log.debug(String.format("Stat: %s: snapshot size: %s", fsNativeGuid, fsSnapshotSize));
            _log.debug(String.format("Stat: %s: %s: provisioned capacity(%s): used capacity(%s)", stat.getResourceId(), fsNativeGuid, provisionedCapacity, usedCapacity));
        } catch (DatabaseException ex) {
            _log.error("Query to db failed for FileShare id {}, skipping recording usage stat.", stat.getResourceId(), ex);
        }
    }
    return stat;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) Stat(com.emc.storageos.db.client.model.Stat) DbClient(com.emc.storageos.db.client.DbClient) Thresholds(com.emc.storageos.isilon.restapi.IsilonSmartQuota.Thresholds) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Aggregations

IsilonSnapshot (com.emc.storageos.isilon.restapi.IsilonSnapshot)4 IsilonException (com.emc.storageos.isilon.restapi.IsilonException)3 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 Snapshot (com.emc.storageos.db.client.model.Snapshot)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)2 URI (java.net.URI)2 DbClient (com.emc.storageos.db.client.DbClient)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)1 PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)1 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)1 Stat (com.emc.storageos.db.client.model.Stat)1 Task (com.emc.storageos.db.client.model.Task)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1