Search in sources :

Example 61 with Session

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

the class SshTest method main.

public static void main(String[] args) {
    // Parameters
    List<String> argsList = Arrays.asList(args);
    Iterator<String> iter = argsList.iterator();
    while (iter.hasNext()) {
        String arg = iter.next();
        if (arg.equals("-h")) {
            host = iter.next();
        }
        if (arg.equals("-p")) {
            password = iter.next();
        }
        if (arg.equals("-u")) {
            url = iter.next();
        }
    }
    if (host == null || host.equals("")) {
        s_logger.info("Did not receive a host back from test, ignoring ssh test");
        System.exit(2);
    }
    if (password == null) {
        s_logger.info("Did not receive a password back from test, ignoring ssh test");
        System.exit(2);
    }
    try {
        s_logger.info("Attempting to SSH into host " + host);
        Connection conn = new Connection(host);
        conn.connect(null, 60000, 60000);
        s_logger.info("User + ssHed successfully into host " + host);
        boolean isAuthenticated = conn.authenticateWithPassword("root", password);
        if (isAuthenticated == false) {
            s_logger.info("Authentication failed for root with password" + password);
            System.exit(2);
        }
        String linuxCommand = "wget " + url;
        Session sess = conn.openSession();
        sess.execCommand(linuxCommand);
        sess.close();
        conn.close();
    } catch (Exception e) {
        s_logger.error("SSH test fail with error", e);
        System.exit(2);
    }
}
Also used : Connection(com.trilead.ssh2.Connection) Session(com.trilead.ssh2.Session)

Example 62 with Session

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

the class guestNetwork method run.

public void run() {
    NDC.push("Following thread has started" + Thread.currentThread().getName());
    int retry = 0;
    //Start copying files between machines in the network
    s_logger.info("The size of the array is " + this.virtualMachines.size());
    while (true) {
        try {
            if (retry > 0) {
                s_logger.info("Retry attempt : " + retry + " ...sleeping 120 seconds before next attempt");
                Thread.sleep(120000);
            }
            for (VirtualMachine vm : this.virtualMachines) {
                s_logger.info("Attempting to SSH into linux host " + this.publicIp + " with retry attempt: " + retry);
                Connection conn = new Connection(this.publicIp);
                conn.connect(null, 600000, 600000);
                s_logger.info("SSHed successfully into linux host " + this.publicIp);
                boolean isAuthenticated = conn.authenticateWithPassword("root", "password");
                if (isAuthenticated == false) {
                    s_logger.info("Authentication failed");
                }
                //execute copy command
                Session sess = conn.openSession();
                String fileName;
                Random ran = new Random();
                fileName = Math.abs(ran.nextInt()) + "-file";
                String copyCommand = new String("./scpScript " + vm.getPrivateIp() + " " + fileName);
                s_logger.info("Executing " + copyCommand);
                sess.execCommand(copyCommand);
                Thread.sleep(120000);
                sess.close();
                //execute wget command
                sess = conn.openSession();
                String downloadCommand = new String("wget http://172.16.0.220/scripts/checkDiskSpace.sh; chmod +x *sh; ./checkDiskSpace.sh; rm -rf checkDiskSpace.sh");
                s_logger.info("Executing " + downloadCommand);
                sess.execCommand(downloadCommand);
                Thread.sleep(120000);
                sess.close();
                //close the connection
                conn.close();
            }
        } catch (Exception ex) {
            s_logger.error(ex);
            retry++;
            if (retry == retryNum) {
                s_logger.info("Performance Guest Network test failed with error " + ex.getMessage());
            }
        }
    }
}
Also used : Random(java.util.Random) Connection(com.trilead.ssh2.Connection) Session(com.trilead.ssh2.Session)

Example 63 with Session

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

the class BoltFailuresIT method throwsWhenRunMessageFails.

private void throwsWhenRunMessageFails(Consumer<ThrowingSessionMonitor> monitorSetup) {
    ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor();
    Monitors monitors = newMonitorsSpy(sessionMonitor);
    db = startTestDb(monitors);
    driver = createDriver();
    Session session = driver.session();
    // setup monitor to throw before running the query to make processing of the RUN message fail
    monitorSetup.accept(sessionMonitor);
    session.run("CREATE ()");
    try {
        session.close();
        fail("Exception expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(ConnectionFailureException.class));
    }
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) ConnectionFailureException(org.neo4j.driver.v1.exceptions.ConnectionFailureException) Session(org.neo4j.driver.v1.Session)

Example 64 with Session

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

the class BoltFailuresIT method throwsWhenInitMessageFails.

private void throwsWhenInitMessageFails(Consumer<ThrowingSessionMonitor> monitorSetup, boolean shouldBeAbleToGetSession) {
    ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor();
    monitorSetup.accept(sessionMonitor);
    Monitors monitors = newMonitorsSpy(sessionMonitor);
    db = startTestDb(monitors);
    driver = createDriver();
    try (Session session = driver.session()) {
        if (shouldBeAbleToGetSession) {
            session.run("CREATE ()").consume();
        } else {
            fail("Exception expected");
        }
    } catch (Exception e) {
        assertThat(e, instanceOf(ConnectionFailureException.class));
    }
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) ConnectionFailureException(org.neo4j.driver.v1.exceptions.ConnectionFailureException) Session(org.neo4j.driver.v1.Session)

Example 65 with Session

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

the class BoltCausalClusteringIT method shouldPickANewServerToWriteToOnLeaderSwitch.

@Test
public void shouldPickANewServerToWriteToOnLeaderSwitch() throws Throwable {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    LeaderSwitcher leaderSwitcher = new LeaderSwitcher(cluster);
    Config config = Config.build().withLogging(new JULogging(Level.OFF)).toConfig();
    Set<BoltServerAddress> seenAddresses = new HashSet<>();
    try (Driver driver = GraphDatabase.driver(leader.routingURI(), AuthTokens.basic("neo4j", "neo4j"), config)) {
        boolean success = false;
        long deadline = System.currentTimeMillis() + (30 * 1000);
        while (!success) {
            if (System.currentTimeMillis() > deadline) {
                fail("Failed to write to the new leader in time. Addresses seen: " + seenAddresses);
            }
            try (Session session = driver.session(AccessMode.WRITE)) {
                BoltServerAddress boltServerAddress = ((RoutingNetworkSession) session).address();
                session.run("CREATE (p:Person)");
                seenAddresses.add(boltServerAddress);
                success = seenAddresses.size() >= 2;
            } catch (Exception e) {
                Thread.sleep(100);
            }
            /*
                 * Having the latch release here ensures that we've done at least one pass through the loop, which means
                 * we've completed a connection before the forced master switch.
                 */
            if (seenAddresses.size() >= 1) {
                leaderSwitcher.start();
            }
        }
    } finally {
        leaderSwitcher.stop();
        assertTrue(leaderSwitcher.hadLeaderSwitch());
        assertThat(seenAddresses.size(), greaterThanOrEqualTo(2));
    }
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Config(org.neo4j.driver.v1.Config) Driver(org.neo4j.driver.v1.Driver) TimeoutException(java.util.concurrent.TimeoutException) SessionExpiredException(org.neo4j.driver.v1.exceptions.SessionExpiredException) ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) IOException(java.io.IOException) ClientException(org.neo4j.driver.v1.exceptions.ClientException) BoltServerAddress(org.neo4j.driver.internal.net.BoltServerAddress) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) JULogging(org.neo4j.driver.internal.logging.JULogging) HashSet(java.util.HashSet) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

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