Search in sources :

Example 66 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class SignatureKeyGenerator method getSignatureKey2.

/**
 * getSignatureKey2 (keeping the original getSignature() as deprecated because portal uses this method from
 * our jar still).
 *
 * @param relKeyLocation "leaf" node under \getSignatureKeyConfig()\getSignatureKeyId()\
 * @param algo algorithm to use for that key
 * @return the key
 * @throws Exception
 */
protected synchronized SecretKey getSignatureKey2(String relKeyLocation, String algo) throws Exception {
    Configuration config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
    if (config != null && config.getConfig(relKeyLocation) != null) {
        final String encodedKey = config.getConfig(relKeyLocation);
        return SignatureHelper.createKey(encodedKey, algo);
    } else {
        InterProcessLock lock = null;
        try {
            lock = _coordinator.getLock(getDistributedSignatureKeyLock());
            lock.acquire();
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            ConfigurationImpl cfg = (ConfigurationImpl) config;
            if (cfg == null) {
                cfg = new ConfigurationImpl();
                cfg.setId(getSignatureKeyId());
                cfg.setKind(getSignatureKeyConfig());
            }
            String keyEncoded = SignatureHelper.generateKey(algo);
            cfg.setConfig(relKeyLocation, keyEncoded);
            _coordinator.persistServiceConfiguration(cfg);
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            final String encodedKey = config.getConfig(relKeyLocation);
            return SignatureHelper.createKey(encodedKey, algo);
        } finally {
            if (lock != null) {
                lock.release();
            }
        }
    }
}
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)

Example 67 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class SignatureKeyGenerator method getSignatureKey.

/**
 * TODO: DELETE in phase 2 when UI has switched to LoginSignatureKeyGenerator api.
 * Used by the UI to get a key.
 *
 * @param algo
 * @return
 * @throws Exception
 */
@Deprecated
public synchronized SecretKey getSignatureKey(String algo) throws Exception {
    Configuration config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
    if (config != null && config.getConfig(getSignatureKey()) != null) {
        final String encodedKey = config.getConfig(getSignatureKey());
        return new SignatureHelper().createKey(encodedKey, algo);
    } else {
        InterProcessLock lock = null;
        try {
            lock = _coordinator.getLock(getDistributedSignatureKeyLock());
            lock.acquire();
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            if (config == null || config.getConfig(getSignatureKey()) == null) {
                ConfigurationImpl cfg = new ConfigurationImpl();
                cfg.setId(getSignatureKeyId());
                cfg.setKind(getSignatureKeyConfig());
                String keyEncoded = SignatureHelper.generateKey(algo);
                cfg.setConfig(getSignatureKey(), keyEncoded);
                _coordinator.persistServiceConfiguration(cfg);
            }
            config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
            final String encodedKey = config.getConfig(getSignatureKey());
            return SignatureHelper.createKey(encodedKey, algo);
        } finally {
            if (lock != null) {
                lock.release();
            }
        }
    }
}
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)

Example 68 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class TokenKeyGenerator method createOrUpdateBundle.

// Coordinator client interraction for persistence
/**
 * Creates or updates a TokenKeysBundle in coordinator.
 *
 * @param bundleIn: bundle to persist
 *            MUST BE CALLED BY A CODE OWNING INTERPROCESS LOCK
 * @throws Exception
 */
private synchronized void createOrUpdateBundle(TokenKeysBundle bundleIn) throws Exception {
    Configuration config = _coordinator.queryConfiguration(SIGNATURE_KEY_CONFIG, SIGNATURE_KEY_ID);
    ConfigurationImpl configImpl = null;
    if (config == null) {
        configImpl = new ConfigurationImpl();
        configImpl.setId(SIGNATURE_KEY_ID);
        configImpl.setKind(SIGNATURE_KEY_CONFIG);
        _log.debug("Creating new config");
    } else {
        configImpl = (ConfigurationImpl) config;
        _log.debug("Updating existing config");
    }
    configImpl.setConfig(SIGNATURE_KEY, SerializerUtils.serializeAsBase64EncodedString(bundleIn));
    _coordinator.persistServiceConfiguration(configImpl);
    _log.debug("Updated keys bundle successfully");
    return;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl)

Example 69 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class TokenKeyGenerator method readBundle.

/**
 * Reads the TokenKeysBundle from coordinator and deserializes it.
 *
 * @return the retrieved bundle or null if not found
 * @throws Exception
 */
public TokenKeysBundle readBundle() throws Exception {
    Configuration config = _coordinator.queryConfiguration(SIGNATURE_KEY_CONFIG, SIGNATURE_KEY_ID);
    if (config == null || config.getConfig(SIGNATURE_KEY) == null) {
        _log.warn("Token keys bundle not found");
        return null;
    }
    String serializedBundle = config.getConfig(SIGNATURE_KEY);
    _log.debug("Read bundle from coordinator: {}", serializedBundle);
    return (TokenKeysBundle) SerializerUtils.deserialize(serializedBundle);
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration)

Example 70 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class StubCoordinatorClientImpl method persistServiceConfiguration.

@Override
public void persistServiceConfiguration(Configuration... config) {
    for (int i = 0; i < config.length; i++) {
        Configuration c = config[i];
        _configMap.put(getKey(c.getKind(), c.getId()), c);
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration)

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