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);
}
}
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());
}
}
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);
}
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);
}
}
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);
}
}
};
}
Aggregations