You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/05/22 05:39:51 UTC
[GitHub] sijie closed pull request #1421: Provide a util method to run
functions with metadata client driver
sijie closed pull request #1421: Provide a util method to run functions with metadata client driver
URL: https://github.com/apache/bookkeeper/pull/1421
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/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
index f27820597..bab6d8423 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/MetadataDrivers.java
@@ -25,16 +25,19 @@
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.net.URI;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Function;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.conf.ServerConfiguration;
import org.apache.bookkeeper.discover.RegistrationManager;
import org.apache.bookkeeper.meta.exceptions.Code;
@@ -318,6 +321,38 @@ public static MetadataBookieDriver getBookieDriver(URI uri) {
return getBookieDriver(schemeParts[0]);
}
+ /**
+ * Process the provided <i>function</i> with metadata client driver resolved
+ * from the metadata service uri returned by {@link ClientConfiguration#getMetadataServiceUri()}.
+ *
+ * @param conf client configuration
+ * @param function function to apply with metadata client driver.
+ * @param executorService executor service used by the metadata client driver.
+ * @throws MetadataException when failed to access metadata store
+ * @throws ExecutionException exception thrown when processing <tt>function</tt>.
+ */
+ public static <T> T runFunctionWithMetadataClientDriver(ClientConfiguration conf,
+ Function<MetadataClientDriver, T> function,
+ ScheduledExecutorService executorService)
+ throws MetadataException, ExecutionException {
+ try (MetadataClientDriver driver = MetadataDrivers.getClientDriver(
+ URI.create(conf.getMetadataServiceUri())
+ )) {
+ driver.initialize(conf, executorService, NullStatsLogger.INSTANCE, Optional.empty());
+ try {
+ return function.apply(driver);
+ } catch (Exception uee) {
+ if (uee.getCause() instanceof MetadataException) {
+ throw (MetadataException) uee.getCause();
+ } else {
+ throw new ExecutionException(uee.getMessage(), uee.getCause());
+ }
+ }
+ } catch (ConfigurationException e) {
+ throw new MetadataException(Code.INVALID_METADATA_SERVICE_URI, e);
+ }
+ }
+
/**
* Process the provided <i>function</i> with metadata bookie driver resolved
* from the metadata service uri returned by {@link ServerConfiguration#getMetadataServiceUri()}.
----------------------------------------------------------------
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