Search in sources :

Example 96 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ConfigSetsHandler method handleRequestBody.

@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);
}
Also used : ConfigSetAction(org.apache.solr.common.params.ConfigSetParams.ConfigSetAction) SolrParams(org.apache.solr.common.params.SolrParams) SolrException(org.apache.solr.common.SolrException)

Example 97 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class ConfigSetsHandler method handleConfigUploadRequest.

private void handleConfigUploadRequest(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    String configSetName = req.getParams().get(NAME);
    if (StringUtils.isBlank(configSetName)) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "The configuration name should be provided in the \"name\" parameter");
    }
    SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
    String configPathInZk = ZkConfigManager.CONFIGS_ZKNODE + Path.SEPARATOR + configSetName;
    if (zkClient.exists(configPathInZk, true)) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "The configuration " + configSetName + " already exists in zookeeper");
    }
    Iterator<ContentStream> contentStreamsIterator = req.getContentStreams().iterator();
    if (!contentStreamsIterator.hasNext()) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "No stream found for the config data to be uploaded");
    }
    InputStream inputStream = contentStreamsIterator.next().getStream();
    // Create a node for the configuration in zookeeper
    boolean trusted = getTrusted(req);
    zkClient.makePath(configPathInZk, ("{\"trusted\": " + Boolean.toString(trusted) + "}").getBytes(StandardCharsets.UTF_8), true);
    ZipInputStream zis = new ZipInputStream(inputStream, StandardCharsets.UTF_8);
    ZipEntry zipEntry = null;
    while ((zipEntry = zis.getNextEntry()) != null) {
        String filePathInZk = configPathInZk + "/" + zipEntry.getName();
        if (zipEntry.isDirectory()) {
            zkClient.makePath(filePathInZk, true);
        } else {
            createZkNodeIfNotExistsAndSetData(zkClient, filePathInZk, IOUtils.toByteArray(zis));
        }
    }
    zis.close();
}
Also used : ContentStream(org.apache.solr.common.util.ContentStream) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) SolrException(org.apache.solr.common.SolrException)

Example 98 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class CoreAdminHandler method handleRequestBody.

@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);
        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);
    }
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 99 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class CreateSnapshotOp method execute.

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
    CoreContainer cc = it.handler.getCoreContainer();
    final SolrParams params = it.req.getParams();
    String commitName = params.required().get(CoreAdminParams.COMMIT_NAME);
    String cname = params.required().get(CoreAdminParams.CORE);
    try (SolrCore core = cc.getCore(cname)) {
        if (core == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
        }
        String indexDirPath = core.getIndexDir();
        IndexCommit ic = core.getDeletionPolicy().getLatestCommit();
        if (ic == null) {
            RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
            try {
                ic = searcher.get().getIndexReader().getIndexCommit();
            } finally {
                searcher.decref();
            }
        }
        SolrSnapshotMetaDataManager mgr = core.getSnapshotMetaDataManager();
        mgr.snapshot(commitName, indexDirPath, ic.getGeneration());
        it.rsp.add(CoreAdminParams.CORE, core.getName());
        it.rsp.add(CoreAdminParams.COMMIT_NAME, commitName);
        it.rsp.add(SolrSnapshotManager.INDEX_DIR_PATH, indexDirPath);
        it.rsp.add(SolrSnapshotManager.GENERATION_NUM, ic.getGeneration());
        it.rsp.add(SolrSnapshotManager.FILE_LIST, ic.getFileNames());
    }
}
Also used : SolrSnapshotMetaDataManager(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager) CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) SolrParams(org.apache.solr.common.params.SolrParams) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SolrException(org.apache.solr.common.SolrException) IndexCommit(org.apache.lucene.index.IndexCommit)

Example 100 with SolrException

use of org.apache.solr.common.SolrException in project lucene-solr by apache.

the class InfoHandler method handle.

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);
}
Also used : RequestHandlerBase(org.apache.solr.handler.RequestHandlerBase) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrException (org.apache.solr.common.SolrException)616 IOException (java.io.IOException)171 ArrayList (java.util.ArrayList)100 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)80 NamedList (org.apache.solr.common.util.NamedList)79 HashMap (java.util.HashMap)75 Map (java.util.Map)70 SolrParams (org.apache.solr.common.params.SolrParams)64 KeeperException (org.apache.zookeeper.KeeperException)60 Test (org.junit.Test)55 Replica (org.apache.solr.common.cloud.Replica)48 Slice (org.apache.solr.common.cloud.Slice)45 DocCollection (org.apache.solr.common.cloud.DocCollection)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)39 SchemaField (org.apache.solr.schema.SchemaField)39 List (java.util.List)38 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)38 SolrServerException (org.apache.solr.client.solrj.SolrServerException)36 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33