Revision 57157
Added by Enrico Ottonello over 4 years ago
ZkUtils.java | ||
---|---|---|
5 | 5 |
import java.util.Map; |
6 | 6 |
import java.util.Map.Entry; |
7 | 7 |
|
8 |
import com.google.common.collect.Maps; |
|
9 |
import eu.dnetlib.rmi.provision.IndexServiceException; |
|
10 | 8 |
import org.apache.commons.io.IOUtils; |
11 | 9 |
import org.apache.commons.logging.Log; |
12 | 10 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
19 | 17 |
import org.springframework.core.io.Resource; |
20 | 18 |
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
21 | 19 |
|
20 |
import com.google.common.collect.Maps; |
|
21 |
|
|
22 |
import eu.dnetlib.rmi.provision.IndexServiceException; |
|
23 |
|
|
24 |
|
|
22 | 25 |
/** |
23 | 26 |
* The Class ZkUtils. |
24 | 27 |
*/ |
... | ... | |
29 | 32 |
*/ |
30 | 33 |
private static final Log log = LogFactory.getLog(ZkUtils.class); // NOPMD by marko on 11/24/08 5:02 PM |
31 | 34 |
|
32 |
/** |
|
33 |
* The Constant CONFIGS_PATH. |
|
34 |
*/ |
|
35 |
/** The Constant CONFIGS_PATH. */ |
|
35 | 36 |
private static final String CONFIGS_PATH = "/configs"; |
36 | 37 |
|
37 |
/** |
|
38 |
* The schema factory. |
|
39 |
*/ |
|
38 |
/** The schema factory. */ |
|
40 | 39 |
@Autowired |
41 | 40 |
private IndexSchemaFactory schemaFactory; |
42 | 41 |
|
43 |
/** |
|
44 |
* The config factory. |
|
45 |
*/ |
|
42 |
/** The config factory. */ |
|
46 | 43 |
private IndexConfigFactory configFactory; |
47 | 44 |
|
48 |
/** |
|
49 |
* The static configuration classpath. |
|
50 |
*/ |
|
45 |
/** The static configuration classpath. */ |
|
51 | 46 |
private String staticConfigurationClasspath; |
52 | 47 |
|
53 | 48 |
/** |
54 | 49 |
* Upload zookeper config. |
55 |
* |
|
56 |
* @param zkClient the zk client |
|
57 |
* @param coreName the core name |
|
58 |
* @param fields the fields |
|
59 |
* @param params the params |
|
60 |
* @param overwrite the overwrite |
|
50 |
* |
|
51 |
* @param zkClient |
|
52 |
* the zk client |
|
53 |
* @param coreName |
|
54 |
* the core name |
|
55 |
* @param fields |
|
56 |
* the fields |
|
57 |
* @param params |
|
58 |
* the params |
|
59 |
* @param overwrite |
|
60 |
* the overwrite |
|
61 | 61 |
*/ |
62 | 62 |
public void uploadZookeperConfig(final SolrZkClient zkClient, |
63 | 63 |
final String coreName, |
... | ... | |
70 | 70 |
log.info("uploading solr configuration to ZK for index collection: " + coreName); |
71 | 71 |
|
72 | 72 |
try { |
73 |
if (overwrite) { |
|
73 |
if (overwrite && zkClient.getSolrZooKeeper().exists(basepath, false) != null) {
|
|
74 | 74 |
log.info("cleanup ZK configuration: " + coreName); |
75 | 75 |
for (String child : zkClient.getSolrZooKeeper().getChildren(basepath, false)) { |
76 | 76 |
final String path = basepath + "/" + child; |
... | ... | |
92 | 92 |
|
93 | 93 |
/** |
94 | 94 |
* Builds the configuration. |
95 |
* |
|
96 |
* @param indexName the index name |
|
97 |
* @param fields the fields |
|
98 |
* @param params the params |
|
95 |
* |
|
96 |
* @param indexName |
|
97 |
* the index name |
|
98 |
* @param fields |
|
99 |
* the fields |
|
100 |
* @param params |
|
101 |
* the params |
|
99 | 102 |
* @return the map |
100 |
* @throws IndexServiceException the index service exception |
|
103 |
* @throws IndexServiceException |
|
104 |
* the index service exception |
|
101 | 105 |
*/ |
102 | 106 |
private Map<String, byte[]> buildConfiguration(final String indexName, final Document fields, final Map<String, String> params) |
103 | 107 |
throws IndexServiceException { |
... | ... | |
107 | 111 |
try { |
108 | 112 |
log.debug("adding schema.xml to the resource map"); |
109 | 113 |
res.put("schema.xml", schemaFactory.getSchema(fields).getBytes()); |
110 |
|
|
114 |
|
|
111 | 115 |
res.put("solrconfig.xml", configFactory.getConfig(params).getBytes()); |
112 | 116 |
log.debug("adding solrconfig.xml to the resource map"); |
113 | 117 |
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); |
... | ... | |
116 | 120 |
for (Resource r : resources) { |
117 | 121 |
InputStream is = r.getInputStream(); |
118 | 122 |
if ((r.getFilename() != null) && !r.getFilename().isEmpty()) { |
119 |
res.put(r.getFilename(), IOUtils.toByteArray(is));
|
|
120 |
log.debug("adding " + r.getFilename() + " to the resource map");
|
|
121 |
is.close();
|
|
123 |
res.put(r.getFilename(), IOUtils.toByteArray(is));
|
|
124 |
log.debug("adding " + r.getFilename() +" to the resource map");
|
|
125 |
is.close();
|
|
122 | 126 |
} |
123 | 127 |
} |
124 | 128 |
return res; |
... | ... | |
129 | 133 |
|
130 | 134 |
/** |
131 | 135 |
* Upload configuration. |
132 |
* |
|
133 |
* @param zkClient the zk client |
|
134 |
* @param basePath the base path |
|
135 |
* @param resources the resources |
|
136 |
* @throws KeeperException the keeper exception |
|
137 |
* @throws InterruptedException the interrupted exception |
|
138 |
* @throws IOException Signals that an I/O exception has occurred. |
|
136 |
* |
|
137 |
* @param zkClient |
|
138 |
* the zk client |
|
139 |
* @param basePath |
|
140 |
* the base path |
|
141 |
* @param resources |
|
142 |
* the resources |
|
143 |
* @throws KeeperException |
|
144 |
* the keeper exception |
|
145 |
* @throws InterruptedException |
|
146 |
* the interrupted exception |
|
147 |
* @throws IOException |
|
148 |
* Signals that an I/O exception has occurred. |
|
139 | 149 |
*/ |
140 | 150 |
private void uploadConfiguration(final SolrZkClient zkClient, final String basePath, final Map<String, byte[]> resources) throws KeeperException, |
141 | 151 |
InterruptedException, IOException { |
... | ... | |
153 | 163 |
|
154 | 164 |
/** |
155 | 165 |
* Gets the config factory. |
156 |
* |
|
166 |
*
|
|
157 | 167 |
* @return the config factory |
158 | 168 |
*/ |
159 | 169 |
public IndexConfigFactory getConfigFactory() { |
... | ... | |
162 | 172 |
|
163 | 173 |
/** |
164 | 174 |
* Sets the config factory. |
165 |
* |
|
166 |
* @param configFactory the new config factory |
|
175 |
* |
|
176 |
* @param configFactory |
|
177 |
* the new config factory |
|
167 | 178 |
*/ |
168 | 179 |
@Required |
169 | 180 |
public void setConfigFactory(final IndexConfigFactory configFactory) { |
... | ... | |
172 | 183 |
|
173 | 184 |
/** |
174 | 185 |
* Gets the static configuration classpath. |
175 |
* |
|
186 |
*
|
|
176 | 187 |
* @return the static configuration classpath |
177 | 188 |
*/ |
178 | 189 |
public String getStaticConfigurationClasspath() { |
... | ... | |
181 | 192 |
|
182 | 193 |
/** |
183 | 194 |
* Sets the static configuration classpath. |
184 |
* |
|
185 |
* @param staticConfigurationClasspath the new static configuration classpath |
|
195 |
* |
|
196 |
* @param staticConfigurationClasspath |
|
197 |
* the new static configuration classpath |
|
186 | 198 |
*/ |
187 | 199 |
@Required |
188 | 200 |
public void setStaticConfigurationClasspath(final String staticConfigurationClasspath) { |
Also available in: Unified diff
solr 772 integration