janhoy commented on a change in pull request #994: SOLR-13662: Package Manager 
(CLI)
URL: https://github.com/apache/lucene-solr/pull/994#discussion_r345637839
 
 

 ##########
 File path: solr/core/src/java/org/apache/solr/util/PackageTool.java
 ##########
 @@ -0,0 +1,255 @@
+/*
+ * 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.solr.util;
+
+import java.lang.invoke.MethodHandles;
+import java.util.Map;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.lucene.util.SuppressForbidden;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.packagemanager.PackageManager;
+import org.apache.solr.packagemanager.PackageUtils;
+import org.apache.solr.packagemanager.RepositoryManager;
+import org.apache.solr.packagemanager.SolrPackageInstance;
+import org.apache.solr.util.SolrCLI.StatusTool;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@SuppressForbidden(reason = "Need to use System.out.println() instead of 
log4j/slf4j for cleaner output")
+public class PackageTool extends SolrCLI.ToolBase {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  @SuppressForbidden(reason = "Need to turn off logging, and SLF4J doesn't 
seem to provide for a way.")
+  public PackageTool() {
+    // Need a logging free, clean output going through to the user.
+    Configurator.setRootLevel(Level.OFF);
+  }
+
+  @Override
+  public String getName() {
+    return "package";
+  }
+
+  public static String solrUrl = null;
+  public static String solrBaseUrl = null;
+  public PackageManager packageManager;
+  public RepositoryManager repositoryManager;
+
+  @Override
+  protected void runImpl(CommandLine cli) throws Exception {
+    try {
+      solrUrl = 
cli.getOptionValues("solrUrl")[cli.getOptionValues("solrUrl").length-1];
+      solrBaseUrl = solrUrl.replaceAll("\\/solr$", ""); // strip out ending 
"/solr"
+      log.info("Solr url: "+solrUrl+", solr base url: "+solrBaseUrl);
+      String zkHost = getZkHost(cli);
+
+      log.info("ZK: "+zkHost);
+      String cmd = cli.getArgList().size() == 0? "help": cli.getArgs()[0];
+
+      try (HttpSolrClient solrClient = new 
HttpSolrClient.Builder(solrBaseUrl).build()) {
+        if (cmd != null) {
+          packageManager = new PackageManager(solrClient, solrBaseUrl, 
zkHost); 
+          try {
+            repositoryManager = new RepositoryManager(solrClient, 
packageManager);
+
+            switch (cmd) {
+              case "add-repo":
+                repositoryManager.addRepository(cli.getArgs()[1], 
cli.getArgs()[2]);
+                break;
+              case "list-installed":
+                packageManager.listInstalled();
 
 Review comment:
   Same as above - should the CLI formatting and printGreen stuff happen in 
this class and not in the PackageManager?

----------------------------------------------------------------
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

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to