use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.
the class KafkaConnectAssemblyOperatorTest method testUpdateClusterFailure.
@Test
public void testUpdateClusterFailure(TestContext context) {
ConfigMapOperator mockCmOps = mock(ConfigMapOperator.class);
ServiceOperator mockServiceOps = mock(ServiceOperator.class);
DeploymentOperator mockDcOps = mock(DeploymentOperator.class);
String clusterCmName = "foo";
String clusterCmNamespace = "test";
ConfigMap clusterCm = ResourceUtils.createEmptyKafkaConnectClusterConfigMap(clusterCmNamespace, clusterCmName);
KafkaConnectCluster connect = KafkaConnectCluster.fromConfigMap(clusterCm);
// Change the image to generate some diff
clusterCm.getData().put("image", "some/different:image");
when(mockCmOps.get(clusterCmNamespace, clusterCmName)).thenReturn(clusterCm);
when(mockServiceOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateService());
when(mockDcOps.get(clusterCmNamespace, connect.getName())).thenReturn(connect.generateDeployment());
ArgumentCaptor<String> serviceNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
when(mockServiceOps.reconcile(serviceNamespaceCaptor.capture(), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
when(mockDcOps.reconcile(dcNamespaceCaptor.capture(), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.failedFuture("Failed"));
ArgumentCaptor<String> dcScaleUpNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleUp(dcScaleUpNamespaceCaptor.capture(), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
ArgumentCaptor<String> dcScaleDownNamespaceCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
when(mockDcOps.scaleDown(dcScaleDownNamespaceCaptor.capture(), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaConnectAssemblyOperator ops = new KafkaConnectAssemblyOperator(vertx, true, mockCmOps, mockDcOps, mockServiceOps);
Async async = context.async();
ops.createOrUpdate(new Reconciliation("test-trigger", AssemblyType.CONNECT, clusterCmNamespace, clusterCmName), clusterCm, createResult -> {
context.assertFalse(createResult.succeeded());
async.complete();
});
}
use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.
the class ResourceUtils method createKafkaConnectS2IClusterConfigMap.
/**
* Generate ConfigMap for Kafka Connect S2I cluster
*/
public static ConfigMap createKafkaConnectS2IClusterConfigMap(String clusterCmNamespace, String clusterCmName, int replicas, String image, int healthDelay, int healthTimeout, String bootstrapServers, String groupID, int configReplicationFactor, int offsetReplicationFactor, int statusReplicationFactor, String keyConverter, String valueConverter, boolean keyConverterSchemas, boolean valuesConverterSchema) {
Map<String, String> cmData = new HashMap<>();
cmData.put(KafkaConnectS2ICluster.KEY_IMAGE, image);
cmData.put(KafkaConnectS2ICluster.KEY_REPLICAS, Integer.toString(replicas));
cmData.put(KafkaConnectS2ICluster.KEY_HEALTHCHECK_DELAY, Integer.toString(healthDelay));
cmData.put(KafkaConnectS2ICluster.KEY_HEALTHCHECK_TIMEOUT, Integer.toString(healthTimeout));
cmData.put(KafkaConnectS2ICluster.KEY_BOOTSTRAP_SERVERS, bootstrapServers);
cmData.put(KafkaConnectS2ICluster.KEY_GROUP_ID, groupID);
cmData.put(KafkaConnectS2ICluster.KEY_CONFIG_STORAGE_REPLICATION_FACTOR, Integer.toString(configReplicationFactor));
cmData.put(KafkaConnectS2ICluster.KEY_OFFSET_STORAGE_REPLICATION_FACTOR, Integer.toString(offsetReplicationFactor));
cmData.put(KafkaConnectS2ICluster.KEY_STATUS_STORAGE_REPLICATION_FACTOR, Integer.toString(statusReplicationFactor));
cmData.put(KafkaConnectS2ICluster.KEY_KEY_CONVERTER, keyConverter);
cmData.put(KafkaConnectS2ICluster.KEY_KEY_CONVERTER_SCHEMAS_EXAMPLE, Boolean.toString(keyConverterSchemas));
cmData.put(KafkaConnectS2ICluster.KEY_VALUE_CONVERTER, valueConverter);
cmData.put(KafkaConnectS2ICluster.KEY_VALUE_CONVERTER_SCHEMAS_EXAMPLE, Boolean.toString(valuesConverterSchema));
ConfigMap cm = createEmptyKafkaConnectS2IClusterConfigMap(clusterCmNamespace, clusterCmName);
cm.setData(cmData);
return cm;
}
use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.
the class ResourceUtils method createKafkaClusterConfigMap.
public static ConfigMap createKafkaClusterConfigMap(String clusterCmNamespace, String clusterCmName, int replicas, String image, int healthDelay, int healthTimeout, String metricsCmJson, String storage, String topicController) {
Map<String, String> cmData = new HashMap<>();
cmData.put(KafkaCluster.KEY_REPLICAS, Integer.toString(replicas));
cmData.put(KafkaCluster.KEY_IMAGE, image);
cmData.put(KafkaCluster.KEY_HEALTHCHECK_DELAY, Integer.toString(healthDelay));
cmData.put(KafkaCluster.KEY_HEALTHCHECK_TIMEOUT, Integer.toString(healthTimeout));
cmData.put(KafkaCluster.KEY_STORAGE, storage);
cmData.put(KafkaCluster.KEY_METRICS_CONFIG, metricsCmJson);
cmData.put(ZookeeperCluster.KEY_REPLICAS, Integer.toString(replicas));
cmData.put(ZookeeperCluster.KEY_IMAGE, image + "-zk");
cmData.put(ZookeeperCluster.KEY_HEALTHCHECK_DELAY, Integer.toString(healthDelay));
cmData.put(ZookeeperCluster.KEY_HEALTHCHECK_TIMEOUT, Integer.toString(healthTimeout));
cmData.put(ZookeeperCluster.KEY_STORAGE, storage);
cmData.put(ZookeeperCluster.KEY_METRICS_CONFIG, metricsCmJson);
if (topicController != null) {
cmData.put(TopicController.KEY_CONFIG, topicController);
}
return new ConfigMapBuilder().withNewMetadata().withName(clusterCmName).withNamespace(clusterCmNamespace).withLabels(Labels.userLabels(singletonMap("my-user-label", "cromulent")).withKind("cluster").withType(AssemblyType.KAFKA).toMap()).endMetadata().withData(cmData).build();
}
use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.
the class TopicControllerTest method testFromConfigMapDefaultConfig.
@Test
public void testFromConfigMapDefaultConfig() {
ConfigMap cm = ResourceUtils.createKafkaClusterConfigMap(namespace, cluster, replicas, image, healthDelay, healthTimeout, metricsCmJson, storageJson, "{ }");
TopicController tc = TopicController.fromConfigMap(cm);
assertEquals(TopicController.DEFAULT_IMAGE, tc.getImage());
assertEquals(namespace, tc.getWatchedNamespace());
assertEquals(TopicController.DEFAULT_FULL_RECONCILIATION_INTERVAL_MS, tc.getReconciliationIntervalMs());
assertEquals(TopicController.DEFAULT_ZOOKEEPER_SESSION_TIMEOUT_MS, tc.getZookeeperSessionTimeoutMs());
assertEquals(TopicController.defaultBootstrapServers(cluster), tc.getKafkaBootstrapServers());
assertEquals(TopicController.defaultZookeeperConnect(cluster), tc.getZookeeperConnect());
assertEquals(TopicController.defaultTopicConfigMapLabels(cluster), tc.getTopicConfigMapLabels());
assertEquals(TopicController.DEFAULT_TOPIC_METADATA_MAX_ATTEMPTS, tc.getTopicMetadataMaxAttempts());
}
use of io.fabric8.docker.api.model.Image in project strimzi by strimzi.
the class TopicControllerTest method testFromConfigMapNoConfig.
@Test
public void testFromConfigMapNoConfig() {
ConfigMap cm = ResourceUtils.createKafkaClusterConfigMap(namespace, cluster, replicas, image, healthDelay, healthTimeout, metricsCmJson);
TopicController tc = TopicController.fromConfigMap(cm);
assertNull(tc);
}
Aggregations