verinec.adaptation
Class DistSsh

java.lang.Object
  extended by verinec.adaptation.DistSsh
All Implemented Interfaces:
IDistributor

public class DistSsh
extends Object
implements IDistributor

Implements the scp target using the verinec.util ssh classes.

todo: we should consider a mechanism to copy all files in one step to the target system if several exist under the same target, as this implementation gives a lot of overhead when the connection is established and closed for each file.

Version:
$Revision: 1042 $
Author:
david.buchmann at unifr.ch
See Also:
SshProgramExec, SshCopy

Field Summary
private  String host
           
private  String hostVerification
           
private  File keyfile
           
private  Logger log
           
private  String passphrase
           
private  String password
           
private  int port
           
private static String prefPublicKey
          The public key algorithm is fixed to ssh-rsa.
private  String remotePrefix
           
private  String username
           
 
Constructor Summary
DistSsh()
           
 
Method Summary
 void distribute(Element config)
          Write a file to the target system using scp.
 String execute(Element command)
          Execute a command over the ssh execute mechanism.
 void setTarget(Element target)
          Set the connection data from a target element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private Logger log

username

private String username

password

private String password

keyfile

private File keyfile

passphrase

private String passphrase

host

private String host

port

private int port

remotePrefix

private String remotePrefix

hostVerification

private String hostVerification

prefPublicKey

private static String prefPublicKey
The public key algorithm is fixed to ssh-rsa.

Constructor Detail

DistSsh

public DistSsh()
Method Detail

setTarget

public void setTarget(Element target)
               throws VerinecException
Set the connection data from a target element. The scp target defines the attributes that will be processed. As required by scp, the tilde (~) at the beginning of a keyfile path is interpreted as the system property user.home and username ~ as user.name

Specified by:
setTarget in interface IDistributor
Parameters:
target - The tr:target element of the service configuration to be distributed.
Throws:
VerinecException - if the target has no scp child or is missing required attributes.

distribute

public void distribute(Element config)
                throws VerinecException
Write a file to the target system using scp.

Specified by:
distribute in interface IDistributor
Parameters:
config - a result-file to distribute.
Throws:
VerinecException - if the config is not a result-file or there is an error during copying the file.

execute

public String execute(Element command)
               throws VerinecException
Execute a command over the ssh execute mechanism. If a return value is provided by the ssh implementation, that value is returned. Otherwise 1 is returned if anything has been written to stderror contains data, 0 otherwise.

Specified by:
execute in interface IDistributor
Parameters:
command - A command element of the pre- or post-process for the configuration.
Returns:
Null if successful, a String containing the error message on failure of the executed program if the command has continueOnError. (Otherwise an execption is thrown on error.)
Throws:
VerinecException - If the command execution fails (and continueOnError is false) or if the underlying communication protocol fails.

Copyright © 2005 Verinec, DIUF