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

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

package org.zodic.kubernetes.confcenter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.zodiac.sdk.toolkit.util.collection.CollUtil;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;

public class ConfigMapConfigInfo extends AbstractConfCenterInfo {

    private static final String TARGET = "Config Map";

    private boolean enableApi = true;

    private List paths = CollUtil.linkedList();

    private List sources = CollUtil.linkedList();

    public ConfigMapConfigInfo() {}

    public boolean isEnableApi() {
        return this.enableApi;
    }

    public void setEnableApi(boolean enableApi) {
        this.enableApi = enableApi;
    }

    public List getPaths() {
        return this.paths;
    }

    public void setPaths(List paths) {
        this.paths = paths;
    }

    public List getSources() {
        return this.sources;
    }

    public void setSources(List sources) {
        this.sources = sources;
    }

    /**
     * @return A list of Source to use If the user has not specified any Source configReloadInfo, then a single Source is
     *         constructed based on the supplied name and namespace
     *
     *         These are the actual name/namespace pairs that are used to create a ConfigMapPropertySource
     */
    public List determineSources() {
        if (this.sources.isEmpty()) {
            return new ArrayList() {
                private static final long serialVersionUID = -3577539942893047837L;

                {
                    add(new NormalizedSource(ConfigMapConfigInfo.this.name, ConfigMapConfigInfo.this.namespace));
                }
            };
        }

        return this.sources.stream().map(s -> s.normalize(this.name, this.namespace)).collect(Collectors.toList());
    }

    @Override
    public String getConfigurationTarget() {
        return TARGET;
    }

    /**
     * Config map source.
     */
    public static class Source {

        /**
         * The name of the ConfigMap.
         */
        private String name;

        /**
         * The namespace where the ConfigMap is found.
         */
        private String namespace;

        public Source() {}

        public Source(String name, String namespace) {
            this.name = name;
            this.namespace = namespace;
        }

        public String getName() {
            return this.name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getNamespace() {
            return this.namespace;
        }

        public void setNamespace(String namespace) {
            this.namespace = namespace;
        }

        public boolean isEmpty() {
            return StrUtil.isEmpty(this.name) && StrUtil.isEmpty(this.namespace);
        }

        public NormalizedSource normalize(String defaultName, String defaultNamespace) {
            final String normalizedName = StrUtil.isEmpty(this.name) ? defaultName : this.name;
            final String normalizedNamespace = StrUtil.isEmpty(this.namespace) ? defaultNamespace : this.namespace;

            return new NormalizedSource(normalizedName, normalizedNamespace);
        }

    }

    static class NormalizedSource {

        private final String name;

        private final String namespace;

        NormalizedSource(String name, String namespace) {
            this.name = name;
            this.namespace = namespace;
        }

        public String getName() {
            return this.name;
        }

        public String getNamespace() {
            return this.namespace;
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy