use of com.emc.storageos.netappc.NetAppClusterApi 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.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeDevice method doDeleteFS.
@Override
public BiosCommandResult doDeleteFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppClusterModeDevice doDeleteFS - start");
if (null == args.getFsName()) {
_log.error("NetAppClusterModeDevice::doDeletFS failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
serviceError.setMessage("Filesystem name is either missing or empty");
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
// Now get the SVM from the fileShare
String portGroup = findSVMName(args.getFs());
if (null != args.getFsShares() && !args.getFsShares().isEmpty()) {
if (!netAppDeleteCIFSExports(storage, args.getFsShares(), portGroup)) {
_log.info("NetAppClusterModeDevice doDeletFS:netAppDeleteCIFSExports {} - failed", args.getFsName());
} else {
_log.info("NetAppClusterModeDevice doDeletFS:netAppDeleteCIFSExports {} - succeeded", args.getFsName());
}
}
boolean failedStatus = false;
NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
if (!ncApi.deleteFS(args.getFsName())) {
failedStatus = true;
}
if (failedStatus == true) {
_log.error("NetAppClusterModeDevice doDeletFS {} - failed", args.getFsName());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("NetAppClusterModeDevice doDeletFS {} - complete", args.getFsName());
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppCException e) {
_log.error("NetAppClusterModeDevice::doDeleteFS failed with a NetAppCException", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppClusterModeDevice::doDeleteFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeDevice method netAppDeleteCIFSExports.
private Boolean netAppDeleteCIFSExports(StorageSystem storage, SMBShareMap currentShares, String portGroup) throws NetAppCException {
int failedCount = 0;
Iterator<Entry<String, SMBFileShare>> it = currentShares.entrySet().iterator();
List<String> removedShareKeys = new ArrayList<String>();
while (it.hasNext()) {
Map.Entry<String, SMBFileShare> entry = it.next();
String key = entry.getKey();
SMBFileShare smbFileShare = entry.getValue();
NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
if (!ncApi.deleteShare(smbFileShare.getName())) {
failedCount++;
} else {
removedShareKeys.add(key);
}
}
for (String keys : removedShareKeys) {
currentShares.remove(keys);
}
if (failedCount > 0) {
return false;
} else {
return true;
}
}
use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeDevice method doExpandFS.
@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppClusterModeDevice doExpandFS - start");
long newFsExpandSize = args.getNewFSCapacity();
String volumeName = args.getFsName();
if (args.getNewFSCapacity() % BYTESPERMB == 0) {
newFsExpandSize = newFsExpandSize / BYTESPERMB;
} else {
newFsExpandSize = newFsExpandSize / BYTESPERMB + 1;
}
_log.info("FileSystem new size translation : {} : {}", args.getNewFSCapacity(), newFsExpandSize);
String strNewFsSize = String.valueOf(newFsExpandSize) + "m";
String portGroup = findSVMName(args.getFs());
NetAppClusterApi nApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
if (!nApi.setVolumeSize(volumeName, strNewFsSize)) {
_log.error("NetAppClusterModeDevice doExpandFS - failed");
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExpandFileSystem();
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("NetAppClusterModeDevice doExpandFS - complete");
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppCException e) {
_log.error("NetAppClusterModeDevice::doExpandFS failed with a NetAppCException", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExpandFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppClusterModeDevice::doExpandFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExpandFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeDevice method doCheckFSExists.
/**
* Checking a file system: - Check if the FS exists on Array or not
*
* @param StorageSystem storage
* @param args FileDeviceInputOutput
* @return boolean true if exists else false
* @throws ControllerException
*/
@Override
public boolean doCheckFSExists(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_log.info("checking file system existence on array: ", args.getFsName());
boolean isFSExists = true;
try {
String portGroup = findSVMName(args.getFs());
NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
List<String> fs = ncApi.listFileSystems();
if (!fs.isEmpty() && fs.contains(args.getFsName())) {
isFSExists = true;
} else {
isFSExists = false;
}
} catch (NetAppException e) {
_log.error("NetAppClusterModeDevice::doCheckFSExists failed with an Exception", e);
}
return isFSExists;
}
Aggregations