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