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 2021/01/22 02:03:13 UTC

[GitHub] [pulsar] rdhabalia opened a new pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

rdhabalia opened a new pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270


   ### Motivation
   As part of pulsar metadata api, we want to use metadata api for admin-resources. With this PR
   - tenant API will start using metadata-store api
   - making tenant admin async and remove all blocking zk call
   
   Note: Next, I will create separate PR for rest of the admin resources.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia commented on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia commented on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-767006050


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia commented on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia commented on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765802352


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia commented on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia commented on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765879469


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia removed a comment on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia removed a comment on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765802352


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia removed a comment on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia removed a comment on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765879469


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia closed pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia closed pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia commented on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia commented on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765876626


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia removed a comment on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia removed a comment on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765672537






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia removed a comment on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia removed a comment on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765876626


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia commented on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia commented on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765250138


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia commented on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia commented on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-767006050


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia commented on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia commented on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765672537


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] eolivelli commented on a change in pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#discussion_r562898653



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BaseResources.java
##########
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.admin.impl;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
+import lombok.Getter;
+import org.apache.pulsar.broker.PulsarServerException;
+import org.apache.pulsar.metadata.api.MetadataCache;
+import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended;
+
+/**
+ * Base class for all configuration resources to access configurations from metadata-store.
+ *
+ * @param <T>
+ *            type of configuration-resources.
+ */
+public class BaseResources<T> {
+
+    @Getter
+    private final MetadataStoreExtended store;
+    @Getter
+    private final MetadataCache<T> cache;
+
+    public BaseResources(MetadataStoreExtended store, Class<T> clazz) {
+        this.store = store;
+        this.cache = store.getMetadataCache(clazz);
+    }
+
+    public CompletableFuture<List<String>> getChildren(String path) {
+        return cache.getChildren(path);
+    }
+
+    public Optional<T> get(String path) throws PulsarServerException {
+        try {
+            return getAsync(path).get();
+        } catch (Exception e) {
+            throw new PulsarServerException("Failed to get data from " + path,
+                    (e instanceof ExecutionException) ? e.getCause() : e);
+        }
+    }
+
+    public CompletableFuture<Optional<T>> getAsync(String path) {
+        return cache.get(path);
+    }
+
+    public void set(String path, Function<T, T> modifyFunction) throws PulsarServerException {
+        try {
+            setAsync(path, modifyFunction).get();
+        } catch (Exception e) {
+            throw new PulsarServerException("Failed to set data for " + path,
+                    (e instanceof ExecutionException) ? e.getCause() : e);
+        }
+    }
+
+    public CompletableFuture<Void> setAsync(String path, Function<T, T> modifyFunction) {
+        return cache.readModifyUpdate(path, modifyFunction);
+    }
+
+    public void create(String path, T data) throws PulsarServerException {
+        try {
+            createAsync(path, data).get();
+        } catch (Exception e) {
+            throw new PulsarServerException("Failed to create " + path,
+                    (e instanceof ExecutionException) ? e.getCause() : e);
+        }
+    }
+
+    public CompletableFuture<Void> createAsync(String path, T data) {
+        return cache.readModifyUpdateOrCreate(path, t -> data);
+    }
+
+    public void delete(String path) throws PulsarServerException {
+        try {
+            deleteAsync(path).get();
+        } catch (Exception e) {
+            throw new PulsarServerException("Failed to delete " + path,
+                    (e instanceof ExecutionException) ? e.getCause() : e);
+        }
+    }
+
+    public CompletableFuture<Void> deleteAsync(String path) {
+        return cache.delete(path);
+    }
+
+    public Boolean exists(String path) throws PulsarServerException {

Review comment:
       Should the return type be `boolean` ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



[GitHub] [pulsar] rdhabalia removed a comment on pull request #9270: [pulsar-broker] Make tenant rest-api async and use metadata-store api

Posted by GitBox <gi...@apache.org>.
rdhabalia removed a comment on pull request #9270:
URL: https://github.com/apache/pulsar/pull/9270#issuecomment-765879469


   /pulsarbot run-failure-checks


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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