SOLR-4789: CoreAdminHandler should write core.properties files in discovery mode

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1491446 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-06-10 13:39:34 +00:00
parent 151f33407f
commit 84b3a0e40b
1 changed files with 47 additions and 0 deletions

View File

@ -18,8 +18,10 @@
package org.apache.solr.core;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.net.URL;
@ -62,6 +64,7 @@ import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.solr.cloud.CloudDescriptor;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CommonParams.EchoParamStyle;
@ -848,6 +851,12 @@ public final class SolrCore implements SolrInfoMBean {
CoreContainer cc = cd.getCoreContainer();
if (cc != null) {
if (cc.cfg != null && cc.cfg instanceof ConfigSolrXml) {
writePropFile(cd, cc);
}
}
if (cc != null && cc.isZooKeeperAware() && Slice.CONSTRUCTION.equals(cd.getCloudDescriptor().getShardState())) {
// set update log to buffer before publishing the core
getUpdateHandler().getUpdateLog().bufferUpdates();
@ -861,6 +870,44 @@ public final class SolrCore implements SolrInfoMBean {
// openHandles.put(this, new RuntimeException("unclosed core - name:" + getName() + " refs: " + refCount.get()));
}
private void writePropFile(CoreDescriptor cd, CoreContainer cc) {
File propFile = new File(cd.getInstanceDir(), "core.properties");
if (!propFile.exists()) {
propFile.getParentFile().mkdirs();
Properties props = new Properties();
props.put("name", cd.getName());
if (cc.isZooKeeperAware()) {
String collection = cd.getCloudDescriptor().getCollectionName();
if (collection != null) {
props.put("collection", collection);
}
String coreNodeName = cd.getCloudDescriptor().getCoreNodeName();
if (coreNodeName != null) {
props.put("coreNodeName", coreNodeName);
}
String roles = cd.getCloudDescriptor().getRoles();
if (roles != null) {
props.put("roles", roles);
}
String shardId = cd.getCloudDescriptor().getShardId();
if (shardId != null) {
props.put("shard", shardId);
}
}
OutputStream out = null;
try {
out = new FileOutputStream(propFile);
props.store(out, "");
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
} finally {
if (out != null) {
IOUtils.closeQuietly(out);
}
}
}
}
private Codec initCodec(SolrConfig solrConfig, final IndexSchema schema) {
final PluginInfo info = solrConfig.getPluginInfo(CodecFactory.class.getName());
final CodecFactory factory;