本文整理汇总了Java中org.apache.solr.common.params.CoreAdminParams类的典型用法代码示例。如果您正苦于以下问题:Java CoreAdminParams类的具体用法?Java CoreAdminParams怎么用?Java CoreAdminParams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CoreAdminParams类属于org.apache.solr.common.params包,在下文中一共展示了CoreAdminParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCores
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
/**
* Get target cores via CoreAdminAPI.
*
* @param httpSolrClient
* @return
*/
public static List<String> getCores(HttpSolrClient httpSolrClient) throws SolrServerException, IOException {
List<String> cores = new ArrayList<>();
NoOpResponseParser responseParser = new NoOpResponseParser();
responseParser.setWriterType("json");
httpSolrClient.setParser(responseParser);
CoreAdminRequest coreAdminRequest = new CoreAdminRequest();
coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS);
coreAdminRequest.setIndexInfoNeeded(false);
NamedList<Object> coreAdminResponse = httpSolrClient.request(coreAdminRequest);
JsonNode statusJsonNode = om.readTree((String) coreAdminResponse.get("response")).get("status");
for (Iterator<JsonNode> i = statusJsonNode.iterator(); i.hasNext(); ) {
String core = i.next().get("name").textValue();
if (!cores.contains(core)) {
cores.add(core);
}
}
return cores;
}
示例2: createCollection
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
public NamedList<Object> createCollection(String name, int numShards, int replicationFactor,
String configName, String createNodeSet, String asyncId, Map<String, String> collectionProperties) throws SolrServerException, IOException {
final ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, CollectionAction.CREATE.name());
params.set(CoreAdminParams.NAME, name);
params.set("numShards", numShards);
params.set("replicationFactor", replicationFactor);
params.set("collection.configName", configName);
if (null != createNodeSet) {
params.set(OverseerCollectionMessageHandler.CREATE_NODE_SET, createNodeSet);
}
if (null != asyncId) {
params.set(CommonAdminParams.ASYNC, asyncId);
}
if(collectionProperties != null) {
for(Map.Entry<String, String> property : collectionProperties.entrySet()){
params.set(CoreAdminParams.PROPERTY_PREFIX + property.getKey(), property.getValue());
}
}
return makeCollectionsRequest(params);
}
示例3: getEstimatedSizeOfShard
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
private long getEstimatedSizeOfShard(ReplicaInfo replica) throws IOException {
try (AuthorizedSolrClient solrClient =
spec.getConnectionConfiguration().createClient(replica.baseUrl())) {
CoreAdminRequest req = new CoreAdminRequest();
req.setAction(CoreAdminParams.CoreAdminAction.STATUS);
req.setIndexInfoNeeded(true);
CoreAdminResponse response;
try {
response = solrClient.process(req);
} catch (SolrServerException e) {
throw new IOException("Can not get core status from " + replica, e);
}
NamedList<Object> coreStatus = response.getCoreStatus(replica.coreName());
NamedList<Object> indexStats = (NamedList<Object>) coreStatus.get("index");
return (long) indexStats.get("sizeInBytes");
}
}
示例4: getParams
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
@Override
public SolrParams getParams() {
if (action == null) {
throw new RuntimeException("no action specified!");
}
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, action.toString());
params.set(CoreAdminParams.CORE, core);
if (indexDirs != null) {
for (String indexDir : indexDirs) {
params.add(CoreAdminParams.INDEX_DIR, indexDir);
}
}
if (srcCores != null) {
for (String srcCore : srcCores) {
params.add(CoreAdminParams.SRC_CORE, srcCore);
}
}
return params;
}
示例5: handleRequestActionStatus
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
/**
* Handle "REQUESTSTATUS" action
*/
protected void handleRequestActionStatus(SolrQueryRequest req, SolrQueryResponse rsp) {
SolrParams params = req.getParams();
String requestId = params.get(CoreAdminParams.REQUESTID);
log.info("Checking request status for : " + requestId);
if (mapContainsTask(RUNNING, requestId)) {
rsp.add(RESPONSE_STATUS, RUNNING);
} else if(mapContainsTask(COMPLETED, requestId)) {
rsp.add(RESPONSE_STATUS, COMPLETED);
rsp.add(RESPONSE, getMap(COMPLETED).get(requestId).getRspObject());
} else if(mapContainsTask(FAILED, requestId)) {
rsp.add(RESPONSE_STATUS, FAILED);
rsp.add(RESPONSE, getMap(FAILED).get(requestId).getRspObject());
} else {
rsp.add(RESPONSE_STATUS, "notfound");
rsp.add(RESPONSE_MESSAGE, "No task found in running, completed or failed tasks");
}
}
示例6: handleRequestBufferUpdatesAction
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
private void handleRequestBufferUpdatesAction(SolrQueryRequest req, SolrQueryResponse rsp) {
SolrParams params = req.getParams();
String cname = params.get(CoreAdminParams.NAME, "");
log.info("Starting to buffer updates on core:" + cname);
try (SolrCore core = coreContainer.getCore(cname)) {
if (core == null)
throw new SolrException(ErrorCode.BAD_REQUEST, "Core [" + cname + "] does not exist");
UpdateLog updateLog = core.getUpdateHandler().getUpdateLog();
if (updateLog.getState() != UpdateLog.State.ACTIVE) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Core " + cname + " not in active state");
}
updateLog.bufferUpdates();
rsp.add("core", cname);
rsp.add("status", "BUFFERING");
} catch (Throwable e) {
if (e instanceof SolrException)
throw (SolrException)e;
else
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not start buffering updates", e);
} finally {
if (req != null) req.close();
}
}
示例7: invokeOverseerOp
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
private void invokeOverseerOp(String electionNode, String op) {
ModifiableSolrParams params = new ModifiableSolrParams();
ShardHandler shardHandler = shardHandlerFactory.getShardHandler();
params.set(CoreAdminParams.ACTION, CoreAdminAction.OVERSEEROP.toString());
params.set("op", op);
params.set("qt", adminPath);
params.set("electionNode", electionNode);
ShardRequest sreq = new ShardRequest();
sreq.purpose = 1;
String replica = zkStateReader.getBaseUrlForNodeName(LeaderElector.getNodeName(electionNode));
sreq.shards = new String[]{replica};
sreq.actualShards = sreq.shards;
sreq.params = params;
shardHandler.submit(sreq, replica, sreq.params);
shardHandler.takeCompletedOrError();
}
示例8: testNonexistentCoreReload
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
@Test
public void testNonexistentCoreReload() throws Exception {
final CoreAdminHandler admin = new CoreAdminHandler(h.getCoreContainer());
SolrQueryResponse resp = new SolrQueryResponse();
try {
admin.handleRequestBody(
req(CoreAdminParams.ACTION,
CoreAdminParams.CoreAdminAction.RELOAD.toString(),
CoreAdminParams.CORE, "non-existent-core")
, resp);
fail("Was able to successfully reload non-existent-core");
} catch (Exception e) {
assertEquals("Expected error message for non-existent core.", "Core with core name [non-existent-core] does not exist.", e.getMessage());
}
}
示例9: doReloadTest
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
private void doReloadTest(String which) throws Exception {
CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");
try {
final CoreAdminHandler admin = new CoreAdminHandler(cc);
SolrQueryResponse resp = new SolrQueryResponse();
admin.handleRequestBody
(req(CoreAdminParams.ACTION,
CoreAdminParams.CoreAdminAction.RELOAD.toString(),
CoreAdminParams.CORE, which),
resp);
assertNull("Exception on reload", resp.getException());
origMatchesPersist(cc, SOLR_XML_LOTS_SYSVARS);
} finally {
cc.shutdown();
if (solrHomeDirectory.exists()) {
FileUtils.deleteDirectory(solrHomeDirectory);
}
}
}
示例10: tryCreateFail
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
private void tryCreateFail(CoreAdminHandler admin, String name, String dataDir, String... errs) throws Exception {
try {
SolrQueryResponse resp = new SolrQueryResponse();
SolrQueryRequest request = req(CoreAdminParams.ACTION,
CoreAdminParams.CoreAdminAction.CREATE.toString(),
CoreAdminParams.DATA_DIR, dataDir,
CoreAdminParams.NAME, name,
"schema", "schema.xml",
"config", "solrconfig.xml");
admin.handleRequestBody(request, resp);
fail("Should have thrown an error");
} catch (SolrException se) {
//SolrException cause = (SolrException)se.getCause();
assertEquals("Exception code should be 500", 500, se.code());
for (String err : errs) {
assertTrue("Should have seen an exception containing the an error",
se.getMessage().contains(err));
}
}
}
示例11: checkStatus
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
private void checkStatus(CoreContainer cc, Boolean ok, String core) throws Exception {
SolrQueryResponse resp = new SolrQueryResponse();
final CoreAdminHandler admin = new CoreAdminHandler(cc);
admin.handleRequestBody
(req(CoreAdminParams.ACTION,
CoreAdminParams.CoreAdminAction.STATUS.toString(),
CoreAdminParams.CORE, core),
resp);
Map<String, Exception> failures =
(Map<String, Exception>) resp.getValues().get("initFailures");
if (ok) {
if (failures.size() != 0) {
fail("Should have cleared the error, but there are failues " + failures.toString());
}
} else {
if (failures.size() == 0) {
fail("Should have had errors here but the status return has no failures!");
}
}
}
示例12: getParams
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
@Override
public SolrParams getParams() {
if (action == null) {
throw new RuntimeException("no action specified!");
}
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, action.toString());
params.set(CoreAdminParams.CORE, core);
if (indexDirs != null) {
for (String indexDir : indexDirs) {
params.set(CoreAdminParams.INDEX_DIR, indexDir);
}
}
if (srcCores != null) {
for (String srcCore : srcCores) {
params.set(CoreAdminParams.SRC_CORE, srcCore);
}
}
return params;
}
示例13: handleAliasAction
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
/**
* Handle "ALIAS" action
*
* @return true if a modification has resulted that requires persistance
* of the CoreContainer configuration.
*/
@Deprecated
protected boolean handleAliasAction(SolrQueryRequest req, SolrQueryResponse rsp) {
SolrParams params = req.getParams();
String name = params.get(CoreAdminParams.OTHER);
String cname = params.get(CoreAdminParams.CORE);
boolean doPersist = false;
if (cname.equals(name)) return doPersist;
SolrCore core = coreContainer.getCore(cname);
if (core != null) {
doPersist = coreContainer.isPersistent();
coreContainer.register(name, core, false);
// no core.close() since each entry in the cores map should increase the ref
}
return doPersist;
}
示例14: handlePersistAction
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
/**
* Handler "PERSIST" action
*
* @return true if a modification has resulted that requires persistence
* of the CoreContainer configuration.
*/
protected boolean handlePersistAction(SolrQueryRequest req, SolrQueryResponse rsp)
throws SolrException {
SolrParams params = req.getParams();
boolean doPersist = false;
String fileName = params.get(CoreAdminParams.FILE);
if (fileName != null) {
File file = new File(coreContainer.getConfigFile().getParentFile(), fileName);
coreContainer.persistFile(file);
rsp.add("saved", file.getAbsolutePath());
doPersist = false;
} else if (!coreContainer.isPersistent()) {
throw new SolrException(SolrException.ErrorCode.FORBIDDEN, "Persistence is not enabled");
} else
doPersist = true;
return doPersist;
}
示例15: handleRenameAction
import org.apache.solr.common.params.CoreAdminParams; //导入依赖的package包/类
/**
* Handle "RENAME" Action
*
* @return true if a modification has resulted that requires persistence of the CoreContainer
* configuration.
*/
protected boolean handleRenameAction(SolrQueryRequest req, SolrQueryResponse rsp) throws SolrException {
SolrParams params = req.getParams();
String name = params.get(CoreAdminParams.OTHER);
String cname = params.get(CoreAdminParams.CORE);
boolean doPersist = false;
if(cname.equals(name))
return doPersist;
doPersist = coreContainer.isPersistent();
coreContainer.rename(cname, name);
return doPersist;
}