SOLR-3138: Add node roles to core admin handler 'create core' and solrj.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1245202 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-02-16 22:02:39 +00:00
parent fd6c1e657a
commit 9897a0e792
7 changed files with 42 additions and 14 deletions

View File

@ -22,7 +22,7 @@ cp -r -f example example4
cp -r -f example example5
cp -r -f example example6
java -classpath lib/*:dist/*:build/lucene-libs/* org.apache.solr.cloud.ZkController 127.0.0.1:9983 example/solr 8983 example/solr/conf conf1
java -classpath lib/*:dist/*:build/lucene-libs/* org.apache.solr.cloud.ZkController 127.0.0.1:9983 8983 example/solr/conf conf1 example/solr
cd example
java -DzkRun -DnumShards=2 -DSTOP.PORT=7983 -DSTOP.KEY=key -jar start.jar 1>example.log 2>&1 &

View File

@ -23,7 +23,7 @@ public class CloudDescriptor {
private String shardId;
private String collectionName;
private SolrParams params;
private String roles = "";
private String roles = null;
private Integer numShards;
public void setShardId(String shardId) {

View File

@ -110,15 +110,21 @@ public final class ZkController {
// start up a tmp zk server first
String zkServerAddress = args[0];
String solrHome = args[1];
String solrPort = args[2];
String solrPort = args[1];
String confDir = args[3];
String confName = args[4];
String confDir = args[2];
String confName = args[3];
SolrZkServer zkServer = new SolrZkServer("true", null, solrHome, solrPort);
zkServer.parseConfig();
zkServer.start();
String solrHome = null;
if (args.length == 5) {
solrHome = args[4];
}
SolrZkServer zkServer = null;
if (solrHome != null) {
zkServer = new SolrZkServer("true", null, solrHome, solrPort);
zkServer.parseConfig();
zkServer.start();
}
SolrZkClient zkClient = new SolrZkClient(zkServerAddress, 15000, 5000,
new OnReconnect() {
@ -127,8 +133,9 @@ public final class ZkController {
}});
uploadConfigDir(zkClient, new File(confDir), confName);
zkServer.stop();
if (solrHome != null) {
zkServer.stop();
}
}
/**
@ -861,6 +868,9 @@ public final class ZkController {
private void publishState(CoreDescriptor cd, String shardZkNodeName, String coreName,
Map<String,String> props) {
CloudDescriptor cloudDesc = cd.getCloudDescriptor();
if (cloudDesc.getRoles() != null) {
props.put(ZkStateReader.ROLES_PROP, cloudDesc.getRoles());
}
if (cloudDesc.getShardId() == null && needsToBeAssignedShardId(cd, zkStateReader.getCloudState(), shardZkNodeName)) {
// publish with no shard id so we are assigned one, and then look for it

View File

@ -33,6 +33,8 @@ import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.request.CoreAdminRequest.Create;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
@ -302,7 +304,13 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
assertNotSame(oneDocs, twoDocs);
assertEquals(3, allDocs);
// we added a role of none on these creates - check for it
ZkStateReader zkStateReader = solrj.getZkStateReader();
zkStateReader.updateCloudState(true);
Map<String,Slice> slices = zkStateReader.getCloudState().getSlices(oneInstanceCollection2);
assertNotNull(slices);
String roles = slices.get("shard1").getShards().values().iterator().next().get(ZkStateReader.ROLES_PROP);
assertEquals("none", roles);
}
private void testSearchByCollectionName() throws SolrServerException {
@ -375,6 +383,7 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
CommonsHttpSolrServer server = new CommonsHttpSolrServer(
baseUrl);
Create createCmd = new Create();
createCmd.setRoles("none");
createCmd.setCoreName(collection + num);
createCmd.setCollection(collection);
createCmd.setNumShards(2);

View File

@ -53,6 +53,7 @@ public class CoreAdminRequest extends SolrRequest
protected String collection;
private Integer numShards;
private String shardId;
private String roles;
public Create() {
action = CoreAdminAction.CREATE;
@ -65,6 +66,7 @@ public class CoreAdminRequest extends SolrRequest
public void setCollection(String collection) { this.collection = collection; }
public void setNumShards(int numShards) {this.numShards = numShards;}
public void setShardId(String shardId) {this.shardId = shardId;}
public void setRoles(String roles) {this.roles = roles;}
public String getInstanceDir() { return instanceDir; }
public String getSchemaName() { return schemaName; }
@ -72,6 +74,7 @@ public class CoreAdminRequest extends SolrRequest
public String getDataDir() { return dataDir; }
public String getCollection() { return collection; }
public String getShardId() { return shardId; }
public String getRoles() { return roles; }
@Override
public SolrParams getParams() {
@ -104,6 +107,9 @@ public class CoreAdminRequest extends SolrRequest
if (shardId != null) {
params.set( ZkStateReader.SHARD_ID_PROP, shardId);
}
if (roles != null) {
params.set( CoreAdminParams.ROLES, roles);
}
return params;
}

View File

@ -69,12 +69,15 @@ public interface CoreAdminParams
/** The shard id in solr cloud */
public final static String SHARD = "shard";
public static final String ROLES = "roles";
/** Prefix for core property name=value pair **/
public final static String PROPERTY_PREFIX = "property.";
/** If you unload a core, delete the index too */
public final static String DELETE_INDEX = "deleteIndex";
public enum CoreAdminAction {
STATUS,
LOAD,

View File

@ -31,11 +31,11 @@
If 'null' (or absent), cores will not be manageable via REST
-->
<cores adminPath="/admin/cores" defaultCoreName="core0" host="127.0.0.1" hostPort="${hostPort:8983}" hostContext="solr" zkClientTimeout="8000">
<core name="core0" instanceDir="./">
<core name="core0" instanceDir="${theInstanceDir:./}" collection="${collection:acollection}">
<property name="version" value="3.5"/>
<property name="l10n" value="EN"/>
<property name="ctlField" value="core0"/>
<property name="comment" value="This is a sample"/>
<property name="comment" value="This is a sample with a sys prop ${sysprop:default}"/>
</core>
<core name="core1" instanceDir="./">
<property name="version" value="2.4"/>