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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations