Search in sources :

Example 1 with OServerParameterConfiguration

use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.

the class AutomaticBackupTest method testFullBackupWithJsonConfigInclude.

@Test
public void testFullBackupWithJsonConfigInclude() 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("dbInclude", 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();
    final ODatabaseDocumentTx database2 = new ODatabaseDocumentTx(URL2);
    if (database2.exists())
        database2.open("admin", "admin").drop();
    database2.create();
    database2.restore(new FileInputStream(BACKUPDIR + "/testautobackup.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) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 2 with OServerParameterConfiguration

use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.

the class AutomaticBackupTest method testExport.

// // @Test
// //TODO: move to EE test suite
// public void testIncrementalBackup() throws IOException, ClassNotFoundException, MalformedObjectNameException,
// InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
// if (new File(BACKUPDIR + "/" + DBNAME).exists())
// OFileUtils.deleteRecursively(new File(BACKUPDIR + "/" + DBNAME));
// 
// 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", "INCREMENTAL_BACKUP"),
// new OServerParameterConfiguration("target.directory", BACKUPDIR) };
// 
// 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(BACKUPDIR + "/" + DBNAME);
// 
// Assert.assertEquals(database2.countClass("TestBackup"), 1);
// }
@Test
public void testExport() throws IOException, ClassNotFoundException, MalformedObjectNameException, InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException {
    if (new File(BACKUPDIR + "/fullExport.json.gz").exists())
        new File(BACKUPDIR + "/fullExport.json.gz").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", "EXPORT"), new OServerParameterConfiguration("target.directory", BACKUPDIR), new OServerParameterConfiguration("target.fileName", "fullExport.json.gz") };
    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();
    new ODatabaseImport(database2, BACKUPDIR + "/fullExport.json.gz", null).importDatabase();
    Assert.assertEquals(database2.countClass("TestBackup"), 1);
}
Also used : ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) 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) Test(org.junit.Test)

Example 3 with OServerParameterConfiguration

use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.

the class OServerPluginManager method startPluginClass.

@SuppressWarnings("unchecked")
protected OServerPlugin startPluginClass(final String iClassName, final OServerParameterConfiguration[] params) throws Exception {
    final Class<? extends OServerPlugin> classToLoad = (Class<? extends OServerPlugin>) Class.forName(iClassName);
    final OServerPlugin instance = classToLoad.newInstance();
    // CONFIG()
    final Method configMethod = classToLoad.getDeclaredMethod("config", OServer.class, OServerParameterConfiguration[].class);
    callListenerBeforeConfig(instance, params);
    configMethod.invoke(instance, server, params);
    callListenerAfterConfig(instance, params);
    // STARTUP()
    final Method startupMethod = classToLoad.getDeclaredMethod("startup");
    callListenerBeforeStartup(instance);
    startupMethod.invoke(instance);
    callListenerAfterStartup(instance);
    return instance;
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) Method(java.lang.reflect.Method)

Example 4 with OServerParameterConfiguration

use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.

the class OMailPlugin method config.

@Override
public void config(final OServer oServer, final OServerParameterConfiguration[] iParams) {
    configuration = new ODocument();
    for (OServerParameterConfiguration param : iParams) {
        if (param.name.equalsIgnoreCase("enabled")) {
            enabled = Boolean.parseBoolean(param.value);
            configuration.field("enabled", enabled);
        } else if (param.name.startsWith(CONFIG_PROFILE_PREFIX)) {
            final String parts = param.name.substring(CONFIG_PROFILE_PREFIX.length());
            int pos = parts.indexOf('.');
            if (pos == -1)
                continue;
            final String profileName = parts.substring(0, pos);
            final String profileParam = parts.substring(pos + 1);
            OMailProfile profile = profiles.get(profileName);
            if (profile == null) {
                profile = new OMailProfile();
                profiles.put(profileName, profile);
            }
            if (profileParam.startsWith(CONFIG_MAIL_PREFIX)) {
                profile.put(profileParam, param.value);
            }
        }
    }
    List<Map<String, String>> profilesDocuments = new ArrayList<Map<String, String>>();
    for (String p : profiles.keySet()) {
        OMailProfile oMailProfile = profiles.get(p);
        Map<String, String> properties = new HashMap<String, String>();
        Set<String> strings = oMailProfile.stringPropertyNames();
        for (String string : strings) {
            properties.put(string, oMailProfile.getProperty(string));
        }
        properties.put("name", p);
        profilesDocuments.add(properties);
    }
    configuration.field("profiles", profilesDocuments);
    configure();
    OLogManager.instance().info(this, "Installing Mail plugin, loaded %d profile(s): %s", profiles.size(), profiles.keySet());
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OServerParameterConfiguration

use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.

the class OLiveQueryPlugin method config.

@Override
public void config(final OServer iServer, final OServerParameterConfiguration[] iParams) {
    enabled = false;
    super.config(iServer, iParams);
    for (OServerParameterConfiguration param : iParams) {
        if (param.name.equalsIgnoreCase("enabled")) {
            if (Boolean.parseBoolean(param.value))
                enabled = true;
        }
    }
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration)

Aggregations

OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)20 File (java.io.File)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)7 SimpleDateFormat (java.text.SimpleDateFormat)7 Date (java.util.Date)5 Test (org.junit.Test)5 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 FileInputStream (java.io.FileInputStream)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