Search in sources :

Example 26 with ErrorData

use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.

the class FunctionsImpl method getFunctionStatus.

@GET
@Path("/{tenant}/{namespace}/{functionName}/status")
public Response getFunctionStatus(@PathParam("tenant") final String tenant, @PathParam("namespace") final String namespace, @PathParam("functionName") final String functionName) throws IOException {
    // validate parameters
    try {
        validateGetFunctionRequestParams(tenant, namespace, functionName);
    } 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();
    InstanceCommunication.FunctionStatusList functionStatusList = null;
    try {
        functionStatusList = functionRuntimeManager.getAllFunctionStatus(tenant, namespace, functionName);
    } 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(functionStatusList);
    return Response.status(Status.OK).entity(jsonResponse).build();
}
Also used : FunctionMetaDataManager(org.apache.pulsar.functions.worker.FunctionMetaDataManager) InstanceCommunication(org.apache.pulsar.functions.proto.InstanceCommunication) 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)

Aggregations

ErrorData (org.apache.pulsar.common.policies.data.ErrorData)26 Response (javax.ws.rs.core.Response)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Test (org.testng.annotations.Test)12 IOException (java.io.IOException)9 FunctionMetaDataManager (org.apache.pulsar.functions.worker.FunctionMetaDataManager)9 Path (javax.ws.rs.Path)8 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)8 RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)8 InputStream (java.io.InputStream)6 Namespace (org.apache.distributedlog.api.namespace.Namespace)6 ExecutionException (java.util.concurrent.ExecutionException)5 FunctionConfig (org.apache.pulsar.functions.proto.Function.FunctionConfig)5 GET (javax.ws.rs.GET)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)2 PackageLocationMetaData (org.apache.pulsar.functions.proto.Function.PackageLocationMetaData)2 FunctionRuntimeManager (org.apache.pulsar.functions.worker.FunctionRuntimeManager)2 Gson (com.google.gson.Gson)1 DELETE (javax.ws.rs.DELETE)1