use of org.apache.pulsar.common.policies.data.SinkStatus in project pulsar by yahoo.
the class PulsarStateTest method testSinkState.
@Test(groups = { "java_state", "state", "function", "java_function" })
public void testSinkState() throws Exception {
String inputTopicName = "test-state-sink-input-" + randomName(8);
String sinkName = "test-state-sink-" + randomName(8);
int numMessages = 10;
submitSinkConnector(sinkName, inputTopicName, "org.apache.pulsar.tests.integration.io.TestStateSink", JAVAJAR);
// get sink info
getSinkInfoSuccess(sinkName);
// get sink status
getSinkStatus(sinkName);
try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(container.getHttpServiceUrl()).build()) {
// java supports schema
@Cleanup PulsarClient client = PulsarClient.builder().serviceUrl(container.getPlainTextServiceUrl()).build();
@Cleanup Producer<String> producer = client.newProducer(Schema.STRING).topic(inputTopicName).create();
{
FunctionState functionState = admin.functions().getFunctionState("public", "default", sinkName, "initial");
assertEquals(functionState.getStringValue(), "val1");
}
for (int i = 0; i < numMessages; i++) {
producer.send("foo");
}
Awaitility.await().ignoreExceptions().untilAsserted(() -> {
SinkStatus status = admin.sinks().getSinkStatus("public", "default", sinkName);
assertEquals(status.getInstances().size(), 1);
assertTrue(status.getInstances().get(0).getStatus().numWrittenToSink > 0);
});
Awaitility.await().ignoreExceptions().untilAsserted(() -> {
FunctionState functionState = admin.functions().getFunctionState("public", "default", sinkName, "now");
assertEquals(functionState.getStringValue(), String.format("val1-%d", numMessages - 1));
});
}
// delete source
deleteSink(sinkName);
getSinkInfoNotFound(sinkName);
}
use of org.apache.pulsar.common.policies.data.SinkStatus in project pulsar by yahoo.
the class PulsarIOSinkRunner method waitForProcessingSinkMessages.
protected void waitForProcessingSinkMessages(String tenant, String namespace, String sinkName, int numMessages) throws Exception {
final String[] commands = { PulsarCluster.ADMIN_SCRIPT, "sink", "status", "--tenant", tenant, "--namespace", namespace, "--name", sinkName };
final ContainerExecResult result = pulsarCluster.getAnyWorker().execCmd(commands);
log.info("Get sink status : {}", result.getStdout());
assertEquals(result.getExitCode(), 0);
final SinkStatus sinkStatus = SinkStatusUtil.decode(result.getStdout());
assertEquals(sinkStatus.getNumInstances(), 1);
assertEquals(sinkStatus.getNumRunning(), 1);
assertEquals(sinkStatus.getInstances().size(), 1);
assertEquals(sinkStatus.getInstances().get(0).getInstanceId(), 0);
assertEquals(sinkStatus.getInstances().get(0).getStatus().isRunning(), true);
assertTrue(sinkStatus.getInstances().get(0).getStatus().getLastReceivedTime() > 0);
assertEquals(sinkStatus.getInstances().get(0).getStatus().getNumReadFromPulsar(), numMessages);
assertEquals(sinkStatus.getInstances().get(0).getStatus().getNumWrittenToSink(), numMessages);
assertEquals(sinkStatus.getInstances().get(0).getStatus().getNumRestarts(), 0);
assertEquals(sinkStatus.getInstances().get(0).getStatus().getLatestSystemExceptions().size(), 0);
}
use of org.apache.pulsar.common.policies.data.SinkStatus in project pulsar by yahoo.
the class PulsarIOSinkRunner method getSinkStatus.
protected void getSinkStatus(String tenant, String namespace, String sinkName) throws Exception {
final String[] commands = { PulsarCluster.ADMIN_SCRIPT, "sink", "status", "--tenant", tenant, "--namespace", namespace, "--name", sinkName };
final ContainerExecResult result = pulsarCluster.getAnyWorker().execCmd(commands);
log.info("Get sink status : {}", result.getStdout());
assertEquals(result.getExitCode(), 0);
SinkStatus sinkStatus = SinkStatusUtil.decode(result.getStdout());
assertEquals(sinkStatus.getNumInstances(), 1);
assertEquals(sinkStatus.getNumRunning(), 1);
assertEquals(sinkStatus.getInstances().size(), 1);
assertEquals(sinkStatus.getInstances().get(0).getInstanceId(), 0);
assertEquals(sinkStatus.getInstances().get(0).getStatus().isRunning(), true);
assertEquals(sinkStatus.getInstances().get(0).getStatus().getNumRestarts(), 0);
assertEquals(sinkStatus.getInstances().get(0).getStatus().getLatestSystemExceptions().size(), 0);
}
use of org.apache.pulsar.common.policies.data.SinkStatus in project pulsar by yahoo.
the class SinksImpl method getSinkStatusAsync.
@Override
public CompletableFuture<SinkStatus> getSinkStatusAsync(String tenant, String namespace, String sinkName) {
final CompletableFuture<SinkStatus> future = new CompletableFuture<>();
if (!validateSinkName(tenant, namespace, sinkName, future)) {
return future;
}
WebTarget path = sink.path(tenant).path(namespace).path(sinkName).path("status");
asyncGetRequest(path, new InvocationCallback<Response>() {
@Override
public void completed(Response response) {
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
future.completeExceptionally(getApiException(response));
} else {
future.complete(response.readEntity(SinkStatus.class));
}
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.common.policies.data.SinkStatus in project incubator-pulsar by apache.
the class SinksImpl method getSinkStatus.
@Override
public SinkStatus getSinkStatus(final String tenant, final String namespace, final String componentName, final URI uri, final String clientRole, final AuthenticationDataSource clientAuthenticationDataHttps) {
// validate parameters
componentStatusRequestValidate(tenant, namespace, componentName, clientRole, clientAuthenticationDataHttps);
SinkStatus sinkStatus;
try {
sinkStatus = new GetSinkStatus().getComponentStatus(tenant, namespace, componentName, uri);
} catch (WebApplicationException we) {
throw we;
} catch (Exception e) {
log.error("{}/{}/{} Got Exception Getting Status", tenant, namespace, componentName, e);
throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
return sinkStatus;
}
Aggregations