diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java index 164be383c04..bd1c2760c66 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java @@ -225,10 +225,21 @@ public class ClusterState implements JSONWriter.Writable { } private static DocCollection collectionFromObjects(String name, Map objs) { - Map props = (Map)objs.get(DocCollection.PROPERTIES); - if (props == null) props = Collections.emptyMap(); + Map props; + Map slices; + + Map sliceObjs = (Map)objs.get(DocCollection.SHARDS); + if (sliceObjs == null) { + // legacy format from 4.0... there was no separate "shards" level to contain the collection shards. + slices = makeSlices(objs); + props = Collections.emptyMap(); + } else { + slices = makeSlices(sliceObjs); + props = new HashMap(objs); + objs.remove(DocCollection.SHARDS); + } + DocRouter router = DocRouter.getDocRouter(props.get(DocCollection.DOC_ROUTER)); - Map slices = makeSlices(objs); return new DocCollection(name, slices, props, router); } @@ -237,15 +248,12 @@ public class ClusterState implements JSONWriter.Writable { Map result = new LinkedHashMap(genericSlices.size()); for (Map.Entry entry : genericSlices.entrySet()) { String name = entry.getKey(); - if (DocCollection.PROPERTIES.equals(name)) continue; // skip special properties entry Object val = entry.getValue(); - Slice s; if (val instanceof Slice) { - s = (Slice)val; - } else { - s = new Slice(name, null, (Map)val); + result.put(name, (Slice)val); + } else if (val instanceof Map) { + result.put(name, new Slice(name, null, (Map)val)); } - result.put(name, s); } return result; } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java index 9d0a0e7e77a..2803a2dba58 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java @@ -21,6 +21,7 @@ import org.apache.noggit.JSONUtil; import org.apache.noggit.JSONWriter; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -29,18 +30,24 @@ import java.util.Map; * Models a Collection in zookeeper (but that Java name is obviously taken, hence "DocCollection") */ public class DocCollection extends ZkNodeProps { - public static final String PROPERTIES = "properties"; public static final String DOC_ROUTER = "router"; + public static final String SHARDS = "shards"; private final String name; private final Map slices; private final DocRouter router; + /** + * @param name The name of the collection + * @param slices The logical shards of the collection. This is used directly and a copy is not made. + * @param props The properties of the slice. This is used directly and a copy is not made. + */ public DocCollection(String name, Map slices, Map props, DocRouter router) { - super(props == null ? new HashMap(1) : props); + super( props==null ? Collections.emptyMap() : props); this.name = name; this.slices = slices; this.router = router; + assert name != null && slices != null; } @@ -81,10 +88,9 @@ public class DocCollection extends ZkNodeProps { @Override public void write(JSONWriter jsonWriter) { - // write out the properties under "properties" LinkedHashMap all = new LinkedHashMap(slices.size()+1); - all.put(PROPERTIES, propMap); - all.putAll(slices); + all.putAll(propMap); + all.put(SHARDS, slices); jsonWriter.write(all); } } diff --git a/solr/webapp/web/js/scripts/cloud.js b/solr/webapp/web/js/scripts/cloud.js index 70705e308fd..5a3083be632 100644 --- a/solr/webapp/web/js/scripts/cloud.js +++ b/solr/webapp/web/js/scripts/cloud.js @@ -369,13 +369,13 @@ var prepare_graph = function( graph_element, callback ) for( var c in state ) { var shards = []; - for( var s in state[c] ) + for( var s in state[c].shards ) { var nodes = []; - for( var n in state[c][s].replicas ) + for( var n in state[c].shards[s].replicas ) { leaf_count++; - var replica = state[c][s].replicas[n] + var replica = state[c].shards[s].replicas[n] var uri = replica.base_url; var parts = uri.match( /^(\w+:)\/\/(([\w\d\.-]+)(:(\d+))?)(.+)$/ );