All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodic.kubernetes.confcenter.ConfigUtils Maven / Gradle / Ivy

package org.zodic.kubernetes.confcenter;

import io.fabric8.kubernetes.client.KubernetesClient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;
import org.zodic.kubernetes.base.constants.KubernetesConstants;

public final class ConfigUtils {

    private static final Logger LOG = LoggerFactory.getLogger(ConfigUtils.class);

    private ConfigUtils() {
        throw new IllegalStateException("Can't instantiate a utility class");
    }

    public static  String getApplicationName(Environment env, String configName,
        String configurationTarget) {
        String name = configName;
        if (StrUtil.isEmpty(name)) {
            // TODO: use relaxed binding
            if (LOG.isDebugEnabled()) {
                LOG.debug("{} name has not been set, taking it from property/env {} (default={})",
                    configurationTarget, SystemPropertiesConstants.Spring.SPRING_APP_NAME, KubernetesConstants.FALLBACK_APPLICATION_NAME);
            }

            name = env.getProperty(SystemPropertiesConstants.Spring.SPRING_APP_NAME, KubernetesConstants.FALLBACK_APPLICATION_NAME);
        }

        return name;
    }

    public static  String getApplicationNamespace(Environment env, KubernetesClient client,
        String configNamespace, String configurationTarget) {
        String namespace = configNamespace;
        if (StrUtil.isEmpty(namespace)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("{} namespace has not been set, taking it from client (ns={})",
                    configurationTarget, client.getNamespace());
            }

            namespace = env.getProperty(SystemPropertiesConstants.Zodiac.SPRING_APP_GROUP, client.getNamespace());
        }

        return namespace;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy