Package org.jclouds.compute.domain

Examples of org.jclouds.compute.domain.ExecResponse


   @Test
   public void testExecHostname() throws IOException {
      SshClient client = setupClient();
      try {
         ExecResponse response = client.exec("hostname");
         assertEquals(response.getExitStatus(), 0);
         assertEquals(response.getError(), "");
         assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName()
               : sshHost);
      } finally {
         client.disconnect();
      }
   }
View Full Code Here


   @Test
   public void testExecInvalidCommand() throws IOException {
      SshClient client = setupClient();
      try {
         ExecResponse response = client.exec("thisCommandDoesNotExist");
         assertNotEquals(response.getExitStatus(), 0);
         assertTrue(response.getOutput().contains("not found") || response.getError().contains("not found"),
               "stdout="+response.getOutput()+"; stderr="+response.getError());
      } finally {
         client.disconnect();
      }
   }
View Full Code Here

               logger.warn("<< " + message);
               backoffForAttempt(++i, message);
            }
            if (errorStatus == -1)
               throw new SshException(message);
            return new ExecResponse(outputString, errorString, errorStatus);
         } finally {
            clear();
         }
      }
View Full Code Here

   public void testExecHostnameRepeatedlyWithSameSessions() throws Exception {
      final SshClient client = setupClient();
     
      try {
         for (int i = 0; i < 100; i++) {
            ExecResponse response = client.exec("hostname");
            assertEquals(response.getError(), "");
            assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName()
                     : sshHost);
            //System.out.println("completed (sequentially) "+i);
         }
      } finally {
         client.disconnect();
View Full Code Here

      try {
         for (int i = 0; i < 100; i++) {
            futures.add(userExecutor.submit(new Callable<ExecResponse>() {
               @Override
               public ExecResponse call() {
                  ExecResponse response = client.exec("hostname");
                  //System.out.println("completed (concurrently) "+count.incrementAndGet());
                  return response;
                 
               }
            }));
         }
         List<ExecResponse> responses = Futures.allAsList(futures).get(3000, TimeUnit.SECONDS);
         for (ExecResponse response : responses) {
            assertEquals(response.getError(), "");
            assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName()
                     : sshHost);
         }
      } finally {
         userExecutor.shutdownNow();
         client.disconnect();
View Full Code Here

               throw new RuntimeException("path " + path + " not stubbed");
            }

            public ExecResponse exec(String command) {
               if (command.equals("hostname")) {
                  return new ExecResponse(sshHost, "", 0);
               }
               throw new RuntimeException("command " + command + " not stubbed");
            }

            @Override
View Full Code Here

      assert contents.indexOf("root") >= 0 : "no root in " + contents;
   }

   public void testExecHostname() throws IOException, InterruptedException {
      SshClient client = setupClient();
      ExecResponse response = client.exec("hostname");
      assertEquals(response.getError(), "");
      assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName()
               : sshHost);
   }
View Full Code Here

            Command output = session.exec(checkNotNull(command, "command"));
            String outputString = IOUtils.readFully(output.getInputStream()).toString();
            output.join(sshClientConnection.getSessionTimeout(), TimeUnit.MILLISECONDS);
            int errorStatus = output.getExitStatus();
            String errorString = IOUtils.readFully(output.getErrorStream()).toString();
            return new ExecResponse(outputString, errorString, errorStatus);
         } finally {
            clear();
         }
      }
View Full Code Here

      }

      @Override
      public boolean apply(String script) {
         System.out.printf("%d: %s testing status%n", System.currentTimeMillis(), script);
         ExecResponse output = ssh.exec(script + " status");
         if (output.getOutput().trim().equals("")) {
            output = ssh.exec(script + " tail");
            String stdout = output.getOutput().trim();
            if (stdout.contains(endMatches)) {
               return true;
            } else {
               output = ssh.exec(script + " tailerr");
               String stderr = output.getOutput().trim();
               throw new RuntimeException(String.format(
                     "script %s ended without token: stdout.log: [%s]; stderr.log: [%s]; ", script, stdout, stderr));
            }
         }
         return false;
View Full Code Here

   protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException {
      SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class)
            .create(HostAndPort.fromParts(server.getVnc().getIp(), 22), creds);
      try {
         ssh.connect();
         ExecResponse hello = ssh.exec("echo hello");
         assertEquals(hello.getOutput().trim(), "hello");
         System.err.println(ssh.exec("df -k").getOutput());
         System.err.println(ssh.exec("mount").getOutput());
         System.err.println(ssh.exec("uname -a").getOutput());
      } finally {
         if (ssh != null)
View Full Code Here

TOP

Related Classes of org.jclouds.compute.domain.ExecResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.