org.apache.solr.request.SolrRequestHandler Java Examples

The following examples show how to use org.apache.solr.request.SolrRequestHandler. 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: SimpleTreeFacetComponentTest.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@Test
public void testBadRequest_missingChildField() {
	SolrCore core = h.getCore();
	
	ModifiableSolrParams params = new ModifiableSolrParams();
	params.add("q", "*:*");
	params.add("facet", "true");
	params.add("facet.tree", "true");
	params.add("facet.tree.field", "{!ftree childField=blah}node_id");
	
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.add("responseHeader", new SimpleOrderedMap<>());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

    SolrRequestHandler handler = core.getRequestHandler(requestHandler);
    handler.handleRequest(req, rsp);
    req.close();
      
    assertNotNull(rsp.getException());
}
 
Example #2
Source File: RequestHandlerBase.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Get the request handler registered to a given name.
 * <p>
 * This function is thread safe.
 */
public static SolrRequestHandler getRequestHandler(String handlerName, PluginBag<SolrRequestHandler> reqHandlers) {
  if (handlerName == null) return null;
  SolrRequestHandler handler = reqHandlers.get(handlerName);
  int idx = 0;
  if (handler == null) {
    for (; ; ) {
      idx = handlerName.indexOf('/', idx + 1);
      if (idx > 0) {
        String firstPart = handlerName.substring(0, idx);
        handler = reqHandlers.get(firstPart);
        if (handler == null) continue;
        if (handler instanceof NestedRequestHandler) {
          return ((NestedRequestHandler) handler).getSubHandler(handlerName.substring(idx));
        }
      } else {
        break;
      }
    }
  }
  return handler;
}
 
Example #3
Source File: SolrConfigHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
private boolean verifyClass(CommandOperation op, String clz, @SuppressWarnings({"rawtypes"})Class expected) {
  if (clz == null) return true;
  if (!"true".equals(String.valueOf(op.getStr("runtimeLib", null)))) {
    PluginInfo info = new PluginInfo(SolrRequestHandler.TYPE, op.getDataMap());
    //this is not dynamically loaded so we can verify the class right away
    try {
      if(expected == Expressible.class) {
        @SuppressWarnings("resource")
        SolrResourceLoader resourceLoader = info.pkgName == null ?
            req.getCore().getResourceLoader() :
            req.getCore().getResourceLoader(info.pkgName);
        resourceLoader.findClass(info.className, expected);
      } else {
        req.getCore().createInitInstance(info, expected, clz, "");
      }
    } catch (Exception e) {
      log.error("Error checking plugin : ", e);
      op.addError(e.getMessage());
      return false;
    }

  }
  return true;
}
 
Example #4
Source File: BaseTestRuleBasedAuthorizationPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllPermissionDeniesActionsWhenUserIsNotCorrectRole() {
  SolrRequestHandler handler = new UpdateRequestHandler();
  assertThat(handler, new IsInstanceOf(PermissionNameProvider.class));
  setUserRole("dev", "dev");
  setUserRole("admin", "admin");
  addPermission("all", "admin");
  checkRules(makeMap("resource", "/update",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", new UpdateRequestHandler(),
      "params", new MapSolrParams(singletonMap("key", "VAL2")))
      , FORBIDDEN);

  handler = new PropertiesRequestHandler();
  assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class)));
  checkRules(makeMap("resource", "/admin/info/properties",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", handler,
      "params", new MapSolrParams(emptyMap()))
      , FORBIDDEN);
}
 
Example #5
Source File: SolrCoreTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testClose() throws Exception {
  final CoreContainer cores = h.getCoreContainer();
  SolrCore core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);

  ClosingRequestHandler handler1 = new ClosingRequestHandler();
  handler1.inform( core );

  String path = "/this/is A path /that won't be registered 2!!!!!!!!!!!";
  SolrRequestHandler old = core.registerRequestHandler( path, handler1 );
  assertNull( old ); // should not be anything...
  assertEquals( core.getRequestHandlers().get( path ), handler1 );
  core.close();
  cores.shutdown();
  assertTrue("Handler not closed", handler1.closed == true);
}
 
Example #6
Source File: BaseTestRuleBasedAuthorizationPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllPermissionAllowsActionsWhenAssociatedRoleIsWildcard() {
  SolrRequestHandler handler = new UpdateRequestHandler();
  assertThat(handler, new IsInstanceOf(PermissionNameProvider.class));
  setUserRole("dev", "dev");
  setUserRole("admin", "admin");
  addPermission("all", "*");
  checkRules(makeMap("resource", "/update",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", new UpdateRequestHandler(),
      "params", new MapSolrParams(singletonMap("key", "VAL2")))
      , STATUS_OK);

  handler = new PropertiesRequestHandler();
  assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class)));
  checkRules(makeMap("resource", "/admin/info/properties",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", handler,
      "params", new MapSolrParams(emptyMap()))
      , STATUS_OK);
}
 
Example #7
Source File: BaseTestRuleBasedAuthorizationPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllPermissionAllowsActionsWhenUserHasCorrectRole() {
  SolrRequestHandler handler = new UpdateRequestHandler();
  assertThat(handler, new IsInstanceOf(PermissionNameProvider.class));
  setUserRole("dev", "dev");
  setUserRole("admin", "admin");
  addPermission("all", "dev", "admin");
  checkRules(makeMap("resource", "/update",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", handler,
      "params", new MapSolrParams(singletonMap("key", "VAL2")))
      , STATUS_OK);

  handler = new PropertiesRequestHandler();
  assertThat(handler, new IsNot<>(new IsInstanceOf(PermissionNameProvider.class)));
  checkRules(makeMap("resource", "/admin/info/properties",
      "userPrincipal", "dev",
      "requestType", RequestType.UNKNOWN,
      "collectionRequests", "go",
      "handler", handler,
      "params", new MapSolrParams(emptyMap()))
      , STATUS_OK);
}
 
Example #8
Source File: PluginBag.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the plugins after reading the meta data from {@link org.apache.solr.core.SolrConfig}.
 *
 * @param defaults These will be registered if not explicitly specified
 */
void init(Map<String, T> defaults, SolrCore solrCore, List<PluginInfo> infos) {
  core = solrCore;
  for (PluginInfo info : infos) {
    PluginHolder<T> o = createPlugin(info);
    String name = info.name;
    if (meta.clazz.equals(SolrRequestHandler.class)) name = RequestHandlers.normalize(info.name);
    PluginHolder<T> old = put(name, o);
    if (old != null) {
      log.warn("Multiple entries of {} with name {}", meta.getCleanTag(), name);
    }
  }
  if (infos.size() > 0) { // Aggregate logging
    if (log.isDebugEnabled()) {
      log.debug("[{}] Initialized {} plugins of type {}: {}", solrCore.getName(), infos.size(), meta.getCleanTag(),
          infos.stream().map(i -> i.name).collect(Collectors.toList()));
    }
  }
  for (Map.Entry<String, T> e : defaults.entrySet()) {
    if (!contains(e.getKey())) {
      put(e.getKey(), new PluginHolder<T>(null, e.getValue()));
    }
  }
}
 
Example #9
Source File: PluginBag.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static void initInstance(Object inst, PluginInfo info) {
  if (inst instanceof PluginInfoInitialized) {
    ((PluginInfoInitialized) inst).init(info);
  } else if (inst instanceof NamedListInitializedPlugin) {
    ((NamedListInitializedPlugin) inst).init(info.initArgs);
  } else if (inst instanceof SolrRequestHandler) {
    ((SolrRequestHandler) inst).init(info.initArgs);
  }
  if (inst instanceof SearchComponent) {
    ((SearchComponent) inst).setName(info.name);
  }
  if (inst instanceof RequestHandlerBase) {
    ((RequestHandlerBase) inst).setPluginInfo(info);
  }

}
 
Example #10
Source File: RequestHandlersTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testStatistics() {
  SolrCore core = h.getCore();
  SolrRequestHandler updateHandler = core.getRequestHandler("/update");
  SolrRequestHandler termHandler = core.getRequestHandler("/terms");

  assertU(adoc("id", "47",
      "text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!"));
  assertU(commit());

  Map<String,Object> updateStats = updateHandler.getSolrMetricsContext().getMetricsSnapshot();
  Map<String,Object> termStats = termHandler.getSolrMetricsContext().getMetricsSnapshot();

  Long updateTime = (Long) updateStats.get("UPDATE./update.totalTime");
  Long termTime = (Long) termStats.get("QUERY./terms.totalTime");

  assertFalse("RequestHandlers should not share statistics!", updateTime.equals(termTime));
}
 
Example #11
Source File: Sparql11SearchHandlerTestCase.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
/**
 * Setup fixture for this test case.
 */
@Before
public void setUp() {
	cut = spy(new Sparql11SearchHandler() {
		@Override
		SolrRequestHandler requestHandler(final SolrQueryRequest request, final String name) {
			return mock(SolrRequestHandler.class);
		}
	});
	
	request = mock(SolrQueryRequest.class);
	response = mock(SolrQueryResponse.class);
	httpRequest = mock(HttpServletRequest.class);
	
	final Map<Object, Object> context = new HashMap<Object, Object>();
	context.put(Names.HTTP_REQUEST_KEY, httpRequest);
	when(request.getContext()).thenReturn(context);
}
 
Example #12
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example #13
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example #14
Source File: Cloud.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     * Returns whether or not a doc exists that satisfies the specified query
     * @param requestHandler the handler that handles the request
     * @param request the request object to put the query on
     * @param query the string that specifies the doc
     * @return <code>true</code> if the specified query returns a doc
     */
    boolean exists(SolrRequestHandler requestHandler, SolrQueryRequest request, String query)
    {
        ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
        // Sets 1 because this is effectively a boolean query to see if there exists a single match
        params.set("q", query).set("fl", "id").set("rows", "1");
        ResultContext rc = this.getResultContext(requestHandler, request, params);

        if (rc != null)
        {
// TODO Should we use rc.docs.matches() instead?
            if (rc.getDocList() != null) { return rc.getDocList().iterator().hasNext(); }
        }

        return false;
    }
 
Example #15
Source File: AbstractXJoinTestCase.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
protected NamedList test(ModifiableSolrParams params, String componentName) {
  SolrCore core = h.getCore();

  SearchComponent sc = core.getSearchComponent(componentName);
  assertTrue("XJoinSearchComponent not found in solrconfig", sc != null);
    
  QParserPlugin qp = core.getQueryPlugin("xjoin");
  assertTrue("XJoinQParserPlugin not found in solrconfig", qp != null);
  
  params.add("q", "*:*");
  params.add("fq", "{!xjoin}" + componentName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  rsp.add("responseHeader", new SimpleOrderedMap<>());
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

  SolrRequestHandler handler = core.getRequestHandler("standard");
  handler.handleRequest(req, rsp);
  req.close();
  assertNull(rsp.getException());
    
  return rsp.getValues();
}
 
Example #16
Source File: SimpleTreeFacetComponentTest.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@Test
public void testBadRequest_missingLocalParams() {
	SolrCore core = h.getCore();
	
	ModifiableSolrParams params = new ModifiableSolrParams();
	params.add("q", "*:*");
	params.add("facet", "true");
	params.add("facet.tree", "true");
	params.add("facet.tree.field", "node_id");
	
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.add("responseHeader", new SimpleOrderedMap<>());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);

    SolrRequestHandler handler = core.getRequestHandler(requestHandler);
    handler.handleRequest(req, rsp);
    req.close();
      
    assertNotNull(rsp.getException());
}
 
Example #17
Source File: CentroidComponentTest.java    From query-segmenter with Apache License 2.0 5 votes vote down vote up
private SolrQueryRequest request(ModifiableSolrParams params) {
  SolrCore core = h.getCore();
  SolrRequestHandler handler = core.getRequestHandler(CENTROID_REQUEST_HANDLER);

  SolrQueryResponse rsp = new SolrQueryResponse();
  NamedList<Object> list = new NamedList<Object>();
  list.add("responseHeader", new SimpleOrderedMap<Object>());
  rsp.setAllValues(list);
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
  handler.handleRequest(req, rsp);
  return req;
}
 
Example #18
Source File: PluginBag.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Pass needThreadSafety=true if plugins can be added and removed concurrently with lookups.
 */
public PluginBag(Class<T> klass, SolrCore core, boolean needThreadSafety) {
  this.apiBag = klass == SolrRequestHandler.class ? new ApiBag(core != null) : null;
  this.core = core;
  this.klass = klass;
  // TODO: since reads will dominate writes, we could also think about creating a new instance of a map each time it changes.
  // Not sure how much benefit this would have over ConcurrentHashMap though
  // We could also perhaps make this constructor into a factory method to return different implementations depending on thread safety needs.
  this.registry = needThreadSafety ? new ConcurrentHashMap<>() : new HashMap<>();
  this.immutableRegistry = Collections.unmodifiableMap(registry);
  meta = SolrConfig.classVsSolrPluginInfo.get(klass.getName());
  if (meta == null) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown Plugin : " + klass.getName());
  }
}
 
Example #19
Source File: QuerySegmenterQParserTest.java    From query-segmenter with Apache License 2.0 5 votes vote down vote up
private SolrQueryRequest request(ModifiableSolrParams params, String handlerName) {
  SolrCore core = h.getCore();
  SolrRequestHandler handler = core.getRequestHandler(handlerName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  NamedList<Object> list = new NamedList<Object>();
  list.add("responseHeader", new SimpleOrderedMap<Object>());
  rsp.setAllValues(list);
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
  handler.handleRequest(req, rsp);
  return req;
}
 
Example #20
Source File: TestInitParams.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testElevateExample(){
  SolrRequestHandler handler = h.getCore().getRequestHandler("/elevate");
  SolrQueryResponse rsp = new SolrQueryResponse();
  handler.handleRequest(req("initArgs", "true"), rsp);
  @SuppressWarnings({"rawtypes"})
  NamedList nl = (NamedList) rsp.getValues().get("initArgs");
  @SuppressWarnings({"rawtypes"})
  NamedList def = (NamedList) nl.get(PluginInfo.DEFAULTS);
  assertEquals("text" ,def.get("df"));

}
 
Example #21
Source File: RequestHandlersTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testPathNormalization()
{
  SolrCore core = h.getCore();
  SolrRequestHandler h1 = core.getRequestHandler("/update" );
  assertNotNull( h1 );

  SolrRequestHandler h2 = core.getRequestHandler("/update/" );
  assertNotNull( h2 );
  
  assertEquals( h1, h2 ); // the same object
  
  assertNull( core.getRequestHandler("/update/asdgadsgas" ) ); // prefix
}
 
Example #22
Source File: RequestHandlersTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testLazyLoading() {
  SolrCore core = h.getCore();
  PluginBag.PluginHolder<SolrRequestHandler> handler = core.getRequestHandlers().getRegistry().get("/lazy");
  assertFalse(handler.isLoaded());
  
  assertU(adoc("id", "42",
               "name", "Zapp Brannigan"));
  assertU(adoc("id", "43",
               "title", "Democratic Order of Planets"));
  assertU(adoc("id", "44",
               "name", "The Zapper"));
  assertU(adoc("id", "45",
               "title", "25 star General"));
  assertU(adoc("id", "46",
               "subject", "Defeated the pacifists of the Gandhi nebula"));
  assertU(adoc("id", "47",
               "text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!"));
  assertU(commit());

  assertQ("lazy request handler returns all matches",
          req("q","id:[42 TO 47]"),
          "*[count(//doc)=6]");

      // But it should behave just like the 'defaults' request handler above
  assertQ("lazy handler returns fewer matches",
          req("q", "id:[42 TO 47]", "qt","/lazy"),
          "*[count(//doc)=4]"
          );

  assertQ("lazy handler includes highlighting",
          req("q", "name:Zapp OR title:General", "qt","/lazy"),
          "//lst[@name='highlighting']"
          );
}
 
Example #23
Source File: TestInitParams.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testArbitraryAttributes() {
  SolrRequestHandler handler = h.getCore().getRequestHandler("/dump7");
  SolrQueryResponse rsp = new SolrQueryResponse();
  handler.handleRequest(req("initArgs", "true"), rsp);
  @SuppressWarnings({"rawtypes"})
  NamedList nl = (NamedList) rsp.getValues().get("initArgs");
  assertEquals("server-enabled.txt", nl.get("healthcheckFile"));
}
 
Example #24
Source File: QuerySegmenterComponentTest.java    From query-segmenter with Apache License 2.0 5 votes vote down vote up
private SolrQueryRequest request(ModifiableSolrParams params, String handlerName) {
  SolrCore core = h.getCore();
  SolrRequestHandler handler = core.getRequestHandler(handlerName);

  SolrQueryResponse rsp = new SolrQueryResponse();
  NamedList<Object> list = new NamedList<Object>();
  list.add("responseHeader", new SimpleOrderedMap<Object>());
  rsp.setAllValues(list);
  SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
  handler.handleRequest(req, rsp);
  return req;
}
 
Example #25
Source File: SpellCheckCollatorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void testCollationWithRangeQuery() throws Exception
{
  SolrCore core = h.getCore();
  SearchComponent speller = core.getSearchComponent("spellcheck");
  assertTrue("speller is null and it shouldn't be", speller != null);
  
  ModifiableSolrParams params = new ModifiableSolrParams();   
  params.add(SpellCheckComponent.COMPONENT_NAME, "true");
  params.add(SpellingParams.SPELLCHECK_BUILD, "true");
  params.add(SpellingParams.SPELLCHECK_COUNT, "10");   
  params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); 
  params.add(SpellingParams.SPELLCHECK_ALTERNATIVE_TERM_COUNT, "10"); 
  params.add(CommonParams.Q, "id:[1 TO 10] AND lowerfilt:lovw");
  {
    SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    req.close();
    NamedList values = rsp.getValues();
    NamedList spellCheck = (NamedList) values.get("spellcheck");
    NamedList collationHolder = (NamedList) spellCheck.get("collations");
    List<String> collations = collationHolder.getAll("collation");
    assertTrue(collations.size()==1); 
    String collation = collations.iterator().next();    
    System.out.println(collation);
    assertTrue("Incorrect collation: " + collation,"id:[1 TO 10] AND lowerfilt:love".equals(collation));
  }
}
 
Example #26
Source File: CoreContainer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
protected <T> T createHandler(String path, String handlerClass, Class<T> clazz) {
  T handler = loader.newInstance(handlerClass, clazz, null, new Class[]{CoreContainer.class}, new Object[]{this});
  if (handler instanceof SolrRequestHandler) {
    containerHandlers.put(path, (SolrRequestHandler) handler);
  }
  if (handler instanceof SolrMetricProducer) {
    ((SolrMetricProducer) handler).initializeMetrics(solrMetricsContext, path);
  }
  return handler;
}
 
Example #27
Source File: TestApiFramework.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, String path,
                                 String fullPath, SolrRequest.METHOD method,
                                 CoreContainer mockCC) {
  HashMap<String, String> parts = new HashMap<>();
  boolean containerHandlerLookup = mockCC.getRequestHandlers() == reqHandlers;
  path = path == null ? fullPath : path;
  Api api = null;
  if (containerHandlerLookup) {
    api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
  } else {
    api = V2HttpCall.getApiInfo(mockCC.getRequestHandlers(), fullPath, "GET", fullPath, parts);
    if (api == null) api = new CompositeApi(null);
    if (api instanceof CompositeApi) {
      CompositeApi compositeApi = (CompositeApi) api;
      api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
      compositeApi.add(api);
      api = compositeApi;
    }
  }

  SolrQueryResponse rsp = new SolrQueryResponse();
  LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>())) {
    @Override
    public List<CommandOperation> getCommands(boolean validateInput) {
      return Collections.emptyList();
    }
  };

  api.call(req, rsp);
  return rsp;

}
 
Example #28
Source File: PluginBag.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void registerMBean(Object inst, SolrCore core, String pluginKey) {
  if (core == null) return;
  if (inst instanceof SolrInfoBean) {
    SolrInfoBean mBean = (SolrInfoBean) inst;
    String name = (inst instanceof SolrRequestHandler) ? pluginKey : mBean.getName();
    core.registerInfoBean(name, mBean);
  }
}
 
Example #29
Source File: RequestHandlers.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
   * Handlers must be initialized before calling this function.  As soon as this is
   * called, the handler can immediately accept requests.
   * 
   * This call is thread safe.
   * 
   * @return the previous handler at the given path or null
   */
  public SolrRequestHandler register( String handlerName, SolrRequestHandler handler ) {
    String norm = normalize(handlerName);
    if (handler == null) {
      return handlers.remove(norm);
    }
    return handlers.put(norm, handler);
//    return register(handlerName, new PluginRegistry.PluginHolder<>(null, handler));
  }
 
Example #30
Source File: SolrCoreLoadListener.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the configuration declares this node as a slave.
 *
 * @param core the hosting {@link SolrCore} instance.
 * @return true if the content store must be set in read only mode, false otherwise.
 */
@SuppressWarnings("rawtypes")
boolean isSlaveModeEnabledFor(SolrCore core)
{
    Predicate<PluginInfo> onlyReplicationHandler =
            plugin -> "/replication".equals(plugin.name)
                    || plugin.className.endsWith(ReplicationHandler.class.getSimpleName());

    Function<NamedList, Boolean> isSlaveModeEnabled =
            params ->  ofNullable(params)
                    .map(configuration -> {
                        Object enable = configuration.get("enable");
                        return enable == null ||
                                (enable instanceof String ? StrUtils.parseBool((String)enable) : Boolean.TRUE.equals(enable));})
                    .orElse(false);

    return core.getSolrConfig().getPluginInfos(SolrRequestHandler.class.getName())
            .stream()
            .filter(PluginInfo::isEnabled)
            .filter(onlyReplicationHandler)
            .findFirst()
            .map(plugin -> plugin.initArgs)
            .map(params -> params.get("slave"))
            .map(NamedList.class::cast)
            .map(isSlaveModeEnabled)
            .orElse(false);
}