use of org.alfresco.jlan.server.core.DeviceContextException 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.core.DeviceContextException 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.core.DeviceContextException in project alfresco-repository by Alfresco.
the class FilesystemTransactionAdvice method invoke.
public Object invoke(final MethodInvocation methodInvocation) throws IOException, SMBException, Throwable {
RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
RetryingTransactionCallback<Object> callback = new RetryingTransactionHelper.RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
try {
return methodInvocation.proceed();
} catch (SMBException e) {
throw new PropagatingException(e);
} catch (IOControlNotImplementedException e) {
throw new PropagatingException(e);
} catch (IOException e) {
// Ensure original checked IOExceptions get propagated
throw new PropagatingException(e);
} catch (DeviceContextException e) {
throw new PropagatingException(e);
}
}
};
try {
return tran.doInTransaction(callback, readOnly);
} catch (PropagatingException pe) {
Throwable t = pe.getCause();
if (t != null) {
if (t instanceof IOException) {
throw (IOException) t;
}
if (t instanceof IOControlNotImplementedException) {
throw (IOControlNotImplementedException) t;
}
if (t instanceof SMBException) {
throw (SMBException) t;
}
if (t instanceof DeviceContextException) {
throw t;
}
throw t;
}
throw pe;
}
}
use of org.alfresco.jlan.server.core.DeviceContextException in project alfresco-repository by Alfresco.
the class ContentDiskDriver method createContext.
/**
* Parse and validate the parameter string and create a device context object for this instance
* of the shared device. The same DeviceInterface implementation may be used for multiple
* shares.
* <p>
* WARNING: side effect, may commit or roll back current user transaction context.
*
* @param deviceName The name of the device
* @param cfg ConfigElement the configuration of the device context.
* @return DeviceContext
* @exception DeviceContextException
*/
// MER TODO - transaction handling in registerContext needs changing
public DeviceContext createContext(String deviceName, ConfigElement cfg) throws DeviceContextException {
ContentContext context = null;
try {
// Get the store
ConfigElement storeElement = cfg.getChild(KEY_STORE);
if (storeElement == null || storeElement.getValue() == null || storeElement.getValue().length() == 0) {
throw new DeviceContextException("Device missing init value: " + KEY_STORE);
}
String storeValue = storeElement.getValue();
// Get the root path
ConfigElement rootPathElement = cfg.getChild(KEY_ROOT_PATH);
if (rootPathElement == null || rootPathElement.getValue() == null || rootPathElement.getValue().length() == 0) {
throw new DeviceContextException("Device missing init value: " + KEY_ROOT_PATH);
}
String rootPath = rootPathElement.getValue();
// Create the context
context = new ContentContext();
context.setDeviceName(deviceName);
context.setStoreName(storeValue);
context.setRootPath(rootPath);
context.setSysAdminParams(this.sysAdminParams);
// Check if a relative path has been specified
ConfigElement relativePathElement = cfg.getChild(KEY_RELATIVE_PATH);
if (relativePathElement != null) {
// Make sure the path is in CIFS format
String relPath = relativePathElement.getValue().replace('/', FileName.DOS_SEPERATOR);
context.setRelativePath(relPath);
}
}/*
* MER - I changed the code below - resulted in a NPE anyway
* lower down
*/
catch (DeviceContextException ex) {
logger.error("Error during create context", ex);
throw ex;
}
// Check if URL link files are enabled
ConfigElement urlFileElem = cfg.getChild("urlFile");
if (urlFileElem != null) {
// Get the pseudo file name and web prefix path
ConfigElement pseudoName = urlFileElem.getChild("filename");
if (pseudoName != null) {
context.setURLFileName(pseudoName.getValue());
}
}
// Check if locked files should be marked as offline
ConfigElement offlineFiles = cfg.getChild("offlineFiles");
if (offlineFiles != null) {
context.setOfflineFiles(true);
}
if (cfg.getChild("disableNodeMonitor") == null) {
// Create the node monitor
context.setDisableNodeMonitor(true);
}
if (cfg.getChild("disableOplocks") != null) {
context.setDisableOplocks(true);
}
// Register the device context
registerContext(context);
return context;
}
use of org.alfresco.jlan.server.core.DeviceContextException in project alfresco-repository by Alfresco.
the class ServerConfigurationBean method processFilesystemsConfig.
/**
* Process the filesystems configuration
*/
protected void processFilesystemsConfig() {
// Create the filesystems configuration section
FilesystemsConfigSection fsysConfig = new FilesystemsConfigSection(this);
// Access the security configuration section
SecurityConfigSection secConfig = (SecurityConfigSection) getConfigSection(SecurityConfigSection.SectionName);
if (this.filesystemContexts != null) {
for (DeviceContext filesystem : this.filesystemContexts) {
try {
// Check the filesystem type and use the appropriate driver
DiskSharedDevice filesys = null;
// Create a new filesystem driver instance and register a context for
// the new filesystem
ExtendedDiskInterface filesysDriver = getRepoDiskInterface();
ContentContext filesysContext = (ContentContext) filesystem;
// Create state cache here and inject
StandaloneFileStateCache standaloneCache = new StandaloneFileStateCache();
standaloneCache.initializeCache(new GenericConfigElement(""), this);
filesysContext.setStateCache(standaloneCache);
if (filesysContext.hasStateCache()) {
// Register the state cache with the reaper thread
// has many side effects including initialisation of the cache
fsysConfig.addFileStateCache(filesystem.getDeviceName(), filesysContext.getStateCache());
// Create the lock manager for the context.
FileStateLockManager lockMgr = new FileStateLockManager(filesysContext.getStateCache());
filesysContext.setLockManager(lockMgr);
filesysContext.setOpLockManager(lockMgr);
}
if (!ftpConfigBean.getServerEnabled() && isContentDiskDriver2(filesysDriver)) {
((ContentContext) filesystem).setDisableNodeMonitor(true);
}
filesysDriver.registerContext(filesystem);
// Check if an access control list has been specified
AccessControlList acls = null;
AccessControlListBean accessControls = filesysContext.getAccessControlList();
if (accessControls != null) {
// Parse the access control list
acls = accessControls.toAccessControlList(secConfig);
} else if (secConfig.hasGlobalAccessControls()) {
// Use the global access control list for this disk share
acls = secConfig.getGlobalAccessControls();
}
// Create the shared filesystem
filesys = new DiskSharedDevice(filesystem.getDeviceName(), filesysDriver, filesysContext);
filesys.setConfiguration(this);
// Add any access controls to the share
filesys.setAccessControlList(acls);
if (filesysContext.getDisableChangeNotifications() == false)
filesysContext.enableChangeHandler(true);
// Start the filesystem
filesysContext.startFilesystem(filesys);
// Add the new filesystem
fsysConfig.addShare(filesys);
} catch (DeviceContextException ex) {
throw new AlfrescoRuntimeException("Error creating filesystem " + filesystem.getDeviceName(), ex);
} catch (InvalidConfigurationException ex) {
throw new AlfrescoRuntimeException(ex.getMessage(), ex);
}
}
} else {
// No filesystems defined
logger.warn("No filesystems defined");
}
// home folder share mapper could be declared in security config
}
Aggregations