use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doExport.
@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
_log.info("NetAppFileStorageDevice doExport - start");
// Verify inputs.
validateExportArgs(exportList);
List<String> rootHosts = new ArrayList<String>();
List<String> rwHosts = new ArrayList<String>();
List<String> roHosts = new ArrayList<String>();
if (args.getFileObjExports() == null || args.getFileObjExports().isEmpty()) {
args.initFileObjExports();
}
FSExportMap existingExpMap = args.getFileObjExports();
List<FileExport> existingExportList = new ArrayList<FileExport>();
FileExport existingExport = null;
Iterator<String> it = existingExpMap.keySet().iterator();
while (it.hasNext()) {
existingExport = existingExpMap.get(it.next());
_log.info("Existing export FileExport key : {} ", existingExport.getFileExportKey());
existingExportList.add(existingExport);
}
// If it's a sub-directory no need to take existing hosts.
boolean isSubDir = checkIfSubDirectory(args.getFsMountPath(), exportList.get(0).getMountPath());
if (isSubDir) {
existingExportList = null;
}
// TODO: Revisit once new Data Model for Exports is implemented.
Map<String, List<String>> existingHosts = null;
if ((null != existingExportList) && !existingExportList.isEmpty()) {
existingHosts = sortHostsFromCurrentExports(existingExportList);
}
if (null != existingHosts) {
if ((null != existingHosts.get(ROOT_HOSTS)) && !existingHosts.get(ROOT_HOSTS).isEmpty()) {
addNewHostsOnly(rootHosts, existingHosts.get(ROOT_HOSTS));
}
if ((null != existingHosts.get(RW_HOSTS)) && !existingHosts.get(RW_HOSTS).isEmpty()) {
addNewHostsOnly(rwHosts, existingHosts.get(RW_HOSTS));
}
if ((null != existingHosts.get(RO_HOSTS)) && !existingHosts.get(RO_HOSTS).isEmpty()) {
addNewHostsOnly(roHosts, existingHosts.get(RO_HOSTS));
}
}
BiosCommandResult result = new BiosCommandResult();
try {
for (int expCount = 0; expCount < exportList.size(); expCount++) {
FileExport export = exportList.get(expCount);
if (!(export.getMountPath().startsWith(VOL_ROOT_NO_SLASH))) {
export.setMountPath(VOL_ROOT_NO_SLASH + export.getMountPath());
}
FileExport fileExport = new FileExport(export.getClients(), export.getStoragePortName(), export.getMountPoint(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getProtocol(), export.getStoragePort(), export.getPath(), export.getMountPath(), export.getSubDirectory(), export.getComments());
args.getFileObjExports().put(fileExport.getFileExportKey(), fileExport);
String portGroup = null;
FileShare fileshare = null;
if (args.getFileOperation() == true) {
fileshare = args.getFs();
portGroup = findVfilerName(fileshare);
} else {
// Get the FS from the snapshot
URI snapShotUID = args.getSnapshotId();
Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapShotUID);
fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
// Now get the VFiler from the fileshare
portGroup = findVfilerName(fileshare);
}
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
List<String> endpointsList = export.getClients();
if (endpointsList == null) {
_log.error("NetAppFileStorageDevice::doExport {} failed: No endpoints specified", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_NO_ENDPOINTS_SPECIFIED);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
sortNewEndPoints(rootHosts, rwHosts, roHosts, endpointsList, export.getPermissions());
String root_user = export.getRootUserMapping();
String mountPath = export.getMountPath();
String exportPath = export.getPath();
if (!nApi.exportFS(exportPath, mountPath, rootHosts, rwHosts, roHosts, root_user, export.getSecurityType())) {
_log.error("NetAppFileStorageDevice::doExport {} failed", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(genDetailedMessage("doExport", args.getFsId().toString()));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
result = BiosCommandResult.createSuccessfulResult();
if ((args.getFileOperation() == true) && (isSubDir == false)) {
nApi.setQtreemode(exportPath, UNIX_QTREE_SETTING);
}
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doExport failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doExport failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
_log.info("NetAppFileStorageDevice::doExport {} - complete", args.getFsId());
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doDeleteSnapshot.
@Override
public BiosCommandResult doDeleteSnapshot(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
if (null == args.getFsName()) {
throw new DeviceControllerException("Filesystem name is either missing or empty", new Object[] {});
}
if (null == args.getSnapshotName()) {
throw new DeviceControllerException("Snapshot name is either missing or empty for filesystem name {0}", new Object[] { args.getFsName() });
}
_log.info("NetAppFileStorageDevice doDeleteSnapshot: {},{} - start", args.getSnapshotId(), args.getSnapshotName());
BiosCommandResult result = new BiosCommandResult();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
try {
if (!nApi.deleteSnapshot(args.getFsName(), args.getSnapshotName())) {
_log.error("NetAppFileStorageDevice doDeleteSnapshot {} - failed", args.getFsId());
result.setCommandSuccess(false);
result.setMessage("NetAppFileStorageDevice doDeleteSnapshot - failed");
result.setCommandStatus(Operation.Status.error.name());
} else {
_log.info("doDeleteSnapshot for snapshot {} on filesystem {} successful", args.getSnapshotName(), args.getFsName());
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
result.setMessage("Snapshot," + args.getSnapshotName() + " has been successfully deleted");
}
} catch (NetAppException e) {
throw new DeviceControllerException("Failed to delete snapshot, {0} for filesystem, {1} with: {2}", new Object[] { args.getSnapshotName(), args.getFsName(), e.getMessage() });
}
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method updateShareACLs.
@Override
public BiosCommandResult updateShareACLs(StorageSystem storage, FileDeviceInputOutput args) {
List<ShareACL> existingAcls = new ArrayList<ShareACL>();
existingAcls = args.getExistingShareAcls();
BiosCommandResult result = new BiosCommandResult();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
try {
processAclsForShare(nApi, args);
result = BiosCommandResult.createSuccessfulResult();
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::updateShareACLs failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToUpdateCIFSShareAcl();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
// if delete or modify fails , revert to old acl
_log.info("update ACL failed ,going to roll back to existing ACLs");
rollbackShareACLs(storage, args, existingAcls);
}
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doRestoreFS.
@Override
public BiosCommandResult doRestoreFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doRestoreFS - start");
if (null == args.getFsName()) {
_log.error("NetAppFileStorageDevice::doRestoreFS failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == args.getSnapshotName()) {
_log.error("NetAppFileStorageDevice::doRestoreFS failed: Snapshot name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_SNAPSHOT_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
if (!nApi.restoreSnapshot(args.getFsName(), args.getSnapshotName())) {
_log.error("NetAppFileStorageDevice doRestoreFS {} - failed", args.getFsName());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("doRestoreFS - restore of snapshot, {} was successfully for filesystem, {} ", args.getSnapshotName(), args.getFsName());
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doRestoreFS failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doRestoreFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method netAppDeleteCIFSExports.
private Boolean netAppDeleteCIFSExports(StorageSystem storage, SMBShareMap currentShares, String portGroup) throws NetAppException {
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();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
if (!nApi.deleteShare(smbFileShare.getName())) {
failedCount++;
} else {
removedShareKeys.add(key);
}
}
for (String keys : removedShareKeys) {
currentShares.remove(keys);
}
if (failedCount > 0) {
return false;
} else {
return true;
}
}
Aggregations