use of com.emc.storageos.db.client.model.Snapshot 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.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doDeleteShare.
/**
* Deletes CIFS FileShare
*
* @param StorageSystem storage
* @param FileDeviceInputOutput args
* @param SMBFileShare smbFileShare
* @return BiosCommandResult
* @throws ControllerException
*/
@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doDeleteShare - start");
FileShare fileshare = null;
if (args.getFileOperation() == true) {
fileshare = args.getFs();
} else {
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
String portGroup = findVfilerName(fileshare);
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
SMBShareMap shares = args.getFileObjShares();
if (shares == null || shares.isEmpty()) {
_log.error("NetAppFileStorageDevice::doDeleteShare failed: FileShare(s) is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
serviceError.setMessage("FileShare(s) is either missing or empty");
result = BiosCommandResult.createErrorResult(serviceError);
}
SMBFileShare fileShare = shares.get(smbFileShare.getName());
if (fileShare != null) {
if (!nApi.deleteShare(smbFileShare.getName())) {
_log.error("NetAppFileStorageDevice doDeleteShare {} - failed", args.getFileObjId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
serviceError.setMessage("Deletion of CIFS File Share failed");
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("NetAppFileStorageDevice doDeleteShare {} - complete", args.getFileObjId());
args.getFileObjShares().remove(smbFileShare.getName());
args.getFileObjShares().remove(smbFileShare.getNativeId());
result = BiosCommandResult.createSuccessfulResult();
}
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doDeleteShare failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doCreateFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXFileCommApi method doDeleteShare.
/**
* Delete a CIFS Share
*
* @param system
* @param moverOrVdm
* data mover the share is on.
* @param shareName
* name of the CIFS share.
* @return result of the operation.
*/
public XMLApiResult doDeleteShare(StorageSystem system, StorageHADomain moverOrVdm, String shareName, String mountPoint, boolean deleteMount, FileDeviceInputOutput args) {
_log.info("CommApi: delete share {}", shareName);
XMLApiResult result = new XMLApiResult();
result.setCommandSuccess();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
try {
updateAttributes(reqAttributeMap, system);
if (null == moverOrVdm) {
result.setCommandFailed();
result.setMessage("Export failed: data mover or VDM not found.");
return result;
}
String moverOrVdmName = moverOrVdm.getAdapterName();
String isVdm = "false";
String moverOrVdmId = moverOrVdm.getName();
reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverOrVdmId);
reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
if (moverOrVdm.getVirtual() != null && moverOrVdm.getVirtual() == true) {
isVdm = "true";
}
_log.info("Using Mover {} to Delete share {}", moverOrVdmId + ":" + moverOrVdmName, shareName);
updateAttributes(reqAttributeMap, system);
reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverOrVdmId);
reqAttributeMap.put(VNXFileConstants.DATAMOVER_NAME, moverOrVdmName);
reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
_provExecutor.setKeyMap(reqAttributeMap);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_CIFS_SERVERS));
List<VNXCifsServer> cifsServers = (List<VNXCifsServer>) _provExecutor.getKeyMap().get(VNXFileConstants.CIFS_SERVERS);
for (VNXCifsServer cifsServer : cifsServers) {
_log.info("CIFServer:" + cifsServer.toString());
}
if (cifsServers == null || cifsServers.isEmpty()) {
_log.info("No CIFS Servers retrieved for mover {} with id {}", moverOrVdmName, moverOrVdmId);
}
String netBios = null;
// Only set netbios for VDM CIFS exports
if (cifsServers != null && !cifsServers.isEmpty() && moverOrVdm.getVirtual()) {
netBios = cifsServers.get(0).getName();
}
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
String data = sshApi.formatDeleteShareCmd(moverOrVdmName, shareName, netBios);
_log.info("doDeleteShare command {}", data);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
FileShare fileShare = null;
if (!args.getFileOperation()) {
Snapshot snapshot = _dbClient.queryObject(Snapshot.class, args.getSnapshotId());
fileShare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
} else {
fileShare = _dbClient.queryObject(FileShare.class, args.getFileObjId());
}
if (result.isCommandSuccess() && getVNXFSDependencies(fileShare, false) <= 1) {
// FileSystem Mount Point
// Delete the mount
data = sshApi.formatUnMountCmd(moverOrVdmName, mountPoint, "CIFS");
_log.info("Unmount filesystem command {}", data);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
}
sshApi.clearConnParams();
} catch (Exception e) {
throw new VNXException("Failure", e);
}
return result;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXFileCommApi method doDeleteExport.
public XMLApiResult doDeleteExport(final StorageSystem system, String exportPath, FileDeviceInputOutput args, boolean deleteMount) {
XMLApiResult result = new XMLApiResult();
result.setCommandSuccess();
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
_log.info("Delete VNX Export : {}", exportPath);
if (exportPath == null || (exportPath != null && exportPath.isEmpty())) {
_log.info("Invalid Export Path");
return result;
}
try {
updateAttributes(reqAttributeMap, system);
String moverId;
StorageHADomain dataMover = null;
String mountPath = "";
if (args.getFileOperation()) {
StoragePort storagePort = _dbClient.queryObject(StoragePort.class, args.getFs().getStoragePort());
URI dataMoverId = storagePort.getStorageHADomain();
dataMover = _dbClient.queryObject(StorageHADomain.class, dataMoverId);
moverId = dataMover.getName();
mountPath = args.getFsMountPath();
_log.info("Using Mover Id {} to unexport FS mounted at {}", moverId, exportPath);
// Delete export from storage system.
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), exportPath).containsKey(exportPath)) {
// Delete the Export.
String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), exportPath);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
}
// we check for any exports and share exists and then run umount operation
if (result.isCommandSuccess() && getVNXFSDependencies(args.getFs(), false) <= 1) {
// Delete the mount
String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), mountPath, "NFS");
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
}
sshApi.clearConnParams();
} else {
String isVdm = "false";
Snapshot snapshot = _dbClient.queryObject(Snapshot.class, args.getSnapshotId());
FileShare fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
StoragePort storagePort = _dbClient.queryObject(StoragePort.class, fileshare.getStoragePort());
URI dataMoverId = storagePort.getStorageHADomain();
dataMover = _dbClient.queryObject(StorageHADomain.class, dataMoverId);
moverId = dataMover.getName();
_log.info("Using Mover Id {} to unexport FS mounted at {}", moverId, exportPath);
if (dataMover.getVirtual()) {
isVdm = "true";
}
// Delete export from storage system.
reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverId);
reqAttributeMap.put(VNXFileConstants.MOUNT_PATH, exportPath);
reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
_provExecutor.setKeyMap(reqAttributeMap);
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), exportPath).containsKey(exportPath)) {
String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), exportPath);
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
}
// Delete the Snapshot mount, only if No depending exports, shares for that snapshot.
if (result.isCommandSuccess() && getVNXFSDependencies(args.getFs(), true) <= 1) {
// Delete the mount
String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), exportPath, "NFS");
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
}
sshApi.clearConnParams();
}
} catch (Exception e) {
throw new VNXException("File Export Delete Exception: ", e);
}
return result;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXFileCommApi method getFSSnapshots.
private List<Snapshot> getFSSnapshots(FileShare fs) {
URI fsId = fs.getId();
List<Snapshot> snapshots = new ArrayList<Snapshot>();
URIQueryResultList snapIDList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(fsId), snapIDList);
while (snapIDList.iterator().hasNext()) {
URI uri = snapIDList.iterator().next();
Snapshot snap = _dbClient.queryObject(Snapshot.class, uri);
if (!snap.getInactive()) {
snapshots.add(snap);
}
}
return snapshots;
}
Aggregations