mirror of https://github.com/apache/lucene.git
SOLR-14884: TestContainerPlugin.testApiFromPackage jenkins failures
This commit is contained in:
parent
da44d09164
commit
4087958d31
|
@ -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) {
|
||||||
PackageLoader.Package p = coreContainer.getPackageLoader().getPackage(pkg);
|
Optional<PackageLoader.Package.Version> ver = coreContainer.getPackageLoader().getPackageVersion(pkg, info.version);
|
||||||
if (p == null) {
|
if (ver.isEmpty()) {
|
||||||
errs.add("Invalid package " + klassInfo.pkg);
|
//may be we are a bit early. Do a refresh and try again
|
||||||
return;
|
coreContainer.getPackageLoader().getPackageAPI().refreshPackages(null);
|
||||||
|
ver = coreContainer.getPackageLoader().getPackageVersion(pkg, info.version);
|
||||||
}
|
}
|
||||||
this.pkgVersion = p.getVersion(info.version);
|
if (ver.isEmpty()) {
|
||||||
if (pkgVersion == null) {
|
PackageLoader.Package p = coreContainer.getPackageLoader().getPackage(pkg);
|
||||||
errs.add("No such package version:" + pkg + ":" + info.version + " . available versions :" + p.allVersions());
|
if (p == null) {
|
||||||
return;
|
errs.add("Invalid package " + klassInfo.pkg);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
errs.add("No such package version:" + pkg + ":" + info.version + " . available versions :" + p.allVersions());
|
||||||
|
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) {
|
||||||
|
|
|
@ -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,32 +102,33 @@ 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 [{}] ... ", SOLR_PKGS_PATH);
|
||||||
log.debug("Updating [{}] ... ", path);
|
// remake watch
|
||||||
|
final Watcher thisWatch = this;
|
||||||
// remake watch
|
refreshPackages(thisWatch);
|
||||||
final Watcher thisWatch = this;
|
|
||||||
final Stat stat = new Stat();
|
|
||||||
final byte[] data = zkClient.getData(path, thisWatch, stat, true);
|
|
||||||
pkgs = readPkgsFromZk(data, stat);
|
|
||||||
packageLoader.refreshPackageConf();
|
|
||||||
}
|
|
||||||
} catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) {
|
|
||||||
log.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: ", e);
|
|
||||||
} catch (KeeperException e) {
|
|
||||||
log.error("A ZK error has occurred", e);
|
|
||||||
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// Restore the interrupted status
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
log.warn("Interrupted", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshPackages(Watcher watcher) {
|
||||||
|
final Stat stat = new Stat();
|
||||||
|
try {
|
||||||
|
final byte[] data = coreContainer.getZkController().getZkClient().getData(SOLR_PKGS_PATH, watcher, stat, true);
|
||||||
|
pkgs = readPkgsFromZk(data, stat);
|
||||||
|
packageLoader.refreshPackageConf();
|
||||||
|
} catch (KeeperException.ConnectionLossException | KeeperException.SessionExpiredException e) {
|
||||||
|
log.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: ", e);
|
||||||
|
} catch (KeeperException e) {
|
||||||
|
log.error("A ZK error has occurred", e);
|
||||||
|
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// Restore the interrupted status
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
log.warn("Interrupted", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Packages readPkgsFromZk(byte[] data, Stat stat) throws KeeperException, InterruptedException {
|
private Packages readPkgsFromZk(byte[] data, Stat stat) throws KeeperException, InterruptedException {
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue