vdiravka commented on a change in pull request #1692: DRILL-6562: Plugin 
Management improvements
URL: https://github.com/apache/drill/pull/1692#discussion_r266309418
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/StorageResources.java
 ##########
 @@ -63,67 +64,86 @@
   @Inject ObjectMapper mapper;
   @Inject SecurityContext sc;
 
-  private static final Comparator<PluginConfigWrapper> PLUGIN_COMPARATOR = new 
Comparator<PluginConfigWrapper>() {
-    @Override
-    public int compare(PluginConfigWrapper o1, PluginConfigWrapper o2) {
-      return o1.getName().compareTo(o2.getName());
-    }
-  };
+  public static final String JSON_FILE_NAME = "json";
+  public static final String HOCON_FILE_NAME = "conf";
+  public static final String ALL_PLUGINS = "all";
+  public static final String ENABLED_PLUGINS = "enabled";
+  public static final String DISABLED_PLUGINS = "disabled";
+
+  private static final Comparator<PluginConfigWrapper> PLUGIN_COMPARATOR =
+      Comparator.comparing(PluginConfigWrapper::getName);
 
   @GET
-  @Path("/storage.json")
+  @Path("/storage/{group}/plugins/export/{format}")
   @Produces(MediaType.APPLICATION_JSON)
-  public List<PluginConfigWrapper> getStoragePluginsJSON() {
-
-    List<PluginConfigWrapper> list = Lists.newArrayList();
-    for (Map.Entry<String, StoragePluginConfig> entry : 
Lists.newArrayList(storage.getStore().getAll())) {
-      PluginConfigWrapper plugin = new PluginConfigWrapper(entry.getKey(), 
entry.getValue());
-      list.add(plugin);
+  public Response getPluginsConfigs(@PathParam("group") String pluginGroup, 
@PathParam("format") String format) {
+    if (JSON_FILE_NAME.equals(format) || HOCON_FILE_NAME.equals(format)) {
+      Response.ResponseBuilder response = Response.ok();
+      response.entity(getPluginsConfigs(pluginGroup).toArray());
+      response.header("Content-Disposition",
+          String.format("attachment;filename=\"%s_storage_plugins.%s\"", 
pluginGroup, format));
+      return response.build();
     }
-
-    Collections.sort(list, PLUGIN_COMPARATOR);
-
-    return list;
+    logger.error("Unknown file type {} for {} Storage Plugin Configs", format, 
pluginGroup);
+    return Response.status(Response.Status.NOT_FOUND).build();
   }
 
   @GET
   @Path("/storage")
   @Produces(MediaType.TEXT_HTML)
-  public Viewable getStoragePlugins() {
-    List<PluginConfigWrapper> list = getStoragePluginsJSON();
+  public Viewable getPlugins() {
+    List<PluginConfigWrapper> list = getPluginsConfigs(ALL_PLUGINS);
     return ViewableWithPermissions.create(authEnabled.get(), 
"/rest/storage/list.ftl", sc, list);
   }
 
+  private List<PluginConfigWrapper> getPluginsConfigs(String pluginsNumber) {
+    List<PluginConfigWrapper> list = Lists.newArrayList();
+    Predicate<Map.Entry<String, StoragePluginConfig>> predicate = entry -> 
false;
+    if (ALL_PLUGINS.equals(pluginsNumber)) {
+      predicate = entry -> true;
+    } else if (ENABLED_PLUGINS.equals(pluginsNumber)) {
+      predicate = entry -> entry.getValue().isEnabled();
+    } else if (DISABLED_PLUGINS.equals(pluginsNumber)) {
+      predicate = entry -> !entry.getValue().isEnabled();
+    }
+    Lists.newArrayList(storage.getStore().getAll()).stream()
 
 Review comment:
   This List was used to obtain Stream from Iterator.
   Replaced List with Iterables:
   ```
   Iterable<Map.Entry<String, StoragePluginConfig>> iterable = () -> 
storage.getStore().getAll();
       StreamSupport.stream(iterable.spliterator(), false)...
   ```

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to