use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestManagedResource method testCustomStorageFormat.
/**
* The ManagedResource storage framework allows the end developer to use a different
* storage format other than JSON, as demonstrated by this test.
*/
@SuppressWarnings("rawtypes")
@Test
public void testCustomStorageFormat() throws Exception {
String resourceId = "/schema/test/foo";
String storedResourceId = "_schema_test_foo.bin";
MockAnalysisComponent observer = new MockAnalysisComponent();
List<ManagedResourceObserver> observers = Arrays.asList((ManagedResourceObserver) observer);
// put some data in the storage impl so that we can test
// initialization of managed data from storage
Map<String, Object> storedData = new HashMap<>();
Map<String, Object> initArgs = new HashMap<>();
// {'initArgs':{'someArg':'someVal', 'arg2':true, 'arg3':['one','two','three'],
// 'arg4':18, 'arg5':0.9, 'arg6':{ 'uno':1, 'dos':2 }},'"
initArgs.put("someArg", "someVal");
initArgs.put("arg2", Boolean.TRUE);
List<String> arg3list = Arrays.asList("one", "two", "three");
initArgs.put("arg3", arg3list);
initArgs.put("arg4", 18L);
initArgs.put("arg5", 0.9);
Map<String, Long> arg6map = new HashMap<>();
arg6map.put("uno", 1L);
arg6map.put("dos", 2L);
initArgs.put("arg6", arg6map);
storedData.put("initArgs", initArgs);
List<String> managedList = new ArrayList<>();
managedList.add("1");
managedList.add("2");
managedList.add("3");
storedData.put(ManagedResource.MANAGED_JSON_LIST_FIELD, managedList);
ManagedResourceStorage.InMemoryStorageIO storageIO = new ManagedResourceStorage.InMemoryStorageIO();
storageIO.storage.put(storedResourceId, ser2bytes((Serializable) storedData));
CustomStorageFormatResource res = new CustomStorageFormatResource(resourceId, new SolrResourceLoader(Paths.get("./")), storageIO);
res.loadManagedDataAndNotify(observers);
assertTrue("Observer was not notified by ManagedResource!", observer.wasNotified);
// now store some data (as if it came from the REST API)
List<String> updatedData = new ArrayList<>();
updatedData.add("1");
updatedData.add("2");
updatedData.add("3");
updatedData.add("4");
res.storeManagedData(updatedData);
Object stored = res.storage.load(resourceId);
assertNotNull(stored);
assertTrue(stored instanceof Map);
Map storedMap = (Map) stored;
assertNotNull(storedMap.get("initArgs"));
List storedList = (List) storedMap.get(ManagedResource.MANAGED_JSON_LIST_FIELD);
assertTrue(storedList.contains("4"));
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class TestManagedResource method testLoadingAndStoringOfManagedData.
/**
* Tests managed data storage to and loading from {@link ManagedResourceStorage.InMemoryStorageIO}.
*/
@SuppressWarnings("unchecked")
@Test
public void testLoadingAndStoringOfManagedData() throws Exception {
String resourceId = "/config/test/foo";
String storedResourceId = "_config_test_foo.json";
MockAnalysisComponent observer = new MockAnalysisComponent();
List<ManagedResourceObserver> observers = Arrays.asList((ManagedResourceObserver) observer);
// put some data in the storage impl so that we can test
// initialization of managed data from storage
String storedJson = "{'initArgs':{'someArg':'someVal', 'arg2':true, 'arg3':['one','two','three']," + " 'arg4':18, 'arg5':0.9, 'arg6':{ 'uno':1, 'dos':2}},'" + ManagedResource.MANAGED_JSON_LIST_FIELD + "':['1','2','3']}";
ManagedResourceStorage.InMemoryStorageIO storageIO = new ManagedResourceStorage.InMemoryStorageIO();
storageIO.storage.put(storedResourceId, new BytesRef(json(storedJson)));
ManagedTestResource res = new ManagedTestResource(resourceId, new SolrResourceLoader(Paths.get("./")), storageIO);
res.loadManagedDataAndNotify(observers);
assertTrue("Observer was not notified by ManagedResource!", observer.wasNotified);
// now update the managed data (as if it came from the REST API)
List<String> updatedData = new ArrayList<>();
updatedData.add("1");
updatedData.add("2");
updatedData.add("3");
updatedData.add("4");
res.storeManagedData(updatedData);
StringReader stringReader = new StringReader(storageIO.storage.get(storedResourceId).utf8ToString());
Map<String, Object> jsonObject = (Map<String, Object>) ObjectBuilder.getVal(new JSONParser(stringReader));
List<String> jsonList = (List<String>) jsonObject.get(ManagedResource.MANAGED_JSON_LIST_FIELD);
assertTrue("Managed data was not updated correctly!", jsonList.contains("4"));
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class SolrSlf4jReporterTest method testReporter.
@Test
public void testReporter() throws Exception {
LogWatcherConfig watcherCfg = new LogWatcherConfig(true, null, null, 100);
LogWatcher watcher = LogWatcher.newRegisteredLogWatcher(watcherCfg, null);
watcher.setThreshold("INFO");
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");
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-slf4jreporter.xml").toFile(), "UTF-8");
NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
h.coreName = DEFAULT_TEST_CORENAME;
SolrMetricManager metricManager = cc.getMetricManager();
Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
assertTrue(reporters.toString(), reporters.size() >= 2);
SolrMetricReporter reporter = reporters.get("test1");
assertNotNull(reporter);
assertTrue(reporter instanceof SolrSlf4jReporter);
reporter = reporters.get("test2");
assertNotNull(reporter);
assertTrue(reporter instanceof SolrSlf4jReporter);
watcher.reset();
Thread.sleep(5000);
SolrDocumentList history = watcher.getHistory(-1, null);
// dot-separated names are treated like class names and collapsed
// in regular log output, but here we get the full name
assertTrue(history.stream().filter(d -> "solr.node".equals(d.getFirstValue("logger"))).count() > 0);
assertTrue(history.stream().filter(d -> "foobar".equals(d.getFirstValue("logger"))).count() > 0);
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class SolrMetricManagerTest method testReporters.
@Test
public void testReporters() throws Exception {
Random r = random();
SolrResourceLoader loader = new SolrResourceLoader();
SolrMetricManager metricManager = new SolrMetricManager();
PluginInfo[] plugins = new PluginInfo[] { createPluginInfo("universal_foo", null, null), createPluginInfo("multigroup_foo", "jvm, node, core", null), createPluginInfo("multiregistry_foo", null, "solr.node, solr.core.collection1"), createPluginInfo("specific_foo", null, "solr.core.collection1"), createPluginInfo("node_foo", "node", null), createPluginInfo("core_foo", "core", null) };
String tag = "xyz";
metricManager.loadReporters(plugins, loader, tag, SolrInfoBean.Group.node);
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.node));
assertEquals(4, reporters.size());
assertTrue(reporters.containsKey("universal_foo@" + tag));
assertTrue(reporters.containsKey("multigroup_foo@" + tag));
assertTrue(reporters.containsKey("node_foo@" + tag));
assertTrue(reporters.containsKey("multiregistry_foo@" + tag));
metricManager.loadReporters(plugins, loader, tag, SolrInfoBean.Group.core, "collection1");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.core, "collection1"));
assertEquals(5, reporters.size());
assertTrue(reporters.containsKey("universal_foo@" + tag));
assertTrue(reporters.containsKey("multigroup_foo@" + tag));
assertTrue(reporters.containsKey("specific_foo@" + tag));
assertTrue(reporters.containsKey("core_foo@" + tag));
assertTrue(reporters.containsKey("multiregistry_foo@" + tag));
metricManager.loadReporters(plugins, loader, tag, SolrInfoBean.Group.jvm);
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm));
assertEquals(2, reporters.size());
assertTrue(reporters.containsKey("universal_foo@" + tag));
assertTrue(reporters.containsKey("multigroup_foo@" + tag));
metricManager.removeRegistry("solr.jvm");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm));
assertEquals(0, reporters.size());
metricManager.removeRegistry("solr.node");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.node));
assertEquals(0, reporters.size());
metricManager.removeRegistry("solr.core.collection1");
reporters = metricManager.getReporters(SolrMetricManager.getRegistryName(SolrInfoBean.Group.core, "collection1"));
assertEquals(0, reporters.size());
}
use of org.apache.solr.core.SolrResourceLoader in project lucene-solr by apache.
the class JvmMetricsTest method testHiddenSysProps.
@Test
public void testHiddenSysProps() throws Exception {
Path home = Paths.get(TEST_HOME());
SolrResourceLoader loader = new SolrResourceLoader(home);
// default config
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr.xml").toFile(), "UTF-8");
NodeConfig config = SolrXmlConfig.fromString(loader, solrXml);
NodeConfig.NodeConfigBuilder.DEFAULT_HIDDEN_SYS_PROPS.forEach(s -> {
assertTrue(s, config.getMetricsConfig().getHiddenSysProps().contains(s));
});
// custom config
solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-hiddensysprops.xml").toFile(), "UTF-8");
NodeConfig config2 = SolrXmlConfig.fromString(loader, solrXml);
Arrays.asList("foo", "bar", "baz").forEach(s -> {
assertTrue(s, config2.getMetricsConfig().getHiddenSysProps().contains(s));
});
}
Aggregations