Search in sources :

Example 26 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class ServerInfoResourceTest method shouldReturnServerInfo.

@Test
public void shouldReturnServerInfo() {
    // When:
    final EndpointResponse response = serverInfoResource.get();
    // Then:
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.getEntity(), instanceOf(ServerInfo.class));
    final ServerInfo serverInfo = (ServerInfo) response.getEntity();
    assertThat(serverInfo, equalTo(new ServerInfo(AppInfo.getVersion(), KAFKA_CLUSTER_ID, KSQL_SERVICE_ID, "RUNNING")));
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) Test(org.junit.Test)

Example 27 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class StreamedQueryResourceTest method shouldReturnForbiddenKafkaAccessForPullQueryAuthorizationDenied.

@Test
public void shouldReturnForbiddenKafkaAccessForPullQueryAuthorizationDenied() {
    // Given:
    when(mockStatementParser.<Query>parseSingleStatement(PULL_QUERY_STRING)).thenReturn(query);
    doThrow(new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(TOPIC_NAME))).when(authorizationValidator).checkAuthorization(any(), any(), any());
    // When:
    final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PULL_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
    final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
    final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) AUTHORIZATION_ERROR_RESPONSE.getEntity();
    assertEquals(response.getStatus(), AUTHORIZATION_ERROR_RESPONSE.getStatus());
    assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}
Also used : KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Query(io.confluent.ksql.parser.tree.Query) MetricsCallbackHolder(io.confluent.ksql.api.server.MetricsCallbackHolder) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 28 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class StreamedQueryResourceTest method shouldThrowOnDenyListedStreamProperty.

@Test
public void shouldThrowOnDenyListedStreamProperty() {
    // Given:
    when(mockStatementParser.<Query>parseSingleStatement(PULL_QUERY_STRING)).thenReturn(query);
    testResource = new StreamedQueryResource(mockKsqlEngine, ksqlRestConfig, mockStatementParser, commandQueue, DISCONNECT_CHECK_INTERVAL, COMMAND_QUEUE_CATCHUP_TIMOEUT, activenessRegistrar, Optional.of(authorizationValidator), errorsHandler, denyListPropertyValidator, queryExecutor);
    final Map<String, Object> props = new HashMap<>(ImmutableMap.of(StreamsConfig.APPLICATION_SERVER_CONFIG, "something:1"));
    props.put(KsqlConfig.KSQL_PROPERTIES_OVERRIDES_DENYLIST, StreamsConfig.NUM_STREAM_THREADS_CONFIG);
    testResource.configure(new KsqlConfig(props));
    final Map<String, Object> overrides = ImmutableMap.of(StreamsConfig.NUM_STREAM_THREADS_CONFIG, 1);
    doThrow(new KsqlException("deny override")).when(denyListPropertyValidator).validateAll(overrides);
    when(errorsHandler.generateResponse(any(), any())).thenReturn(badRequest("A property override was set locally for a property that the " + "server prohibits overrides for: 'num.stream.threads'"));
    // When:
    final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PULL_QUERY_STRING, // stream properties
    overrides, Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
    // Then:
    verify(denyListPropertyValidator).validateAll(overrides);
    assertThat(response.getStatus(), CoreMatchers.is(BAD_REQUEST.code()));
    assertThat(((KsqlErrorMessage) response.getEntity()).getMessage(), is("A property override was set locally for a property that the server prohibits " + "overrides for: '" + StreamsConfig.NUM_STREAM_THREADS_CONFIG + "'"));
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Query(io.confluent.ksql.parser.tree.Query) MetricsCallbackHolder(io.confluent.ksql.api.server.MetricsCallbackHolder) HashMap(java.util.HashMap) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 29 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class StreamedQueryResourceTest method shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException.

@Test
public void shouldReturnForbiddenKafkaAccessIfKsqlTopicAuthorizationException() {
    // Given:
    when(mockStatementParser.<Query>parseSingleStatement(PUSH_QUERY_STRING)).thenReturn(query);
    doThrow(new KsqlTopicAuthorizationException(AclOperation.READ, Collections.singleton(TOPIC_NAME))).when(authorizationValidator).checkAuthorization(any(), any(), any());
    // When:
    final EndpointResponse response = testResource.streamQuery(securityContext, new KsqlRequest(PUSH_QUERY_STRING, Collections.emptyMap(), Collections.emptyMap(), null), new CompletableFuture<>(), Optional.empty(), new MetricsCallbackHolder(), context);
    final KsqlErrorMessage responseEntity = (KsqlErrorMessage) response.getEntity();
    final KsqlErrorMessage expectedEntity = (KsqlErrorMessage) AUTHORIZATION_ERROR_RESPONSE.getEntity();
    assertEquals(response.getStatus(), AUTHORIZATION_ERROR_RESPONSE.getStatus());
    assertEquals(responseEntity.getMessage(), expectedEntity.getMessage());
}
Also used : KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Query(io.confluent.ksql.parser.tree.Query) MetricsCallbackHolder(io.confluent.ksql.api.server.MetricsCallbackHolder) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) Test(org.junit.Test)

Example 30 with EndpointResponse

use of io.confluent.ksql.rest.EndpointResponse in project ksql by confluentinc.

the class ServerInternalKsqlClient method makeKsqlRequest.

@Override
public RestResponse<KsqlEntityList> makeKsqlRequest(final URI serverEndpoint, final String sql, final Map<String, ?> requestProperties) {
    final KsqlRequest request = new KsqlRequest(sql, Collections.emptyMap(), requestProperties, null);
    final EndpointResponse response = ksqlResource.handleKsqlStatements(securityContext, request);
    final int status = response.getStatus();
    if (status == OK.code()) {
        return RestResponse.successful(status, (KsqlEntityList) response.getEntity());
    } else {
        return RestResponse.erroneous(status, (KsqlErrorMessage) response.getEntity());
    }
}
Also used : EndpointResponse(io.confluent.ksql.rest.EndpointResponse) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest)

Aggregations

EndpointResponse (io.confluent.ksql.rest.EndpointResponse)30 Test (org.junit.Test)25 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)10 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)8 KsqlException (io.confluent.ksql.util.KsqlException)7 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)6 HashMap (java.util.HashMap)6 MetricsCallbackHolder (io.confluent.ksql.api.server.MetricsCallbackHolder)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Query (io.confluent.ksql.parser.tree.Query)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 SessionConfig (io.confluent.ksql.config.SessionConfig)3 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)3 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)3 KsqlConfig (io.confluent.ksql.util.KsqlConfig)3 ImmutableList (com.google.common.collect.ImmutableList)2 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)2 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)2