Search in sources :

Example 11 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class SourceDescriptionFactoryTest method shouldReturnLocalStatsBasedOnKafkaTopic.

@Test
public void shouldReturnLocalStatsBasedOnKafkaTopic() {
    // Given:
    final String kafkaTopicName = "kafka";
    final DataSource dataSource = buildDataSource(kafkaTopicName, Optional.empty());
    final MetricCollectors mock = Mockito.mock(MetricCollectors.class);
    Mockito.when(mock.getAndFormatStatsFor(anyString(), anyBoolean())).thenReturn(mockStringStat);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), true)).thenReturn(errorStats);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), false)).thenReturn(stats);
    KsqlHostInfo localhost = new KsqlHostInfo("myhost", 10);
    // When
    final SourceDescription sourceDescription = SourceDescriptionFactory.create(dataSource, true, Collections.emptyList(), Collections.emptyList(), Optional.empty(), Collections.emptyList(), Collections.emptyList(), Stream.empty(), Stream.empty(), localhost, mock);
    // Then:
    // TODO deprecate and remove
    assertThat(sourceDescription.getStatistics(), containsString(mockStringStat));
    assertThat(sourceDescription.getErrorStats(), containsString(mockStringStat));
    // Also check includes its own stats in cluster stats
    final Stream<QueryHostStat> localStats = stats.stream().map((s) -> QueryHostStat.fromStat(s, new KsqlHostInfoEntity(localhost)));
    assertThat(localStats.collect(Collectors.toList()), everyItem(isIn(sourceDescription.getClusterStatistics())));
    final Stream<QueryHostStat> localErrors = errorStats.stream().map((s) -> QueryHostStat.fromStat(s, new KsqlHostInfoEntity(localhost)));
    assertThat(localErrors.collect(Collectors.toList()), everyItem(isIn(sourceDescription.getClusterErrorStats())));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 12 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class SourceDescriptionFactoryTest method testShouldIncludeRemoteStatsIfProvided.

@Test
public void testShouldIncludeRemoteStatsIfProvided() {
    final List<QueryHostStat> remoteStats = IntStream.range(0, 5).boxed().map(x -> new QueryHostStat(new KsqlHostInfoEntity("otherhost:1090"), ConsumerCollector.CONSUMER_MESSAGES_PER_SEC, x, x)).collect(Collectors.toList());
    final List<QueryHostStat> remoteErrors = IntStream.range(0, 5).boxed().map(x -> new QueryHostStat(new KsqlHostInfoEntity("otherhost:1090"), StreamsErrorCollector.CONSUMER_FAILED_MESSAGES_PER_SEC, x, x)).collect(Collectors.toList());
    // Given:
    final String kafkaTopicName = "kafka";
    final DataSource dataSource = buildDataSource(kafkaTopicName, Optional.empty());
    final MetricCollectors mock = Mockito.mock(MetricCollectors.class);
    Mockito.when(mock.getAndFormatStatsFor(anyString(), anyBoolean())).thenReturn(mockStringStat);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), true)).thenReturn(errorStats);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), false)).thenReturn(stats);
    // When
    final SourceDescription sourceDescription = SourceDescriptionFactory.create(dataSource, true, Collections.emptyList(), Collections.emptyList(), Optional.empty(), Collections.emptyList(), Collections.emptyList(), remoteStats.stream(), remoteErrors.stream(), new KsqlHostInfo("myhost", 10), mock);
    // Then:
    assertThat(remoteStats, everyItem(isIn(sourceDescription.getClusterStatistics())));
    assertThat(remoteErrors, everyItem(isIn(sourceDescription.getClusterErrorStats())));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DataSource(io.confluent.ksql.metastore.model.DataSource) IntStream(java.util.stream.IntStream) TopicSensors(io.confluent.ksql.metrics.TopicSensors) ColumnName(io.confluent.ksql.name.ColumnName) SourceName(io.confluent.ksql.name.SourceName) FormatFactory(io.confluent.ksql.serde.FormatFactory) KeyFormat(io.confluent.ksql.serde.KeyFormat) Mock(org.mockito.Mock) Mockito.mockStatic(org.mockito.Mockito.mockStatic) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Matchers.everyItem(org.hamcrest.Matchers.everyItem) ImmutableList(com.google.common.collect.ImmutableList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) Matchers.isIn(org.hamcrest.Matchers.isIn) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Test(org.junit.Test) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) ValueFormat(io.confluent.ksql.serde.ValueFormat) Collectors(java.util.stream.Collectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Mockito(org.mockito.Mockito) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Stream(java.util.stream.Stream) StreamsErrorCollector(io.confluent.ksql.metrics.StreamsErrorCollector) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Optional(java.util.Optional) FormatInfo(io.confluent.ksql.serde.FormatInfo) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) Collections(java.util.Collections) ConsumerCollector(io.confluent.ksql.metrics.ConsumerCollector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 13 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class ActiveHostFilterTest method setUp.

@Before
public void setUp() {
    activeHost = new KsqlHostInfo("activeHost", 2345);
    HostInfo activeHostInfo = new HostInfo("activeHost", 2345);
    standByHost = new KsqlHostInfo("standby1", 1234);
    activeHostFilter = new ActiveHostFilter(activeHostInfo);
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Before(org.junit.Before)

Example 14 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class KsqlResource method configure.

@Override
public void configure(final KsqlConfig config) {
    if (!config.getKsqlStreamConfigProps().containsKey(StreamsConfig.APPLICATION_SERVER_CONFIG)) {
        throw new IllegalArgumentException("Need KS application server set");
    }
    final String applicationServer = (String) config.getKsqlStreamConfigProps().get(StreamsConfig.APPLICATION_SERVER_CONFIG);
    final HostInfo hostInfo = ServerUtil.parseHostInfo(applicationServer);
    this.localHost = new KsqlHostInfo(hostInfo.host(), hostInfo.port());
    try {
        this.localUrl = new URL(applicationServer);
    } catch (final Exception e) {
        throw new IllegalStateException("Failed to convert remote host info to URL." + " remoteInfo: " + localHost.host() + ":" + localHost.host());
    }
    this.validator = new RequestValidator(CustomValidators.VALIDATOR_MAP, injectorFactory, ksqlEngine::createSandbox, new ValidatedCommandFactory());
    this.handler = new RequestHandler(customExecutors.EXECUTOR_MAP, new DistributingExecutor(config, commandRunner.getCommandQueue(), distributedCmdResponseTimeout, injectorFactory, authorizationValidator, new ValidatedCommandFactory(), errorHandler, commandRunnerWarning), ksqlEngine, new DefaultCommandQueueSync(commandRunner.getCommandQueue(), this::shouldSynchronize, distributedCmdResponseTimeout));
}
Also used : DistributingExecutor(io.confluent.ksql.rest.server.computation.DistributingExecutor) RequestValidator(io.confluent.ksql.rest.server.validation.RequestValidator) RequestHandler(io.confluent.ksql.rest.server.execution.RequestHandler) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) DefaultCommandQueueSync(io.confluent.ksql.rest.server.execution.DefaultCommandQueueSync) ValidatedCommandFactory(io.confluent.ksql.rest.server.computation.ValidatedCommandFactory) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) URL(java.net.URL) PatternSyntaxException(java.util.regex.PatternSyntaxException) KsqlException(io.confluent.ksql.util.KsqlException) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException)

Example 15 with KsqlHostInfo

use of io.confluent.ksql.util.KsqlHostInfo in project ksql by confluentinc.

the class KsLocatorTest method shouldReturnRemoteOwnerForDifferentPort.

@Test
public void shouldReturnRemoteOwnerForDifferentPort() {
    // Given:
    final HostInfo localHostInfo = new HostInfo(LOCAL_HOST_URL.getHost(), LOCAL_HOST_URL.getPort() + 1);
    final KsqlHostInfo localHost = locator.asKsqlHost(localHostInfo);
    getActiveAndStandbyMetadata(localHostInfo);
    when(activeFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    when(livenessFilter.filter(eq(localHost))).thenReturn(Host.include(localHost));
    // When:
    final List<KsqlPartitionLocation> result = locator.locate(ImmutableList.of(KEY), routingOptions, routingFilterFactoryActive, false);
    // Then:
    List<KsqlNode> nodeList = result.get(0).getNodes();
    assertThat(nodeList.stream().findFirst().map(KsqlNode::isLocal), is(Optional.of(false)));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlPartitionLocation(io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation) KsqlNode(io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode) HostInfo(org.apache.kafka.streams.state.HostInfo) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Test(org.junit.Test)

Aggregations

KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)19 HostInfo (org.apache.kafka.streams.state.HostInfo)9 Test (org.junit.Test)7 KsqlPartitionLocation (io.confluent.ksql.execution.streams.materialization.Locator.KsqlPartitionLocation)6 KsqlNode (io.confluent.ksql.execution.streams.materialization.Locator.KsqlNode)5 Before (org.junit.Before)4 HostStatus (io.confluent.ksql.util.HostStatus)3 RoutingFilter (io.confluent.ksql.execution.streams.RoutingFilter)2 DataSource (io.confluent.ksql.metastore.model.DataSource)2 MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)2 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 List (java.util.List)2 Optional (java.util.Optional)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)1 RoutingOptions (io.confluent.ksql.execution.streams.RoutingOptions)1