Package org.jclouds.sshj

Examples of org.jclouds.sshj.SshjSshClient$Connection


    try {
      File tmpFile = createTmpDir();
      String fileLocation = tmpFile.getAbsolutePath() + file.getName();
      fileOutputStream = new FileOutputStream(fileLocation);

      final SshjSshClient client = getSSHClient(url, privateKey);
      inputStream = client.get(fileName).openStream();

      FileCopyUtils.copy(inputStream, fileOutputStream);
      return fileLocation;
    }
    catch (IOException ioException) {
View Full Code Here


    Assert.notNull(dir, "dir should not be null");
    Assert.hasText(fileName, "The remote file name must be specified.");
    boolean isFileCopied = false;
    long timeout = System.currentTimeMillis() + retryTime;
    while (!isFileCopied && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + dir);
      client.put(dir + "/" + fileName, payload);
      ExecResponse response = client.exec("ls -al " + dir + "/" + fileName);
      if (response.getExitStatus() > 0) {
        continue; //file was not created
      }
      response = client.exec("cat " + dir + "/" + fileName);
      if (response.getExitStatus() > 0 || !payload.equals(response.getOutput())) {
        continue;//data stored on machine is different than was expected.
      }
      isFileCopied = true;
    }
View Full Code Here

    Assert.notNull(uri, "uri should not be null");
    Assert.notNull(file, "file must not be null");
    boolean isFileCopied = false;
    long timeout = System.currentTimeMillis() + waitTime;
    while (!isFileCopied && System.currentTimeMillis() < timeout) {
      final SshjSshClient client = getSSHClient(host, privateKey);
      Assert.isTrue(file.exists(), "File to be copied to remote machine does not exist");
      ByteSource byteSource = com.google.common.io.Files.asByteSource(file);
      ByteSourcePayload payload = new ByteSourcePayload(byteSource);
      long byteSourceSize = -1;
      try {
        byteSourceSize = byteSource.size();
        payload.getContentMetadata().setContentLength(byteSourceSize);
      }
      catch (IOException ioe) {
        throw new IllegalStateException("Unable to retrieve size for file to be copied to remote machine.", ioe);
      }
      client.put(uri.getPath(), payload);
      if (client.exec("ls -al " + uri.getPath()).getExitStatus() == 0) {
        ExecResponse statResponse = client.exec("stat --format=%s " + uri.getPath());
        long copySize = Long.valueOf(statResponse.getOutput().trim());
        if (copySize == byteSourceSize) {
          isFileCopied = true;
        }
      }
View Full Code Here

    Assert.hasText(path, "path must not be empty nor null");
    Assert.hasText(host, "host must not be empty nor null");
    Assert.hasText(privateKey, "privateKey must not be empty nor null");
    long timeout = System.currentTimeMillis() + waitTime;
    while (!isDirectoryCreated && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + path);
      ExecResponse response = client.exec("ls -al " + path);
      if (response.getExitStatus() > 0) {
        continue; //directory was not created
      }
      isDirectoryCreated = true;
    }
View Full Code Here

    Assert.hasText(privateKey, "privateKey must not be empty nor null.");
    Assert.hasText(host, "The remote machine's URL must be specified.");
    Assert.notNull(dir, "dir should not be null");
    Assert.hasText(fileName, "The remote file name must be specified.");

    final SshjSshClient client = getSSHClient(host, privateKey);
    client.exec("echo '" + payload + "' >> " + dir + "/" + fileName);
  }
View Full Code Here

   * @return An Integer array that contains the pids.
   */
  public static Integer[] getContainerPidsFromURL(URL url, String privateKey, String jpsCommand) {
    Assert.notNull(url, "url can not be null");
    Assert.hasText(privateKey, "privateKey can not be empty nor null");
    SshjSshClient client = getSSHClient(url, privateKey);
    ExecResponse response = client.exec(jpsCommand);
    return extractPidsFromJPS(response.getOutput());
  }
View Full Code Here

  private static SshjSshClient getSSHClient(String host, String privateKey) {
    final LoginCredentials credential = LoginCredentials
        .fromCredentials(new Credentials("ubuntu", privateKey));
    final HostAndPort socket = HostAndPort.fromParts(host, 22);
    final SshjSshClient client = new SshjSshClient(
        new BackoffLimitedRetryHandler(), socket, credential, 5000);
    return client;
  }
View Full Code Here

      RetryablePredicate<IPSocket> socketOpen = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180,
               5, TimeUnit.SECONDS);

      socketOpen.apply(socket);

      SshClient ssh = new SshjSshClient(new BackoffLimitedRetryHandler(), socket, 60000, credentials.identity, null,
               credentials.credential.getBytes());
      try {
         ssh.connect();
         ExecResponse hello = ssh.exec("echo hello");
         assertEquals(hello.getOutput().trim(), "hello");
         ExecResponse exec = ssh.exec("df");
         assertTrue(exec.getOutput().contains("Filesystem"),
                  "The output should've contained filesystem information, but it didn't. Output: " + exec);
      } finally {
         if (ssh != null)
            ssh.disconnect();
      }
   }
View Full Code Here

         this.injector = injector;
      }

      @Override
      public SshClient create(HostAndPort socket, LoginCredentials credentials) {
         SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout);
         injector.injectMembers(client);// add logger
         return client;
      }
View Full Code Here

         this.injector = injector;
      }

      @Override
      public SshClient create(HostAndPort socket, LoginCredentials credentials) {
         SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout, getAgentConnector());
         injector.injectMembers(client)// add logger
         return client;
      }
View Full Code Here

TOP

Related Classes of org.jclouds.sshj.SshjSshClient$Connection

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.