use of org.apache.pulsar.functions.worker.FunctionRuntimeManager 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();
}
use of org.apache.pulsar.functions.worker.FunctionRuntimeManager in project incubator-pulsar by apache.
the class FunctionsImpl method getAssignments.
@GET
@Path("/assignments")
public Response getAssignments() {
FunctionRuntimeManager functionRuntimeManager = worker().getFunctionRuntimeManager();
Map<String, Map<String, Function.Assignment>> assignments = functionRuntimeManager.getCurrentAssignments();
Map<String, Collection<String>> ret = new HashMap<>();
for (Map.Entry<String, Map<String, Function.Assignment>> entry : assignments.entrySet()) {
ret.put(entry.getKey(), entry.getValue().keySet());
}
return Response.status(Status.OK).entity(new Gson().toJson(ret)).build();
}
use of org.apache.pulsar.functions.worker.FunctionRuntimeManager 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();
}
Aggregations