use of org.apache.pulsar.common.policies.data.SourceStatus in project pulsar by apache.
the class SourcesImpl method getSourceStatusAsync.
@Override
public CompletableFuture<SourceStatus> getSourceStatusAsync(String tenant, String namespace, String sourceName) {
WebTarget path = source.path(tenant).path(namespace).path(sourceName).path("status");
final CompletableFuture<SourceStatus> future = new CompletableFuture<>();
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(SourceStatus.class));
}
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.common.policies.data.SourceStatus in project pulsar by apache.
the class PulsarStateTest method testSourceState.
@Test(groups = { "java_state", "state", "function", "java_function" })
public void testSourceState() throws Exception {
String outputTopicName = "test-state-source-output-" + randomName(8);
String sourceName = "test-state-source-" + randomName(8);
submitSourceConnector(sourceName, outputTopicName, "org.apache.pulsar.tests.integration.io.TestStateSource", JAVAJAR);
// get source info
getSourceInfoSuccess(sourceName);
// get source status
getSourceStatus(sourceName);
try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(container.getHttpServiceUrl()).build()) {
Awaitility.await().ignoreExceptions().untilAsserted(() -> {
SourceStatus status = admin.sources().getSourceStatus("public", "default", sourceName);
assertEquals(status.getInstances().size(), 1);
assertTrue(status.getInstances().get(0).getStatus().numWritten > 0);
});
{
FunctionState functionState = admin.functions().getFunctionState("public", "default", sourceName, "initial");
assertEquals(functionState.getStringValue(), "val1");
}
Awaitility.await().ignoreExceptions().untilAsserted(() -> {
FunctionState functionState = admin.functions().getFunctionState("public", "default", sourceName, "now");
assertTrue(functionState.getStringValue().matches("val1-.*"));
});
}
// delete source
deleteSource(sourceName);
getSourceInfoNotFound(sourceName);
}
use of org.apache.pulsar.common.policies.data.SourceStatus in project pulsar by apache.
the class BatchSourceTest method testGenericRecordSource.
@Test(groups = { "source" })
public void testGenericRecordSource() throws Exception {
String outputTopicName = "test-state-source-output-" + randomName(8);
String sourceName = "test-state-source-" + randomName(8);
int numMessages = 10;
try {
submitSourceConnector(sourceName, outputTopicName, "builtin://batch-data-generator");
// get source info
getSourceInfoSuccess(container, sourceName);
// get source status
getSourceStatus(container, sourceName);
try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(container.getHttpServiceUrl()).build()) {
retryStrategically((test) -> {
try {
SourceStatus status = admin.sources().getSourceStatus("public", "default", sourceName);
return status.getInstances().size() > 0 && status.getInstances().get(0).getStatus().numWritten >= 10;
} catch (PulsarAdminException e) {
return false;
}
}, 10, 200);
SourceStatus status = admin.sources().getSourceStatus("public", "default", sourceName);
assertEquals(status.getInstances().size(), 1);
assertTrue(status.getInstances().get(0).getStatus().numWritten >= 10);
}
consumeMessages(container, outputTopicName, numMessages);
// delete source
deleteSource(container, sourceName);
getSourceInfoNotFound(container, sourceName);
} finally {
dumpFunctionLogs(sourceName);
}
}
use of org.apache.pulsar.common.policies.data.SourceStatus in project pulsar by apache.
the class GenericRecordSourceTest method testGenericRecordSource.
@Test(groups = { "source" })
public void testGenericRecordSource() throws Exception {
String outputTopicName = "test-state-source-output-" + randomName(8);
String sourceName = "test-state-source-" + randomName(8);
int numMessages = 10;
try {
submitSourceConnector(sourceName, outputTopicName, "org.apache.pulsar.tests.integration.io.GenericRecordSource", JAVAJAR);
// get source info
getSourceInfoSuccess(container, sourceName);
// get source status
getSourceStatus(container, sourceName);
try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(container.getHttpServiceUrl()).build()) {
retryStrategically((test) -> {
try {
SourceStatus status = admin.sources().getSourceStatus("public", "default", sourceName);
return status.getInstances().size() > 0 && status.getInstances().get(0).getStatus().numWritten >= 10;
} catch (PulsarAdminException e) {
return false;
}
}, 10, 200);
SourceStatus status = admin.sources().getSourceStatus("public", "default", sourceName);
assertEquals(status.getInstances().size(), 1);
assertTrue(status.getInstances().get(0).getStatus().numWritten >= 10);
}
consumeMessages(container, outputTopicName, numMessages);
// delete source
deleteSource(container, sourceName);
getSourceInfoNotFound(container, sourceName);
} finally {
dumpFunctionLogs(sourceName);
}
}
use of org.apache.pulsar.common.policies.data.SourceStatus in project pulsar by apache.
the class PulsarIOSourceRunner method waitForProcessingSourceMessages.
protected void waitForProcessingSourceMessages(String tenant, String namespace, String sourceName, int numMessages) throws Exception {
final String[] commands = { PulsarCluster.ADMIN_SCRIPT, "source", "status", "--tenant", tenant, "--namespace", namespace, "--name", sourceName };
final ContainerExecResult result = pulsarCluster.getAnyWorker().execCmd(commands);
log.info("Get source status : {}", result.getStdout());
assertEquals(result.getExitCode(), 0);
SourceStatus sourceStatus = SourceStatusUtil.decode(result.getStdout());
assertEquals(sourceStatus.getNumInstances(), 1);
assertEquals(sourceStatus.getNumRunning(), 1);
assertEquals(sourceStatus.getInstances().size(), 1);
assertEquals(sourceStatus.getInstances().get(0).getInstanceId(), 0);
assertEquals(sourceStatus.getInstances().get(0).getStatus().isRunning(), true);
assertTrue(sourceStatus.getInstances().get(0).getStatus().getLastReceivedTime() > 0);
assertEquals(sourceStatus.getInstances().get(0).getStatus().getNumReceivedFromSource(), numMessages);
assertEquals(sourceStatus.getInstances().get(0).getStatus().getNumWritten(), numMessages);
assertEquals(sourceStatus.getInstances().get(0).getStatus().getNumRestarts(), 0);
assertEquals(sourceStatus.getInstances().get(0).getStatus().getLatestSystemExceptions().size(), 0);
}
Aggregations