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));
}
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));
}
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;
}
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));
}
}
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();
}))));
}
Aggregations