use of com.emc.storageos.model.file.ExportRule 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.ExportRule in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice 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();
// To be processed export rules
List<ExportRule> exportsToRemove = new ArrayList<>();
List<ExportRule> exportsToModify = new ArrayList<>();
List<ExportRule> exportsToAdd = new ArrayList<>();
// Calculate Export Path
String exportPath;
String subDir = args.getSubDirectory();
// ".snapshot"
if (!args.getFileOperation()) {
exportPath = args.getSnapshotPath();
if (subDir != null && subDir.length() > 0) {
exportPath = args.getSnapshotPath() + "/" + subDir;
}
} else {
exportPath = args.getFs().getPath();
if (subDir != null && subDir.length() > 0) {
exportPath = args.getFs().getPath() + "/" + subDir;
}
}
_log.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
try {
// add the new export rule from the array into the update request.
Map<String, ExportRule> arrayExportRuleMap = extraExportRuleFromArray(storage, args);
if (!arrayExportRuleMap.isEmpty()) {
if (exportModify != null) {
// merge the end point for which sec flavor is common.
for (ExportRule exportRule : exportModify) {
ExportRule arrayExportRule = arrayExportRuleMap.remove(exportRule.getSecFlavor());
if (arrayExportRule != null) {
if (exportRule.getReadOnlyHosts() != null) {
exportRule.getReadOnlyHosts().addAll(arrayExportRule.getReadOnlyHosts());
} else {
exportRule.setReadOnlyHosts(arrayExportRule.getReadOnlyHosts());
}
if (exportRule.getReadWriteHosts() != null) {
exportRule.getReadWriteHosts().addAll(arrayExportRule.getReadWriteHosts());
} else {
exportRule.setReadWriteHosts(arrayExportRule.getReadWriteHosts());
}
if (exportRule.getRootHosts() != null) {
exportRule.getRootHosts().addAll(arrayExportRule.getRootHosts());
} else {
exportRule.setRootHosts(arrayExportRule.getRootHosts());
}
}
}
// now add the remaining export rule
exportModify.addAll(arrayExportRuleMap.values());
} else {
// if exportModify is null then create a new export rule and add
exportModify = new ArrayList<ExportRule>();
exportModify.addAll(arrayExportRuleMap.values());
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
_log.error("Not able to fetch latest Export rule from backend array.", e);
}
// ALL EXPORTS
List<ExportRule> existingDBExportRule = args.getExistingDBExportRules();
List<ExportRule> exportsToprocess = new ArrayList<>();
for (ExportRule rule : existingDBExportRule) {
if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
exportsToprocess.add(rule);
}
}
_log.info("Number of existing Rules found {} for exportPath {}", exportsToprocess.size(), exportPath);
// list and add to read/Write list.
if (!exportsToprocess.isEmpty() || !exportAdd.isEmpty()) {
if (exportModify != null && !exportModify.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
for (ExportRule newExportRule : exportModify) {
if (newExportRule.getSecFlavor().equals(existingRule.getSecFlavor())) {
newExportRule.setDeviceExportId(existingRule.getDeviceExportId());
exportsToModify.add(newExportRule);
}
}
}
}
// Handle Delete export Rules
if (exportDelete != null && !exportDelete.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
for (ExportRule oldExport : exportDelete) {
if (oldExport.getSecFlavor().equals(existingRule.getSecFlavor())) {
_log.info("Deleting Export Rule {}", existingRule);
exportsToRemove.add(existingRule);
}
}
}
}
// No of exports found to remove from the list
_log.info("No of exports found to remove from the existing exports list {}", exportsToRemove.size());
exportsToprocess.removeAll(exportsToRemove);
// Handle Add Export Rules
if (exportAdd != null && !exportAdd.isEmpty()) {
for (ExportRule newExport : exportAdd) {
_log.info("Add Export Rule {}", newExport);
newExport.setExportPath(exportPath);
exportsToAdd.add(newExport);
}
}
exportsToprocess.addAll(exportAdd);
}
// Process Mods
IsilonApi isi = getIsilonDevice(storage);
for (ExportRule existingRule : exportsToModify) {
_log.info("Modify Export rule : {}", existingRule.toString());
}
processIsiExport(isi, args, exportsToModify);
for (ExportRule existingRule : exportsToRemove) {
_log.info("Remove Export rule : {}", existingRule.toString());
}
processRemoveIsiExport(isi, args, exportsToRemove);
for (ExportRule existingRule : exportsToAdd) {
_log.info("Add Export rule : {}", existingRule.toString());
}
processAddIsiExport(isi, args, exportsToAdd);
BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
return result;
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class DataDomainFileStorageDevice method doAddDeleteClients.
private void doAddDeleteClients(DataDomainClient ddClient, String storagePoolId, String exportId, List<ExportRule> rulesToModify, boolean delete) throws DataDomainApiException {
if ((rulesToModify != null) && (!rulesToModify.isEmpty())) {
// Build list of endpoints for rules being modified (added or deleted)
List<DDExportClient> ddExportClients = new ArrayList<>();
for (ExportRule ruleToModify : rulesToModify) {
List<DDExportClient> ddExpClients = ddBuildExportClientList(ruleToModify);
if (ddExpClients != null) {
ddExportClients.addAll(ddExpClients);
}
}
// Build list of clients to be modified on the array
List<DDExportClientModify> modifyClients = new ArrayList<>();
for (DDExportClient ddExportClient : ddExportClients) {
DDExportClientModify modifyClient = new DDExportClientModify(ddExportClient.getName(), ddExportClient.getOptions(), delete);
modifyClients.add(modifyClient);
}
// Modify clients on the array
if (!modifyClients.isEmpty()) {
DDExportInfo ddExportInfo = ddClient.modifyExport(storagePoolId, exportId, modifyClients);
if (ddExportInfo.getPathStatus() != DataDomainApiConstants.PATH_EXISTS) {
DDExportInfoDetail exportDetail = ddClient.getExport(storagePoolId, exportId);
if (delete) {
throw DataDomainApiException.exceptions.failedToDeleteExportClients(exportDetail.getPath());
} else {
throw DataDomainApiException.exceptions.failedToAddExportClients(exportDetail.getPath());
}
}
}
}
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class NetAppClusterModeDevice method updateExportRules.
@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) {
// Requested Export Rules
List<ExportRule> exportAdd = args.getExportRulesToAdd();
List<ExportRule> exportDelete = args.getExportRulesToDelete();
List<ExportRule> exportModify = args.getExportRulesToModify();
// To be processed export rules
List<ExportRule> exportsToRemove = new ArrayList<>();
List<ExportRule> exportsToAdd = new ArrayList<>();
List<ExportRule> exportsRemove = new ArrayList<>();
// ALL EXPORTS
List<ExportRule> exportsToprocess = args.getExistingDBExportRules();
String fsName = "";
if (exportsToprocess == null) {
exportsToprocess = new ArrayList<>();
}
_log.info("Number of existng Rules found {}", exportsToprocess.size());
String exportPath;
String subDir = args.getSubDirectory();
BiosCommandResult result = new BiosCommandResult();
if (!args.getFileOperation()) {
_log.error("NetAppClusterModeDevice::updateExportRules {} : Snapshot export/unexport is not Supported", args.getSnapshotId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportSnapshot();
serviceError.setMessage(genDetailedMessage("updateExportRules", args.getSnapshotId().toString(), "Snapshot export/unexport is not Supported"));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
} else {
exportPath = args.getFs().getPath();
if (subDir != null && subDir.length() > 0) {
exportPath = args.getFs().getPath() + "/" + subDir;
}
}
// if only delete provided with no existing rules -- How do we handle this?
_log.info("Number of Export Rules to update after processing found {}", exportsToprocess.size());
try {
String portGroup = null;
if (args.getFileOperation() == true) {
FileShare fileshare = args.getFs();
fsName = fileshare.getName();
portGroup = findSVMName(fileshare);
}
NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
String qtreePath = "";
String qtreeName = null;
if (args.getFileOperation()) {
qtreePath = exportPath;
if (subDir != null && subDir.length() > 0) {
if (ncApi.isQtree(args.getFsName(), subDir)) {
qtreeName = subDir;
qtreePath = constructQtreePath(args.getFsName(), subDir);
} else {
_log.error("NetAppClusterModeDevice::updateExportRules {} : Sub-directory export/unexport is not Supported", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
serviceError.setMessage(genDetailedMessage("updateExportRules", args.getFsId().toString(), "Sub-directory export/unexport is not Supported"));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
}
}
_log.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
// Handle Modified export Rules
if (!exportsToprocess.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
for (ExportRule modifiedrule : exportModify) {
if (modifiedrule.getSecFlavor().equals(existingRule.getSecFlavor())) {
_log.info("Modifying Export Rule from {}, To {}", existingRule, modifiedrule);
if (!ncApi.modifyNFSShare(fsName, qtreeName, qtreePath, existingRule, modifiedrule)) {
_log.error("NetAppClusterModeDevice updateFSExportRules {} - failed", args.getFsId());
result.setMessage("NetAppClusterModeDevice updateFSExportRules {} - failed");
result.setCommandStatus(Operation.Status.error.name());
return result;
}
}
}
}
}
// Handle Add export Rules
if (exportAdd != null && !exportAdd.isEmpty()) {
for (ExportRule newExport : exportAdd) {
_log.info("Adding Export Rule {}", newExport);
if (!ncApi.addNFSShare(fsName, qtreeName, qtreePath, newExport)) {
_log.error("NetAppClusterModeDevice updateFSExportRules {} - failed", args.getFsId());
result.setMessage("NetAppClusterModeDevice updateFSExportRules {} - failed");
result.setCommandStatus(Operation.Status.error.name());
return result;
}
}
}
// Handle Delete export Rules
if (exportDelete != null && !exportDelete.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
exportsToRemove.add(existingRule);
for (ExportRule oldExport : exportDelete) {
if (oldExport.getSecFlavor().equals(existingRule.getSecFlavor())) {
_log.info("Deleting Export Rule {}", existingRule);
exportsRemove.add(existingRule);
if (!ncApi.deleteNFSShare(fsName, qtreeName, existingRule, qtreePath)) {
_log.error("NetAppClusterModeDevice updateFSExportRules {} - failed", args.getFsId());
result.setMessage("NetAppClusterModeDevice updateFSExportRules {} - failed");
result.setCommandStatus(Operation.Status.error.name());
return result;
}
}
}
}
}
}
// No of exports found to remove from the list
_log.info("No of exports found to remove from the existing exports list {}", exportsRemove.size());
exportsToRemove.removeAll(exportsRemove);
_log.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
// If we delete filesystem without deleting export policy. Export policy will not get cleared on Array.
if (exportsToRemove.isEmpty() && !exportsRemove.isEmpty()) {
ncApi.deleteNFSExport(qtreePath);
}
}
} catch (NetAppCException e) {
_log.info("Exception:" + e.getMessage());
throw new DeviceControllerException("Exception while performing export for {0} - {1} ", new Object[] { args.getFsId(), e.getMessage() });
}
_log.info("NetAppClusterModeDevice updateFSExportRules {} - 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 VNXFileStorageDeviceXML method deleteExportRules.
@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult biosResult = new BiosCommandResult();
biosResult.setCommandSuccess(true);
biosResult.setCommandStatus(Operation.Status.ready.name());
List<ExportRule> allExports = args.getExistingDBExportRules();
String subDir = args.getSubDirectory();
boolean allDirs = args.isAllDir();
String exportPath;
String subDirExportPath = "";
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;
}
}
Set<String> allPaths = new HashSet<String>();
try {
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) {
allPaths.add(rule.getExportPath());
}
} 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) {
if (rule.getExportPath().endsWith("/" + subDir)) {
allPaths.add(subDirExportPath);
break;
}
}
} 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");
allPaths.add(exportPath);
}
_log.info("Number of Exports to Delete : {}", allPaths.size());
Map<String, Boolean> operationResult = new HashMap<String, Boolean>();
XMLApiResult result = null;
ApplicationContext context = null;
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
for (String exportPathToDelete : allPaths) {
_log.info("Deleting Export Path {}", exportPathToDelete);
try {
result = vnxComm.doDeleteExport(storage, exportPathToDelete, args, false);
if (result.isCommandSuccess()) {
_log.info("Export Deleted : {}", exportPathToDelete);
operationResult.put(exportPathToDelete, true);
} else {
_log.error("Error deleting Export : {}", exportPathToDelete);
operationResult.put(exportPathToDelete, false);
biosResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToUnexportFileSystem(result.getMessage()));
}
} catch (Exception e) {
_log.error("Error deleting Export : {}", exportPathToDelete);
operationResult.put(exportPathToDelete, false);
biosResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToUnexportFileSystem(result.getMessage()));
}
}
} catch (VNXException e) {
_log.error("Exception:" + e.getMessage());
throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
}
_log.info("VNXFileStorageDevice deleteExportRules {} - complete", args.getFsId());
return biosResult;
}
Aggregations