Search in sources :

Example 1 with KafkaTopics

use of com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics in project streamline by hortonworks.

the class KafkaMetadataService method getTopicsFromZk.

public KafkaTopics getTopicsFromZk() throws ZookeeperClientException, IOException {
    final Security security = getSecurity();
    final List<String> topics = zkCli.getChildren(kafkaZkConnection.buildZkRootPath(ZK_RELATIVE_PATH_KAFKA_TOPICS));
    return topics == null ? new KafkaTopics(Collections.emptyList(), security) : new KafkaTopics(topics, security);
}
Also used : KafkaTopics(com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics) Security(com.hortonworks.streamline.streams.cluster.service.metadata.json.Security)

Example 2 with KafkaTopics

use of com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics in project streamline by hortonworks.

the class AbstractKafkaBundleHintProviderTest method getHintsOnClusterWithZkServiceNotAvailable.

protected void getHintsOnClusterWithZkServiceNotAvailable() throws Exception {
    final List<String> topics = Lists.newArrayList("test1", "test2", "test3");
    new Expectations() {

        {
            kafkaMetadataService.getTopicsFromZk();
            result = new KafkaTopics(topics, security);
            zookeeperMetadataService.getZookeeperServers();
            result = new ServiceNotFoundException(1L, ServiceConfigurations.ZOOKEEPER.name());
        }
    };
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setName("cluster1");
    Map<String, Object> hints = provider.getHintsOnCluster(cluster, null, null);
    Assert.assertNotNull(hints);
    Assert.assertEquals(4, hints.size());
    Assert.assertEquals(topics, hints.get(KafkaBundleHintProvider.FIELD_NAME_TOPIC));
    new Verifications() {

        {
            kafkaMetadataService.getTopicsFromZk();
            zookeeperMetadataService.getZookeeperServers();
        }
    };
}
Also used : Expectations(mockit.Expectations) KafkaTopics(com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Verifications(mockit.Verifications)

Example 3 with KafkaTopics

use of com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics in project streamline by hortonworks.

the class AbstractKafkaBundleHintProviderTest method getHintsOnCluster.

protected void getHintsOnCluster() throws Exception {
    final List<String> topics = Lists.newArrayList("test1", "test2", "test3");
    final List<HostPort> zkHosts = Lists.newArrayList(new HostPort("svr1", 2181), new HostPort("svr2", 2181), new HostPort("svr3", 2181));
    final Map<KafkaBrokerListeners.Protocol, List<String>> protocolToHostsWithPort = getProtocolToHostsWithPort();
    new Expectations() {

        {
            kafkaMetadataService.getTopicsFromZk();
            result = new KafkaTopics(topics, security);
            zookeeperMetadataService.getZookeeperServers();
            result = zkHosts;
            kafkaMetadataService.getKafkaBrokerListeners().getProtocolToHostsWithPort();
            result = protocolToHostsWithPort;
        }
    };
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setName("cluster1");
    Map<String, Object> hints = provider.getHintsOnCluster(cluster, null, null);
    Assert.assertNotNull(hints);
    Assert.assertEquals(4, hints.size());
    Assert.assertEquals(topics, hints.get(KafkaBundleHintProvider.FIELD_NAME_TOPIC));
    Assert.assertEquals(AbstractKafkaBundleHintProvider.mapValuesJoiner(protocolToHostsWithPort, ","), hints.get(KafkaBundleHintProvider.FIELD_NAME_BOOTSTRAP_SERVERS));
    new Verifications() {

        {
            kafkaMetadataService.getTopicsFromZk();
            zookeeperMetadataService.getZookeeperServers();
        }
    };
}
Also used : Expectations(mockit.Expectations) HostPort(com.hortonworks.streamline.streams.cluster.service.metadata.common.HostPort) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Verifications(mockit.Verifications) KafkaTopics(com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics) List(java.util.List)

Example 4 with KafkaTopics

use of com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics in project streamline by hortonworks.

the class AbstractKafkaBundleHintProvider method getHintsOnCluster.

@Override
public Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject) {
    Map<String, Object> hintClusterMap = new HashMap<>();
    try (KafkaMetadataService kms = KafkaMetadataService.newInstance(environmentService, cluster.getId(), securityContext)) {
        KafkaTopics topics = kms.getTopicsFromZk();
        hintClusterMap.put(FIELD_NAME_TOPIC, topics.list());
        fillZookeeperHints(cluster, hintClusterMap);
        final Map<KafkaBrokerListeners.Protocol, List<String>> protocolToHostsWithPort = kms.getKafkaBrokerListeners().getProtocolToHostsWithPort();
        hintClusterMap.put(FIELD_NAME_BOOTSTRAP_SERVERS, mapValuesJoiner(protocolToHostsWithPort, ","));
        hintClusterMap.put(FIELD_NAME_SECURITY_PROTOCOL, protocolToHostsWithPort.keySet());
        hintClusterMap.put(FIELD_NAME_KAFKA_SERVICE_NAME, kms.getKafkaServiceName());
    } catch (ServiceNotFoundException e) {
        // we access it from mapping information so shouldn't be here
        throw new IllegalStateException("Service " + Constants.Kafka.SERVICE_NAME + " in cluster " + cluster.getName() + " not found but mapping information exists.");
    } catch (ServiceConfigurationNotFoundException e) {
    // there's KAFKA service but not enough configuration info.
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return hintClusterMap;
}
Also used : HashMap(java.util.HashMap) KafkaMetadataService(com.hortonworks.streamline.streams.cluster.service.metadata.KafkaMetadataService) ServiceComponentNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceComponentNotFoundException) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) KafkaTopics(com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Aggregations

KafkaTopics (com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics)4 Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)2 ServiceNotFoundException (com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException)2 List (java.util.List)2 Expectations (mockit.Expectations)2 Verifications (mockit.Verifications)2 ServiceComponentNotFoundException (com.hortonworks.streamline.streams.cluster.exception.ServiceComponentNotFoundException)1 ServiceConfigurationNotFoundException (com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException)1 KafkaMetadataService (com.hortonworks.streamline.streams.cluster.service.metadata.KafkaMetadataService)1 HostPort (com.hortonworks.streamline.streams.cluster.service.metadata.common.HostPort)1 Security (com.hortonworks.streamline.streams.cluster.service.metadata.json.Security)1 HashMap (java.util.HashMap)1 Collectors.toList (java.util.stream.Collectors.toList)1