use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.
the class TestProvAlias method testRemoveAlias_aliasNameExistsButIsNotAnAlias.
@Test
public void testRemoveAlias_aliasNameExistsButIsNotAnAlias() throws Exception {
String testName = getTestName();
// create the domain
String domainName = underscoreToHyphen(testName) + "." + BASE_DOMAIN_NAME;
domainName = domainName.toLowerCase();
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
Domain domain = prov.createDomain(domainName, attrs);
// create the account
String acctName = getEmail("acct-1", domainName);
Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
// create another account
String acct2Name = getEmail("acct-2", domainName);
Account acct2 = prov.createAccount(acct2Name, PASSWORD, new HashMap<String, Object>());
String acct2Id = acct2.getId();
// create a distribution list
String dlName = getEmail("dl", domainName);
DistributionList dl = prov.createDistributionList(dlName, new HashMap<String, Object>());
String dlId = dl.getId();
boolean good = false;
try {
prov.removeAlias(acct, acct2Name);
} catch (ServiceException e) {
if (AccountServiceException.NO_SUCH_ALIAS.equals(e.getCode()))
good = true;
}
assertTrue(good);
// make sure the account is not touched
prov.flushCache(CacheEntryType.account, new CacheEntry[] { new CacheEntry(Key.CacheEntryBy.id, acct2Id) });
acct2 = prov.get(AccountBy.id, acct2Id);
assertNotNull(acct2);
assertEquals(acct2Id, acct2.getId());
assertEquals(acct2Name, acct2.getName());
try {
prov.removeAlias(acct, dlName);
} catch (ServiceException e) {
if (AccountServiceException.NO_SUCH_ALIAS.equals(e.getCode()))
good = true;
}
assertTrue(good);
// make sure the dl is not touched
// mProv.flushCache(CacheEntryType.account, new CacheEntry[]{new CacheEntry(CacheEntryBy.id, acct2Id)});
dl = prov.get(Key.DistributionListBy.id, dlId);
assertNotNull(dl);
assertEquals(dlId, dl.getId());
assertEquals(dlName, dl.getName());
}
use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.
the class TestProvisioning method flushCacheTest.
private void flushCacheTest() throws Exception {
System.out.println("Testing flush cache");
// skin|locale|account|config|cos|domain|server|zimlet
String value = null;
String newVal = "new value";
String oldVal = "old value";
Map<String, Object> attrs = new HashMap<String, Object>();
/*
* account
*/
String acctAttr = Provisioning.A_description;
Account acct = mSoapProv.get(Key.AccountBy.name, ACCT_EMAIL);
assertNotNull(acct);
// write the old value
attrs.clear();
attrs.put(acctAttr, oldVal);
// modify via soap
mSoapProv.modifyAttrs(acct, attrs);
// get the entry
acct = mSoapProv.get(Key.AccountBy.name, ACCT_EMAIL);
// get the attr
value = acct.getAttr(acctAttr);
// make sure the attr is updated
assertEquals(oldVal, value);
// update with the new values via ldap
attrs.clear();
attrs.put(acctAttr, newVal);
acct = mProv.get(Key.AccountBy.name, ACCT_EMAIL);
// modify via ldap prov
mProv.modifyAttrs(acct, attrs);
// ensure it is still the old value
// get the entry via soap
acct = mSoapProv.get(Key.AccountBy.name, ACCT_EMAIL);
// get the attr
value = acct.getAttr(acctAttr);
// the value should be still old value
assertEquals(oldVal, value);
// flush the account
mSoapProv.flushCache(CacheEntryType.account, new CacheEntry[] { new CacheEntry(Key.CacheEntryBy.id, acct.getId()) });
// ensure it is the new value
// get he entry via soap
acct = mSoapProv.get(Key.AccountBy.name, ACCT_EMAIL);
// get the attr
value = acct.getAttr(acctAttr);
// now we should see the new value
assertEquals(newVal, value);
/*
* cos
*/
String cosAttr = Provisioning.A_zimbraPrefSkin;
Cos cos = mSoapProv.get(Key.CosBy.name, COS_NAME);
assertNotNull(cos);
// write the old value
attrs.clear();
attrs.put(cosAttr, oldVal);
// modify via soap
mSoapProv.modifyAttrs(cos, attrs);
// get the entry
cos = mSoapProv.get(Key.CosBy.name, COS_NAME);
// get the attr
value = cos.getAttr(cosAttr);
// make sure the attr is updated
assertEquals(oldVal, value);
// update with the new values via ldap
attrs.clear();
attrs.put(cosAttr, newVal);
cos = mProv.get(Key.CosBy.name, COS_NAME);
// modify via ldap prov
mProv.modifyAttrs(cos, attrs);
// ensure it is still the old value
// get he entry via soap
cos = mSoapProv.get(Key.CosBy.name, COS_NAME);
// get the attr
value = cos.getAttr(cosAttr);
// the value should be still old value
assertEquals(oldVal, value);
// ensure the account is also still the old value
// get the entry via soap
acct = mSoapProv.get(Key.AccountBy.name, ACCT_EMAIL);
// get the attr
value = acct.getAttr(cosAttr);
// the value should be still old value
assertEquals(oldVal, value);
// flush the cos
mSoapProv.flushCache(CacheEntryType.cos, new CacheEntry[] { new CacheEntry(Key.CacheEntryBy.id, cos.getId()) });
// ensure it is the new value
// get he entry via soap
cos = mSoapProv.get(Key.CosBy.name, COS_NAME);
// get the attr
value = cos.getAttr(cosAttr);
// now we should see the new value
assertEquals(newVal, value);
// ensure the account also gets the new value
// get he entry via soap
acct = mSoapProv.get(Key.AccountBy.name, ACCT_EMAIL);
// get the attr
value = acct.getAttr(cosAttr);
// now we should see the new value
assertEquals(newVal, value);
/*
* config
*/
String configAttr = "zimbraWebClientLoginUrl";
Config config = mSoapProv.getConfig();
assertNotNull(config);
// write the old value
attrs.clear();
attrs.put(configAttr, oldVal);
// modify via soap
mSoapProv.modifyAttrs(config, attrs);
// get the entry
config = mSoapProv.getConfig();
// get the attr
value = config.getAttr(configAttr);
// make sure the attr is updated
assertEquals(oldVal, value);
// update with the new values via ldap
attrs.clear();
attrs.put(configAttr, newVal);
config = mProv.getConfig();
// modify via ldap prov
mProv.modifyAttrs(config, attrs);
// ensure it is still the old value
// get the entry via soap
config = mSoapProv.getConfig();
// get the attr
value = config.getAttr(configAttr);
// the value should be still old value
assertEquals(oldVal, value);
// flush the account
mSoapProv.flushCache(CacheEntryType.config, null);
// ensure it is the new value
// get he entry via soap
config = mSoapProv.getConfig();
// get the attr
value = config.getAttr(configAttr);
// now we should see the new value
assertEquals(newVal, value);
}
use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.
the class ModifyAccount method checkNewServer.
/*
* if the account's home server is changed as a result of this command and the new server is no longer this server,
* need to send a flush cache command to the new server so we don't get into the following:
*
* account is on server A (this server)
*
* on server B: zmprov ma {account} zimbraMailHost B (the ma is proxied to server A; and on server B, the account
* still appears to be on A)
*
* zmprov ma {account} {any attr} {value} ERROR: service.TOO_MANY_HOPS Until the account is expired from cache on
* server B.
*/
private void checkNewServer(ZimbraSoapContext zsc, Map<String, Object> context, Account acct, Server newServer) {
try {
if (!Provisioning.onLocalServer(acct)) {
// in the case when zimbraMailHost is being removed, newServer will be null
if (newServer != null) {
SoapProvisioning soapProv = new SoapProvisioning();
String adminUrl = URLUtil.getAdminURL(newServer, AdminConstants.ADMIN_SERVICE_URI, true);
soapProv.soapSetURI(adminUrl);
soapProv.soapZimbraAdminAuthenticate();
soapProv.flushCache(CacheEntryType.account, new CacheEntry[] { new CacheEntry(CacheEntryBy.id, acct.getId()) });
}
}
} catch (ServiceException e) {
// ignore any error and continue
ZimbraLog.mailbox.warn("cannot flush account cache on server " + (newServer == null ? "" : newServer.getName()) + " for " + acct.getName(), e);
}
}
use of com.zimbra.cs.account.Provisioning.CacheEntry in project zm-mailbox by Zimbra.
the class FlushCache method getCacheEntries.
private static CacheEntry[] getCacheEntries(CacheSelector cacheSelector) throws ServiceException {
List<CacheEntrySelector> cacheEntrySelectors = cacheSelector.getEntries();
if (cacheEntrySelectors.size() < 1) {
return null;
}
CacheEntry[] entries = new CacheEntry[cacheEntrySelectors.size()];
int i = 0;
for (CacheEntrySelector cacheEntrySelector : cacheEntrySelectors) {
entries[i++] = new CacheEntry(cacheEntrySelector.getBy().toKeyCacheEntryBy(), cacheEntrySelector.getKey());
}
return entries;
}
Aggregations