Skip to content

Commit d0fa05e

Browse files
committed
SOLR-17600 (Part 2/4): Migrate Core Configuration classes from MapSerializable
1 parent 74d671e commit d0fa05e

14 files changed

Lines changed: 187 additions & 174 deletions

solr/core/src/java/org/apache/solr/api/NodeConfigClusterPluginsSource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ private static Map<String, Object> readPlugins(final NodeConfig cfg) {
7979
pluginMap.put("class", p.className);
8080

8181
if (p.initArgs.size() > 0) {
82-
Map<String, Object> config = p.initArgs.toMap(new HashMap<>());
83-
pluginMap.put("config", config);
82+
pluginMap.put("config", p.initArgs.asMap(0));
8483
}
8584

8685
pluginInfos.put(pluginName, pluginMap);

solr/core/src/java/org/apache/solr/core/ConfigOverlay.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

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

21+
import java.io.IOException;
2122
import java.util.ArrayList;
2223
import java.util.Collections;
2324
import java.util.LinkedHashMap;
2425
import java.util.List;
2526
import java.util.Map;
26-
import org.apache.solr.common.MapSerializable;
27+
import org.apache.solr.common.MapWriter;
2728
import org.apache.solr.common.SolrException;
2829
import org.apache.solr.common.params.CoreAdminParams;
2930
import org.apache.solr.common.util.StrUtils;
@@ -33,7 +34,7 @@
3334
* This class encapsulates the config overlay json file. It is immutable and any edit operations
3435
* performed on this gives a new copy of the object with the changed value
3536
*/
36-
public class ConfigOverlay implements MapSerializable {
37+
public class ConfigOverlay implements MapWriter {
3738
private final int version;
3839
private final Map<String, Object> data;
3940
private Map<String, Object> props;
@@ -233,10 +234,9 @@ public Map<String, Object> getUserProps() {
233234
}
234235

235236
@Override
236-
public Map<String, Object> toMap(Map<String, Object> map) {
237-
map.put(ZNODEVER, version);
238-
map.putAll(data);
239-
return map;
237+
public void writeMap(EntryWriter ew) throws IOException {
238+
ew.put(ZNODEVER, version);
239+
data.forEach(ew::putNoEx);
240240
}
241241

242242
@SuppressWarnings({"unchecked"})

solr/core/src/java/org/apache/solr/core/PluginInfo.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@
2323
import static org.apache.solr.schema.FieldType.CLASS_NAME;
2424

2525
import com.google.common.annotations.VisibleForTesting;
26+
import java.io.IOException;
2627
import java.util.ArrayList;
2728
import java.util.HashSet;
2829
import java.util.LinkedHashMap;
2930
import java.util.List;
3031
import java.util.Map;
3132
import org.apache.solr.common.ConfigNode;
32-
import org.apache.solr.common.MapSerializable;
33+
import org.apache.solr.common.MapWriter;
3334
import org.apache.solr.common.util.NamedList;
35+
import org.apache.solr.common.util.SimpleOrderedMap;
3436
import org.apache.solr.util.DOMConfigNode;
3537
import org.w3c.dom.Node;
3638

3739
/** An Object which represents a Plugin of any type */
38-
public class PluginInfo implements MapSerializable {
40+
public class PluginInfo implements MapWriter {
3941
public final String name, className, type, pkgName;
4042
public final ClassName cName;
4143
public final NamedList<Object> initArgs;
@@ -192,27 +194,35 @@ public PluginInfo getChild(String type) {
192194
}
193195

194196
@Override
195-
@SuppressWarnings({"unchecked", "rawtypes"})
196-
public Map<String, Object> toMap(Map<String, Object> map) {
197-
map.putAll(attributes);
198-
Map m = map;
199-
if (initArgs != null) m.putAll(initArgs.asMap(3));
200-
if (children != null) {
201-
for (PluginInfo child : children) {
202-
Object old = m.get(child.name);
203-
if (old == null) {
204-
m.put(child.name, child.toMap(new LinkedHashMap<>()));
205-
} else if (old instanceof List list) {
206-
list.add(child.toMap(new LinkedHashMap<>()));
207-
} else {
208-
ArrayList l = new ArrayList();
209-
l.add(old);
210-
l.add(child.toMap(new LinkedHashMap<>()));
211-
m.put(child.name, l);
212-
}
197+
@SuppressWarnings("unchecked")
198+
public void writeMap(EntryWriter ew) throws IOException {
199+
new NamedList<>(attributes).writeMap(ew);
200+
if (initArgs != null) {
201+
for (Map.Entry<String, Object> entry : initArgs.asMap(3).entrySet()) {
202+
ew.put(entry.getKey(), entry.getValue());
203+
}
204+
}
205+
if (children == null || children.isEmpty()) {
206+
return;
207+
}
208+
209+
Map<String, Object> childrenGrouped = new LinkedHashMap<>();
210+
for (PluginInfo child : children) {
211+
Object old = childrenGrouped.get(child.name);
212+
if (old == null) {
213+
childrenGrouped.put(child.name, child);
214+
} else if (old instanceof List) {
215+
((List<Object>) old).add(child);
216+
} else {
217+
List<Object> l = new ArrayList<>();
218+
l.add(old);
219+
l.add(child);
220+
childrenGrouped.put(child.name, l);
213221
}
214222
}
215-
return m;
223+
for (Map.Entry<String, Object> entry : childrenGrouped.entrySet()) {
224+
ew.put(entry.getKey(), entry.getValue());
225+
}
216226
}
217227

218228
/**

solr/core/src/java/org/apache/solr/core/RequestParams.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import org.apache.solr.cloud.ZkSolrResourceLoader;
27-
import org.apache.solr.common.MapSerializable;
27+
import org.apache.solr.common.MapWriter;
2828
import org.apache.solr.common.SolrException;
2929
import org.apache.solr.common.cloud.SolrZkClient;
3030
import org.apache.solr.common.params.MultiMapSolrParams;
@@ -38,7 +38,7 @@
3838
* The class encapsulates the request time parameters . This is immutable and any changes performed
3939
* returns a copy of the Object with the changed values
4040
*/
41-
public class RequestParams implements MapSerializable {
41+
public class RequestParams implements MapWriter {
4242
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
4343

4444
private final Map<String, Object> data;
@@ -112,8 +112,9 @@ public int getZnodeVersion() {
112112
}
113113

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

119120
public static Map<String, Object> getMapWithVersion(Map<String, Object> data, int znodeVersion) {
@@ -129,7 +130,9 @@ public RequestParams setParams(String name, ParamSet paramSet) {
129130
Map p = (Map) deepCopy.get(NAME);
130131
if (p == null) deepCopy.put(NAME, p = new LinkedHashMap<>());
131132
if (paramSet == null) p.remove(name);
132-
else p.put(name, paramSet.toMap(new LinkedHashMap<>()));
133+
else {
134+
p.put(name, Utils.convertToMap(paramSet, new HashMap<>()));
135+
}
133136
return new RequestParams(deepCopy, znodeVersion);
134137
}
135138

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

209212
@SuppressWarnings({"unchecked"})
210-
public static class ParamSet implements MapSerializable {
213+
public static class ParamSet implements MapWriter {
211214
private final Map<String, Object> defaults, appends, invariants;
212215
Map<String, VersionedParams> paramsMap;
213216
public final Map<String, Long> meta;
@@ -234,12 +237,11 @@ public Long getVersion() {
234237
}
235238

236239
@Override
237-
public Map<String, Object> toMap(Map<String, Object> result) {
238-
result.putAll(defaults);
239-
if (appends != null) result.put(APPENDS, appends);
240-
if (invariants != null) result.put(INVARIANTS, invariants);
241-
if (meta != null) result.put("", meta);
242-
return result;
240+
public void writeMap(EntryWriter ew) throws IOException {
241+
defaults.forEach(ew::putNoEx);
242+
if (appends != null) ew.put(APPENDS, appends);
243+
if (invariants != null) ew.put(INVARIANTS, invariants);
244+
if (meta != null) ew.put("", meta);
243245
}
244246

245247
@SuppressWarnings({"rawtypes"})

0 commit comments

Comments
 (0)