use of io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder in project strimzi by strimzi.
the class KafkaConnectDockerfileTest method testNoUrlWhenRequired.
@ParallelTest
public void testNoUrlWhenRequired() {
Artifact tgzArtifact = new TgzArtifactBuilder().build();
Artifact jarArtifact = new JarArtifactBuilder().build();
Artifact zipArtifact = new ZipArtifactBuilder().build();
Artifact otherArtifact = new OtherArtifactBuilder().build();
Build connectBuildTgz = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(tgzArtifact)).build()).build();
Throwable e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildTgz));
assertThat(e.getMessage(), is("`tgz` artifact is missing a URL."));
Build connectBuildZip = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(zipArtifact)).build()).build();
e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildZip));
assertThat(e.getMessage(), is("`zip` artifact is missing a URL."));
Build connectBuildJar = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(jarArtifact)).build()).build();
e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildJar));
assertThat(e.getMessage(), is("`jar` artifact is missing a URL."));
Build connectBuildOther = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(otherArtifact)).build()).build();
e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildOther));
assertThat(e.getMessage(), is("`other` artifact is missing a URL."));
}
use of io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder in project strimzi by strimzi.
the class ConnectBuilderIsolatedST method testUpdateConnectWithAnotherPlugin.
@ParallelTest
void testUpdateConnectWithAnotherPlugin(ExtensionContext extensionContext) {
String connectClusterName = mapWithClusterNames.get(extensionContext.getDisplayName()) + "-connect";
String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
String echoConnector = "echo-sink-connector";
String camelConnector = "camel-http-connector";
final String imageName = getImageNameForTestCase();
Plugin secondPlugin = new PluginBuilder().withName("camel-connector").withArtifacts(new TgzArtifactBuilder().withUrl(CAMEL_CONNECTOR_TGZ_URL).withSha512sum(CAMEL_CONNECTOR_TGZ_CHECKSUM).build()).build();
String topicName = KafkaTopicUtils.generateRandomNameOfTopic();
resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(INFRA_NAMESPACE, topicName).build());
resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
String kafkaClientsPodName = kubeClient().listPodsByPrefixInName(kafkaClientsName).get(0).getMetadata().getName();
resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, connectClusterName, INFRA_NAMESPACE, INFRA_NAMESPACE, 1, true).editMetadata().addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().editOrNewSpec().addToConfig("key.converter.schemas.enable", false).addToConfig("value.converter.schemas.enable", false).addToConfig("key.converter", "org.apache.kafka.connect.storage.StringConverter").addToConfig("value.converter", "org.apache.kafka.connect.storage.StringConverter").withNewBuild().withPlugins(PLUGIN_WITH_TAR_AND_JAR).withNewDockerOutput().withImage(imageName).endDockerOutput().endBuild().withNewInlineLogging().addToLoggers("connect.root.logger.level", "INFO").endInlineLogging().endSpec().build());
Map<String, Object> echoSinkConfig = new HashMap<>();
echoSinkConfig.put("topics", topicName);
echoSinkConfig.put("level", "INFO");
LOGGER.info("Creating EchoSink connector");
resourceManager.createResource(extensionContext, KafkaConnectorTemplates.kafkaConnector(echoConnector, connectClusterName).editOrNewSpec().withClassName(ECHO_SINK_CLASS_NAME).withConfig(echoSinkConfig).endSpec().build());
String deploymentName = KafkaConnectResources.deploymentName(connectClusterName);
Map<String, String> connectSnapshot = DeploymentUtils.depSnapshot(deploymentName);
LOGGER.info("Checking that KafkaConnect API contains EchoSink connector and not Camel-Telegram Connector class name");
String plugins = cmdKubeClient().execInPod(kafkaClientsPodName, "curl", "-X", "GET", "http://" + KafkaConnectResources.serviceName(connectClusterName) + ":8083/connector-plugins").out();
assertFalse(plugins.contains(CAMEL_CONNECTOR_HTTP_SINK_CLASS_NAME));
assertTrue(plugins.contains(ECHO_SINK_CLASS_NAME));
LOGGER.info("Adding one more connector to the KafkaConnect");
KafkaConnectResource.replaceKafkaConnectResource(connectClusterName, kafkaConnect -> {
kafkaConnect.getSpec().getBuild().getPlugins().add(secondPlugin);
});
DeploymentUtils.waitTillDepHasRolled(deploymentName, 1, connectSnapshot);
Map<String, Object> camelHttpConfig = new HashMap<>();
camelHttpConfig.put("camel.sink.path.httpUri", "http://" + KafkaConnectResources.serviceName(connectClusterName) + ":8083");
camelHttpConfig.put("topics", topicName);
LOGGER.info("Creating Camel-HTTP-Sink connector");
resourceManager.createResource(extensionContext, KafkaConnectorTemplates.kafkaConnector(camelConnector, connectClusterName).editOrNewSpec().withClassName(CAMEL_CONNECTOR_HTTP_SINK_CLASS_NAME).withConfig(camelHttpConfig).endSpec().build());
KafkaConnect kafkaConnect = KafkaConnectResource.kafkaConnectClient().inNamespace(INFRA_NAMESPACE).withName(connectClusterName).get();
LOGGER.info("Checking if both Connectors were created and Connect contains both plugins");
assertThat(kafkaConnect.getSpec().getBuild().getPlugins().size(), is(2));
assertTrue(kafkaConnect.getStatus().getConnectorPlugins().stream().anyMatch(connectorPlugin -> connectorPlugin.getConnectorClass().contains(ECHO_SINK_CLASS_NAME)));
assertTrue(kafkaConnect.getStatus().getConnectorPlugins().stream().anyMatch(connectorPlugin -> connectorPlugin.getConnectorClass().contains(CAMEL_CONNECTOR_HTTP_SINK_CLASS_NAME)));
}
use of io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaConnectDockerfileTest method testNoUrlWhenRequired.
@ParallelTest
public void testNoUrlWhenRequired() {
Artifact tgzArtifact = new TgzArtifactBuilder().build();
Artifact jarArtifact = new JarArtifactBuilder().build();
Artifact zipArtifact = new ZipArtifactBuilder().build();
Artifact otherArtifact = new OtherArtifactBuilder().build();
Build connectBuildTgz = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(tgzArtifact)).build()).build();
Throwable e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildTgz));
assertThat(e.getMessage(), is("`tgz` artifact is missing a URL."));
Build connectBuildZip = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(zipArtifact)).build()).build();
e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildZip));
assertThat(e.getMessage(), is("`zip` artifact is missing a URL."));
Build connectBuildJar = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(jarArtifact)).build()).build();
e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildJar));
assertThat(e.getMessage(), is("`jar` artifact is missing a URL."));
Build connectBuildOther = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(singletonList(otherArtifact)).build()).build();
e = assertThrows(InvalidConfigurationException.class, () -> new KafkaConnectDockerfile("myImage:latest", connectBuildOther));
assertThat(e.getMessage(), is("`other` artifact is missing a URL."));
}
use of io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder in project strimzi-kafka-operator by strimzi.
the class ConnectBuilderIsolatedST method testUpdateConnectWithAnotherPlugin.
@ParallelTest
void testUpdateConnectWithAnotherPlugin(ExtensionContext extensionContext) {
String connectClusterName = mapWithClusterNames.get(extensionContext.getDisplayName()) + "-connect";
String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
String echoConnector = "echo-sink-connector";
String camelConnector = "camel-http-connector";
final String imageName = getImageNameForTestCase();
Plugin secondPlugin = new PluginBuilder().withName("camel-connector").withArtifacts(new TgzArtifactBuilder().withUrl(CAMEL_CONNECTOR_TGZ_URL).withSha512sum(CAMEL_CONNECTOR_TGZ_CHECKSUM).build()).build();
String topicName = KafkaTopicUtils.generateRandomNameOfTopic();
resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(INFRA_NAMESPACE, topicName).build());
resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
String kafkaClientsPodName = kubeClient().listPodsByPrefixInName(kafkaClientsName).get(0).getMetadata().getName();
resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, connectClusterName, INFRA_NAMESPACE, INFRA_NAMESPACE, 1, true).editMetadata().addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").endMetadata().editOrNewSpec().addToConfig("key.converter.schemas.enable", false).addToConfig("value.converter.schemas.enable", false).addToConfig("key.converter", "org.apache.kafka.connect.storage.StringConverter").addToConfig("value.converter", "org.apache.kafka.connect.storage.StringConverter").withNewBuild().withPlugins(PLUGIN_WITH_TAR_AND_JAR).withNewDockerOutput().withImage(imageName).endDockerOutput().endBuild().withNewInlineLogging().addToLoggers("connect.root.logger.level", "INFO").endInlineLogging().endSpec().build());
Map<String, Object> echoSinkConfig = new HashMap<>();
echoSinkConfig.put("topics", topicName);
echoSinkConfig.put("level", "INFO");
LOGGER.info("Creating EchoSink connector");
resourceManager.createResource(extensionContext, KafkaConnectorTemplates.kafkaConnector(echoConnector, connectClusterName).editOrNewSpec().withClassName(ECHO_SINK_CLASS_NAME).withConfig(echoSinkConfig).endSpec().build());
String deploymentName = KafkaConnectResources.deploymentName(connectClusterName);
Map<String, String> connectSnapshot = DeploymentUtils.depSnapshot(deploymentName);
LOGGER.info("Checking that KafkaConnect API contains EchoSink connector and not Camel-Telegram Connector class name");
String plugins = cmdKubeClient().execInPod(kafkaClientsPodName, "curl", "-X", "GET", "http://" + KafkaConnectResources.serviceName(connectClusterName) + ":8083/connector-plugins").out();
assertFalse(plugins.contains(CAMEL_CONNECTOR_HTTP_SINK_CLASS_NAME));
assertTrue(plugins.contains(ECHO_SINK_CLASS_NAME));
LOGGER.info("Adding one more connector to the KafkaConnect");
KafkaConnectResource.replaceKafkaConnectResource(connectClusterName, kafkaConnect -> {
kafkaConnect.getSpec().getBuild().getPlugins().add(secondPlugin);
});
DeploymentUtils.waitTillDepHasRolled(deploymentName, 1, connectSnapshot);
Map<String, Object> camelHttpConfig = new HashMap<>();
camelHttpConfig.put("camel.sink.path.httpUri", "http://" + KafkaConnectResources.serviceName(connectClusterName) + ":8083");
camelHttpConfig.put("topics", topicName);
LOGGER.info("Creating Camel-HTTP-Sink connector");
resourceManager.createResource(extensionContext, KafkaConnectorTemplates.kafkaConnector(camelConnector, connectClusterName).editOrNewSpec().withClassName(CAMEL_CONNECTOR_HTTP_SINK_CLASS_NAME).withConfig(camelHttpConfig).endSpec().build());
KafkaConnect kafkaConnect = KafkaConnectResource.kafkaConnectClient().inNamespace(INFRA_NAMESPACE).withName(connectClusterName).get();
LOGGER.info("Checking if both Connectors were created and Connect contains both plugins");
assertThat(kafkaConnect.getSpec().getBuild().getPlugins().size(), is(2));
assertTrue(kafkaConnect.getStatus().getConnectorPlugins().stream().anyMatch(connectorPlugin -> connectorPlugin.getConnectorClass().contains(ECHO_SINK_CLASS_NAME)));
assertTrue(kafkaConnect.getStatus().getConnectorPlugins().stream().anyMatch(connectorPlugin -> connectorPlugin.getConnectorClass().contains(CAMEL_CONNECTOR_HTTP_SINK_CLASS_NAME)));
}
Aggregations