Search in sources :

Example 11 with Snapshot

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

the class FileService method getFileSystemSchedulePolicySnapshots.

/**
 * Get file system Snapshot created by policy
 *
 * @param id
 *            The URN of a ViPR file system
 * @param filePolicyUri
 *            The URN of a file policy schedule
 * @param timeout
 *            Time limit in seconds to get the output .Default is 30 seconds
 * @brief Get snapshots related to the specified policy
 * @return List of snapshots created by a file policy
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/file-policies/{filePolicyUri}/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ScheduleSnapshotList getFileSystemSchedulePolicySnapshots(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, @QueryParam("timeout") int timeout) {
    // valid value of timeout is 10 sec to 10 min
    if (timeout < 10 || timeout > 600) {
        // default timeout value.
        timeout = 30;
    }
    ScheduleSnapshotList list = new ScheduleSnapshotList();
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
    ArgValidator.checkUri(filePolicyUri);
    FilePolicy sp = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
    ArgValidator.checkEntityNotNull(sp, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
    // verify the schedule policy is associated with file system or not.
    if (!fs.getFilePolicies().contains(filePolicyUri.toString())) {
        throw APIException.badRequests.cannotFindAssociatedPolicy(filePolicyUri);
    }
    String task = UUID.randomUUID().toString();
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE);
    op.setDescription("list snapshots created by a policy");
    try {
        _log.info("No Errors found. Proceeding further {}, {}, {}", new Object[] { _dbClient, fs, sp });
        controller.listSanpshotByPolicy(device.getId(), fs.getId(), sp.getId(), task);
        Task taskObject = null;
        auditOp(OperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), sp.getId());
        int timeoutCounter = 0;
        // wait till timeout or result from controller service ,whichever is earlier
        do {
            TimeUnit.SECONDS.sleep(1);
            taskObject = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), task);
            timeoutCounter++;
        // exit the loop if task is completed with error/success or timeout
        } while ((taskObject != null && !(taskObject.isReady() || taskObject.isError())) && timeoutCounter < timeout);
        if (taskObject == null) {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots task information");
        } else if (taskObject.isReady()) {
            URIQueryResultList snapshotsURIs = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id), snapshotsURIs);
            List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapshotsURIs);
            for (Snapshot snap : snapList) {
                if (!snap.getInactive() && snap.getExtensions().containsKey("schedule")) {
                    ScheduleSnapshotRestRep snapRest = new ScheduleSnapshotRestRep();
                    getScheduleSnapshotRestRep(snapRest, snap);
                    list.getScheduleSnapList().add(snapRest);
                    snap.setInactive(true);
                    _dbClient.updateObject(snap);
                }
            }
        } else if (taskObject.isError()) {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to" + taskObject.getMessage());
        } else {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to timeout");
        }
    } catch (BadRequestException e) {
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error while getting  Filesystem policy  Snapshots {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    } catch (Exception e) {
        _log.error("Error while getting  Filesystem policy  Snapshots {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return list;
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileController(com.emc.storageos.volumecontroller.FileController) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Snapshot(com.emc.storageos.db.client.model.Snapshot) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyList(com.emc.storageos.model.file.FilePolicyList) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) List(java.util.List) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) MirrorList(com.emc.storageos.model.block.MirrorList) SnapshotList(com.emc.storageos.model.SnapshotList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ScheduleSnapshotRestRep(com.emc.storageos.model.file.ScheduleSnapshotRestRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 12 with Snapshot

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

the class FileSnapshotService method getSnapshots.

/**
 * Get all Snapshots matching the path
 *
 * @QueryParam mountpath
 * @brief Show snapshots
 * @return Snapshot details
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public List<FileSnapshotRestRep> getSnapshots(@QueryParam("mountpath") String mountPath) {
    List<FileSnapshotRestRep> snapRepList = new ArrayList<FileSnapshotRestRep>();
    List<URI> ids = _dbClient.queryByType(Snapshot.class, true);
    Iterator<Snapshot> iter = _dbClient.queryIterativeObjects(Snapshot.class, ids);
    _log.info("getSnapshots call ... with mountpath {}", mountPath);
    while (iter.hasNext()) {
        Snapshot snap = iter.next();
        if (snap != null) {
            if (mountPath != null) {
                if (snap.getMountPath().equalsIgnoreCase(mountPath)) {
                    snapRepList.add(map(snap));
                } else {
                    _log.info("Skip this Snapshot Mount Path doesnt match {} {}", snap.getMountPath(), mountPath);
                }
            } else {
                _log.info("Mountpath query param is null");
                snapRepList.add(map(snap));
            }
        }
    }
    return snapRepList;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileSnapshotRestRep(com.emc.storageos.model.file.FileSnapshotRestRep) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with Snapshot

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

the class FileSnapshotService method deleteSnapshotShareACL.

/**
 * Delete Snapshot Share ACL
 *
 * @param id
 *            the file system URI
 * @param shareName
 *            name of the share
 * @brief Delete a snapshot ACL
 * @return TaskResponse
 */
@DELETE
@Path("/{id}/shares/{shareName}/acl")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteSnapshotShareACL(@PathParam("id") URI id, @PathParam("shareName") String shareName) {
    // log input received.
    _log.info("Delete ACL of share: Request received for {}, of file snapshot {}", shareName, id);
    String taskId = UUID.randomUUID().toString();
    // Validate the snapshot id.
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    ArgValidator.checkFieldNotNull(shareName, "shareName");
    Snapshot snapshot = queryResource(id);
    ArgValidator.checkEntity(snapshot, id, isIdEmbeddedInURL(id));
    if (!CifsShareUtility.doesShareExist(snapshot, shareName)) {
        _log.error("CIFS share does not exist {}", shareName);
        throw APIException.notFound.invalidParameterObjectHasNoSuchShare(snapshot.getId(), shareName);
    }
    FileShare fs = _permissionsHelper.getObjectById(snapshot.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    CifsShareUtility.checkForUpdateShareACLOperationOnStorage(device.getSystemType(), OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE_ACL.name());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE_ACL);
    op.setDescription("Delete ACL of Snapshot Cifs share");
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.deleteShareACLs(device.getId(), snapshot.getId(), shareName, taskId);
    auditOp(OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE_ACL, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), device.getId().toString(), shareName);
    return toTask(snapshot, taskId, 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) DELETE(javax.ws.rs.DELETE) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with Snapshot

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

the class FileSnapshotService method getTenantOwner.

@Override
protected URI getTenantOwner(URI id) {
    Snapshot snapshot = queryResource(id);
    URI projectUri = snapshot.getProject().getURI();
    ArgValidator.checkUri(projectUri);
    Project project = _permissionsHelper.getObjectById(projectUri, Project.class);
    ArgValidator.checkEntityNotNull(project, projectUri, isIdEmbeddedInURL(projectUri));
    return project.getTenantOrg().getURI();
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 15 with Snapshot

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

the class FileSnapshotService method getFileSystemSnapshotExportList.

/**
 * @Deprecated use {id}/export instead
 *             Get file share snapshots exports
 * @param id
 *            the URN of a ViPR Snapshot
 * @brief List file snapshot exports.This method is deprecated.
 *        <p>
 *        Use /file/snapshots/{id}/export instead.
 * @return List of file share snapshot exports
 */
@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 getFileSystemSnapshotExportList(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snapshot = queryResource(id);
    FileSystemExportList fileExportListResponse = new FileSystemExportList();
    if (snapshot.getInactive()) {
        return fileExportListResponse;
    }
    // Get export map from snapshot
    FSExportMap exportMap = snapshot.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());
        fileExportListResponse.getExportList().add(fileExportParam);
    }
    return fileExportListResponse;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) 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) 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