use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method addStepsToReplicateNFSExportRules.
/**
* Child workflow for replicating source file system NFS export Rules to target.
*
* @param systemTarget
* - URI of target StorageSystem where source NFS shares has to be replicated.
* @param fsURI
* -URI of the source FileSystem
* @param taskId
*/
public void addStepsToReplicateNFSExportRules(URI systemTarget, URI fsURI, String taskId) {
s_logger.info("Generating steps for Replicating NFS export rules to Target Cluster");
FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
Workflow workflow = null;
FileShare targetFileShare = null;
try {
FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
} else {
targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
}
workflow = this._workflowService.getNewWorkflow(this, REPLICATE_NFS_EXPORT_RULES_TO_TARGET_WF_NAME, false, taskId, completer);
FSExportMap sourceFSExportMap = sourceFileShare.getFsExports();
FSExportMap targetFSExportMap = targetFileShare.getFsExports();
if (sourceFSExportMap == null && targetFSExportMap != null) {
// There are no export rule on source but there are on target!!
List<ExportRule> exportRulesToDelete;
HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
for (String exportPath : targetExportRuleMap.keySet()) {
FileExportUpdateParams params = new FileExportUpdateParams();
if (exportPath.equals(targetFileShare.getPath())) {
// File system export rules....
exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath());
} else {
// Sub directory export rules....
String subDir = exportPath.split(targetFileShare.getPath())[1];
exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
params.setSubDir(subDir.substring(1));
}
ExportRules deleteExportRules = new ExportRules();
deleteExportRules.setExportRules(exportRulesToDelete);
params.setExportRulesToDelete(deleteExportRules);
updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
}
} else if (targetFSExportMap != null && sourceFSExportMap != null) {
// Both source and target have export rules!!
HashMap<String, List<ExportRule>> sourceExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(sourceFileShare, s_dbClient);
HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
for (String exportPath : sourceExportRuleMap.keySet()) {
FileExportUpdateParams params = new FileExportUpdateParams();
List<ExportRule> exportRulesToAdd = new ArrayList<ExportRule>();
List<ExportRule> exportRulesToDelete = new ArrayList<ExportRule>();
List<ExportRule> exportRulesToModify = new ArrayList<ExportRule>();
List<ExportRule> sourceExportRules;
List<ExportRule> targetExportRules;
HashMap<String, ExportRule> srcExportRuleSecFlvMap;
HashMap<String, ExportRule> trgtExportRuleSecFlvMap;
if (exportPath.equals(sourceFileShare.getPath())) {
// File system export rules....
sourceExportRules = sourceExportRuleMap.get(exportPath);
targetExportRules = targetExportRuleMap.get(targetFileShare.getPath());
} else {
// Sub directory export rules....
sourceExportRules = sourceExportRuleMap.get(exportPath);
String subDir = exportPath.split(sourceFileShare.getPath())[1];
targetExportRules = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
params.setSubDir(subDir.substring(1));
}
if (sourceExportRules != null && targetExportRules != null) {
srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
FileOrchestrationUtils.checkForExportRuleToAdd(sourceFileShare, targetFileShare, srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToAdd);
FileOrchestrationUtils.checkForExportRuleToDelete(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToDelete);
sourceExportRules.removeAll(exportRulesToAdd);
targetExportRules.removeAll(exportRulesToDelete);
srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
FileOrchestrationUtils.checkForExportRuleToModify(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToModify);
if (!exportRulesToAdd.isEmpty()) {
ExportRules addExportRules = new ExportRules();
addExportRules.setExportRules(exportRulesToAdd);
params.setExportRulesToAdd(addExportRules);
}
if (!exportRulesToDelete.isEmpty()) {
ExportRules deleteExportRules = new ExportRules();
deleteExportRules.setExportRules(exportRulesToDelete);
params.setExportRulesToDelete(deleteExportRules);
}
if (!exportRulesToModify.isEmpty()) {
ExportRules modifyExportRules = new ExportRules();
modifyExportRules.setExportRules(exportRulesToModify);
params.setExportRulesToModify(modifyExportRules);
}
if (params.retrieveAllExports() != null && !params.retrieveAllExports().isEmpty()) {
updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
}
}
}
}
String successMessage = String.format("Replicating source File System : %s, NFS Exports Rules to Target System finished successfully", sourceFileShare.getLabel());
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error("Could not replicate source filesystem NFS Exports Rules : " + fsURI, ex);
String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fsURI.toString(), opName, ex);
completer.error(s_dbClient, this._locker, serviceError);
}
}
use of com.emc.storageos.model.file.ExportRules 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.model.file.ExportRules in project coprhd-controller by CoprHD.
the class FileStorageUtils method updateFileSystemExport.
public static String updateFileSystemExport(URI fileSystemId, String subDirectory, FileExportRule[] fileExportRules, boolean bypassDnsCheck) {
List<ExportRule> exportRuleList = getFileSystemExportRules(fileSystemId, 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(fileSystemId);
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);
}
}
FileShareExportUpdateParams params = new FileShareExportUpdateParams();
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);
}
params.setBypassDnsCheck(bypassDnsCheck);
Task<FileShareRestRep> task = execute(new UpdateFileSystemExport(fileSystemId, subDirectory, params));
addAffectedResource(task);
String exportId = task.getResourceId().toString();
logInfo("file.storage.export.task", exportId, task.getOpId());
return exportId;
}
use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class FileSystems method deleteFileSystemExport.
@FlashException(referrer = { "fileSystem" })
public static void deleteFileSystemExport(String fileSystemId, String security, String exportPath) {
ViPRCoreClient client = BourneUtil.getViprClient();
ExportRule rule = new ExportRule();
rule.setSecFlavor(security);
List<ExportRule> list = Lists.newArrayList();
list.add(rule);
ExportRules exportRules = new ExportRules();
exportRules.setExportRules(list);
FileShareExportUpdateParams params = new FileShareExportUpdateParams();
params.setExportRulesToDelete(exportRules);
FileShareRestRep fileSystem = client.fileSystems().get(uri(fileSystemId));
String subDir = FileUtils.findSubDirectory(fileSystem.getMountPath(), exportPath);
client.fileSystems().updateExport(uri(fileSystemId), subDir, params);
flash.put("info", MessagesUtils.get("resources.filesystem.export.deactivate"));
fileSystem(fileSystemId);
}
use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class ExportVerificationUtility method reportAddErrors.
private void reportAddErrors(FileExportUpdateParams param) throws Exception {
String opName = ExportOperationType.ADD.name();
// Report Add Export Errors
ExportRules listExportRules = param.getExportRulesToAdd();
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 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:
{
throw APIException.badRequests.exportExists(opName, exportRule.toString());
}
case STORAGE_SYSTEM_NOT_SUPPORT_MUL_SECS:
{
StorageSystem system = null;
String systemName = "";
if (fs != null) {
system = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
} else if (snapshot != null) {
FileShare fileSystem = _dbClient.queryObject(FileShare.class, snapshot.getParent());
system = _dbClient.queryObject(StorageSystem.class, fileSystem.getStorageDevice());
}
if (system != null) {
systemName = system.getSystemType();
}
throw APIException.badRequests.storageDoesNotSupportMulSecRule(opName, systemName, exportRule.toString());
}
case EXPORT_NOT_FOUND:
case NO_ERROR:
default:
break;
}
}
}
}
Aggregations