use of com.emc.storageos.isilon.restapi.IsilonExport in project coprhd-controller by CoprHD.
the class IsilonCommunicationInterface method discoverAccessZoneExports.
private HashMap<String, HashSet<Integer>> discoverAccessZoneExports(StorageSystem storageSystem, String isilonAccessZone) throws IsilonCollectionException {
HashMap<String, HashSet<Integer>> allExports = new HashMap<>();
URI storageSystemId = storageSystem.getId();
String resumeToken = null;
try {
_log.info("discoverAllExports for storage system {} - start", storageSystemId);
IsilonApi isilonApi = getIsilonDevice(storageSystem);
do {
IsilonApi.IsilonList<IsilonExport> isilonExports = isilonApi.listExports(resumeToken, isilonAccessZone);
List<IsilonExport> exports = isilonExports.getList();
for (IsilonExport exp : exports) {
_log.info("Discovered fS export {}", exp.toString());
if (exp.getPaths() == null || exp.getPaths().isEmpty()) {
_log.info("Ignoring export {} as it is not having any path", exp.getId().toString());
continue;
}
HashSet<Integer> exportIds = new HashSet<>();
// Ignore Export with multiple paths
if (exp.getPaths().size() > 1) {
_log.info("Discovered Isilon Export: {} has multiple paths so ingnoring it", exp.toString());
continue;
}
String path = exp.getPaths().get(0);
exportIds = allExports.get(path);
if (exportIds == null) {
exportIds = new HashSet<>();
}
exportIds.add(exp.getId());
allExports.put(path, exportIds);
_log.debug("Discovered fS put export Path {} Export id {}", path, exportIds.size() + ":" + exportIds);
}
resumeToken = isilonExports.getToken();
} while (resumeToken != null);
_log.info("discoverd All NFS Exports for access zone {} ", isilonAccessZone);
return allExports;
} catch (IsilonException ie) {
_log.error("discoverAllExports failed. Storage system: {}", storageSystemId, ie);
IsilonCollectionException ice = new IsilonCollectionException("discoverAllExports failed. Storage system: " + storageSystemId);
ice.initCause(ie);
throw ice;
} catch (Exception e) {
_log.error("discoverAllExports failed. Storage system: {}", storageSystemId, e);
IsilonCollectionException ice = new IsilonCollectionException("discoverAllExports failed. Storage system: " + storageSystemId);
ice.initCause(e);
throw ice;
}
}
use of com.emc.storageos.isilon.restapi.IsilonExport in project coprhd-controller by CoprHD.
the class IsilonCommunicationInterface method getUnManagedFSExportMap.
/**
* Generate Export Map for UnManagedFileSystem
* Ignore exports with multiple exports for the same path
* Ignore exports that have multiple security flavors
* Ignore exports with multiple paths
* Ignore exports not found on the array
* Ignore exports which have the same internal export key ( <sec, perm, root-mapping>)
*
* @param umfs
* @param isilonExportIds
* @param storagePort
* @param fsPath
* @param isilonApi
* @return boolean
*/
private boolean getUnManagedFSExportMap(UnManagedFileSystem umfs, HashSet<Integer> isilonExportIds, StoragePort storagePort, String fsPath, String zoneName, IsilonApi isilonApi, List<UnManagedFileExportRule> expRules) {
UnManagedFSExportMap exportMap = new UnManagedFSExportMap();
int generatedExportCount = 0;
ArrayList<IsilonExport> isilonExports = new ArrayList<>();
if (isilonExportIds != null && isilonExportIds.size() > 1) {
_log.info("Found multiple export rules for file system path {}, {} ", fsPath, isilonExportIds.size());
}
for (Integer expId : isilonExportIds) {
IsilonExport exp = getIsilonExport(isilonApi, expId, zoneName);
if (exp == null) {
_log.info("Ignoring export {} as it is not found", expId);
continue;
}
for (String expPath : exp.getPaths()) {
if (expPath != null && !expPath.equalsIgnoreCase(fsPath) && !expPath.startsWith(fsPath + "/")) {
_log.info("Ignoring export {} as it's path doesn't match with file path {} ", expId, fsPath);
continue;
}
}
isilonExports.add(exp);
}
StringSet secTypes = new StringSet();
for (IsilonExport exp : isilonExports) {
String csSecurityTypes = "";
Set<String> orderedList = new TreeSet<>();
// store all security flavor separated by comma(,)
for (String sec : exp.getSecurityFlavors()) {
String securityFlavor = sec;
// Isilon Maps sys to unix and we do this conversion during export from ViPR
if (sec.equalsIgnoreCase(UNIXSECURITY)) {
securityFlavor = SYSSECURITY;
}
orderedList.add(securityFlavor);
}
Iterator<String> secIter = orderedList.iterator();
csSecurityTypes = secIter.next().toString();
while (secIter.hasNext()) {
csSecurityTypes += "," + secIter.next().toString();
}
if (!csSecurityTypes.isEmpty() && secTypes.contains(csSecurityTypes)) {
_log.warn("Ignoring file system exports {}, as it contains multiple export rules with same security {}", fsPath, csSecurityTypes);
return false;
}
secTypes.add(csSecurityTypes);
String path = exp.getPaths().get(0);
// Get User
String rootUserMapping = "";
String mapAllUserMapping = "";
if (exp.getMap_root() != null && exp.getMap_root().getUser() != null) {
rootUserMapping = exp.getMap_root().getUser();
} else if (exp.getMap_all() != null && exp.getMap_all().getUser() != null) {
mapAllUserMapping = exp.getMap_all().getUser();
}
String resolvedUser = (rootUserMapping != null && (!rootUserMapping.isEmpty())) ? rootUserMapping : mapAllUserMapping;
// Create Export rule!!
UnManagedFileExportRule expRule = new UnManagedFileExportRule();
expRule.setExportPath(path);
expRule.setSecFlavor(csSecurityTypes);
expRule.setAnon(resolvedUser);
expRule.setDeviceExportId(exp.getId().toString());
expRule.setFileSystemId(umfs.getId());
expRule.setMountPoint(storagePort.getPortNetworkId() + ":" + path);
if (exp != null && exp.getReadOnlyClients() != null && !exp.getReadOnlyClients().isEmpty()) {
UnManagedFSExport unManagedROFSExport = new UnManagedFSExport(exp.getReadOnlyClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RO, resolvedUser, NFS, storagePort.getPortName(), path, exp.getPaths().get(0));
unManagedROFSExport.setIsilonId(exp.getId().toString());
exportMap.put(unManagedROFSExport.getFileExportKey(), unManagedROFSExport);
generatedExportCount++;
expRule.setReadOnlyHosts(new StringSet(exp.getReadOnlyClients()));
}
if (exp != null && exp.getReadWriteClients() != null && !exp.getReadWriteClients().isEmpty()) {
UnManagedFSExport unManagedRWFSExport = new UnManagedFSExport(exp.getReadWriteClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RW, resolvedUser, NFS, storagePort.getPortName(), path, exp.getPaths().get(0));
unManagedRWFSExport.setIsilonId(exp.getId().toString());
exportMap.put(unManagedRWFSExport.getFileExportKey(), unManagedRWFSExport);
generatedExportCount++;
expRule.setReadWriteHosts(new StringSet(exp.getReadWriteClients()));
}
if (exp != null && exp.getRootClients() != null && !exp.getRootClients().isEmpty()) {
UnManagedFSExport unManagedROOTFSExport = new UnManagedFSExport(exp.getRootClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, ROOT, resolvedUser, NFS, storagePort.getPortName(), path, path);
unManagedROOTFSExport.setIsilonId(exp.getId().toString());
exportMap.put(unManagedROOTFSExport.getFileExportKey(), unManagedROOTFSExport);
generatedExportCount++;
expRule.setRootHosts(new StringSet(exp.getRootClients()));
}
if (exp.getReadOnlyClients() != null && exp.getReadWriteClients() != null && exp.getRootClients() != null) {
// Check Clients size
if (exp.getReadOnlyClients().isEmpty() && exp.getReadWriteClients().isEmpty() && exp.getRootClients().isEmpty()) {
if (exp.getReadOnly()) {
// This is a read only export for all hosts
UnManagedFSExport unManagedROFSExport = new UnManagedFSExport(exp.getClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RO, rootUserMapping, NFS, storagePort.getPortName(), path, path);
unManagedROFSExport.setIsilonId(exp.getId().toString());
exportMap.put(unManagedROFSExport.getFileExportKey(), unManagedROFSExport);
generatedExportCount++;
// This is a read only export for all hosts
expRule.setReadOnlyHosts(new StringSet(exp.getClients()));
} else {
// Not read Only case
if (exp.getMap_all() != null && exp.getMap_all().getUser() != null && exp.getMap_all().getUser().equalsIgnoreCase(ROOT)) {
// All hosts with root permission
UnManagedFSExport unManagedROOTFSExport = new UnManagedFSExport(exp.getClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, ROOT, mapAllUserMapping, NFS, storagePort.getPortName(), path, path);
unManagedROOTFSExport.setIsilonId(exp.getId().toString());
exportMap.put(unManagedROOTFSExport.getFileExportKey(), unManagedROOTFSExport);
generatedExportCount++;
// All hosts with root permission
expRule.setRootHosts(new StringSet(exp.getClients()));
} else if (exp.getMap_all() != null) {
// All hosts with RW permission
UnManagedFSExport unManagedRWFSExport = new UnManagedFSExport(exp.getClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RW, rootUserMapping, NFS, storagePort.getPortName(), path, path);
unManagedRWFSExport.setIsilonId(exp.getId().toString());
exportMap.put(unManagedRWFSExport.getFileExportKey(), unManagedRWFSExport);
generatedExportCount++;
// All hosts with RW permission
expRule.setReadWriteHosts(new StringSet(exp.getClients()));
}
}
}
}
// Create Export rule for the export!!!
expRules.add(expRule);
}
if (exportMap.values().size() < generatedExportCount) {
// The keys are not unique and so all the exports are not valid
_log.info("Ignoring Exports because they have multiple exports with the same internal export key <sec, perm, root-mapping>. Expected {} got {}", generatedExportCount, exportMap.values().size());
return false;
}
// Return valid
UnManagedFSExportMap allExportMap = umfs.getFsUnManagedExportMap();
if (allExportMap == null) {
allExportMap = new UnManagedFSExportMap();
}
allExportMap.putAll(exportMap);
umfs.setFsUnManagedExportMap(allExportMap);
return true;
}
use of com.emc.storageos.isilon.restapi.IsilonExport in project coprhd-controller by CoprHD.
the class IsilonFileStorageDevice method setIsilonExport.
private IsilonExport setIsilonExport(FileExport fileExport, String permissions, List<String> securityType, String root_user, String mountPath, String comments) {
IsilonExport newIsilonExport = new IsilonExport();
newIsilonExport.addPath(mountPath);
if (comments == null) {
comments = "";
}
newIsilonExport.setComment(comments);
// Empty list of clients means --- all clients.
newIsilonExport.addClients(fileExport.getClients());
// set security type
// Need to use "unix" instead of "sys" . Isilon requires "unix", not
// "sys".
List<String> securityFlavors = new ArrayList<String>();
for (String secType : securityType) {
if (secType.equals(FileShareExport.SecurityTypes.sys.name())) {
securityFlavors.add("unix");
} else {
securityFlavors.add(secType);
}
}
newIsilonExport.setSecurityFlavors(new ArrayList<String>(securityFlavors));
newIsilonExport.setMapRoot(root_user);
// of clients in the request is empty.
if (permissions.equals(FileShareExport.Permissions.ro.name())) {
newIsilonExport.addReadOnlyClients(fileExport.getClients());
newIsilonExport.setReadOnly();
} else if (permissions.equals(FileShareExport.Permissions.rw.name())) {
newIsilonExport.addReadWriteClients(fileExport.getClients());
newIsilonExport.resetReadOnly();
} else if (permissions.equals(FileShareExport.Permissions.root.name())) {
newIsilonExport.addRootClients(fileExport.getClients());
newIsilonExport.resetReadOnly();
}
return newIsilonExport;
}
use of com.emc.storageos.isilon.restapi.IsilonExport 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.isilon.restapi.IsilonExport 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