use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class ExportVerificationUtility method verifyModifyExportRule.
/**
* Verify each export rule that can be added
*
* @param fs
* @param listExportRule
*/
private void verifyModifyExportRule(List<ExportRule> listExportRule) throws Exception {
if (listExportRule == null) {
return;
}
_log.info("{} Export Rule(s) Requested to Modify {} - 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.isToProceed()) {
_log.info("Same Security Flavor found across the exports {}", exportRule.toString());
break;
}
FileExportRule rule = validateHosts(exportRule);
// If found -- allow to modify.
if (rule != null) {
verifyExportAnon(exportRule);
} else // If not, stop proceed further.
{
if (exportRule.isToProceed()) {
_log.info("Export not found to modify");
exportRule.setIsToProceed(false, ExportOperationErrorType.EXPORT_NOT_FOUND);
}
}
}
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class ExportVerificationUtility method getAvailableExportRule.
/**
* Verify is the rule available in the database
*
* @param compositeKey
* @throws URISyntaxException
*/
private FileExportRule getAvailableExportRule(FileExportRule exportRule) throws URISyntaxException {
String exportIndex = exportRule.getFsExportIndex();
if (snapshot != null) {
exportIndex = exportRule.getSnapshotExportIndex();
}
_log.info("Retriving DB Model using its index {}", exportIndex);
FileExportRule rule = null;
URIQueryResultList result = new URIQueryResultList();
if (snapshot != null) {
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotExportRuleConstraint(exportIndex), result);
} else {
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileExportRuleConstraint(exportIndex), result);
}
Iterator<URI> it = result.iterator();
while (it.hasNext()) {
if (result.iterator().hasNext()) {
rule = _dbClient.queryObject(FileExportRule.class, it.next());
if (rule != null && !rule.getInactive()) {
_log.info("Existing DB Model found {}", rule);
break;
} else {
rule = null;
}
}
}
return rule;
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class FileDeviceController method unexport.
@Override
public void unexport(URI storage, URI fileUri, List<FileShareExport> exports, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fileUri, opId);
FileObject fsObj = null;
FileShare fs = null;
Snapshot snapshotObj = null;
StorageSystem storageObj = null;
try {
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
FileDeviceInputOutput args = new FileDeviceInputOutput();
boolean isFile = false;
if (URIUtil.isType(fileUri, FileShare.class)) {
isFile = true;
fs = _dbClient.queryObject(FileShare.class, fileUri);
setVirtualNASinArgs(fs.getVirtualNAS(), args);
fsObj = fs;
args.addFSFileObject(fs);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
} else {
snapshotObj = _dbClient.queryObject(Snapshot.class, fileUri);
fsObj = snapshotObj;
fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
setVirtualNASinArgs(fs.getVirtualNAS(), args);
args.addFileShare(fs);
args.addSnapshotFileObject(snapshotObj);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
}
args.setFileOperation(isFile);
args.setOpId(opId);
_log.info("Export details... ");
List<FileExport> fileExports = new ArrayList<FileExport>();
List<FileExportRule> exportRules = new ArrayList<FileExportRule>();
if (exports != null) {
for (FileShareExport fileShareExport : exports) {
FileExport fileExport = fileShareExport.getFileExport();
fileExports.add(fileExport);
_log.info("FileExport:" + fileExport.getClients() + ":" + fileExport.getStoragePortName() + ":" + fileExport.getStoragePort() + ":" + fileExport.getRootUserMapping() + ":" + fileExport.getPermissions() + ":" + fileExport.getProtocol() + ":" + fileExport.getSecurityType() + ":" + fileExport.getMountPoint() + ":" + fileExport.getMountPath() + ":" + fileExport.getPath());
_log.info("FileShareExport: " + fileExport.getFileExportKey());
// Per New Model : Lets create the Export Rules, So these will not get missed.
FileExportRule rule = getFileExportRule(fileUri, fileExport, args);
exportRules.add(rule);
}
} else {
_log.info("Exports are null");
}
WorkflowStepCompleter.stepExecuting(opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doUnexport(storageObj, args, fileExports);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
// Set status
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
OperationTypeEnum auditType = (isFile) ? OperationTypeEnum.UNEXPORT_FILE_SYSTEM : OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT;
if (result.isCommandSuccess()) {
// Remove Export
for (FileExport fileExport : fileExports) {
fsObj.getFsExports().remove(fileExport.getFileExportKey());
_log.info("FileShareExport removed : " + fileExport.getFileExportKey());
}
// Query Existing Export rule and if found set to delete.
for (FileExportRule rule : exportRules) {
URIQueryResultList dbresult = new URIQueryResultList();
if (!args.getFileOperation() && 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()) {
_log.info("Existing DB Model found {}", rule);
rule.setInactive(true);
_dbClient.updateObject(rule);
break;
}
}
}
}
FSExportMap exportsMap = fsObj.getFsExports();
List<FileExport> fsExports = new ArrayList<FileExport>(exportsMap.values());
if (isFile) {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fsExports), fs, storageObj);
} else {
recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fsExports), snapshotObj, fs, storageObj);
}
}
_dbClient.updateObject(fsObj);
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
String[] params = { storage.toString(), fileUri.toString(), e.getMessage() };
_log.error("Unable to unexport file system or snapshot: storage {}, FS/snapshot URI {}: {}", params);
for (FileShareExport fsExport : exports) {
_log.error("{} ", fsExport);
}
updateTaskStatus(opId, fsObj, e);
if (URIUtil.isType(fileUri, FileShare.class)) {
if ((fs != null) && (storageObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
}
} else {
if ((fs != null) && (storageObj != null) && (snapshotObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
}
}
}
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class FileDeviceController method queryExports.
private List<ExportRule> queryExports(FileDeviceInputOutput args) {
List<ExportRule> rules = null;
try {
ContainmentConstraint containmentConstraint;
if (args.getFileOperation()) {
FileShare fs = args.getFs();
_log.info("Querying all ExportRules Using FsId {}", fs.getId());
containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
} else {
URI snapshotId = args.getSnapshotId();
_log.info("Querying all ExportRules Using Snapshot Id {}", snapshotId);
containmentConstraint = ContainmentConstraint.Factory.getSnapshotExportRulesConstraint(snapshotId);
}
List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
rules = new ArrayList<>();
for (FileExportRule fileExportRule : fileExportRules) {
ExportRule rule = new ExportRule();
getExportRule(fileExportRule, rule);
rules.add(rule);
}
} catch (Exception e) {
_log.error("Error while querying {}", e);
}
return rules;
}
use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.
the class FileDeviceController method getFileExportRule.
private FileExportRule getFileExportRule(URI uri, FileExport fileExport, FileDeviceInputOutput args) {
FileExportRule rule = new FileExportRule();
rule.setAnon(fileExport.getRootUserMapping());
rule.setExportPath(fileExport.getPath());
if (!args.getFileOperation()) {
rule.setSnapshotId(uri);
} else {
rule.setFileSystemId(uri);
}
rule.setSecFlavor(fileExport.getSecurityType());
if (fileExport.getPermissions().equals(FileShareExport.Permissions.ro.name()) && fileExport.getClients() != null && !fileExport.getClients().isEmpty()) {
rule.setReadOnlyHosts(new StringSet(fileExport.getClients()));
}
if (fileExport.getPermissions().equals(FileShareExport.Permissions.rw.name()) && fileExport.getClients() != null && !fileExport.getClients().isEmpty()) {
rule.setReadWriteHosts(new StringSet(fileExport.getClients()));
}
if (fileExport.getPermissions().equals(FileShareExport.Permissions.root.name()) && fileExport.getClients() != null && !fileExport.getClients().isEmpty()) {
rule.setRootHosts(new StringSet(fileExport.getClients()));
}
rule.setMountPoint(fileExport.getMountPoint());
// _log.info("Generating FileExportRule IsilonId ? {}", fileExport.getIsilonId());
if (fileExport.getIsilonId() != null) {
rule.setDeviceExportId(fileExport.getIsilonId());
}
if (fileExport.getNativeId() != null) {
rule.setDeviceExportId(fileExport.getNativeId());
}
return rule;
}
Aggregations