use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class OServerPluginManager method installDynamicPlugin.
private void installDynamicPlugin(final File pluginFile) {
String pluginName = pluginFile.getName();
final OServerPluginInfo currentPluginData;
OLogManager.instance().info(this, "Installing dynamic plugin '%s'...", pluginName);
URLClassLoader pluginClassLoader = null;
try {
final URL url = pluginFile.toURI().toURL();
pluginClassLoader = new URLClassLoader(new URL[] { url }, getClass().getClassLoader());
// LOAD PLUGIN.JSON FILE
final URL r = pluginClassLoader.findResource("plugin.json");
if (r == null) {
OLogManager.instance().error(this, "Plugin definition file ('plugin.json') is not found for dynamic plugin '%s'", pluginName);
throw new IllegalArgumentException(String.format("Plugin definition file ('plugin.json') is not found for dynamic plugin '%s'", pluginName));
}
final InputStream pluginConfigFile = r.openStream();
try {
if (pluginConfigFile == null || pluginConfigFile.available() == 0) {
OLogManager.instance().error(this, "Error on loading 'plugin.json' file for dynamic plugin '%s'", pluginName);
throw new IllegalArgumentException(String.format("Error on loading 'plugin.json' file for dynamic plugin '%s'", pluginName));
}
final ODocument properties = new ODocument().fromJSON(pluginConfigFile);
if (properties.containsField("name"))
// OVERWRITE PLUGIN NAME
pluginName = properties.field("name");
final String pluginClass = properties.field("javaClass");
final OServerPlugin pluginInstance;
final Map<String, Object> parameters;
if (pluginClass != null) {
// CREATE PARAMETERS
parameters = properties.field("parameters");
final List<OServerParameterConfiguration> params = new ArrayList<OServerParameterConfiguration>();
for (String paramName : parameters.keySet()) {
params.add(new OServerParameterConfiguration(paramName, (String) parameters.get(paramName)));
}
final OServerParameterConfiguration[] pluginParams = params.toArray(new OServerParameterConfiguration[params.size()]);
pluginInstance = startPluginClass(pluginClass, pluginParams);
} else {
pluginInstance = null;
parameters = null;
}
// REGISTER THE PLUGIN
currentPluginData = new OServerPluginInfo(pluginName, (String) properties.field("version"), (String) properties.field("description"), (String) properties.field("web"), pluginInstance, parameters, pluginFile.lastModified(), pluginClassLoader);
registerPlugin(currentPluginData);
loadedPlugins.put(pluginFile.getName(), pluginName);
registerStaticDirectory(currentPluginData);
} finally {
pluginConfigFile.close();
}
} catch (Exception e) {
OLogManager.instance().error(this, "Error on installing dynamic plugin '%s'", e, pluginName);
}
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class AutomaticBackupTest method testFullBackup.
@Test
public void testFullBackup() throws IOException, ClassNotFoundException, MalformedObjectNameException, InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
if (new File(BACKUPDIR + "/fullBackup.zip").exists())
new File(BACKUPDIR + "/fullBackup.zip").delete();
final OAutomaticBackup aBackup = new OAutomaticBackup();
final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] { new OServerParameterConfiguration("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000))), new OServerParameterConfiguration("delay", "1d"), new OServerParameterConfiguration("mode", "FULL_BACKUP"), new OServerParameterConfiguration("target.directory", BACKUPDIR), new OServerParameterConfiguration("target.fileName", "fullBackup.zip") };
aBackup.config(server, config);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
aBackup.sendShutdown();
final ODatabaseDocumentTx database2 = new ODatabaseDocumentTx(URL2);
if (database2.exists())
database2.open("admin", "admin").drop();
database2.create();
database2.restore(new FileInputStream(BACKUPDIR + "/fullBackup.zip"), null, null, null);
Assert.assertEquals(database2.countClass("TestBackup"), 1);
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class AutomaticBackupTest method testFullBackupWithJsonConfigExclude.
@Test
public void testFullBackupWithJsonConfigExclude() throws IOException, ClassNotFoundException, MalformedObjectNameException, InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
if (new File(BACKUPDIR + "/testautobackup.zip").exists())
new File(BACKUPDIR + "/testautobackup.zip").delete();
Assert.assertFalse(new File(tempDirectory + "/config/automatic-backup.json").exists());
String jsonConfig = OIOUtils.readStreamAsString(getClass().getResourceAsStream("automatic-backup.json"));
ODocument doc = new ODocument().fromJSON(jsonConfig);
doc.field("enabled", true);
doc.field("targetFileName", "${DBNAME}.zip");
doc.field("dbExclude", new String[] { "testautobackup" });
doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));
OIOUtils.writeFile(new File(tempDirectory + "/config/automatic-backup.json"), doc.toJSON());
final OAutomaticBackup aBackup = new OAutomaticBackup();
final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] {};
aBackup.config(server, config);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
aBackup.sendShutdown();
Assert.assertFalse(new File(BACKUPDIR + "/testautobackup.zip").exists());
}
Aggregations