Search in sources :

Example 6 with AdminCreateWaitSetResponse

use of com.zimbra.soap.admin.message.AdminCreateWaitSetResponse in project zm-mailbox by Zimbra.

the class AdminCreateWaitSetRequest method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    com.zimbra.soap.admin.message.AdminCreateWaitSetRequest req = zsc.elementToJaxb(request);
    AdminCreateWaitSetResponse resp = new AdminCreateWaitSetResponse();
    CreateWaitSet.staticHandle(this, req, context, resp);
    return zsc.jaxbToElement(resp);
/* MUST use zsc variant NOT JaxbUtil */
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)

Example 7 with AdminCreateWaitSetResponse

use of com.zimbra.soap.admin.message.AdminCreateWaitSetResponse in project zm-mailbox by Zimbra.

the class ImapServerListener method restoreWaitSet.

private synchronized void restoreWaitSet() throws ServiceException {
    ZimbraLog.imap.debug("Attempting to restore admin waitset for all registered listeners.");
    if (wsID != null) {
        ZimbraLog.imap.debug("Another thread has already restored waitset.");
        // another thread has already restored waitset
        return;
    }
    cancelPendingRequest();
    AdminCreateWaitSetRequest req = new AdminCreateWaitSetRequest("all", false);
    checkAuth();
    AdminCreateWaitSetResponse resp;
    resp = soapProv.invokeJaxbAsAdminWithRetry(req, server);
    if (resp == null) {
        throw ServiceException.FAILURE("Received null response from AdminCreateWaitSetRequest", null);
    }
    wsID = resp.getWaitSetId();
    setWaitSetIdOnMailboxes();
    lastSequence.set(resp.getSequence());
    ZimbraLog.imap.debug("Created new waitset to replace lost or cancelled one. WaitSet ID: %s", wsID);
    // send non-blocking synchronous WaitSetRequest. This way the caller has certainty that listeners were added on remote server
    AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(wsID, lastSequence.toString());
    waitSetReq.setBlock(false);
    waitSetReq.setExpand(true);
    Enumeration<String> accountIds = this.sessionMap.keys();
    while (accountIds.hasMoreElements()) {
        String accountId = accountIds.nextElement();
        WaitSetAddSpec updateOrAdd = new WaitSetAddSpec();
        updateOrAdd.setId(accountId);
        Enumeration<Integer> folderIDs = this.sessionMap.get(accountId).keys();
        while (folderIDs.hasMoreElements()) {
            updateOrAdd.addFolderInterest(folderIDs.nextElement());
            ZimbraLog.imap.debug("Adding account %s to waitset %s", accountId, wsID);
            waitSetReq.addAddAccount(updateOrAdd);
        }
    }
    ZimbraLog.imap.debug("Sending initial AdminWaitSetRequest. WaitSet ID: %s", wsID);
    AdminWaitSetResponse wsResp = soapProv.invokeJaxbAsAdminWithRetry(waitSetReq, server);
    try {
        processAdminWaitSetResponse(wsResp);
    } catch (Exception e) {
        throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) AdminServiceException(com.zimbra.cs.service.admin.AdminServiceException) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)

Example 8 with AdminCreateWaitSetResponse

use of com.zimbra.soap.admin.message.AdminCreateWaitSetResponse in project zm-mailbox by Zimbra.

the class ImapServerListener method initWaitSet.

private synchronized void initWaitSet(String accountId, boolean alreadyListening) throws ServiceException {
    if (wsID == null && this.sessionMap.containsKey(accountId)) {
        AdminCreateWaitSetRequest req = new AdminCreateWaitSetRequest("all", false);
        checkAuth();
        AdminCreateWaitSetResponse resp;
        resp = soapProv.invokeJaxbAsAdminWithRetry(req, server);
        if (resp == null) {
            throw ServiceException.FAILURE("Received null response from AdminCreateWaitSetRequest", null);
        }
        wsID = resp.getWaitSetId();
        setWaitSetIdOnMailboxes();
        lastSequence.set(resp.getSequence());
    } else {
        cancelPendingRequest();
    }
    ZimbraLog.imap.debug("Current waitset ID is %s", wsID);
    // send non-blocking synchronous WaitSetRequest. This way the caller has certainty that listener was added on remote server
    AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(wsID, lastSequence.toString());
    waitSetReq.setBlock(false);
    waitSetReq.setExpand(true);
    if (!this.sessionMap.containsKey(accountId) || this.sessionMap.get(accountId).isEmpty()) {
        ZimbraLog.imap.debug("Removing accout %s from waitset %s", accountId, wsID);
        waitSetReq.addRemoveAccount(new Id(accountId));
    } else {
        WaitSetAddSpec updateOrAdd = new WaitSetAddSpec();
        updateOrAdd.setId(accountId);
        Enumeration<Integer> folderIDs = this.sessionMap.get(accountId).keys();
        while (folderIDs.hasMoreElements()) {
            updateOrAdd.addFolderInterest(folderIDs.nextElement());
        }
        if (alreadyListening) {
            ZimbraLog.imap.debug("Updating folder interests for account %s in waitset %s", accountId, wsID);
            waitSetReq.addUpdateAccount(updateOrAdd);
        } else {
            ZimbraLog.imap.debug("Adding account %s to waitset %s", accountId, wsID);
            waitSetReq.addAddAccount(updateOrAdd);
        }
    }
    try {
        ZimbraLog.imap.debug("Sending initial AdminWaitSetRequest. WaitSet ID: %s", wsID);
        AdminWaitSetResponse wsResp = soapProv.invokeJaxbAsAdminWithRetry(waitSetReq, server);
        processAdminWaitSetResponse(wsResp);
    } catch (SoapFaultException e) {
        if (AdminServiceException.NO_SUCH_WAITSET.equalsIgnoreCase(e.getCode())) {
            // waitset is gone. Create a new one
            ZimbraLog.imap.warn("AdminWaitSet %s does not exist anymore", wsID);
            wsID = null;
            unsetWaitSetIdOnMailboxes();
            lastSequence.set(0);
            restoreWaitSet();
        } else {
            throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) WaitSetAddSpec(com.zimbra.soap.type.WaitSetAddSpec) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) Id(com.zimbra.soap.type.Id) SoapFaultException(com.zimbra.common.soap.SoapFaultException) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) AdminServiceException(com.zimbra.cs.service.admin.AdminServiceException) AdminCreateWaitSetRequest(com.zimbra.soap.admin.message.AdminCreateWaitSetRequest) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)

Example 9 with AdminCreateWaitSetResponse

use of com.zimbra.soap.admin.message.AdminCreateWaitSetResponse in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method adminWSfolderInterestChanges.

/**
 * Test that can change the info on which folders we're interested in several times.
 * Introduced for ZCS-2220 although discovered that shouldn't need ADMIN SOAP sessions
 * for IMAP AdminWaitSet code, so counting them is a bit redundant.  Kept test
 * as some assurance that lots of folder interest changes works OK.
 */
@Test
public void adminWSfolderInterestChanges() throws Exception {
    int numFolders = LC.zimbra_session_limit_admin.intValue() + 15;
    String user1Name = testInfo.getMethodName().toLowerCase() + "user1";
    acc1 = TestUtil.createAccount(user1Name);
    ZMailbox zMbox1 = TestUtil.getZMailbox(user1Name);
    Set<String> accountIds = new HashSet<String>();
    String acct1Id = zMbox1.getAccountId();
    accountIds.add(acct1Id);
    String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
    List<ZFolder> folders = new ArrayList<>(numFolders);
    for (int fnum = 1; fnum <= numFolders; fnum++) {
        folders.add(TestUtil.createFolder(zMbox1, String.format("FOLDER_%s", fnum)));
    }
    int numSess = countActiveSessionsForAdmin();
    SessionCache.getAllSessions(acct1Id);
    AdminCreateWaitSetResponse resp = createAdminWaitSet(accountIds, adminAuthToken, false);
    assertNotNull(resp);
    waitSetId = resp.getWaitSetId();
    int seq = resp.getSequence();
    for (int fnum = 0; fnum < numFolders; fnum++) {
        AdminWaitSetRequest waitSet = new AdminWaitSetRequest(waitSetId, Integer.toString(seq));
        Set<Integer> folderInterest = Sets.newHashSet();
        folderInterest.add(folders.get(fnum).getFolderIdInOwnerMailbox());
        waitSet.addUpdateAccount(createWaitSetAddSpec(acct1Id, folderInterest));
        AdminWaitSetResponse wsResp = sendReq(envelope(adminAuthToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getAdminSoapUrl() + "AdminWaitSetRequest");
        seq = Integer.parseInt(wsResp.getSeqNo());
        assertEquals("Number of ADMIN sessions (should not have increased)", numSess, countActiveSessionsForAdmin());
    }
}
Also used : AdminWaitSetRequest(com.zimbra.soap.admin.message.AdminWaitSetRequest) ArrayList(java.util.ArrayList) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZMailbox(com.zimbra.client.ZMailbox) AdminWaitSetResponse(com.zimbra.soap.admin.message.AdminWaitSetResponse) ZFolder(com.zimbra.client.ZFolder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with AdminCreateWaitSetResponse

use of com.zimbra.soap.admin.message.AdminCreateWaitSetResponse in project zm-mailbox by Zimbra.

the class TestWaitSetRequest method testDestroyWaitset.

@Test
public void testDestroyWaitset() throws Exception {
    ZimbraLog.test.info("Starting testDestroyWaitset");
    String user1Name = "testDestroyWaitset_user1";
    acc1 = TestUtil.createAccount(user1Name);
    ZMailbox mbox = TestUtil.getZMailbox(user1Name);
    Set<String> accountIds = new HashSet<String>();
    accountIds.add(mbox.getAccountId());
    String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
    AdminCreateWaitSetResponse resp = createAdminWaitSet(accountIds, adminAuthToken, false);
    assertNotNull(resp);
    waitSetId = resp.getWaitSetId();
    assertNotNull(waitSetId);
    QueryWaitSetRequest qwsReq = new QueryWaitSetRequest(waitSetId);
    QueryWaitSetResponse qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
    validateQueryWaitSetResponse(qwsResp, acc1.getId(), null, null, false);
    AdminDestroyWaitSetRequest destroyReq = new AdminDestroyWaitSetRequest(waitSetId);
    AdminDestroyWaitSetResponse destroyResp = (AdminDestroyWaitSetResponse) sendReq(destroyReq, adminAuthToken, TestUtil.getAdminSoapUrl());
    assertNotNull("AdminDestroyWaitSetResponse should not be null", destroyResp);
    assertNotNull("AdminDestroyWaitSetResponse::waitSetId should not be null", destroyResp.getWaitSetId());
    assertEquals("AdminDestroyWaitSetResponse has wrong waitSetId", waitSetId, destroyResp.getWaitSetId());
    qwsReq = new QueryWaitSetRequest(waitSetId);
    Element faultResp = sendReqExpectedToFail(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl(), HttpStatus.SC_INTERNAL_SERVER_ERROR);
    assertNotNull("should return Element", faultResp);
    try {
        TestUtil.getAdminSoapTransport().extractBodyElement(faultResp);
        fail("Should thrown SoapFaultException");
    } catch (SoapFaultException sfe) {
        assertEquals("Expecting admin.NO_SUCH_WAITSET", AdminServiceException.NO_SUCH_WAITSET, sfe.getCode());
    } catch (SoapParseException spe) {
        fail("Should not be throwing SoapParseException. " + spe.getMessage());
    }
    waitSetId = null;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) Element(com.zimbra.common.soap.Element) SoapParseException(com.zimbra.common.soap.SoapParseException) QueryWaitSetRequest(com.zimbra.soap.admin.message.QueryWaitSetRequest) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) SoapFaultException(com.zimbra.common.soap.SoapFaultException) HashSet(java.util.HashSet) AdminCreateWaitSetResponse(com.zimbra.soap.admin.message.AdminCreateWaitSetResponse) Test(org.junit.Test)

Aggregations

AdminCreateWaitSetResponse (com.zimbra.soap.admin.message.AdminCreateWaitSetResponse)11 AdminWaitSetRequest (com.zimbra.soap.admin.message.AdminWaitSetRequest)8 ZMailbox (com.zimbra.client.ZMailbox)7 SoapFaultException (com.zimbra.common.soap.SoapFaultException)7 Test (org.junit.Test)7 ServiceException (com.zimbra.common.service.ServiceException)6 AdminServiceException (com.zimbra.cs.service.admin.AdminServiceException)6 HashSet (java.util.HashSet)6 SoapParseException (com.zimbra.common.soap.SoapParseException)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)4 AdminWaitSetResponse (com.zimbra.soap.admin.message.AdminWaitSetResponse)4 WaitSetAddSpec (com.zimbra.soap.type.WaitSetAddSpec)4 IOException (java.io.IOException)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 JAXBException (javax.xml.bind.JAXBException)4 AdminCreateWaitSetRequest (com.zimbra.soap.admin.message.AdminCreateWaitSetRequest)3 ZFolder (com.zimbra.client.ZFolder)2 ArrayList (java.util.ArrayList)2 Element (com.zimbra.common.soap.Element)1