use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class FileService method getFSExportRules.
/**
* Get FS Export Rules
*
* @param id
* the URN of a ViPR fileSystem
* @param subDir
* sub-directory within a filesystem
* @param allDirs
* All Dirs within a filesystem
* @brief Show export rules for a file system
* @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 getFSExportRules(@PathParam("id") URI id, @QueryParam("allDirs") boolean allDirs, @QueryParam("subDir") String subDir) {
_log.info("Request recieved for Exports with Id : {} allDirs : {} subDir : {}", new Object[] { id, allDirs, subDir });
// Validate the FS id.
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
// validate the subDir,no need to check return value as it is optional.
ArgValidator.checkSubDirName("subDir", subDir);
List<ExportRule> exportRule = FileOperationUtils.getExportRules(id, allDirs, subDir, _dbClient);
ExportRules rules = new ExportRules();
if (!exportRule.isEmpty()) {
rules.setExportRules(exportRule);
}
return rules;
}
use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class ExportVerificationUtility method verifyExports.
/**
* Since, Modifying an export is not allowed This method verifies the
* existing export params with the new one issued to modify.
*
* @param fs
* @param param
*/
public void verifyExports(FileShare fileShare, Snapshot snapshot, FileExportUpdateParams fsParam) throws Exception {
fs = fileShare;
param = fsParam;
this.snapshot = snapshot;
// Add Payload
ExportRules exportRules = param.getExportRulesToAdd();
validateExportRules(exportRules, ExportOperationType.ADD);
reportErrors(fsParam, ExportOperationType.ADD);
// Modify Payload
ExportRules exportModifyRules = param.getExportRulesToModify();
validateExportRules(exportModifyRules, ExportOperationType.MODIFY);
reportErrors(fsParam, ExportOperationType.MODIFY);
// Delete Payload
ExportRules exportDeleteRules = param.getExportRulesToDelete();
validateExportRules(exportDeleteRules, ExportOperationType.DELETE);
reportErrors(fsParam, ExportOperationType.DELETE);
// letThisObjEligibleForGC();
}
use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class ExportVerificationUtility method reportDeleteErrors.
private void reportDeleteErrors(FileExportUpdateParams param) throws Exception {
String opName = ExportOperationType.DELETE.name();
// Report Delete Export Errors
ExportRules listExportRules = param.getExportRulesToDelete();
if (listExportRules == null || listExportRules.getExportRules().isEmpty()) {
return;
}
List<ExportRule> listExportRule = listExportRules.getExportRules();
for (ExportRule exportRule : listExportRule) {
if (!exportRule.isToProceed()) {
ExportOperationErrorType error = exportRule.getErrorTypeIfNotToProceed();
switch(error) {
case INVALID_SECURITY_TYPE:
{
if (exportRule.getSecFlavor() != null) {
throw APIException.badRequests.invalidSecurityType(exportRule.getSecFlavor());
} else {
throw APIException.badRequests.missingInputTypeFound(SEC_TYPE, ExportOperationType.DELETE.name());
}
}
case MULTIPLE_EXPORTS_WITH_SAME_SEC_FLAVOR:
{
if (exportRule.getSecFlavor() != null) {
throw APIException.badRequests.sameSecurityFlavorInMultipleExportsFound(exportRule.getSecFlavor(), opName);
} else {
throw APIException.badRequests.missingInputTypeFound(SEC_TYPE, opName);
}
}
case EXPORT_NOT_FOUND:
{
throw APIException.badRequests.exportNotFound(ExportOperationType.DELETE.name(), exportRule.toString());
}
case EXPORT_EXISTS:
case INVALID_ANON:
case NO_ERROR:
default:
break;
}
}
}
}
use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class ExportVerificationUtility method reportModifyErrors.
private void reportModifyErrors(FileExportUpdateParams param) throws Exception {
String opName = ExportOperationType.MODIFY.name();
// Report Modify Export Errors
ExportRules listExportRules = param.getExportRulesToModify();
if (listExportRules == null || listExportRules.getExportRules().isEmpty()) {
return;
}
List<ExportRule> listExportRule = listExportRules.getExportRules();
for (ExportRule exportRule : listExportRule) {
if (!exportRule.isToProceed()) {
ExportOperationErrorType error = exportRule.getErrorTypeIfNotToProceed();
switch(error) {
case SNAPSHOT_EXPORT_SHOULD_BE_READ_ONLY:
{
throw APIException.badRequests.snapshotExportPermissionReadOnly();
}
case EXPORT_NOT_FOUND:
{
throw APIException.badRequests.exportNotFound(opName, exportRule.toString());
}
case INVALID_SECURITY_TYPE:
{
if (exportRule.getSecFlavor() != null) {
throw APIException.badRequests.invalidSecurityType(exportRule.getSecFlavor());
} else {
throw APIException.badRequests.missingInputTypeFound(SEC_TYPE, opName);
}
}
case MULTIPLE_EXPORTS_WITH_SAME_SEC_FLAVOR:
{
if (exportRule.getSecFlavor() != null) {
throw APIException.badRequests.sameSecurityFlavorInMultipleExportsFound(exportRule.getSecFlavor(), opName);
} else {
throw APIException.badRequests.missingInputTypeFound(SEC_TYPE, opName);
}
}
case INVALID_ANON:
{
if (exportRule.getAnon() != null) {
throw APIException.badRequests.invalidAnon(exportRule.getAnon());
} else {
throw APIException.badRequests.missingInputTypeFound(ANON_TYPE, opName);
}
}
case NO_HOSTS_FOUND:
{
throw APIException.badRequests.missingInputTypeFound(NO_HOSTS_FOUND, opName);
}
case EXPORT_EXISTS:
case NO_ERROR:
default:
break;
}
}
}
}
use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class FileStorageUtils method updateFileSnapshotExport.
public static String updateFileSnapshotExport(URI fileSnapshotId, String subDirectory, FileExportRule[] fileExportRules) {
List<ExportRule> exportRuleList = getFileSnapshotExportRules(fileSnapshotId, false, subDirectory);
Set<String> existingRuleSet = Sets.newHashSet();
for (ExportRule rule : exportRuleList) {
existingRuleSet.add(rule.getSecFlavor());
}
List<ExportRule> exportRuleListToAdd = Lists.newArrayList();
List<ExportRule> exportRuleListToModify = Lists.newArrayList();
for (FileExportRule rule : fileExportRules) {
ExportRule exportRule = new ExportRule();
exportRule.setFsID(fileSnapshotId);
exportRule.setSecFlavor(rule.security);
String rootUserMapping = rule.rootUserMapping;
String domain = rule.domain;
if (StringUtils.isNotBlank(domain)) {
rootUserMapping = domain.trim() + "\\" + rootUserMapping.trim();
}
exportRule.setAnon(rootUserMapping);
Set<String> exportHosts = new HashSet<String>(rule.exportHosts);
switch(rule.getPermission()) {
case "ro":
exportRule.setReadOnlyHosts(exportHosts);
break;
case "rw":
exportRule.setReadWriteHosts(exportHosts);
break;
case "root":
exportRule.setRootHosts(exportHosts);
break;
default:
break;
}
if (existingRuleSet.contains(exportRule.getSecFlavor())) {
exportRuleListToModify.add(exportRule);
} else {
exportRuleListToAdd.add(exportRule);
}
}
SnapshotExportUpdateParams params = new SnapshotExportUpdateParams();
if (!exportRuleListToAdd.isEmpty()) {
ExportRules exportRulesToAdd = new ExportRules();
exportRulesToAdd.setExportRules(exportRuleListToAdd);
params.setExportRulesToAdd(exportRulesToAdd);
}
if (!exportRuleListToModify.isEmpty()) {
ExportRules exportRulesToModify = new ExportRules();
exportRulesToModify.setExportRules(exportRuleListToModify);
params.setExportRulesToModify(exportRulesToModify);
}
Task<FileSnapshotRestRep> task = execute(new UpdateFileSnapshotExport(fileSnapshotId, subDirectory, params));
addAffectedResource(task);
String exportId = task.getResourceId().toString();
logInfo("file.storage.export.task", exportId, task.getOpId());
return exportId;
}
Aggregations