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

 ##########
 File path: 
solr/core/src/java/org/apache/solr/packagemanager/PackageManager.java
 ##########
 @@ -0,0 +1,415 @@
+/*
+ * 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.packagemanager;
+
+import static org.apache.solr.packagemanager.PackageUtils.getMapper;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+
+import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.packagemanager.SolrPackage.Command;
+import org.apache.solr.packagemanager.SolrPackage.Manifest;
+import org.apache.solr.packagemanager.SolrPackage.Plugin;
+import org.apache.solr.pkg.PackagePluginHolder;
+import org.apache.solr.util.SolrCLI;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Strings;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.PathNotFoundException;
+
+/**
+ * Handles most of the management of packages that are already installed in 
Solr.
+ */
+public class PackageManager implements Closeable {
+
+  final String solrBaseUrl;
+  final HttpSolrClient solrClient;
+  final SolrZkClient zkClient;
+
+  private Map<String, List<SolrPackageInstance>> packages = null;
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+
+  public PackageManager(HttpSolrClient solrClient, String solrBaseUrl, String 
zkHost) {
+    this.solrBaseUrl = solrBaseUrl;
+    this.solrClient = solrClient;
+    this.zkClient = new SolrZkClient(zkHost, 30000);
+    log.info("Done initializing a zkClient instance...");
+  }
+
+  @Override
+  public void close() throws IOException {
+    if (zkClient != null) {
+      zkClient.close();
+    }
+  }
+
+  public List<SolrPackageInstance> fetchInstalledPackageInstances() throws 
SolrException {
+    log.info("Getting packages from packages.json...");
+    List<SolrPackageInstance> ret = new ArrayList<SolrPackageInstance>();
+    packages = new HashMap<String, List<SolrPackageInstance>>();
+    try {
+      Map packagesZnodeMap = null;
+
+      if (zkClient.exists("/packages.json", true) == true) {
+        packagesZnodeMap = (Map)getMapper().readValue(
+            new String(zkClient.getData("/packages.json", null, null, true), 
"UTF-8"), Map.class).get("packages");
+        for (Object packageName: packagesZnodeMap.keySet()) {
+          List pkg = (List)packagesZnodeMap.get(packageName);
+          for (Map pkgVersion: (List<Map>)pkg) {
+            Manifest manifest = PackageUtils.fetchManifest(solrClient, 
solrBaseUrl, pkgVersion.get("manifest").toString(), 
pkgVersion.get("manifestSHA512").toString());
+            List<Plugin> solrplugins = manifest.plugins;
+            SolrPackageInstance pkgInstance = new 
SolrPackageInstance(packageName.toString(), null, 
+                pkgVersion.get("version").toString(), manifest, solrplugins, 
manifest.parameterDefaults);
+            List<SolrPackageInstance> list = 
packages.containsKey(packageName)? packages.get(packageName): new 
ArrayList<SolrPackageInstance>();
+            list.add(pkgInstance);
+            packages.put(packageName.toString(), list);
+            ret.add(pkgInstance);
+          }
+        }
+      }
+    } catch (Exception e) {
+      throw new SolrException(ErrorCode.BAD_REQUEST, e);
+    }
+    log.info("Got packages: "+ret);
+    return ret;
+  }
+
+  public Map<String, SolrPackageInstance> getPackagesDeployed(String 
collection) {
+    String paramsJson = 
PackageUtils.getJsonStringFromUrl(solrClient.getHttpClient(), 
solrBaseUrl+"/api/collections/"+collection+"/config/params/PKG_VERSIONS?omitHeader=true");
 
 Review comment:
   We can simply use the following and avoid dependency on `JsonPath`
   ` NavigableObject result = (NavigableObject) 
Utils.executeGET(solrClient.getHttpClient(),solrBaseUrl+"/api/collections/"+collection+"/config/params/PKG_VERSIONS?omitHeader=true&wt=javabin",Utils.JAVABINCONSUMER
  )
       Map<String, String> packages = (Map<String, String>) 
result._get("/response/params.PKG_VERSIONS", null);`

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