use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class CoordinatorClientExt method getNodeGlobalScopeInfo.
/**
* Get node info from specific site.
*
* @param clazz
* @param siteId
* @param kind
* @param id
* @param <T>
* @return
* @throws Exception
*/
public <T extends CoordinatorSerializable> T getNodeGlobalScopeInfo(final Class<T> clazz, final String siteId, final String kind, final String id) throws Exception {
final T info = clazz.newInstance();
final Configuration config = _coordinator.queryConfiguration(siteId, kind, id);
if (config != null && config.getConfig(NODE_INFO) != null) {
final String infoStr = config.getConfig(NODE_INFO);
_log.debug("getNodeGlobalScopelInfo({}): info={}", clazz.getName(), Strings.repr(infoStr));
final T decodeInfo = info.decodeFromString(infoStr);
_log.debug("getNodeGlobalScopelInfo({}): info={}", clazz.getName(), decodeInfo);
return decodeInfo;
}
return null;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class SecretsInit method checkDbInitDone.
private boolean checkDbInitDone(String dbsvcName) {
int nodeCount = coordinator.getNodeCount();
int doneCount = 0;
String dbVersion = coordinator.getCurrentDbSchemaVersion();
String configIdPrefix = Constants.GEODBSVC_NAME.equalsIgnoreCase(dbsvcName) ? "geodb" : "db";
log.info("Checking db init status for {} on {} nodes", dbsvcName, nodeCount);
for (int i = 1; i <= nodeCount; i++) {
String dbConfigId = String.format("%s-%d", configIdPrefix, i);
String configKind = coordinator.getCoordinatorClient().getVersionedDbConfigPath(dbsvcName, dbVersion);
Configuration config = coordinator.getCoordinatorClient().queryConfiguration(coordinator.getCoordinatorClient().getSiteId(), configKind, dbConfigId);
if (config == null) {
return false;
}
String initDoneStr = config.getConfig(DbConfigConstants.INIT_DONE);
if (initDoneStr != null && initDoneStr.equals("true")) {
doneCount++;
log.info("{}-{} init is done.", dbsvcName, i);
}
}
return doneCount == nodeCount;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class InterVDCTokenCacheHelper method getAllCachedBundles.
/**
* Retrieves all the cached TokenKeysBundles for VDCs from which tokens were borrowed
*
* @return VDCid->bundle map
*/
public HashMap<String, TokenKeysBundle> getAllCachedBundles() {
HashMap<String, TokenKeysBundle> bundleToReturn = new HashMap<String, TokenKeysBundle>();
Configuration config = coordinator.queryConfiguration(FOREIGN_TOKEN_KEYS_BUNDLE_CONFIG, FOREIGN_TOKEN_KEYS_BUNDLE_KEYID);
if (config == null) {
log.info("No cached foreign token keys");
return bundleToReturn;
}
Map<String, String> bundles = config.getAllConfigs(true);
log.info("Key bundles retrieved: {}", bundles.size());
for (Entry<String, String> e : bundles.entrySet()) {
TokenKeysBundle bundle;
try {
bundle = (TokenKeysBundle) SerializerUtils.deserialize(e.getValue());
} catch (Exception ex) {
log.error("Could not deserialize token keys bundle", ex);
return null;
}
bundleToReturn.put(e.getKey(), bundle);
}
return bundleToReturn;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class InterVDCTokenCacheHelper method saveTokenKeysBundle.
/**
* Stores the token key bundle in cache (zookeeper path based on vdcid)
* Locks on vdcid for the write.
*
* @param vdcID
* @param bundle
*/
private synchronized void saveTokenKeysBundle(String vdcID, TokenKeysBundle bundle) {
InterProcessLock tokenBundleLock = null;
try {
tokenBundleLock = coordinator.getLock(FOREIGN_TOKEN_BUNDLE_CONFIG_LOCK);
if (tokenBundleLock == null) {
log.error("Could not acquire lock for tokenkeys bundle caching");
throw SecurityException.fatals.couldNotAcquireLockTokenCaching();
}
tokenBundleLock.acquire();
Configuration config = coordinator.queryConfiguration(FOREIGN_TOKEN_KEYS_BUNDLE_CONFIG, FOREIGN_TOKEN_KEYS_BUNDLE_KEYID);
ConfigurationImpl configImpl = null;
if (config == null) {
configImpl = new ConfigurationImpl();
configImpl.setId(FOREIGN_TOKEN_KEYS_BUNDLE_KEYID);
configImpl.setKind(FOREIGN_TOKEN_KEYS_BUNDLE_CONFIG);
log.debug("Creating new foreign tokens config");
} else {
configImpl = (ConfigurationImpl) config;
log.debug("Updating existing foreign token config");
}
configImpl.setConfig(vdcID, SerializerUtils.serializeAsBase64EncodedString(bundle));
coordinator.persistServiceConfiguration(configImpl);
foreignTokenKeysMap.put(vdcID, bundle);
} catch (Exception ex) {
log.error("Could not acquire lock while trying to cache tokenkeys bundle.", ex);
} finally {
try {
if (tokenBundleLock != null) {
tokenBundleLock.release();
}
} catch (Exception ex) {
log.error("Unable to release token keys bundle caching lock", ex);
}
}
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class InterVDCTokenCacheHelper method readTokenKeysBundle.
/**
* Reads from zk to get a TokenKeyBundle for the passed in vdc id.
* Updates the local cache map if found.
*
* @param vdcID
* @return
* @throws Exception
*/
private TokenKeysBundle readTokenKeysBundle(String vdcID) throws Exception {
Configuration config = coordinator.queryConfiguration(FOREIGN_TOKEN_KEYS_BUNDLE_CONFIG, FOREIGN_TOKEN_KEYS_BUNDLE_KEYID);
if (config == null || config.getConfig(vdcID) == null) {
log.info("Foreign token keys bundle not found for vdcid {}", vdcID);
return null;
}
String serializedBundle = config.getConfig(vdcID);
log.debug("Got foreign token keys bundle from coordinator: {}", vdcID);
TokenKeysBundle bundle = (TokenKeysBundle) SerializerUtils.deserialize(serializedBundle);
foreignTokenKeysMap.put(vdcID, bundle);
return bundle;
}
Aggregations