Search in sources :

Example 76 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 77 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 78 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)

Example 79 with SolrException

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

the class BackupCoreOp method execute.

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
    ZkController zkController = it.handler.coreContainer.getZkController();
    if (zkController == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Internal SolrCloud API");
    }
    final SolrParams params = it.req.getParams();
    String cname = params.get(CoreAdminParams.CORE);
    if (cname == null) {
        throw new IllegalArgumentException(CoreAdminParams.CORE + " is required");
    }
    String name = params.get(NAME);
    if (name == null) {
        throw new IllegalArgumentException(CoreAdminParams.NAME + " is required");
    }
    String repoName = params.get(CoreAdminParams.BACKUP_REPOSITORY);
    BackupRepository repository = it.handler.coreContainer.newBackupRepository(Optional.ofNullable(repoName));
    String location = repository.getBackupLocation(params.get(CoreAdminParams.BACKUP_LOCATION));
    if (location == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'location' is not specified as a query" + " parameter or as a default repository property");
    }
    // An optional parameter to describe the snapshot to be backed-up. If this
    // parameter is not supplied, the latest index commit is backed-up.
    String commitName = params.get(CoreAdminParams.COMMIT_NAME);
    URI locationUri = repository.createURI(location);
    try (SolrCore core = it.handler.coreContainer.getCore(cname)) {
        SnapShooter snapShooter = new SnapShooter(repository, core, locationUri, name, commitName);
        //  file system. Otherwise, perhaps the FS location isn't shared -- we want an error.
        if (!snapShooter.getBackupRepository().exists(snapShooter.getLocation())) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Directory to contain snapshots doesn't exist: " + snapShooter.getLocation());
        }
        snapShooter.validateCreateSnapshot();
        snapShooter.createSnapshot();
    } catch (Exception e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed to backup core=" + cname + " because " + e, e);
    }
}
Also used : SnapShooter(org.apache.solr.handler.SnapShooter) BackupRepository(org.apache.solr.core.backup.repository.BackupRepository) ZkController(org.apache.solr.cloud.ZkController) SolrCore(org.apache.solr.core.SolrCore) SolrParams(org.apache.solr.common.params.SolrParams) URI(java.net.URI) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Example 80 with SolrException

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

the class BaseHandlerApiSupport method getApi.

private Api getApi(final V2EndPoint op) {
    final BaseHandlerApiSupport apiHandler = this;
    return new Api(ApiBag.getSpec(op.getSpecName())) {

        @Override
        public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
            SolrParams params = req.getParams();
            SolrRequest.METHOD method = SolrRequest.METHOD.valueOf(req.getHttpMethod());
            List<ApiCommand> commands = commandsMapping.get(method).get(op);
            try {
                if (method == POST) {
                    List<CommandOperation> cmds = req.getCommands(true);
                    if (cmds.size() > 1)
                        throw new SolrException(BAD_REQUEST, "Only one command is allowed");
                    CommandOperation c = cmds.size() == 0 ? null : cmds.get(0);
                    ApiCommand command = null;
                    String commandName = c == null ? null : c.name;
                    for (ApiCommand cmd : commands) {
                        if (Objects.equals(cmd.meta().getName(), commandName)) {
                            command = cmd;
                            break;
                        }
                    }
                    if (command == null) {
                        throw new SolrException(BAD_REQUEST, " no such command " + c);
                    }
                    wrapParams(req, c, command, false);
                    command.invoke(req, rsp, apiHandler);
                } else {
                    if (commands == null || commands.isEmpty()) {
                        rsp.add("error", "No support for : " + method + " at :" + req.getPath());
                        return;
                    }
                    if (commands.size() > 1) {
                        for (ApiCommand command : commands) {
                            if (command.meta().getName().equals(req.getPath())) {
                                commands = Collections.singletonList(command);
                                break;
                            }
                        }
                    }
                    wrapParams(req, new CommandOperation("", Collections.EMPTY_MAP), commands.get(0), true);
                    commands.get(0).invoke(req, rsp, apiHandler);
                }
            } catch (SolrException e) {
                throw e;
            } catch (Exception e) {
                throw new SolrException(BAD_REQUEST, e);
            } finally {
                req.setParams(params);
            }
        }
    };
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CommandOperation(org.apache.solr.common.util.CommandOperation) SolrRequest(org.apache.solr.client.solrj.SolrRequest) SolrException(org.apache.solr.common.SolrException) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrParams(org.apache.solr.common.params.SolrParams) Api(org.apache.solr.api.Api) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrException (org.apache.solr.common.SolrException)617 IOException (java.io.IOException)172 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)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 SolrCore (org.apache.solr.core.SolrCore)33