use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class DataDomainFileStorageDevice method updateExportRules.
@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
// Requested Export Rules
List<ExportRule> exportAdd = args.getExportRulesToAdd();
List<ExportRule> exportDelete = args.getExportRulesToDelete();
List<ExportRule> exportModify = args.getExportRulesToModify();
// Export path
String exportPath;
String subDir = args.getSubDirectory();
StringBuilder path = new StringBuilder();
if (!args.getFileOperation()) {
path.append(args.getSnapshotPath());
} else {
path.append(args.getFs().getPath());
}
if ((subDir != null) && (subDir.length() > 0)) {
path.append("/");
path.append(subDir);
}
exportPath = path.toString();
// Data Domain attaches a prefix to every file system path
path = new StringBuilder();
if (!exportPath.startsWith(DataDomainApiConstants.FS_PATH_BASE)) {
path.append(DataDomainApiConstants.FS_PATH_BASE);
}
path.append(exportPath);
_log.info("exportPath : {}", path);
args.setExportPath(path.toString());
// Check to ensure clients are not repeated
if (repeatedClientsInRequest(exportAdd, exportDelete, exportModify)) {
ServiceError serviceError = DeviceControllerErrors.datadomain.exportUpdateFailedRepeatedClients();
return BiosCommandResult.createErrorResult(serviceError);
}
// Ensure that the clients being added don't already exist in
// another export rule
List<ExportRule> existingExports = args.getExistingDBExportRules();
if (addingExistingClient(existingExports, path.toString(), exportAdd)) {
ServiceError serviceError = DeviceControllerErrors.datadomain.exportUpdateFailedAddingExistingClient();
return BiosCommandResult.createErrorResult(serviceError);
}
// To be processed export rules
List<ExportRule> exportsToRemove = new ArrayList<>();
List<ExportRule> exportsToAdd = new ArrayList<>();
if (existingExports != null && !existingExports.isEmpty()) {
args.setObjIdOnDevice(existingExports.get(0).getDeviceExportId());
_log.info("Number of existng Rules found {}", existingExports.size());
}
// Create/Modify/Delete exports on the array
DataDomainClient ddClient = getDataDomainClient(storage);
if (ddClient == null) {
_log.error("updateExportRules failed, provider unreachable");
String op = "Update export rules";
return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
}
URI storagePoolId = args.getFs().getPool();
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
// may be deleted selectively without deleting the export.
if ((exportModify != null) && (!exportModify.isEmpty())) {
// Are all existing rules being modified?
int existingRulesToModify = 0;
int numExistingRules = 0;
for (ExportRule modifyRule : exportModify) {
String securityFlavor = modifyRule.getSecFlavor();
for (ExportRule existingRule : existingExports) {
if (existingRule.getExportPath().equals(path.toString())) {
if (existingRule.getSecFlavor().equals(securityFlavor)) {
existingRulesToModify++;
}
numExistingRules++;
}
}
}
if (existingRulesToModify == numExistingRules) {
// All rules are being modified, delete the existing export on the array
String deviceExportId = null;
for (ExportRule existingRule : existingExports) {
if (existingRule.getExportPath().equals(path.toString())) {
deviceExportId = existingRule.getDeviceExportId();
break;
}
}
try {
doDeleteFsExport(ddClient, storagePool.getNativeId(), deviceExportId);
} catch (DataDomainApiException dde) {
_log.error("Export update failed, device error.", dde);
return BiosCommandResult.createErrorResult(dde);
}
// Export rules to create
for (ExportRule modifyRule : exportModify) {
exportsToAdd.add(modifyRule);
}
doCreateExports(ddClient, storagePool.getNativeId(), path.toString(), exportsToAdd);
exportsToAdd.clear();
} else {
// end points selectively
for (ExportRule modifyRule : exportModify) {
String securityFlavor = modifyRule.getSecFlavor();
ExportRule matchingRule = null;
for (ExportRule existingRule : existingExports) {
if (existingRule.getSecFlavor().equals(securityFlavor)) {
matchingRule = existingRule;
break;
}
}
// Since the list has been validated already, we can safely assume we will
// always find a matching existing rule.
modifyRule.setExportPath(args.getExportPath());
modifyRule.setFsID(args.getFsId());
exportsToRemove.add(matchingRule);
exportsToAdd.add(modifyRule);
}
}
}
// Process add list
if ((exportAdd != null) && (!exportAdd.isEmpty())) {
for (ExportRule newExport : exportAdd) {
_log.info("Adding Export Rule {}", newExport);
if (args.getFileObjExports() != null) {
Collection<FileExport> expList = args.getFileObjExports().values();
Iterator<FileExport> it = expList.iterator();
FileExport exp = null;
while (it.hasNext()) {
FileExport export = it.next();
if (export.getPath().equalsIgnoreCase(path.toString())) {
exp = export;
}
}
// set the device export id with export id.
if (exp != null) {
if (exp.getIsilonId() != null) {
newExport.setDeviceExportId(exp.getIsilonId());
}
if (exp.getNativeId() != null) {
newExport.setDeviceExportId(exp.getNativeId());
}
}
}
newExport.setExportPath(args.getExportPath());
newExport.setFsID(args.getFsId());
exportsToAdd.add(newExport);
}
// otherwise, update the exports.
if (existingExports == null || existingExports.isEmpty()) {
doCreateExports(ddClient, storagePool.getNativeId(), path.toString(), exportsToAdd);
exportsToAdd.clear();
}
}
// selectively, without disrupting unaffected end points.
if ((exportDelete != null) && (!exportDelete.isEmpty())) {
// Are all existing rules being deleted?
int existingRulesToDelete = 0;
for (ExportRule deleteRule : exportDelete) {
String securityFlavor = deleteRule.getSecFlavor();
for (ExportRule existingRule : existingExports) {
if (existingRule.getSecFlavor().equals(securityFlavor)) {
existingRulesToDelete++;
}
}
}
if (existingRulesToDelete == existingExports.size()) {
// All rules are being deleted, delete the existing export on the array
String deviceExportId = existingExports.get(0).getDeviceExportId();
try {
doDeleteFsExport(ddClient, storagePool.getNativeId(), deviceExportId);
} catch (DataDomainApiException dde) {
_log.error("Export update failed, device error.", dde);
return BiosCommandResult.createErrorResult(dde);
}
} else {
// end points selectively
for (ExportRule deleteRule : exportDelete) {
String securityFlavor = deleteRule.getSecFlavor();
ExportRule matchingRule = null;
for (ExportRule existingRule : existingExports) {
if (existingRule.getSecFlavor().equals(securityFlavor)) {
matchingRule = existingRule;
break;
}
}
// Since the list has been validated already, we can safely assume we will
// always find a matching existing rule.
exportsToRemove.add(matchingRule);
}
}
}
_log.info("No of exports to be removed from the existing list {}", exportsToRemove.size());
_log.info("No of exports to be added to the existing list {}", exportsToAdd.size());
// Delete clients selectively
try {
String deviceExportId = null;
for (ExportRule existingRule : existingExports) {
if (existingRule.getExportPath().equals(path.toString())) {
deviceExportId = existingRule.getDeviceExportId();
break;
}
}
boolean deleteClients = true;
doAddDeleteClients(ddClient, storagePool.getNativeId(), deviceExportId, exportsToRemove, deleteClients);
} catch (DataDomainApiException dde) {
_log.error("Export update failed, device error.", dde);
return BiosCommandResult.createErrorResult(dde);
}
// Create exports
try {
String deviceExportId = null;
for (ExportRule existingRule : existingExports) {
if (existingRule.getExportPath().equals(path.toString())) {
deviceExportId = existingRule.getDeviceExportId();
break;
}
}
boolean deleteClients = false;
doAddDeleteClients(ddClient, storagePool.getNativeId(), deviceExportId, exportsToAdd, deleteClients);
} catch (DataDomainApiException dde) {
_log.error("Export update failed, device error.", dde);
return BiosCommandResult.createErrorResult(dde);
}
_log.info("DataDomainFileStorageDevice updateFSExportRules {} - complete", args.getFsId());
return BiosCommandResult.createSuccessfulResult();
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method deleteExportRules.
@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
List<ExportRule> allExports = args.getExistingDBExportRules();
String subDir = args.getSubDirectory();
boolean allDirs = args.isAllDir();
String exportPath;
String subDirExportPath = "";
subDir = args.getSubDirectory();
if (!args.getFileOperation()) {
exportPath = args.getSnapshotPath();
if (subDir != null && subDir.length() > 0) {
subDirExportPath = args.getSnapshotPath() + "/" + subDir;
}
} else {
exportPath = args.getFs().getPath();
if (subDir != null && subDir.length() > 0) {
subDirExportPath = args.getFs().getPath() + "/" + subDir;
}
}
_log.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
_log.info("Number of existing exports found {}", allExports.size());
try {
IsilonApi isi = getIsilonDevice(storage);
String zoneName = getZoneName(args.getvNAS());
if (allDirs) {
// ALL EXPORTS
_log.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
for (ExportRule rule : allExports) {
_log.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
if (zoneName != null) {
isi.deleteExport(rule.getDeviceExportId(), zoneName);
} else {
isi.deleteExport(rule.getDeviceExportId());
}
}
} else if (subDir != null && !subDir.isEmpty()) {
// Filter for a specific Sub Directory export
_log.info("Deleting all subdir exports rules at ViPR and sub directory export at device {}", subDir);
for (ExportRule rule : allExports) {
_log.info("Delete IsilonExport id for path {} f containing subdirectory {}", rule.getDeviceExportId() + ":" + rule.getExportPath(), subDir);
String fsExportPathWithSub = args.getFsPath() + "/" + subDir;
if (rule.getExportPath().equalsIgnoreCase(fsExportPathWithSub)) {
_log.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
if (zoneName != null) {
isi.deleteExport(rule.getDeviceExportId(), zoneName);
} else {
isi.deleteExport(rule.getDeviceExportId());
}
}
}
} else {
// Filter for No SUBDIR - main export rules with no sub dirs
_log.info("Deleting all export rules from DB and export at device not included sub dirs");
for (ExportRule rule : allExports) {
if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
_log.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
if (zoneName != null) {
isi.deleteExport(rule.getDeviceExportId(), zoneName);
} else {
isi.deleteExport(rule.getDeviceExportId());
}
}
}
}
} catch (IsilonException ie) {
_log.info("Exception: {}", ie);
throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
}
_log.info("IsilonFileStorageDevice exportFS {} - complete", args.getFsId());
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
return result;
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method processRemoveIsiExport.
/**
* Delete isilon exports
*
* @param isi
* IsilonApi object
* @param args
* FileDeviceInputOutput object
* @param exports
* new exports to add
* @throws IsilonException
*/
private void processRemoveIsiExport(IsilonApi isi, FileDeviceInputOutput args, List<ExportRule> exports) throws IsilonException {
_log.info("processRemoveIsiExport Start");
// process and export each NFSExport independently.
for (ExportRule exportRule : exports) {
// create and set IsilonExport instance from ExportRule
_log.info("Remove this export rule {}", exportRule.toString());
String isilonExportId = exportRule.getDeviceExportId();
if (isilonExportId != null) {
// The Export Rule already exists on the array so modify it
_log.info("Export rule exists on the device so remove it: {}", exportRule);
String zoneName = getZoneName(args.getvNAS());
if (zoneName != null) {
isi.deleteExport(isilonExportId, zoneName);
} else {
isi.deleteExport(isilonExportId);
}
}
}
_log.info("processRemoveIsiExport Completed");
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method processAddIsiExport.
/**
* Add isilon exports
*
* @param isi
* IsilonApi object
* @param args
* FileDeviceInputOutput object
* @param exports
* new exports to add
* @throws IsilonException
*/
private void processAddIsiExport(IsilonApi isi, FileDeviceInputOutput args, List<ExportRule> exports) throws IsilonException {
_log.info("ProcessAddExport Start");
List<ExportRule> modifyRules = new ArrayList<>();
// process and export each NFSExport independently.
for (ExportRule exportRule : exports) {
// create and set IsilonExport instance from ExportRule
_log.info("Add this export rule {}", exportRule.toString());
String isilonExportId = exportRule.getDeviceExportId();
String zoneName = getZoneName(args.getvNAS());
if (isilonExportId != null) {
// The Export Rule already exists on the array so modify it
_log.info("Export rule exists on the device so modify it: {}", exportRule);
modifyRules.add(exportRule);
} else {
// Create the Export
_log.info("Export rule does not exist on the device so create it: {}", exportRule);
IsilonExport newIsilonExport = setIsilonExport(exportRule);
String expId = null;
if (zoneName != null) {
expId = isi.createExport(newIsilonExport, zoneName, args.getBypassDnsCheck());
} else {
expId = isi.createExport(newIsilonExport, args.getBypassDnsCheck());
}
exportRule.setDeviceExportId(expId);
}
if (!modifyRules.isEmpty()) {
// Call Process Isi Export
processIsiExport(isi, args, modifyRules);
}
}
_log.info("ProcessAddExport completed.");
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method processIsiExport.
/**
* Update isilon exports
*
* @param isi
* IsilonApi object
* @param args
* FileDeviceInputOutput object
* @param exports
* new exports to add
* @throws IsilonException
*/
private void processIsiExport(IsilonApi isi, FileDeviceInputOutput args, List<ExportRule> exports) throws IsilonException {
_log.info("ProcessIsiExport Start");
// process and export each NFSExport independently.
for (ExportRule exportRule : exports) {
// create and set IsilonExport instance from ExportRule
String root_user = exportRule.getAnon();
Set<String> rootHosts = exportRule.getRootHosts();
String isilonExportId = exportRule.getDeviceExportId();
if (isilonExportId != null) {
IsilonExport isilonExport = null;
String zoneName = getZoneName(args.getvNAS());
if (zoneName != null) {
isilonExport = isi.getExport(isilonExportId, zoneName);
} else {
isilonExport = isi.getExport(isilonExportId);
}
// Update the comment
if (exportRule.getComments() != null && !exportRule.getComments().isEmpty()) {
isilonExport.setComment(exportRule.getComments());
}
_log.info("Update Isilon Export with id {} and {}", isilonExportId, isilonExport);
List<String> allClients = new ArrayList<>();
if (isilonExport != null) {
boolean hasrwClients = false;
boolean hasrootClients = false;
if ((isilonExport.getReadWriteClients() != null && !isilonExport.getReadWriteClients().isEmpty()) || (exportRule.getReadWriteHosts() != null && !exportRule.getReadWriteHosts().isEmpty())) {
hasrwClients = true;
}
if ((isilonExport.getRootClients() != null && !isilonExport.getRootClients().isEmpty()) || (exportRule.getRootHosts() != null && !exportRule.getRootHosts().isEmpty())) {
hasrootClients = true;
}
List<String> roClients = new ArrayList<>();
// over write roClients
if (exportRule.getReadOnlyHosts() != null) {
roClients.addAll(exportRule.getReadOnlyHosts());
allClients.addAll(exportRule.getReadOnlyHosts());
List<String> existingRWRootClients = new ArrayList<String>();
existingRWRootClients.addAll(isilonExport.getReadWriteClients());
existingRWRootClients.addAll(isilonExport.getRootClients());
List<String> commonHosts = getIntersection(existingRWRootClients, roClients);
if (!commonHosts.isEmpty()) {
// RW, RO and Root permissions cannot co-exist for
// same client hosts
// Using Set to eliminate duplicates
Set<String> existingRWClients = new HashSet<String>(isilonExport.getReadWriteClients());
Set<String> existingRootClients = new HashSet<String>(isilonExport.getRootClients());
// Remove common hosts
existingRWClients.removeAll(commonHosts);
existingRootClients.removeAll(commonHosts);
isilonExport.setRootClients(new ArrayList<String>(existingRootClients));
isilonExport.setReadWriteClients(new ArrayList<String>(existingRWClients));
} else {
setClientsIntoIsilonExport("root", exportRule.getRootHosts(), isilonExport);
setClientsIntoIsilonExport("rw", exportRule.getReadWriteHosts(), isilonExport);
}
isilonExport.setReadOnlyClients(new ArrayList<String>(roClients));
}
List<String> rwClients = new ArrayList<>();
// elements
if (exportRule.getReadWriteHosts() != null) {
rwClients.addAll(exportRule.getReadWriteHosts());
allClients.addAll(exportRule.getReadWriteHosts());
List<String> existingRORootClients = new ArrayList<String>();
existingRORootClients.addAll(isilonExport.getReadOnlyClients());
existingRORootClients.addAll(isilonExport.getRootClients());
List<String> commonHosts = getIntersection(existingRORootClients, rwClients);
if (!commonHosts.isEmpty()) {
// RW, RO and Root permissions cannot co-exist for
// same client hosts
// Using Set to eliminate duplicates
Set<String> existingROClients = new HashSet<String>(isilonExport.getReadOnlyClients());
Set<String> existingRootClients = new HashSet<String>(isilonExport.getRootClients());
// Remove common hosts
existingROClients.removeAll(commonHosts);
existingRootClients.removeAll(commonHosts);
isilonExport.setRootClients(new ArrayList<String>(existingRootClients));
isilonExport.setReadOnlyClients(new ArrayList<String>(existingROClients));
} else {
setClientsIntoIsilonExport("root", exportRule.getRootHosts(), isilonExport);
setClientsIntoIsilonExport("ro", exportRule.getReadOnlyHosts(), isilonExport);
}
isilonExport.setReadWriteClients(new ArrayList<String>(rwClients));
}
// over write rootClients
List<String> rootClients = new ArrayList<>();
if (rootHosts != null) {
rootClients.addAll(rootHosts);
allClients.addAll(rootHosts);
List<String> existingRORWClients = new ArrayList<String>();
existingRORWClients.addAll(isilonExport.getReadOnlyClients());
existingRORWClients.addAll(isilonExport.getReadWriteClients());
List<String> commonHosts = getIntersection(existingRORWClients, rootClients);
if (!commonHosts.isEmpty()) {
// RW, RO and Root permissions cannot co-exist for
// same client hosts
Set<String> existingROClients = new HashSet<String>(isilonExport.getReadOnlyClients());
Set<String> existingRWClients = new HashSet<String>(isilonExport.getReadWriteClients());
existingROClients.removeAll(commonHosts);
existingRWClients.removeAll(commonHosts);
isilonExport.setReadWriteClients(new ArrayList<String>(existingRWClients));
isilonExport.setReadOnlyClients(new ArrayList<String>(existingROClients));
} else {
setClientsIntoIsilonExport("ro", exportRule.getReadOnlyHosts(), isilonExport);
setClientsIntoIsilonExport("rw", exportRule.getReadWriteHosts(), isilonExport);
}
isilonExport.setRootClients(new ArrayList<String>(rootClients));
}
if (hasrwClients || hasrootClients) {
isilonExport.resetReadOnly();
} else {
isilonExport.setReadOnly();
}
isilonExport.setMapAll(null);
isilonExport.setMapRoot(root_user);
// There is export in Isilon with the given id.
// Overwrite this export with a new set of clients.
// We overwrite only clients element in exports. Isilon API
// does not use read_only_clients,
// read_write_clients or root_clients.
// List<String> newClients = isilonExport.getClients();
// newClients.addAll(allClients);
isilonExport.setClients(new ArrayList<String>(allClients));
IsilonExport clonedExport = cloneExport(isilonExport);
_log.info("Update Isilon Export with id {} and new info {}", isilonExportId, clonedExport.toString());
if (zoneName != null) {
isi.modifyExport(isilonExportId, zoneName, clonedExport, args.getBypassDnsCheck());
} else {
isi.modifyExport(isilonExportId, clonedExport, args.getBypassDnsCheck());
}
}
}
}
_log.info("ProcessIsiExport Completed");
}
Aggregations