Search in sources :

Example 16 with Configuration

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

the class CoordinatorClientImpl method getTargetInfo.

private <T extends CoordinatorSerializable> T getTargetInfo(String siteId, final Class<T> clazz, String id, String kind) throws CoordinatorException {
    T info;
    try {
        info = clazz.newInstance();
    } catch (Exception e) {
        log.error("Failed to create instance according class {}, {}", clazz, e);
        throw CoordinatorException.fatals.unableToCreateInstanceOfTargetInfo(clazz.getName(), e);
    }
    final Configuration config = queryConfiguration(siteId, kind, id);
    if (config != null && config.getConfig(TARGET_INFO) != null) {
        final String infoStr = config.getConfig(TARGET_INFO);
        log.debug("getTargetInfo({}): info={}", clazz.getName(), Strings.repr(infoStr));
        final T decodeInfo = info.decodeFromString(infoStr);
        log.debug("getTargetInfo({}): info={}", clazz.getName(), decodeInfo);
        return decodeInfo;
    }
    return null;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 17 with Configuration

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

the class CoordinatorClientImpl method getPropertyInfo.

/**
 * Get property
 *
 * This method gets target properties from coordinator service as a string
 * and merges it with the defaults and the ovf properties
 * Syssvc is responsible for publishing the target property information into coordinator
 *
 * @return property object
 * @throws CoordinatorException
 */
@Override
public PropertyInfo getPropertyInfo() throws CoordinatorException {
    PropertyInfo info = new PropertyInfo();
    Map<String, String> defaults = new HashMap<String, String>((Map) defaultProperties);
    final Configuration config = queryConfiguration(TARGET_PROPERTY, TARGET_PROPERTY_ID);
    if (null == config || null == config.getConfig(TARGET_INFO)) {
        log.debug("getPropertyInfo(): no properties saved in coordinator returning defaults");
        info.setProperties(defaults);
    } else {
        final String infoStr = config.getConfig(TARGET_INFO);
        try {
            log.debug("getPropertyInfo(): properties saved in coordinator=" + Strings.repr(infoStr));
            info.setProperties(mergeProps(defaults, decodeFromString(infoStr).getProperties()));
        } catch (final Exception e) {
            throw CoordinatorException.fatals.unableToDecodeDataFromCoordinator(e);
        }
    }
    // add site specific properties
    PropertyInfoExt siteScopePropInfo = getTargetInfo(getSiteId(), PropertyInfoExt.class);
    if (siteScopePropInfo != null) {
        info.getProperties().putAll(siteScopePropInfo.getProperties());
    }
    // add the ovf properties
    info.getProperties().putAll((Map) ovfProperties);
    return info;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) PropertyInfo(com.emc.storageos.model.property.PropertyInfo) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 18 with Configuration

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

the class CoordinatorClientImpl method persistServiceConfiguration.

@Override
public void persistServiceConfiguration(String siteId, Configuration... configs) throws CoordinatorException {
    try {
        for (Configuration config : configs) {
            String configParentPath = getKindPath(siteId, config.getKind());
            EnsurePath path = new EnsurePath(configParentPath);
            path.ensure(_zkConnection.curator().getZookeeperClient());
            String servicePath = String.format("%1$s/%2$s", configParentPath, config.getId());
            Stat stat = _zkConnection.curator().checkExists().forPath(servicePath);
            CuratorTransaction handler = zkTransactionHandler.get();
            if (stat != null) {
                if (handler != null) {
                    CuratorTransactionFinal tx = handler.setData().forPath(servicePath, config.serialize()).and();
                    zkTransactionHandler.set(tx);
                } else {
                    _zkConnection.curator().setData().forPath(servicePath, config.serialize());
                }
            } else {
                if (handler != null) {
                    CuratorTransactionFinal tx = handler.create().forPath(servicePath, config.serialize()).and();
                    zkTransactionHandler.set(tx);
                } else {
                    _zkConnection.curator().create().forPath(servicePath, config.serialize());
                }
            }
        }
    } catch (final Exception e) {
        log.error("Failed to persist service configuration e=", e);
        throw CoordinatorException.fatals.unableToPersistTheConfiguration(e);
    }
}
Also used : EnsurePath(org.apache.curator.utils.EnsurePath) Stat(org.apache.zookeeper.data.Stat) Configuration(com.emc.storageos.coordinator.common.Configuration) CuratorTransaction(org.apache.curator.framework.api.transaction.CuratorTransaction) CuratorTransactionFinal(org.apache.curator.framework.api.transaction.CuratorTransactionFinal) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 19 with Configuration

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

the class CoordinatorClientImpl method queryAllConfiguration.

@Override
public List<Configuration> queryAllConfiguration(String siteId, String kind) throws CoordinatorException {
    String serviceParentPath = getKindPath(siteId, kind);
    List<String> configPaths;
    try {
        configPaths = _zkConnection.curator().getChildren().forPath(serviceParentPath);
    } catch (KeeperException.NoNodeException ignore) {
        // Ignore exception, don't re-throw
        log.debug("Caught exception but ignoring it: " + ignore);
        return Arrays.asList(new Configuration[0]);
    } catch (Exception e) {
        throw CoordinatorException.fatals.unableToListAllConfigurationForKind(kind, e);
    }
    List<Configuration> configs = new ArrayList<Configuration>(configPaths.size());
    for (String configPath : configPaths) {
        Configuration config = queryConfiguration(siteId, kind, configPath);
        if (config != null) {
            configs.add(config);
        }
    }
    return configs;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) ArrayList(java.util.ArrayList) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) KeeperException(org.apache.zookeeper.KeeperException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 20 with Configuration

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

the class SetupUtils method isSetupComplete.

public static boolean isSetupComplete() {
    if (StorageOsPlugin.isEnabled()) {
        CoordinatorClient coordinatorClient = StorageOsPlugin.getInstance().getCoordinatorClient();
        Configuration setupConfig = coordinatorClient.queryConfiguration(CONFIG_KIND, CONFIG_ID);
        complete = (setupConfig != null) && StringUtils.equals(setupConfig.getConfig(COMPLETE), Boolean.TRUE.toString());
    } else // In Dev mode we don't have coordinator so assume always setup
    if (Play.mode.isDev()) {
        complete = true;
    } else {
        complete = false;
    }
    return complete;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient)

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