use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllAlwaysOnClusters.
@Override
public List<AlwaysOnCluster> getAllAlwaysOnClusters() throws ServiceException {
List<AlwaysOnCluster> result = new ArrayList<AlwaysOnCluster>();
ZLdapFilter filter = filterFactory.allAlwaysOnClusters();
try {
ZSearchResultEnumeration ne = helper.searchDir(mDIT.alwaysOnClusterBaseDN(), filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
LdapAlwaysOnCluster c = new LdapAlwaysOnCluster(sr.getDN(), sr.getAttributes(), null, this);
result.add(c);
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all alwaysOnClusters", e);
}
if (result.size() > 0)
alwaysOnClusterCache.put(result, true);
Collections.sort(result);
return result;
}
use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.
the class LdapProvisioning method extendLifeInCacheOrFlush.
public void extendLifeInCacheOrFlush(Entry entry) {
if (entry instanceof Account) {
accountCache.replace((Account) entry);
} else if (entry instanceof LdapCos) {
cosCache.replace((LdapCos) entry);
} else if (entry instanceof Domain) {
domainCache.replace((Domain) entry);
} else if (entry instanceof Server) {
serverCache.replace((Server) entry);
} else if (entry instanceof UCService) {
ucServiceCache.replace((UCService) entry);
} else if (entry instanceof XMPPComponent) {
xmppComponentCache.replace((XMPPComponent) entry);
} else if (entry instanceof LdapZimlet) {
zimletCache.replace((LdapZimlet) entry);
} else if (entry instanceof LdapAlwaysOnCluster) {
alwaysOnClusterCache.replace((AlwaysOnCluster) entry);
} else if (entry instanceof Group) {
/*
* DLs returned by Provisioning.get(DistributionListBy) and
* DLs/dynamic groups returned by Provisioning.getGroup(DistributionListBy)
* are "not" cached.
*
* DLs returned by Provisioning.getDLBasic(DistributionListBy) and
* DLs/dynamic groups returned by Provisioning.getGroupBasic(DistributionListBy)
* "are" cached.
*
* Need to flush out the cached entries if the instance being modified is not
* in cache. (i.e. the instance being modified was obtained by get/getGroup)
*/
Group modifiedInstance = (Group) entry;
Group cachedInstance = getGroupFromCache(DistributionListBy.id, modifiedInstance.getId());
if (cachedInstance != null && modifiedInstance != cachedInstance) {
groupCache.remove(cachedInstance);
}
}
}
use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.
the class LdapProvisioning method refreshEntry.
void refreshEntry(Entry entry, ZLdapContext initZlc) throws ServiceException {
try {
String dn = ((LdapEntry) entry).getDN();
ZAttributes attributes = helper.getAttributes(initZlc, dn);
Map<String, Object> attrs = attributes.getAttrs();
Map<String, Object> defaults = null;
Map<String, Object> secondaryDefaults = null;
Map<String, Object> overrideDefaults = null;
if (entry instanceof Account) {
//
// We can get here from either modifyAttrsInternal or reload path.
//
// If we got here from modifyAttrsInternal, zimbraCOSId on account
// might have been changed, added, removed, but entry now still contains
// the old attrs. Create a temp Account object from the new attrs, and then
// use the same cos of the temp Account object for our entry object.
//
// If we got here from reload, attrs are likely not changed, the callsites
// just want a refreshed object. For this case it's best if we still
// always resolve the COS correctly. makeAccount is a cheap call and won't
// add any overhead like loading cos/domain from LDAP: even if cos/domain
// has to be loaded (because not in cache) in the getCOS(temp) call, it's
// just the same as calling (buggy) getCOS(entry) before.
//
// We only need the temp object for the getCOS call, don't need to setup
// primary/secondary defaults on the temp object because:
// zimbraCOSId is only on account(of course), and that's all needed
// for determining the COS for the account in the getCOS call: if
// zimbraCOSId is not set on account, it will fallback to the domain
// default COS, then fallback to the system default COS.
//
Account temp = makeAccountNoDefaults(dn, attributes);
Cos cos = getCOS(temp);
if (cos != null)
defaults = cos.getAccountDefaults();
Domain domain = getDomain((Account) entry);
if (domain != null)
secondaryDefaults = domain.getAccountDefaults();
} else if (entry instanceof Domain) {
defaults = getConfig().getDomainDefaults();
} else if (entry instanceof Server) {
defaults = getConfig().getServerDefaults();
AlwaysOnCluster aoc = getAlwaysOnCluster((Server) entry);
if (aoc != null) {
overrideDefaults = aoc.getServerOverrides();
}
}
if (defaults == null && secondaryDefaults == null)
entry.setAttrs(attrs);
else
entry.setAttrs(attrs, defaults, secondaryDefaults, overrideDefaults);
extendLifeInCacheOrFlush(entry);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to refresh entry", e);
}
}
use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.
the class LdapProvisioning method flushCache.
@Override
public void flushCache(CacheEntryType type, CacheEntry[] entries) throws ServiceException {
switch(type) {
case all:
if (entries != null) {
throw ServiceException.INVALID_REQUEST("cannot specify entry for flushing all", null);
}
ZimbraLog.account.info("Flushing all LDAP entry caches");
flushCache(CacheEntryType.account, null);
flushCache(CacheEntryType.group, null);
flushCache(CacheEntryType.config, null);
flushCache(CacheEntryType.globalgrant, null);
flushCache(CacheEntryType.cos, null);
flushCache(CacheEntryType.domain, null);
flushCache(CacheEntryType.mime, null);
flushCache(CacheEntryType.server, null);
flushCache(CacheEntryType.alwaysOnCluster, null);
flushCache(CacheEntryType.zimlet, null);
break;
case account:
if (entries != null) {
for (CacheEntry entry : entries) {
AccountBy accountBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? AccountBy.id : AccountBy.name;
Account account = getFromCache(accountBy, entry.mEntryIdentity);
/*
* We now call removeFromCache instead of reload for flushing an account
* from cache. This change was originally for bug 25028, but that would still
* need an extrat step to flush cache after the account's zimbraCOSId changed.
* (if we call reload insteasd of removeFromCache, flush cache of the account would
* not clear the mDefaults for inherited attrs, that was the bug.)
* Bug 25028 is now taken care of by the callback. We still call removeFromCache
* for flushing account cache, because that does a cleaner flush.
*
* Note, we only call removeFromCache for account.
* We should *NOT* do removeFromCache when flushing global config and cos caches.
*
* Because the "mDefaults" Map(contains a ref to the old instance of COS.mAccountDefaults for
* all the accountInherited COS attrs) stored in all the cached accounts. Same for the
* inherited attrs of server/domain from global config. If we do removeFromCache for flushing
* cos/global config, then after FlushCache(cos) if you do a ga on a cached account, it still
* shows the old COS value for values that are inherited from COS. Although, for newly loaded
* accounts or when a cached account is going thru auth(that'll trigger a reload) they will get
* the new COS values(refreshed as a result of FlushCache(cos)).
*/
if (account != null) {
removeFromCache(account);
}
}
} else {
accountCache.clear();
}
return;
case group:
if (entries != null) {
for (CacheEntry entry : entries) {
Key.DistributionListBy dlBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.DistributionListBy.id : Key.DistributionListBy.name;
removeGroupFromCache(dlBy, entry.mEntryIdentity);
}
} else {
allDLs.clear();
groupCache.clear();
}
return;
case config:
if (entries != null) {
throw ServiceException.INVALID_REQUEST("cannot specify entry for flushing global config", null);
}
Config config = getConfig();
reload(config, false);
EphemeralStore.clearFactory();
return;
case globalgrant:
if (entries != null) {
throw ServiceException.INVALID_REQUEST("cannot specify entry for flushing global grant", null);
}
GlobalGrant globalGrant = getGlobalGrant();
reload(globalGrant, false);
return;
case cos:
if (entries != null) {
for (CacheEntry entry : entries) {
Key.CosBy cosBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.CosBy.id : Key.CosBy.name;
Cos cos = getFromCache(cosBy, entry.mEntryIdentity);
if (cos != null)
reload(cos, false);
}
} else
cosCache.clear();
return;
case domain:
if (entries != null) {
for (CacheEntry entry : entries) {
Key.DomainBy domainBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.DomainBy.id : Key.DomainBy.name;
Domain domain = getFromCache(domainBy, entry.mEntryIdentity, GetFromDomainCacheOption.BOTH);
if (domain != null) {
if (domain instanceof DomainCache.NonExistingDomain)
domainCache.removeFromNegativeCache(domainBy, entry.mEntryIdentity);
else
reload(domain, false);
}
}
} else
domainCache.clear();
return;
case mime:
mimeTypeCache.flushCache(this);
return;
case server:
if (entries != null) {
for (CacheEntry entry : entries) {
Key.ServerBy serverBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.ServerBy.id : Key.ServerBy.name;
Server server = get(serverBy, entry.mEntryIdentity);
if (server != null)
reload(server, false);
}
} else
serverCache.clear();
return;
case alwaysOnCluster:
if (entries != null) {
for (CacheEntry entry : entries) {
Key.AlwaysOnClusterBy clusterBy = Key.AlwaysOnClusterBy.id;
AlwaysOnCluster cluster = get(clusterBy, entry.mEntryIdentity);
if (cluster != null)
reload(cluster, false);
}
} else
alwaysOnClusterCache.clear();
return;
case zimlet:
if (entries != null) {
for (CacheEntry entry : entries) {
Key.ZimletBy zimletBy = (entry.mEntryBy == Key.CacheEntryBy.id) ? Key.ZimletBy.id : Key.ZimletBy.name;
Zimlet zimlet = getFromCache(zimletBy, entry.mEntryIdentity);
if (zimlet != null)
reload(zimlet, false);
}
} else
zimletCache.clear();
return;
default:
throw ServiceException.INVALID_REQUEST("invalid cache type " + type, null);
}
}
use of com.zimbra.cs.account.AlwaysOnCluster in project zm-mailbox by Zimbra.
the class GetAllAlwaysOnClusters method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
List<AlwaysOnCluster> clusters = prov.getAllAlwaysOnClusters();
AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
Element response = zsc.createElement(AdminConstants.GET_ALL_ALWAYSONCLUSTERS_RESPONSE);
for (Iterator<AlwaysOnCluster> it = clusters.iterator(); it.hasNext(); ) {
AlwaysOnCluster cluster = it.next();
if (aac.hasRightsToList(cluster, Admin.R_listAlwaysOnCluster, null))
GetAlwaysOnCluster.encodeAlwaysOnCluster(response, cluster, null, aac.getAttrRightChecker(cluster));
}
return response;
}
Aggregations