Search in sources :

Example 1 with TreeQuota

use of com.emc.nas.vnxfile.xmlapi.TreeQuota in project coprhd-controller by CoprHD.

the class VNXAllQuotaDirsProcessor method processResult.

@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    _logger.info("processing quota dir id response" + resultObj);
    final PostMethod result = (PostMethod) resultObj;
    try {
        ResponsePacket responsePacket = (ResponsePacket) _unmarshaller.unmarshal(result.getResponseBodyAsStream());
        if (null != responsePacket.getPacketFault()) {
            Status status = responsePacket.getPacketFault();
            processErrorStatus(status, keyMap);
        } else {
            List<Object> quotaDirList = getQueryResponse(responsePacket);
            List<TreeQuota> quotaDirs = new ArrayList<TreeQuota>();
            _logger.info("Received the response size {} ", quotaDirList.size());
            Iterator<Object> quotaDirItr = quotaDirList.iterator();
            if (quotaDirItr.hasNext()) {
                Status status = (Status) quotaDirItr.next();
                if (status.getMaxSeverity() == Severity.OK) {
                    while (quotaDirItr.hasNext()) {
                        TreeQuota quotaDir = (TreeQuota) quotaDirItr.next();
                        _logger.debug("searching quota dir: {}", quotaDir.getTree());
                        String id = quotaDir.getTree();
                        quotaDirs.add(quotaDir);
                        _logger.info("Found matching quota dir id: {}", id);
                    }
                    keyMap.put(VNXFileConstants.QUOTA_DIR_LIST, quotaDirs);
                    keyMap.put(VNXFileConstants.CMD_RESULT, VNXFileConstants.CMD_SUCCESS);
                }
            }
        }
    } catch (final Exception ex) {
        _logger.error("Exception occurred while processing the quota dir response due to {}", ex.getMessage());
        keyMap.put(VNXFileConstants.FAULT_DESC, ex.getMessage());
        keyMap.put(VNXFileConstants.CMD_RESULT, VNXFileConstants.CMD_FAILURE);
    } finally {
        result.releaseConnection();
    }
}
Also used : Status(com.emc.nas.vnxfile.xmlapi.Status) ResponsePacket(com.emc.nas.vnxfile.xmlapi.ResponsePacket) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ArrayList(java.util.ArrayList) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) TreeQuota(com.emc.nas.vnxfile.xmlapi.TreeQuota)

Example 2 with TreeQuota

use of com.emc.nas.vnxfile.xmlapi.TreeQuota in project coprhd-controller by CoprHD.

the class VNXFileQuotaDirectoryIdProcessor method processResult.

@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    _logger.info("processing quota dir id response" + resultObj);
    final PostMethod result = (PostMethod) resultObj;
    try {
        ResponsePacket responsePacket = (ResponsePacket) _unmarshaller.unmarshal(result.getResponseBodyAsStream());
        if (null != responsePacket.getPacketFault()) {
            Status status = responsePacket.getPacketFault();
            processErrorStatus(status, keyMap);
        } else {
            boolean isQuotaDirFound = false;
            List<Object> quotaDirList = getQueryResponse(responsePacket);
            final String quotaDirName = (String) keyMap.get(VNXFileConstants.QUOTA_DIR_NAME);
            String quotaDirPath = "/" + quotaDirName;
            _logger.info("Quota dir name to match: {} Size of quotadir found {} ", quotaDirName, quotaDirList.size());
            Iterator<Object> quotaDirItr = quotaDirList.iterator();
            if (quotaDirItr.hasNext()) {
                Status status = (Status) quotaDirItr.next();
                if (status.getMaxSeverity() == Severity.OK) {
                    while (quotaDirItr.hasNext()) {
                        TreeQuota quotaDir = (TreeQuota) quotaDirItr.next();
                        _logger.debug("searching quota dir: {}", quotaDir.getTree());
                        if (quotaDir.getPath().equals(quotaDirPath)) {
                            String id = quotaDir.getTree();
                            _logger.info("Found matching quota dir: {}", id);
                            keyMap.put(VNXFileConstants.QUOTA_DIR_ID, id);
                            keyMap.put(VNXFileConstants.QUOTA_DIR_PATH, quotaDir.getPath());
                            keyMap.put(VNXFileConstants.CMD_RESULT, VNXFileConstants.CMD_SUCCESS);
                            isQuotaDirFound = true;
                            break;
                        }
                    }
                    if (!isQuotaDirFound) {
                        _logger.error("Error in getting the quota dir information.");
                    }
                } else {
                    _logger.error("Error in getting the quota dir information.");
                }
            }
        }
    } catch (final Exception ex) {
        _logger.error("Exception occurred while processing the quota dir response due to {}", ex.getMessage());
        keyMap.put(VNXFileConstants.FAULT_DESC, ex.getMessage());
        keyMap.put(VNXFileConstants.CMD_RESULT, VNXFileConstants.CMD_FAILURE);
    } finally {
        result.releaseConnection();
    }
}
Also used : Status(com.emc.nas.vnxfile.xmlapi.Status) ResponsePacket(com.emc.nas.vnxfile.xmlapi.ResponsePacket) PostMethod(org.apache.commons.httpclient.methods.PostMethod) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) TreeQuota(com.emc.nas.vnxfile.xmlapi.TreeQuota)

Example 3 with TreeQuota

use of com.emc.nas.vnxfile.xmlapi.TreeQuota in project coprhd-controller by CoprHD.

the class VNXFileCommunicationInterface method discoverUmanagedFileQuotaDirectory.

private void discoverUmanagedFileQuotaDirectory(AccessProfile profile, StringSet umfsIds) throws Exception {
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    try {
        Map<String, Object> reqAttributeMap = getRequestParamsMap(storageSystem);
        reqAttributeMap.put(VNXFileConstants.CMD_RESULT, VNXFileConstants.CMD_SUCCESS);
        _discExecutor.setKeyMap(reqAttributeMap);
        // Retrieve all the qtree info.
        List<TreeQuota> qtrees = getAllQuotaTrees(storageSystem);
        if (null != qtrees && !qtrees.isEmpty()) {
            List<UnManagedFileQuotaDirectory> unManagedFileQuotaDirectories = new ArrayList<>();
            List<UnManagedFileQuotaDirectory> existingUnManagedFileQuotaDirectories = new ArrayList<>();
            for (TreeQuota quotaTree : qtrees) {
                String fsNativeId;
                // Process the QD's only of unmanaged file systems.
                if (!umfsIds.contains(quotaTree.getFileSystem())) {
                    continue;
                }
                String qdName = "";
                if (quotaTree.getPath() != null) {
                    // Ignore / from QD path
                    qdName = quotaTree.getPath().substring(1);
                }
                String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quotaTree.getFileSystem() + "");
                String nativeGUID = NativeGUIDGenerator.generateNativeGuidForQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), qdName, quotaTree.getFileSystem() + "");
                String nativeUnmanagedGUID = NativeGUIDGenerator.generateNativeGuidForUnManagedQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), qdName, quotaTree.getFileSystem() + "");
                if (checkStorageQuotaDirectoryExistsInDB(nativeGUID)) {
                    continue;
                }
                UnManagedFileQuotaDirectory tempUnManagedFileQuotaDirectory = checkUnManagedQuotaDirectoryExistsInDB(nativeUnmanagedGUID);
                boolean unManagedFileQuotaDirectoryExists = tempUnManagedFileQuotaDirectory == null ? false : true;
                UnManagedFileQuotaDirectory unManagedFileQuotaDirectory;
                if (!unManagedFileQuotaDirectoryExists) {
                    unManagedFileQuotaDirectory = new UnManagedFileQuotaDirectory();
                    unManagedFileQuotaDirectory.setId(URIUtil.createId(UnManagedFileQuotaDirectory.class));
                } else {
                    unManagedFileQuotaDirectory = tempUnManagedFileQuotaDirectory;
                }
                unManagedFileQuotaDirectory.setLabel(qdName);
                unManagedFileQuotaDirectory.setNativeGuid(nativeUnmanagedGUID);
                unManagedFileQuotaDirectory.setParentFSNativeGuid(fsNativeGuid);
                unManagedFileQuotaDirectory.setOpLock(false);
                if (quotaTree.getLimits() != null) {
                    /* 
                         * response is in MB, so Byte = 1024 * 1024 * response
                         */
                    unManagedFileQuotaDirectory.setSize(Long.valueOf(quotaTree.getLimits().getSpaceHardLimit()) * BYTESCONV * BYTESCONV);
                }
                if (!unManagedFileQuotaDirectoryExists) {
                    // Set ID only for new UnManagedQuota Directory
                    unManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
                } else {
                    existingUnManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
                }
            }
            if (!unManagedFileQuotaDirectories.isEmpty()) {
                _partitionManager.insertInBatches(unManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
            }
            if (!existingUnManagedFileQuotaDirectories.isEmpty()) {
                _partitionManager.updateAndReIndexInBatches(existingUnManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
            }
        }
    } catch (Exception e) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
        }
        _logger.error("discovery of UMFS Quota Directory failed. Storage system: " + storageSystemId);
        throw e;
    }
}
Also used : UnManagedFileQuotaDirectory(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory) ArrayList(java.util.ArrayList) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) UnManagedDiscoveredObject(com.emc.storageos.db.client.model.UnManagedDiscoveredObject) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) IOException(java.io.IOException) VNXFileCollectionException(com.emc.storageos.plugins.metering.vnxfile.VNXFileCollectionException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) TreeQuota(com.emc.nas.vnxfile.xmlapi.TreeQuota)

Example 4 with TreeQuota

use of com.emc.nas.vnxfile.xmlapi.TreeQuota in project coprhd-controller by CoprHD.

the class VNXFileCommunicationInterface method getAllQuotaTrees.

private List<TreeQuota> getAllQuotaTrees(final StorageSystem system) throws VNXException {
    List<TreeQuota> quotaTrees = new ArrayList<TreeQuota>();
    List<TreeQuota> tempQuotaTrees = null;
    try {
        _discExecutor.execute((Namespace) _discNamespaces.getNsList().get("vnxallquotas"));
        tempQuotaTrees = (ArrayList<TreeQuota>) _discExecutor.getKeyMap().get(VNXFileConstants.QUOTA_DIR_LIST);
        if (null != tempQuotaTrees && !tempQuotaTrees.isEmpty()) {
            quotaTrees.addAll(tempQuotaTrees);
            _logger.info("Found {} Quota directories ", tempQuotaTrees.size());
        } else {
            _logger.info("No Quota directories found ");
        }
    } catch (BaseCollectionException e) {
        throw new VNXException("Get QuotaTrees op failed", e);
    }
    return quotaTrees;
}
Also used : VNXException(com.emc.storageos.vnx.xmlapi.VNXException) ArrayList(java.util.ArrayList) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) TreeQuota(com.emc.nas.vnxfile.xmlapi.TreeQuota)

Example 5 with TreeQuota

use of com.emc.nas.vnxfile.xmlapi.TreeQuota in project coprhd-controller by CoprHD.

the class VNXFileCommApi method deleteAllQuotaDirs.

private XMLApiResult deleteAllQuotaDirs(StorageSystem system, StorageHADomain dataMover, FileShare fs) {
    XMLApiResult result = new XMLApiResult();
    result.setCommandSuccess();
    _log.info("deleteAllQuotaDirs for {}", fs.getName());
    try {
        // Process for quota dir delete on this file share.
        List<TreeQuota> quotaDirs = (List<TreeQuota>) _provExecutor.getKeyMap().get(VNXFileConstants.QUOTA_DIR_LIST);
        if (quotaDirs != null && !quotaDirs.isEmpty() && dataMover != null) {
            _log.info("Number of quota dirs found {} for a file system {}", quotaDirs.size(), fs.getName());
            // In the process of delete file system, we are unmounting the FileSystem.
            // In order to delete Quota Directory, file system should be mounted.
            // we just mount the file system temporarily. if it was un-mounted.
            sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
            Map<String, String> existingMounts = sshApi.getFsMountpathMap(dataMover.getAdapterName());
            if (existingMounts.get(fs.getName()) == null) {
                String mountCmdArgs = sshApi.formatMountCmd(dataMover.getAdapterName(), fs.getName(), fs.getMountPath());
                result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_MOUNT_CMD, mountCmdArgs);
            }
            for (TreeQuota quota : quotaDirs) {
                if (quota != null) {
                    // exclude the "/" in the beginning of the
                    String quotaDirName = quota.getPath().substring(1);
                    // path.
                    XMLApiResult status = deleteQuotaDirectory(system, fs.getName(), quotaDirName, true, false);
                    if (!status.isCommandSuccess()) {
                        String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
                        result.setCommandFailed();
                        result.setMessage(errMsg);
                        return result;
                    }
                }
            }
        }
        return result;
    } catch (Exception e) {
        throw new VNXException("File system quota directory delete exception: ", e);
    }
}
Also used : VNXException(com.emc.storageos.vnx.xmlapi.VNXException) ArrayList(java.util.ArrayList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) URISyntaxException(java.net.URISyntaxException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) TreeQuota(com.emc.nas.vnxfile.xmlapi.TreeQuota)

Aggregations

TreeQuota (com.emc.nas.vnxfile.xmlapi.TreeQuota)6 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 ArrayList (java.util.ArrayList)5 ResponsePacket (com.emc.nas.vnxfile.xmlapi.ResponsePacket)3 Status (com.emc.nas.vnxfile.xmlapi.Status)3 VNXException (com.emc.storageos.vnx.xmlapi.VNXException)3 PostMethod (org.apache.commons.httpclient.methods.PostMethod)3 URISyntaxException (java.net.URISyntaxException)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 UnManagedDiscoveredObject (com.emc.storageos.db.client.model.UnManagedDiscoveredObject)1 UnManagedFileQuotaDirectory (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 NamespaceList (com.emc.storageos.plugins.common.domainmodel.NamespaceList)1 VNXFileCollectionException (com.emc.storageos.plugins.metering.vnxfile.VNXFileCollectionException)1 XMLApiResult (com.emc.storageos.vnx.xmlapi.XMLApiResult)1 IOException (java.io.IOException)1 URI (java.net.URI)1 List (java.util.List)1