Search in sources :

Example 1 with OtherArtifactBuilder

use of io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder 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."));
}
Also used : ZipArtifactBuilder(io.strimzi.api.kafka.model.connect.build.ZipArtifactBuilder) Build(io.strimzi.api.kafka.model.connect.build.Build) TgzArtifactBuilder(io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) Artifact(io.strimzi.api.kafka.model.connect.build.Artifact) ZipArtifact(io.strimzi.api.kafka.model.connect.build.ZipArtifact) OtherArtifact(io.strimzi.api.kafka.model.connect.build.OtherArtifact) MavenArtifact(io.strimzi.api.kafka.model.connect.build.MavenArtifact) JarArtifact(io.strimzi.api.kafka.model.connect.build.JarArtifact) OtherArtifactBuilder(io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder) JarArtifactBuilder(io.strimzi.api.kafka.model.connect.build.JarArtifactBuilder) BuildBuilder(io.strimzi.api.kafka.model.connect.build.BuildBuilder) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 2 with OtherArtifactBuilder

use of io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder in project strimzi by strimzi.

the class ConnectBuilderIsolatedST method testBuildOtherPluginTypeWithAndWithoutFileName.

@ParallelTest
void testBuildOtherPluginTypeWithAndWithoutFileName(ExtensionContext extensionContext) {
    final String connectClusterName = mapWithClusterNames.get(extensionContext.getDisplayName()) + "-connect";
    String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String imageName = getImageNameForTestCase();
    String topicName = KafkaTopicUtils.generateRandomNameOfTopic();
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(INFRA_NAMESPACE, topicName).build());
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
    resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, connectClusterName, INFRA_NAMESPACE, INFRA_NAMESPACE, 1, false).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_OTHER_TYPE).withNewDockerOutput().withImage(imageName).endDockerOutput().endBuild().endSpec().build());
    String deploymentName = KafkaConnectResources.deploymentName(connectClusterName);
    Map<String, String> connectSnapshot = DeploymentUtils.depSnapshot(deploymentName);
    String connectPodName = kubeClient().listPods(connectClusterName, Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND).get(0).getMetadata().getName();
    LOGGER.info("Checking that plugin has correct file name: {}", ECHO_SINK_FILE_NAME);
    assertEquals(getPluginFileNameFromConnectPod(connectPodName), ECHO_SINK_FILE_NAME);
    final Plugin pluginWithoutFileName = new PluginBuilder().withName(PLUGIN_WITH_OTHER_TYPE_NAME).withArtifacts(new OtherArtifactBuilder().withUrl(ECHO_SINK_JAR_URL).withSha512sum(ECHO_SINK_JAR_CHECKSUM).build()).build();
    LOGGER.info("Removing file name from the plugin, hash should be used");
    KafkaConnectResource.replaceKafkaConnectResource(connectClusterName, connect -> {
        connect.getSpec().getBuild().setPlugins(Collections.singletonList(pluginWithoutFileName));
    });
    DeploymentUtils.waitTillDepHasRolled(deploymentName, 1, connectSnapshot);
    LOGGER.info("Checking that plugin has different name than before");
    connectPodName = kubeClient().listPods(connectClusterName, Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND).get(0).getMetadata().getName();
    String fileName = getPluginFileNameFromConnectPod(connectPodName);
    assertNotEquals(fileName, ECHO_SINK_FILE_NAME);
    assertEquals(fileName, Util.sha1Prefix(ECHO_SINK_JAR_URL));
}
Also used : PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) OtherArtifactBuilder(io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder) Plugin(io.strimzi.api.kafka.model.connect.build.Plugin) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 3 with OtherArtifactBuilder

use of io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder in project strimzi-kafka-operator by strimzi.

the class ConnectBuilderIsolatedST method testBuildOtherPluginTypeWithAndWithoutFileName.

@ParallelTest
void testBuildOtherPluginTypeWithAndWithoutFileName(ExtensionContext extensionContext) {
    final String connectClusterName = mapWithClusterNames.get(extensionContext.getDisplayName()) + "-connect";
    String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String imageName = getImageNameForTestCase();
    String topicName = KafkaTopicUtils.generateRandomNameOfTopic();
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(INFRA_NAMESPACE, topicName).build());
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(false, kafkaClientsName).build());
    resourceManager.createResource(extensionContext, KafkaConnectTemplates.kafkaConnect(extensionContext, connectClusterName, INFRA_NAMESPACE, INFRA_NAMESPACE, 1, false).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_OTHER_TYPE).withNewDockerOutput().withImage(imageName).endDockerOutput().endBuild().endSpec().build());
    String deploymentName = KafkaConnectResources.deploymentName(connectClusterName);
    Map<String, String> connectSnapshot = DeploymentUtils.depSnapshot(deploymentName);
    String connectPodName = kubeClient().listPods(connectClusterName, Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND).get(0).getMetadata().getName();
    LOGGER.info("Checking that plugin has correct file name: {}", ECHO_SINK_FILE_NAME);
    assertEquals(getPluginFileNameFromConnectPod(connectPodName), ECHO_SINK_FILE_NAME);
    final Plugin pluginWithoutFileName = new PluginBuilder().withName(PLUGIN_WITH_OTHER_TYPE_NAME).withArtifacts(new OtherArtifactBuilder().withUrl(ECHO_SINK_JAR_URL).withSha512sum(ECHO_SINK_JAR_CHECKSUM).build()).build();
    LOGGER.info("Removing file name from the plugin, hash should be used");
    KafkaConnectResource.replaceKafkaConnectResource(connectClusterName, connect -> {
        connect.getSpec().getBuild().setPlugins(Collections.singletonList(pluginWithoutFileName));
    });
    DeploymentUtils.waitTillDepHasRolled(deploymentName, 1, connectSnapshot);
    LOGGER.info("Checking that plugin has different name than before");
    connectPodName = kubeClient().listPods(connectClusterName, Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND).get(0).getMetadata().getName();
    String fileName = getPluginFileNameFromConnectPod(connectPodName);
    assertNotEquals(fileName, ECHO_SINK_FILE_NAME);
    assertEquals(fileName, Util.sha1Prefix(ECHO_SINK_JAR_URL));
}
Also used : PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) OtherArtifactBuilder(io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder) Plugin(io.strimzi.api.kafka.model.connect.build.Plugin) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 4 with OtherArtifactBuilder

use of io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder in project strimzi by strimzi.

the class KafkaConnectDockerfileTest method testInsecureArtifacts.

@ParallelTest
public void testInsecureArtifacts() {
    OtherArtifact art1 = new OtherArtifactBuilder((OtherArtifact) otherArtifactNoChecksum).withInsecure(true).build();
    ZipArtifact art2 = new ZipArtifactBuilder((ZipArtifact) zipArtifactWithChecksum).withInsecure(true).build();
    Build connectBuild = new BuildBuilder().withPlugins(new PluginBuilder().withName("my-connector-plugin").withArtifacts(art1, art2).build()).build();
    KafkaConnectDockerfile df = new KafkaConnectDockerfile("myImage:latest", connectBuild);
    assertThat(df.getDockerfile(), isEquivalent("FROM myImage:latest", "USER root:root", "RUN 'mkdir' '-p' '/opt/kafka/plugins/my-connector-plugin/90e04094' \\", "      && 'curl' '-k' '-L' '--output' '/opt/kafka/plugins/my-connector-plugin/90e04094.zip' 'https://mydomain.tld/my2.zip' \\", "      && 'echo' 'sha-512-checksum /opt/kafka/plugins/my-connector-plugin/90e04094.zip' > '/opt/kafka/plugins/my-connector-plugin/90e04094.zip.sha512' \\", "      && 'sha512sum' '--check' '/opt/kafka/plugins/my-connector-plugin/90e04094.zip.sha512' \\", "      && 'rm' '-f' '/opt/kafka/plugins/my-connector-plugin/90e04094.zip.sha512' \\", "      && 'unzip' '/opt/kafka/plugins/my-connector-plugin/90e04094.zip' '-d' '/opt/kafka/plugins/my-connector-plugin/90e04094' \\", "      && 'find' '/opt/kafka/plugins/my-connector-plugin/90e04094' '-type' 'l' | 'xargs' 'rm' '-f' \\", "      && 'rm' '-vf' '/opt/kafka/plugins/my-connector-plugin/90e04094.zip'", "RUN 'mkdir' '-p' '/opt/kafka/plugins/my-connector-plugin/2c3b64c7' \\", "      && 'curl' '-k' '-L' '--output' '/opt/kafka/plugins/my-connector-plugin/2c3b64c7/my.so' 'https://mydomain.tld/download?artifact=my.so'", "USER 1001"));
}
Also used : ZipArtifact(io.strimzi.api.kafka.model.connect.build.ZipArtifact) ZipArtifactBuilder(io.strimzi.api.kafka.model.connect.build.ZipArtifactBuilder) OtherArtifact(io.strimzi.api.kafka.model.connect.build.OtherArtifact) Build(io.strimzi.api.kafka.model.connect.build.Build) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) OtherArtifactBuilder(io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder) BuildBuilder(io.strimzi.api.kafka.model.connect.build.BuildBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 5 with OtherArtifactBuilder

use of io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder 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."));
}
Also used : ZipArtifactBuilder(io.strimzi.api.kafka.model.connect.build.ZipArtifactBuilder) Build(io.strimzi.api.kafka.model.connect.build.Build) TgzArtifactBuilder(io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder) PluginBuilder(io.strimzi.api.kafka.model.connect.build.PluginBuilder) Artifact(io.strimzi.api.kafka.model.connect.build.Artifact) ZipArtifact(io.strimzi.api.kafka.model.connect.build.ZipArtifact) OtherArtifact(io.strimzi.api.kafka.model.connect.build.OtherArtifact) MavenArtifact(io.strimzi.api.kafka.model.connect.build.MavenArtifact) JarArtifact(io.strimzi.api.kafka.model.connect.build.JarArtifact) OtherArtifactBuilder(io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder) JarArtifactBuilder(io.strimzi.api.kafka.model.connect.build.JarArtifactBuilder) BuildBuilder(io.strimzi.api.kafka.model.connect.build.BuildBuilder) InvalidConfigurationException(io.strimzi.operator.common.InvalidConfigurationException) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

OtherArtifactBuilder (io.strimzi.api.kafka.model.connect.build.OtherArtifactBuilder)6 PluginBuilder (io.strimzi.api.kafka.model.connect.build.PluginBuilder)6 Build (io.strimzi.api.kafka.model.connect.build.Build)4 BuildBuilder (io.strimzi.api.kafka.model.connect.build.BuildBuilder)4 OtherArtifact (io.strimzi.api.kafka.model.connect.build.OtherArtifact)4 ZipArtifact (io.strimzi.api.kafka.model.connect.build.ZipArtifact)4 ZipArtifactBuilder (io.strimzi.api.kafka.model.connect.build.ZipArtifactBuilder)4 ParallelTest (io.strimzi.test.annotations.ParallelTest)4 Artifact (io.strimzi.api.kafka.model.connect.build.Artifact)2 JarArtifact (io.strimzi.api.kafka.model.connect.build.JarArtifact)2 JarArtifactBuilder (io.strimzi.api.kafka.model.connect.build.JarArtifactBuilder)2 MavenArtifact (io.strimzi.api.kafka.model.connect.build.MavenArtifact)2 Plugin (io.strimzi.api.kafka.model.connect.build.Plugin)2 TgzArtifactBuilder (io.strimzi.api.kafka.model.connect.build.TgzArtifactBuilder)2 InvalidConfigurationException (io.strimzi.operator.common.InvalidConfigurationException)2 ParallelTest (io.strimzi.systemtest.annotations.ParallelTest)2