From 9897a0e7927dd87761411ed6ee2f30d2cb3a522b Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Thu, 16 Feb 2012 22:02:39 +0000 Subject: [PATCH] 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 --- solr/cloud-dev/solrcloud-start.sh | 2 +- .../apache/solr/cloud/CloudDescriptor.java | 2 +- .../org/apache/solr/cloud/ZkController.java | 28 +++++++++++++------ .../solr/cloud/BasicDistributedZkTest.java | 11 +++++++- .../solrj/request/CoreAdminRequest.java | 6 ++++ .../solr/common/params/CoreAdminParams.java | 3 ++ .../src/test-files/solrj/solr/shared/solr.xml | 4 +-- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/solr/cloud-dev/solrcloud-start.sh b/solr/cloud-dev/solrcloud-start.sh index 0bfc70b07cd..429778fe324 100644 --- a/solr/cloud-dev/solrcloud-start.sh +++ b/solr/cloud-dev/solrcloud-start.sh @@ -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 & diff --git a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java index 6d87635524d..c29b7c35981 100644 --- a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java +++ b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java @@ -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) { diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java index b6a1642e768..9770c77f37b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -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 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 diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java index 6b94d5d51a0..089bd696edd 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -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 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); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java index abc4bf538bf..de8aba85cab 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java @@ -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; } diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java index 5f42654795d..cc8a958e427 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java @@ -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, diff --git a/solr/solrj/src/test-files/solrj/solr/shared/solr.xml b/solr/solrj/src/test-files/solrj/solr/shared/solr.xml index d8a5b0583f8..dd17d78acb9 100644 --- a/solr/solrj/src/test-files/solrj/solr/shared/solr.xml +++ b/solr/solrj/src/test-files/solrj/solr/shared/solr.xml @@ -31,11 +31,11 @@ If 'null' (or absent), cores will not be manageable via REST --> - + - +