Search in sources :

Example 6 with SinkStatus

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);
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) FunctionState(org.apache.pulsar.common.functions.FunctionState) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) PulsarClient(org.apache.pulsar.client.api.PulsarClient) Cleanup(lombok.Cleanup) Test(org.testng.annotations.Test)

Example 7 with SinkStatus

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);
}
Also used : ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus)

Example 8 with SinkStatus

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);
}
Also used : ContainerExecResult(org.apache.pulsar.tests.integration.docker.ContainerExecResult) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus)

Example 9 with SinkStatus

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;
}
Also used : Response(javax.ws.rs.core.Response) CompletableFuture(java.util.concurrent.CompletableFuture) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) WebTarget(javax.ws.rs.client.WebTarget)

Example 10 with SinkStatus

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;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RestException(org.apache.pulsar.common.util.RestException) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) RestUtils.throwUnavailableException(org.apache.pulsar.functions.worker.rest.RestUtils.throwUnavailableException) RestException(org.apache.pulsar.common.util.RestException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

SinkStatus (org.apache.pulsar.common.policies.data.SinkStatus)24 Cleanup (lombok.Cleanup)9 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)9 PulsarClient (org.apache.pulsar.client.api.PulsarClient)9 Test (org.testng.annotations.Test)9 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)6 ContainerExecResult (org.apache.pulsar.tests.integration.docker.ContainerExecResult)6 IOException (java.io.IOException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 WebTarget (javax.ws.rs.client.WebTarget)3 Response (javax.ws.rs.core.Response)3 MessageId (org.apache.pulsar.client.api.MessageId)3 FunctionState (org.apache.pulsar.common.functions.FunctionState)3 SinkConfig (org.apache.pulsar.common.io.SinkConfig)3 SubscriptionStats (org.apache.pulsar.common.policies.data.SubscriptionStats)3 TopicStats (org.apache.pulsar.common.policies.data.TopicStats)3 KeyValue (org.apache.pulsar.common.schema.KeyValue)3 RestException (org.apache.pulsar.common.util.RestException)3 PulsarFunctionTestUtils (org.apache.pulsar.functions.worker.PulsarFunctionTestUtils)3