Search in sources :

Example 36 with SMBShareMap

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

the class FileOrchestrationDeviceController method addStepsToReplicateCIFSShares.

/**
 * Child workflow for replicating source file system CIFS shares to target.
 *
 * @param systemTarget
 *            - URI of target StorageSystem where source CIFS shares has to be replicated.
 * @param fsURI
 *            -URI of the source FileSystem
 * @param cifsPort
 *            -StoragePort, CIFS port of target File System where new shares has to be created.
 * @param taskId
 */
public void addStepsToReplicateCIFSShares(URI systemTarget, URI fsURI, StoragePort cifsPort, String taskId) {
    s_logger.info("Generating steps for Replicating CIFS shares 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_CIFS_SHARES_TO_TARGET_WF_NAME, false, taskId, completer);
        SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
        SMBShareMap targetSMBShareMap = targetFileShare.getSMBFileShares();
        if (sourceSMBShareMap == null && targetSMBShareMap != null) {
            // source file system don't have any CIFS share but target do have share.
            List<SMBFileShare> targetSMBShares = new ArrayList<SMBFileShare>(targetSMBShareMap.values());
            deleteCIFSShareFromTarget(workflow, systemTarget, targetSMBShares, targetFileShare);
        } else if (targetSMBShareMap == null && sourceSMBShareMap != null) {
            // target file system don't have any CIFS share but source do have share
            List<SMBFileShare> sourceSMBShares = new ArrayList<SMBFileShare>(sourceSMBShareMap.values());
            createCIFSShareOnTarget(workflow, systemTarget, sourceSMBShares, cifsPort, targetFileShare, sourceFileShare);
        } else if (targetSMBShareMap != null && sourceSMBShareMap != null) {
            // both source and target file system do have some shares..
            List<SMBFileShare> targetSMBSharestoDelete = new ArrayList<SMBFileShare>();
            List<SMBFileShare> targetSMBSharestoCreate = new ArrayList<SMBFileShare>();
            for (String sourceSMBSharesName : sourceSMBShareMap.keySet()) {
                if (targetSMBShareMap.get(sourceSMBSharesName) == null) {
                    targetSMBSharestoCreate.add(sourceSMBShareMap.get(sourceSMBSharesName));
                }
            }
            for (String targetSMBSharesName : targetSMBShareMap.keySet()) {
                if (sourceSMBShareMap.get(targetSMBSharesName) == null) {
                    targetSMBSharestoDelete.add(targetSMBShareMap.get(targetSMBSharesName));
                }
            }
            if (!targetSMBSharestoCreate.isEmpty()) {
                createCIFSShareOnTarget(workflow, systemTarget, targetSMBSharestoCreate, cifsPort, targetFileShare, sourceFileShare);
            }
            if (!targetSMBSharestoDelete.isEmpty()) {
                deleteCIFSShareFromTarget(workflow, systemTarget, targetSMBSharestoDelete, targetFileShare);
            }
        }
        String successMessage = String.format("Replicating source File System : %s, CIFS Shares to Target System finished successfully", sourceFileShare.getLabel());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem CIFS shares: " + 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) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) 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) List(java.util.List) ArrayList(java.util.ArrayList) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 37 with SMBShareMap

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

the class FileSnapshotService method getFileSystemShareList.

/**
 * Lists all SMB shares for the specified snapshot.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @brief List file snapshot SMB shares
 * @return List of SMB shares
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSystemShareList getFileSystemShareList(@PathParam("id") URI id) {
    _log.info(String.format("Get list of SMB file shares for snapshot: %1$s", id));
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    FileSystemShareList fileShareListResponse = new FileSystemShareList();
    if (snap.getInactive()) {
        return fileShareListResponse;
    }
    // Get SMB share map from snapshot
    SMBShareMap smbShareMap = snap.getSMBFileShares();
    Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
    if (smbShareMap != null) {
        smbShares = smbShareMap.values();
    }
    // Process each share from the map and add its data to shares in response list.
    for (SMBFileShare smbShare : smbShares) {
        SmbShareResponse shareParam = new SmbShareResponse();
        shareParam.setShareName(smbShare.getName());
        shareParam.setDescription(smbShare.getDescription());
        shareParam.setMaxUsers(Integer.toString(smbShare.getMaxUsers()));
        // Check for "unlimited"
        if (shareParam.getMaxUsers().equals("-1")) {
            shareParam.setMaxUsers(FileService.UNLIMITED_USERS);
        }
        shareParam.setPermissionType(smbShare.getPermissionType());
        shareParam.setPermission(smbShare.getPermission());
        shareParam.setMountPoint(smbShare.getMountPoint());
        shareParam.setPath(smbShare.getPath());
        fileShareListResponse.getShareList().add(shareParam);
    }
    return fileShareListResponse;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) ArrayList(java.util.ArrayList) SmbShareResponse(com.emc.storageos.model.file.SmbShareResponse) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 38 with SMBShareMap

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

the class CifsShareUtility method doesShareExist.

/**
 * Checks whether share exists in the file object
 *
 * @param fileObject fileshare or snapshot object
 * @param shareName name of the share
 * @return true if share exists in the SMBShareMap, false otherwise
 */
public static boolean doesShareExist(FileObject fileObject, String shareName) {
    SMBShareMap existingShares = fileObject.getSMBFileShares();
    if (existingShares != null && !existingShares.isEmpty()) {
        SMBFileShare existingShare = existingShares.get(shareName);
        if (existingShare != null) {
            _log.info("CIFS share: {}, exists in ", shareName, fileObject.getId());
            return true;
        }
    }
    _log.info("CIFS share: {}, does not exist in {}", shareName, fileObject.getId());
    return false;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 39 with SMBShareMap

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

the class FileDeviceController method deleteQDExportsAndShares.

/**
 * Delete NFS exports and shares file system quota directory
 *
 * @param storage
 * @param fs
 * @param quotaDirObj
 * @param task
 */
private void deleteQDExportsAndShares(URI storage, FileShare fs, QuotaDirectory quotaDirObj, String task) {
    FSExportMap fsExportMap = fs.getFsExports();
    String quotaName = quotaDirObj.getName();
    boolean isExported = false;
    // delete export
    if (fsExportMap != null && !fsExportMap.isEmpty()) {
        // check the quota directory is exported
        for (FileExport fileExport : fsExportMap.values()) {
            if (quotaName.equals(fileExport.getSubDirectory()) && fileExport.getPath().endsWith(quotaName)) {
                isExported = true;
                _log.info("Delete the nfs sub directory export path {} and key {}", fileExport.getPath(), fileExport.getFileExportKey());
            }
        }
        if (true == isExported) {
            // delete the export of quota directory
            this.deleteExportRules(storage, fs.getId(), false, quotaName, task);
        }
    }
    // delete fileshare of quota directory
    SMBShareMap smbShareMap = fs.getSMBFileShares();
    if (smbShareMap != null && !smbShareMap.isEmpty()) {
        FileSMBShare fileSMBShare = null;
        List<FileSMBShare> fileSMBShares = new ArrayList<FileSMBShare>();
        for (SMBFileShare smbFileShare : smbShareMap.values()) {
            // check for quotaname in native fs path
            if (true == (smbFileShare.getPath().endsWith(quotaName))) {
                fileSMBShare = new FileSMBShare(smbFileShare);
                _log.info("Delete the cifs sub directory path of quota directory {}", smbFileShare.getPath());
                fileSMBShares.add(fileSMBShare);
            }
        }
        if (fileSMBShares != null && !fileSMBShares.isEmpty()) {
            // delete shares
            for (FileSMBShare tempFileSMBShare : fileSMBShares) {
                this.deleteShare(storage, fs.getId(), tempFileSMBShare, task);
                _log.info("Delete SMB Share Name{} for quota ", tempFileSMBShare.getName());
            }
        }
    }
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare)

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