Search in sources :

Example 31 with SMBShareMap

use of com.emc.storageos.db.client.model.SMBShareMap 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 32 with SMBShareMap

use of com.emc.storageos.db.client.model.SMBShareMap 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 33 with SMBShareMap

use of com.emc.storageos.db.client.model.SMBShareMap 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 34 with SMBShareMap

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

the class FileOrchestrationDeviceController method failoverFileSystem.

@Override
public void failoverFileSystem(URI fsURI, StoragePort nfsPort, StoragePort cifsPort, boolean replicateConfiguration, String taskId) throws ControllerException {
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    Workflow workflow = null;
    String stepDescription = null;
    MirrorFileFailoverTaskCompleter failoverCompleter = null;
    try {
        FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
        FileShare targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        StorageSystem systemTarget = s_dbClient.queryObject(StorageSystem.class, targetFileShare.getStorageDevice());
        workflow = this._workflowService.getNewWorkflow(this, FAILOVER_FILESYSTEMS_WF_NAME, false, taskId, completer);
        // Failover File System to Target
        s_logger.info("Generating steps for Failover File System to Target");
        String failoverStep = workflow.createStepId();
        List<URI> combined = Arrays.asList(sourceFileShare.getId(), targetFileShare.getId());
        failoverCompleter = new MirrorFileFailoverTaskCompleter(FileShare.class, combined, failoverStep);
        stepDescription = String.format("Failover Source File System %s to Target System.", sourceFileShare.getLabel());
        Object[] args = new Object[] { systemTarget.getId(), targetFileShare.getId(), failoverCompleter };
        String waitForFailover = _fileDeviceController.createMethod(workflow, null, FAILOVER_FILE_SYSTEM_METHOD, failoverStep, stepDescription, systemTarget.getId(), args);
        // Replicate quota setting
        stepDescription = String.format("Replicating directory quota settings from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
        Workflow.Method replicateDirQuotaSettingsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_DIRECTORY_QUOTA_SETTINGS_METHOD, systemTarget.getId(), fsURI);
        String replicateDirQuotaSettingsStep = workflow.createStepId();
        workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateDirQuotaSettingsMethod, null, replicateDirQuotaSettingsStep);
        if (replicateConfiguration) {
            Map<String, List<NfsACE>> sourceNFSACL = FileOrchestrationUtils.queryNFSACL(sourceFileShare, s_dbClient);
            Map<String, List<NfsACE>> targetNFSACL = FileOrchestrationUtils.queryNFSACL(targetFileShare, s_dbClient);
            if (!sourceNFSACL.isEmpty() || !targetNFSACL.isEmpty()) {
                stepDescription = String.format("Replicating NFS ACL from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
                Workflow.Method replicateNFSACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_ACLS_METHOD, systemTarget.getId(), fsURI);
                String replicateNFSACLsStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateNFSACLsMethod, null, replicateNFSACLsStep);
            }
            SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
            SMBShareMap targetSMBShareMap = targetFileShare.getSMBFileShares();
            if (sourceSMBShareMap != null || targetSMBShareMap != null) {
                // Both source and target share map shouldn't be null
                stepDescription = String.format("Replicating CIFS shares from source file system : %s to target file system : %s", sourceFileShare.getId(), targetFileShare.getId());
                Workflow.Method replicateCIFSShareMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARES_METHOD, systemTarget.getId(), fsURI, cifsPort);
                String replicateCIFSShareStep = workflow.createStepId();
                String waitForShare = workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateCIFSShareMethod, null, replicateCIFSShareStep);
                stepDescription = String.format("Replicating CIFS share ACLs from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
                Workflow.Method replicateCIFSShareACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARE_ACLS_METHOD, systemTarget.getId(), fsURI);
                String replicateCIFSShareACLsStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForShare, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateCIFSShareACLsMethod, null, replicateCIFSShareACLsStep);
            }
            // Replicate NFS export and rules to Target Cluster.
            FSExportMap sourceNFSExportMap = sourceFileShare.getFsExports();
            FSExportMap targetNFSExportMap = targetFileShare.getFsExports();
            if (sourceNFSExportMap != null || targetNFSExportMap != null) {
                // Both source and target export map shouldn't be null
                stepDescription = String.format("Replicating NFS exports from source file system : %s to target file system : %s", sourceFileShare.getId(), targetFileShare.getId());
                Workflow.Method replicateNFSExportMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_METHOD, systemTarget.getId(), fsURI, nfsPort);
                String replicateNFSExportStep = workflow.createStepId();
                String waitForExport = workflow.createStep(null, stepDescription, waitForFailover, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateNFSExportMethod, null, replicateNFSExportStep);
                stepDescription = String.format("Replicating NFS export rules from source file system : %s to target file system : %s", sourceFileShare.getId(), targetFileShare.getId());
                Workflow.Method replicateNFSExportRulesMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_RULE_METHOD, systemTarget.getId(), fsURI);
                String replicateNFSExportRulesStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForExport, systemTarget.getId(), systemTarget.getSystemType(), getClass(), replicateNFSExportRulesMethod, null, replicateNFSExportRulesStep);
            }
        }
        String successMessage = "Failover FileSystem successful for: " + sourceFileShare.getLabel();
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not failover filesystems: " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.createFileSharesFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) MirrorFileFailoverTaskCompleter(com.emc.storageos.volumecontroller.impl.file.MirrorFileFailoverTaskCompleter) 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) URI(java.net.URI) 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) FileObject(com.emc.storageos.db.client.model.FileObject) List(java.util.List) ArrayList(java.util.ArrayList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 35 with SMBShareMap

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

the class FileOrchestrationDeviceController method addStepsToReplicateCIFSShareACLs.

/**
 * Child workflow for replicating source file system CIFS ACLs to target system.
 *
 * @param systemTarget
 *            - URI of target StorageSystem where source CIFS shares has to be replicated.
 * @param fsURI
 *            -URI of the source FileSystem
 * @param taskId
 */
public void addStepsToReplicateCIFSShareACLs(URI systemTarget, URI fsURI, String taskId) {
    s_logger.info("Generating steps for Replicating CIFS share ACLs to Target Cluster");
    CifsShareACLUpdateParams params;
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    FileShare targetFileShare = null;
    Workflow workflow = 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_CIFS_SHARE_ACLS_TO_TARGET_WF_NAME, false, taskId, completer);
        SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
        if (sourceSMBShareMap != null) {
            List<SMBFileShare> sourceSMBShares = new ArrayList<SMBFileShare>(sourceSMBShareMap.values());
            for (SMBFileShare sourceSMBShare : sourceSMBShares) {
                List<ShareACL> sourceShareACLs = FileOrchestrationUtils.queryShareACLs(sourceSMBShare.getName(), sourceFileShare.getId(), s_dbClient);
                List<ShareACL> targetShareACLs = FileOrchestrationUtils.queryShareACLs(sourceSMBShare.getName(), targetFileShare.getId(), s_dbClient);
                if (!sourceShareACLs.isEmpty() && targetShareACLs.isEmpty()) {
                    // target share doesn't have any ACLs but corresponding share on source does have ACL
                    params = new CifsShareACLUpdateParams();
                    ShareACLs shareACLs = new ShareACLs();
                    shareACLs.setShareACLs(sourceShareACLs);
                    params.setAclsToAdd(shareACLs);
                    updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
                } else if (!targetShareACLs.isEmpty() && sourceShareACLs.isEmpty()) {
                    // source share doesn't have any ACLs but corresponding share on target does have ACL
                    params = new CifsShareACLUpdateParams();
                    ShareACLs shareACLs = new ShareACLs();
                    shareACLs.setShareACLs(targetShareACLs);
                    // TO FIX COP-26361 DU case
                    // params.setAclsToDelete(shareACLs);
                    updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
                } else if (!targetShareACLs.isEmpty() && !sourceShareACLs.isEmpty()) {
                    // both source and target share have some ACL
                    List<ShareACL> shareACLsToAdd = new ArrayList<ShareACL>();
                    List<ShareACL> shareACLsToDelete = new ArrayList<ShareACL>();
                    List<ShareACL> shareACLsToModify = new ArrayList<ShareACL>();
                    HashMap<String, ShareACL> sourceShareACLMap = FileOrchestrationUtils.getShareACLMap(sourceShareACLs);
                    HashMap<String, ShareACL> targetShareACLMap = FileOrchestrationUtils.getShareACLMap(targetShareACLs);
                    // ACLs To Add
                    for (String sourceACLName : sourceShareACLMap.keySet()) {
                        if (targetShareACLMap.get(sourceACLName) == null) {
                            ShareACL shareACL = sourceShareACLMap.get(sourceACLName);
                            shareACL.setFileSystemId(targetFileShare.getId());
                            shareACLsToAdd.add(shareACL);
                        }
                    }
                    // ACLs To Delete
                    for (String targetACLName : targetShareACLMap.keySet()) {
                        if (sourceShareACLMap.get(targetACLName) == null) {
                            shareACLsToDelete.add(targetShareACLMap.get(targetACLName));
                        }
                    }
                    // ACLs to Modify
                    targetShareACLs.removeAll(shareACLsToDelete);
                    sourceShareACLs.removeAll(shareACLsToAdd);
                    sourceShareACLMap = FileOrchestrationUtils.getShareACLMap(sourceShareACLs);
                    targetShareACLMap = FileOrchestrationUtils.getShareACLMap(targetShareACLs);
                    for (String sourceACLName : sourceShareACLMap.keySet()) {
                        if (targetShareACLMap.get(sourceACLName) != null && !targetShareACLMap.get(sourceACLName).getPermission().equals(sourceShareACLMap.get(sourceACLName).getPermission())) {
                            ShareACL shareACL = targetShareACLMap.get(sourceACLName);
                            shareACL.setPermission(sourceShareACLMap.get(sourceACLName).getPermission());
                            shareACLsToModify.add(shareACL);
                        }
                    }
                    params = new CifsShareACLUpdateParams();
                    if (!shareACLsToAdd.isEmpty()) {
                        ShareACLs addShareACLs = new ShareACLs();
                        addShareACLs.setShareACLs(shareACLsToAdd);
                        params.setAclsToAdd(addShareACLs);
                    }
                    if (!shareACLsToDelete.isEmpty()) {
                        ShareACLs deleteShareACLs = new ShareACLs();
                        deleteShareACLs.setShareACLs(shareACLsToDelete);
                    // TO FIX COP-26361 DU case
                    // params.setAclsToDelete(deleteShareACLs);
                    }
                    if (!shareACLsToModify.isEmpty()) {
                        ShareACLs modifyShareACLs = new ShareACLs();
                        modifyShareACLs.setShareACLs(shareACLsToModify);
                        params.setAclsToModify(modifyShareACLs);
                    }
                    if (params.retrieveAllACLs() != null && !params.retrieveAllACLs().isEmpty()) {
                        updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
                    }
                }
            }
        }
        String successMessage = String.format("Replicating source File System : %s, CIFS Shares ACLs to Target System finished successfully", sourceFileShare.getLabel());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem CIFS shares ACLs : " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareCIFSACLsFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) ArrayList(java.util.ArrayList) CifsShareACLUpdateParams(com.emc.storageos.model.file.CifsShareACLUpdateParams) Workflow(com.emc.storageos.workflow.Workflow) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) ShareACL(com.emc.storageos.model.file.ShareACL) 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) ShareACLs(com.emc.storageos.model.file.ShareACLs) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Aggregations

SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)39 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)31 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)16 ArrayList (java.util.ArrayList)15 FileShare (com.emc.storageos.db.client.model.FileShare)14 URI (java.net.URI)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 ControllerException (com.emc.storageos.volumecontroller.ControllerException)11 Snapshot (com.emc.storageos.db.client.model.Snapshot)10 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)8 WorkflowException (com.emc.storageos.workflow.WorkflowException)6 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)5 DataDomainClient (com.emc.storageos.datadomain.restapi.DataDomainClient)4 DataDomainApiException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)4 FileObject (com.emc.storageos.db.client.model.FileObject)4 NetAppException (com.emc.storageos.netapp.NetAppException)4 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)3 FileExport (com.emc.storageos.db.client.model.FileExport)3 Operation (com.emc.storageos.db.client.model.Operation)3