Search in sources :

Example 1 with CacheEntryType

use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.

the class CacheExtension method register.

/*
     * Register a cache type that can be flushed by the zmprov fc <cache> command.
     * 
     * It should be invoked from the init() method of ZimbraExtension.
     */
public static synchronized void register(String cacheType, CacheExtension handler) {
    if (mHandlers == null)
        mHandlers = new HashMap<String, CacheExtension>();
    else {
        // make sure the cache is not already registered
        CacheExtension obj = mHandlers.get(cacheType);
        if (obj != null) {
            ZimbraLog.account.warn("cache type " + cacheType + " is already registered, " + "registering of " + obj.getClass().getCanonicalName() + " is ignored");
            return;
        }
        // make sure the cache type does not clash with one on of the internal cache type
        CacheEntryType cet = null;
        try {
            cet = CacheEntryType.fromString(cacheType);
        } catch (ServiceException e) {
        // this is good
        }
        if (cet != null) {
            ZimbraLog.account.warn("cache type " + cacheType + " is one of the internal cache type, " + "registering of " + obj.getClass().getCanonicalName() + " is ignored");
            return;
        }
    }
    mHandlers.put(cacheType, handler);
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType)

Example 2 with CacheEntryType

use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.

the class TestImapViaImapDaemon method flushNonImapCacheTypes.

@Test
public void flushNonImapCacheTypes() throws Exception {
    // Flushing these cache types won't do anything on the imapd server, but
    // we want to make sure that this does not fail;
    ImapConnection adminConn = getAdminConnection();
    Set<CacheEntryType> allTypes = new HashSet<CacheEntryType>(Arrays.asList(CacheEntryType.values()));
    Set<CacheEntryType> nonImapTypes = Sets.difference(allTypes, ImapHandler.IMAP_CACHE_TYPES);
    for (CacheEntryType type : nonImapTypes) {
        try {
            adminConn.flushCache(CacheEntryType.license.toString());
        } catch (CommandFailedException e) {
            fail("should be able issue X-ZIMBRA-FLUSHCACHE command for cache type " + type.toString());
        }
    }
}
Also used : CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType) ImapConnection(com.zimbra.cs.mailclient.imap.ImapConnection) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with CacheEntryType

use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.

the class FlushCache method doFlushCache.

public static void doFlushCache(AdminDocumentHandler handler, Map<String, Object> context, FlushCacheRequest req) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Server localServer = Provisioning.getInstance().getLocalServer();
    handler.checkRight(zsc, context, localServer, Admin.R_flushCache);
    CacheSelector cacheSelector = req.getCache();
    boolean allServers = cacheSelector.isAllServers();
    boolean imapServers = cacheSelector.isIncludeImapServers();
    String[] types = cacheSelector.getTypes().split(",");
    for (String type : types) {
        CacheEntryType cacheType = null;
        try {
            cacheType = CacheEntryType.fromString(type);
            doFlush(context, cacheType, cacheSelector);
        } catch (ServiceException e) {
            if (cacheType == null) {
                // see if it is a registered extension
                CacheExtension ce = CacheExtension.getHandler(type);
                if (ce != null) {
                    ce.flushCache();
                } else {
                    throw e;
                }
            } else {
                throw e;
            }
        }
    }
    if (imapServers) {
        flushCacheOnImapDaemons(req, zsc);
    }
    if (allServers) {
        flushCacheOnAllServers(zsc, req);
    }
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) Server(com.zimbra.cs.account.Server) ServiceException(com.zimbra.common.service.ServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CacheExtension(com.zimbra.cs.account.CacheExtension) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType)

Example 4 with CacheEntryType

use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.

the class ImapHandler method doFLUSHCACHE.

private boolean doFLUSHCACHE(String tag, List<CacheEntryType> types, List<CacheEntrySelector> entries) throws IOException {
    if (!checkState(tag, State.AUTHENTICATED)) {
        return true;
    } else if (!checkZimbraAdminAuth()) {
        sendNO(tag, "must be authenticated as admin with X-ZIMBRA auth mechanism");
        return true;
    }
    if (types.isEmpty()) {
        // nothing to do here
        sendOK(tag, "FLUSHCACHE completed");
        return true;
    }
    AuthToken authToken = ((ZimbraAuthenticator) authenticator).getAuthToken();
    try {
        AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(authToken);
        Server localServer = Provisioning.getInstance().getLocalServer();
        aac.checkRight(localServer, Admin.R_flushCache);
    } catch (ServiceException e) {
        if (e.getCode().equalsIgnoreCase(ServiceException.PERM_DENIED)) {
            ZimbraLog.imap.error("insufficient rights for flushing cache on IMAP server", e);
        } else {
            ZimbraLog.imap.error("error while checking rights for flushing cache on IMAP server", e);
        }
        return canContinue(e);
    }
    CacheSelector cacheSelector = new CacheSelector();
    cacheSelector.setEntries(entries);
    for (CacheEntryType type : types) {
        try {
            FlushCache.doFlush(null, type, cacheSelector);
        } catch (ServiceException e) {
            ZimbraLog.imap.error("error flushing cache on IMAP server", e);
            return canContinue(e);
        }
    }
    sendOK(tag, "FLUSHCACHE completed");
    return true;
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) ZimbraAuthenticator(com.zimbra.cs.security.sasl.ZimbraAuthenticator) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) AuthToken(com.zimbra.cs.account.AuthToken) AdminAccessControl(com.zimbra.cs.service.admin.AdminAccessControl) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType)

Example 5 with CacheEntryType

use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.

the class ImapRequest method readCacheEntryTypes.

protected List<CacheEntryType> readCacheEntryTypes() throws IOException, ImapParseException {
    if (peekChar() != '(') {
        CacheEntryType type = readCacheEntryType();
        if (type != null) {
            return Arrays.asList(new CacheEntryType[] { type });
        } else {
            return Collections.emptyList();
        }
    }
    skipChar('(');
    List<CacheEntryType> cacheTypes = new ArrayList<CacheEntryType>();
    if (peekChar() != ')') {
        do {
            CacheEntryType cacheType = readCacheEntryType();
            if (cacheType != null) {
                cacheTypes.add(cacheType);
            }
            if (peekChar() == ')') {
                break;
            }
            skipSpace();
        } while (true);
        skipChar(')');
        return cacheTypes;
    } else {
        throw new ImapParseException(tag, "must specify a cache type");
    }
}
Also used : ArrayList(java.util.ArrayList) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType)

Aggregations

CacheEntryType (com.zimbra.soap.admin.type.CacheEntryType)5 ServiceException (com.zimbra.common.service.ServiceException)3 Server (com.zimbra.cs.account.Server)2 CacheSelector (com.zimbra.soap.admin.type.CacheSelector)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthToken (com.zimbra.cs.account.AuthToken)1 CacheExtension (com.zimbra.cs.account.CacheExtension)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)1 ImapConnection (com.zimbra.cs.mailclient.imap.ImapConnection)1 ZimbraAuthenticator (com.zimbra.cs.security.sasl.ZimbraAuthenticator)1 AdminAccessControl (com.zimbra.cs.service.admin.AdminAccessControl)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1