Search in sources :

Example 71 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot 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)

Example 72 with Snapshot

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

the class FileSnapshotService method deleteSnapshot.

/**
 * Deactivate filesystem snapshot, this will move the snapshot to a "marked-for-delete" state.
 * This will be deleted by the garbage collector on a subsequent iteration
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @brief Delete file snapshot
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteSnapshot(@PathParam("id") URI id) throws InternalException {
    String task = UUID.randomUUID().toString();
    _log.info(String.format("FileSnapshotDelete --- Snapshot id: %1$s, Task: %2$s", id, task));
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    Operation op = null;
    if (snap != null) {
        ArgValidator.checkReference(Snapshot.class, id, checkForDelete(snap));
        if (snap.getInactive()) {
            op = new Operation();
            op.setResourceType(ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT);
            op.ready();
            _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, op);
        } else {
            FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
            if (null != fs) {
                StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
                op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT);
                FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
                fileServiceApi.deleteSnapshot(device.getId(), null, snap.getId(), false, FileControllerConstants.DeleteTypeEnum.FULL.toString(), task);
                auditOp(OperationTypeEnum.DELETE_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), device.getId().toString());
            }
        }
    }
    return toTask(snap, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) 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) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 73 with Snapshot

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

the class FileSnapshotService method export.

/**
 * Add file share snapshot export.
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @param param
 *            File system export parameters
 * @brief Create file snapshot export
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep export(@PathParam("id") URI id, FileSystemExportParam param) throws InternalException {
    _log.info("Snapshot Export request recieved {}", id);
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    ArgValidator.checkEntity(snap, id, true);
    if (!param.getPermissions().equals(FileShareExport.Permissions.ro.name())) {
        throw APIException.badRequests.snapshotExportPermissionReadOnly();
    }
    ArgValidator.checkFieldValueFromEnum(param.getSecurityType(), "type", EnumSet.allOf(FileShareExport.SecurityTypes.class));
    ArgValidator.checkFieldValueFromEnum(param.getProtocol(), "protocol", EnumSet.allOf(StorageProtocol.File.class));
    ArgValidator.checkSubDirName("sub_directory", param.getSubDirectory());
    FileService.validateIpInterfacesRegistered(param.getEndpoints(), _dbClient);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    // Locate storage port for exporting file snap
    // We use file system in the call since file snap belongs to the same neighbourhood as its parent file system
    StoragePort sport = _fileScheduler.placeFileShareExport(fs, param.getProtocol(), param.getEndpoints());
    String path = snap.getPath();
    String mountPath = snap.getMountPath();
    _log.info("Check whether there is a NFS Export already for the path {}", path);
    FSExportMap exportMap = snap.getFsExports();
    if (exportMap != null) {
        Iterator it = snap.getFsExports().keySet().iterator();
        boolean exportExists = false;
        while (it.hasNext()) {
            String fsExpKey = (String) it.next();
            FileExport fileExport = snap.getFsExports().get(fsExpKey);
            _log.info("Snap export key {} does it exist ? {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
            if (fileExport.getPath().equalsIgnoreCase(path)) {
                exportExists = true;
                _log.info("Snap export key {} exist {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
                break;
            }
        }
        if (exportExists) {
            throw APIException.badRequests.snapshotHasExistingExport();
        }
    }
    verifyFileSnapshotExports(snap, param, path);
    FileShareExport export = new FileShareExport(param.getEndpoints(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol(), sport.getPortGroup(), sport.getPortNetworkId(), path, mountPath, param.getSubDirectory(), param.getComments());
    _log.info("FileSnapExport --- FileSnap id: " + id + ", Clients: " + export.getClients() + ", StoragePort:" + sport.getPortName() + ", StoragePort :" + export.getStoragePort() + ", SecurityType: " + export.getSecurityType() + ", Permissions: " + export.getPermissions() + ", Root user mapping: " + export.getRootUserMapping() + ",Protocol: " + export.getProtocol() + ",path:" + export.getPath() + ",mountPath:" + export.getMountPath());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.EXPORT_FILE_SNAPSHOT);
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.export(device.getId(), snap.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.EXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), device.getId().toString(), export.getClients(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol());
    return toTask(snap, task, op);
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) Iterator(java.util.Iterator) FileExport(com.emc.storageos.db.client.model.FileExport) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 74 with Snapshot

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

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

the class FileSnapshotService method getSnapshotExportRules.

/**
 * Get Snapshot Export Rules
 *
 * @param id
 *            the URN of a file system
 * @param allDirs
 *            All Dirs within a file system
 * @param subDir
 *            sub-directory within a file system
 * @brief List the export rules for a snapshot
 * @return ExportRules
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/export")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ExportRules getSnapshotExportRules(@PathParam("id") URI id, @QueryParam("allDirs") boolean allDirs, @QueryParam("subDir") String subDir) {
    _log.info("Request recieved to list snapshotExports with Id : {}", new Object[] { id });
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snapshot = queryResource(id);
    ExportRules exportRules = new ExportRules();
    List<ExportRule> exportRule = new ArrayList<>();
    // Query All Export Rules Specific to a File System.
    List<FileExportRule> exports = queryDBSnapshotExports(snapshot);
    _log.info("Number of existing snapshot exports found : {} ", exports.size());
    // All EXPORTS
    for (FileExportRule rule : exports) {
        ExportRule expRule = new ExportRule();
        // Copy Props
        copyPropertiesToSave(rule, expRule, snapshot);
        exportRule.add(expRule);
    }
    _log.info("Number of snapshot export rules returning {}", exportRule.size());
    exportRules.setExportRules(exportRule);
    return exportRules;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) ExportRules(com.emc.storageos.model.file.ExportRules) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ArrayList(java.util.ArrayList) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

Snapshot (com.emc.storageos.db.client.model.Snapshot)92 FileShare (com.emc.storageos.db.client.model.FileShare)59 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)52 URI (java.net.URI)36 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 ControllerException (com.emc.storageos.volumecontroller.ControllerException)34 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)31 ArrayList (java.util.ArrayList)24 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)23 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)22 FileObject (com.emc.storageos.db.client.model.FileObject)21 URISyntaxException (java.net.URISyntaxException)21 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)19 WorkflowException (com.emc.storageos.workflow.WorkflowException)19 MapFileSnapshot (com.emc.storageos.api.mapper.functions.MapFileSnapshot)18 Path (javax.ws.rs.Path)18 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)17 Produces (javax.ws.rs.Produces)17