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;
}
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;
}
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);
}
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();
}
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;
}
Aggregations