Java Code Examples for org.apache.solr.response.SolrQueryResponse#setHttpCaching()
The following examples show how to use
org.apache.solr.response.SolrQueryResponse#setHttpCaching() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertiesRequestHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { NamedList<String> props = new SimpleOrderedMap<>(); String name = req.getParams().get(NAME); if( name != null ) { String property = getSecuredPropertyValue(name); props.add( name, property); } else { Enumeration<?> enumeration = System.getProperties().propertyNames(); while(enumeration.hasMoreElements()){ name = (String) enumeration.nextElement(); props.add(name, getSecuredPropertyValue(name)); } } rsp.add( "system.properties", props ); rsp.setHttpCaching(false); }
Example 2
Source File: InfoHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private void handle(SolrQueryRequest req, SolrQueryResponse rsp, String path) { int i = path.lastIndexOf('/'); String name = path.substring(i + 1, path.length()); RequestHandlerBase handler = handlers.get(name.toLowerCase(Locale.ROOT)); if(handler == null) { throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No handler by name "+name + " available names are "+ handlers.keySet()); } handler.handleRequest(req, rsp); rsp.setHttpCaching(false); }
Example 3
Source File: SystemInfoHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { rsp.setHttpCaching(false); SolrCore core = req.getCore(); if (AdminHandlersProxy.maybeProxyToNodes(req, rsp, getCoreContainer(req, core))) { return; // Request was proxied to other node } if (core != null) rsp.add( "core", getCoreInfo( core, req.getSchema() ) ); boolean solrCloudMode = getCoreContainer(req, core).isZooKeeperAware(); rsp.add( "mode", solrCloudMode ? "solrcloud" : "std"); if (solrCloudMode) { rsp.add("zkHost", getCoreContainer(req, core).getZkController().getZkServerAddress()); } if (cc != null) rsp.add( "solr_home", cc.getSolrHome()); rsp.add( "lucene", getLuceneInfo() ); rsp.add( "jvm", getJvmInfo() ); rsp.add( "security", getSecurityInfo(req) ); rsp.add( "system", getSystemInfo() ); if (solrCloudMode) { rsp.add("node", getCoreContainer(req, core).getZkController().getNodeName()); } SolrEnvironment env = SolrEnvironment.getFromSyspropOrClusterprop(solrCloudMode ? getCoreContainer(req, core).getZkController().zkStateReader : null); if (env.isDefined()) { rsp.add("environment", env.getCode()); if (env.getLabel() != null) { rsp.add("environment_label", env.getLabel()); } if (env.getColor() != null) { rsp.add("environment_color", env.getColor()); } } }
Example 4
Source File: CollectionsHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { // Make sure the cores is enabled CoreContainer cores = getCoreContainer(); if (cores == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core container instance missing"); } // Make sure that the core is ZKAware if (!cores.isZooKeeperAware()) { throw new SolrException(ErrorCode.BAD_REQUEST, "Solr instance is not running in SolrCloud mode."); } // Pick the action SolrParams params = req.getParams(); String a = params.get(CoreAdminParams.ACTION); if (a != null) { CollectionAction action = CollectionAction.get(a); if (action == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + a); } CollectionOperation operation = CollectionOperation.get(action); if (log.isInfoEnabled()) { log.info("Invoked Collection Action :{} with params {} and sendToOCPQueue={}" , action.toLower(), req.getParamString(), operation.sendToOCPQueue); } MDCLoggingContext.setCollection(req.getParams().get(COLLECTION)); invokeAction(req, rsp, cores, action, operation); } else { throw new SolrException(ErrorCode.BAD_REQUEST, "action is a required param"); } rsp.setHttpCaching(false); }
Example 5
Source File: SolrInfoMBeanHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { NamedList<NamedList<NamedList<Object>>> cats = getMBeanInfo(req); if(req.getParams().getBool("diff", false)) { ContentStream body = null; try { body = req.getContentStreams().iterator().next(); } catch(Exception ex) { throw new SolrException(ErrorCode.BAD_REQUEST, "missing content-stream for diff"); } String content = IOUtils.toString(body.getReader()); NamedList<NamedList<NamedList<Object>>> ref = fromXML(content); // Normalize the output SolrQueryResponse wrap = new SolrQueryResponse(); wrap.add("solr-mbeans", cats); cats = (NamedList<NamedList<NamedList<Object>>>) BinaryResponseWriter.getParsedResponse(req, wrap).get("solr-mbeans"); // Get rid of irrelevant things ref = normalize(ref); cats = normalize(cats); // Only the changes boolean showAll = req.getParams().getBool("all", false); rsp.add("solr-mbeans", getDiff(ref,cats, showAll)); } else { rsp.add("solr-mbeans", cats); } rsp.setHttpCaching(false); // never cache, no matter what init config looks like }
Example 6
Source File: PluginInfoHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { SolrParams params = req.getParams(); boolean stats = params.getBool( "stats", false ); rsp.add( "plugins", getSolrInfoBeans( req.getCore(), stats ) ); rsp.setHttpCaching(false); }
Example 7
Source File: ConfigSetsHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { if (coreContainer == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core container instance missing"); } // Make sure that the core is ZKAware if (!coreContainer.isZooKeeperAware()) { throw new SolrException(ErrorCode.BAD_REQUEST, "Solr instance is not running in SolrCloud mode."); } // Pick the action SolrParams params = req.getParams(); String a = params.get(ConfigSetParams.ACTION); if (a != null) { ConfigSetAction action = ConfigSetAction.get(a); if (action == null) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + a); if (action == ConfigSetAction.UPLOAD) { handleConfigUploadRequest(req, rsp); return; } invokeAction(req, rsp, action); } else { throw new SolrException(ErrorCode.BAD_REQUEST, "action is a required param"); } rsp.setHttpCaching(false); }
Example 8
Source File: MMseg4jHandler.java From mmseg4j-solr with Apache License 2.0 | 5 votes |
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { rsp.setHttpCaching(false); final SolrParams solrParams = req.getParams(); String dicPath = solrParams.get("dicPath"); Dictionary dict = Utils.getDict(dicPath, loader); NamedList<Object> result = new NamedList<Object>(); result.add("dicPath", dict.getDicPath().toURI()); boolean check = solrParams.getBool("check", false); //仅仅用于检测词库是否有变化 //用于尝试加载词库,有此参数, check 参数可以省略。 boolean reload = solrParams.getBool("reload", false); check |= reload; boolean changed = false; boolean reloaded = false; if(check) { changed = dict.wordsFileIsChange(); result.add("changed", changed); } if(changed && reload) { reloaded = dict.reload(); result.add("reloaded", reloaded); } rsp.add("result", result); }
Example 9
Source File: HealthCheckHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { CoreContainer cores = getCoreContainer(); rsp.setHttpCaching(false); // Core container should not be null and active (redundant check) if(cores == null || cores.isShutDown()) { rsp.setException(new SolrException(SolrException.ErrorCode.SERVER_ERROR, "CoreContainer is either not initialized or shutting down")); return; } if(!cores.isZooKeeperAware()) { //TODO: Support standalone instances rsp.setException(new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Health check is only available when running in SolrCloud mode")); return; } if (log.isDebugEnabled()) { log.debug("Invoked HealthCheckHandler on [{}]", coreContainer.getZkController().getNodeName()); } ZkStateReader zkStateReader = cores.getZkController().getZkStateReader(); ClusterState clusterState = zkStateReader.getClusterState(); // Check for isConnected and isClosed if(zkStateReader.getZkClient().isClosed() || !zkStateReader.getZkClient().isConnected()) { rsp.add(STATUS, FAILURE); rsp.setException(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Host Unavailable: Not connected to zk")); return; } // Fail if not in live_nodes if (!clusterState.getLiveNodes().contains(cores.getZkController().getNodeName())) { rsp.add(STATUS, FAILURE); rsp.setException(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Host Unavailable: Not in live nodes as per zk")); return; } // Optionally require that all cores on this node are active if param 'requireHealthyCores=true' if (req.getParams().getBool(PARAM_REQUIRE_HEALTHY_CORES, false)) { Collection<CloudDescriptor> coreDescriptors = cores.getCores().stream() .map(c -> c.getCoreDescriptor().getCloudDescriptor()).collect(Collectors.toList()); long unhealthyCores = findUnhealthyCores(coreDescriptors, clusterState); if (unhealthyCores > 0) { rsp.add(STATUS, FAILURE); rsp.add("num_cores_unhealthy", unhealthyCores); rsp.setException(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, unhealthyCores + " out of " + cores.getAllCoreNames().size() + " replicas are currently initializing or recovering")); return; } rsp.add("message", "All cores are healthy"); } // All lights green, report healthy rsp.add(STATUS, OK); }
Example 10
Source File: SegmentsInfoRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { getSegmentsInfo(req, rsp); rsp.setHttpCaching(false); }
Example 11
Source File: ShowFileRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer coreContainer) throws KeeperException, InterruptedException, UnsupportedEncodingException { SolrZkClient zkClient = coreContainer.getZkController().getZkClient(); String adminFile = getAdminFileFromZooKeeper(req, rsp, zkClient, hiddenFiles); if (adminFile == null) { return; } // Show a directory listing List<String> children = zkClient.getChildren(adminFile, null, true); if (children.size() > 0) { NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>(); for (String f : children) { if (isHiddenFile(req, rsp, f, false, hiddenFiles)) { continue; } SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>(); files.add(f, fileInfo); List<String> fchildren = zkClient.getChildren(adminFile + "/" + f, null, true); if (fchildren.size() > 0) { fileInfo.add("directory", true); } else { // TODO? content type fileInfo.add("size", f.length()); } // TODO: ? // fileInfo.add( "modified", new Date( f.lastModified() ) ); } rsp.add("files", files); } else { // Include the file contents // The file logic depends on RawResponseWriter, so force its use. ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); params.set(CommonParams.WT, "raw"); req.setParams(params); ContentStreamBase content = new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null, true), adminFile); content.setContentType(req.getParams().get(USE_CONTENT_TYPE)); rsp.add(RawResponseWriter.CONTENT, content); } rsp.setHttpCaching(false); }
Example 12
Source File: ShowFileRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) { File adminFile = getAdminFileFromFileSystem(req, rsp, hiddenFiles); if (adminFile == null) { // exception already recorded return; } // Make sure the file exists, is readable and is not a hidden file if( !adminFile.exists() ) { log.error("Can not find: {} [{}]", adminFile.getName(), adminFile.getAbsolutePath()); rsp.setException(new SolrException ( ErrorCode.NOT_FOUND, "Can not find: "+adminFile.getName() + " ["+adminFile.getAbsolutePath()+"]" )); return; } if( !adminFile.canRead() || adminFile.isHidden() ) { log.error("Can not show: {} [{}]", adminFile.getName(), adminFile.getAbsolutePath()); rsp.setException(new SolrException ( ErrorCode.NOT_FOUND, "Can not show: "+adminFile.getName() + " ["+adminFile.getAbsolutePath()+"]" )); return; } // Show a directory listing if( adminFile.isDirectory() ) { // it's really a directory, just go for it. int basePath = adminFile.getAbsolutePath().length() + 1; NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>(); for( File f : adminFile.listFiles() ) { String path = f.getAbsolutePath().substring( basePath ); path = path.replace( '\\', '/' ); // normalize slashes if (isHiddenFile(req, rsp, f.getName().replace('\\', '/'), false, hiddenFiles)) { continue; } SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>(); files.add( path, fileInfo ); if( f.isDirectory() ) { fileInfo.add( "directory", true ); } else { // TODO? content type fileInfo.add( "size", f.length() ); } fileInfo.add( "modified", new Date( f.lastModified() ) ); } rsp.add("files", files); } else { // Include the file contents //The file logic depends on RawResponseWriter, so force its use. ModifiableSolrParams params = new ModifiableSolrParams( req.getParams() ); params.set( CommonParams.WT, "raw" ); req.setParams(params); ContentStreamBase content = new ContentStreamBase.FileStream( adminFile ); content.setContentType(req.getParams().get(USE_CONTENT_TYPE)); rsp.add(RawResponseWriter.CONTENT, content); } rsp.setHttpCaching(false); }
Example 13
Source File: CoreAdminHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { // Make sure the cores is enabled try { CoreContainer cores = getCoreContainer(); if (cores == null) { throw new SolrException(ErrorCode.BAD_REQUEST, "Core container instance missing"); } //boolean doPersist = false; final String taskId = req.getParams().get(CommonAdminParams.ASYNC); final TaskObject taskObject = new TaskObject(taskId); if(taskId != null) { // Put the tasks into the maps for tracking if (getRequestStatusMap(RUNNING).containsKey(taskId) || getRequestStatusMap(COMPLETED).containsKey(taskId) || getRequestStatusMap(FAILED).containsKey(taskId)) { throw new SolrException(ErrorCode.BAD_REQUEST, "Duplicate request with the same requestid found."); } addTask(RUNNING, taskObject); } // Pick the action CoreAdminOperation op = opMap.get(req.getParams().get(ACTION, STATUS.toString()).toLowerCase(Locale.ROOT)); if (op == null) { handleCustomAction(req, rsp); return; } final CallInfo callInfo = new CallInfo(this, req, rsp, op); String coreName = req.getParams().get(CoreAdminParams.CORE); if (coreName == null) { coreName = req.getParams().get(CoreAdminParams.NAME); } MDCLoggingContext.setCoreName(coreName); if (taskId == null) { callInfo.call(); } else { try { MDC.put("CoreAdminHandler.asyncId", taskId); MDC.put("CoreAdminHandler.action", op.action.toString()); parallelExecutor.execute(() -> { boolean exceptionCaught = false; try { callInfo.call(); taskObject.setRspObject(callInfo.rsp); } catch (Exception e) { exceptionCaught = true; taskObject.setRspObjectFromException(e); } finally { removeTask("running", taskObject.taskId); if (exceptionCaught) { addTask("failed", taskObject, true); } else { addTask("completed", taskObject, true); } } }); } finally { MDC.remove("CoreAdminHandler.asyncId"); MDC.remove("CoreAdminHandler.action"); } } } finally { rsp.setHttpCaching(false); } }
Example 14
Source File: ReplicationHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { rsp.setHttpCaching(false); final SolrParams solrParams = req.getParams(); String command = solrParams.required().get(COMMAND); // This command does not give the current index version of the master // It gives the current 'replicateable' index version if (command.equals(CMD_INDEX_VERSION)) { IndexCommit commitPoint = indexCommitPoint; // make a copy so it won't change if (commitPoint == null) { // if this handler is 'lazy', we may not have tracked the last commit // because our commit listener is registered on inform commitPoint = core.getDeletionPolicy().getLatestCommit(); } if (commitPoint != null && replicationEnabled.get()) { // // There is a race condition here. The commit point may be changed / deleted by the time // we get around to reserving it. This is a very small window though, and should not result // in a catastrophic failure, but will result in the client getting an empty file list for // the CMD_GET_FILE_LIST command. // core.getDeletionPolicy().setReserveDuration(commitPoint.getGeneration(), reserveCommitDuration); rsp.add(CMD_INDEX_VERSION, IndexDeletionPolicyWrapper.getCommitTimestamp(commitPoint)); rsp.add(GENERATION, commitPoint.getGeneration()); rsp.add(STATUS, OK_STATUS); } else { // This happens when replication is not configured to happen after startup and no commit/optimize // has happened yet. rsp.add(CMD_INDEX_VERSION, 0L); rsp.add(GENERATION, 0L); rsp.add(STATUS, OK_STATUS); } } else if (command.equals(CMD_GET_FILE)) { getFileStream(solrParams, rsp); } else if (command.equals(CMD_GET_FILE_LIST)) { getFileList(solrParams, rsp); } else if (command.equalsIgnoreCase(CMD_BACKUP)) { doSnapShoot(new ModifiableSolrParams(solrParams), rsp, req); } else if (command.equalsIgnoreCase(CMD_RESTORE)) { restore(new ModifiableSolrParams(solrParams), rsp, req); } else if (command.equalsIgnoreCase(CMD_RESTORE_STATUS)) { populateRestoreStatus(rsp); } else if (command.equalsIgnoreCase(CMD_DELETE_BACKUP)) { deleteSnapshot(new ModifiableSolrParams(solrParams), rsp); } else if (command.equalsIgnoreCase(CMD_FETCH_INDEX)) { fetchIndex(solrParams, rsp); } else if (command.equalsIgnoreCase(CMD_DISABLE_POLL)) { disablePoll(rsp); } else if (command.equalsIgnoreCase(CMD_ENABLE_POLL)) { enablePoll(rsp); } else if (command.equalsIgnoreCase(CMD_ABORT_FETCH)) { if (abortFetch()) { rsp.add(STATUS, OK_STATUS); } else { reportErrorOnResponse(rsp, "No slave configured", null); } } else if (command.equals(CMD_SHOW_COMMITS)) { populateCommitInfo(rsp); } else if (command.equals(CMD_DETAILS)) { getReplicationDetails(rsp, solrParams.getBool("slave", true)); } else if (CMD_ENABLE_REPL.equalsIgnoreCase(command)) { replicationEnabled.set(true); rsp.add(STATUS, OK_STATUS); } else if (CMD_DISABLE_REPL.equalsIgnoreCase(command)) { replicationEnabled.set(false); rsp.add(STATUS, OK_STATUS); } }
Example 15
Source File: CdcrRequestHandler.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { // Pick the action SolrParams params = req.getParams(); CdcrParams.CdcrAction action = null; String a = params.get(CommonParams.ACTION); if (a != null) { action = CdcrParams.CdcrAction.get(a); } if (action == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown action: " + a); } switch (action) { case START: { this.handleStartAction(req, rsp); break; } case STOP: { this.handleStopAction(req, rsp); break; } case STATUS: { this.handleStatusAction(req, rsp); break; } case COLLECTIONCHECKPOINT: { this.handleCollectionCheckpointAction(req, rsp); break; } case SHARDCHECKPOINT: { this.handleShardCheckpointAction(req, rsp); break; } case ENABLEBUFFER: { this.handleEnableBufferAction(req, rsp); break; } case DISABLEBUFFER: { this.handleDisableBufferAction(req, rsp); break; } case LASTPROCESSEDVERSION: { this.handleLastProcessedVersionAction(req, rsp); break; } case QUEUES: { this.handleQueuesAction(req, rsp); break; } case OPS: { this.handleOpsAction(req, rsp); break; } case ERRORS: { this.handleErrorsAction(req, rsp); break; } case BOOTSTRAP: { this.handleBootstrapAction(req, rsp); break; } case BOOTSTRAP_STATUS: { this.handleBootstrapStatus(req, rsp); break; } case CANCEL_BOOTSTRAP: { this.handleCancelBootstrap(req, rsp); break; } default: { throw new RuntimeException("Unknown action: " + action); } } rsp.setHttpCaching(false); }