Search in sources :

Example 31 with FSExportMap

use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.

the class FileDeviceInputOutput method isFileShareMounted.

public boolean isFileShareMounted() {
    FSExportMap exports = getFs().getFsExports();
    SMBShareMap shares = getFs().getSMBFileShares();
    boolean isMounted = true;
    if ((exports == null || (exports != null && exports.isEmpty())) && (shares == null || (shares != null && shares.isEmpty()))) {
        isMounted = false;
    }
    return isMounted;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FSExportMap(com.emc.storageos.db.client.model.FSExportMap)

Example 32 with FSExportMap

use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.

the class VNXFileCommApi method deleteAllExportsAndShares.

private XMLApiResult deleteAllExportsAndShares(StorageSystem system, StorageHADomain dataMover, FileShare fs, Snapshot snapshot) {
    FSExportMap exports;
    SMBShareMap shares;
    XMLApiResult result = new XMLApiResult();
    result.setCommandSuccess();
    String fileId = fs.getId().toString();
    FileObject fObj = fs;
    _log.info("deleteAllExportsAndShares for {} {}", fs.getName(), snapshot);
    boolean fileOperation = false;
    if (snapshot == null) {
        // FileShare operation
        _log.info("deleteAllExportsAndShares FileShare delete operation");
        exports = fs.getFsExports();
        shares = fs.getSMBFileShares();
        fileOperation = true;
        fObj = fs;
    } else {
        _log.info("deleteAllExportsAndShares Snapshot delete operation");
        exports = snapshot.getFsExports();
        shares = snapshot.getSMBFileShares();
        fObj = snapshot;
        fileId = snapshot.getId().toString();
    }
    int exportsToUnExport = 0;
    Set<String> keys = new HashSet();
    if (exports != null) {
        exportsToUnExport = exports.size();
        keys = exports.keySet();
    }
    int noOfShares = 0;
    if (shares != null) {
        noOfShares = shares.size();
    }
    _log.info("Number of NFS exports {}  SMB Shares found {} for File/Snapshot Id {}", new Object[] { exportsToUnExport, noOfShares, fileId });
    // To avoid concurrent modification exceptions
    Set<String> exportKeys = new HashSet();
    exportKeys.addAll(keys);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    args.setFileOperation(fileOperation);
    args.addFSFileObject(fs);
    if (fileOperation) {
        args.setFileOperation(true);
        args.addFSFileObject(fs);
    } else {
        args.setFileOperation(false);
        args.addFSFileObject(fs);
        args.addSnapshot(snapshot);
    }
    for (String key : exportKeys) {
        FileExport exp = exports.get(key);
        VNXFileExport fileExport = new VNXFileExport(exp.getClients(), exp.getStoragePortName(), exp.getPath(), exp.getSecurityType(), exp.getPermissions(), exp.getRootUserMapping(), exp.getProtocol(), exp.getStoragePort(), exp.getSubDirectory(), exp.getComments());
        fileExport.setStoragePort(fs.getStoragePort().toString());
        boolean deleteMount = false;
        if (exportsToUnExport == 1 && noOfShares == 0 && fileOperation) {
            deleteMount = true;
        }
        XMLApiResult status = doUnexport(system, fileExport, args, deleteMount);
        if (!status.isCommandSuccess()) {
            String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
            result.setCommandFailed();
            result.setMessage(errMsg);
            return result;
        } else {
            fObj.getFsExports().remove(key);
            _log.info("Export removed : " + key);
            exportsToUnExport--;
        }
        // Persist the object after exports removed
        _dbClient.persistObject(fObj);
    }
    // Now Let Handle SMB/CIFS Shares
    keys = new HashSet<>();
    int noOfSharesToDelete = 0;
    if (shares != null) {
        keys = shares.keySet();
        noOfSharesToDelete = keys.size();
    }
    int noOfExports = 0;
    if (exports != null) {
        noOfExports = exports.size();
    }
    _log.info("Number of CIFS/SMB Shares {}  NFS Exports found {} for File/Snapshot Id {}", new Object[] { noOfSharesToDelete, noOfExports, fileId });
    // To avoid concurrent modification exceptions
    Set<String> shareKeys = new HashSet();
    shareKeys.addAll(keys);
    for (String key : shareKeys) {
        SMBFileShare share = shares.get(key);
        _log.info("Delete SMB/CIFS Share {} from FS/Snapshot {}", share.getName(), fileId);
        boolean deleteMount = false;
        if (noOfSharesToDelete == 1 && noOfExports == 0 && fileOperation) {
            deleteMount = true;
        }
        XMLApiResult status = doDeleteShare(system, dataMover, share.getName(), fs.getMountPath(), deleteMount, args);
        if (!status.isCommandSuccess()) {
            _log.info("SMBFileShare deletion failed key {} : {} ", key, share.getName());
            String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
            result.setCommandFailed();
            result.setMessage(errMsg);
            return result;
        } else {
            fObj.getSMBFileShares().remove(key);
            _log.info("SMBFileShare removed : " + key);
            noOfSharesToDelete--;
        }
        // Persist the object after SMBShares removed
        _dbClient.persistObject(fObj);
    }
    return result;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Checkpoint(com.emc.nas.vnxfile.xmlapi.Checkpoint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) FileExport(com.emc.storageos.db.client.model.FileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) HashSet(java.util.HashSet)

Example 33 with FSExportMap

use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.

the class VNXFileCommApi method getVNXFSDependencies.

/*
     * Check the dependencies on file share or on snap shot.
     * input :
     * fs: File share object
     * considerSnapshots: consider the snap shot dependencies.
     * return: this function will check and return the number of dependencies like
     * exports, shares, snapshot and quota directories on the given file share.
     */
private int getVNXFSDependencies(FileShare fs, Boolean considerSnapshots) {
    FSExportMap exports = null;
    SMBShareMap shares = null;
    int totalDependencies = 0;
    // FileShare operation
    if (fs.getFsExports() != null) {
        exports = fs.getFsExports();
    }
    if (fs.getSMBFileShares() != null) {
        shares = fs.getSMBFileShares();
    }
    if (exports != null) {
        totalDependencies += exports.size();
    }
    if (shares != null) {
        totalDependencies += shares.size();
    }
    List<Snapshot> snapshots = getFSSnapshots(fs);
    if (snapshots != null && !snapshots.isEmpty()) {
        totalDependencies += snapshots.size();
    }
    List<QuotaDirectory> quotaDirs = getFSQuotaDirs(fs);
    if (quotaDirs != null && !quotaDirs.isEmpty()) {
        totalDependencies += quotaDirs.size();
    }
    if (considerSnapshots && snapshots != null) {
        totalDependencies = snapshots.size();
        for (Snapshot snap : snapshots) {
            exports = snap.getFsExports();
            shares = snap.getSMBFileShares();
            if (exports != null) {
                totalDependencies += exports.size();
            }
            if (shares != null) {
                totalDependencies += shares.size();
            }
        }
    }
    _log.info("FileShare : total dependencies {} ", totalDependencies);
    return totalDependencies;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXSnapshot(com.emc.storageos.vnx.xmlapi.VNXSnapshot) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Checkpoint(com.emc.nas.vnxfile.xmlapi.Checkpoint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 34 with FSExportMap

use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.

the class DbCli method dumpBeanProperties.

/**
 * Dump the contents in xml format
 *
 * @param pds
 * @param object
 * @throws Exception
 */
private <T extends DataObject> void dumpBeanProperties(PropertyDescriptor[] pds, T object) throws Exception {
    Element record = doc.createElement("record");
    record.setAttribute("id", object.getId().toString());
    schemaNode.appendChild(record);
    // Add readOnlyField node.
    Element readOnlyElement = doc.createElement("readOnlyField");
    record.appendChild(readOnlyElement);
    System.out.println("id: " + object.getId().toString());
    Object objValue;
    Class type;
    for (PropertyDescriptor pd : pds) {
        objValue = pd.getReadMethod().invoke(object);
        if (objValue == null) {
            continue;
        }
        // Skip password property.
        if (pd.getName().toLowerCase().matches("[a-zA-Z\\d]*password[a-zA-Z\\d]*")) {
            continue;
        }
        // Skip some properties.
        if (pd.getName().equals("class") || pd.getName().equals("id")) {
            Element readOnlyfieldNode = doc.createElement("field");
            // delete the prefix string "class "
            readOnlyfieldNode.setAttribute("type", pd.getPropertyType().toString().substring(6));
            readOnlyfieldNode.setAttribute("name", pd.getName().toString());
            readOnlyfieldNode.setAttribute("value", objValue.toString());
            readOnlyElement.appendChild(readOnlyfieldNode);
            continue;
        }
        // Skip the fields without @Name annotation
        Name name = pd.getReadMethod().getAnnotation(Name.class);
        if (name == null) {
            log.info("Ignore data object fields without @Name annotation, fieldName={}.", pd.getName());
            continue;
        }
        // use value from @Name instead of mtehod name
        String objKey = name.value();
        type = pd.getPropertyType();
        if (DEBUG) {
            System.out.print("\t" + pd.getPropertyType() + "\t" + objKey + " = ");
        }
        Element fieldNode = doc.createElement("field");
        // delete the prefix string "class "
        fieldNode.setAttribute("type", type.toString().substring(6));
        fieldNode.setAttribute("name", objKey);
        if (type == StringSetMap.class) {
            StringSetMap stringSetMap = (StringSetMap) objValue;
            FieldType.marshall(stringSetMap, fieldNode, StringSetMapWrapper.class);
        } else if (type == StringSet.class) {
            StringSet stringSet = (StringSet) objValue;
            FieldType.marshall(stringSet, fieldNode, StringSetWrapper.class);
        } else if (type == ScopedLabelSet.class) {
            ScopedLabelSet scopedLabelSet = (ScopedLabelSet) objValue;
            FieldType.marshall(scopedLabelSet, fieldNode, ScopedLabelSetWrapper.class);
        } else if (type == OpStatusMap.class) {
            OpStatusMap opStatusMap = (OpStatusMap) objValue;
            FieldType.marshall(opStatusMap, fieldNode, OpStatusMapWrapper.class);
        } else if (type == StringMap.class) {
            StringMap stringMap = (StringMap) objValue;
            FieldType.marshall(stringMap, fieldNode, StringMapWrapper.class);
        } else if (type == FSExportMap.class) {
            FSExportMap fSExportMap = (FSExportMap) objValue;
            FieldType.marshall(fSExportMap, fieldNode, FSExportMapWrapper.class);
        } else if (type == SMBShareMap.class) {
            SMBShareMap sMBShareMap = (SMBShareMap) objValue;
            FieldType.marshall(sMBShareMap, fieldNode, SMBShareMapWrapper.class);
        } else {
            fieldNode.setAttribute("value", objValue.toString());
        }
        record.appendChild(fieldNode);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) PropertyDescriptor(java.beans.PropertyDescriptor) Element(org.w3c.dom.Element) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) FSExportMapWrapper(com.emc.storageos.dbcli.wrapper.FSExportMapWrapper) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) Name(com.emc.storageos.db.client.model.Name) OpStatusMapWrapper(com.emc.storageos.dbcli.wrapper.OpStatusMapWrapper) StringSet(com.emc.storageos.db.client.model.StringSet) StringSetWrapper(com.emc.storageos.dbcli.wrapper.StringSetWrapper) DataObject(com.emc.storageos.db.client.model.DataObject)

Example 35 with FSExportMap

use of com.emc.storageos.db.client.model.FSExportMap in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method addStepsToReplicateNFSExportRules.

/**
 * Child workflow for replicating source file system NFS export Rules to target.
 *
 * @param systemTarget
 *            - URI of target StorageSystem where source NFS shares has to be replicated.
 * @param fsURI
 *            -URI of the source FileSystem
 * @param taskId
 */
public void addStepsToReplicateNFSExportRules(URI systemTarget, URI fsURI, String taskId) {
    s_logger.info("Generating steps for Replicating NFS export rules to Target Cluster");
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    Workflow workflow = null;
    FileShare targetFileShare = null;
    try {
        FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
        if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
            List<String> targetfileUris = new ArrayList<String>();
            targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
            targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        } else {
            targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
        }
        workflow = this._workflowService.getNewWorkflow(this, REPLICATE_NFS_EXPORT_RULES_TO_TARGET_WF_NAME, false, taskId, completer);
        FSExportMap sourceFSExportMap = sourceFileShare.getFsExports();
        FSExportMap targetFSExportMap = targetFileShare.getFsExports();
        if (sourceFSExportMap == null && targetFSExportMap != null) {
            // There are no export rule on source but there are on target!!
            List<ExportRule> exportRulesToDelete;
            HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
            for (String exportPath : targetExportRuleMap.keySet()) {
                FileExportUpdateParams params = new FileExportUpdateParams();
                if (exportPath.equals(targetFileShare.getPath())) {
                    // File system export rules....
                    exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath());
                } else {
                    // Sub directory export rules....
                    String subDir = exportPath.split(targetFileShare.getPath())[1];
                    exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
                    params.setSubDir(subDir.substring(1));
                }
                ExportRules deleteExportRules = new ExportRules();
                deleteExportRules.setExportRules(exportRulesToDelete);
                params.setExportRulesToDelete(deleteExportRules);
                updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
            }
        } else if (targetFSExportMap != null && sourceFSExportMap != null) {
            // Both source and target have export rules!!
            HashMap<String, List<ExportRule>> sourceExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(sourceFileShare, s_dbClient);
            HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
            for (String exportPath : sourceExportRuleMap.keySet()) {
                FileExportUpdateParams params = new FileExportUpdateParams();
                List<ExportRule> exportRulesToAdd = new ArrayList<ExportRule>();
                List<ExportRule> exportRulesToDelete = new ArrayList<ExportRule>();
                List<ExportRule> exportRulesToModify = new ArrayList<ExportRule>();
                List<ExportRule> sourceExportRules;
                List<ExportRule> targetExportRules;
                HashMap<String, ExportRule> srcExportRuleSecFlvMap;
                HashMap<String, ExportRule> trgtExportRuleSecFlvMap;
                if (exportPath.equals(sourceFileShare.getPath())) {
                    // File system export rules....
                    sourceExportRules = sourceExportRuleMap.get(exportPath);
                    targetExportRules = targetExportRuleMap.get(targetFileShare.getPath());
                } else {
                    // Sub directory export rules....
                    sourceExportRules = sourceExportRuleMap.get(exportPath);
                    String subDir = exportPath.split(sourceFileShare.getPath())[1];
                    targetExportRules = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
                    params.setSubDir(subDir.substring(1));
                }
                if (sourceExportRules != null && targetExportRules != null) {
                    srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
                    trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
                    FileOrchestrationUtils.checkForExportRuleToAdd(sourceFileShare, targetFileShare, srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToAdd);
                    FileOrchestrationUtils.checkForExportRuleToDelete(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToDelete);
                    sourceExportRules.removeAll(exportRulesToAdd);
                    targetExportRules.removeAll(exportRulesToDelete);
                    srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
                    trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
                    FileOrchestrationUtils.checkForExportRuleToModify(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToModify);
                    if (!exportRulesToAdd.isEmpty()) {
                        ExportRules addExportRules = new ExportRules();
                        addExportRules.setExportRules(exportRulesToAdd);
                        params.setExportRulesToAdd(addExportRules);
                    }
                    if (!exportRulesToDelete.isEmpty()) {
                        ExportRules deleteExportRules = new ExportRules();
                        deleteExportRules.setExportRules(exportRulesToDelete);
                        params.setExportRulesToDelete(deleteExportRules);
                    }
                    if (!exportRulesToModify.isEmpty()) {
                        ExportRules modifyExportRules = new ExportRules();
                        modifyExportRules.setExportRules(exportRulesToModify);
                        params.setExportRulesToModify(modifyExportRules);
                    }
                    if (params.retrieveAllExports() != null && !params.retrieveAllExports().isEmpty()) {
                        updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
                    }
                }
            }
        }
        String successMessage = String.format("Replicating source File System : %s, NFS Exports Rules to Target System finished successfully", sourceFileShare.getLabel());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem NFS Exports Rules : " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) FileWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter) FileExportUpdateParams(com.emc.storageos.model.file.FileExportUpdateParams) ExportRules(com.emc.storageos.model.file.ExportRules) ExportRule(com.emc.storageos.model.file.ExportRule) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

FSExportMap (com.emc.storageos.db.client.model.FSExportMap)46 FileExport (com.emc.storageos.db.client.model.FileExport)33 ArrayList (java.util.ArrayList)22 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)20 FileShare (com.emc.storageos.db.client.model.FileShare)18 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 Snapshot (com.emc.storageos.db.client.model.Snapshot)11 URI (java.net.URI)11 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)9 WorkflowException (com.emc.storageos.workflow.WorkflowException)7 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 FileShareExport (com.emc.storageos.volumecontroller.FileShareExport)6 List (java.util.List)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)5