Search in sources :

Example 31 with OrderedProperties

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

the class TestConfigurationWithoutDefaults method testJsonWithDuplicates.

@ParallelTest
public void testJsonWithDuplicates() {
    JsonObject configuration = new JsonObject().put("var1", "aaa").put("var2", "bbb").put("var3", "ccc").put("var2", "ddd");
    OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "ddd", "var1", "aaa");
    AbstractConfiguration config = new TestConfiguration(configuration);
    assertThat(config.asOrderedProperties(), is(expectedConfiguration));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 32 with OrderedProperties

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

the class TestConfigurationWithoutDefaults method testJsonWithForbiddenKeysPrefix.

@ParallelTest
public void testJsonWithForbiddenKeysPrefix() {
    JsonObject configuration = new JsonObject().put("var1", "aaa").put("var2", "bbb").put("var3", "ccc").put("forbidden.option.first", "ddd").put("forbidden.option.second", "ddd");
    OrderedProperties expectedConfiguration = createWithDefaults("var3", "ccc", "var2", "bbb", "var1", "aaa");
    AbstractConfiguration config = new TestConfiguration(configuration);
    assertThat(config.asOrderedProperties(), is(expectedConfiguration));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 33 with OrderedProperties

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

the class AbstractModel method getOrderedProperties.

/**
 * Read a config file and returns the properties in a deterministic order.
 *
 * @param reconciliation The reconciliation
 * @param configFileName The filename.
 * @return The OrderedProperties of the inputted file.
 */
public static OrderedProperties getOrderedProperties(Reconciliation reconciliation, String configFileName) {
    if (configFileName == null || configFileName.isEmpty()) {
        throw new IllegalArgumentException("configFileName must be non-empty string");
    }
    OrderedProperties properties = new OrderedProperties();
    InputStream is = AbstractModel.class.getResourceAsStream("/" + configFileName);
    if (is == null) {
        LOGGER.warnCr(reconciliation, "Cannot find resource '{}'", configFileName);
    } else {
        try {
            properties.addStringPairs(is);
        } catch (IOException e) {
            LOGGER.warnCr(reconciliation, "Unable to read default log config from '{}'", configFileName);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                LOGGER.errorCr(reconciliation, "Failed to close stream. Reason: " + e.getMessage());
            }
        }
    }
    return properties;
}
Also used : InputStream(java.io.InputStream) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) IOException(java.io.IOException)

Example 34 with OrderedProperties

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

the class ZookeeperPodSetTest method testPodSet.

@ParallelTest
public void testPodSet() {
    ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, KAFKA, VERSIONS);
    StrimziPodSet ps = zc.generatePodSet(3, true, null, null, Map.of());
    assertThat(ps.getMetadata().getName(), is(KafkaResources.zookeeperStatefulSetName(CLUSTER)));
    assertThat(ps.getMetadata().getLabels().entrySet().containsAll(zc.getLabelsWithStrimziName(zc.getName(), null).toMap().entrySet()), is(true));
    assertThat(ps.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_STORAGE), is(ModelUtils.encodeStorageToJson(new PersistentClaimStorageBuilder().withSize("100Gi").withDeleteClaim(false).build())));
    assertThat(ps.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(ps.getMetadata().getOwnerReferences().get(0), is(zc.createOwnerReference()));
    assertThat(ps.getSpec().getSelector().getMatchLabels(), is(zc.getSelectorLabels().toMap()));
    assertThat(ps.getSpec().getPods().size(), is(3));
    // We need to loop through the pods to make sure they have the right values
    List<Pod> pods = PodSetUtils.mapsToPods(ps.getSpec().getPods());
    for (Pod pod : pods) {
        assertThat(pod.getMetadata().getLabels().entrySet().containsAll(zc.getLabelsWithStrimziNameAndPodName(zc.getName(), pod.getMetadata().getName(), null).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(zc.getName()).toMap().entrySet()), is(true));
        assertThat(pod.getMetadata().getAnnotations().size(), is(1));
        assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
        assertThat(pod.getSpec().getHostname(), is(pod.getMetadata().getName()));
        assertThat(pod.getSpec().getSubdomain(), is(zc.getHeadlessServiceName()));
        assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
        assertThat(pod.getSpec().getTerminationGracePeriodSeconds(), is(30L));
        assertThat(pod.getSpec().getVolumes().stream().filter(volume -> volume.getName().equalsIgnoreCase("strimzi-tmp")).findFirst().orElse(null).getEmptyDir().getSizeLimit(), is(new Quantity(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_SIZE)));
        assertThat(pod.getSpec().getContainers().size(), is(1));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getInitialDelaySeconds(), is(15));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds(), is(15));
        assertThat(AbstractModel.containerEnvVars(pod.getSpec().getContainers().get(0)).get(ZookeeperCluster.ENV_VAR_STRIMZI_KAFKA_GC_LOG_ENABLED), is(Boolean.toString(AbstractModel.DEFAULT_JVM_GC_LOGGING_ENABLED)));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getName(), is(AbstractModel.VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/var/lib/zookeeper"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getName(), is("zookeeper-metrics-and-logging"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getMountPath(), is("/opt/kafka/custom-config/"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getName(), is(ZookeeperCluster.ZOOKEEPER_NODE_CERTIFICATES_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getMountPath(), is(ZookeeperCluster.ZOOKEEPER_NODE_CERTIFICATES_VOLUME_MOUNT));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getName(), is(ZookeeperCluster.ZOOKEEPER_CLUSTER_CA_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getMountPath(), is(ZookeeperCluster.ZOOKEEPER_CLUSTER_CA_VOLUME_MOUNT));
        // Config
        OrderedProperties expectedConfig = new OrderedProperties().addMapPairs(ZookeeperConfiguration.DEFAULTS);
        OrderedProperties actual = new OrderedProperties().addStringPairs(AbstractModel.containerEnvVars(pod.getSpec().getContainers().get(0)).get(ZookeeperCluster.ENV_VAR_ZOOKEEPER_CONFIGURATION));
        assertThat(actual, is(expectedConfig));
    }
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) ParallelSuite(io.strimzi.test.annotations.ParallelSuite) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) SecurityContextBuilder(io.fabric8.kubernetes.api.model.SecurityContextBuilder) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Collections.singletonMap(java.util.Collections.singletonMap) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PodRevision(io.strimzi.operator.cluster.operator.resource.PodRevision) Affinity(io.fabric8.kubernetes.api.model.Affinity) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Probe(io.strimzi.api.kafka.model.Probe) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest) Pod(io.fabric8.kubernetes.api.model.Pod) Toleration(io.fabric8.kubernetes.api.model.Toleration) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) List(java.util.List) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Pod(io.fabric8.kubernetes.api.model.Pod) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 35 with OrderedProperties

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

the class KafkaConnectApiTest method testChangeLoggers.

@IsolatedTest
public void testChangeLoggers(VertxTestContext context) throws InterruptedException {
    String desired = "log4j.rootLogger=TRACE, CONSOLE\n" + "log4j.logger.org.apache.zookeeper=WARN\n" + "log4j.logger.org.I0Itec.zkclient=INFO\n" + "log4j.logger.org.reflections.Reflection=INFO\n" + "log4j.logger.org.reflections=FATAL\n" + "log4j.logger.foo=WARN\n" + "log4j.logger.foo.bar=TRACE\n" + "log4j.logger.foo.bar.quux=DEBUG";
    KafkaConnectApi client = new KafkaConnectApiImpl(vertx);
    Checkpoint async = context.checkpoint();
    OrderedProperties ops = new OrderedProperties();
    ops.addStringPairs(desired);
    client.updateConnectLoggers(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, desired, ops).onComplete(context.succeeding(wasChanged -> context.verify(() -> assertEquals(true, wasChanged)))).compose(a -> client.listConnectLoggers(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT).onComplete(context.succeeding(map -> context.verify(() -> {
        assertThat(map.get("root"), is("TRACE"));
        assertThat(map.get("org.apache.zookeeper"), is("WARN"));
        assertThat(map.get("org.I0Itec.zkclient"), is("INFO"));
        assertThat(map.get("org.reflections"), is("FATAL"));
        assertThat(map.get("org.reflections.Reflection"), is("INFO"));
        assertThat(map.get("org.reflections.Reflection"), is("INFO"));
        assertThat(map.get("foo"), is("WARN"));
        assertThat(map.get("foo.bar"), is("TRACE"));
        assertThat(map.get("foo.bar.quux"), is("DEBUG"));
    })))).compose(a -> client.updateConnectLoggers(Reconciliation.DUMMY_RECONCILIATION, "localhost", PORT, desired, ops).onComplete(context.succeeding(wasChanged -> context.verify(() -> {
        assertEquals(false, wasChanged);
        async.flag();
    }))));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) BackOff(io.strimzi.operator.common.BackOff) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.not(org.hamcrest.Matchers.not) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) IsolatedTest(io.strimzi.test.annotations.IsolatedTest) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StrimziKafkaCluster(io.strimzi.test.container.StrimziKafkaCluster) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) Files(java.nio.file.Files) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) ConnectorPlugin(io.strimzi.api.kafka.model.connect.ConnectorPlugin) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) File(java.io.File) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Checkpoint(io.vertx.junit5.Checkpoint) Connect(org.apache.kafka.connect.runtime.Connect) Matchers.is(org.hamcrest.Matchers.is) Handler(io.vertx.core.Handler) Matchers.containsString(org.hamcrest.Matchers.containsString) ConnectDistributed(org.apache.kafka.connect.cli.ConnectDistributed) Checkpoint(io.vertx.junit5.Checkpoint) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) IsolatedTest(io.strimzi.test.annotations.IsolatedTest)

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