Search in sources :

Example 6 with CommandId

use of io.confluent.ksql.rest.server.computation.CommandId 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 7 with CommandId

use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.

the class StatusResourceTest method testGetAllStatuses.

@Test
public void testGetAllStatuses() {
    StatusResource testResource = getTestStatusResource();
    Object statusesEntity = testResource.getAllStatuses().getEntity();
    assertThat(statusesEntity, instanceOf(CommandStatuses.class));
    CommandStatuses testCommandStatuses = (CommandStatuses) statusesEntity;
    Map<CommandId, CommandStatus.Status> expectedCommandStatuses = CommandStatuses.fromFullStatuses(mockCommandStatuses);
    assertEquals(expectedCommandStatuses, testCommandStatuses);
}
Also used : CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) CommandStatuses(io.confluent.ksql.rest.entity.CommandStatuses) EasyMock.anyObject(org.easymock.EasyMock.anyObject) CommandId(io.confluent.ksql.rest.server.computation.CommandId) Test(org.junit.Test)

Example 8 with CommandId

use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.

the class TestUtils method getAllPriorCommandRecords.

public List<Pair<CommandId, Command>> getAllPriorCommandRecords() {
    List<Pair<CommandId, Command>> priorCommands = new ArrayList<>();
    Command topicCommand = new Command("REGISTER TOPIC pageview_topic WITH " + "(value_format = 'json', " + "kafka_topic='pageview_topic_json');", new HashMap<>());
    CommandId topicCommandId = new CommandId(CommandId.Type.TOPIC, "_CSASTopicGen", CommandId.Action.CREATE);
    priorCommands.add(new Pair<>(topicCommandId, topicCommand));
    Command csCommand = new Command("CREATE STREAM pageview " + "(viewtime bigint, pageid varchar, userid varchar) " + "WITH (registered_topic = 'pageview_topic');", new HashMap<>());
    CommandId csCommandId = new CommandId(CommandId.Type.STREAM, "_CSASStreamGen", CommandId.Action.CREATE);
    priorCommands.add(new Pair<>(csCommandId, csCommand));
    Command csasCommand = new Command("CREATE STREAM user1pv " + " AS select * from pageview WHERE userid = 'user1';", new HashMap<>());
    CommandId csasCommandId = new CommandId(CommandId.Type.STREAM, "_CSASGen", CommandId.Action.CREATE);
    priorCommands.add(new Pair<>(csasCommandId, csasCommand));
    Command ctasCommand = new Command("CREATE TABLE user1pvtb " + " AS select * from pageview window tumbling(size 5 " + "second) WHERE userid = " + "'user1' group by pageid;", new HashMap<>());
    CommandId ctasCommandId = new CommandId(CommandId.Type.TABLE, "_CTASGen", CommandId.Action.CREATE);
    priorCommands.add(new Pair<>(ctasCommandId, ctasCommand));
    return priorCommands;
}
Also used : Command(io.confluent.ksql.rest.server.computation.Command) ArrayList(java.util.ArrayList) CommandId(io.confluent.ksql.rest.server.computation.CommandId) Pair(io.confluent.ksql.util.Pair)

Example 9 with CommandId

use of io.confluent.ksql.rest.server.computation.CommandId 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)

Example 10 with CommandId

use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.

the class KsqlRestClientTest method testStatus.

@Test
public void testStatus() {
    RestResponse<CommandStatuses> commandStatusesRestResponse = ksqlRestClient.makeStatusRequest();
    Assert.assertNotNull(commandStatusesRestResponse);
    Assert.assertTrue(commandStatusesRestResponse.isSuccessful());
    CommandStatuses commandStatuses = commandStatusesRestResponse.getResponse();
    Assert.assertTrue(commandStatuses.size() == 2);
    Assert.assertTrue(commandStatuses.get(new CommandId(CommandId.Type.TOPIC, "c1", CommandId.Action.CREATE)) == CommandStatus.Status.SUCCESS);
    Assert.assertTrue(commandStatuses.get(new CommandId(CommandId.Type.TOPIC, "c2", CommandId.Action.CREATE)) == CommandStatus.Status.ERROR);
}
Also used : CommandStatuses(io.confluent.ksql.rest.entity.CommandStatuses) CommandId(io.confluent.ksql.rest.server.computation.CommandId) Test(org.junit.Test)

Aggregations

CommandId (io.confluent.ksql.rest.server.computation.CommandId)10 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)7 HashMap (java.util.HashMap)5 Test (org.junit.Test)4 CommandStatuses (io.confluent.ksql.rest.entity.CommandStatuses)3 Expression (io.confluent.ksql.parser.tree.Expression)2 RegisterTopic (io.confluent.ksql.parser.tree.RegisterTopic)2 StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)2 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)2 Command (io.confluent.ksql.rest.server.computation.Command)2 StatementExecutor (io.confluent.ksql.rest.server.computation.StatementExecutor)2 KsqlException (io.confluent.ksql.util.KsqlException)2 Map (java.util.Map)2 GET (javax.ws.rs.GET)2 EasyMock.anyObject (org.easymock.EasyMock.anyObject)2 KsqlEngine (io.confluent.ksql.KsqlEngine)1 CreateStreamCommand (io.confluent.ksql.ddl.commands.CreateStreamCommand)1 RegisterTopicCommand (io.confluent.ksql.ddl.commands.RegisterTopicCommand)1 CreateStream (io.confluent.ksql.parser.tree.CreateStream)1 TableElement (io.confluent.ksql.parser.tree.TableElement)1