use of org.alfresco.util.shard.ExplicitShardingPolicy in project SearchServices by Alfresco.
the class AlfrescoCoreAdminHandler method newCore.
protected boolean newCore(String coreName, int numShards, StoreRef storeRef, String templateName, int replicationFactor, int nodeInstance, int numNodes, String shardIds, Properties extraProperties, SolrQueryResponse rsp) {
try {
// copy core from template
File solrHome = new File(coreContainer.getSolrHome());
File templates = new File(solrHome, "templates");
File template = new File(templates, templateName);
if (numShards > 1) {
String collectionName = templateName + "--" + storeRef.getProtocol() + "-" + storeRef.getIdentifier() + "--shards--" + numShards + "-x-" + replicationFactor + "--node--" + nodeInstance + "-of-" + numNodes;
String coreBase = storeRef.getProtocol() + "-" + storeRef.getIdentifier() + "-";
if (coreName != null) {
collectionName = templateName + "--" + coreName + "--shards--" + numShards + "-x-" + replicationFactor + "--node--" + nodeInstance + "-of-" + numNodes;
coreBase = coreName + "-";
}
File baseDirectory = new File(solrHome, collectionName);
if (nodeInstance == -1) {
return false;
}
List<Integer> shards;
if (shardIds != null) {
shards = extractShards(shardIds, numShards);
} else {
ExplicitShardingPolicy policy = new ExplicitShardingPolicy(numShards, replicationFactor, numNodes);
if (!policy.configurationIsValid()) {
return false;
}
shards = policy.getShardIdsForNode(nodeInstance);
}
for (Integer shard : shards) {
coreName = coreBase + shard;
File newCore = new File(baseDirectory, coreName);
String solrCoreName = coreName;
if (coreName == null) {
if (storeRef.equals(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE)) {
solrCoreName = "alfresco-" + shard;
} else if (storeRef.equals(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE)) {
solrCoreName = "archive-" + shard;
}
}
createAndRegisterNewCore(rsp, extraProperties, storeRef, template, solrCoreName, newCore, numShards, shard, templateName);
}
return true;
} else {
if (coreName == null) {
coreName = storeRef.getProtocol() + "-" + storeRef.getIdentifier();
}
File newCore = new File(solrHome, coreName);
createAndRegisterNewCore(rsp, extraProperties, storeRef, template, coreName, newCore, 0, 0, templateName);
return true;
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
use of org.alfresco.util.shard.ExplicitShardingPolicy in project alfresco-repository by Alfresco.
the class ExplicitSolrStoreMappingWrapper method init.
public void init() {
httpClientFactory = (HttpClientFactory) beanFactory.getBean(wrapped.getHttpClientFactory());
random = new Random(123);
if ((wrapped.getNodes() == null) || (wrapped.getNodes().length == 0)) {
HttpClient httpClient = httpClientFactory.getHttpClient();
HttpClientParams params = httpClient.getParams();
// params.setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true);
// httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin"));
httpClientsAndBaseURLs.add(new HttpClientAndBaseUrl(httpClient, wrapped.getBaseUrl()));
} else {
for (String node : wrapped.getNodes()) {
String nodeHost = httpClientFactory.getHost();
String nodePort = "" + httpClientFactory.getPort();
String nodeBaseUrl = wrapped.getBaseUrl();
if (node.length() > 0) {
int colon = node.indexOf(':');
int forward = (colon > -1) ? node.indexOf('/', colon) : node.indexOf('/');
if (colon == -1) {
if (forward == -1) {
// single value
if (node.startsWith("/")) {
nodeBaseUrl = node;
}
try {
int port = Integer.parseInt(node);
nodePort = "" + port;
} catch (NumberFormatException nfe) {
nodeHost = node;
}
} else {
try {
String potentialPort = node.substring(0, forward);
if (potentialPort.length() > 0) {
int port = Integer.parseInt(potentialPort);
nodePort = "" + port;
}
} catch (NumberFormatException nfe) {
nodeHost = node.substring(0, forward);
}
nodeBaseUrl = node.substring(forward);
}
} else {
if (forward == -1) {
if (colon > 0) {
nodeHost = node.substring(0, colon);
}
if (colon + 1 < node.length()) {
String port = node.substring(colon + 1);
if (port.length() > 0) {
nodePort = port;
}
}
} else {
if (colon > 0) {
nodeHost = node.substring(0, colon);
}
String port = node.substring(colon + 1, forward);
if (port.length() > 0) {
nodePort = port;
}
nodeBaseUrl = node.substring(forward);
}
}
}
try {
int realPort = Integer.parseInt(nodePort);
httpClientsAndBaseURLs.add(new HttpClientAndBaseUrl(httpClientFactory.getHttpClient(nodeHost, realPort), nodeBaseUrl));
} catch (NumberFormatException nfe) {
httpClientsAndBaseURLs.add(new HttpClientAndBaseUrl(httpClientFactory.getHttpClient(nodeHost, httpClientFactory.getPort()), nodeBaseUrl));
}
}
}
policy = new ExplicitShardingPolicy(wrapped.getNumShards(), wrapped.getReplicationFactor(), httpClientsAndBaseURLs.size());
}
Aggregations