Search in sources :

Example 41 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class TestRestManager method testManagedResourceRegistrationAndInitialization.

/**
   * Test RestManager initialization and handling of registered ManagedResources. 
   */
@Test
@Ignore
public void testManagedResourceRegistrationAndInitialization() throws Exception {
    // first, we need to register some ManagedResources, which is done with the registry
    // provided by the SolrResourceLoader
    SolrResourceLoader loader = new SolrResourceLoader(Paths.get("./"));
    RestManager.Registry registry = loader.getManagedResourceRegistry();
    assertNotNull("Expected a non-null RestManager.Registry from the SolrResourceLoader!", registry);
    String resourceId = "/config/test/foo";
    registry.registerManagedResource(resourceId, ManagedWordSetResource.class, new MockAnalysisComponent());
    // verify the two different components can register the same ManagedResource in the registry
    registry.registerManagedResource(resourceId, ManagedWordSetResource.class, new MockAnalysisComponent());
    // verify we can register another resource under a different resourceId
    registry.registerManagedResource("/config/test/foo2", ManagedWordSetResource.class, new MockAnalysisComponent());
    ignoreException("REST API path .* already registered to instances of ");
    String failureMessage = "Should not be able to register a different" + " ManagedResource implementation for {}";
    // of ManagedResource implementation under the same resourceId
    try {
        registry.registerManagedResource(resourceId, BogusManagedResource.class, new MockAnalysisComponent());
        fail(String.format(Locale.ROOT, failureMessage, resourceId));
    } catch (SolrException solrExc) {
    // expected output
    }
    resetExceptionIgnores();
    ignoreException("is a reserved endpoint used by the Solr REST API!");
    failureMessage = "Should not be able to register reserved endpoint {}";
    // verify that already-spoken-for REST API endpoints can't be registered
    Set<String> reservedEndpoints = registry.getReservedEndpoints();
    assertTrue(reservedEndpoints.size() > 2);
    assertTrue(reservedEndpoints.contains(RestManager.SCHEMA_BASE_PATH + RestManager.MANAGED_ENDPOINT));
    for (String endpoint : reservedEndpoints) {
        try {
            registry.registerManagedResource(endpoint, BogusManagedResource.class, new MockAnalysisComponent());
            fail(String.format(Locale.ROOT, failureMessage, endpoint));
        } catch (SolrException solrExc) {
        // expected output
        }
        // also try to register already-spoken-for REST API endpoints with a child segment
        endpoint += "/kid";
        try {
            registry.registerManagedResource(endpoint, BogusManagedResource.class, new MockAnalysisComponent());
            fail(String.format(Locale.ROOT, failureMessage, endpoint));
        } catch (SolrException solrExc) {
        // expected output
        }
    }
    resetExceptionIgnores();
    NamedList<String> initArgs = new NamedList<>();
    RestManager restManager = new RestManager();
    restManager.init(loader, initArgs, new ManagedResourceStorage.InMemoryStorageIO());
    ManagedResource res = restManager.getManagedResource(resourceId);
    assertTrue(res instanceof ManagedWordSetResource);
    assertEquals(res.getResourceId(), resourceId);
    // exception if it isn't registered
    restManager.getManagedResource("/config/test/foo2");
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrException(org.apache.solr.common.SolrException) ManagedWordSetResource(org.apache.solr.rest.schema.analysis.ManagedWordSetResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 42 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class TestRestManager method testReloadFromPersistentStorage.

@Test
public void testReloadFromPersistentStorage() throws Exception {
    SolrResourceLoader loader = new SolrResourceLoader(Paths.get("./"));
    File unitTestStorageDir = createTempDir("testRestManager").toFile();
    assertTrue(unitTestStorageDir.getAbsolutePath() + " is not a directory!", unitTestStorageDir.isDirectory());
    assertTrue(unitTestStorageDir.canRead());
    assertTrue(unitTestStorageDir.canWrite());
    NamedList<String> ioInitArgs = new NamedList<>();
    ioInitArgs.add(ManagedResourceStorage.STORAGE_DIR_INIT_ARG, unitTestStorageDir.getAbsolutePath());
    StorageIO storageIO = new ManagedResourceStorage.FileStorageIO();
    storageIO.configure(loader, ioInitArgs);
    NamedList<String> initArgs = new NamedList<>();
    RestManager restManager = new RestManager();
    restManager.init(loader, initArgs, storageIO);
    // verifies a RestManager can be reloaded from a previous RestManager's data
    RestManager restManager2 = new RestManager();
    restManager2.init(loader, initArgs, storageIO);
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) NamedList(org.apache.solr.common.util.NamedList) StorageIO(org.apache.solr.rest.ManagedResourceStorage.StorageIO) File(java.io.File) Test(org.junit.Test)

Example 43 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class DateFieldTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // set some system properties for use by tests
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    SolrConfig config = new SolrConfig(new SolrResourceLoader(Paths.get(testInstanceDir)), testConfHome + "solrconfig.xml", null);
    IndexSchema schema = IndexSchemaFactory.buildIndexSchema(testConfHome + "schema.xml", config);
    f = random().nextBoolean() ? new TrieDateField() : new DatePointField();
    f.init(schema, Collections.<String, String>emptyMap());
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrConfig(org.apache.solr.core.SolrConfig)

Example 44 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class OpenExchangeRatesOrgProviderTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    AbstractCurrencyFieldTest.assumeCurrencySupport("USD", "EUR", "MXN", "GBP", "JPY");
    super.setUp();
    mockParams.put(OpenExchangeRatesOrgProvider.PARAM_RATES_FILE_LOCATION, "open-exchange-rates.json");
    oerp = new OpenExchangeRatesOrgProvider();
    loader = new SolrResourceLoader(TEST_PATH().resolve("collection1"));
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) Before(org.junit.Before)

Example 45 with SolrResourceLoader

use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.

the class SchemaManager method doOperations.

private List doOperations(List<CommandOperation> operations) throws InterruptedException, IOException, KeeperException {
    //The default timeout is 10 minutes when no BaseSolrResource.UPDATE_TIMEOUT_SECS is specified
    int timeout = req.getParams().getInt(BaseSolrResource.UPDATE_TIMEOUT_SECS, 600);
    //If BaseSolrResource.UPDATE_TIMEOUT_SECS=0 or -1 then end time then we'll try for 10 mins ( default timeout )
    if (timeout < 1) {
        timeout = 600;
    }
    TimeOut timeOut = new TimeOut(timeout, TimeUnit.SECONDS);
    SolrCore core = req.getCore();
    String errorMsg = "Unable to persist managed schema. ";
    List errors = Collections.emptyList();
    int latestVersion = -1;
    synchronized (req.getSchema().getSchemaUpdateLock()) {
        while (!timeOut.hasTimedOut()) {
            managedIndexSchema = getFreshManagedSchema(req.getCore());
            for (CommandOperation op : operations) {
                OpType opType = OpType.get(op.name);
                if (opType != null) {
                    opType.perform(op, this);
                } else {
                    op.addError("No such operation : " + op.name);
                }
            }
            errors = CommandOperation.captureErrors(operations);
            if (!errors.isEmpty())
                break;
            SolrResourceLoader loader = req.getCore().getResourceLoader();
            if (loader instanceof ZkSolrResourceLoader) {
                ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
                StringWriter sw = new StringWriter();
                try {
                    managedIndexSchema.persist(sw);
                } catch (IOException e) {
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "unable to serialize schema");
                //unlikely
                }
                try {
                    latestVersion = ZkController.persistConfigResourceToZooKeeper(zkLoader, managedIndexSchema.getSchemaZkVersion(), managedIndexSchema.getResourceName(), sw.toString().getBytes(StandardCharsets.UTF_8), true);
                    req.getCore().getCoreContainer().reload(req.getCore().getName());
                    break;
                } catch (ZkController.ResourceModifiedInZkException e) {
                    log.info("Schema was modified by another node. Retrying..");
                }
            } else {
                try {
                    //only for non cloud stuff
                    managedIndexSchema.persistManagedSchema(false);
                    core.setLatestSchema(managedIndexSchema);
                } catch (SolrException e) {
                    log.warn(errorMsg);
                    errors = singletonList(errorMsg + e.getMessage());
                }
                break;
            }
        }
    }
    if (req.getCore().getResourceLoader() instanceof ZkSolrResourceLoader) {
        // Don't block further schema updates while waiting for a pending update to propagate to other replicas.
        // This reduces the likelihood of a (time-limited) distributed deadlock during concurrent schema updates.
        waitForOtherReplicasToUpdate(timeOut, latestVersion);
    }
    if (errors.isEmpty() && timeOut.hasTimedOut()) {
        log.warn(errorMsg + "Timed out.");
        errors = singletonList(errorMsg + "Timed out.");
    }
    return errors;
}
Also used : TimeOut(org.apache.solr.util.TimeOut) SolrCore(org.apache.solr.core.SolrCore) CommandOperation(org.apache.solr.common.util.CommandOperation) IOException(java.io.IOException) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) StringWriter(java.io.StringWriter) ZkController(org.apache.solr.cloud.ZkController) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)54 Test (org.junit.Test)18 File (java.io.File)11 InputStream (java.io.InputStream)11 NamedList (org.apache.solr.common.util.NamedList)10 SolrException (org.apache.solr.common.SolrException)9 NodeConfig (org.apache.solr.core.NodeConfig)9 Path (java.nio.file.Path)8 CoreContainer (org.apache.solr.core.CoreContainer)8 InputStreamReader (java.io.InputStreamReader)7 Reader (java.io.Reader)7 Map (java.util.Map)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)5 SolrCore (org.apache.solr.core.SolrCore)5 ArrayList (java.util.ArrayList)4 ZkSolrResourceLoader (org.apache.solr.cloud.ZkSolrResourceLoader)4 SolrConfig (org.apache.solr.core.SolrConfig)4