Search in sources :

Example 1 with GetNodesParameters

use of org.alfresco.solr.client.GetNodesParameters in project SearchServices by Alfresco.

the class MetadataTracker method indexTransactions.

private void indexTransactions() throws IOException, AuthenticationException, JSONException {
    long startElapsed = System.nanoTime();
    int docCount = 0;
    boolean requiresCommit = false;
    while (transactionsToIndex.peek() != null) {
        Long transactionId = transactionsToIndex.poll();
        if (transactionId != null) {
            Transactions transactions = client.getTransactions(null, transactionId, null, transactionId + 1, 1);
            if ((transactions.getTransactions().size() > 0) && (transactionId.equals(transactions.getTransactions().get(0).getId()))) {
                Transaction info = transactions.getTransactions().get(0);
                GetNodesParameters gnp = new GetNodesParameters();
                ArrayList<Long> txs = new ArrayList<Long>();
                txs.add(info.getId());
                gnp.setTransactionIds(txs);
                gnp.setStoreProtocol(storeRef.getProtocol());
                gnp.setStoreIdentifier(storeRef.getIdentifier());
                gnp.setShardProperty(shardProperty);
                List<Node> nodes = client.getNodes(gnp, (int) info.getUpdates());
                for (Node node : nodes) {
                    docCount++;
                    if (log.isDebugEnabled()) {
                        log.debug(node.toString());
                    }
                    this.infoSrv.indexNode(node, false);
                    checkShutdown();
                }
                // Index the transaction doc after the node - if this is not found then a reindex will be done.
                this.infoSrv.indexTransaction(info, false);
                requiresCommit = true;
                trackerStats.addTxDocs(nodes.size());
            }
        }
        if (docCount > batchCount) {
            if (this.infoSrv.getRegisteredSearcherCount() < getMaxLiveSearchers()) {
                checkShutdown();
                // this.infoSrv.commit();
                long endElapsed = System.nanoTime();
                trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
                startElapsed = endElapsed;
                docCount = 0;
                requiresCommit = false;
            }
        }
    }
    if (requiresCommit || (docCount > 0)) {
        checkShutdown();
        // this.infoSrv.commit();
        long endElapsed = System.nanoTime();
        trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
    }
}
Also used : Transactions(org.alfresco.solr.client.Transactions) Transaction(org.alfresco.solr.client.Transaction) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) ArrayList(java.util.ArrayList)

Example 2 with GetNodesParameters

use of org.alfresco.solr.client.GetNodesParameters in project SearchServices by Alfresco.

the class AclTracker method getFullNodesForDbTransaction.

public List<Node> getFullNodesForDbTransaction(Long txid) {
    try {
        GetNodesParameters gnp = new GetNodesParameters();
        ArrayList<Long> txs = new ArrayList<Long>();
        txs.add(txid);
        gnp.setTransactionIds(txs);
        gnp.setStoreProtocol(storeRef.getProtocol());
        gnp.setStoreIdentifier(storeRef.getIdentifier());
        return client.getNodes(gnp, Integer.MAX_VALUE);
    } catch (IOException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    } catch (JSONException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    } catch (AuthenticationException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    }
}
Also used : AuthenticationException(org.alfresco.httpclient.AuthenticationException) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 3 with GetNodesParameters

use of org.alfresco.solr.client.GetNodesParameters in project SearchServices by Alfresco.

the class MetadataTracker method getFullNodesForDbTransaction.

public List<Node> getFullNodesForDbTransaction(Long txid) {
    try {
        GetNodesParameters gnp = new GetNodesParameters();
        ArrayList<Long> txs = new ArrayList<Long>();
        txs.add(txid);
        gnp.setTransactionIds(txs);
        gnp.setStoreProtocol(storeRef.getProtocol());
        gnp.setStoreIdentifier(storeRef.getIdentifier());
        return client.getNodes(gnp, Integer.MAX_VALUE);
    } catch (IOException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    } catch (JSONException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    } catch (AuthenticationException e) {
        throw new AlfrescoRuntimeException("Failed to get nodes", e);
    }
}
Also used : AuthenticationException(org.alfresco.httpclient.AuthenticationException) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 4 with GetNodesParameters

use of org.alfresco.solr.client.GetNodesParameters in project SearchServices by Alfresco.

the class MetadataTracker method reindexTransactions.

private void reindexTransactions() throws IOException, AuthenticationException, JSONException {
    long startElapsed = System.nanoTime();
    int docCount = 0;
    while (transactionsToReindex.peek() != null) {
        Long transactionId = transactionsToReindex.poll();
        if (transactionId != null) {
            // make sure it is cleaned out so we do not miss deletes
            this.infoSrv.deleteByTransactionId(transactionId);
            Transactions transactions = client.getTransactions(null, transactionId, null, transactionId + 1, 1);
            if ((transactions.getTransactions().size() > 0) && (transactionId.equals(transactions.getTransactions().get(0).getId()))) {
                Transaction info = transactions.getTransactions().get(0);
                this.infoSrv.dirtyTransaction(info.getId());
                GetNodesParameters gnp = new GetNodesParameters();
                ArrayList<Long> txs = new ArrayList<Long>();
                txs.add(info.getId());
                gnp.setTransactionIds(txs);
                gnp.setStoreProtocol(storeRef.getProtocol());
                gnp.setStoreIdentifier(storeRef.getIdentifier());
                List<Node> nodes = client.getNodes(gnp, (int) info.getUpdates());
                for (Node node : nodes) {
                    docCount++;
                    if (log.isDebugEnabled()) {
                        log.debug(node.toString());
                    }
                    this.infoSrv.indexNode(node, true);
                    checkShutdown();
                }
                // Index the transaction doc after the node - if this is not found then a reindex will be done.
                this.infoSrv.indexTransaction(info, true);
            }
        }
        if (docCount > batchCount) {
            if (this.infoSrv.getRegisteredSearcherCount() < getMaxLiveSearchers()) {
                checkShutdown();
                long endElapsed = System.nanoTime();
                trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
                startElapsed = endElapsed;
                docCount = 0;
            }
        }
    }
    if (docCount > 0) {
        checkShutdown();
        // this.infoSrv.commit();
        long endElapsed = System.nanoTime();
        trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
    }
}
Also used : Transactions(org.alfresco.solr.client.Transactions) Transaction(org.alfresco.solr.client.Transaction) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) ArrayList(java.util.ArrayList)

Example 5 with GetNodesParameters

use of org.alfresco.solr.client.GetNodesParameters in project SearchServices by Alfresco.

the class MetadataTracker method checkNode.

public NodeReport checkNode(Long dbid) {
    NodeReport nodeReport = new NodeReport();
    nodeReport.setDbid(dbid);
    // In DB
    GetNodesParameters parameters = new GetNodesParameters();
    parameters.setFromNodeId(dbid);
    parameters.setToNodeId(dbid);
    List<Node> dbnodes;
    try {
        dbnodes = client.getNodes(parameters, 1);
        if (dbnodes.size() == 1) {
            Node dbnode = dbnodes.get(0);
            nodeReport.setDbNodeStatus(dbnode.getStatus());
            nodeReport.setDbTx(dbnode.getTxnId());
        } else {
            nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
            nodeReport.setDbTx(-1l);
        }
    } catch (IOException e) {
        nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
        nodeReport.setDbTx(-2l);
    } catch (JSONException e) {
        nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
        nodeReport.setDbTx(-3l);
    } catch (AuthenticationException e1) {
        nodeReport.setDbNodeStatus(SolrApiNodeStatus.UNKNOWN);
        nodeReport.setDbTx(-4l);
    }
    this.infoSrv.addCommonNodeReportInfo(nodeReport);
    return nodeReport;
}
Also used : AuthenticationException(org.alfresco.httpclient.AuthenticationException) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) JSONException(org.json.JSONException) IOException(java.io.IOException) NodeReport(org.alfresco.solr.NodeReport)

Aggregations

GetNodesParameters (org.alfresco.solr.client.GetNodesParameters)6 ArrayList (java.util.ArrayList)5 Node (org.alfresco.solr.client.Node)4 IOException (java.io.IOException)3 AuthenticationException (org.alfresco.httpclient.AuthenticationException)3 Transaction (org.alfresco.solr.client.Transaction)3 JSONException (org.json.JSONException)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 Transactions (org.alfresco.solr.client.Transactions)2 NodeReport (org.alfresco.solr.NodeReport)1