Search in sources :

Example 1 with QueueAttr

use of com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr in project zm-mailbox by Zimbra.

the class GetMailQueue method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Element serverElem = request.getElement(AdminConstants.E_SERVER);
    String serverName = serverElem.getAttribute(AdminConstants.A_NAME);
    Server server = prov.get(Key.ServerBy.name, serverName);
    if (server == null) {
        throw ServiceException.INVALID_REQUEST("server with name " + serverName + " could not be found", null);
    }
    checkRight(zsc, context, server, Admin.R_manageMailQueue);
    Element queueElem = serverElem.getElement(AdminConstants.E_QUEUE);
    String queueName = queueElem.getAttribute(AdminConstants.A_NAME);
    boolean scan = queueElem.getAttributeBool(AdminConstants.A_SCAN, false);
    long waitMillis = (queueElem.getAttributeLong(AdminConstants.A_WAIT, MAIL_QUEUE_SCAN_DEFUALT_WAIT_SECONDS)) * 1000;
    Element queryElem = queueElem.getElement(AdminConstants.E_QUERY);
    int offset = (int) queryElem.getAttributeLong(AdminConstants.A_OFFSET, 0);
    int limit = (int) queryElem.getAttributeLong(AdminConstants.A_LIMIT, MAIL_QUEUE_QUERY_DEFAULT_LIMIT);
    Query query = buildLuceneQuery(queryElem);
    RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, queueName, scan);
    boolean stillScanning = rmq.waitForScan(waitMillis);
    RemoteMailQueue.SearchResult sr = rmq.search(query, offset, limit);
    Element response = zsc.createElement(AdminConstants.GET_MAIL_QUEUE_RESPONSE);
    serverElem = response.addElement(AdminConstants.E_SERVER);
    serverElem.addAttribute(AdminConstants.A_NAME, serverName);
    queueElem = serverElem.addElement(AdminConstants.E_QUEUE);
    queueElem.addAttribute(AdminConstants.A_NAME, queueName);
    queueElem.addAttribute(AdminConstants.A_TIME, rmq.getScanTime());
    queueElem.addAttribute(AdminConstants.A_SCAN, stillScanning);
    queueElem.addAttribute(AdminConstants.A_TOTAL, rmq.getNumMessages());
    queueElem.addAttribute(AdminConstants.A_MORE, ((offset + limit) < sr.hits));
    for (QueueAttr attr : sr.sitems.keySet()) {
        List<SummaryItem> slist = sr.sitems.get(attr);
        Collections.sort(slist);
        Element qsElem = queueElem.addElement(AdminConstants.A_QUEUE_SUMMARY);
        qsElem.addAttribute(AdminConstants.A_TYPE, attr.toString());
        int i = 0;
        for (SummaryItem sitem : slist) {
            i++;
            if (i > MAIL_QUEUE_SUMMARY_CUTOFF) {
                break;
            }
            Element qsiElem = qsElem.addElement(AdminConstants.A_QUEUE_SUMMARY_ITEM);
            qsiElem.addAttribute(AdminConstants.A_N, sitem.count());
            qsiElem.addAttribute(AdminConstants.A_T, sitem.term());
        }
    }
    for (Map<QueueAttr, String> qitem : sr.qitems) {
        Element qiElem = queueElem.addElement(AdminConstants.A_QUEUE_ITEM);
        for (QueueAttr attr : qitem.keySet()) {
            qiElem.addAttribute(attr.toString(), qitem.get(attr));
        }
    }
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) SummaryItem(com.zimbra.cs.rmgmt.RemoteMailQueue.SummaryItem) RemoteMailQueue(com.zimbra.cs.rmgmt.RemoteMailQueue) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) QueueAttr(com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr)

Example 2 with QueueAttr

use of com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr in project zm-mailbox by Zimbra.

the class TestUtil method postfixFlushDeferredMailQueue.

/**
 * @return true if likely to have had things delayed in the deferred queue
 */
private static boolean postfixFlushDeferredMailQueue(Server server, long waitMillis) {
    long start = System.currentTimeMillis();
    try {
        if (null == server) {
            server = Provisioning.getInstance().getLocalServer();
        }
        RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, "deferred", true);
        boolean stillScanning = rmq.waitForScan(waitMillis);
        if (stillScanning) {
            ZimbraLog.test.info("postfixFlushDeferredMailQueue - taking too long to scan queue.");
            return true;
        }
        RemoteMailQueue.SearchResult sr = rmq.search(null, 0, Integer.MAX_VALUE);
        if (sr.qitems.size() == 0) {
            ZimbraLog.test.info("postfixFlushDeferredMailQueue - deferred queue was empty.");
            return false;
        }
        String[] ids = new String[sr.qitems.size()];
        int i = 0;
        StringBuilder qinfo = new StringBuilder();
        for (Map<QueueAttr, String> qitem : sr.qitems) {
            qinfo.append("\nDEFERRED_POSTFIX_QUEUE_ENTRY:");
            ids[i++] = qitem.get(QueueAttr.id);
            for (QueueAttr qattr : QueueAttr.values()) {
                String val = qitem.get(qattr);
                if (!Strings.isNullOrEmpty(val)) {
                    qinfo.append(" ").append(qattr.name()).append("=").append(val);
                }
            }
        }
        ZimbraLog.test.info("postfixFlushDeferredMailQueue - deferred queue:%s", qinfo);
        rmq.action(server, RemoteMailQueue.QueueAction.requeue, ids);
        ZimbraLog.test.info("postfixFlushDeferredMailQueue done requeue");
        // requeueing isn't enough on its own to get things moving
        RemoteManager rmgr = RemoteManager.getRemoteManager(server);
        rmgr.execute(RemoteCommands.FLUSHQUEUE);
        ZimbraLog.test.info("postfixFlushDeferredMailQueue finished [%s]", ZimbraLog.elapsedTime(start, System.currentTimeMillis()));
    } catch (ServiceException e) {
        ZimbraLog.test.error("postfixFlushDeferredMailQueue - Problem getting 'deferred' mail queue", e);
    }
    return true;
}
Also used : RemoteMailQueue(com.zimbra.cs.rmgmt.RemoteMailQueue) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) RemoteManager(com.zimbra.cs.rmgmt.RemoteManager) QueueAttr(com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr) ZMountpoint(com.zimbra.client.ZMountpoint)

Aggregations

RemoteMailQueue (com.zimbra.cs.rmgmt.RemoteMailQueue)2 QueueAttr (com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr)2 ZMountpoint (com.zimbra.client.ZMountpoint)1 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 Provisioning (com.zimbra.cs.account.Provisioning)1 Server (com.zimbra.cs.account.Server)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 SummaryItem (com.zimbra.cs.rmgmt.RemoteMailQueue.SummaryItem)1 RemoteManager (com.zimbra.cs.rmgmt.RemoteManager)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Query (org.apache.lucene.search.Query)1 TermQuery (org.apache.lucene.search.TermQuery)1