Revision 48891
Added by Claudio Atzori over 6 years ago
RemoteSolrAdministrator.java | ||
---|---|---|
14 | 14 |
import org.apache.http.HttpResponse; |
15 | 15 |
import org.apache.http.client.HttpClient; |
16 | 16 |
import org.apache.http.client.methods.HttpGet; |
17 |
import org.apache.solr.client.solrj.SolrServer;
|
|
17 |
import org.apache.solr.client.solrj.SolrClient;
|
|
18 | 18 |
import org.apache.solr.client.solrj.SolrServerException; |
19 |
import org.apache.solr.client.solrj.impl.CloudSolrServer;
|
|
19 |
import org.apache.solr.client.solrj.impl.CloudSolrClient;
|
|
20 | 20 |
import org.apache.solr.client.solrj.request.LukeRequest; |
21 | 21 |
import org.apache.solr.client.solrj.response.LukeResponse; |
22 | 22 |
import org.apache.solr.client.solrj.response.LukeResponse.FieldInfo; |
23 | 23 |
import org.apache.solr.client.solrj.response.SolrPingResponse; |
24 | 24 |
import org.apache.solr.common.cloud.SolrZkClient; |
25 |
import org.apache.zookeeper.WatchedEvent; |
|
26 | 25 |
import org.apache.zookeeper.Watcher; |
27 | 26 |
import org.apache.zookeeper.data.Stat; |
28 | 27 |
import org.springframework.beans.factory.annotation.Required; |
... | ... | |
74 | 73 |
return false; |
75 | 74 |
} |
76 | 75 |
|
77 |
public boolean indexCollectionExists(final String indexCollectionId, final CloudSolrServer server) {
|
|
76 |
public boolean indexCollectionExists(final String indexCollectionId, final CloudSolrClient client) {
|
|
78 | 77 |
|
79 |
Watcher watcher = new Watcher() { |
|
80 |
|
|
81 |
@Override |
|
82 |
public void process(final WatchedEvent arg0) {} |
|
83 |
}; |
|
78 |
Watcher watcher = arg0 -> {}; |
|
84 | 79 |
try { |
85 | 80 |
// server.connect(); |
86 |
SolrZkClient client = server.getZkStateReader().getZkClient(); |
|
87 |
if (!client.isConnected()) { |
|
88 |
server.shutdown(); |
|
89 |
server.connect(); |
|
81 |
SolrZkClient zkClient = client.getZkStateReader().getZkClient(); |
|
82 |
if (!zkClient.isConnected()) { |
|
83 |
client.connect(); |
|
90 | 84 |
} |
91 | 85 |
|
92 |
byte[] data = client.getData("/clusterstate.json", watcher, new Stat(), true);
|
|
86 |
byte[] data = zkClient.getData("/clusterstate.json", watcher, new Stat(), true);
|
|
93 | 87 |
if (data == null) return false; |
94 | 88 |
String jsonLine = new String(data); |
95 | 89 |
JsonElement jelement = new JsonParser().parse(jsonLine); |
96 | 90 |
JsonObject jobject = jelement.getAsJsonObject(); |
97 | 91 |
if (jobject.has(indexCollectionId)) { |
98 |
server.setDefaultCollection(indexCollectionId);
|
|
99 |
server.connect();
|
|
100 |
SolrPingResponse status = server.ping();
|
|
92 |
client.setDefaultCollection(indexCollectionId);
|
|
93 |
client.connect();
|
|
94 |
SolrPingResponse status = client.ping();
|
|
101 | 95 |
return (Integer) status.getResponseHeader().get("status") == 0; |
102 | 96 |
} else return false; |
103 | 97 |
|
... | ... | |
117 | 111 |
else return ValueType.STRING; |
118 | 112 |
} |
119 | 113 |
|
120 |
public Map<String, ValueType> getFieldNamesAndTypes(final String coreName, final SolrServer server) throws IndexServiceException {
|
|
114 |
public Map<String, ValueType> getFieldNamesAndTypes(final String coreName, final SolrClient client) throws IndexServiceException {
|
|
121 | 115 |
try { |
122 | 116 |
if (cachedSchema.get(coreName) == null) { |
123 | 117 |
synchronized (cachedSchema) { |
124 |
Map<String, ValueType> schema = readFieldNamesAndTypes(coreName, server);
|
|
118 |
Map<String, ValueType> schema = readFieldNamesAndTypes(coreName, client);
|
|
125 | 119 |
log.info("setting cache for schema of collection: " + coreName); |
126 | 120 |
cachedSchema.put(coreName, schema); |
127 | 121 |
} |
... | ... | |
132 | 126 |
} |
133 | 127 |
} |
134 | 128 |
|
135 |
private Map<String, ValueType> readFieldNamesAndTypes(final String coreName, final SolrServer server) throws SolrServerException, IOException {
|
|
129 |
private Map<String, ValueType> readFieldNamesAndTypes(final String coreName, final SolrClient client) throws SolrServerException, IOException {
|
|
136 | 130 |
final LukeRequest request = new LukeRequest(); |
137 | 131 |
request.setShowSchema(true); |
138 | 132 |
request.setNumTerms(0); |
139 |
final LukeResponse response = request.process(server);
|
|
133 |
final LukeResponse response = request.process(client);
|
|
140 | 134 |
final Map<String, FieldInfo> fieldInfos = response.getFieldInfo(); |
141 | 135 |
final Map<String, LukeResponse.FieldTypeInfo> fieldTypeInfos = response.getFieldTypeInfo(); |
142 | 136 |
final Map<String, ValueType> result = Maps.newHashMap(); |
Also available in: Unified diff
upgraded solr version to 6.6.0