Search in sources :

Example 1 with ConfigValue

use of de.cinovo.cloudconductor.api.model.ConfigValue in project cloudconductor-agent-redhat by cinovo.

the class ServerCom method getConfig.

/**
 * @return the config for this agent
 * @throws CloudConductorException error if retrieval fails
 */
public static Map<String, String> getConfig() throws CloudConductorException {
    Map<String, String> configMap = new HashMap<>();
    try {
        for (ConfigValue c : ServerCom.config.getConfig(AgentState.info().getTemplate(), AgentVars.SERVICE_NAME)) {
            if ((c.getService() != null) && c.getService().equals(AgentVars.SERVICE_NAME)) {
                ServerCom.LOGGER.debug("Add config: " + c.getKey() + ": " + c.getValue());
                configMap.put(c.getKey(), (String) c.getValue());
            }
        }
    } catch (RuntimeException e) {
        ServerCom.LOGGER.error("Error getting config from server: ", e);
        throw new CloudConductorException(e.getMessage());
    }
    return configMap;
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) ConfigValue(de.cinovo.cloudconductor.api.model.ConfigValue) HashMap(java.util.HashMap)

Example 2 with ConfigValue

use of de.cinovo.cloudconductor.api.model.ConfigValue in project cloudconductor-agent-redhat by cinovo.

the class ConfigValueHandler method getConfig.

/**
 * @param template the template name
 * @param service the serice name
 * @return map containing config kv-pairs of the service
 * @throws CloudConductorException Error indicating connection or data problems
 */
@SuppressWarnings("unchecked")
public List<ConfigValue> getConfig(String template, String service) throws CloudConductorException {
    String path = this.pathGenerator("/config/{template}/{service}", template, service);
    ConfigValueHandler.LOGGER.debug("Receive config from '" + path + "'...");
    JavaType type = AbstractApiHandler.mapper.getTypeFactory().constructCollectionLikeType(ArrayList.class, ConfigValue.class);
    List<ConfigValue> configList = (ArrayList<ConfigValue>) this._get(path, type);
    return configList;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ConfigValue(de.cinovo.cloudconductor.api.model.ConfigValue) ArrayList(java.util.ArrayList)

Aggregations

ConfigValue (de.cinovo.cloudconductor.api.model.ConfigValue)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1