Search in sources :

Example 1 with FunctionStatus

use of org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus in project incubator-pulsar by apache.

the class FunctionsImpl method getFunctionInstanceStatus.

@GET
@Path("/{tenant}/{namespace}/{functionName}/{instanceId}/status")
public Response getFunctionInstanceStatus(@PathParam("tenant") final String tenant, @PathParam("namespace") final String namespace, @PathParam("functionName") final String functionName, @PathParam("instanceId") final String instanceId) throws IOException {
    // validate parameters
    try {
        validateGetFunctionInstanceRequestParams(tenant, namespace, functionName, instanceId);
    } catch (IllegalArgumentException e) {
        log.error("Invalid getFunctionStatus request @ /{}/{}/{}", tenant, namespace, functionName, e);
        return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON).entity(new ErrorData(e.getMessage())).build();
    }
    FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();
    if (!functionMetaDataManager.containsFunction(tenant, namespace, functionName)) {
        log.error("Function in getFunctionStatus does not exist @ /{}/{}/{}", tenant, namespace, functionName);
        return Response.status(Status.NOT_FOUND).type(MediaType.APPLICATION_JSON).entity(new ErrorData(String.format("Function %s doesn't exist", functionName))).build();
    }
    FunctionRuntimeManager functionRuntimeManager = worker().getFunctionRuntimeManager();
    FunctionStatus functionStatus = null;
    try {
        functionStatus = functionRuntimeManager.getFunctionInstanceStatus(tenant, namespace, functionName, Integer.parseInt(instanceId));
    } catch (Exception e) {
        log.error("Got Exception Getting Status", e);
        FunctionStatus.Builder functionStatusBuilder = FunctionStatus.newBuilder();
        functionStatusBuilder.setRunning(false);
        String functionConfigJson = org.apache.pulsar.functions.utils.Utils.printJson(functionStatusBuilder.build());
        return Response.status(Status.OK).entity(functionConfigJson).build();
    }
    String jsonResponse = org.apache.pulsar.functions.utils.Utils.printJson(functionStatus);
    return Response.status(Status.OK).entity(jsonResponse).build();
}
Also used : FunctionStatus(org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus) FunctionMetaDataManager(org.apache.pulsar.functions.worker.FunctionMetaDataManager) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FunctionRuntimeManager(org.apache.pulsar.functions.worker.FunctionRuntimeManager) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with FunctionStatus

use of org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus in project incubator-pulsar by apache.

the class ProcessRuntime method main.

public static void main(String[] args) throws ExecutionException, InterruptedException {
    int port = Integer.parseInt(args[0]);
    ManagedChannel channel = ManagedChannelBuilder.forAddress("127.0.0.1", port).usePlaintext(true).build();
    InstanceControlFutureStub stub = InstanceControlGrpc.newFutureStub(channel);
    ListenableFuture<FunctionStatus> response = stub.getFunctionStatus(Empty.newBuilder().build());
    CompletableFuture<FunctionStatus> future = new CompletableFuture<>();
    Futures.addCallback(response, new FutureCallback<FunctionStatus>() {

        @Override
        public void onFailure(Throwable throwable) {
            log.info("GetFunctionStatus:", throwable);
            future.completeExceptionally(throwable);
        }

        @Override
        public void onSuccess(InstanceCommunication.FunctionStatus t) {
            log.info("GetFunctionStatus: {}", t);
            future.complete(t);
        }
    });
    FunctionStatus status = future.get();
    log.info("Function Status : {}", status);
}
Also used : FunctionStatus(org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedChannel(io.grpc.ManagedChannel) InstanceCommunication(org.apache.pulsar.functions.proto.InstanceCommunication) InstanceControlFutureStub(org.apache.pulsar.functions.proto.InstanceControlGrpc.InstanceControlFutureStub) FunctionStatus(org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus)

Aggregations

FunctionStatus (org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus)2 ManagedChannel (io.grpc.ManagedChannel)1 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 ErrorData (org.apache.pulsar.common.policies.data.ErrorData)1 InstanceCommunication (org.apache.pulsar.functions.proto.InstanceCommunication)1 InstanceControlFutureStub (org.apache.pulsar.functions.proto.InstanceControlGrpc.InstanceControlFutureStub)1 FunctionMetaDataManager (org.apache.pulsar.functions.worker.FunctionMetaDataManager)1 FunctionRuntimeManager (org.apache.pulsar.functions.worker.FunctionRuntimeManager)1