/*
* Copyright (C) 2006 Alfresco, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.admin;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.repo.node.index.FullIndexRecoveryComponent.RecoveryMode;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.InvalidStoreRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.AbstractLifecycleBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
/**
* Component to perform a bootstrap check of the alignment of the
* database, Lucene indexes and content store.
*
* The algorithm is:
*
*
Get all stores from the NodeService
*
Get each root node
*
Perform a Lucene query for each root node
*
Query Lucene for a small set of content nodes
*
Get content readers for each node
*
* If any of the steps fail then the bootstrap bean will fail, except if
* the indexes are marked for full recovery. In this case, the Lucene
* checks are not required as the indexes will be due for a rebuild.
*
* @author Derek Hulley
*/
public class ConfigurationChecker extends AbstractLifecycleBean
{
private static Log logger = LogFactory.getLog(ConfigurationChecker.class);
private static final String WARN_RELATIVE_DIR_ROOT = "system.config_check.warn.dir_root";
private static final String MSG_DIR_ROOT = "system.config_check.msg.dir_root";
private static final String ERR_DUPLICATE_ROOT_NODE = "system.config_check.err.indexes.duplicate_root_node";
private static final String ERR_MISSING_INDEXES = "system.config_check.err.missing_index";
private static final String ERR_MISSING_CONTENT = "system.config_check.err.missing_content";
private static final String ERR_FIX_DIR_ROOT = "system.config_check.err.fix_dir_root";
private static final String MSG_HOWTO_INDEX_RECOVER = "system.config_check.msg.howto_index_recover";
private static final String WARN_STARTING_WITH_ERRORS = "system.config_check.warn.starting_with_errors";
private boolean strict;
private RecoveryMode indexRecoveryMode;
private String dirRoot;
private ImporterBootstrap systemBootstrap;
private TransactionService transactionService;
private NamespaceService namespaceService;
private NodeService nodeService;
private SearchService searchService;
private ContentService contentService;
public ConfigurationChecker()
{
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(50);
sb.append("ConfigurationChecker")
.append("[indexRecoveryMode=").append(indexRecoveryMode)
.append("]");
return sb.toString();
}
/**
* This flag controls the behaviour of the component in the event of problems being found.
* Generally, the system should be strict, but this can be changed if indexes are
* going to be recovered, or if missing content is acceptable.
*
* @param strict true to prevent system startup if problems are found, otherwise
* false to allow the system to startup regardless.
*/
public void setStrict(boolean strict)
{
this.strict = strict;
}
/**
* Set the index recovery mode. If this is
* {@link org.alfresco.repo.node.index.FullIndexRecoveryComponent.RecoveryMode#VALIDATE FULL}
* then the index checks are ignored as the indexes will be scheduled for a rebuild
* anyway.
*
* @see org.alfresco.repo.node.index.FullIndexRecoveryComponent.RecoveryMode
*/
public void setIndexRecoveryMode(String indexRecoveryMode)
{
this.indexRecoveryMode = RecoveryMode.valueOf(indexRecoveryMode);
}
public void setDirRoot(String dirRoot)
{
this.dirRoot = dirRoot;
}
public void setSystemBootstrap(ImporterBootstrap systemBootstrap)
{
this.systemBootstrap = systemBootstrap;
}
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
@Override
protected void onBootstrap(ApplicationEvent event)
{
TransactionWork