mirror of https://github.com/apache/lucene.git
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:
parent
fd6c1e657a
commit
9897a0e792
|
@ -22,7 +22,7 @@ cp -r -f example example4
|
||||||
cp -r -f example example5
|
cp -r -f example example5
|
||||||
cp -r -f example example6
|
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
|
cd example
|
||||||
java -DzkRun -DnumShards=2 -DSTOP.PORT=7983 -DSTOP.KEY=key -jar start.jar 1>example.log 2>&1 &
|
java -DzkRun -DnumShards=2 -DSTOP.PORT=7983 -DSTOP.KEY=key -jar start.jar 1>example.log 2>&1 &
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class CloudDescriptor {
|
||||||
private String shardId;
|
private String shardId;
|
||||||
private String collectionName;
|
private String collectionName;
|
||||||
private SolrParams params;
|
private SolrParams params;
|
||||||
private String roles = "";
|
private String roles = null;
|
||||||
private Integer numShards;
|
private Integer numShards;
|
||||||
|
|
||||||
public void setShardId(String shardId) {
|
public void setShardId(String shardId) {
|
||||||
|
|
|
@ -110,15 +110,21 @@ public final class ZkController {
|
||||||
// start up a tmp zk server first
|
// start up a tmp zk server first
|
||||||
String zkServerAddress = args[0];
|
String zkServerAddress = args[0];
|
||||||
|
|
||||||
String solrHome = args[1];
|
String solrPort = args[1];
|
||||||
String solrPort = args[2];
|
|
||||||
|
|
||||||
String confDir = args[3];
|
String confDir = args[2];
|
||||||
String confName = args[4];
|
String confName = args[3];
|
||||||
|
|
||||||
SolrZkServer zkServer = new SolrZkServer("true", null, solrHome, solrPort);
|
String solrHome = null;
|
||||||
zkServer.parseConfig();
|
if (args.length == 5) {
|
||||||
zkServer.start();
|
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,
|
SolrZkClient zkClient = new SolrZkClient(zkServerAddress, 15000, 5000,
|
||||||
new OnReconnect() {
|
new OnReconnect() {
|
||||||
|
@ -127,8 +133,9 @@ public final class ZkController {
|
||||||
}});
|
}});
|
||||||
|
|
||||||
uploadConfigDir(zkClient, new File(confDir), confName);
|
uploadConfigDir(zkClient, new File(confDir), confName);
|
||||||
|
if (solrHome != null) {
|
||||||
zkServer.stop();
|
zkServer.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -861,6 +868,9 @@ public final class ZkController {
|
||||||
private void publishState(CoreDescriptor cd, String shardZkNodeName, String coreName,
|
private void publishState(CoreDescriptor cd, String shardZkNodeName, String coreName,
|
||||||
Map<String,String> props) {
|
Map<String,String> props) {
|
||||||
CloudDescriptor cloudDesc = cd.getCloudDescriptor();
|
CloudDescriptor cloudDesc = cd.getCloudDescriptor();
|
||||||
|
if (cloudDesc.getRoles() != null) {
|
||||||
|
props.put(ZkStateReader.ROLES_PROP, cloudDesc.getRoles());
|
||||||
|
}
|
||||||
|
|
||||||
if (cloudDesc.getShardId() == null && needsToBeAssignedShardId(cd, zkStateReader.getCloudState(), shardZkNodeName)) {
|
if (cloudDesc.getShardId() == null && needsToBeAssignedShardId(cd, zkStateReader.getCloudState(), shardZkNodeName)) {
|
||||||
// publish with no shard id so we are assigned one, and then look for it
|
// publish with no shard id so we are assigned one, and then look for it
|
||||||
|
|
|
@ -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.request.CoreAdminRequest.Create;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
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.CommonParams;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||||
|
|
||||||
|
@ -302,7 +304,13 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
|
||||||
assertNotSame(oneDocs, twoDocs);
|
assertNotSame(oneDocs, twoDocs);
|
||||||
assertEquals(3, allDocs);
|
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 {
|
private void testSearchByCollectionName() throws SolrServerException {
|
||||||
|
@ -375,6 +383,7 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase {
|
||||||
CommonsHttpSolrServer server = new CommonsHttpSolrServer(
|
CommonsHttpSolrServer server = new CommonsHttpSolrServer(
|
||||||
baseUrl);
|
baseUrl);
|
||||||
Create createCmd = new Create();
|
Create createCmd = new Create();
|
||||||
|
createCmd.setRoles("none");
|
||||||
createCmd.setCoreName(collection + num);
|
createCmd.setCoreName(collection + num);
|
||||||
createCmd.setCollection(collection);
|
createCmd.setCollection(collection);
|
||||||
createCmd.setNumShards(2);
|
createCmd.setNumShards(2);
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class CoreAdminRequest extends SolrRequest
|
||||||
protected String collection;
|
protected String collection;
|
||||||
private Integer numShards;
|
private Integer numShards;
|
||||||
private String shardId;
|
private String shardId;
|
||||||
|
private String roles;
|
||||||
|
|
||||||
public Create() {
|
public Create() {
|
||||||
action = CoreAdminAction.CREATE;
|
action = CoreAdminAction.CREATE;
|
||||||
|
@ -65,6 +66,7 @@ public class CoreAdminRequest extends SolrRequest
|
||||||
public void setCollection(String collection) { this.collection = collection; }
|
public void setCollection(String collection) { this.collection = collection; }
|
||||||
public void setNumShards(int numShards) {this.numShards = numShards;}
|
public void setNumShards(int numShards) {this.numShards = numShards;}
|
||||||
public void setShardId(String shardId) {this.shardId = shardId;}
|
public void setShardId(String shardId) {this.shardId = shardId;}
|
||||||
|
public void setRoles(String roles) {this.roles = roles;}
|
||||||
|
|
||||||
public String getInstanceDir() { return instanceDir; }
|
public String getInstanceDir() { return instanceDir; }
|
||||||
public String getSchemaName() { return schemaName; }
|
public String getSchemaName() { return schemaName; }
|
||||||
|
@ -72,6 +74,7 @@ public class CoreAdminRequest extends SolrRequest
|
||||||
public String getDataDir() { return dataDir; }
|
public String getDataDir() { return dataDir; }
|
||||||
public String getCollection() { return collection; }
|
public String getCollection() { return collection; }
|
||||||
public String getShardId() { return shardId; }
|
public String getShardId() { return shardId; }
|
||||||
|
public String getRoles() { return roles; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SolrParams getParams() {
|
public SolrParams getParams() {
|
||||||
|
@ -104,6 +107,9 @@ public class CoreAdminRequest extends SolrRequest
|
||||||
if (shardId != null) {
|
if (shardId != null) {
|
||||||
params.set( ZkStateReader.SHARD_ID_PROP, shardId);
|
params.set( ZkStateReader.SHARD_ID_PROP, shardId);
|
||||||
}
|
}
|
||||||
|
if (roles != null) {
|
||||||
|
params.set( CoreAdminParams.ROLES, roles);
|
||||||
|
}
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,15 @@ public interface CoreAdminParams
|
||||||
/** The shard id in solr cloud */
|
/** The shard id in solr cloud */
|
||||||
public final static String SHARD = "shard";
|
public final static String SHARD = "shard";
|
||||||
|
|
||||||
|
public static final String ROLES = "roles";
|
||||||
|
|
||||||
/** Prefix for core property name=value pair **/
|
/** Prefix for core property name=value pair **/
|
||||||
public final static String PROPERTY_PREFIX = "property.";
|
public final static String PROPERTY_PREFIX = "property.";
|
||||||
|
|
||||||
/** If you unload a core, delete the index too */
|
/** If you unload a core, delete the index too */
|
||||||
public final static String DELETE_INDEX = "deleteIndex";
|
public final static String DELETE_INDEX = "deleteIndex";
|
||||||
|
|
||||||
|
|
||||||
public enum CoreAdminAction {
|
public enum CoreAdminAction {
|
||||||
STATUS,
|
STATUS,
|
||||||
LOAD,
|
LOAD,
|
||||||
|
|
|
@ -31,11 +31,11 @@
|
||||||
If 'null' (or absent), cores will not be manageable via REST
|
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">
|
<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="version" value="3.5"/>
|
||||||
<property name="l10n" value="EN"/>
|
<property name="l10n" value="EN"/>
|
||||||
<property name="ctlField" value="core0"/>
|
<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>
|
||||||
<core name="core1" instanceDir="./">
|
<core name="core1" instanceDir="./">
|
||||||
<property name="version" value="2.4"/>
|
<property name="version" value="2.4"/>
|
||||||
|
|
Loading…
Reference in New Issue