private void handleGET() { if (parts.size() == 1) { resp.add("solrConfig", req.getCore().getSolrConfig().toMap()); } else { if (ConfigOverlay.NAME.equals(parts.get(1))) { resp.add(ConfigOverlay.NAME, req.getCore().getSolrConfig().getOverlay().toMap()); } else if (RequestParams.NAME.equals(parts.get(1))) { if (parts.size() == 3) { RequestParams params = req.getCore().getSolrConfig().getRequestParams(); MapSolrParams p = params.getParams(parts.get(2)); Map m = new LinkedHashMap<>(); m.put(ConfigOverlay.ZNODEVER, params.getZnodeVersion()); if (p != null) { m.put(RequestParams.NAME, ZkNodeProps.makeMap(parts.get(2), p.getMap())); } resp.add(SolrQueryResponse.NAME, m); } else { resp.add( SolrQueryResponse.NAME, req.getCore().getSolrConfig().getRequestParams().toMap()); } } else { Map<String, Object> m = req.getCore().getSolrConfig().toMap(); resp.add("solrConfig", ZkNodeProps.makeMap(parts.get(1), m.get(parts.get(1)))); } } }
private void handleParams(ArrayList<CommandOperation> ops, RequestParams params) { for (CommandOperation op : ops) { switch (op.name) { case CREATE: case UPDATE: { Map<String, Object> map = op.getDataMap(); if (op.hasError()) break; for (Map.Entry<String, Object> entry : map.entrySet()) { Map val = null; String key = entry.getKey(); if (key == null || key.trim().isEmpty()) { op.addError("null key "); continue; } key = key.trim(); if (!validName(key)) { op.addError( MessageFormat.format( "''{0}'' name should only have chars [a-zA-Z_-.0-9] ", key)); continue; } try { val = (Map) entry.getValue(); } catch (Exception e1) { op.addError("invalid params for key : " + key); continue; } if (val.containsKey("")) { op.addError("Empty keys are not allowed in params"); continue; } MapSolrParams old = params.getParams(key); if (op.name.equals(UPDATE)) { LinkedHashMap m = new LinkedHashMap(old.getMap()); m.putAll(val); val = m; } params = params.setParams(key, val); } break; } case "delete": { List<String> name = op.getStrs(CommandOperation.ROOT_OBJ); if (op.hasError()) break; for (String s : name) { if (params.getParams(s) == null) { op.addError( MessageFormat.format("can't delete . No such params ''{0}'' exist", s)); } params = params.setParams(s, null); } } } } List errs = CommandOperation.captureErrors(ops); if (!errs.isEmpty()) { resp.add(CommandOperation.ERR_MSGS, errs); return; } SolrResourceLoader loader = req.getCore().getResourceLoader(); if (loader instanceof ZkSolrResourceLoader) { ZkController.persistConfigResourceToZooKeeper( loader, params.getZnodeVersion(), RequestParams.RESOURCE, params.toByteArray(), true); } else { SolrResourceLoader.persistConfLocally( loader, ConfigOverlay.RESOURCE_NAME, params.toByteArray()); req.getCore().getSolrConfig().refreshRequestParams(); } }