SOLR-14108: Handle missing verify commands or missing default params in Package Manager

This commit is contained in:
Ishan Chattopadhyaya 2019-12-19 10:38:34 +05:30
parent 04e306f616
commit 3a4f43227b
2 changed files with 22 additions and 20 deletions

View File

@ -289,27 +289,27 @@ public class PackageManager implements Closeable {
public boolean verify(SolrPackageInstance pkg, List<String> collections) { public boolean verify(SolrPackageInstance pkg, List<String> collections) {
boolean success = true; boolean success = true;
for (Plugin plugin: pkg.plugins) { for (Plugin plugin: pkg.plugins) {
for (String collection: collections) { Command cmd = plugin.verifyCommand;
Map<String, String> collectionParameterOverrides = getPackageParams(pkg.name, collection); if (plugin.verifyCommand != null && !Strings.isNullOrEmpty(cmd.path)) {
Command cmd = plugin.verifyCommand; for (String collection: collections) {
Map<String, String> collectionParameterOverrides = getPackageParams(pkg.name, collection);
Map<String, String> systemParams = PackageUtils.map("collection", collection, "package-name", pkg.name, "package-version", pkg.version); Map<String, String> systemParams = PackageUtils.map("collection", collection, "package-name", pkg.name, "package-version", pkg.version);
String url = solrBaseUrl + PackageUtils.resolve(cmd.path, pkg.parameterDefaults, collectionParameterOverrides, systemParams); String url = solrBaseUrl + PackageUtils.resolve(cmd.path, pkg.parameterDefaults, collectionParameterOverrides, systemParams);
PackageUtils.printGreen("Executing " + url + " for collection:" + collection); PackageUtils.printGreen("Executing " + url + " for collection:" + collection);
if ("GET".equalsIgnoreCase(cmd.method)) { if ("GET".equalsIgnoreCase(cmd.method)) {
String response = PackageUtils.getJsonStringFromUrl(solrClient.getHttpClient(), url); String response = PackageUtils.getJsonStringFromUrl(solrClient.getHttpClient(), url);
PackageUtils.printGreen(response); PackageUtils.printGreen(response);
String actualValue = JsonPath.parse(response, PackageUtils.jsonPathConfiguration()) String actualValue = JsonPath.parse(response, PackageUtils.jsonPathConfiguration())
.read(PackageUtils.resolve(cmd.condition, pkg.parameterDefaults, collectionParameterOverrides, systemParams)); .read(PackageUtils.resolve(cmd.condition, pkg.parameterDefaults, collectionParameterOverrides, systemParams));
String expectedValue = PackageUtils.resolve(cmd.expected, pkg.parameterDefaults, collectionParameterOverrides, systemParams); String expectedValue = PackageUtils.resolve(cmd.expected, pkg.parameterDefaults, collectionParameterOverrides, systemParams);
PackageUtils.printGreen("Actual: "+actualValue+", expected: "+expectedValue); PackageUtils.printGreen("Actual: "+actualValue+", expected: "+expectedValue);
if (!expectedValue.equals(actualValue)) { if (!expectedValue.equals(actualValue)) {
PackageUtils.printRed("Failed to deploy plugin: " + plugin.name); PackageUtils.printRed("Failed to deploy plugin: " + plugin.name);
success = false; success = false;
}
} }
} else {
throw new SolrException(ErrorCode.BAD_REQUEST, "Non-GET method not supported for setup commands");
} }
} }
} }

View File

@ -172,8 +172,10 @@ public class PackageUtils {
// TODO: Should perhaps use Matchers etc. instead of this clumsy replaceAll(). // TODO: Should perhaps use Matchers etc. instead of this clumsy replaceAll().
if (str == null) return null; if (str == null) return null;
for (String param: defaults.keySet()) { if (defaults != null) {
str = str.replaceAll("\\$\\{"+param+"\\}", overrides.containsKey(param)? overrides.get(param): defaults.get(param)); for (String param: defaults.keySet()) {
str = str.replaceAll("\\$\\{"+param+"\\}", overrides.containsKey(param)? overrides.get(param): defaults.get(param));
}
} }
for (String param: overrides.keySet()) { for (String param: overrides.keySet()) {
str = str.replaceAll("\\$\\{"+param+"\\}", overrides.get(param)); str = str.replaceAll("\\$\\{"+param+"\\}", overrides.get(param));