Search in sources :

Example 6 with Session

use of iaik.pkcs.pkcs11.Session in project neo4j by neo4j.

the class BoltCausalClusteringIT method sessionShouldExpireOnFailingReadQuery.

@Test
public void sessionShouldExpireOnFailingReadQuery() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember coreServer = cluster.getCoreMemberById(0);
    Driver driver = GraphDatabase.driver(coreServer.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
    inExpirableSession(driver, Driver::session, (session) -> {
        session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
        return null;
    });
    try (Session readSession = driver.session(AccessMode.READ)) {
        // when
        connectedServer(readSession).shutdown();
        // then
        readSession.run("MATCH (n) RETURN n LIMIT 1").consume();
        fail("Should have thrown an exception as the read replica went away mid query");
    } catch (SessionExpiredException sep) {
        // then
        assertThat(sep.getMessage(), containsString("is no longer available"));
    } finally {
        driver.close();
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 7 with Session

use of iaik.pkcs.pkcs11.Session in project neo4j by neo4j.

the class BoltCausalClusteringIT method shouldNotBeAbleToWriteOnAReadSession.

@Test
public void shouldNotBeAbleToWriteOnAReadSession() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    assertEventually("Failed to execute write query on read server", () -> {
        switchLeader(cluster.awaitLeader());
        CoreClusterMember leader = cluster.awaitLeader();
        Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"));
        try (Session session = driver.session(AccessMode.READ)) {
            // when
            session.run("CREATE (n:Person {name: 'Jim'})").consume();
            return false;
        } catch (ClientException ex) {
            assertEquals("Write queries cannot be performed in READ access mode.", ex.getMessage());
            return true;
        } finally {
            driver.close();
        }
    }, is(true), 30, SECONDS);
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) ClientException(org.neo4j.driver.v1.exceptions.ClientException) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 8 with Session

use of iaik.pkcs.pkcs11.Session in project CloudStack-archive by CloudStack-extras.

the class StressTestDirectAttach method sshTest.

private static String sshTest(String host, String password) {
    int i = 0;
    if (host == null) {
        s_logger.info("Did not receive a host back from test, ignoring ssh test");
        return null;
    }
    if (password == null) {
        s_logger.info("Did not receive a password back from test, ignoring ssh test");
        return null;
    }
    // We will retry 5 times before quitting
    String result = null;
    int retry = 0;
    while (true) {
        try {
            if (retry > 0) {
                s_logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt. Account is " + _account.get());
                Thread.sleep(120000);
            }
            s_logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry + ". Account is " + _account.get());
            Connection conn = new Connection(host);
            conn.connect(null, 60000, 60000);
            s_logger.info("User + " + _account.get() + " ssHed successfully into linux host " + host);
            boolean isAuthenticated = conn.authenticateWithPassword("root", password);
            if (isAuthenticated == false) {
                s_logger.info("Authentication failed for root with password" + password);
                return "Authentication failed";
            }
            boolean success = false;
            String linuxCommand = null;
            if (i % 10 == 0)
                linuxCommand = "rm -rf *; wget http://192.168.1.250/dump.bin && ls -al dump.bin";
            else
                linuxCommand = "wget http://192.168.1.250/dump.bin && ls -al dump.bin";
            Session sess = conn.openSession();
            s_logger.info("User " + _account.get() + " executing : " + linuxCommand);
            sess.execCommand(linuxCommand);
            InputStream stdout = sess.getStdout();
            InputStream stderr = sess.getStderr();
            byte[] buffer = new byte[8192];
            while (true) {
                if ((stdout.available() == 0) && (stderr.available() == 0)) {
                    int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
                    if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                        s_logger.info("Timeout while waiting for data from peer.");
                        return null;
                    }
                    if ((conditions & ChannelCondition.EOF) != 0) {
                        if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                            break;
                        }
                    }
                }
                while (stdout.available() > 0) {
                    success = true;
                    int len = stdout.read(buffer);
                    if (// this check is somewhat paranoid
                    len > 0)
                        s_logger.info(new String(buffer, 0, len));
                }
                while (stderr.available() > 0) {
                    /* int len = */
                    stderr.read(buffer);
                }
            }
            sess.close();
            conn.close();
            if (!success) {
                retry++;
                if (retry == MAX_RETRY_LINUX) {
                    result = "SSH Linux Network test fail";
                }
            }
            return result;
        } catch (Exception e) {
            retry++;
            s_logger.error("SSH Linux Network test fail with error");
            if (retry == MAX_RETRY_LINUX) {
                return "SSH Linux Network test fail with error " + e.getMessage();
            }
        }
        i++;
    }
}
Also used : InputStream(java.io.InputStream) Connection(com.trilead.ssh2.Connection) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Session(com.trilead.ssh2.Session)

Example 9 with Session

use of iaik.pkcs.pkcs11.Session in project CloudStack-archive by CloudStack-extras.

the class TestClient method sshTest.

private static String sshTest(String host) {
    if (host == null) {
        s_logger.info("Did not receive a host back from test, ignoring ssh test");
        return null;
    }
    // We will retry 5 times before quitting
    int retry = 0;
    while (true) {
        try {
            if (retry > 0) {
                s_logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt");
                Thread.sleep(120000);
            }
            s_logger.info("Attempting to SSH into linux host " + host + " with retry attempt: " + retry);
            Connection conn = new Connection(host);
            conn.connect(null, 60000, 60000);
            s_logger.info("SSHed successfully into linux host " + host);
            boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
            if (isAuthenticated == false) {
                return "Authentication failed";
            }
            boolean success = false;
            Session sess = conn.openSession();
            s_logger.info("Executing : wget http://172.16.0.220/dump.bin");
            sess.execCommand("wget http://172.16.0.220/dump.bin && ls -al dump.bin");
            InputStream stdout = sess.getStdout();
            InputStream stderr = sess.getStderr();
            byte[] buffer = new byte[8192];
            while (true) {
                if ((stdout.available() == 0) && (stderr.available() == 0)) {
                    int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
                    if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                        s_logger.info("Timeout while waiting for data from peer.");
                        return null;
                    }
                    if ((conditions & ChannelCondition.EOF) != 0) {
                        if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                            break;
                        }
                    }
                }
                while (stdout.available() > 0) {
                    success = true;
                    int len = stdout.read(buffer);
                    if (// this check is somewhat paranoid
                    len > 0)
                        s_logger.info(new String(buffer, 0, len));
                }
                while (stderr.available() > 0) {
                    int len = stderr.read(buffer);
                }
            }
            sess.close();
            conn.close();
            if (success) {
                return null;
            } else {
                retry++;
                if (retry == MAX_RETRY_LINUX) {
                    return "SSH Linux Network test fail";
                }
            }
        } catch (Exception e) {
            retry++;
            if (retry == MAX_RETRY_LINUX) {
                return "SSH Linux Network test fail with error " + e.getMessage();
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) Connection(com.trilead.ssh2.Connection) Session(com.trilead.ssh2.Session)

Example 10 with Session

use of iaik.pkcs.pkcs11.Session in project CloudStack-archive by CloudStack-extras.

the class TestClient method sshWinTest.

private static String sshWinTest(String host) {
    if (host == null) {
        s_logger.info("Did not receive a host back from test, ignoring win ssh test");
        return null;
    }
    // We will retry 5 times before quitting
    int retry = 0;
    while (true) {
        try {
            if (retry > 0) {
                s_logger.info("Retry attempt : " + retry + " ...sleeping 300 seconds before next attempt");
                Thread.sleep(300000);
            }
            s_logger.info("Attempting to SSH into windows host " + host + " with retry attempt: " + retry);
            Connection conn = new Connection(host);
            conn.connect(null, 60000, 60000);
            s_logger.info("SSHed successfully into windows host " + host);
            boolean success = false;
            boolean isAuthenticated = conn.authenticateWithPassword("vmops", "vmops");
            if (isAuthenticated == false) {
                return "Authentication failed";
            }
            SCPClient scp = new SCPClient(conn);
            scp.put("wget.exe", "");
            Session sess = conn.openSession();
            s_logger.info("Executing : wget http://172.16.0.220/dump.bin");
            sess.execCommand("wget http://172.16.0.220/dump.bin && dir dump.bin");
            InputStream stdout = sess.getStdout();
            InputStream stderr = sess.getStderr();
            byte[] buffer = new byte[8192];
            while (true) {
                if ((stdout.available() == 0) && (stderr.available() == 0)) {
                    int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
                    if ((conditions & ChannelCondition.TIMEOUT) != 0) {
                        s_logger.info("Timeout while waiting for data from peer.");
                        return null;
                    }
                    if ((conditions & ChannelCondition.EOF) != 0) {
                        if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
                            break;
                        }
                    }
                }
                while (stdout.available() > 0) {
                    success = true;
                    int len = stdout.read(buffer);
                    if (// this check is somewhat paranoid
                    len > 0)
                        s_logger.info(new String(buffer, 0, len));
                }
                while (stderr.available() > 0) {
                    int len = stderr.read(buffer);
                }
            }
            sess.close();
            conn.close();
            if (success) {
                return null;
            } else {
                retry++;
                if (retry == MAX_RETRY_WIN) {
                    return "SSH Windows Network test fail";
                }
            }
        } catch (Exception e) {
            retry++;
            if (retry == MAX_RETRY_WIN) {
                return "SSH Windows Network test fail with error " + e.getMessage();
            }
        }
    }
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) InputStream(java.io.InputStream) Connection(com.trilead.ssh2.Connection) Session(com.trilead.ssh2.Session)

Aggregations

Session (com.trilead.ssh2.Session)42 Session (org.neo4j.driver.v1.Session)38 Connection (com.trilead.ssh2.Connection)32 IOException (java.io.IOException)29 Test (org.junit.Test)29 InputStream (java.io.InputStream)27 Driver (org.neo4j.driver.v1.Driver)27 StatementResult (org.neo4j.driver.v1.StatementResult)20 TokenException (iaik.pkcs.pkcs11.TokenException)15 P11TokenException (org.xipki.security.exception.P11TokenException)15 Record (org.neo4j.driver.v1.Record)12 Session (iaik.pkcs.pkcs11.Session)10 SecretKey (iaik.pkcs.pkcs11.objects.SecretKey)10 ValuedSecretKey (iaik.pkcs.pkcs11.objects.ValuedSecretKey)10 DSAPrivateKey (iaik.pkcs.pkcs11.objects.DSAPrivateKey)9 ECPrivateKey (iaik.pkcs.pkcs11.objects.ECPrivateKey)9 PrivateKey (iaik.pkcs.pkcs11.objects.PrivateKey)9 RSAPrivateKey (iaik.pkcs.pkcs11.objects.RSAPrivateKey)9 SM2PrivateKey (iaik.pkcs.pkcs11.objects.SM2PrivateKey)9 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)9