Search in sources :

Example 1 with DeviceContextException

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);
        }
    }
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) DiskFullException(org.alfresco.jlan.server.filesys.DiskFullException) IOControlNotImplementedException(org.alfresco.jlan.server.filesys.IOControlNotImplementedException) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileNotFoundException(java.io.FileNotFoundException) QuotaManagerException(org.alfresco.jlan.server.filesys.quota.QuotaManagerException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) SMBException(org.alfresco.jlan.smb.SMBException) QuotaManagerException(org.alfresco.jlan.server.filesys.quota.QuotaManagerException)

Example 2 with DeviceContextException

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);
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) StoreRef(org.alfresco.service.cmr.repository.StoreRef) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DiskFullException(org.alfresco.jlan.server.filesys.DiskFullException) FileSharingException(org.alfresco.jlan.server.filesys.FileSharingException) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException) FileNotFoundException(java.io.FileNotFoundException) QuotaManagerException(org.alfresco.jlan.server.filesys.quota.QuotaManagerException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) DirectoryNotEmptyException(org.alfresco.jlan.server.filesys.DirectoryNotEmptyException) QuotaManagerException(org.alfresco.jlan.server.filesys.quota.QuotaManagerException)

Example 3 with DeviceContextException

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;
    }
}
Also used : DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) SMBException(org.alfresco.jlan.smb.SMBException) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) IOControlNotImplementedException(org.alfresco.jlan.server.filesys.IOControlNotImplementedException) IOException(java.io.IOException)

Example 4 with DeviceContextException

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;
}
Also used : DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) ConfigElement(org.springframework.extensions.config.ConfigElement)

Example 5 with DeviceContextException

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
}
Also used : AccessControlList(org.alfresco.jlan.server.auth.acl.AccessControlList) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) SecurityConfigSection(org.alfresco.jlan.server.config.SecurityConfigSection) GenericConfigElement(org.springframework.extensions.config.element.GenericConfigElement) ExtendedDiskInterface(org.alfresco.filesys.alfresco.ExtendedDiskInterface) StandaloneFileStateCache(org.alfresco.jlan.server.filesys.cache.StandaloneFileStateCache) AccessControlListBean(org.alfresco.filesys.config.acl.AccessControlListBean) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException) FilesystemsConfigSection(org.alfresco.jlan.server.filesys.FilesystemsConfigSection) DeviceContext(org.alfresco.jlan.server.core.DeviceContext) FileStateLockManager(org.alfresco.jlan.server.filesys.cache.FileStateLockManager) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ContentContext(org.alfresco.filesys.repo.ContentContext) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Aggregations

DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)5 IOException (java.io.IOException)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 FileNotFoundException (java.io.FileNotFoundException)2 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)2 DirectoryNotEmptyException (org.alfresco.jlan.server.filesys.DirectoryNotEmptyException)2 DiskFullException (org.alfresco.jlan.server.filesys.DiskFullException)2 IOControlNotImplementedException (org.alfresco.jlan.server.filesys.IOControlNotImplementedException)2 QuotaManagerException (org.alfresco.jlan.server.filesys.quota.QuotaManagerException)2 SMBException (org.alfresco.jlan.smb.SMBException)2 NodeLockedException (org.alfresco.service.cmr.lock.NodeLockedException)2 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 StoreRef (org.alfresco.service.cmr.repository.StoreRef)2 UserTransaction (javax.transaction.UserTransaction)1 ExtendedDiskInterface (org.alfresco.filesys.alfresco.ExtendedDiskInterface)1 AccessControlListBean (org.alfresco.filesys.config.acl.AccessControlListBean)1 ContentContext (org.alfresco.filesys.repo.ContentContext)1 AccessControlList (org.alfresco.jlan.server.auth.acl.AccessControlList)1 InvalidConfigurationException (org.alfresco.jlan.server.config.InvalidConfigurationException)1