Search in sources :

Example 1 with CacheEntry

use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.

the class ProvUtil method doFlushCache.

private void doFlushCache(String[] args) throws ServiceException {
    if (!(prov instanceof SoapProvisioning)) {
        throwSoapOnly();
    }
    boolean allServers = false;
    int argIdx = 1;
    if (args[argIdx].equals("-a")) {
        allServers = true;
        if (args.length > 2) {
            argIdx++;
        } else {
            usage();
            return;
        }
    }
    String type = args[argIdx++];
    CacheEntry[] entries = null;
    if (args.length > argIdx) {
        entries = new CacheEntry[args.length - argIdx];
        for (int i = argIdx; i < args.length; i++) {
            Key.CacheEntryBy entryBy;
            if (Provisioning.isUUID(args[i])) {
                entryBy = Key.CacheEntryBy.id;
            } else {
                entryBy = Key.CacheEntryBy.name;
            }
            entries[i - argIdx] = new CacheEntry(entryBy, args[i]);
        }
    }
    SoapProvisioning sp = (SoapProvisioning) prov;
    sp.flushCache(type, entries, allServers);
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry) Key(com.zimbra.common.account.Key)

Example 2 with CacheEntry

use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.

the class TestProv method flushCache.

protected void flushCache(Account acct) throws Exception {
    CacheEntry[] entries = new CacheEntry[1];
    entries[0] = new CacheEntry(Key.CacheEntryBy.name, acct.getName());
    mProv.flushCache(CacheEntryType.account, entries);
}
Also used : CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry)

Example 3 with CacheEntry

use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.

the class TestLdapProvCos method domainCos.

@Test
public void domainCos() throws Exception {
    String ATTR_NAME = Provisioning.A_zimbraMailQuota;
    final String COS1_NAME = genCosName("1");
    final String COS2_NAME = genCosName("2");
    final String DOMAIN_DEFAULT_COS_NAME = genCosName("domain-default-cos");
    final String COS1_VALUE = "10000";
    final String COS2_VALUE = "20000";
    final String DOMAIN_DEFAULT_COS_VALUE = "30000";
    final String ACCOUNT_VALUE = "40000";
    final String SYSTEM_DEFAULT_COS_VALUE = prov.get(CosBy.name, Provisioning.DEFAULT_COS_NAME).getAttr(ATTR_NAME);
    Map<String, Object> cos1Attrs = Maps.newHashMap();
    cos1Attrs.put(ATTR_NAME, COS1_VALUE);
    Cos cos1 = createCos(COS1_NAME, cos1Attrs);
    Map<String, Object> cos2Attrs = Maps.newHashMap();
    cos2Attrs.put(ATTR_NAME, COS2_VALUE);
    Cos cos2 = createCos(COS2_NAME, cos2Attrs);
    Map<String, Object> domainDefaultCosAttrs = Maps.newHashMap();
    domainDefaultCosAttrs.put(ATTR_NAME, DOMAIN_DEFAULT_COS_VALUE);
    Cos domainDefaultCos = createCos(DOMAIN_DEFAULT_COS_NAME, domainDefaultCosAttrs);
    modifyAttr(domain, Provisioning.A_zimbraDomainDefaultCOSId, domainDefaultCos.getId());
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    final String ACCT_NAME = acct.getName();
    // account should inherit the domain default cos value
    assertEquals(DOMAIN_DEFAULT_COS_VALUE, acct.getAttr(ATTR_NAME));
    // modify value on the domain default cos, should get the new value
    String newValue = String.valueOf(Long.valueOf(DOMAIN_DEFAULT_COS_VALUE) - 1);
    modifyAttr(domainDefaultCos, ATTR_NAME, newValue);
    assertEquals(newValue, acct.getAttr(ATTR_NAME));
    // modify the value back
    modifyAttr(domainDefaultCos, ATTR_NAME, DOMAIN_DEFAULT_COS_VALUE);
    // modify domain default cos, should still be the old cos value
    // known bug. This is fine for now - don't have a use case/bug for this, have to fix if needed
    modifyAttr(domain, Provisioning.A_zimbraDomainDefaultCOSId, cos1.getId());
    assertEquals(DOMAIN_DEFAULT_COS_VALUE, acct.getAttr(ATTR_NAME));
    // flush cache, re-get acct, we now should get the updated cos value
    prov.flushCache(CacheEntryType.account, new CacheEntry[] { new CacheEntry(Key.CacheEntryBy.name, ACCT_NAME) });
    acct = prov.get(AccountBy.name, ACCT_NAME);
    assertEquals(COS1_VALUE, acct.getAttr(ATTR_NAME));
    // remove domain default cos, should get the system default cos value,
    // but because of the bug, will still be the old cos value (known bug)
    modifyAttr(domain, Provisioning.A_zimbraDomainDefaultCOSId, null);
    assertEquals(COS1_VALUE, acct.getAttr(ATTR_NAME));
    // flush cache, we now should get the updated cos value
    prov.flushCache(CacheEntryType.account, new CacheEntry[] { new CacheEntry(Key.CacheEntryBy.name, ACCT_NAME) });
    acct = prov.get(AccountBy.name, ACCT_NAME);
    assertEquals(SYSTEM_DEFAULT_COS_VALUE, acct.getAttr(ATTR_NAME));
    provUtil.deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) Cos(com.zimbra.cs.account.Cos) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry)

Example 4 with CacheEntry

use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.

the class GalGroup method flushCache.

public static void flushCache(CacheEntry[] domains) throws ServiceException {
    if (domains != null) {
        for (CacheEntry entry : domains) {
            Key.DomainBy domainBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.DomainBy.id : Key.DomainBy.name;
            Domain domain = prov.get(Key.DomainBy.name, entry.mEntryIdentity);
            if (domain == null)
                throw AccountServiceException.NO_SUCH_DOMAIN(entry.mEntryIdentity);
            GalGroup.flushCache(domain);
        }
    } else {
        GalGroup.flushCache((Domain) null);
    }
}
Also used : CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry) Domain(com.zimbra.cs.account.Domain) Key(com.zimbra.common.account.Key) EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey)

Example 5 with CacheEntry

use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.

the class DistributionListDocumentHandler method flushAccountCache.

private static void flushAccountCache(Provisioning prov, String[] members) {
    // List<CacheEntry> localAccts = Lists.newArrayList();
    Map<String, List<CacheEntry>> /* server name */
    remoteAccts = Maps.newHashMap();
    for (String member : members) {
        try {
            Account acct = prov.get(AccountBy.name, member);
            if (acct != null) {
                if (prov.onLocalServer(acct)) {
                // localAccts.add(new CacheEntry(CacheEntryBy.id, acct.getId()));
                } else {
                    Server server = acct.getServer();
                    String serverName = server.getName();
                    List<CacheEntry> acctsOnServer = remoteAccts.get(serverName);
                    if (acctsOnServer == null) {
                        acctsOnServer = Lists.newArrayList();
                        remoteAccts.put(serverName, acctsOnServer);
                    }
                    acctsOnServer.add(new CacheEntry(CacheEntryBy.id, acct.getId()));
                }
            }
        // else, not internal account, skip
        } catch (ServiceException e) {
            // log and continue
            ZimbraLog.account.warn("unable to flush account cache", e);
        }
    }
    /*
         * No need to flush cache on local server, account membership for static/dynamic
         * groups are handled in LdapProvisioning
         *
        // flush accounts from cache on local server
        try {
            prov.flushCache(CacheEntryType.account, localAccts.toArray(new CacheEntry[localAccts.size()]));
        } catch (ServiceException e) {
            // log and continue
            ZimbraLog.account.warn("unable to flush account cache on local server", e);
        }
        */
    // flush accounts from cache on remote servers
    // if the remote server does not run admin server, too bad - accounts on that
    // server will have to wait till cache expire to get updated membership
    SoapProvisioning soapProv = new SoapProvisioning();
    String adminUrl = null;
    for (Map.Entry<String, List<CacheEntry>> acctsOnServer : remoteAccts.entrySet()) {
        String serverName = acctsOnServer.getKey();
        List<CacheEntry> accts = acctsOnServer.getValue();
        try {
            Server server = prov.get(ServerBy.name, serverName);
            adminUrl = URLUtil.getAdminURL(server, AdminConstants.ADMIN_SERVICE_URI, true);
            soapProv.soapSetURI(adminUrl);
            soapProv.soapZimbraAdminAuthenticate();
            soapProv.flushCache(CacheEntryType.account, accts.toArray(new CacheEntry[accts.size()]));
        } catch (ServiceException e) {
            ZimbraLog.account.warn("unable to flush account cache on remote server: " + serverName, e);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) List(java.util.List) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry) Map(java.util.Map)

Aggregations

CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)9 ServiceException (com.zimbra.common.service.ServiceException)3 Account (com.zimbra.cs.account.Account)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)3 Key (com.zimbra.common.account.Key)2 Domain (com.zimbra.cs.account.Domain)2 HashMap (java.util.HashMap)2 Cos (com.zimbra.cs.account.Cos)1 DistributionList (com.zimbra.cs.account.DistributionList)1 EntryCacheDataKey (com.zimbra.cs.account.EntryCacheDataKey)1 Server (com.zimbra.cs.account.Server)1 CacheEntrySelector (com.zimbra.soap.admin.type.CacheEntrySelector)1 List (java.util.List)1 Map (java.util.Map)1