use of org.apache.solr.common.cloud.TISZkStateReader in project tis by qlangtech.
the class SolrCloudQueryResutStrategy method createCollectionTopology.
public CollectionTopology createCollectionTopology() {
CollectionTopology topology = new CollectionTopology();
TISZkStateReader clusterReader = runContext.getZkStateReader();
DocCollection docCollection = TISZkStateReader.getCollectionLive(clusterReader, domain.getAppName());
if (docCollection == null) {
throw new IllegalStateException("collection:" + domain.getAppName() + " relevant docCollection can not be null");
}
CollectionTopology.Shared shared = null;
Map<String, Slice> groups = docCollection.getSlicesMap();
short shard;
for (Map.Entry<String, Slice> entry : groups.entrySet()) {
shared = new CollectionTopology.Shared(entry.getKey());
topology.addShard(shared);
// shardName = entry.getKey();
for (Replica replic : entry.getValue().getReplicas()) {
shared.addReplic(replic);
// groupServer = new ServerJoinGroup();
// groupServer.setLeader(replic.getBool("leader", false));
// groupServer.setIpAddress(replic.getCoreUrl());
// shard = (Short.parseShort(StringUtils.substringAfter(entry.getKey(), SHARD_PREIX)));
// groupServer.setGroupIndex(--shard);
// result.add(groupServer);
}
}
return topology;
}
use of org.apache.solr.common.cloud.TISZkStateReader in project tis by qlangtech.
the class TestCollectionAction method buildZkStateReaderMock.
private void buildZkStateReaderMock() throws Exception {
TISZkStateReader tisZkStateReader = buildTisZkStateReaderMock();
DocCollection docCollection = buildDocCollectionMock(true, true, COLLECTION_NAME, tisZkStateReader);
}
use of org.apache.solr.common.cloud.TISZkStateReader in project tis by qlangtech.
the class TestCollectionAction method buildTisZkStateReaderMock.
private TISZkStateReader buildTisZkStateReaderMock() {
TISZkStateReader tisZkStateReader = this.mock("tisZkStateReader", TISZkStateReader.class);
MockClusterStateReader.mockStateReader = tisZkStateReader;
return tisZkStateReader;
}
use of org.apache.solr.common.cloud.TISZkStateReader in project tis by qlangtech.
the class SolrCloudQueryResutStrategy method query.
// @Override
// public int getServicePort() {
// return 7001;
// }
@Override
public List<ServerJoinGroup> query() {
List<ServerJoinGroup> result = new ArrayList<ServerJoinGroup>();
ServerJoinGroup groupServer = null;
TISZkStateReader clusterReader = runContext.getZkStateReader();
DocCollection docCollection = TISZkStateReader.getCollectionLive(clusterReader, domain.getAppName());
if (docCollection == null) {
throw new IllegalStateException("collection:" + domain.getAppName() + " relevant docCollection can not be null");
}
Map<String, Slice> groups = docCollection.getSlicesMap();
short shard;
for (Map.Entry<String, Slice> entry : groups.entrySet()) {
for (Replica replic : entry.getValue().getReplicas()) {
groupServer = new ServerJoinGroup();
groupServer.setLeader(replic.getBool("leader", false));
groupServer.setIpAddress(replic.getCoreUrl());
groupServer.setReplicBaseUrl(replic.getBaseUrl());
shard = (Short.parseShort(StringUtils.substringAfter(entry.getKey(), SHARD_PREIX)));
groupServer.setGroupIndex(--shard);
result.add(groupServer);
}
}
return result;
}
use of org.apache.solr.common.cloud.TISZkStateReader in project tis by qlangtech.
the class ClusterStateReader method createSerivce.
@Override
protected TISZkStateReader createSerivce(RunEnvironment runtime) {
try {
TisZkClient zkClinet = (TisZkClient) zooKeeperGetter.getInstance(runtime);
final TISZkStateReader zkStateReader = new TISZkStateReader(zkClinet.getZK());
zkClinet.addOnReconnect(() -> {
try {
zkStateReader.createClusterStateWatchersAndUpdate();
} catch (KeeperException e) {
LOG.error("A ZK error has occurred", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "A ZK error has occurred", e);
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
LOG.error("Interrupted", e);
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "Interrupted", e);
}
});
zkStateReader.createClusterStateWatchersAndUpdate();
return zkStateReader;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations