Search in sources :

Example 46 with OrderedProperties

use of io.strimzi.operator.common.model.OrderedProperties in project strimzi by strimzi.

the class AbstractModel method parseLogging.

/**
 * @param logging The Logging to parse.
 * @param externalCm The external ConfigMap, used if Logging is an instance of ExternalLogging
 * @return The logging properties as a String in log4j/2 properties file format.
 */
public String parseLogging(Logging logging, ConfigMap externalCm) {
    if (logging instanceof InlineLogging) {
        InlineLogging inlineLogging = (InlineLogging) logging;
        OrderedProperties newSettings = getDefaultLogConfig();
        if (inlineLogging.getLoggers() != null) {
            // Inline logging as specified and some loggers are configured
            if (shouldPatchLoggerAppender()) {
                String rootAppenderName = getRootAppenderNamesFromDefaultLoggingConfig(newSettings);
                String newRootLogger = inlineLogging.getLoggers().get("log4j.rootLogger");
                newSettings.addMapPairs(inlineLogging.getLoggers());
                if (newRootLogger != null && !rootAppenderName.isEmpty() && !newRootLogger.contains(",")) {
                    // this should never happen as appender name is added in default configuration
                    LOGGER.debugCr(reconciliation, "Newly set rootLogger does not contain appender. Setting appender to {}.", rootAppenderName);
                    String level = newSettings.asMap().get("log4j.rootLogger");
                    newSettings.addPair("log4j.rootLogger", level + ", " + rootAppenderName);
                }
            } else {
                newSettings.addMapPairs(inlineLogging.getLoggers());
            }
        }
        return createLog4jProperties(newSettings);
    } else if (logging instanceof ExternalLogging) {
        ExternalLogging externalLogging = (ExternalLogging) logging;
        if (externalLogging.getValueFrom() != null && externalLogging.getValueFrom().getConfigMapKeyRef() != null && externalLogging.getValueFrom().getConfigMapKeyRef().getKey() != null) {
            if (externalCm != null && externalCm.getData() != null && externalCm.getData().containsKey(externalLogging.getValueFrom().getConfigMapKeyRef().getKey())) {
                return maybeAddMonitorIntervalToExternalLogging(externalCm.getData().get(externalLogging.getValueFrom().getConfigMapKeyRef().getKey()));
            } else {
                throw new InvalidResourceException(String.format("ConfigMap %s with external logging configuration does not exist or doesn't contain the configuration under the %s key.", externalLogging.getValueFrom().getConfigMapKeyRef().getName(), externalLogging.getValueFrom().getConfigMapKeyRef().getKey()));
            }
        } else {
            throw new InvalidResourceException("Property logging.valueFrom has to be specified when using external logging.");
        }
    } else {
        LOGGER.debugCr(reconciliation, "logging is not set, using default loggers");
        return createLog4jProperties(getDefaultLogConfig());
    }
}
Also used : ExternalLogging(io.strimzi.api.kafka.model.ExternalLogging) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InlineLogging(io.strimzi.api.kafka.model.InlineLogging)

Aggregations

OrderedProperties (io.strimzi.operator.common.model.OrderedProperties)46 ParallelTest (io.strimzi.test.annotations.ParallelTest)24 Map (java.util.Map)20 Reconciliation (io.strimzi.operator.common.Reconciliation)16 JsonObject (io.vertx.core.json.JsonObject)16 ArrayList (java.util.ArrayList)14 List (java.util.List)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)12 LabelSelectorBuilder (io.fabric8.kubernetes.api.model.LabelSelectorBuilder)12 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)12 Collections (java.util.Collections)10 Collections.emptyMap (java.util.Collections.emptyMap)10 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 HostAlias (io.fabric8.kubernetes.api.model.HostAlias)8 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 PodSecurityContextBuilder (io.fabric8.kubernetes.api.model.PodSecurityContextBuilder)8 Quantity (io.fabric8.kubernetes.api.model.Quantity)8 Secret (io.fabric8.kubernetes.api.model.Secret)8 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)8