use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class FileService method queryDBFSExports.
private List<FileExportRule> queryDBFSExports(FileShare fs) {
_log.info("Querying all ExportRules Using FsId {}", fs.getId());
try {
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
return fileExportRules;
} catch (Exception e) {
_log.error("Error while querying {}", e);
}
return null;
}
use of com.emc.storageos.db.client.model.FileExportRule 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;
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class FileSnapshotService method queryDBSnapshotExports.
private List<FileExportRule> queryDBSnapshotExports(Snapshot snapshot) {
_log.info("Querying all ExportRules Using Snapshot Id {}", snapshot.getId());
try {
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getSnapshotExportRulesConstraint(snapshot.getId());
List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
return fileExportRules;
} catch (Exception e) {
_log.error("Error while querying {}", e);
}
return null;
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class FileSnapshotService method deleteSnapshotExportRules.
/**
* Delete Snapshot Export Rules
*
* @param id
* the URN of a ViPR file system
* @brief Delete an export rule
* @return TaskResponse
*/
@DELETE
@Path("/{id}/export")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteSnapshotExportRules(@PathParam("id") URI id) {
// log input received.
_log.info("Delete Snapshot Export Rules : request received for {}", new Object[] { id });
String task = UUID.randomUUID().toString();
// Validate the FS id.
ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
Snapshot snapshot = queryResource(id);
FileShare fileShare = _permissionsHelper.getObjectById(snapshot.getParent(), FileShare.class);
ArgValidator.checkEntity(snapshot, id, isIdEmbeddedInURL(id));
/* check if the Snapshot has any export rules on it */
List<FileExportRule> exports = queryDBSnapshotExports(snapshot);
if (exports == null || exports.isEmpty()) {
_log.error("Error Processing Export Updates for snapshot {} doesnot have exports", snapshot.getName());
throw APIException.badRequests.snapshotHasNoExport(snapshot.getId());
}
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fileShare.getStorageDevice());
String path = snapshot.getPath();
_log.info("Export path found {} ", path);
Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snapshot.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT);
try {
FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fileShare, _dbClient);
fileServiceApi.deleteExportRules(device.getId(), snapshot.getId(), false, null, false, task);
auditOp(OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), device.getId().toString(), false, null);
return toTask(snapshot, task, op);
} catch (BadRequestException e) {
_log.error("Error Processing Export Updates {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Error Processing Export Updates {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class ExportVerificationUtility method verifyAddExportRule.
/**
* Verify each export rule that can be added
*
* @param listExportRule
*/
private void verifyAddExportRule(List<ExportRule> listExportRule) throws Exception {
if (listExportRule == null) {
return;
}
_log.info("Checking if file system is exported before adding export rule");
if (!isFileSystemExported()) {
String msg = "File system is not exported. To add export rule, file system must be exported first.";
_log.error(msg);
String urn = fs != null ? fs.getId().toString() : snapshot.getId().toString();
throw APIException.badRequests.fileSystemNotExported(ExportOperationType.ADD.name(), urn);
}
_log.info("Number of Export Rule(s) Requested to Add {} - Iterating ..", listExportRule.size());
for (ExportRule exportRule : listExportRule) {
exportRule.setIsToProceed(true, ExportOperationErrorType.NO_ERROR);
_log.info("Verifying Export Rule {}", exportRule.toString());
// is same security flavor found in several exports - report the error
scanForDuplicateSecFlavor(exportRule);
if (exportRule.getErrorTypeIfNotToProceed() != null && !(exportRule.getErrorTypeIfNotToProceed().name().equals(ExportOperationErrorType.NO_ERROR.name()))) {
_log.info("Same Security Flavor found across the exports {}", exportRule.toString());
break;
}
// Now validate hosts
FileExportRule rule = validateHosts(exportRule);
// If same export already found -- Don't allow to add again.
if (rule != null) {
_log.info("Duplicate Export to Add {} Requested : {}", rule, exportRule);
exportRule.setIsToProceed(false, ExportOperationErrorType.EXPORT_EXISTS);
break;
} else // If not found proceed for further verifications.
{
if (exportRule.isToProceed()) {
_log.info("No Existing Export found in DB {}", exportRule);
verifyExportAnon(exportRule);
}
}
}
}
Aggregations