Search in sources :

Example 1 with WorkerFunctionInstanceStats

use of org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats in project pulsar by apache.

the class WorkerImpl method getFunctionsStatsAsync.

@Override
public CompletableFuture<List<WorkerFunctionInstanceStats>> getFunctionsStatsAsync() {
    WebTarget path = workerStats.path("functionsmetrics");
    final CompletableFuture<List<WorkerFunctionInstanceStats>> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<Response>() {

        @Override
        public void completed(Response response) {
            if (response.getStatus() != Response.Status.OK.getStatusCode()) {
                future.completeExceptionally(new ClientErrorException(response));
            } else {
                List<WorkerFunctionInstanceStats> metricsList = response.readEntity(new GenericType<List<WorkerFunctionInstanceStats>>() {
                });
                future.complete(metricsList);
            }
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : Response(javax.ws.rs.core.Response) WorkerFunctionInstanceStats(org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats) CompletableFuture(java.util.concurrent.CompletableFuture) GenericType(javax.ws.rs.core.GenericType) ClientErrorException(javax.ws.rs.ClientErrorException) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Example 2 with WorkerFunctionInstanceStats

use of org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats in project pulsar by yahoo.

the class WorkerImpl method getFunctionsMetrics.

@Override
public List<WorkerFunctionInstanceStats> getFunctionsMetrics(String clientRole) throws IOException {
    if (!isWorkerServiceAvailable()) {
        throwUnavailableException();
    }
    if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
        log.error("Client [{}] is not authorized to get function stats", clientRole);
        throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
    }
    Map<String, FunctionRuntimeInfo> functionRuntimes = worker().getFunctionRuntimeManager().getFunctionRuntimeInfos();
    List<WorkerFunctionInstanceStats> metricsList = new ArrayList<>(functionRuntimes.size());
    for (Map.Entry<String, FunctionRuntimeInfo> entry : functionRuntimes.entrySet()) {
        String fullyQualifiedInstanceName = entry.getKey();
        FunctionRuntimeInfo functionRuntimeInfo = entry.getValue();
        if (worker().getFunctionRuntimeManager().getRuntimeFactory().externallyManaged()) {
            Function.FunctionDetails functionDetails = functionRuntimeInfo.getFunctionInstance().getFunctionMetaData().getFunctionDetails();
            int parallelism = functionDetails.getParallelism();
            for (int i = 0; i < parallelism; ++i) {
                FunctionInstanceStatsImpl functionInstanceStats = WorkerUtils.getFunctionInstanceStats(fullyQualifiedInstanceName, functionRuntimeInfo, i);
                WorkerFunctionInstanceStats workerFunctionInstanceStats = new WorkerFunctionInstanceStats();
                workerFunctionInstanceStats.setName(FunctionCommon.getFullyQualifiedInstanceId(functionDetails.getTenant(), functionDetails.getNamespace(), functionDetails.getName(), i));
                workerFunctionInstanceStats.setMetrics(functionInstanceStats.getMetrics());
                metricsList.add(workerFunctionInstanceStats);
            }
        } else {
            FunctionInstanceStatsImpl functionInstanceStats = WorkerUtils.getFunctionInstanceStats(fullyQualifiedInstanceName, functionRuntimeInfo, functionRuntimeInfo.getFunctionInstance().getInstanceId());
            WorkerFunctionInstanceStats workerFunctionInstanceStats = new WorkerFunctionInstanceStats();
            workerFunctionInstanceStats.setName(fullyQualifiedInstanceName);
            workerFunctionInstanceStats.setMetrics(functionInstanceStats.getMetrics());
            metricsList.add(workerFunctionInstanceStats);
        }
    }
    return metricsList;
}
Also used : RestException(org.apache.pulsar.common.util.RestException) ArrayList(java.util.ArrayList) WorkerFunctionInstanceStats(org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats) Function(org.apache.pulsar.functions.proto.Function) FunctionInstanceStatsImpl(org.apache.pulsar.common.policies.data.FunctionInstanceStatsImpl) FunctionRuntimeInfo(org.apache.pulsar.functions.worker.FunctionRuntimeInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with WorkerFunctionInstanceStats

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

the class WorkerImpl method getFunctionsStatsAsync.

@Override
public CompletableFuture<List<WorkerFunctionInstanceStats>> getFunctionsStatsAsync() {
    WebTarget path = workerStats.path("functionsmetrics");
    final CompletableFuture<List<WorkerFunctionInstanceStats>> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<Response>() {

        @Override
        public void completed(Response response) {
            if (response.getStatus() != Response.Status.OK.getStatusCode()) {
                future.completeExceptionally(new ClientErrorException(response));
            } else {
                List<WorkerFunctionInstanceStats> metricsList = response.readEntity(new GenericType<List<WorkerFunctionInstanceStats>>() {
                });
                future.complete(metricsList);
            }
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : Response(javax.ws.rs.core.Response) WorkerFunctionInstanceStats(org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats) CompletableFuture(java.util.concurrent.CompletableFuture) GenericType(javax.ws.rs.core.GenericType) ClientErrorException(javax.ws.rs.ClientErrorException) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Example 4 with WorkerFunctionInstanceStats

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

the class WorkerImpl method getFunctionsMetrics.

@Override
public List<WorkerFunctionInstanceStats> getFunctionsMetrics(String clientRole) throws IOException {
    if (!isWorkerServiceAvailable()) {
        throwUnavailableException();
    }
    if (worker().getWorkerConfig().isAuthorizationEnabled() && !isSuperUser(clientRole)) {
        log.error("Client [{}] is not authorized to get function stats", clientRole);
        throw new RestException(Status.UNAUTHORIZED, "Client is not authorized to perform operation");
    }
    Map<String, FunctionRuntimeInfo> functionRuntimes = worker().getFunctionRuntimeManager().getFunctionRuntimeInfos();
    List<WorkerFunctionInstanceStats> metricsList = new ArrayList<>(functionRuntimes.size());
    for (Map.Entry<String, FunctionRuntimeInfo> entry : functionRuntimes.entrySet()) {
        String fullyQualifiedInstanceName = entry.getKey();
        FunctionRuntimeInfo functionRuntimeInfo = entry.getValue();
        if (worker().getFunctionRuntimeManager().getRuntimeFactory().externallyManaged()) {
            Function.FunctionDetails functionDetails = functionRuntimeInfo.getFunctionInstance().getFunctionMetaData().getFunctionDetails();
            int parallelism = functionDetails.getParallelism();
            for (int i = 0; i < parallelism; ++i) {
                FunctionInstanceStatsImpl functionInstanceStats = WorkerUtils.getFunctionInstanceStats(fullyQualifiedInstanceName, functionRuntimeInfo, i);
                WorkerFunctionInstanceStats workerFunctionInstanceStats = new WorkerFunctionInstanceStats();
                workerFunctionInstanceStats.setName(FunctionCommon.getFullyQualifiedInstanceId(functionDetails.getTenant(), functionDetails.getNamespace(), functionDetails.getName(), i));
                workerFunctionInstanceStats.setMetrics(functionInstanceStats.getMetrics());
                metricsList.add(workerFunctionInstanceStats);
            }
        } else {
            FunctionInstanceStatsImpl functionInstanceStats = WorkerUtils.getFunctionInstanceStats(fullyQualifiedInstanceName, functionRuntimeInfo, functionRuntimeInfo.getFunctionInstance().getInstanceId());
            WorkerFunctionInstanceStats workerFunctionInstanceStats = new WorkerFunctionInstanceStats();
            workerFunctionInstanceStats.setName(fullyQualifiedInstanceName);
            workerFunctionInstanceStats.setMetrics(functionInstanceStats.getMetrics());
            metricsList.add(workerFunctionInstanceStats);
        }
    }
    return metricsList;
}
Also used : RestException(org.apache.pulsar.common.util.RestException) ArrayList(java.util.ArrayList) WorkerFunctionInstanceStats(org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats) Function(org.apache.pulsar.functions.proto.Function) FunctionInstanceStatsImpl(org.apache.pulsar.common.policies.data.FunctionInstanceStatsImpl) FunctionRuntimeInfo(org.apache.pulsar.functions.worker.FunctionRuntimeInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with WorkerFunctionInstanceStats

use of org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats in project pulsar by yahoo.

the class WorkerImpl method getFunctionsStatsAsync.

@Override
public CompletableFuture<List<WorkerFunctionInstanceStats>> getFunctionsStatsAsync() {
    WebTarget path = workerStats.path("functionsmetrics");
    final CompletableFuture<List<WorkerFunctionInstanceStats>> future = new CompletableFuture<>();
    asyncGetRequest(path, new InvocationCallback<Response>() {

        @Override
        public void completed(Response response) {
            if (response.getStatus() != Response.Status.OK.getStatusCode()) {
                future.completeExceptionally(new ClientErrorException(response));
            } else {
                List<WorkerFunctionInstanceStats> metricsList = response.readEntity(new GenericType<List<WorkerFunctionInstanceStats>>() {
                });
                future.complete(metricsList);
            }
        }

        @Override
        public void failed(Throwable throwable) {
            future.completeExceptionally(getApiException(throwable.getCause()));
        }
    });
    return future;
}
Also used : Response(javax.ws.rs.core.Response) WorkerFunctionInstanceStats(org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats) CompletableFuture(java.util.concurrent.CompletableFuture) GenericType(javax.ws.rs.core.GenericType) ClientErrorException(javax.ws.rs.ClientErrorException) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

WorkerFunctionInstanceStats (org.apache.pulsar.common.policies.data.WorkerFunctionInstanceStats)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ClientErrorException (javax.ws.rs.ClientErrorException)3 WebTarget (javax.ws.rs.client.WebTarget)3 GenericType (javax.ws.rs.core.GenericType)3 Response (javax.ws.rs.core.Response)3 FunctionInstanceStatsImpl (org.apache.pulsar.common.policies.data.FunctionInstanceStatsImpl)3 RestException (org.apache.pulsar.common.util.RestException)3 Function (org.apache.pulsar.functions.proto.Function)3 FunctionRuntimeInfo (org.apache.pulsar.functions.worker.FunctionRuntimeInfo)3