Search in sources :

Example 1 with Tracker

use of org.alfresco.solr.tracker.Tracker in project SearchServices by Alfresco.

the class SolrCoreLoadRegistration method createTrackers.

/**
 * Creates the trackers
 *
 * @param coreName
 * @param trackerRegistry
 * @param props
 * @param scheduler
 * @param repositoryClient
 * @param srv
 * @return A list of trackers
 */
private static List<Tracker> createTrackers(String coreName, TrackerRegistry trackerRegistry, Properties props, SolrTrackerScheduler scheduler, SOLRAPIClient repositoryClient, SolrInformationServer srv) {
    List<Tracker> trackers = new ArrayList<Tracker>();
    AclTracker aclTracker = new AclTracker(props, repositoryClient, coreName, srv);
    trackerRegistry.register(coreName, aclTracker);
    scheduler.schedule(aclTracker, coreName, props);
    ContentTracker contentTrkr = new ContentTracker(props, repositoryClient, coreName, srv);
    trackerRegistry.register(coreName, contentTrkr);
    scheduler.schedule(contentTrkr, coreName, props);
    MetadataTracker metaTrkr = new MetadataTracker(props, repositoryClient, coreName, srv);
    trackerRegistry.register(coreName, metaTrkr);
    scheduler.schedule(metaTrkr, coreName, props);
    CascadeTracker cascadeTrkr = new CascadeTracker(props, repositoryClient, coreName, srv);
    trackerRegistry.register(coreName, cascadeTrkr);
    scheduler.schedule(cascadeTrkr, coreName, props);
    // The CommitTracker will acquire these locks in order
    // The ContentTracker will likely have the longest runs so put it first to ensure the MetadataTracker is not paused while
    // waiting for the ContentTracker to release it's lock.
    // The aclTracker will likely have the shortest runs so put it last.
    trackers.add(cascadeTrkr);
    trackers.add(contentTrkr);
    trackers.add(metaTrkr);
    trackers.add(aclTracker);
    return trackers;
}
Also used : ContentTracker(org.alfresco.solr.tracker.ContentTracker) Tracker(org.alfresco.solr.tracker.Tracker) MetadataTracker(org.alfresco.solr.tracker.MetadataTracker) CommitTracker(org.alfresco.solr.tracker.CommitTracker) CascadeTracker(org.alfresco.solr.tracker.CascadeTracker) AclTracker(org.alfresco.solr.tracker.AclTracker) ModelTracker(org.alfresco.solr.tracker.ModelTracker) ArrayList(java.util.ArrayList) AclTracker(org.alfresco.solr.tracker.AclTracker) ContentTracker(org.alfresco.solr.tracker.ContentTracker) CascadeTracker(org.alfresco.solr.tracker.CascadeTracker) MetadataTracker(org.alfresco.solr.tracker.MetadataTracker)

Example 2 with Tracker

use of org.alfresco.solr.tracker.Tracker in project SearchServices by Alfresco.

the class SolrCoreLoadRegistration method registerForCore.

/**
 * Registers with the admin handler the information server and the trackers.
 */
public static void registerForCore(AlfrescoCoreAdminHandler adminHandler, CoreContainer coreContainer, SolrCore core, String coreName) {
    TrackerRegistry trackerRegistry = adminHandler.getTrackerRegistry();
    Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getProperties();
    if (Boolean.parseBoolean(props.getProperty("enable.alfresco.tracking", "false"))) {
        SolrTrackerScheduler scheduler = adminHandler.getScheduler();
        SolrResourceLoader loader = core.getLatestSchema().getResourceLoader();
        SolrKeyResourceLoader keyResourceLoader = new SolrKeyResourceLoader(loader);
        if (trackerRegistry.hasTrackersForCore(coreName)) {
            log.info("Trackers for " + coreName + " is already registered, shutting them down.");
            shutdownTrackers(coreName, trackerRegistry.getTrackersForCore(coreName), scheduler);
            trackerRegistry.removeTrackersForCore(coreName);
            adminHandler.getInformationServers().remove(coreName);
        }
        SOLRAPIClientFactory clientFactory = new SOLRAPIClientFactory();
        SOLRAPIClient repositoryClient = clientFactory.getSOLRAPIClient(props, keyResourceLoader, AlfrescoSolrDataModel.getInstance().getDictionaryService(CMISStrictDictionaryService.DEFAULT), AlfrescoSolrDataModel.getInstance().getNamespaceDAO());
        // Start content store
        SolrContentStore contentStore = new SolrContentStore(coreContainer.getSolrHome());
        SolrInformationServer srv = new SolrInformationServer(adminHandler, core, repositoryClient, contentStore);
        props.putAll(srv.getProps());
        adminHandler.getInformationServers().put(coreName, srv);
        log.info("Starting to track " + coreName);
        ModelTracker mTracker = null;
        // Prevents other threads from registering the ModelTracker at the same time
        synchronized (trackerRegistry) {
            mTracker = trackerRegistry.getModelTracker();
            if (mTracker == null) {
                log.debug("Creating ModelTracker when registering trackers for core " + coreName);
                mTracker = new ModelTracker(coreContainer.getSolrHome(), props, repositoryClient, coreName, srv);
                trackerRegistry.setModelTracker(mTracker);
                log.info("Ensuring first model sync.");
                mTracker.ensureFirstModelSync();
                log.info("Done ensuring first model sync.");
                // Scheduling the ModelTracker.
                scheduler.schedule(mTracker, coreName, props);
            }
        }
        List<Tracker> trackers = createTrackers(coreName, trackerRegistry, props, scheduler, repositoryClient, srv);
        CommitTracker commitTracker = new CommitTracker(props, repositoryClient, coreName, srv, trackers);
        trackerRegistry.register(coreName, commitTracker);
        scheduler.schedule(commitTracker, coreName, props);
        log.info("The Trackers are now scheduled to run");
        // Add the commitTracker to the list of scheduled trackers that can be shutdown
        trackers.add(commitTracker);
        core.addCloseHook(new CloseHook() {

            @Override
            public void preClose(SolrCore core) {
                log.info("Shutting down " + core.getName());
                SolrCoreLoadRegistration.shutdownTrackers(core.getName(), trackers, scheduler);
            }

            @Override
            public void postClose(SolrCore core) {
            }
        });
    }
}
Also used : ContentTracker(org.alfresco.solr.tracker.ContentTracker) Tracker(org.alfresco.solr.tracker.Tracker) MetadataTracker(org.alfresco.solr.tracker.MetadataTracker) CommitTracker(org.alfresco.solr.tracker.CommitTracker) CascadeTracker(org.alfresco.solr.tracker.CascadeTracker) AclTracker(org.alfresco.solr.tracker.AclTracker) ModelTracker(org.alfresco.solr.tracker.ModelTracker) SolrContentStore(org.alfresco.solr.content.SolrContentStore) SolrCore(org.apache.solr.core.SolrCore) CommitTracker(org.alfresco.solr.tracker.CommitTracker) Properties(java.util.Properties) TrackerRegistry(org.alfresco.solr.tracker.TrackerRegistry) SolrInformationServer(org.alfresco.solr.SolrInformationServer) ModelTracker(org.alfresco.solr.tracker.ModelTracker) CoreDescriptorDecorator(org.apache.solr.core.CoreDescriptorDecorator) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CloseHook(org.apache.solr.core.CloseHook) SOLRAPIClientFactory(org.alfresco.solr.client.SOLRAPIClientFactory) SOLRAPIClient(org.alfresco.solr.client.SOLRAPIClient) SolrTrackerScheduler(org.alfresco.solr.tracker.SolrTrackerScheduler) SolrKeyResourceLoader(org.alfresco.solr.SolrKeyResourceLoader)

Example 3 with Tracker

use of org.alfresco.solr.tracker.Tracker in project SearchServices by Alfresco.

the class AlfrescoSolrReloadTest method testReload.

@Test
public void testReload() throws Exception {
    long localId = 0L;
    logger.info("######### Starting tracker reload test NODES ###########");
    AclChangeSet aclChangeSet = getAclChangeSet(1, ++localId);
    Acl acl = getAcl(aclChangeSet);
    AclReaders aclReaders = getAclReaders(aclChangeSet, acl, list("joel"), list("phil"), null);
    indexAclChangeSet(aclChangeSet, list(acl), list(aclReaders));
    int numNodes = 1000;
    List<Node> nodes = new ArrayList();
    List<NodeMetaData> nodeMetaDatas = new ArrayList();
    Transaction bigTxn = getTransaction(0, numNodes, ++localId);
    for (int i = 0; i < numNodes; i++) {
        Node node = getNode(bigTxn, acl, Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn, acl, "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 1000, 100000);
    Collection<Tracker> trackers = getTrackers();
    int numOfTrackers = trackers.size();
    int jobs = getJobsCount();
    reloadAndAssertCorrect(trackers, numOfTrackers, jobs);
    Transaction bigTxn2 = getTransaction(0, numNodes, ++localId);
    for (int i = 0; i < numNodes; i++) {
        Node node = getNode(bigTxn2, acl, Node.SolrApiNodeStatus.UPDATED);
        nodes.add(node);
        NodeMetaData nodeMetaData = getNodeMetaData(node, bigTxn2, acl, "mike", null, false);
        nodeMetaDatas.add(nodeMetaData);
    }
    indexTransaction(bigTxn2, nodes, nodeMetaDatas);
    waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 2000, 100000);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Tracker(org.alfresco.solr.tracker.Tracker) NodeMetaData(org.alfresco.solr.client.NodeMetaData) AlfrescoSolrUtils.getNodeMetaData(org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData) Node(org.alfresco.solr.client.Node) AlfrescoSolrUtils.getNode(org.alfresco.solr.AlfrescoSolrUtils.getNode) ArrayList(java.util.ArrayList) Acl(org.alfresco.solr.client.Acl) AlfrescoSolrUtils.getAcl(org.alfresco.solr.AlfrescoSolrUtils.getAcl) Term(org.apache.lucene.index.Term) Transaction(org.alfresco.solr.client.Transaction) AlfrescoSolrUtils.getTransaction(org.alfresco.solr.AlfrescoSolrUtils.getTransaction) AlfrescoSolrUtils.getAclChangeSet(org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet) AlfrescoSolrUtils.indexAclChangeSet(org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet) AclChangeSet(org.alfresco.solr.client.AclChangeSet) AlfrescoSolrUtils.getAclReaders(org.alfresco.solr.AlfrescoSolrUtils.getAclReaders) AclReaders(org.alfresco.solr.client.AclReaders) Test(org.junit.Test)

Aggregations

Tracker (org.alfresco.solr.tracker.Tracker)3 ArrayList (java.util.ArrayList)2 AclTracker (org.alfresco.solr.tracker.AclTracker)2 CascadeTracker (org.alfresco.solr.tracker.CascadeTracker)2 CommitTracker (org.alfresco.solr.tracker.CommitTracker)2 ContentTracker (org.alfresco.solr.tracker.ContentTracker)2 MetadataTracker (org.alfresco.solr.tracker.MetadataTracker)2 ModelTracker (org.alfresco.solr.tracker.ModelTracker)2 Properties (java.util.Properties)1 AlfrescoSolrUtils.getAcl (org.alfresco.solr.AlfrescoSolrUtils.getAcl)1 AlfrescoSolrUtils.getAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet)1 AlfrescoSolrUtils.getAclReaders (org.alfresco.solr.AlfrescoSolrUtils.getAclReaders)1 AlfrescoSolrUtils.getNode (org.alfresco.solr.AlfrescoSolrUtils.getNode)1 AlfrescoSolrUtils.getNodeMetaData (org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData)1 AlfrescoSolrUtils.getTransaction (org.alfresco.solr.AlfrescoSolrUtils.getTransaction)1 AlfrescoSolrUtils.indexAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet)1 SolrInformationServer (org.alfresco.solr.SolrInformationServer)1 SolrKeyResourceLoader (org.alfresco.solr.SolrKeyResourceLoader)1 Acl (org.alfresco.solr.client.Acl)1 AclChangeSet (org.alfresco.solr.client.AclChangeSet)1