use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class FileSystemExportToFileSystemExportRuleMigration method createFSExportRules.
private List<FileExportRule> createFSExportRules(FileShare fileShare) {
List<FileExportRule> fsExpRuleList = new ArrayList<FileExportRule>();
FSExportMap fsExportMap = fileShare.getFsExports();
if (fsExportMap != null) {
for (String exportKey : fsExportMap.keySet()) {
FileExport fsExport = fsExportMap.get(exportKey);
FileExportRule expRule = new FileExportRule();
expRule.setId(URIUtil.createId(FileExportRule.class));
copyFileExportData(fsExport, expRule);
// Set fileSystemId in the end as setFileSystemId() calculates
// fsExportIndex with exportPath and security flavor
expRule.setFileSystemId(fileShare.getId());
fsExpRuleList.add(expRule);
}
}
return fsExpRuleList;
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class VNXeExportFileSystemJob method updateExportRules.
private void updateExportRules(URI uri, FileExport fileExport, DbClient dbClient) {
List<FileExportRule> existingRules = queryFileExports(uri, dbClient);
FileExportRule newRule = getFileExportRule(uri, fileExport);
if (existingRules != null && existingRules.isEmpty()) {
newRule.setId(URIUtil.createId(FileExportRule.class));
_logger.info("No Existing rules available for this FS Export and so creating the rule now {}", newRule);
dbClient.createObject(newRule);
} else {
_logger.debug("Checking inside for ExitingRule(s) available for this export");
boolean isRuleFound = false;
for (FileExportRule rule : existingRules) {
_logger.debug("Available Export Rule {} - Matching with New Rule {}", rule, newRule);
if (newRule.getFsExportIndex() != null && rule.getFsExportIndex().equals(newRule.getFsExportIndex())) {
isRuleFound = true;
_logger.info("Match Found : Skipping this Rule as alreday available {}", newRule);
break;
}
}
if (!isRuleFound) {
_logger.info("Creating new Export Rule {}", newRule);
newRule.setId(URIUtil.createId(FileExportRule.class));
dbClient.createObject(newRule);
}
}
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class VNXeExportFileSystemJob method queryFileExports.
private List<FileExportRule> queryFileExports(URI uri, DbClient dbClient) {
List<FileExportRule> fileExportRules = null;
try {
ContainmentConstraint containmentConstraint;
if (isFile) {
_logger.info("Querying all ExportRules Using FsId {}", uri);
containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(uri);
} else {
_logger.info("Querying all ExportRules Using Snapshot Id {}", uri);
containmentConstraint = ContainmentConstraint.Factory.getSnapshotExportRulesConstraint(uri);
}
fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileExportRule.class, containmentConstraint);
} catch (Exception e) {
_logger.error("Error while querying {}", e);
}
return fileExportRules;
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class VNXeModifyExportJob method updateExportRules.
/**
* update FileShare after exported in VNXe
*
* @param fsOjb fileShare object in vipr
* @param dbClient DbClient
* @param vnxeApiClient VNXeApiClient
*/
private void updateExportRules(VNXeApiClient vnxeApiClient, DbClient dbClient, FileShare fileObj, VNXeNfsShare nfsShare) {
_logger.info("updating file export. ");
try {
// Modify Existing Exports
FileExportRule newRule = new FileExportRule();
URI snapshotId = null;
if (!isFile) {
snapshotId = getTaskCompleter().getId();
}
// Copy the properties to build the index id to query DB for existing Export Rule
copyPropertiesToSave(newRule, rule, fileObj, dbClient, snapshotId);
newRule = getAvailableExportRule(newRule, dbClient);
// it updates the existing one with new information and upon keeping/appending to old one.
if (newRule != null) {
newRule.setInactive(true);
_logger.info("Removing Existing DB Export Rule {}", rule);
dbClient.persistObject(newRule);
}
if (!isDeleteRule) {
newRule = new FileExportRule();
newRule.setId(URIUtil.createId(FileExportRule.class));
if (nfsShare != null) {
if (nfsShare.getReadOnlyHosts() != null) {
Set<String> hosts = new HashSet<String>();
for (VNXeBase hostId : nfsShare.getReadOnlyHosts()) {
hosts.add(vnxeApiClient.getHostById(hostId.getId()).getName());
}
rule.setReadOnlyHosts(hosts);
}
if (nfsShare.getReadWriteHosts() != null) {
Set<String> hosts = new HashSet<String>();
for (VNXeBase hostId : nfsShare.getReadWriteHosts()) {
hosts.add(vnxeApiClient.getHostById(hostId.getId()).getName());
}
rule.setReadWriteHosts(hosts);
}
if (nfsShare.getRootAccessHosts() != null) {
Set<String> hosts = new HashSet<String>();
for (VNXeBase hostId : nfsShare.getRootAccessHosts()) {
hosts.add(vnxeApiClient.getHostById(hostId.getId()).getName());
}
rule.setRootHosts(hosts);
}
}
// Now, Copy the properties again into the rule came out of DB, before updating.
copyPropertiesToSave(newRule, rule, fileObj, dbClient, snapshotId);
_logger.info("Storing New DB Export Rule {}", newRule);
dbClient.createObject(newRule);
}
} catch (Exception e) {
_logger.info("Error While executing CRUD Operations {}", e);
}
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class VNXeUnexportFileSystemJob method updateExportRule.
private void updateExportRule(DbClient dbClient, FileExportRule rule) {
// Query Existing Export rule and if found set to delete.
URIQueryResultList dbresult = new URIQueryResultList();
if (!isFile && rule.getSnapshotExportIndex() != null) {
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotExportRuleConstraint(rule.getSnapshotExportIndex()), dbresult);
} else if (rule.getFsExportIndex() != null) {
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileExportRuleConstraint(rule.getFsExportIndex()), dbresult);
}
Iterator<URI> it = dbresult.iterator();
while (it.hasNext()) {
if (dbresult.iterator().hasNext()) {
rule = dbClient.queryObject(FileExportRule.class, it.next());
if (rule != null && !rule.getInactive()) {
_logger.info("Existing DB Model found {}", rule);
rule.setInactive(true);
dbClient.persistObject(rule);
break;
}
}
}
}
Aggregations