@Test public void shouldFetchPropertiesFromKafkaCustomResources() { final KubernetesClient client = mock(KubernetesClient.class); final KafkaMetaDataRetrieval metaDataRetrieval = new KafkaMetaDataRetrieval() { @Override KubernetesClient createKubernetesClient() { return client; } }; @SuppressWarnings("unchecked") final MixedOperation<Kafka, KafkaResourceList, KafkaResourceDoneable, Resource<Kafka, KafkaResourceDoneable>> operation = mock( MixedOperation.class); when(client.customResources(KAFKA_CRD, Kafka.class, KafkaResourceList.class, KafkaResourceDoneable.class)).thenReturn(operation); when(operation.inAnyNamespace()).thenReturn(operation); when(operation.list()).thenReturn(KAFKAS); final SyndesisMetadataProperties properties = metaDataRetrieval.fetchProperties(null, null, null); final Map<String, List<PropertyPair>> expected = new HashMap<>(); expected.put("brokers", Arrays.asList( new PropertyPair("my-cluster-kafka-bootstrap.zregvart.svc:9092", "zregvart::my-cluster (plain)"), new PropertyPair("my-cluster-kafka-bootstrap.zregvart.svc:9093", "zregvart::my-cluster (tls)"), new PropertyPair("zorans-cluster-kafka-bootstrap.zregvart.svc:9092", "zregvart::zorans-cluster (plain)"), new PropertyPair("zorans-cluster-kafka-bootstrap.zregvart.svc:9093", "zregvart::zorans-cluster (tls)") )); assertThat(properties.getProperties()).containsExactlyEntriesOf(expected); }
@Override public SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId, Map<String, Object> properties) { List<PropertyPair> brokers = new ArrayList<>(); try (KubernetesClient client = createKubernetesClient()) { KafkaResourceList kafkaList = client.customResources(KAFKA_CRD, Kafka.class, KafkaResourceList.class, KafkaResourceDoneable.class).inAnyNamespace().list(); kafkaList.getItems().forEach(kafka -> processKafkaResource(brokers, kafka)); } catch (Exception t) { LOG.warn("Couldn't auto discover any kafka broker.", t); } Map<String, List<PropertyPair>> dynamicProperties = new HashMap<>(); dynamicProperties.put("brokers", brokers); return new SyndesisMetadataProperties(dynamicProperties); }
KafkaMetaDataRetrieval extends ComponentMetadataRetrieval { @Override public SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId, Map<String, Object> properties) { List<PropertyPair> brokers = new ArrayList<>(); try (KubernetesClient client = createKubernetesClient()) { KafkaResourceList kafkaList = client.customResources(KAFKA_CRD, Kafka.class, KafkaResourceList.class, KafkaResourceDoneable.class).inAnyNamespace().list(); kafkaList.getItems().forEach(kafka -> processKafkaResource(brokers, kafka)); } catch (Exception t) { LOG.warn("Couldn't auto discover any kafka broker.", t); } Map<String, List<PropertyPair>> dynamicProperties = new HashMap<>(); dynamicProperties.put("brokers", brokers); return new SyndesisMetadataProperties(dynamicProperties); } }
KafkaMetaDataRetrieval extends ComponentMetadataRetrieval { @Override public SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId, Map<String, Object> properties) { List<PropertyPair> brokers = new ArrayList<>(); try (KubernetesClient client = createKubernetesClient()) { KafkaResourceList kafkaList = client.customResources(KAFKA_CRD, Kafka.class, KafkaResourceList.class, KafkaResourceDoneable.class).inAnyNamespace().list(); kafkaList.getItems().forEach(kafka -> processKafkaResource(brokers, kafka)); } catch (Exception t) { LOG.warn("Couldn't auto discover any kafka broker.", t); } Map<String, List<PropertyPair>> dynamicProperties = new HashMap<>(); dynamicProperties.put("brokers", brokers); return new SyndesisMetadataProperties(dynamicProperties); }  }
KafkaMetaDataRetrieval extends ComponentMetadataRetrieval { @Override public SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId, Map<String, Object> properties) { List<PropertyPair> brokers = new ArrayList<>(); try (KubernetesClient client = createKubernetesClient()) { KafkaResourceList kafkaList = client.customResources(KAFKA_CRD, Kafka.class, KafkaResourceList.class, KafkaResourceDoneable.class).inAnyNamespace().list(); kafkaList.getItems().forEach(kafka -> processKafkaResource(brokers, kafka)); } catch (Exception t) { LOG.warn("Couldn't auto discover any kafka broker.", t); } Map<String, List<PropertyPair>> dynamicProperties = new HashMap<>(); dynamicProperties.put("brokers", brokers); return new SyndesisMetadataProperties(dynamicProperties); }  @Override SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId,
                                                      Map<String, Object> properties); }
KafkaMetaDataRetrieval extends ComponentMetadataRetrieval { @Override public SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId, Map<String, Object> properties) { List<PropertyPair> brokers = new ArrayList<>(); try (KubernetesClient client = createKubernetesClient()) { KafkaResourceList kafkaList = client.customResources(KAFKA_CRD, Kafka.class, KafkaResourceList.class, KafkaResourceDoneable.class).inAnyNamespace().list(); kafkaList.getItems().forEach(kafka -> processKafkaResource(brokers, kafka)); } catch (Exception t) { LOG.warn("Couldn't auto discover any kafka broker.", t); } Map<String, List<PropertyPair>> dynamicProperties = new HashMap<>(); dynamicProperties.put("brokers", brokers); return new SyndesisMetadataProperties(dynamicProperties); }  @Override SyndesisMetadataProperties fetchProperties(CamelContext context, String componentId,
                                                      Map<String, Object> properties);  }