Search in sources :

Example 11 with VNXeNfsShare

use of com.emc.storageos.vnxe.models.VNXeNfsShare in project coprhd-controller by CoprHD.

the class VNXeApiClient method exportFileSystem.

/**
 * NFS export
 *
 * @param fsId
 *            file system KH id
 * @param endpoints
 *            list of host ipaddresses export to
 * @param access
 *            access right
 * @return VNXeCommandJob
 * @throws VNXeException
 */
public VNXeCommandJob exportFileSystem(String fsId, List<String> roEndpoints, List<String> rwEndpoints, List<String> rootEndpoints, AccessEnum access, String path, String shareName, String shareId, String comments) throws VNXeException {
    _logger.info("Exporting file system:" + fsId);
    FileSystemRequest fsRequest = new FileSystemRequest(_khClient, fsId);
    VNXeFileSystem fs = fsRequest.get();
    if (fs == null) {
        _logger.info("Could not find file system in the vxne");
        throw VNXeException.exceptions.vnxeCommandFailed("Could not find file system in the vnxe for: " + fsId);
    }
    String resourceId = fs.getStorageResource().getId();
    ModifyFileSystemParam modifyFSParm = new ModifyFileSystemParam();
    List<VNXeBase> roHosts = getHosts(roEndpoints);
    List<VNXeBase> rwHosts = getHosts(rwEndpoints);
    List<VNXeBase> rootHosts = getHosts(rootEndpoints);
    VNXeNfsShare nfsShareFound = null;
    if (shareName != null) {
        nfsShareFound = findNfsShare(fsId, shareName);
    } else {
        nfsShareFound = getNfsShareById(shareId);
    }
    String nfsShareId = null;
    List<VNXeBase> hosts = new ArrayList<VNXeBase>();
    if (nfsShareFound != null) {
        nfsShareId = nfsShareFound.getId();
    }
    NfsShareParam shareParm = new NfsShareParam();
    shareParm.setReadOnlyHosts(roHosts);
    shareParm.setReadWriteHosts(rwHosts);
    shareParm.setRootAccessHosts(rootHosts);
    if (comments != null) {
        shareParm.setDescription(comments);
    }
    if (access == null) {
        if (nfsShareFound != null) {
            hosts.addAll(nfsShareFound.getNoAccessHosts());
            hosts.addAll(nfsShareFound.getRootAccessHosts());
            hosts.addAll(nfsShareFound.getReadWriteHosts());
            hosts.addAll(nfsShareFound.getReadOnlyHosts());
        }
        NFSShareDefaultAccessEnum nfsShareDefaultAccess = NFSShareDefaultAccessEnum.NONE;
        if (nfsShareFound != null) {
            nfsShareDefaultAccess = nfsShareFound.getDefaultAccess();
        }
        if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.ROOT)) {
            if (!hosts.isEmpty()) {
                shareParm.setRootAccessHosts(hosts);
            } else {
                shareParm.setRootAccessHosts(null);
            }
            shareParm.setNoAccessHosts(null);
            shareParm.setReadWriteHosts(null);
            shareParm.setReadOnlyHosts(null);
        } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READONLY)) {
            if (!hosts.isEmpty()) {
                shareParm.setReadOnlyHosts(hosts);
            } else {
                shareParm.setReadOnlyHosts(null);
            }
            shareParm.setNoAccessHosts(null);
            shareParm.setReadWriteHosts(null);
            shareParm.setRootAccessHosts(null);
        } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READWRITE)) {
            if (!hosts.isEmpty()) {
                shareParm.setReadWriteHosts(hosts);
            } else {
                shareParm.setReadWriteHosts(null);
            }
            shareParm.setNoAccessHosts(null);
            shareParm.setReadOnlyHosts(null);
            shareParm.setRootAccessHosts(null);
        } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.NONE)) {
            if (!hosts.isEmpty()) {
                shareParm.setNoAccessHosts(hosts);
            } else {
                shareParm.setNoAccessHosts(null);
            }
            shareParm.setReadWriteHosts(null);
            shareParm.setReadOnlyHosts(null);
            shareParm.setRootAccessHosts(null);
        }
    }
    if (nfsShareId == null) {
        // not found, new export
        if (!isUnityClient()) {
            shareParm.setDefaultAccess(NFSShareDefaultAccessEnum.NONE);
        }
        NfsShareCreateParam nfsShareCreateParm = new NfsShareCreateParam();
        nfsShareCreateParm.setName(shareName);
        nfsShareCreateParm.setPath(path);
        nfsShareCreateParm.setNfsShareParameters(shareParm);
        List<NfsShareCreateParam> nfsList = new ArrayList<NfsShareCreateParam>();
        nfsList.add(nfsShareCreateParm);
        modifyFSParm.setNfsShareCreate(nfsList);
    } else {
        // update export
        NfsShareModifyParam nfsShareModifyParam = new NfsShareModifyParam();
        VNXeBase nfsShare = new VNXeBase();
        nfsShare.setId(nfsShareId);
        nfsShareModifyParam.setNfsShare(nfsShare);
        nfsShareModifyParam.setNfsShareParameters(shareParm);
        List<NfsShareModifyParam> nfsModifyList = new ArrayList<NfsShareModifyParam>();
        nfsModifyList.add(nfsShareModifyParam);
        modifyFSParm.setNfsShareModify(nfsModifyList);
    }
    FileSystemActionRequest req = new FileSystemActionRequest(_khClient);
    return req.modifyFileSystemAsync(modifyFSParm, resourceId);
}
Also used : VNXeFileSystem(com.emc.storageos.vnxe.models.VNXeFileSystem) NFSShareDefaultAccessEnum(com.emc.storageos.vnxe.models.NfsShareParam.NFSShareDefaultAccessEnum) ArrayList(java.util.ArrayList) NfsShareCreateParam(com.emc.storageos.vnxe.models.NfsShareCreateParam) NfsShareModifyParam(com.emc.storageos.vnxe.models.NfsShareModifyParam) FileSystemRequest(com.emc.storageos.vnxe.requests.FileSystemRequest) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) NfsShareParam(com.emc.storageos.vnxe.models.NfsShareParam) ModifyFileSystemParam(com.emc.storageos.vnxe.models.ModifyFileSystemParam) FileSystemActionRequest(com.emc.storageos.vnxe.requests.FileSystemActionRequest)

Example 12 with VNXeNfsShare

use of com.emc.storageos.vnxe.models.VNXeNfsShare in project coprhd-controller by CoprHD.

the class VNXeApiClient method createNfsShareForSnap.

/**
 * Create Nfs share for snapshot
 *
 * @param snapId
 *            snapshot id
 * @param endpoints
 *            hosts
 * @param access
 *            READ, WRITE, ROOT
 * @param path
 * @param exportKey
 * @return VNXeCommandJob
 * @throws VNXeException
 */
public VNXeCommandJob createNfsShareForSnap(String snapId, List<String> roEndpoints, List<String> rwEndpoints, List<String> rootEndpoints, AccessEnum access, String path, String shareName, String comments) throws VNXeException {
    _logger.info("creating nfs share for the snap: " + snapId);
    NfsShareRequests request = new NfsShareRequests(_khClient);
    String softwareVersion = getBasicSystemInfo().getSoftwareVersion();
    FileSystemSnapRequests req = new FileSystemSnapRequests(_khClient, softwareVersion);
    VNXeFileSystemSnap snapshot = req.getFileSystemSnap(snapId, softwareVersion);
    if (snapshot == null) {
        _logger.info("Could not find snapshot in the vxne");
        throw VNXeException.exceptions.vnxeCommandFailed("Could not find snapshot in the vnxe for: " + snapId);
    }
    NfsShareCreateForSnapParam nfsCreateParam = new NfsShareCreateForSnapParam();
    VNXeBase snap = new VNXeBase(snapId);
    if (!VNXeUtils.isHigherVersion(softwareVersion, VNXeConstants.VNXE_BASE_SOFT_VER)) {
        nfsCreateParam.setFilesystemSnap(snap);
    } else {
        nfsCreateParam.setSnap(snap);
    }
    List<VNXeBase> roHosts = getHosts(roEndpoints);
    List<VNXeBase> rwHosts = getHosts(rwEndpoints);
    List<VNXeBase> rootHosts = getHosts(rootEndpoints);
    VNXeCommandJob job = null;
    VNXeNfsShare nfsShareFound = request.findSnapNfsShare(snapId, shareName, softwareVersion);
    if (nfsShareFound == null) {
        // new export
        nfsCreateParam.setReadOnlyHosts(roHosts);
        nfsCreateParam.setReadWriteHosts(rwHosts);
        nfsCreateParam.setRootAccessHosts(rootHosts);
        nfsCreateParam.setName(shareName);
        nfsCreateParam.setPath(path);
        if (comments != null) {
            nfsCreateParam.setDescription(comments);
        }
        request.unsetQueryParameters();
        job = request.createShareForSnapshot(nfsCreateParam);
    } else {
        String nfsShareId = nfsShareFound.getId();
        NFSShareDefaultAccessEnum nfsShareDefaultAccess = nfsShareFound.getDefaultAccess();
        NfsShareModifyForShareParam nfsModifyParam = new NfsShareModifyForShareParam();
        List<VNXeBase> hosts = new ArrayList<VNXeBase>();
        nfsModifyParam.setReadOnlyHosts(roHosts);
        nfsModifyParam.setReadWriteHosts(rwHosts);
        nfsModifyParam.setRootAccessHosts(rootHosts);
        if (comments != null) {
            nfsModifyParam.setDescription(comments);
        }
        if (access == null) {
            if (nfsShareFound != null) {
                hosts.addAll(nfsShareFound.getNoAccessHosts());
                hosts.addAll(nfsShareFound.getRootAccessHosts());
                hosts.addAll(nfsShareFound.getReadWriteHosts());
                hosts.addAll(nfsShareFound.getReadOnlyHosts());
            }
            if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.ROOT)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setRootAccessHosts(hosts);
                } else {
                    nfsModifyParam.setRootAccessHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READONLY)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setReadOnlyHosts(hosts);
                } else {
                    nfsModifyParam.setReadOnlyHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.READWRITE)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setReadWriteHosts(hosts);
                } else {
                    nfsModifyParam.setReadWriteHosts(null);
                }
                nfsModifyParam.setNoAccessHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            } else if (nfsShareDefaultAccess.equals(NFSShareDefaultAccessEnum.NONE)) {
                if (!hosts.isEmpty()) {
                    nfsModifyParam.setNoAccessHosts(hosts);
                } else {
                    nfsModifyParam.setNoAccessHosts(null);
                }
                nfsModifyParam.setReadWriteHosts(null);
                nfsModifyParam.setReadOnlyHosts(null);
                nfsModifyParam.setRootAccessHosts(null);
            }
        }
        request.unsetQueryParameters();
        job = request.modifyShareForSnapshot(nfsShareId, nfsModifyParam);
    }
    return job;
}
Also used : VNXeFileSystemSnap(com.emc.storageos.vnxe.models.VNXeFileSystemSnap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileSystemSnapRequests(com.emc.storageos.vnxe.requests.FileSystemSnapRequests) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) NfsShareRequests(com.emc.storageos.vnxe.requests.NfsShareRequests) NFSShareDefaultAccessEnum(com.emc.storageos.vnxe.models.NfsShareParam.NFSShareDefaultAccessEnum) NfsShareModifyForShareParam(com.emc.storageos.vnxe.models.NfsShareModifyForShareParam) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) ArrayList(java.util.ArrayList) NfsShareCreateForSnapParam(com.emc.storageos.vnxe.models.NfsShareCreateForSnapParam)

Example 13 with VNXeNfsShare

use of com.emc.storageos.vnxe.models.VNXeNfsShare in project coprhd-controller by CoprHD.

the class VNXeExportFileSystemJob method updateFSExport.

/**
 * update FileShare after exported in VNXe
 *
 * @param fsOjb fileShare object in vipr
 * @param dbClient DbClient
 * @param vnxeApiClient VNXeApiClient
 */
private void updateFSExport(FileShare fsObj, DbClient dbClient, VNXeApiClient apiClient, FileExport newExport) {
    _logger.info("upading file export. ");
    FSExportMap exports = fsObj.getFsExports();
    if (exports == null) {
        exports = new FSExportMap();
    }
    VNXeNfsShare nfsShare = apiClient.findNfsShare(fsObj.getNativeId(), shareName);
    String nfsShareId = nfsShare.getId();
    newExport.setIsilonId(nfsShareId);
    exports.put(newExport.getFileExportKey(), newExport);
    fsObj.setFsExports(exports);
    updateExportRules(fsObj.getId(), newExport, dbClient);
    dbClient.persistObject(fsObj);
}
Also used : VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) FSExportMap(com.emc.storageos.db.client.model.FSExportMap)

Example 14 with VNXeNfsShare

use of com.emc.storageos.vnxe.models.VNXeNfsShare in project coprhd-controller by CoprHD.

the class VNXeExportFileSystemJob method updateSnapExport.

/**
 * update snapshot if the export job is for snapshot export
 *
 * @param dbClient
 * @param apiClient
 * @return Snapshot instance
 */
private Snapshot updateSnapExport(DbClient dbClient, VNXeApiClient apiClient, FileExport newExport) {
    _logger.info("upading snap export. ");
    URI snapId = getTaskCompleter().getId();
    Snapshot snapObj = dbClient.queryObject(Snapshot.class, snapId);
    FSExportMap exports = snapObj.getFsExports();
    if (exports == null) {
        exports = new FSExportMap();
    }
    VNXeNfsShare nfsShare = apiClient.findSnapNfsShare(snapObj.getNativeId(), shareName);
    String nfsShareId = nfsShare.getId();
    newExport.setIsilonId(nfsShareId);
    exports.put(newExport.getFileExportKey(), newExport);
    snapObj.setFsExports(exports);
    updateExportRules(snapObj.getId(), newExport, dbClient);
    dbClient.persistObject(snapObj);
    return snapObj;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) URI(java.net.URI)

Example 15 with VNXeNfsShare

use of com.emc.storageos.vnxe.models.VNXeNfsShare in project coprhd-controller by CoprHD.

the class VNXeModifyExportJob method updateStatus.

/**
 * Called to update the job status when the export file system job completes.
 *
 * @param jobContext The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
        FileShare fsObj = null;
        Snapshot snapObj = null;
        URI objId = getTaskCompleter().getId();
        StorageSystem storageObj = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS) {
            _isSuccess = true;
            FileExport newExport = null;
            if (exportInfo != null) {
                newExport = exportInfo.getFileExport();
            }
            VNXeNfsShare nfsShare = null;
            if (isFile) {
                fsObj = dbClient.queryObject(FileShare.class, objId);
                nfsShare = vnxeApiClient.getNfsShareById(rule.getDeviceExportId());
                // nfsShare = vnxeApiClient.findNfsShare(fsObj.getNativeId(), shareName);
                updateExportRules(vnxeApiClient, dbClient, fsObj, nfsShare);
                if (newExport != null) {
                    updateFSExport(fsObj, dbClient, newExport);
                }
            } else {
                snapObj = dbClient.queryObject(Snapshot.class, objId);
                fsObj = dbClient.queryObject(FileShare.class, snapObj.getParent().getURI());
                nfsShare = vnxeApiClient.findSnapNfsShare(snapObj.getNativeId(), shareName);
                updateExportRules(vnxeApiClient, dbClient, fsObj, nfsShare);
                if (newExport != null) {
                    updateSnapshotExport(snapObj, dbClient, newExport);
                }
            }
        } else if (_status == JobStatus.FAILED) {
            // cleanupFSExport(fsObj, dbClient);
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("Task %s failed to update export rules: %s", opId, objId.toString()));
        }
        _logger.info(logMsgBuilder.toString());
        if (isFile) {
            FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SYSTEM, _isSuccess, logMsgBuilder.toString(), "", fsObj, storageObj);
        } else {
            FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SNAPSHOT, _isSuccess, logMsgBuilder.toString(), "", snapObj, fsObj, storageObj);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeModifyExportJob", e);
        setErrorStatus("Encountered an internal error during update export rules job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) FileExport(com.emc.storageos.db.client.model.FileExport) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) FileShare(com.emc.storageos.db.client.model.FileShare) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

VNXeNfsShare (com.emc.storageos.vnxe.models.VNXeNfsShare)19 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)6 NfsShareRequests (com.emc.storageos.vnxe.requests.NfsShareRequests)6 ArrayList (java.util.ArrayList)6 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)4 VNXeFileSystem (com.emc.storageos.vnxe.models.VNXeFileSystem)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)3 VNXeFileSystemSnap (com.emc.storageos.vnxe.models.VNXeFileSystemSnap)3 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 Snapshot (com.emc.storageos.db.client.model.Snapshot)2 StoragePort (com.emc.storageos.db.client.model.StoragePort)2 UnManagedFileExportRule (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule)2 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)2 ExportRule (com.emc.storageos.model.file.ExportRule)2 NFSShareDefaultAccessEnum (com.emc.storageos.vnxe.models.NfsShareParam.NFSShareDefaultAccessEnum)2 VNXeCifsShare (com.emc.storageos.vnxe.models.VNXeCifsShare)2 VNXeHost (com.emc.storageos.vnxe.models.VNXeHost)2 UnManagedExportVerificationUtility (com.emc.storageos.volumecontroller.impl.utils.UnManagedExportVerificationUtility)2 IOException (java.io.IOException)2