use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method updateExportRules.
@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
// 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);
// 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());
// Handle Modified export Rules
if (exportsToprocess != null && !exportsToprocess.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 modification exception 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);
if (exportsToprocess.isEmpty() && !exportsToRemove.isEmpty()) {
// If all exports rules deleted, export will get deleted too. So set back to its defaults
ExportRule rule = new ExportRule();
rule.setSecFlavor("sys");
rule.setAnon("root");
java.util.Set<String> roHosts = new HashSet<>();
roHosts.add("Default");
rule.setReadOnlyHosts(roHosts);
exportsToprocess.add(rule);
}
} else {
if (exportsToprocess == null) {
exportsToprocess = new ArrayList<>();
}
exportsToprocess.addAll(exportAdd);
exportsToprocess.addAll(exportModify);
}
// if only delete provided with no existing rules -- How do we handle this? [GOPI]
_log.info("Number of Export Rules to update after processing found {}", exportsToprocess.size());
BiosCommandResult result = new BiosCommandResult();
try {
String portGroup = null;
if (args.getFileOperation() == true) {
FileShare 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 fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
portGroup = findVfilerName(fileshare);
}
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
if (!nApi.modifyNFSShare(exportPath, exportsToprocess)) {
_log.error("NetAppFileStorageDevice updateFSExportRules {} - failed", args.getFsId());
result.setMessage("NetAppFileStorageDevice updateFSExportRules {} - failed");
result.setCommandStatus(Operation.Status.error.name());
return result;
}
if ((args.getFileOperation() == true) && args.getSubDirectory() == null) {
nApi.setQtreemode(exportPath, UNIX_QTREE_SETTING);
}
} catch (NetAppException e) {
_log.info("Exception:" + e.getMessage());
throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
}
_log.info("NetAppFileStorageDevice updateFSExportRules {} - complete", args.getFsId());
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
return result;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class IsilonStatsRecorder method addUsageStat.
/**
* Adds a Stat for usage from the IsilonQuota.
*
* @param quota
* @param keyMap
* @param fsNativeGuid native Guid of the file share
* @param isilonApi
* @return the stat
*/
public Stat addUsageStat(IsilonSmartQuota quota, Map<String, Object> keyMap, String fsNativeGuid, IsilonApi isilonApi) {
Stat stat = zeroRecordGenerator.injectattr(keyMap, fsNativeGuid, FileShare.class);
if (stat != null) {
try {
DbClient dbClient = (DbClient) keyMap.get(Constants.dbClient);
stat.setTimeInMillis((Long) keyMap.get(Constants._TimeCollected));
stat.setTimeCollected((Long) keyMap.get(Constants._TimeCollected));
statsColumnInjector.injectColumns(stat, dbClient);
long provisionedCapacity = 0L;
Thresholds threshold = quota.getThresholds();
if (threshold != null && threshold.getHard() != null) {
provisionedCapacity = threshold.getHard();
}
stat.setProvisionedCapacity(provisionedCapacity);
long usedCapacity = quota.getUsagePhysical();
stat.setAllocatedCapacity(usedCapacity);
URIQueryResultList snapURIList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(stat.getResourceId()), snapURIList);
// Set snapshot count.
// Set snapshot size. Get current data for snapshot size (snapshot size changes dynamically).
int snapCount = 0;
long fsSnapshotSize = 0;
IsilonSnapshot isiSnap;
for (URI snapURI : snapURIList) {
Snapshot snap = dbClient.queryObject(Snapshot.class, snapURI);
// Filter out deleted Snapshot
if (snap != null && (!snap.getInactive())) {
String nativeId = snap.getNativeId();
try {
isiSnap = isilonApi.getSnapshot(nativeId);
} catch (IsilonException iex) {
_log.error(String.format("Stat: %s: can not get snapshot size for snapshot: %s", fsNativeGuid, nativeId), iex);
continue;
}
snapCount++;
fsSnapshotSize += Long.valueOf(isiSnap.getSize());
}
}
stat.setSnapshotCount(snapCount);
_log.debug(String.format("Stat: %s: snapshot count: %s", fsNativeGuid, snapCount));
stat.setSnapshotCapacity(fsSnapshotSize);
_log.debug(String.format("Stat: %s: snapshot size: %s", fsNativeGuid, fsSnapshotSize));
_log.debug(String.format("Stat: %s: %s: provisioned capacity(%s): used capacity(%s)", stat.getResourceId(), fsNativeGuid, provisionedCapacity, usedCapacity));
} catch (DatabaseException ex) {
_log.error("Query to db failed for FileShare id {}, skipping recording usage stat.", stat.getResourceId(), ex);
}
}
return stat;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXFileCommApi method getVNXFSDependencies.
/*
* Check the dependencies on file share or on snap shot.
* input :
* fs: File share object
* considerSnapshots: consider the snap shot dependencies.
* return: this function will check and return the number of dependencies like
* exports, shares, snapshot and quota directories on the given file share.
*/
private int getVNXFSDependencies(FileShare fs, Boolean considerSnapshots) {
FSExportMap exports = null;
SMBShareMap shares = null;
int totalDependencies = 0;
// FileShare operation
if (fs.getFsExports() != null) {
exports = fs.getFsExports();
}
if (fs.getSMBFileShares() != null) {
shares = fs.getSMBFileShares();
}
if (exports != null) {
totalDependencies += exports.size();
}
if (shares != null) {
totalDependencies += shares.size();
}
List<Snapshot> snapshots = getFSSnapshots(fs);
if (snapshots != null && !snapshots.isEmpty()) {
totalDependencies += snapshots.size();
}
List<QuotaDirectory> quotaDirs = getFSQuotaDirs(fs);
if (quotaDirs != null && !quotaDirs.isEmpty()) {
totalDependencies += quotaDirs.size();
}
if (considerSnapshots && snapshots != null) {
totalDependencies = snapshots.size();
for (Snapshot snap : snapshots) {
exports = snap.getFsExports();
shares = snap.getSMBFileShares();
if (exports != null) {
totalDependencies += exports.size();
}
if (shares != null) {
totalDependencies += shares.size();
}
}
}
_log.info("FileShare : total dependencies {} ", totalDependencies);
return totalDependencies;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class VNXFileCommApi method deleteFileSystem.
public XMLApiResult deleteFileSystem(final StorageSystem system, final String fileId, final String fileSys, final boolean isForceDelete, FileShare fs) throws VNXException {
_log.info("Delete VNX File System: fs id {}, Force Delete {}", fileId, isForceDelete);
XMLApiResult result = new XMLApiResult();
if (null == fileId || null == fileSys || fileId.trim().equals("") || fileSys.trim().equals("")) {
result.setCommandFailed();
result.setMessage("Invalid Input Parameters.");
return result;
}
Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
try {
updateAttributes(reqAttributeMap, system);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_NAME, fileSys);
reqAttributeMap.put(VNXFileConstants.FILESYSTEM_ID, fileId);
_provExecutor.setKeyMap(reqAttributeMap);
// Before deleting check whether it is available or not on the array - This need to be done as part of
// deleting un-managed FS.
_provExecutor.setKeyMap(reqAttributeMap);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FSIDQUERY_FILE_DELETE));
boolean isFsAvailable = false;
_log.debug("Listing VNX File File Systems");
String cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (null != cmdResult && cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
isFsAvailable = (Boolean) _provExecutor.getKeyMap().get(VNXFileConstants.IS_FILESYSTEM_AVAILABLE_ON_ARRAY);
}
if (!isFsAvailable) {
_log.debug("File System **Not found on array which requested to delete.");
result.setCommandSuccess();
// No need to set Inactive and persist here as this will be done in upper layer(FileDeviceController)
}
if (isForceDelete) {
// handle snapshots
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FS_FORCE_DEL_FILE));
cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
StorageHADomain dataMover = getDataMover(fs);
if (cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
List<Checkpoint> snaps = (List<Checkpoint>) _provExecutor.getKeyMap().get(VNXFileConstants.SNAPSHOTS_LIST);
int numSnapshots = (snaps != null) ? snaps.size() : 0;
_log.info("Number of Snapshots found {} for a file system {}", numSnapshots, fileId);
if (snaps != null && !snaps.isEmpty()) {
for (Checkpoint checkpoint : snaps) {
_log.info("Deleting Snapshot having name {} - and id {}", checkpoint.getName(), checkpoint.getCheckpoint());
String nativeGuid = NativeGUIDGenerator.getNativeGuidforSnapshot(system, system.getSerialNumber(), checkpoint.getCheckpoint());
_log.info("NativeGuid {} built for snapshot {}", nativeGuid, checkpoint.getCheckpoint());
Snapshot snapshot = null;
List<URI> snapShotUris = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotNativeGuidConstraint(nativeGuid));
_log.info("{} Snapshots found with native guid : {} ", snapShotUris.size(), nativeGuid);
if (!snapShotUris.isEmpty()) {
_log.info("Retriving Snapshot using URI : {} ", snapShotUris.get(0));
snapshot = _dbClient.queryObject(Snapshot.class, snapShotUris.get(0));
}
if (snapshot != null) {
result = deleteAllExportsAndShares(system, dataMover, fs, snapshot);
XMLApiResult status = doDeleteSnapshot(system, checkpoint.getCheckpoint(), checkpoint.getName(), false);
if (!status.isCommandSuccess()) {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
return result;
}
}
}
}
// Delete All Quota directories of FileShare.
result = deleteAllQuotaDirs(system, dataMover, fs);
// Delete Exports/SMB Shares of FileShare
result = deleteAllExportsAndShares(system, dataMover, fs, null);
} else {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
return result;
}
}
if (isFsAvailable) {
_log.debug("File System found on array which requested to delete. Now, deleting on Array.");
// First unmount it
StorageHADomain dataMover = getDataMover(fs);
if (dataMover != null) {
Map<String, String> existingMounts = sshApi.getFsMountpathMap(dataMover.getAdapterName());
// is FS mount still exists?
if (existingMounts.get(fs.getName()) != null) {
// The File system is mounted and we need to unmount it before deleting it
String unMountCmd = sshApi.formatUnMountCmd(dataMover.getAdapterName(), fs.getMountPath(), "NFS");
_log.info("Unmount FS {}", unMountCmd);
sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, unMountCmd);
}
} else {
_log.info("No need to Unmount FS {} since there is no mount info", fs.getMountPath());
}
_provExecutor.setKeyMap(reqAttributeMap);
_provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_FSDEL_FILE));
cmdResult = (String) _provExecutor.getKeyMap().get(VNXFileConstants.CMD_RESULT);
if (null != cmdResult && cmdResult.equals(VNXFileConstants.CMD_SUCCESS)) {
result.setCommandSuccess();
} else {
String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
result.setCommandFailed();
result.setMessage(errMsg);
}
}
} catch (Exception e) {
throw new VNXException("File system delete exception: ", e);
}
return result;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method deleteShare.
@Override
public void deleteShare(URI storage, URI uri, FileSMBShare fileSMBShare, String opId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Deleting file system: %s CIFS share: %s ", uri, fileSMBShare.getName());
successMessage = String.format("Deleting file system: %s CIFS share: %s finished succesfully.", uri, fileSMBShare.getName());
opName = ResourceOperationTypeEnum.DELETE_FILE_SYSTEM_SHARE.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Deleting file system snapshot: %s CIFS share: %s ", uri, fileSMBShare.getName());
successMessage = String.format("Deleting file system snapshot: %s CIFS share: %s finished succesfully.", uri, fileSMBShare.getName());
opName = ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, DELETE_FILESYSTEM_CIFS_SHARE_WF_NAME, false, opId, completer);
String sharedeleteStep = workflow.createStepId();
Object[] args = new Object[] { storage, uri, fileSMBShare };
_fileDeviceController.createMethod(workflow, null, DELETE_FILESYSTEM_SHARE_METHOD, sharedeleteStep, stepDescription, storage, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Deleting file system snapshot: %s CIFS share: %s failed.", uri, fileSMBShare.getName()), ex);
ServiceError serviceError = DeviceControllerException.errors.deleteCIFSShareFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
Aggregations