org.apache.solr.core.CoreContainer Java Examples

The following examples show how to use org.apache.solr.core.CoreContainer. 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: AlfrescoCoreAdminHandlerTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void maxTransactionScheduledParameterAndConfigurationIsNull_shouldGetTheHardCodedDefault()
{
    params.set(CORE, ALFRESCO_CORE_NAME);

    Properties coreProperties = new Properties();

    CoreContainer coreContainer = mock(CoreContainer.class);
    SolrCore core = mock(SolrCore.class);
    SolrResourceLoader resourceLoader = mock(SolrResourceLoader.class);
    when(coreContainer.getCore(ALFRESCO_CORE_NAME)).thenReturn(core);
    when(core.getResourceLoader()).thenReturn(resourceLoader);
    when(resourceLoader.getCoreProperties()).thenReturn(coreProperties);

    admin = new AlfrescoCoreAdminHandler(coreContainer);

    assertEquals(Integer.MAX_VALUE, admin.getMaxTransactionToSchedule(params));
}
 
Example #2
Source File: OverseerCollectionConfigSetProcessorTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpOnce() throws Exception {
  assumeWorkingMockito();
  
  workQueueMock = mock(OverseerTaskQueue.class);
  stateUpdateQueueMock = mock(OverseerTaskQueue.class);
  runningMapMock = mock(DistributedMap.class);
  completedMapMock = mock(DistributedMap.class);
  failureMapMock = mock(DistributedMap.class);
  shardHandlerFactoryMock = mock(HttpShardHandlerFactory.class);
  shardHandlerMock = mock(HttpShardHandler.class);
  zkStateReaderMock = mock(ZkStateReader.class);
  clusterStateMock = mock(ClusterState.class);
  solrZkClientMock = mock(SolrZkClient.class);
  overseerMock = mock(Overseer.class);
  zkControllerMock = mock(ZkController.class);
  cloudDataProviderMock = mock(SolrCloudManager.class);
  objectCache = new ObjectCache();
  clusterStateProviderMock = mock(ClusterStateProvider.class);
  stateManagerMock = mock(DistribStateManager.class);
  cloudManagerMock = mock(SolrCloudManager.class);
  distribStateManagerMock = mock(DistribStateManager.class);
  coreContainerMock = mock(CoreContainer.class);
  updateShardHandlerMock = mock(UpdateShardHandler.class);
  httpClientMock = mock(HttpClient.class);
}
 
Example #3
Source File: ScheduledTriggerTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
@AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018
// this does not appear to be a good way to test this
public void testTrigger() throws Exception {
  CoreContainer container = cluster.getJettySolrRunners().get(0).getCoreContainer();

  Map<String, Object> properties = createTriggerProperties(new Date().toInstant().toString(), TimeZone.getDefault().getID());

  scheduledTriggerTest(container, properties);

  TimeZone timeZone = TimeZone.getDefault();
  DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder()
      .append(DateTimeFormatter.ISO_LOCAL_DATE).appendPattern("['T'[HH[:mm[:ss]]]]") //brackets mean optional
      .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
      .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
      .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
      .toFormatter(Locale.ROOT).withZone(timeZone.toZoneId());
  properties = createTriggerProperties(dateTimeFormatter.format(Instant.now()), timeZone.getID());
  scheduledTriggerTest(container, properties);
}
 
Example #4
Source File: MDCLoggingContext.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Sets multiple information from the params.
 * REMEMBER TO CALL {@link #clear()} in a finally!
 */
public static void setCoreDescriptor(CoreContainer coreContainer, CoreDescriptor cd) {
  setNode(coreContainer);

  int callDepth = CALL_DEPTH.get();
  CALL_DEPTH.set(callDepth + 1);
  if (callDepth > 0) {
    return;
  }

  if (cd != null) {

    assert cd.getName() != null;
    setCoreName(cd.getName());
    
    CloudDescriptor ccd = cd.getCloudDescriptor();
    if (ccd != null) {
      setCollection(ccd.getCollectionName());
      setShard(ccd.getShardId());
      setReplica(ccd.getCoreNodeName());
    }
  }
}
 
Example #5
Source File: DistributedZkUpdateProcessor.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public DistributedZkUpdateProcessor(SolrQueryRequest req,
                                    SolrQueryResponse rsp, UpdateRequestProcessor next) {
  super(req, rsp, next);
  CoreContainer cc = req.getCore().getCoreContainer();
  cloudDesc = req.getCore().getCoreDescriptor().getCloudDescriptor();
  zkController = cc.getZkController();
  cmdDistrib = new SolrCmdDistributor(cc.getUpdateShardHandler());
  cloneRequiredOnLeader = isCloneRequiredOnLeader(next);
  collection = cloudDesc.getCollectionName();
  clusterState = zkController.getClusterState();
  DocCollection coll = clusterState.getCollectionOrNull(collection);
  if (coll != null) {
    // check readOnly property in coll state
    readOnlyCollection = coll.isReadOnly();
  }
}
 
Example #6
Source File: TestCollectionAPIs.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
void invokeAction(SolrQueryRequest req, SolrQueryResponse rsp,
                  CoreContainer cores,
                  CollectionParams.CollectionAction action,
                  CollectionOperation operation) throws Exception {
  Map<String, Object> result = null;
  if (action == CollectionParams.CollectionAction.COLLECTIONPROP) {
    //Fake this action, since we don't want to write to ZooKeeper in this test
    result = new HashMap<>();
    result.put(NAME, req.getParams().required().get(NAME));
    result.put(PROPERTY_NAME, req.getParams().required().get(PROPERTY_NAME));
    result.put(PROPERTY_VALUE, req.getParams().required().get(PROPERTY_VALUE));
  } else {
    result = operation.execute(req, rsp, this);
  }
  if (result != null) {
    result.put(QUEUE_OPERATION, operation.action.toLower());
    rsp.add(ZkNodeProps.class.getName(), new ZkNodeProps(result));
  }
}
 
Example #7
Source File: DeleteSnapshotOp.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
  final SolrParams params = it.req.getParams();
  String commitName = params.required().get(CoreAdminParams.COMMIT_NAME);
  String cname = params.required().get(CoreAdminParams.CORE);

  CoreContainer cc = it.handler.getCoreContainer();
  SolrCore core = cc.getCore(cname);
  if (core == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
  }

  try {
    core.deleteNamedSnapshot(commitName);
    // Ideally we shouldn't need this. This is added since the RPC logic in
    // OverseerCollectionMessageHandler can not provide the coreName as part of the result.
    it.rsp.add(CoreAdminParams.CORE, core.getName());
    it.rsp.add(CoreAdminParams.COMMIT_NAME, commitName);
  } finally {
    core.close();
  }
}
 
Example #8
Source File: EmbeddedSolrService.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
@Override
public void activateSolr() throws Exception
{
   ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
   Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );

   try
   {
      File directory = new File( fileConfig.dataDirectory(), descriptor.identity().toString() );
      directory.mkdirs();

      System.setProperty( "solr.solr.home", directory.getAbsolutePath() );

      CoreContainer.Initializer initializer = new CoreContainer.Initializer();
      coreContainer = initializer.initialize();
      server = new EmbeddedSolrServer( coreContainer, "" );
      core = coreContainer.getCore( "" );
   } finally
   {
      Thread.currentThread().setContextClassLoader( oldCl );
   }
}
 
Example #9
Source File: ScheduledTriggerTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testIgnoredEvent() throws Exception {
  CoreContainer container = cluster.getJettySolrRunners().get(0).getCoreContainer();
  long threeDaysAgo = new Date().getTime() - TimeUnit.DAYS.toMillis(3);
  Map<String, Object> properties = createTriggerProperties(new Date(threeDaysAgo).toInstant().toString(),
      TimeZone.getDefault().getID(),
      "+2DAYS", "+1HOUR");
  try (ScheduledTrigger scheduledTrigger = new ScheduledTrigger("sched1")) {
    scheduledTrigger.configure(container.getResourceLoader(), container.getZkController().getSolrCloudManager(), properties);
    scheduledTrigger.init();
    AtomicReference<TriggerEvent> eventRef = new AtomicReference<>();
    scheduledTrigger.setProcessor(event -> {
      eventRef.set(event);
      return true;
    });
    scheduledTrigger.run();
    assertTrue(eventRef.get().isIgnored());
  }
}
 
Example #10
Source File: SolrDispatchFilter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void setupJvmMetrics(CoreContainer coresInit)  {
  metricManager = coresInit.getMetricManager();
  registryName = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
  final Set<String> hiddenSysProps = coresInit.getConfig().getMetricsConfig().getHiddenSysProps();
  try {
    metricManager.registerAll(registryName, new AltBufferPoolMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "buffers");
    metricManager.registerAll(registryName, new ClassLoadingGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "classes");
    metricManager.registerAll(registryName, new OperatingSystemMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "os");
    metricManager.registerAll(registryName, new GarbageCollectorMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "gc");
    metricManager.registerAll(registryName, new MemoryUsageGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "memory");
    metricManager.registerAll(registryName, new ThreadStatesGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "threads"); // todo should we use CachedThreadStatesGaugeSet instead?
    MetricsMap sysprops = new MetricsMap((detailed, map) -> {
      System.getProperties().forEach((k, v) -> {
        if (!hiddenSysProps.contains(k)) {
          map.put(String.valueOf(k), v);
        }
      });
    });
    metricManager.registerGauge(null, registryName, sysprops, metricTag, true, "properties", "system");
  } catch (Exception e) {
    log.warn("Error registering JVM metrics", e);
  }
}
 
Example #11
Source File: StreamHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public void inform(SolrCore core) {
  String defaultCollection;
  String defaultZkhost;
  CoreContainer coreContainer = core.getCoreContainer();
  this.solrClientCache = coreContainer.getSolrClientCache();
  this.coreName = core.getName();
  String cacheKey = this.getClass().getName() + "_" + coreName + "_";
  this.objectCache = coreContainer.getObjectCache().computeIfAbsent(cacheKey + "objectCache",
      ConcurrentHashMap.class, k-> new ConcurrentHashMap());
  if (coreContainer.isZooKeeperAware()) {
    defaultCollection = core.getCoreDescriptor().getCollectionName();
    defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
    streamFactory.withCollectionZkHost(defaultCollection, defaultZkhost);
    streamFactory.withDefaultZkHost(defaultZkhost);
    modelCache = coreContainer.getObjectCache().computeIfAbsent(cacheKey + "modelCache",
        ModelCache.class,
        k -> new ModelCache(250, defaultZkhost, solrClientCache));
  }
  streamFactory.withSolrResourceLoader(core.getResourceLoader());

  // This pulls all the overrides and additions from the config
  addExpressiblePlugins(streamFactory, core);
}
 
Example #12
Source File: EmbeddedSolrServerFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param solrHome
 *              path to directory where solr.xml lives
 * @param coreName
 *              the name of the core to load
 * @param dataDir
 *              the data dir for the core
 *
 * @return an EmbeddedSolrServer for the given core
 */
public static SolrClient create(String solrHome, String coreName, String dataDir)
        throws IOException {

    Map<String,String> props = new HashMap<>();
    if (dataDir != null) {
        File coreDataDir = new File(dataDir + "/" + coreName);
        if (coreDataDir.exists()) {
            FileUtils.deleteDirectory(coreDataDir);
        }
        props.put("dataDir", dataDir + "/" + coreName);
    }

    final CoreContainer coreContainer = new CoreContainer(solrHome);
    coreContainer.load();

    return new EmbeddedSolrServer(coreContainer, coreName);
}
 
Example #13
Source File: SolrMetricManager.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void loadClusterReporters(PluginInfo[] pluginInfos, CoreContainer cc) {
  // don't load for non-cloud instances
  if (!cc.isZooKeeperAware()) {
    return;
  }
  Map<String, String> attrs = new HashMap<>();
  attrs.put("name", "clusterDefault");
  attrs.put("group", SolrInfoBean.Group.cluster.toString());
  Map<String, Object> initArgs = new HashMap<>();
  initArgs.put("period", DEFAULT_CLOUD_REPORTER_PERIOD);
  List<PluginInfo> infos = prepareCloudPlugins(pluginInfos, SolrInfoBean.Group.cluster.toString(),
      attrs, initArgs);
  String registryName = getRegistryName(SolrInfoBean.Group.cluster);
  for (PluginInfo info : infos) {
    try {
      loadReporter(registryName, cc, info);
    } catch (Exception e) {
      log.warn("Could not load cluster reporter, pluginInfo={}", info, e);
    }
  }
}
 
Example #14
Source File: OverseerTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private ZkController createMockZkController(String zkAddress, SolrZkClient zkClient, ZkStateReader reader) throws InterruptedException, NoSuchFieldException, SecurityException, SessionExpiredException {
  ZkController zkController = mock(ZkController.class);

  if (zkClient == null) {
    SolrZkClient newZkClient = new SolrZkClient(server.getZkAddress(), AbstractZkTestCase.TIMEOUT);
    Mockito.doAnswer(
        new Answer<Void>() {
          public Void answer(InvocationOnMock invocation) {
            newZkClient.close();
            return null;
          }}).when(zkController).close();
    zkClient = newZkClient;
  } else {
    doNothing().when(zkController).close();
  }

  CoreContainer mockAlwaysUpCoreContainer = mock(CoreContainer.class,
      Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
  when(mockAlwaysUpCoreContainer.isShutDown()).thenReturn(testDone);  // Allow retry on session expiry
  when(mockAlwaysUpCoreContainer.getResourceLoader()).thenReturn(new SolrResourceLoader());
  FieldSetter.setField(zkController, ZkController.class.getDeclaredField("zkClient"), zkClient);
  FieldSetter.setField(zkController, ZkController.class.getDeclaredField("cc"), mockAlwaysUpCoreContainer);
  when(zkController.getCoreContainer()).thenReturn(mockAlwaysUpCoreContainer);
  when(zkController.getZkClient()).thenReturn(zkClient);
  when(zkController.getZkStateReader()).thenReturn(reader);

  when(zkController.getLeaderProps(anyString(), anyString(), anyInt())).thenCallRealMethod();
  when(zkController.getLeaderProps(anyString(), anyString(), anyInt(), anyBoolean())).thenCallRealMethod();
  doReturn(getCloudDataProvider(zkAddress, zkClient, reader))
      .when(zkController).getSolrCloudManager();
  return zkController;
}
 
Example #15
Source File: SecureCoreAdminHandlerTest.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private CoreContainer getZkAwareCoreContainer(final CoreContainer cc) {
  Enhancer e = new Enhancer();
  e.setClassLoader(cc.getClass().getClassLoader());
  e.setSuperclass(CoreContainer.class);
  e.setCallback(new MethodInterceptor() {
    public Object intercept(Object obj, Method method, Object [] args, MethodProxy proxy) throws Throwable {
      if (method.getName().equals("isZooKeeperAware")) {
        return Boolean.TRUE;
      }
      return method.invoke(cc, args);
    }
  });
  return (CoreContainer)e.create();
}
 
Example #16
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static boolean hasInitException(String message) {
  for (Map.Entry<String, CoreContainer.CoreLoadFailure> entry : h.getCoreContainer().getCoreInitFailures().entrySet()) {
    if (entry.getValue().exception.getMessage().contains(message))
      return true;
  }
  return false;
}
 
Example #17
Source File: JettySolrRunner.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void waitForLoadingCoresToFinish(long timeoutMs) {
  if (dispatchFilter != null) {
    SolrDispatchFilter solrFilter = (SolrDispatchFilter) dispatchFilter.getFilter();
    CoreContainer cores = solrFilter.getCores();
    if (cores != null) {
      cores.waitForLoadingCoresToFinish(timeoutMs);
    } else {
      throw new IllegalStateException("The CoreContainer is not set!");
    }
  } else {
    throw new IllegalStateException("The dispatchFilter is not set!");
  }
}
 
Example #18
Source File: BaseEmbeddedSolrTest.java    From jate with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setup() throws Exception {
        setSolrCoreName();
        setReindex();
//        if(reindex)
//            cleanIndexDirectory(solrHome.toString(), solrCoreName);
        CoreContainer testBedContainer = new CoreContainer(solrHome.toString());
        testBedContainer.load();
        server = new EmbeddedSolrServer(testBedContainer, solrCoreName);
    }
 
Example #19
Source File: ChangedSchemaMergeTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptimizeDiffSchemas() throws Exception {
  // load up a core (why not put it on disk?)
  CoreContainer cc = init();
  try (SolrCore changed = cc.getCore("changed")) {

    assertSimilarity(changed, simfac1);
                     
    // add some documents
    addDoc(changed, "id", "1", "which", "15", "text", "some stuff with which");
    addDoc(changed, "id", "2", "which", "15", "text", "some stuff with which");
    addDoc(changed, "id", "3", "which", "15", "text", "some stuff with which");
    addDoc(changed, "id", "4", "which", "15", "text", "some stuff with which");
    SolrQueryRequest req = new LocalSolrQueryRequest(changed, new NamedList<>());
    changed.getUpdateHandler().commit(new CommitUpdateCommand(req, false));

    // write the new schema out and make it current
    FileUtils.writeStringToFile(schemaFile, withoutWhich, StandardCharsets.UTF_8);

    IndexSchema iSchema = IndexSchemaFactory.buildIndexSchema("schema.xml", changed.getSolrConfig());
    changed.setLatestSchema(iSchema);
    
    assertSimilarity(changed, simfac2);
    // sanity check our sanity check
    assertFalse("test is broken: both simfacs are the same", simfac1.equals(simfac2)); 

    addDoc(changed, "id", "1", "text", "some stuff without which");
    addDoc(changed, "id", "5", "text", "some stuff without which");

    changed.getUpdateHandler().commit(new CommitUpdateCommand(req, false));
    changed.getUpdateHandler().commit(new CommitUpdateCommand(req, true));
  } catch (Throwable e) {
    log.error("Test exception, logging so not swallowed if there is a (finally) shutdown exception: {}"
        , e.getMessage(), e);
    throw e;
  } finally {
    if (cc != null) cc.shutdown();
  }
}
 
Example #20
Source File: ChaosMonkey.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void expireSession(final JettySolrRunner jetty) {
  CoreContainer cores = jetty.getCoreContainer();
  if (cores != null) {
    monkeyLog("expire session for " + jetty.getLocalPort() + " !");
    causeConnectionLoss(jetty);
    long sessionId = cores.getZkController().getZkClient()
        .getSolrZooKeeper().getSessionId();
    zkServer.expire(sessionId);
  }

}
 
Example #21
Source File: TestCoreAdminApis.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public static CoreContainer getCoreContainerMock(final Map<String, Object[]> in,Map<String,Object> out ) {
  assumeWorkingMockito();
  
  CoreContainer mockCC = mock(CoreContainer.class);
  when(mockCC.create(any(String.class), any(Path.class) , any(Map.class), anyBoolean())).thenAnswer(invocationOnMock -> {
    in.put("create", invocationOnMock.getArguments());
    return null;
  });

  doAnswer(invocationOnMock -> {
    in.put("swap", invocationOnMock.getArguments());
    return null;
  }).when(mockCC).swap(any(String.class), any(String.class));

  doAnswer(invocationOnMock -> {
    in.put("rename", invocationOnMock.getArguments());
    return null;
  }).when(mockCC).rename(any(String.class), any(String.class));


  doAnswer(invocationOnMock -> {
    in.put("unload", invocationOnMock.getArguments());
    return null;
  }).when(mockCC).unload(any(String.class), anyBoolean(),
      anyBoolean(), anyBoolean());

  when(mockCC.getCoreRootDirectory()).thenReturn(Paths.get("coreroot"));
  when(mockCC.getContainerProperties()).thenReturn(new Properties());

  when(mockCC.getRequestHandlers()).thenAnswer(invocationOnMock -> out.get("getRequestHandlers"));
  return mockCC;
}
 
Example #22
Source File: MtasSolrTestSearchConsistency.java    From mtas with Apache License 2.0 5 votes vote down vote up
/**
 * Setup.
 */
@org.junit.BeforeClass
public static void setup() {
  try {
    Path dataPath = Paths.get("src" + File.separator + "test"
        + File.separator + "resources" + File.separator + "data");
    // data
    Map<Integer, SolrInputDocument> solrDocuments = MtasSolrBase
        .createDocuments(true);

    // create
    ArrayList<String> collections = new ArrayList<>(
        Arrays.asList("collection1", "collection2", "collection3"));
    initializeDirectory(dataPath, collections);
    CoreContainer container = new CoreContainer(
        solrPath.toAbsolutePath().toString());
    container.load();
    server = new EmbeddedSolrServer(container, collections.get(0));

    // add
    server.add("collection1", solrDocuments.get(1));
    server.commit("collection1");
    server.add("collection1", solrDocuments.get(2));
    server.add("collection1", solrDocuments.get(3));
    server.commit("collection1");

    server.add("collection2", solrDocuments.get(1));
    server.commit("collection2");

    server.add("collection3", solrDocuments.get(3));
    server.add("collection3", solrDocuments.get(2));
    server.commit("collection3");

  } catch (IOException | SolrServerException e) {
    log.error(e);
  }
}
 
Example #23
Source File: SolrEmbedded.java    From FXDesktopSearch with Apache License 2.0 5 votes vote down vote up
public SolrEmbedded(final Config config) throws IOException {
    // Copy all required files
    final var solrHome = config.solrHome;
    solrHome.mkdirs();

    copyResourceToFile("/solrhome/solr.xml", new File(solrHome, "solr.xml"));

    final var core1 = new File(solrHome, "core1");
    final var core1conf = new File(core1, "conf");
    final var core1data = new File(core1, "data");
    final var core1lang = new File(core1, "lang");

    core1conf.mkdirs();
    core1data.mkdirs();
    core1lang.mkdirs();

    // Core1
    copyResourceToFile("/solrhome/core1/core.properties", new File(core1, "core.properties"));
    copyResourceToFile("/solrhome/core1/currency.xml", new File(core1, "currency.xml"));
    copyResourceToFile("/solrhome/core1/protwords.txt", new File(core1, "protwords.txt"));
    copyResourceToFile("/solrhome/core1/solrconfig.xml", new File(core1, "solrconfig.xml"));
    copyResourceToFile("/solrhome/core1/stopwords.txt", new File(core1, "stopwords.txt"));
    copyResourceToFile("/solrhome/core1/synonyms.txt", new File(core1, "synonyms.txt"));
    copyResourceToFile("/solrhome/core1/update-script.js", new File(core1, "update-script.js"));

    // Core1 Config
    copyResourceToFile("/solrhome/core1/conf/elevate.xml", new File(core1conf, "elevate.xml"));
    copyResourceToFile("/solrhome/core1/conf/managed-schema", new File(core1conf, "managed-schema"));

    // Core1 Language
    copyResourceToFile("/solrhome/core1/lang/stopwords_en.txt", new File(core1lang, "stopwords_en.txt"));

    // Bootstrap
    coreContainer = new CoreContainer(solrHome.toString());
    coreContainer.load();

    embeddedSolrServer = new EmbeddedSolrServer(coreContainer, "core1");
}
 
Example #24
Source File: MDCLoggingContext.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static void setNode(CoreContainer cc) {
  if (cc != null) {
    ZkController zk = cc.getZkController();
    if (zk != null) {
      setNode(zk.getNodeName());
    }
  }
}
 
Example #25
Source File: TestCollectionAPIs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static Pair<SolrQueryRequest, SolrQueryResponse> makeCall(final ApiBag apiBag, String path,
                                                                 final SolrRequest.METHOD method,
                                                                 final String payload, final CoreContainer cc) throws Exception {
  SolrParams queryParams = new MultiMapSolrParams(Collections.emptyMap());
  if (path.indexOf('?') > 0) {
    String queryStr = path.substring(path.indexOf('?') + 1);
    path = path.substring(0, path.indexOf('?'));
    queryParams = SolrRequestParsers.parseQueryString(queryStr);
  }
  final HashMap<String, String> parts = new HashMap<>();
  Api api = apiBag.lookup(path, method.toString(), parts);
  if (api == null) throw new RuntimeException("No handler at path :" + path);
  SolrQueryResponse rsp = new SolrQueryResponse();
  LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, queryParams) {
    @Override
    public List<CommandOperation> getCommands(boolean validateInput) {
      if (payload == null) return Collections.emptyList();
      return ApiBag.getCommandOperations(new ContentStreamBase.StringStream(payload), api.getCommandSchema(), true);
    }

    @Override
    public Map<String, String> getPathTemplateValues() {
      return parts;
    }

    @Override
    public String getHttpMethod() {
      return method.toString();
    }
  };
  try {
    api.call(req, rsp);
  } catch (ApiBag.ExceptionWithErrObject e) {
    throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()), e);

  }
  return new Pair<>(req, rsp);
}
 
Example #26
Source File: SolrGraphiteReporterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testReporter() throws Exception {
  int jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1: 0;
  Path home = Paths.get(TEST_HOME());
  // define these properties, they are used in solrconfig.xml
  System.setProperty("solr.test.sys.prop1", "propone");
  System.setProperty("solr.test.sys.prop2", "proptwo");

  MockGraphite mock = new MockGraphite();
  try {
    mock.start();
    Thread.sleep(1000);
    // define the port where MockGraphite is running
    System.setProperty("mock-graphite-port", String.valueOf(mock.port));
    String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-graphitereporter.xml").toFile(), "UTF-8");
    NodeConfig cfg = SolrXmlConfig.fromString(home, solrXml);
    CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator
                                           (DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(),
                                            "solrconfig.xml", "schema.xml"));
                                           
    h.coreName = DEFAULT_TEST_CORENAME;
    SolrMetricManager metricManager = cc.getMetricManager();
    Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
    assertEquals(1 + jmxReporter, reporters.size());
    SolrMetricReporter reporter = reporters.get("test");
    assertNotNull(reporter);
    assertTrue(reporter instanceof SolrGraphiteReporter);
    Thread.sleep(5000);
    assertTrue(mock.lines.size() >= 3);
    String[] frozenLines = mock.lines.toArray(new String[mock.lines.size()]);
    for (String line : frozenLines) {
      assertTrue(line, line.startsWith("test.solr.node.CONTAINER.cores."));
    }
  } finally {
    mock.close();
  }
}
 
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: SolrDispatchFilter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Override this to change CoreContainer initialization
 * @return a CoreContainer to hold this server's cores
 */
protected CoreContainer createCoreContainer(Path solrHome, Properties extraProperties) {
  NodeConfig nodeConfig = loadNodeConfig(solrHome, extraProperties);
  final CoreContainer coreContainer = new CoreContainer(nodeConfig, true);
  coreContainer.load();
  return coreContainer;
}
 
Example #29
Source File: RecoveryStrategy.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected RecoveryStrategy(CoreContainer cc, CoreDescriptor cd, RecoveryListener recoveryListener) {
  this.cc = cc;
  this.coreName = cd.getName();
  this.recoveryListener = recoveryListener;
  zkController = cc.getZkController();
  zkStateReader = zkController.getZkStateReader();
  baseUrl = zkController.getBaseUrl();
  coreZkNodeName = cd.getCloudDescriptor().getCoreNodeName();
  replicaType = cd.getCloudDescriptor().getReplicaType();
}
 
Example #30
Source File: TestManagedSchemaThreadSafety.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private ZkController createZkController(SolrZkClient client) throws KeeperException, InterruptedException {
  assumeWorkingMockito();
  
  CoreContainer mockAlwaysUpCoreContainer = mock(CoreContainer.class, 
      Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
  when(mockAlwaysUpCoreContainer.isShutDown()).thenReturn(Boolean.FALSE);  // Allow retry on session expiry
  
  
  ZkController zkController = mock(ZkController.class,
      Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));

  when(zkController.getCoreContainer()).thenReturn(mockAlwaysUpCoreContainer);

  when(zkController.getZkClient()).thenReturn(client);
  Mockito.doAnswer(new Answer<Boolean>() {
    volatile boolean sessionExpired=false;
    
    @Override
    public Boolean answer(InvocationOnMock invocation) throws Throwable {
      String path = (String) invocation.getArguments()[0];
      perhapsExpired();
      Boolean exists = client.exists(path, true);
      perhapsExpired();
      return exists;
    }

    private void perhapsExpired() throws SessionExpiredException {
      if (!sessionExpired && rarely()) {
        sessionExpired = true;
        throw new KeeperException.SessionExpiredException();
      }
    }
  }).when(zkController).pathExists(Mockito.anyString());
  return zkController;
}