com.dtolabs.rundeck.core.execution.impl.common
Class BaseFileCopier

java.lang.Object
  extended by com.dtolabs.rundeck.core.execution.impl.common.BaseFileCopier
Direct Known Subclasses:
JschScpFileCopier, LocalFileCopier

public class BaseFileCopier
extends java.lang.Object

BaseFileCopier provides utility methods for a FileCopier class.


Field Summary
static java.lang.String FILE_COPY_DESTINATION_DIR
           
 
Constructor Summary
BaseFileCopier()
           
 
Method Summary
static java.lang.String appendRemoteFileExtensionForNode(INodeEntry node, java.lang.String filepath)
          Return a string with an appropriate script file extension appended if it is not already on the file path provided.
static java.lang.String generateRemoteFilepathForNode(INodeEntry node, java.lang.String scriptfileName)
          Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)
static java.lang.String getRemoteDirForNode(INodeEntry node)
          Return a remote destination temp dir path for the given node.
protected static java.io.File writeLocalFile(java.io.File original, java.io.InputStream input, java.lang.String script, java.io.File destinationFile)
           
static java.io.File writeScriptTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script, INodeEntry node)
          Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two.
protected static java.io.File writeTempFile(ExecutionContext context, java.io.File original, java.io.InputStream input, java.lang.String script)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_COPY_DESTINATION_DIR

public static final java.lang.String FILE_COPY_DESTINATION_DIR
See Also:
Constant Field Values
Constructor Detail

BaseFileCopier

public BaseFileCopier()
Method Detail

writeScriptTempFile

public static java.io.File writeScriptTempFile(ExecutionContext context,
                                               java.io.File original,
                                               java.io.InputStream input,
                                               java.lang.String script,
                                               INodeEntry node)
                                        throws FileCopierException
Copy a script file, script source stream, or script string into a temp file, and replace \ embedded tokens with values from the dataContext for the latter two. Marks the file as executable and delete-on-exit. This will not rewrite any content if the input is originally a file.

Parameters:
context - execution context
original - local system file, or null
input - input stream to write, or null
script - file content string, or null
node - destination node entry, to provide node data context
Returns:
temp file path
Throws:
ExecutionException - if an IO problem occurs
FileCopierException

appendRemoteFileExtensionForNode

public static java.lang.String appendRemoteFileExtensionForNode(INodeEntry node,
                                                                java.lang.String filepath)
Return a string with an appropriate script file extension appended if it is not already on the file path provided. The OS-family of the node determines the appropriate extension to use.

Parameters:
node - node destination
filepath - the file path string

getRemoteDirForNode

public static java.lang.String getRemoteDirForNode(INodeEntry node)
Return a remote destination temp dir path for the given node. If specified, the node attribute named "file-copy-destination-dir" is used, otherwise a temp directory appropriate for the os-family of the node is returned.

Parameters:
node - the node entry
Returns:
a path to destination dir for the node

generateRemoteFilepathForNode

public static java.lang.String generateRemoteFilepathForNode(INodeEntry node,
                                                             java.lang.String scriptfileName)
Return a temporary filepath for a file to be copied to the node, given the input filename (without directory path)

Parameters:
node - the destination node
scriptfileName - the name of the file to copy
Returns:
a filepath specifying destination of the file to copy that should be unique for the node and current date.

writeTempFile

protected static java.io.File writeTempFile(ExecutionContext context,
                                            java.io.File original,
                                            java.io.InputStream input,
                                            java.lang.String script)
                                     throws FileCopierException
Throws:
FileCopierException

writeLocalFile

protected static java.io.File writeLocalFile(java.io.File original,
                                             java.io.InputStream input,
                                             java.lang.String script,
                                             java.io.File destinationFile)
                                      throws FileCopierException
Throws:
FileCopierException