You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/05/08 00:31:43 UTC
[GitHub] sijie closed pull request #1734: Print periodic status of instances
in localrun
sijie closed pull request #1734: Print periodic status of instances in localrun
URL: https://github.com/apache/incubator-pulsar/pull/1734
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
index c0d88588d8..3e6201ec35 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
@@ -29,13 +29,10 @@
import java.io.ObjectOutputStream;
import java.lang.reflect.Type;
import java.net.MalformedURLException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -1014,6 +1011,32 @@ public void run() {
}
}
});
+ Timer statusCheckTimer = new Timer();
+ statusCheckTimer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ CompletableFuture<String>[] futures = new CompletableFuture[spawners.size()];
+ int index = 0;
+ for (RuntimeSpawner spawner : spawners) {
+ futures[index++] = spawner.getFunctionStatusAsJson();
+ }
+ try {
+ CompletableFuture.allOf(futures).get(5, TimeUnit.SECONDS);
+ for (index = 0; index < futures.length; ++index) {
+ String json = futures[index].get();
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ log.info(gson.toJson(new JsonParser().parse(json)));
+ }
+ } catch (Exception ex) {
+ log.error("Could not get status from all local instances");
+ }
+ }
+ }, 30000, 30000);
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ statusCheckTimer.cancel();
+ }
+ });
for (RuntimeSpawner spawner : spawners) {
spawner.join();
log.info("RuntimeSpawner quit because of {}", spawner.getRuntime().getDeathException());
diff --git a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java
index ede905671b..0994adcc73 100644
--- a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java
+++ b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeSpawner.java
@@ -23,6 +23,7 @@
*/
package org.apache.pulsar.functions.runtime;
+import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CompletableFuture;
@@ -31,6 +32,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.functions.instance.InstanceConfig;
import org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus;
+import org.apache.pulsar.functions.utils.Utils;
@Slf4j
public class RuntimeSpawner implements AutoCloseable {
@@ -100,6 +102,16 @@ public void join() throws Exception {
});
}
+ public CompletableFuture<String> getFunctionStatusAsJson() {
+ return this.getFunctionStatus().thenApply(msg -> {
+ try {
+ return Utils.printJson(msg);
+ } catch (IOException e) {
+ throw new RuntimeException("Exception parsing getstatus", e);
+ }
+ });
+ }
+
@Override
public void close() {
if (null != runtime) {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services