Search in sources :

Example 91 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OrientGraphFactoryEncryptionTest method shouldFailWitWrongKey.

@Test
public void shouldFailWitWrongKey() {
    ODatabase db = new ODatabaseDocumentTx("plocal:" + dbPath);
    db.setProperty(STORAGE_ENCRYPTION_METHOD.getKey(), "des");
    db.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db.create();
    db.close();
    OStorage storage = ((ODatabaseDocumentInternal) db).getStorage();
    storage.close();
    OrientGraphFactory graphFactory = new OrientGraphFactory("plocal:" + dbPath);
    graphFactory.setProperty(STORAGE_ENCRYPTION_METHOD.getKey(), "des");
    graphFactory.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db = graphFactory.getDatabase();
    db.command(new OCommandSQL("create class TestEncryption")).execute();
    db.command(new OCommandSQL("insert into TestEncryption set name = 'Jay'")).execute();
    db.close();
    storage = ((ODatabaseDocumentInternal) db).getStorage();
    graphFactory.close();
    storage.close();
    //    Orient.instance().shutdown();
    //    Orient.instance().startup();
    graphFactory = new OrientGraphFactory("plocal:" + dbPath);
    graphFactory.setProperty(STORAGE_ENCRYPTION_METHOD.getKey(), "des");
    graphFactory.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    db = graphFactory.getDatabase();
    List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from TestEncryption"));
    assertThat(result).hasSize(1);
    db.close();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabase(com.orientechnologies.orient.core.db.ODatabase) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 92 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OrientGraphFactoryEncryptionTest method testCreatedDESEncryptedCluster.

@Test
public void testCreatedDESEncryptedCluster() {
    OrientGraphFactory graphFactory = new OrientGraphFactory("plocal:" + dbPath);
    graphFactory.setProperty(STORAGE_ENCRYPTION_KEY.getKey(), "T1JJRU5UREJfSVNfQ09PTA==");
    ODatabaseDocumentTx db = graphFactory.getDatabase();
//    verifyClusterEncryption(db, "des");
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.junit.Test)

Example 93 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OMatchStatementExecutionTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    db = new ODatabaseDocumentTx(DB_STORAGE + ":" + DB_NAME);
    db.create();
    getProfilerInstance().startRecording();
    db.command(new OCommandSQL("CREATE class Person extends V")).execute();
    db.command(new OCommandSQL("CREATE class Friend extends E")).execute();
    db.command(new OCommandSQL("CREATE VERTEX Person set name = 'n1'")).execute();
    db.command(new OCommandSQL("CREATE VERTEX Person set name = 'n2'")).execute();
    db.command(new OCommandSQL("CREATE VERTEX Person set name = 'n3'")).execute();
    db.command(new OCommandSQL("CREATE VERTEX Person set name = 'n4'")).execute();
    db.command(new OCommandSQL("CREATE VERTEX Person set name = 'n5'")).execute();
    db.command(new OCommandSQL("CREATE VERTEX Person set name = 'n6'")).execute();
    String[][] friendList = new String[][] { { "n1", "n2" }, { "n1", "n3" }, { "n2", "n4" }, { "n4", "n5" }, { "n4", "n6" } };
    for (String[] pair : friendList) {
        db.command(new OCommandSQL("CREATE EDGE Friend from (select from Person where name = ?) to (select from Person where name = ?)")).execute(pair[0], pair[1]);
    }
    db.command(new OCommandSQL("CREATE class MathOp extends V")).execute();
    db.command(new OCommandSQL("CREATE VERTEX MathOp set a = 1, b = 3, c = 2")).execute();
    db.command(new OCommandSQL("CREATE VERTEX MathOp set a = 5, b = 3, c = 2")).execute();
    initOrgChart();
    initTriangleTest();
    initEdgeIndexTest();
    initDiamondTest();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) BeforeClass(org.junit.BeforeClass)

Example 94 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OServerCommandAuthenticatedDbAbstract method getProfiledDatabaseInstanceToken.

protected ODatabaseDocumentInternal getProfiledDatabaseInstanceToken(final OHttpRequest iRequest) throws InterruptedException {
    // after authentication, if current login user is different compare with current DB user, reset DB user to login user
    ODatabaseDocumentInternal localDatabase = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (localDatabase == null) {
        localDatabase = (ODatabaseDocumentTx) server.openDatabase(iRequest.databaseName, iRequest.bearerToken);
    } else {
        ORID currentUserId = iRequest.bearerToken.getUserId();
        if (currentUserId != null && localDatabase != null && localDatabase.getUser() != null) {
            if (!currentUserId.equals(localDatabase.getUser().getDocument().getIdentity())) {
                ODocument userDoc = localDatabase.load(currentUserId);
                localDatabase.setUser(new OUser(userDoc));
            }
        }
    }
    iRequest.data.lastDatabase = localDatabase.getName();
    iRequest.data.lastUser = localDatabase.getUser() != null ? localDatabase.getUser().getName() : null;
    return (ODatabaseDocumentTx) localDatabase.getDatabaseOwner();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORID(com.orientechnologies.orient.core.id.ORID) OUser(com.orientechnologies.orient.core.metadata.security.OUser) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 95 with ODatabaseDocumentTx

use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.

the class OAutomaticBackup method config.

@Override
public void config(final OServer iServer, final OServerParameterConfiguration[] iParams) {
    serverInstance = iServer;
    configuration = new ODocument();
    for (OServerParameterConfiguration param : iParams) {
        if (param.name.equalsIgnoreCase("config") && param.value.trim().length() > 0) {
            configFile = param.value.trim();
            final File f = new File(OSystemVariableResolver.resolveSystemVariables(configFile));
            if (!f.exists())
                throw new OConfigurationException("Automatic Backup configuration file '" + configFile + "' not found. Automatic Backup will be disabled");
            break;
        // LEGACY <v2.2: CONVERT ALL SETTINGS IN JSON
        } else if (param.name.equalsIgnoreCase("enabled")) {
            configuration.field("enabled", Boolean.parseBoolean(param.value));
        } else if (param.name.equalsIgnoreCase("delay"))
            configuration.field("delay", param.value);
        else if (param.name.equalsIgnoreCase("firstTime")) {
            configuration.field("firstTime", param.value);
        } else if (param.name.equalsIgnoreCase("target.directory"))
            configuration.field("targetDirectory", param.value);
        else if (param.name.equalsIgnoreCase("db.include") && param.value.trim().length() > 0)
            configuration.field("dbInclude", param.value);
        else if (param.name.equalsIgnoreCase("db.exclude") && param.value.trim().length() > 0)
            configuration.field("dbExclude", param.value);
        else if (param.name.equalsIgnoreCase("target.fileName"))
            configuration.field("targetFileName", param.value);
        else if (param.name.equalsIgnoreCase("bufferSize"))
            configuration.field("bufferSize", Integer.parseInt(param.value));
        else if (param.name.equalsIgnoreCase("compressionLevel"))
            configuration.field("compressionLevel", Integer.parseInt(param.value));
        else if (param.name.equalsIgnoreCase("mode"))
            configuration.field("mode", param.value);
        else if (param.name.equalsIgnoreCase("exportOptions"))
            configuration.field("exportOptions", param.value);
    }
    // LOAD CFG FROM JSON FILE. THIS FILE, IF SPECIFIED, OVERWRITE DEFAULT AND XML SETTINGS
    configure();
    if (delay <= 0)
        throw new OConfigurationException("Cannot find mandatory parameter 'delay'");
    if (!targetDirectory.endsWith("/"))
        targetDirectory += "/";
    final File filePath = new File(targetDirectory);
    if (filePath.exists()) {
        if (!filePath.isDirectory())
            throw new OConfigurationException("Parameter 'path' points to a file, not a directory");
    } else
        // CREATE BACKUP FOLDER(S) IF ANY
        filePath.mkdirs();
    OLogManager.instance().info(this, "Automatic Backup plugin installed and active: delay=%dms, firstTime=%s, targetDirectory=%s", delay, firstTime, targetDirectory);
    final TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            OLogManager.instance().info(this, "Scanning databases to backup...");
            int ok = 0, errors = 0;
            final Map<String, String> databases = serverInstance.getAvailableStorageNames();
            for (final Entry<String, String> database : databases.entrySet()) {
                final String dbName = database.getKey();
                final String dbURL = database.getValue();
                boolean include;
                if (includeDatabases.size() > 0)
                    include = includeDatabases.contains(dbName);
                else
                    include = true;
                if (excludeDatabases.contains(dbName))
                    include = false;
                if (include) {
                    ODatabaseDocumentInternal db = null;
                    try {
                        db = new ODatabaseDocumentTx(dbURL);
                        db.setProperty(ODatabase.OPTIONS.SECURITY.toString(), OSecurityNull.class);
                        db.open("admin", "aaa");
                        final long begin = System.currentTimeMillis();
                        switch(mode) {
                            case FULL_BACKUP:
                                fullBackupDatabase(dbURL, targetDirectory + getFileName(database), db);
                                OLogManager.instance().info(this, "Full Backup of database '" + dbURL + "' completed in " + (System.currentTimeMillis() - begin) + "ms");
                                break;
                            case INCREMENTAL_BACKUP:
                                incrementalBackupDatabase(dbURL, targetDirectory, db);
                                OLogManager.instance().info(this, "Incremental Backup of database '" + dbURL + "' completed in " + (System.currentTimeMillis() - begin) + "ms");
                                break;
                            case EXPORT:
                                exportDatabase(dbURL, targetDirectory + getFileName(database), db);
                                OLogManager.instance().info(this, "Export of database '" + dbURL + "' completed in " + (System.currentTimeMillis() - begin) + "ms");
                                break;
                        }
                        try {
                            for (OAutomaticBackupListener listener : listeners) {
                                listener.onBackupCompleted(dbName);
                            }
                        } catch (Exception e) {
                            OLogManager.instance().error(this, "Error on listener for database '" + dbURL, e);
                        }
                        ok++;
                    } catch (Exception e) {
                        OLogManager.instance().error(this, "Error on backup of database '" + dbURL + "' to directory: " + targetDirectory, e);
                        errors++;
                    } finally {
                        if (db != null)
                            db.close();
                    }
                }
            }
            OLogManager.instance().info(this, "Automatic Backup finished: %d ok, %d errors", ok, errors);
        }
    };
    if (firstTime == null)
        Orient.instance().scheduleTask(timerTask, delay, delay);
    else
        Orient.instance().scheduleTask(timerTask, firstTime, delay);
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) ParseException(java.text.ParseException) IOException(java.io.IOException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)590 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)257 Test (org.testng.annotations.Test)182 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)120 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)81 Test (org.junit.Test)79 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)61 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)47 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)46 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)41 ORID (com.orientechnologies.orient.core.id.ORID)39 ORecordId (com.orientechnologies.orient.core.id.ORecordId)34 Before (org.junit.Before)34 File (java.io.File)33 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)25 ArrayList (java.util.ArrayList)25 BeforeClass (org.testng.annotations.BeforeClass)23 BeforeMethod (org.testng.annotations.BeforeMethod)23 OStorage (com.orientechnologies.orient.core.storage.OStorage)21 List (java.util.List)20