use of org.alfresco.jlan.server.filesys.quota.QuotaManagerException in project alfresco-repository by Alfresco.
the class ContentDiskDriver2 method registerContext.
/*
* Register context implementation
* <p>
* Results in various obscure bits and pieces being initialised, most importantly the
* calculation of the root node ref.
* <p>
* There's a load of initialisation that needs to be moved out of this method, like the
* instantiation of the lock manager, quota manager and node monitor.
*/
public void registerContext(DeviceContext ctx) throws DeviceContextException {
logger.debug("registerContext");
super.registerContext(ctx);
final ContentContext context = (ContentContext) ctx;
final String rootPath = context.getRootPath();
final String storeValue = context.getStoreName();
/**
* Work using the repo needs to run as system.
*/
RunAsWork<Void> runAsSystem = new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
StoreRef storeRef = new StoreRef(storeValue);
if (!nodeService.exists(storeRef)) {
throw new DeviceContextException("Store not created prior to application startup: " + storeRef);
}
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
// Find the root node for this device
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
NodeRef rootNodeRef = null;
if (nodeRefs.size() > 1) {
throw new DeviceContextException("Multiple possible roots for device: \n" + " root path: " + rootPath + "\n" + " results: " + nodeRefs);
} else if (nodeRefs.size() == 0) {
// Nothing found
throw new DeviceContextException("No root found for device: \n" + " root path: " + rootPath);
} else {
// We found the root node ref
rootNodeRef = nodeRefs.get(0);
}
// Check if a relative path has been specified
String relPath = context.getRelativePath();
try {
if (relPath != null && relPath.length() > 0) {
// Find the node and validate that the relative path is to a folder
NodeRef relPathNode = cifsHelper.getNodeRef(rootNodeRef, relPath);
if (cifsHelper.isDirectory(relPathNode) == false) {
throw new DeviceContextException("Relative path is not a folder, " + relPath);
}
// Use the relative path node as the root of the filesystem
rootNodeRef = relPathNode;
} else {
// Make sure the default root node is a folder
if (cifsHelper.isDirectory(rootNodeRef) == false) {
throw new DeviceContextException("Root node is not a folder type node");
}
}
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Error during create context", ex);
}
throw new DeviceContextException("Unable to find root node.", ex);
}
// Record the root node ref
if (logger.isDebugEnabled()) {
logger.debug("set root node ref:" + rootNodeRef);
}
context.setRootNodeRef(rootNodeRef);
return null;
}
};
/**
* Run the above code as system - in particular resolves root node ref.
*/
AuthenticationUtil.runAs(runAsSystem, AuthenticationUtil.getSystemUserName());
// Check if locked files should be marked as offline
if (context.getOfflineFiles()) {
// Enable marking locked files as offline
isLockedFilesAsOffline = true;
logger.info("Locked files will be marked as offline");
}
// Enable file state caching
// context.enableStateCache(serverConfig, true);
// context.getStateCache().setCaseSensitive( false);
logger.debug("initialise the node monitor");
// Install the node service monitor
if (!context.getDisableNodeMonitor() && m_nodeMonitorFactory != null) {
NodeMonitor nodeMonitor = m_nodeMonitorFactory.createNodeMonitor(context);
context.setNodeMonitor(nodeMonitor);
}
logger.debug("initialise the file state lock manager");
if (context.getDisableOplocks() == true) {
logger.warn("Oplock support disabled for filesystem " + context.getDeviceName());
}
// Start the quota manager, if enabled
if (context.hasQuotaManager()) {
try {
// Start the quota manager
context.getQuotaManager().startManager(this, context);
logger.info("Quota manager enabled for filesystem");
} catch (QuotaManagerException ex) {
logger.error("Failed to start quota manager", ex);
}
}
}
use of org.alfresco.jlan.server.filesys.quota.QuotaManagerException in project alfresco-repository by Alfresco.
the class ContentDiskDriver method registerContext.
/**
* Registers a device context object for this instance
* of the shared device. The same DeviceInterface implementation may be used for multiple
* shares.
*
* WARNING: side effect, will commit or roll back current user transaction context.
*
* @param ctx the context
* @exception DeviceContextException
*/
// MER TODO - transaction handling in registerContext needs changing
@Override
public void registerContext(DeviceContext ctx) throws DeviceContextException {
super.registerContext(ctx);
ContentContext context = (ContentContext) ctx;
// Wrap the initialization in a transaction
UserTransaction tx = getTransactionService().getUserTransaction(true);
try {
// Use the system user as the authenticated context for the filesystem initialization
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
if (tx != null)
tx.begin();
// Get the store
String storeValue = context.getStoreName();
StoreRef storeRef = new StoreRef(storeValue);
if (!nodeService.exists(storeRef)) {
throw new DeviceContextException("Store not created prior to application startup: " + storeRef);
}
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
// Get the root path
String rootPath = context.getRootPath();
// Find the root node for this device
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, rootPath, null, namespaceService, false);
NodeRef rootNodeRef = null;
if (nodeRefs.size() > 1) {
throw new DeviceContextException("Multiple possible roots for device: \n" + " root path: " + rootPath + "\n" + " results: " + nodeRefs);
} else if (nodeRefs.size() == 0) {
throw new DeviceContextException("No root found for device: \n" + " root path: " + rootPath);
} else {
// We found a node
rootNodeRef = nodeRefs.get(0);
}
// Check if a relative path has been specified
String relPath = context.getRelativePath();
if (relPath != null && relPath.length() > 0) {
// Find the node and validate that the relative path is to a folder
NodeRef relPathNode = cifsHelper.getNodeRef(rootNodeRef, relPath);
if (cifsHelper.isDirectory(relPathNode) == false)
throw new DeviceContextException("Relative path is not a folder, " + relPath);
// Use the relative path node as the root of the filesystem
rootNodeRef = relPathNode;
} else {
if (cifsHelper.isDirectory(rootNodeRef) == false)
throw new DeviceContextException("Root node is not a folder type node");
}
// Commit the transaction
// MER 16/03/2010 - Why is this transaction management here?
tx.commit();
tx = null;
// Record the root node ref
context.setRootNodeRef(rootNodeRef);
} catch (Exception ex) {
logger.error("Error during create context", ex);
// MER BUGBUG Exception swallowed - will result in null pointer errors at best.
throw new DeviceContextException("unable to register context", ex);
// MER END
} finally {
// Restore authentication context
AuthenticationUtil.popAuthentication();
if (tx != null) {
try {
tx.rollback();
} catch (Exception ex) {
logger.warn("Failed to rollback transaction", ex);
}
}
}
// Check if locked files should be marked as offline
if (context.getOfflineFiles()) {
// Enable marking locked files as offline
isLockedFilesAsOffline = true;
// Logging
logger.info("Locked files will be marked as offline");
}
if (!context.getDisableNodeMonitor() && m_nodeMonitorFactory != null) {
// Create the node monitor
NodeMonitor nodeMonitor = m_nodeMonitorFactory.createNodeMonitor(context);
context.setNodeMonitor(nodeMonitor);
}
if (context.getDisableOplocks() == true)
logger.warn("Oplock support disabled for filesystem " + ctx.getDeviceName());
if (context.hasQuotaManager()) {
try {
// Start the quota manager
context.getQuotaManager().startManager(this, context);
logger.info("Quota manager enabled for filesystem");
} catch (QuotaManagerException ex) {
logger.error("Failed to start quota manager", ex);
}
}
}
use of org.alfresco.jlan.server.filesys.quota.QuotaManagerException in project alfresco-repository by Alfresco.
the class ContentQuotaManager method loadUsageDetails.
/**
* Load the user quota details
*
* @param userName - name of the user.
* @return UserQuotaDetails
* @throws QuotaManagerException
*/
private UserQuotaDetails loadUsageDetails(String userName) throws QuotaManagerException {
// Check if the user name is available
UserQuotaDetails quotaDetails = null;
try {
if (userName == null || userName.length() == 0) {
logger.debug("user name is null or empty - throw QuotaManagerException");
throw new QuotaManagerException("No user name for client");
}
// Get the usage quota and current usage values for the user
long userQuota = m_usageService.getUserQuota(userName);
long userUsage = m_usageService.getUserUsage(userName);
// Create the user quota details for live tracking
quotaDetails = new UserQuotaDetails(userName, userQuota);
if (userUsage > 0L) {
quotaDetails.setCurrentUsage(userUsage);
}
// Add the details to the live tracking table
// Check if another thread has added the details
UserQuotaDetails details = m_liveUsage.get(userName);
if (details != null) {
quotaDetails = details;
} else {
m_liveUsage.put(userName, quotaDetails);
}
if (logger.isDebugEnabled()) {
logger.debug("Added live usage tracking " + quotaDetails);
}
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to load usage for" + userName, ex);
}
throw new QuotaManagerException("Failed to load usage for " + userName + ", " + ex);
}
return quotaDetails;
}
Aggregations