Search in sources :

Example 1 with RemoteMailQueue

use of com.zimbra.cs.rmgmt.RemoteMailQueue 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 RemoteMailQueue

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

the class MailQueueAction method handle.

@Override
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);
    RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, queueName, false);
    Element actionElem = queueElem.getElement(AdminConstants.E_ACTION);
    String op = actionElem.getAttribute(AdminConstants.A_OP);
    QueueAction action = QueueAction.valueOf(op);
    if (action == null) {
        throw ServiceException.INVALID_REQUEST("bad " + AdminConstants.A_OP + ":" + op, null);
    }
    String by = actionElem.getAttribute(AdminConstants.A_BY);
    String[] ids;
    if (by.equals(AdminConstants.BY_ID)) {
        ids = actionElem.getText().split(",");
    } else if (by.equals(AdminConstants.BY_QUERY)) {
        Element queryElem = actionElem.getElement(AdminConstants.E_QUERY);
        Query query = GetMailQueue.buildLuceneQuery(queryElem);
        RemoteMailQueue.SearchResult sr = rmq.search(query, 0, Integer.MAX_VALUE);
        ids = new String[sr.qitems.size()];
        int i = 0;
        for (Map<QueueAttr, String> qitem : sr.qitems) {
            ids[i++] = qitem.get(QueueAttr.id);
        }
    } else {
        throw ServiceException.INVALID_REQUEST("bad " + AdminConstants.A_BY + ": " + by, null);
    }
    rmq.action(server, action, ids);
    Element response = zsc.createElement(AdminConstants.MAIL_QUEUE_ACTION_RESPONSE);
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) RemoteMailQueue(com.zimbra.cs.rmgmt.RemoteMailQueue) Query(org.apache.lucene.search.Query) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) QueueAction(com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAction) Map(java.util.Map) Provisioning(com.zimbra.cs.account.Provisioning)

Example 3 with RemoteMailQueue

use of com.zimbra.cs.rmgmt.RemoteMailQueue 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)3 Element (com.zimbra.common.soap.Element)2 Provisioning (com.zimbra.cs.account.Provisioning)2 Server (com.zimbra.cs.account.Server)2 QueueAttr (com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 Query (org.apache.lucene.search.Query)2 ZMountpoint (com.zimbra.client.ZMountpoint)1 ServiceException (com.zimbra.common.service.ServiceException)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 QueueAction (com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAction)1 SummaryItem (com.zimbra.cs.rmgmt.RemoteMailQueue.SummaryItem)1 RemoteManager (com.zimbra.cs.rmgmt.RemoteManager)1 Map (java.util.Map)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 TermQuery (org.apache.lucene.search.TermQuery)1