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