Search in sources :

Example 1 with ScheduleSnapshotList

use of com.emc.storageos.model.file.ScheduleSnapshotList 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 2 with ScheduleSnapshotList

use of com.emc.storageos.model.file.ScheduleSnapshotList in project coprhd-controller by CoprHD.

the class FileSystems method listPolicySnapshotJson.

public static void listPolicySnapshotJson(String fileSystemAndpolicyId) {
    renderArgs.put("dataTable", new FilePolicySnapshotsDataTable());
    String fileSystemId = null;
    String policyId = null;
    if (StringUtils.isNotBlank(fileSystemAndpolicyId)) {
        String[] parts = fileSystemAndpolicyId.split("~~~");
        if (parts.length == 2) {
            fileSystemId = parts[0];
            policyId = parts[1];
        }
    }
    ViPRCoreClient client = BourneUtil.getViprClient();
    List<FilePolicySnapshotsDataTable.FileSnapshot> snapshotList = Lists.newArrayList();
    ScheduleSnapshotList snapList = client.fileSystems().getFilePolicySnapshots(uri(fileSystemId), uri(policyId));
    for (ScheduleSnapshotRestRep snap : snapList.getScheduleSnapList()) {
        snapshotList.add(new FilePolicySnapshotsDataTable.FileSnapshot(snap));
    }
    renderJSON(DataTablesSupport.createJSON(snapshotList, params));
}
Also used : ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) FilePolicySnapshotsDataTable(models.datatable.FilePolicySnapshotsDataTable) ScheduleSnapshotRestRep(com.emc.storageos.model.file.ScheduleSnapshotRestRep)

Aggregations

ScheduleSnapshotList (com.emc.storageos.model.file.ScheduleSnapshotList)2 ScheduleSnapshotRestRep (com.emc.storageos.model.file.ScheduleSnapshotRestRep)2 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)1 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)1 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 Operation (com.emc.storageos.db.client.model.Operation)1 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)1 Snapshot (com.emc.storageos.db.client.model.Snapshot)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 Task (com.emc.storageos.db.client.model.Task)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 SnapshotList (com.emc.storageos.model.SnapshotList)1