Search in sources :

Example 56 with Configuration

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;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration)

Example 57 with Configuration

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;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration)

Example 58 with Configuration

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;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) TokenKeysBundle(com.emc.storageos.security.authentication.TokenKeyGenerator.TokenKeysBundle) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SecurityException(com.emc.storageos.security.exceptions.SecurityException)

Example 59 with Configuration

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);
        }
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl) SecurityException(com.emc.storageos.security.exceptions.SecurityException)

Example 60 with Configuration

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;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) TokenKeysBundle(com.emc.storageos.security.authentication.TokenKeyGenerator.TokenKeysBundle)

Aggregations

Configuration (com.emc.storageos.coordinator.common.Configuration)87 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)16 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)11 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)9 IOException (java.io.IOException)9 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)8 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)8 Site (com.emc.storageos.coordinator.client.model.Site)7 UnknownHostException (java.net.UnknownHostException)7 KeeperException (org.apache.zookeeper.KeeperException)7 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)3 MigrationStatus (com.emc.storageos.coordinator.client.model.MigrationStatus)2 PropertyInfoExt (com.emc.storageos.coordinator.client.model.PropertyInfoExt)2 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)2 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)2 SiteConfigRestRep (com.emc.storageos.model.dr.SiteConfigRestRep)2