SOLR-14884: TestContainerPlugin.testApiFromPackage jenkins failures

This commit is contained in:
noblepaul 2020-09-22 11:20:49 +10:00
parent da44d09164
commit 4087958d31
3 changed files with 47 additions and 31 deletions

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.lucene.analysis.util.ResourceLoaderAware; import org.apache.lucene.analysis.util.ResourceLoaderAware;
@ -228,16 +229,23 @@ public class CustomContainerPlugins implements ClusterPropertiesListener, MapWri
PluginInfo.ClassName klassInfo = new PluginInfo.ClassName(info.klass); PluginInfo.ClassName klassInfo = new PluginInfo.ClassName(info.klass);
pkg = klassInfo.pkg; pkg = klassInfo.pkg;
if (pkg != null) { if (pkg != null) {
Optional<PackageLoader.Package.Version> ver = coreContainer.getPackageLoader().getPackageVersion(pkg, info.version);
if (ver.isEmpty()) {
//may be we are a bit early. Do a refresh and try again
coreContainer.getPackageLoader().getPackageAPI().refreshPackages(null);
ver = coreContainer.getPackageLoader().getPackageVersion(pkg, info.version);
}
if (ver.isEmpty()) {
PackageLoader.Package p = coreContainer.getPackageLoader().getPackage(pkg); PackageLoader.Package p = coreContainer.getPackageLoader().getPackage(pkg);
if (p == null) { if (p == null) {
errs.add("Invalid package " + klassInfo.pkg); errs.add("Invalid package " + klassInfo.pkg);
return; return;
} } else {
this.pkgVersion = p.getVersion(info.version);
if (pkgVersion == null) {
errs.add("No such package version:" + pkg + ":" + info.version + " . available versions :" + p.allVersions()); errs.add("No such package version:" + pkg + ":" + info.version + " . available versions :" + p.allVersions());
return; return;
} }
}
this.pkgVersion = ver.get();
try { try {
klas = pkgVersion.getLoader().findClass(klassInfo.className, Object.class); klas = pkgVersion.getLoader().findClass(klassInfo.className, Object.class);
} catch (Exception e) { } catch (Exception e) {

View File

@ -93,8 +93,7 @@ public class PackageAPI {
private void registerListener(SolrZkClient zkClient) private void registerListener(SolrZkClient zkClient)
throws KeeperException, InterruptedException { throws KeeperException, InterruptedException {
String path = SOLR_PKGS_PATH; zkClient.exists(SOLR_PKGS_PATH,
zkClient.exists(path,
new Watcher() { new Watcher() {
@Override @Override
@ -103,17 +102,22 @@ public class PackageAPI {
if (Event.EventType.None.equals(event.getType())) { if (Event.EventType.None.equals(event.getType())) {
return; return;
} }
try {
synchronized (this) { synchronized (this) {
log.debug("Updating [{}] ... ", path); log.debug("Updating [{}] ... ", SOLR_PKGS_PATH);
// remake watch // remake watch
final Watcher thisWatch = this; final Watcher thisWatch = this;
refreshPackages(thisWatch);
}
}
}, true);
}
public void refreshPackages(Watcher watcher) {
final Stat stat = new Stat(); final Stat stat = new Stat();
final byte[] data = zkClient.getData(path, thisWatch, stat, true); try {
final byte[] data = coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, watcher, stat, true);
pkgs = readPkgsFromZk(data, stat); pkgs = readPkgsFromZk(data, stat);
packageLoader.refreshPackageConf(); packageLoader.refreshPackageConf();
}
} catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) { } catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) {
log.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: ", e); log.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: ", e);
} catch (KeeperException e) { } catch (KeeperException e) {
@ -126,10 +130,6 @@ public class PackageAPI {
} }
} }
}, true);
}
private Packages readPkgsFromZk(byte[] data, Stat stat) throws KeeperException, InterruptedException { private Packages readPkgsFromZk(byte[] data, Stat stat) throws KeeperException, InterruptedException {
if (data == null || stat == null) { if (data == null || stat == null) {

View File

@ -31,6 +31,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -61,6 +62,12 @@ public class PackageLoader implements Closeable {
private PackageAPI packageAPI; private PackageAPI packageAPI;
public Optional<Package.Version> getPackageVersion(String pkg, String version) {
Package p = packageClassLoaders.get(pkg);
if(p == null) return Optional.empty();
return Optional.ofNullable(p.getVersion(version));
}
public PackageLoader(CoreContainer coreContainer) { public PackageLoader(CoreContainer coreContainer) {
this.coreContainer = coreContainer; this.coreContainer = coreContainer;
packageAPI = new PackageAPI(coreContainer, this); packageAPI = new PackageAPI(coreContainer, this);
@ -227,6 +234,7 @@ public class PackageLoader implements Closeable {
} }
public Version getVersion(String version) { public Version getVersion(String version) {
if(version == null) return getLatest();
return myVersions.get(version); return myVersions.get(version);
} }