Search in sources :

Example 16 with OServerParameterConfiguration

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);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) URL(java.net.URL) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) URLClassLoader(java.net.URLClassLoader) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OServerParameterConfiguration

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);
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 18 with OServerParameterConfiguration

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());
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)18 File (java.io.File)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Date (java.util.Date)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 FileInputStream (java.io.FileInputStream)4 Test (org.junit.Test)4 OException (com.orientechnologies.common.exception.OException)2 OIOException (com.orientechnologies.common.io.OIOException)2 ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)2 OAutomaticBackup (com.orientechnologies.orient.server.handler.OAutomaticBackup)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 OConsoleReader (com.orientechnologies.common.console.OConsoleReader)1 ODefaultConsoleReader (com.orientechnologies.common.console.ODefaultConsoleReader)1 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)1 OContextConfiguration (com.orientechnologies.orient.core.config.OContextConfiguration)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OServerConfiguration (com.orientechnologies.orient.server.config.OServerConfiguration)1