Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ private static Map<String, Object> readPlugins(final NodeConfig cfg) {
pluginMap.put("class", p.className);

if (p.initArgs.size() > 0) {
Map<String, Object> config = p.initArgs.toMap(new HashMap<>());
pluginMap.put("config", config);
pluginMap.put("config", p.initArgs.asMap(0));
}

pluginInfos.put(pluginName, pluginMap);
Expand Down
12 changes: 6 additions & 6 deletions solr/core/src/java/org/apache/solr/core/ConfigOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import static org.apache.solr.common.util.Utils.toJSONString;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.solr.common.MapSerializable;
import org.apache.solr.common.MapWriter;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.StrUtils;
Expand All @@ -33,7 +34,7 @@
* This class encapsulates the config overlay json file. It is immutable and any edit operations
* performed on this gives a new copy of the object with the changed value
*/
public class ConfigOverlay implements MapSerializable {
public class ConfigOverlay implements MapWriter {
private final int version;
private final Map<String, Object> data;
private Map<String, Object> props;
Expand Down Expand Up @@ -233,10 +234,9 @@ public Map<String, Object> getUserProps() {
}

@Override
public Map<String, Object> toMap(Map<String, Object> map) {
map.put(ZNODEVER, version);
map.putAll(data);
return map;
public void writeMap(EntryWriter ew) throws IOException {
ew.put(ZNODEVER, version);
data.forEach(ew::putNoEx);
}

@SuppressWarnings({"unchecked"})
Expand Down
52 changes: 31 additions & 21 deletions solr/core/src/java/org/apache/solr/core/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@
import static org.apache.solr.schema.FieldType.CLASS_NAME;

import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.solr.common.ConfigNode;
import org.apache.solr.common.MapSerializable;
import org.apache.solr.common.MapWriter;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.util.DOMConfigNode;
import org.w3c.dom.Node;

/** An Object which represents a Plugin of any type */
public class PluginInfo implements MapSerializable {
public class PluginInfo implements MapWriter {
public final String name, className, type, pkgName;
public final ClassName cName;
public final NamedList<Object> initArgs;
Expand Down Expand Up @@ -192,27 +194,35 @@ public PluginInfo getChild(String type) {
}

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Map<String, Object> toMap(Map<String, Object> map) {
map.putAll(attributes);
Map m = map;
if (initArgs != null) m.putAll(initArgs.asMap(3));
if (children != null) {
for (PluginInfo child : children) {
Object old = m.get(child.name);
if (old == null) {
m.put(child.name, child.toMap(new LinkedHashMap<>()));
} else if (old instanceof List list) {
list.add(child.toMap(new LinkedHashMap<>()));
} else {
ArrayList l = new ArrayList();
l.add(old);
l.add(child.toMap(new LinkedHashMap<>()));
m.put(child.name, l);
}
@SuppressWarnings("unchecked")
public void writeMap(EntryWriter ew) throws IOException {
new NamedList<>(attributes).writeMap(ew);
if (initArgs != null) {
for (Map.Entry<String, Object> entry : initArgs.asMap(3).entrySet()) {
ew.put(entry.getKey(), entry.getValue());
}
}
if (children == null || children.isEmpty()) {
return;
}

Map<String, Object> childrenGrouped = new LinkedHashMap<>();
for (PluginInfo child : children) {
Object old = childrenGrouped.get(child.name);
if (old == null) {
childrenGrouped.put(child.name, child);
} else if (old instanceof List) {
((List<Object>) old).add(child);
} else {
List<Object> l = new ArrayList<>();
l.add(old);
l.add(child);
childrenGrouped.put(child.name, l);
}
}
return m;
for (Map.Entry<String, Object> entry : childrenGrouped.entrySet()) {
ew.put(entry.getKey(), entry.getValue());
}
Comment on lines +199 to 225
}

/**
Expand Down
26 changes: 14 additions & 12 deletions solr/core/src/java/org/apache/solr/core/RequestParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.List;
import java.util.Map;
import org.apache.solr.cloud.ZkSolrResourceLoader;
import org.apache.solr.common.MapSerializable;
import org.apache.solr.common.MapWriter;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.params.MultiMapSolrParams;
Expand All @@ -38,7 +38,7 @@
* The class encapsulates the request time parameters . This is immutable and any changes performed
* returns a copy of the Object with the changed values
*/
public class RequestParams implements MapSerializable {
public class RequestParams implements MapWriter {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private final Map<String, Object> data;
Expand Down Expand Up @@ -112,8 +112,9 @@ public int getZnodeVersion() {
}

@Override
public Map<String, Object> toMap(Map<String, Object> map) {
return getMapWithVersion(data, znodeVersion);
public void writeMap(EntryWriter ew) throws IOException {
ew.put(ConfigOverlay.ZNODEVER, znodeVersion);
data.forEach(ew::putNoEx);
}

public static Map<String, Object> getMapWithVersion(Map<String, Object> data, int znodeVersion) {
Expand All @@ -129,7 +130,9 @@ public RequestParams setParams(String name, ParamSet paramSet) {
Map p = (Map) deepCopy.get(NAME);
if (p == null) deepCopy.put(NAME, p = new LinkedHashMap<>());
if (paramSet == null) p.remove(name);
else p.put(name, paramSet.toMap(new LinkedHashMap<>()));
else {
p.put(name, Utils.convertToMap(paramSet, new HashMap<>()));
}
return new RequestParams(deepCopy, znodeVersion);
}

Expand Down Expand Up @@ -207,7 +210,7 @@ public byte[] toByteArray() {
public static final String INVARIANTS = "_invariants_";

@SuppressWarnings({"unchecked"})
public static class ParamSet implements MapSerializable {
public static class ParamSet implements MapWriter {
private final Map<String, Object> defaults, appends, invariants;
Map<String, VersionedParams> paramsMap;
public final Map<String, Long> meta;
Expand All @@ -234,12 +237,11 @@ public Long getVersion() {
}

@Override
public Map<String, Object> toMap(Map<String, Object> result) {
result.putAll(defaults);
if (appends != null) result.put(APPENDS, appends);
if (invariants != null) result.put(INVARIANTS, invariants);
if (meta != null) result.put("", meta);
return result;
public void writeMap(EntryWriter ew) throws IOException {
defaults.forEach(ew::putNoEx);
if (appends != null) ew.put(APPENDS, appends);
if (invariants != null) ew.put(INVARIANTS, invariants);
if (meta != null) ew.put("", meta);
}

@SuppressWarnings({"rawtypes"})
Expand Down
Loading