Search in sources :

Example 1 with AdminClientProvider

use of io.strimzi.operator.common.AdminClientProvider in project strimzi by strimzi.

the class ResourceUtils method adminClientProvider.

public static AdminClientProvider adminClientProvider() {
    return new AdminClientProvider() {

        @Override
        public Admin createAdminClient(String bootstrapHostnames, Secret clusterCaCertSecret, Secret keyCertSecret, String keyCertName) {
            Admin mock = mock(AdminClient.class);
            DescribeClusterResult dcr;
            try {
                Constructor<DescribeClusterResult> declaredConstructor = DescribeClusterResult.class.getDeclaredConstructor(KafkaFuture.class, KafkaFuture.class, KafkaFuture.class, KafkaFuture.class);
                declaredConstructor.setAccessible(true);
                KafkaFuture<Node> objectKafkaFuture = KafkaFutureImpl.completedFuture(new Node(0, "localhost", 9091));
                KafkaFuture<String> stringKafkaFuture = KafkaFutureImpl.completedFuture("CLUSTERID");
                dcr = declaredConstructor.newInstance(null, objectKafkaFuture, stringKafkaFuture, null);
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.describeCluster()).thenReturn(dcr);
            ListTopicsResult ltr;
            try {
                Constructor<ListTopicsResult> declaredConstructor = ListTopicsResult.class.getDeclaredConstructor(KafkaFuture.class);
                declaredConstructor.setAccessible(true);
                KafkaFuture<Map<String, TopicListing>> future = KafkaFutureImpl.completedFuture(emptyMap());
                ltr = declaredConstructor.newInstance(future);
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.listTopics(any())).thenReturn(ltr);
            DescribeTopicsResult dtr;
            try {
                Constructor<DescribeTopicsResult> declaredConstructor = DescribeTopicsResult.class.getDeclaredConstructor(Map.class);
                declaredConstructor.setAccessible(true);
                dtr = declaredConstructor.newInstance(emptyMap());
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.describeTopics(any(Collection.class))).thenReturn(dtr);
            DescribeConfigsResult dcfr;
            try {
                Constructor<DescribeConfigsResult> declaredConstructor = DescribeConfigsResult.class.getDeclaredConstructor(Map.class);
                declaredConstructor.setAccessible(true);
                dcfr = declaredConstructor.newInstance(emptyMap());
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.describeConfigs(any())).thenReturn(dcfr);
            return mock;
        }
    };
}
Also used : Node(org.apache.kafka.common.Node) DescribeConfigsResult(org.apache.kafka.clients.admin.DescribeConfigsResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) Admin(org.apache.kafka.clients.admin.Admin) Secret(io.fabric8.kubernetes.api.model.Secret) DescribeClusterResult(org.apache.kafka.clients.admin.DescribeClusterResult) ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult) Collection(java.util.Collection) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 2 with AdminClientProvider

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

the class ResourceUtils method adminClientProvider.

public static AdminClientProvider adminClientProvider() {
    return new AdminClientProvider() {

        @Override
        public Admin createAdminClient(String bootstrapHostnames, Secret clusterCaCertSecret, Secret keyCertSecret, String keyCertName) {
            Admin mock = mock(AdminClient.class);
            DescribeClusterResult dcr;
            try {
                Constructor<DescribeClusterResult> declaredConstructor = DescribeClusterResult.class.getDeclaredConstructor(KafkaFuture.class, KafkaFuture.class, KafkaFuture.class, KafkaFuture.class);
                declaredConstructor.setAccessible(true);
                KafkaFuture<Node> objectKafkaFuture = KafkaFutureImpl.completedFuture(new Node(0, "localhost", 9091));
                KafkaFuture<String> stringKafkaFuture = KafkaFutureImpl.completedFuture("CLUSTERID");
                dcr = declaredConstructor.newInstance(null, objectKafkaFuture, stringKafkaFuture, null);
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.describeCluster()).thenReturn(dcr);
            ListTopicsResult ltr;
            try {
                Constructor<ListTopicsResult> declaredConstructor = ListTopicsResult.class.getDeclaredConstructor(KafkaFuture.class);
                declaredConstructor.setAccessible(true);
                KafkaFuture<Map<String, TopicListing>> future = KafkaFutureImpl.completedFuture(emptyMap());
                ltr = declaredConstructor.newInstance(future);
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.listTopics(any())).thenReturn(ltr);
            DescribeTopicsResult dtr;
            try {
                Constructor<DescribeTopicsResult> declaredConstructor = DescribeTopicsResult.class.getDeclaredConstructor(Map.class);
                declaredConstructor.setAccessible(true);
                dtr = declaredConstructor.newInstance(emptyMap());
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.describeTopics(any(Collection.class))).thenReturn(dtr);
            DescribeConfigsResult dcfr;
            try {
                Constructor<DescribeConfigsResult> declaredConstructor = DescribeConfigsResult.class.getDeclaredConstructor(Map.class);
                declaredConstructor.setAccessible(true);
                dcfr = declaredConstructor.newInstance(emptyMap());
            } catch (ReflectiveOperationException e) {
                throw new RuntimeException(e);
            }
            when(mock.describeConfigs(any())).thenReturn(dcfr);
            return mock;
        }
    };
}
Also used : Node(org.apache.kafka.common.Node) DescribeConfigsResult(org.apache.kafka.clients.admin.DescribeConfigsResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) Admin(org.apache.kafka.clients.admin.Admin) Secret(io.fabric8.kubernetes.api.model.Secret) DescribeClusterResult(org.apache.kafka.clients.admin.DescribeClusterResult) ListTopicsResult(org.apache.kafka.clients.admin.ListTopicsResult) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult) Collection(java.util.Collection) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 3 with AdminClientProvider

use of io.strimzi.operator.common.AdminClientProvider in project strimzi by strimzi.

the class Main method main.

public static void main(String[] args) {
    LOGGER.info("UserOperator {} is starting", Main.class.getPackage().getImplementationVersion());
    UserOperatorConfig config = UserOperatorConfig.fromMap(System.getenv());
    // Setup Micrometer metrics options
    VertxOptions options = new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setJvmMetricsEnabled(true).setEnabled(true));
    Vertx vertx = Vertx.vertx(options);
    KubernetesClient client = new DefaultKubernetesClient();
    AdminClientProvider adminClientProvider = new DefaultAdminClientProvider();
    run(vertx, client, adminClientProvider, config).onComplete(ar -> {
        if (ar.failed()) {
            LOGGER.error("Unable to start operator", ar.cause());
            System.exit(1);
        }
    });
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Vertx(io.vertx.core.Vertx) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider)

Example 4 with AdminClientProvider

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

the class Main method main.

public static void main(String[] args) {
    LOGGER.info("UserOperator {} is starting", Main.class.getPackage().getImplementationVersion());
    UserOperatorConfig config = UserOperatorConfig.fromMap(System.getenv());
    // Setup Micrometer metrics options
    VertxOptions options = new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setJvmMetricsEnabled(true).setEnabled(true));
    Vertx vertx = Vertx.vertx(options);
    KubernetesClient client = new DefaultKubernetesClient();
    AdminClientProvider adminClientProvider = new DefaultAdminClientProvider();
    run(vertx, client, adminClientProvider, config).onComplete(ar -> {
        if (ar.failed()) {
            LOGGER.error("Unable to start operator", ar.cause());
            System.exit(1);
        }
    });
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) VertxPrometheusOptions(io.vertx.micrometer.VertxPrometheusOptions) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Vertx(io.vertx.core.Vertx) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) VertxOptions(io.vertx.core.VertxOptions) MicrometerMetricsOptions(io.vertx.micrometer.MicrometerMetricsOptions) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider)

Aggregations

AdminClientProvider (io.strimzi.operator.common.AdminClientProvider)4 Secret (io.fabric8.kubernetes.api.model.Secret)2 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 DefaultAdminClientProvider (io.strimzi.operator.common.DefaultAdminClientProvider)2 Vertx (io.vertx.core.Vertx)2 VertxOptions (io.vertx.core.VertxOptions)2 MicrometerMetricsOptions (io.vertx.micrometer.MicrometerMetricsOptions)2 VertxPrometheusOptions (io.vertx.micrometer.VertxPrometheusOptions)2 Collection (java.util.Collection)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.singletonMap (java.util.Collections.singletonMap)2 Map (java.util.Map)2 Admin (org.apache.kafka.clients.admin.Admin)2 DescribeClusterResult (org.apache.kafka.clients.admin.DescribeClusterResult)2 DescribeConfigsResult (org.apache.kafka.clients.admin.DescribeConfigsResult)2 DescribeTopicsResult (org.apache.kafka.clients.admin.DescribeTopicsResult)2 ListTopicsResult (org.apache.kafka.clients.admin.ListTopicsResult)2 Node (org.apache.kafka.common.Node)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2