Search in sources :

Example 51 with FileExport

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

the class NetAppFileStorageDevice method netAppDeleteNFSExports.

private Boolean netAppDeleteNFSExports(StorageSystem storage, FSExportMap exportMap) throws NetAppException {
    int failedCount = 0;
    Iterator<Map.Entry<String, FileExport>> it = exportMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, FileExport> entry = it.next();
        String key = entry.getKey();
        FileExport fsExport = entry.getValue();
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
        if (!nApi.deleteNFS(fsExport.getPath())) {
            failedCount++;
        } else {
            exportMap.remove(key);
        }
    }
    if (failedCount > 0) {
        return false;
    } else {
        return true;
    }
}
Also used : Entry(java.util.Map.Entry) FileExport(com.emc.storageos.db.client.model.FileExport) NetAppApi(com.emc.storageos.netapp.NetAppApi) HashMap(java.util.HashMap) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Map(java.util.Map) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap)

Example 52 with FileExport

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

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

the class ComputeSystemControllerImpl method addStepsForFileShares.

public String addStepsForFileShares(Workflow workflow, String waitFor, URI hostId) {
    String newWaitFor = waitFor;
    List<FileShare> fileShares = ComputeSystemHelper.getFileSharesByHost(_dbClient, hostId);
    List<String> endpoints = ComputeSystemHelper.getIpInterfaceEndpoints(_dbClient, hostId);
    for (FileShare fileShare : fileShares) {
        if (fileShare != null && fileShare.getFsExports() != null) {
            for (FileExport fileExport : fileShare.getFsExports().values()) {
                if (fileExport != null && fileExport.getClients() != null) {
                    if (fileExportContainsEndpoint(fileExport, endpoints)) {
                        StorageSystem device = _dbClient.queryObject(StorageSystem.class, fileShare.getStorageDevice());
                        List<String> clients = fileExport.getClients();
                        clients.removeAll(endpoints);
                        fileExport.setStoragePort(fileShare.getStoragePort().toString());
                        FileShareExport export = new FileShareExport(clients, fileExport.getSecurityType(), fileExport.getPermissions(), fileExport.getRootUserMapping(), fileExport.getProtocol(), fileExport.getStoragePortName(), fileExport.getStoragePort(), fileExport.getPath(), fileExport.getMountPath(), "", "");
                        if (clients.isEmpty()) {
                            _log.info("Unexporting file share " + fileShare.getId());
                            newWaitFor = workflow.createStep(UNEXPORT_FILESHARE_STEP, String.format("Unexport fileshare %s", fileShare.getId()), waitFor, fileShare.getId(), fileShare.getId().toString(), this.getClass(), unexportFileShareMethod(device.getId(), device.getSystemType(), fileShare.getId(), export), rollbackMethodNullMethod(), null);
                        } else {
                            _log.info("Updating export for file share " + fileShare.getId());
                            newWaitFor = workflow.createStep(UPDATE_FILESHARE_EXPORT_STEP, String.format("Update fileshare export %s", fileShare.getId()), waitFor, fileShare.getId(), fileShare.getId().toString(), this.getClass(), updateFileShareMethod(device.getId(), device.getSystemType(), fileShare.getId(), export), rollbackMethodNullMethod(), null);
                        }
                    }
                }
            }
        }
    }
    return newWaitFor;
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) FileExport(com.emc.storageos.db.client.model.FileExport) FileShare(com.emc.storageos.db.client.model.FileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 54 with FileExport

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

the class FileService method getFileSystemExportList.

/**
 * @Deprecated use @Path("/{id}/export") instead.
 *             Get list of file system exports
 * @param id
 *            the URN of a ViPR File system
 * @brief List file system exports.
 *        <p>
 *        Use /file/filesystems/{id}/export instead
 * @return File system exports list.
 */
@Deprecated
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSystemExportList getFileSystemExportList(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fileShare = queryResource(id);
    FileSystemExportList fileExportListResponse = new FileSystemExportList();
    if (fileShare.getInactive()) {
        return fileExportListResponse;
    }
    // Get export map from fileSystem
    FSExportMap exportMap = fileShare.getFsExports();
    Collection<FileExport> fileExports = new ArrayList<FileExport>();
    if (exportMap != null) {
        fileExports = exportMap.values();
    }
    // Process each export from the map and its data to exports in response list.
    for (FileExport fileExport : fileExports) {
        FileSystemExportParam fileExportParam = new FileSystemExportParam();
        fileExportParam.setEndpoints(fileExport.getClients());
        fileExportParam.setSecurityType(fileExport.getSecurityType());
        fileExportParam.setPermissions(fileExport.getPermissions());
        fileExportParam.setRootUserMapping(fileExport.getRootUserMapping());
        fileExportParam.setProtocol(fileExport.getProtocol());
        fileExportParam.setMountPoint(fileExport.getMountPoint());
        fileExportParam.setSubDirectory(fileExport.getSubDirectory());
        fileExportListResponse.getExportList().add(fileExportParam);
    }
    return fileExportListResponse;
}
Also used : FileSystemExportParam(com.emc.storageos.model.file.FileSystemExportParam) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 55 with FileExport

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

the class FileSnapshotService method unexport.

/**
 * Remove file share snapshot export.
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @param protocol
 *            Protocol valid values - NFS,NFSv4,CIFS
 * @param securityType
 *            Security type valid values - sys,krb5,krb5i,krb5p
 * @param permissions
 *            Permissions valid values - ro,rw,root
 * @param rootUserMapping
 *            Root user mapping
 * @brief Delete file snapshot export
 * @return Task resource representation
 * @throws InternalException
 */
@DELETE
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports/{protocol},{secType},{perm},{rootMapping}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep unexport(@PathParam("id") URI id, @PathParam("protocol") String protocol, @PathParam("secType") String securityType, @PathParam("perm") String permissions, @PathParam("rootMapping") String rootUserMapping) throws InternalException {
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    ArgValidator.checkFieldNotNull(protocol, "protocol");
    ArgValidator.checkFieldNotNull(securityType, "secType");
    ArgValidator.checkFieldNotNull(permissions, "perm");
    ArgValidator.checkFieldNotNull(rootUserMapping, "rootMapping");
    if (snap.getFsExports() == null || snap.getFsExports().isEmpty()) {
        // No export to unexport, return success.
        String message = "Export does not exist";
        return getSuccessResponse(snap, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, message);
    }
    ArgValidator.checkEntity(snap, id, isIdEmbeddedInURL(id));
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    String path = snap.getPath();
    _log.info(String.format("securityType %1$s, permissions %2$s, rootMapping %3$s %4$s", securityType, permissions, rootUserMapping, path));
    FileExport fileSnapExport = snap.getFsExports().get(FileExport.exportLookupKey(protocol, securityType, permissions, rootUserMapping, path));
    if (fileSnapExport == null) {
        // No export to unexport, return success.
        String message = "Export does not exist";
        return getSuccessResponse(snap, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, message);
    }
    // empty list for unexport
    List<String> endpoints = new ArrayList<String>();
    FileShareExport export = new FileShareExport(endpoints, securityType, permissions, rootUserMapping, protocol, fileSnapExport.getStoragePortName(), fileSnapExport.getStoragePort(), fileSnapExport.getPath());
    export.setIsilonId(fileSnapExport.getIsilonId());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT);
    controller.unexport(device.getId(), snap.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), device.getId().toString(), securityType, permissions, rootUserMapping, protocol);
    return toTask(snap, task, op);
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileController(com.emc.storageos.volumecontroller.FileController) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

FileExport (com.emc.storageos.db.client.model.FileExport)66 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)33 ArrayList (java.util.ArrayList)32 FileShare (com.emc.storageos.db.client.model.FileShare)31 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)29 Snapshot (com.emc.storageos.db.client.model.Snapshot)21 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)20 FileShareExport (com.emc.storageos.volumecontroller.FileShareExport)18 ControllerException (com.emc.storageos.volumecontroller.ControllerException)17 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)16 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)14 VNXeException (com.emc.storageos.vnxe.VNXeException)12 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)11 URI (java.net.URI)10 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)8 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)8 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)8 FileObject (com.emc.storageos.db.client.model.FileObject)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7