use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class ZkNodePropsTest method testBasic.
@Test
public void testBasic() throws IOException {
Map<String, Object> props = new HashMap<>();
props.put("prop1", "value1");
props.put("prop2", "value2");
props.put("prop3", "value3");
props.put("prop4", "value4");
props.put("prop5", "value5");
props.put("prop6", "value6");
ZkNodeProps zkProps = new ZkNodeProps(props);
byte[] bytes = Utils.toJSON(zkProps);
ZkNodeProps props2 = ZkNodeProps.load(bytes);
assertEquals("value1", props2.getStr("prop1"));
assertEquals("value2", props2.getStr("prop2"));
assertEquals("value3", props2.getStr("prop3"));
assertEquals("value4", props2.getStr("prop4"));
assertEquals("value5", props2.getStr("prop5"));
assertEquals("value6", props2.getStr("prop6"));
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method showCounts.
public void showCounts() {
Set<String> theShards = shardToJetty.keySet();
for (String shard : theShards) {
List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
for (CloudJettyRunner cjetty : solrJetties) {
ZkNodeProps props = cjetty.info;
System.err.println("PROPS:" + props);
try {
SolrParams query = params("q", "*:*", "rows", "0", "distrib", "false", "tests", // "tests" is just a
"checkShardConsistency");
// tag that won't do
// anything except be
// echoed in logs
long num = cjetty.client.solrClient.query(query).getResults().getNumFound();
System.err.println("DOCS:" + num);
} catch (SolrServerException | SolrException | IOException e) {
System.err.println("error contacting client: " + e.getMessage() + "\n");
continue;
}
boolean live = false;
String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
live = true;
}
System.err.println(" live:" + live);
}
}
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class AbstractZkTestCase method buildZooKeeper.
// static to share with distrib test
public static void buildZooKeeper(String zkHost, String zkAddress, File solrhome, String config, String schema) throws Exception {
SolrZkClient zkClient = new SolrZkClient(zkHost, AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null);
zkClient.makePath("/solr", false, true);
zkClient.close();
zkClient = new SolrZkClient(zkAddress, AbstractZkTestCase.TIMEOUT);
Map<String, Object> props = new HashMap<>();
props.put("configName", "conf1");
final ZkNodeProps zkProps = new ZkNodeProps(props);
zkClient.makePath("/collections/collection1", Utils.toJSON(zkProps), CreateMode.PERSISTENT, true);
zkClient.makePath("/collections/collection1/shards", CreateMode.PERSISTENT, true);
zkClient.makePath("/collections/control_collection", Utils.toJSON(zkProps), CreateMode.PERSISTENT, true);
zkClient.makePath("/collections/control_collection/shards", CreateMode.PERSISTENT, true);
// for now, always upload the config and schema to the canonical names
putConfig("conf1", zkClient, solrhome, config, "solrconfig.xml");
putConfig("conf1", zkClient, solrhome, schema, "schema.xml");
putConfig("conf1", zkClient, solrhome, "solrconfig.snippet.randomindexconfig.xml");
putConfig("conf1", zkClient, solrhome, "stopwords.txt");
putConfig("conf1", zkClient, solrhome, "protwords.txt");
putConfig("conf1", zkClient, solrhome, "currency.xml");
putConfig("conf1", zkClient, solrhome, "enumsConfig.xml");
putConfig("conf1", zkClient, solrhome, "open-exchange-rates.json");
putConfig("conf1", zkClient, solrhome, "mapping-ISOLatin1Accent.txt");
putConfig("conf1", zkClient, solrhome, "old_synonyms.txt");
putConfig("conf1", zkClient, solrhome, "synonyms.txt");
zkClient.close();
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class ForceLeaderTest method unsetLeader.
protected void unsetLeader(String collection, String slice) throws Exception {
DistributedQueue inQueue = Overseer.getStateUpdateQueue(cloudClient.getZkStateReader().getZkClient());
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.LEADER.toLower(), ZkStateReader.SHARD_ID_PROP, slice, ZkStateReader.COLLECTION_PROP, collection);
inQueue.offer(Utils.toJSON(m));
ClusterState clusterState = null;
boolean transition = false;
for (int counter = 10; counter > 0; counter--) {
clusterState = zkStateReader.getClusterState();
Replica newLeader = clusterState.getSlice(collection, slice).getLeader();
if (newLeader == null) {
transition = true;
break;
}
Thread.sleep(1000);
}
if (!transition) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not unset replica leader" + ". Cluster state: " + printClusterStateInfo(collection));
}
}
use of org.apache.solr.common.cloud.ZkNodeProps in project lucene-solr by apache.
the class LeaderElectionTest method testCancelElection.
@Test
public void testCancelElection() throws Exception {
LeaderElector first = new LeaderElector(zkClient);
ZkNodeProps props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, "http://127.0.0.1/solr/", ZkStateReader.CORE_NAME_PROP, "1");
ElectionContext firstContext = new ShardLeaderElectionContextBase(first, "slice1", "collection2", "dummynode1", props, zkStateReader);
first.setup(firstContext);
first.joinElection(firstContext, false);
Thread.sleep(1000);
assertEquals("original leader was not registered", "http://127.0.0.1/solr/1/", getLeaderUrl("collection2", "slice1"));
LeaderElector second = new LeaderElector(zkClient);
props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, "http://127.0.0.1/solr/", ZkStateReader.CORE_NAME_PROP, "2");
ElectionContext context = new ShardLeaderElectionContextBase(second, "slice1", "collection2", "dummynode2", props, zkStateReader);
second.setup(context);
second.joinElection(context, false);
Thread.sleep(1000);
assertEquals("original leader should have stayed leader", "http://127.0.0.1/solr/1/", getLeaderUrl("collection2", "slice1"));
firstContext.cancelElection();
Thread.sleep(1000);
assertEquals("new leader was not registered", "http://127.0.0.1/solr/2/", getLeaderUrl("collection2", "slice1"));
}
Aggregations