Search in sources :

Example 6 with CommandStatus

use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.

the class StatusResourceTest method testGetStatus.

@Test
public void testGetStatus() throws Exception {
    StatusResource testResource = getTestStatusResource();
    for (Map.Entry<CommandId, CommandStatus> commandEntry : mockCommandStatuses.entrySet()) {
        CommandId commandId = commandEntry.getKey();
        CommandStatus expectedCommandStatus = commandEntry.getValue();
        Object statusEntity = testResource.getStatus(commandId.getType().name(), commandId.getEntity(), commandId.getAction().name()).getEntity();
        assertThat(statusEntity, instanceOf(CommandStatus.class));
        CommandStatus testCommandStatus = (CommandStatus) statusEntity;
        assertEquals(expectedCommandStatus, testCommandStatus);
    }
}
Also used : CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) EasyMock.anyObject(org.easymock.EasyMock.anyObject) CommandId(io.confluent.ksql.rest.server.computation.CommandId) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with CommandStatus

use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.

the class KsqlRestClient method makeStatusRequest.

public RestResponse<CommandStatus> makeStatusRequest(String commandId) {
    RestResponse<CommandStatus> result;
    Response response = makeGetRequest(String.format("status/%s", commandId));
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
        result = RestResponse.successful(response.readEntity(CommandStatus.class));
    } else {
        result = RestResponse.erroneous(response.readEntity(ErrorMessage.class));
    }
    response.close();
    return result;
}
Also used : Response(javax.ws.rs.core.Response) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus)

Example 8 with CommandStatus

use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.

the class KsqlResourceTest method testInstantRegisterTopic.

@Test
public void testInstantRegisterTopic() throws Exception {
    KsqlResource testResource = TestKsqlResourceUtil.get(ksqlEngine, ksqlRestConfig);
    final String ksqlTopic = "FOO";
    final String kafkaTopic = "bar";
    final String format = "json";
    final String ksqlString = String.format("REGISTER TOPIC %s WITH (kafka_topic='%s', value_format='%s');", ksqlTopic, kafkaTopic, format);
    final Map<String, Expression> createTopicProperties = new HashMap<>();
    createTopicProperties.put(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral(kafkaTopic));
    createTopicProperties.put(DdlConfig.VALUE_FORMAT_PROPERTY, new StringLiteral(format));
    final RegisterTopic ksqlStatement = new RegisterTopic(QualifiedName.of(ksqlTopic), false, createTopicProperties);
    final CommandId commandId = new CommandId(CommandId.Type.TOPIC, ksqlTopic, CommandId.Action.CREATE);
    final CommandStatus commandStatus = new CommandStatus(CommandStatus.Status.QUEUED, "Statement written to command topic");
    final CommandStatusEntity expectedCommandStatusEntity = new CommandStatusEntity(ksqlString, commandId, commandStatus);
    final Map<String, Object> streamsProperties = Collections.emptyMap();
    KsqlEntity testKsqlEntity = makeSingleRequest(testResource, ksqlString, ksqlStatement, streamsProperties, KsqlEntity.class);
    assertEquals(expectedCommandStatusEntity, testKsqlEntity);
}
Also used : HashMap(java.util.HashMap) RegisterTopic(io.confluent.ksql.parser.tree.RegisterTopic) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) CommandId(io.confluent.ksql.rest.server.computation.CommandId) Test(org.junit.Test)

Example 9 with CommandStatus

use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.

the class StatusResourceTest method getTestStatusResource.

private StatusResource getTestStatusResource() {
    StatementExecutor mockStatementExecutor = mock(StatementExecutor.class);
    expect(mockStatementExecutor.getStatuses()).andReturn(mockCommandStatuses);
    for (Map.Entry<CommandId, CommandStatus> commandEntry : mockCommandStatuses.entrySet()) {
        expect(mockStatementExecutor.getStatus(commandEntry.getKey())).andReturn(Optional.of(commandEntry.getValue()));
    }
    expect(mockStatementExecutor.getStatus(anyObject(CommandId.class))).andReturn(Optional.empty());
    replay(mockStatementExecutor);
    return new StatusResource(mockStatementExecutor);
}
Also used : CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) CommandId(io.confluent.ksql.rest.server.computation.CommandId) StatementExecutor(io.confluent.ksql.rest.server.computation.StatementExecutor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with CommandStatus

use of io.confluent.ksql.rest.entity.CommandStatus in project ksql by confluentinc.

the class StatusResource method getStatus.

@GET
@Path("/{type}/{entity}/{action}")
public Response getStatus(@PathParam("type") String type, @PathParam("entity") String entity, @PathParam("action") String action) throws Exception {
    CommandId commandId = new CommandId(type, entity, action);
    Optional<CommandStatus> commandStatus = statementExecutor.getStatus(commandId);
    if (!commandStatus.isPresent()) {
        throw new Exception("Command not found");
    }
    return Response.ok(commandStatus.get()).build();
}
Also used : CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) CommandId(io.confluent.ksql.rest.server.computation.CommandId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)13 CommandId (io.confluent.ksql.rest.server.computation.CommandId)5 KsqlException (io.confluent.ksql.util.KsqlException)5 WakeupException (org.apache.kafka.common.errors.WakeupException)4 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)3 Map (java.util.Map)3 Test (org.junit.Test)3 DdlStatement (io.confluent.ksql.parser.tree.DdlStatement)2 QueryId (io.confluent.ksql.query.QueryId)2 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)2 HashMap (java.util.HashMap)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GenericRow (io.confluent.ksql.GenericRow)1 DdlCommandResult (io.confluent.ksql.ddl.commands.DdlCommandResult)1 CreateAsSelect (io.confluent.ksql.parser.tree.CreateAsSelect)1 Expression (io.confluent.ksql.parser.tree.Expression)1 QuerySpecification (io.confluent.ksql.parser.tree.QuerySpecification)1 RegisterTopic (io.confluent.ksql.parser.tree.RegisterTopic)1 Relation (io.confluent.ksql.parser.tree.Relation)1