use of com.emc.storageos.db.client.model.StorageHADomain in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method processStorageHADomains.
private void processStorageHADomains(com.emc.storageos.db.client.model.StorageSystem storageSystem, Map<StoragePort, com.emc.storageos.db.client.model.StoragePort> driverPortsToDBPorts) {
// Map ha zone names to driver ports
Map<String, Set<StoragePort>> haZoneNameToDriverPorts = new HashMap<>();
Set<StoragePort> driverPorts = driverPortsToDBPorts.keySet();
for (StoragePort driverPort : driverPorts) {
if (driverPort.getPortHAZone() != null && !driverPort.getPortHAZone().isEmpty()) {
Set<StoragePort> haZonePorts = haZoneNameToDriverPorts.get(driverPort.getPortHAZone());
if (haZonePorts == null) {
haZonePorts = new HashSet<>();
haZoneNameToDriverPorts.put(driverPort.getPortHAZone(), haZonePorts);
}
haZonePorts.add(driverPort);
}
}
for (Map.Entry<String, Set<StoragePort>> haZoneNameToDriverPort : haZoneNameToDriverPorts.entrySet()) {
String portHAZone = haZoneNameToDriverPort.getKey();
Set<StoragePort> haZoneDriverPorts = haZoneNameToDriverPort.getValue();
if (portHAZone != null) {
String haDomainNativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem, portHAZone, NativeGUIDGenerator.ADAPTER);
_log.info("HA Domain Native Guid : {}", haDomainNativeGUID);
@SuppressWarnings("deprecation") List<URI> uriHaList = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageHADomainByNativeGuidConstraint(haDomainNativeGUID));
StorageHADomain haDomain;
if (uriHaList.isEmpty()) {
haDomain = new StorageHADomain();
haDomain.setId(URIUtil.createId(StorageHADomain.class));
haDomain.setNativeGuid(haDomainNativeGUID);
haDomain.setName(portHAZone);
haDomain.setAdapterName(portHAZone);
haDomain.setStorageDeviceURI(storageSystem.getId());
haDomain.setNumberofPorts(String.valueOf(haZoneDriverPorts.size()));
_dbClient.createObject(haDomain);
} else {
haDomain = _dbClient.queryObject(StorageHADomain.class, uriHaList.get(0));
haDomain.setNumberofPorts(String.valueOf(haZoneDriverPorts.size()));
_dbClient.updateObject(haDomain);
}
for (StoragePort driverPort : haZoneDriverPorts) {
com.emc.storageos.db.client.model.StoragePort port = driverPortsToDBPorts.get(driverPort);
port.setStorageHADomain(haDomain.getId());
}
}
}
}
use of com.emc.storageos.db.client.model.StorageHADomain in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method updateExportRules.
@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
XMLApiResult result = null;
ApplicationContext context = null;
// 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<>();
String exportPath;
String subDir = args.getSubDirectory();
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 existng Rules found {}", exportsToprocess.size());
// If there are no Export rules and add is allowed
if (!exportsToprocess.isEmpty() || (exportAdd != null && !exportAdd.isEmpty())) {
for (ExportRule existingRule : exportsToprocess) {
for (ExportRule modifiedrule : exportModify) {
if (modifiedrule.getSecFlavor().equals(existingRule.getSecFlavor())) {
_log.info("Modifying Export Rule from {}, To {}", existingRule, modifiedrule);
// use a separate list to avoid concurrent modifications for now.
exportsToRemove.add(existingRule);
exportsToAdd.add(modifiedrule);
}
}
}
// Handle Add export Rules
if (exportAdd != null && !exportAdd.isEmpty()) {
for (ExportRule newExport : exportAdd) {
_log.info("Adding Export Rule {}", newExport);
exportsToAdd.add(newExport);
}
}
// 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);
_log.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
exportsToprocess.addAll(exportsToAdd);
// Figure out mounted or not
SMBShareMap shares = args.getFs().getSMBFileShares();
boolean isMounted = true;
if (exportsToprocess.isEmpty() && (shares == null || (shares != null && shares.isEmpty()))) {
isMounted = false;
}
// Mounting is only necessary for FileSystem and not snapshot for the first time export
if (!args.getFileOperation()) {
isMounted = false;
}
// To be compatible with existing export creating an empty list
List<String> newPaths = new ArrayList<String>();
newPaths.add(exportPath);
try {
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
// Get DataMover Name and whether it is virtual
StorageHADomain dm = this.getDataMover(args.getFs());
if (dm == null) {
Exception e = new Exception("VNX File Export Failed Data Mover not found");
throw VNXException.exceptions.createExportFailed("VNX File Export Failed Data Mover not found", e);
}
List<VNXFileExport> exportList = new ArrayList<VNXFileExport>();
for (ExportRule rule : exportsToprocess) {
VNXFileExport vnxExp = null;
// update the comment
String comments = rule.getComments();
String protocol = "nfs";
if (rule.getReadOnlyHosts() != null && !rule.getReadOnlyHosts().isEmpty()) {
vnxExp = new VNXFileExport(new ArrayList<String>(rule.getReadOnlyHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "ro", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
exportList.add(vnxExp);
}
if (rule.getReadWriteHosts() != null && !rule.getReadWriteHosts().isEmpty()) {
vnxExp = new VNXFileExport(new ArrayList<String>(rule.getReadWriteHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "rw", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
exportList.add(vnxExp);
}
if (rule.getRootHosts() != null && !rule.getRootHosts().isEmpty()) {
vnxExp = new VNXFileExport(new ArrayList<String>(rule.getRootHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "root", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
exportList.add(vnxExp);
}
}
// existing VNXComm API. This is required to read the subsequent information down the line.
if ((exportList != null && exportList.isEmpty()) && (exportsToRemove != null && !exportsToRemove.isEmpty())) {
_log.info("Requested to remove all export rules");
VNXFileExport vnxExp = new VNXFileExport(new ArrayList<String>(), dm.getName(), exportPath, "", "root", "", "", args.getFs().getStoragePort().toString(), subDir, "");
exportList.add(vnxExp);
}
// List<VNXFileExport> vnxExports = getVNXFileExports(newExpList);
if (args.getFileOperation()) {
// Perform FileSystem export
result = vnxComm.doExport(storage, dm, exportList, newPaths, args.getFileObj(), args.getFsNativeId(), isMounted);
} else {
// perform Snapshot export
result = vnxComm.doExport(storage, dm, exportList, newPaths, args.getFileObj(), args.getSnapNativeId(), isMounted);
}
if (result.isCommandSuccess()) {
_log.info("updateExportRules result.isCommandSuccess true");
}
} catch (VNXException e) {
throw VNXException.exceptions.createExportFailed("VNX File Export Failed", e);
} finally {
clearContext(context);
}
}
BiosCommandResult cmdResult = null;
if (result.isCommandSuccess()) {
cmdResult = BiosCommandResult.createSuccessfulResult();
} else {
cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToUpdateExport(result.getMessage()));
}
return cmdResult;
}
use of com.emc.storageos.db.client.model.StorageHADomain in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doDeleteShare.
@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
_log.info("Call FileShare doDeleteShare");
XMLApiResult result = null;
ApplicationContext context = null;
try {
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
StorageHADomain dm = null;
String mountPoint = null;
if (args.getFileOperation()) {
mountPoint = args.getFs().getMountPath();
// Get DataMover
dm = this.getDataMover(args.getFs());
if (dm == null) {
Exception e = new Exception("VNX File Share creation Failed Data Mover not found");
throw VNXException.exceptions.createExportFailed("VNX File Delete Share Failed Data Mover not found", e);
}
} else {
// Get DataMover
URI snapshotId = args.getSnapshotId();
Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapshotId);
FileShare fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
mountPoint = fileshare.getMountPath();
dm = this.getDataMover(fileshare);
if (dm == null) {
Exception e = new Exception("VNX File Share creation Failed Data Mover not found");
throw VNXException.exceptions.createExportFailed("VNX File Delete Share Failed Data Mover not found", e);
}
}
result = vnxComm.doDeleteShare(storage, dm, smbFileShare.getName(), mountPoint, false, args);
args.getFileObjShares().remove(smbFileShare.getName());
} catch (VNXException e) {
throw new DeviceControllerException(e);
} finally {
clearContext(context);
}
BiosCommandResult cmdResult = null;
if (result.isCommandSuccess()) {
cmdResult = BiosCommandResult.createSuccessfulResult();
} else {
cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToDeleteFileShare(result.getMessage()));
}
return cmdResult;
}
use of com.emc.storageos.db.client.model.StorageHADomain in project coprhd-controller by CoprHD.
the class VNXeStorageDevice method doCreateFS.
@Override
public BiosCommandResult doCreateFS(StorageSystem storage, FileDeviceInputOutput fileInOut) throws ControllerException {
_logger.info("creating file system: ", fileInOut.getFsName());
Long fsSize = fileInOut.getFsCapacity();
if (fsSize < 1) {
// Invalid size throw an error
_logger.error("doCreateFS failed : FileSystem size in bytes is not valid {}", fileInOut.getFsCapacity());
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("FileSystem size in bytes is not valid");
return BiosCommandResult.createErrorResult(error);
}
VNXeFileTaskCompleter completer = null;
VNXeApiClient apiClient = getVnxeClient(storage);
VNXeCommandJob job = null;
try {
FileShare fs = fileInOut.getFs();
URI port = fs.getStoragePort();
if (port == null) {
_logger.error("No storageport uri found in the fs");
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("No storageport uri found in the fs");
return BiosCommandResult.createErrorResult(error);
}
StoragePort portObj = _dbClient.queryObject(StoragePort.class, port);
URI haDomainUri = portObj.getStorageHADomain();
StorageHADomain haDomainObj = _dbClient.queryObject(StorageHADomain.class, haDomainUri);
StringSet protocols = fs.getProtocol();
if (protocols.contains(StorageProtocol.File.NFS_OR_CIFS.name())) {
/*
* the protocol is set to NFS_OR_CIFS, only if virtual pool's protocol is not set
* and the pool's protocol is set to NFS_OR_CIFS, since pool's protocol is set based on
* storageHADomain's protocol, setting the protocols to the selected StorageHADomain.
*/
protocols = haDomainObj.getFileSharingProtocols();
}
VNXeFSSupportedProtocolEnum protocolEnum = null;
if (protocols.contains(StorageProtocol.File.NFS.name()) && protocols.contains(StorageProtocol.File.CIFS.name())) {
protocolEnum = VNXeFSSupportedProtocolEnum.NFS_CIFS;
} else if (protocols.contains(StorageProtocol.File.NFS.name())) {
protocolEnum = VNXeFSSupportedProtocolEnum.NFS;
} else if (protocols.contains(StorageProtocol.File.CIFS.name())) {
protocolEnum = VNXeFSSupportedProtocolEnum.CIFS;
} else {
_logger.error("protocol is not support: " + protocols);
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("protocol is not support:" + protocols);
return BiosCommandResult.createErrorResult(error);
}
job = apiClient.createFileSystem(fileInOut.getFsName(), fsSize, fileInOut.getPoolNativeId(), haDomainObj.getSerialNumber(), fileInOut.getThinProvision(), protocolEnum);
if (job != null) {
_logger.info("opid:" + fileInOut.getOpId());
completer = new VNXeFileTaskCompleter(FileShare.class, fileInOut.getFsId(), fileInOut.getOpId());
if (fileInOut.getFs() == null) {
_logger.error("Could not find the fs object");
}
VNXeCreateFileSystemJob createFSJob = new VNXeCreateFileSystemJob(job.getId(), storage.getId(), completer, fileInOut.getPoolId());
ControllerServiceImpl.enqueueJob(new QueueJob(createFSJob));
} else {
_logger.error("No job returned from creatFileSystem");
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("No Job returned from createFileSystem");
return BiosCommandResult.createErrorResult(error);
}
} catch (VNXeException e) {
_logger.error("Create file system got the exception", e);
if (completer != null) {
completer.error(_dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Create file system got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateFileSystem", ex.getMessage());
if (completer != null) {
completer.error(_dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Create filesystem job submitted - Array:%s, Pool:%s, fileSystem: %s", storage.getSerialNumber(), fileInOut.getPoolNativeId(), fileInOut.getFsName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.db.client.model.StorageHADomain in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice method doCreateFS.
@Override
public BiosCommandResult doCreateFS(StorageSystem storage, FileDeviceInputOutput fileInOut) throws ControllerException {
_logger.info("creating file system: ", fileInOut.getFsName());
Long fsSize = fileInOut.getFsCapacity();
if (fsSize < 1) {
// Invalid size throw an error
_logger.error("doCreateFS failed : FileSystem size in bytes is not valid {}", fileInOut.getFsCapacity());
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("FileSystem size in bytes is not valid");
return BiosCommandResult.createErrorResult(error);
}
VNXeFileTaskCompleter completer = null;
VNXeApiClient apiClient = getVnxUnityClient(storage);
VNXeCommandJob job = null;
try {
FileShare fs = fileInOut.getFs();
URI port = fs.getStoragePort();
if (port == null) {
_logger.error("No storageport uri found in the fs");
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("No storageport uri found in the fs");
return BiosCommandResult.createErrorResult(error);
}
StoragePort portObj = dbClient.queryObject(StoragePort.class, port);
URI haDomainUri = portObj.getStorageHADomain();
StorageHADomain haDomainObj = dbClient.queryObject(StorageHADomain.class, haDomainUri);
StringSet protocols = fs.getProtocol();
if (protocols.contains(StorageProtocol.File.NFS_OR_CIFS.name())) {
/*
* the protocol is set to NFS_OR_CIFS, only if virtual pool's protocol is not set
* and the pool's protocol is set to NFS_OR_CIFS, since pool's protocol is set based on
* storageHADomain's protocol, setting the protocols to the selected StorageHADomain.
*/
protocols = haDomainObj.getFileSharingProtocols();
}
VNXeFSSupportedProtocolEnum protocolEnum = null;
if (protocols.contains(StorageProtocol.File.NFS.name()) && protocols.contains(StorageProtocol.File.CIFS.name())) {
protocolEnum = VNXeFSSupportedProtocolEnum.NFS_CIFS;
} else if (protocols.contains(StorageProtocol.File.NFS.name())) {
protocolEnum = VNXeFSSupportedProtocolEnum.NFS;
} else if (protocols.contains(StorageProtocol.File.CIFS.name())) {
protocolEnum = VNXeFSSupportedProtocolEnum.CIFS;
} else {
_logger.error("The protocol is not supported: " + protocols);
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("The protocol is not supported:" + protocols);
return BiosCommandResult.createErrorResult(error);
}
job = apiClient.createFileSystem(fileInOut.getFsName(), fsSize, fileInOut.getPoolNativeId(), haDomainObj.getSerialNumber(), fileInOut.getThinProvision(), protocolEnum);
if (job != null) {
_logger.info("opid:" + fileInOut.getOpId());
completer = new VNXeFileTaskCompleter(FileShare.class, fileInOut.getFsId(), fileInOut.getOpId());
if (fileInOut.getFs() == null) {
_logger.error("Could not find the fs object");
}
VNXeCreateFileSystemJob createFSJob = new VNXeCreateFileSystemJob(job.getId(), storage.getId(), completer, fileInOut.getPoolId());
ControllerServiceImpl.enqueueJob(new QueueJob(createFSJob));
} else {
_logger.error("No job returned from creatFileSystem");
ServiceError error = DeviceControllerErrors.vnxe.unableToCreateFileSystem("No Job returned from createFileSystem");
return BiosCommandResult.createErrorResult(error);
}
} catch (VNXeException e) {
_logger.error("Create file system got an exception", e);
if (completer != null) {
completer.error(dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Create file system got an exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateFileSystem", ex.getMessage());
if (completer != null) {
completer.error(dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Create filesystem job submitted - Array:%s, Pool:%s, fileSystem: %s", storage.getSerialNumber(), fileInOut.getPoolNativeId(), fileInOut.getFsName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
Aggregations