Groovy Documentation

org.linkedin.glu.agent.impl.capabilities
[Groovy] Class ShellImpl

java.lang.Object
  org.linkedin.glu.agent.impl.capabilities.ShellImpl

class ShellImpl

contains the utility methods for the shell

Authors:
ypujante@linkedin.com


Field Summary
static java.lang.String MODULE

static java.lang.Object log

 
Property Summary
AgentProperties agentProperties

java.lang.Object charset

The charset to use for reading/writing files

Clock clock

java.io.FileSystem fileSystem

 
Method Summary
java.lang.Object ant(groovy.lang.Closure closure)

Exporting ant access to the shell

java.lang.String cat(java.lang.Object location)

Returns the content of the location as a String or null if the location is not reachable

Resource chmod(java.lang.Object file, java.lang.Object perm)

Change the permission of the file

Resource chmodPlusX(java.lang.Object file)

Shortcut/More efficient implementation of the more generic {@link #chmod(Object, Object) call

Resource chmodRecursive(java.lang.Object dir, java.lang.Object perm)

java.lang.Object demultiplexExecStream(java.io.InputStream execStream, java.io.OutputStream stdout, java.io.OutputStream stderr)

@{inheritDoc}

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.String exec(java.lang.String command)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.String exec(java.util.Collection command)

Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.

java.lang.Object exec(java.util.Map args)

@{inheritDoc}

void fail(java.lang.Object message)

Calling this method will force a script failure

Resource fetch(java.lang.Object location)

Fetches the file pointed to by the location.

Resource fetch(java.lang.Object location, java.lang.Object destination)

Fetches the file pointed to by the location.

java.lang.String fetchContent(java.lang.Object location)

Fetches the content of the location and returns it as a String or null if the location is not reachable

java.util.Map getEnv()

java.util.Collection getMimeTypes(java.lang.Object file)

Submitter getSubmitter()

java.util.Collection grep(java.lang.Object location, java.lang.Object pattern)

Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern.

java.lang.Object grep(java.lang.Object location, java.lang.Object pattern, java.lang.Object options)

Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern

Resource gunzip(java.lang.Object file)

Uncompresses the provided file

Resource gunzip(java.lang.Object file, java.lang.Object toFile)

Uncompresses the provided file (if compressed) into a new file

Resource gzip(java.lang.Object file)

Compresses the provided file (first make sure that the file is compressed)

Resource gzip(java.lang.Object file, java.lang.Object toFile)

Compresses the provided file (first make sure that the file is compressed)

java.util.Map gzipFileOrFolder(java.lang.Object fileOrFolder, boolean recurse)

Compresses each file in a folder

java.util.Map httpHead(java.lang.Object location)

Issue a 'HEAD' request.

java.util.Map httpPost(java.lang.Object location, java.util.Map parameters)

Issue a 'POST' request.

boolean listening(java.lang.Object server, java.lang.Object port)

@return true if there is a socket open on the server/port combination

Shell newShell(java.lang.Object fileSystem)

java.lang.Object noException(groovy.lang.Closure closure)

Runs the closure in a protected block that will not throw an exception but will return null in the case one happens

java.lang.String replaceTokens(java.lang.String input, java.util.Map tokens)

Replaces the tokens provided in the map in the input.

Resource replaceTokens(java.lang.Object from, java.lang.Object to, java.util.Map tokens)

Processes from through the replacement token mechanism and writes the result to to

Resource saveContent(java.lang.Object file, java.lang.String content, java.util.Map tokens)

Processes the content to the token replacement method.

void setSubmitter(Submitter submitter)

java.io.InputStream tail(java.lang.Object location, long maxLine)

Tail the location

java.io.InputStream tail(java.lang.Object args)

Tail the location

protected java.io.InputStream toInputStream(java.lang.Object stream)

protected java.lang.String toStringCommandLine(java.lang.Object commandLine)

Make sure that the command line is a string.

protected java.lang.Object toStringOutput(byte[] output)

Converts the output into a string.

Resource untar(java.lang.Object file)

Resource untar(java.lang.Object file, java.lang.Object toDir)

Resource untarAndDecrypt(java.lang.Object file, java.lang.Object toDir, java.lang.Object encryptionKeys)

Resource unzip(java.lang.Object file)

Resource unzip(java.lang.Object file, java.lang.Object toDir)

boolean waitFor(java.lang.Object args, groovy.lang.Closure condition)

Waits for the condition to be true no longer than the timeout.

boolean waitFor(groovy.lang.Closure condition)

Waits for the condition to be true no longer than the timeout.

java.lang.Object withMBeanServerConnection(java.lang.Object pid, groovy.lang.Closure closure)

Invokes the closure with an MBeanServerConnection to the jmx control running on the vm started with the provided pid.

java.lang.Object withReader(java.lang.Object file, groovy.lang.Closure closure)

Same as withInputStream but wraps in a reader using the charset

java.lang.Object withWriter(java.lang.Object file, groovy.lang.Closure closure)

Same as withOutputStream but wraps in a writer using the charset

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

MODULE

public static final java.lang.String MODULE


log

public static final java.lang.Object log


 
Property Detail

agentProperties

AgentProperties agentProperties


charset

java.lang.Object charset
The charset to use for reading/writing files


clock

Clock clock


fileSystem

@Delegate
java.io.FileSystem fileSystem


 
Method Detail

ant

java.lang.Object ant(groovy.lang.Closure closure)
Exporting ant access to the shell


cat

java.lang.String cat(java.lang.Object location)
Returns the content of the location as a String or null if the location is not reachable


chmod

Resource chmod(java.lang.Object file, java.lang.Object perm)
Change the permission of the file


chmodPlusX

Resource chmodPlusX(java.lang.Object file)
Shortcut/More efficient implementation of the more generic {
link:
#chmod(Object, Object) call


chmodRecursive

Resource chmodRecursive(java.lang.Object dir, java.lang.Object perm)


demultiplexExecStream

java.lang.Object demultiplexExecStream(java.io.InputStream execStream, java.io.OutputStream stdout, java.io.OutputStream stderr)
@{inheritDoc}


exec

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.


exec

java.lang.String exec(java.lang.Object executable, java.lang.Object executableArgs)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.


exec

java.lang.String exec(java.lang.String command)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.


exec

java.lang.String exec(java.util.Collection command)
Executes a shell command... the command will be delegated straight to shell and the output of the shell command is returned.


exec

java.lang.Object exec(java.util.Map args)
@{inheritDoc}


fail

void fail(java.lang.Object message)
Calling this method will force a script failure


fetch

Resource fetch(java.lang.Object location)
Fetches the file pointed to by the location. The location can be File, a String or URI and must contain a scheme. Example of locations: http://locahost:8080/file.txt', file:/tmp/file.txt, ivy:/org.linkedin/util-core/1.0.0.


fetch

Resource fetch(java.lang.Object location, java.lang.Object destination)
Fetches the file pointed to by the location. The location can be File, a String or URI and must contain a scheme. Example of locations: http://locahost:8080/file.txt', file:/tmp/file.txt, ivy:/org.linkedin/util-core/1.0.0. The difference with the other fetch method is that it fetches the file in the provided destination rather than in the tmp space.


fetchContent

java.lang.String fetchContent(java.lang.Object location)
Fetches the content of the location and returns it as a String or null if the location is not reachable
deprecated:
use {@link #cat(Object) instead


getEnv

java.util.Map getEnv()


getMimeTypes

java.util.Collection getMimeTypes(java.lang.Object file)


getSubmitter

Submitter getSubmitter()


grep

java.util.Collection grep(java.lang.Object location, java.lang.Object pattern)
Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern.


grep

java.lang.Object grep(java.lang.Object location, java.lang.Object pattern, java.lang.Object options)
Similarly to the unix grep command, checks the location one line at a time and returns all the lines which matches the pattern
Parameters:
options - options to the command: out: an object to output the lines which match (default to []) count: returns the count only (does not use out) maxCount: stop reading after maxCount matches


gunzip

Resource gunzip(java.lang.Object file)
Uncompresses the provided file
Returns:
the original file or the new one


gunzip

Resource gunzip(java.lang.Object file, java.lang.Object toFile)
Uncompresses the provided file (if compressed) into a new file


gzip

Resource gzip(java.lang.Object file)
Compresses the provided file (first make sure that the file is compressed)
Returns:
the gziped file or the original file if not zipped


gzip

Resource gzip(java.lang.Object file, java.lang.Object toFile)
Compresses the provided file (first make sure that the file is compressed)
Returns:
the gziped file or the original file if not zipped


gzipFileOrFolder

java.util.Map gzipFileOrFolder(java.lang.Object fileOrFolder, boolean recurse)
Compresses each file in a folder
Parameters:
fileOrFolder - a file (behaves like gzip(Object)) or a folder
recurse - if true then recursively process all folders
Returns:
a map with key is resource and value is delta in size (original - new) (note that it contains only the resources that are modified!)


httpHead

java.util.Map httpHead(java.lang.Object location)
Issue a 'HEAD' request. The location should be an http or https link.
Parameters:
location
Returns:
a map with the following entries: responseCode: 200, 404... java.net.HttpURLConnection#getResponseCode() responseMessage: message java.net.HttpURLConnection#getResponseMessage() headers: representing all the headers java.net.URLConnection#getHeaderFields()


httpPost

java.util.Map httpPost(java.lang.Object location, java.util.Map parameters)
Issue a 'POST' request. The location should be an http or https link. The request will be made with application/x-www-form-urlencoded content type.
Parameters:
location
parameters - the parameters of the post as map of key value pairs (value can be a single value or a collection of values)
Returns:
a map with the following entries: responseCode: 200, 404... java.net.HttpURLConnection#getResponseCode() responseMessage: message java.net.HttpURLConnection#getResponseMessage() headers: representing all the headers java.net.URLConnection#getHeaderFields()


listening

boolean listening(java.lang.Object server, java.lang.Object port)
Returns:
true if there is a socket open on the server/port combination


newShell

Shell newShell(java.lang.Object fileSystem)


noException

java.lang.Object noException(groovy.lang.Closure closure)
Runs the closure in a protected block that will not throw an exception but will return null in the case one happens


replaceTokens

java.lang.String replaceTokens(java.lang.String input, java.util.Map tokens)
Replaces the tokens provided in the map in the input. Token replacement is using ant token replacement class so in the input, the tokens are surrounded by the '@' sign. Example:
 input = "abcd @myToken@"
 assert "abcd foo" == replaceTokens(input, [myToken: 'foo'])
 


replaceTokens

Resource replaceTokens(java.lang.Object from, java.lang.Object to, java.util.Map tokens)
Processes from through the replacement token mechanism and writes the result to to
Parameters:
from - anything that can be provided to java.io.FileSystem#toResource(java.lang.Object)
to - anything that can be provided to java.io.FileSystem#toResource(java.lang.Object)
tokens - a map of token
Returns:
to as a Resource
See Also:
replaceTokens(String, Map)


saveContent

Resource saveContent(java.lang.Object file, java.lang.String content, java.util.Map tokens)
Processes the content to the token replacement method.
See Also:
java.io.FileSystem#saveContent(java.lang.Object, java.lang.String)


setSubmitter

void setSubmitter(Submitter submitter)


tail

java.io.InputStream tail(java.lang.Object location, long maxLine)
Tail the location
params:
location the location of the file to tail
params:
maxLine the number of lines maximum to read
Returns:
the input stream to read the content of the tail


tail

java.io.InputStream tail(java.lang.Object args)
Tail the location
params:
args.location the location of the file to tail
params:
args.maxLine the number of lines maximum to read (-1 for the entire file)
params:
args.maxSize the maximum size to read (-1 for the entire file)
Returns:
the input stream to read the content of the tail


toInputStream

protected java.io.InputStream toInputStream(java.lang.Object stream)


toStringCommandLine

protected java.lang.String toStringCommandLine(java.lang.Object commandLine)
Make sure that the command line is a string.


toStringOutput

protected java.lang.Object toStringOutput(byte[] output)
Converts the output into a string. Assumes that the encoding is UTF-8. Replaces all line feeds by '\n' and remove the last line feed.


untar

Resource untar(java.lang.Object file)


untar

Resource untar(java.lang.Object file, java.lang.Object toDir)


untarAndDecrypt

Resource untarAndDecrypt(java.lang.Object file, java.lang.Object toDir, java.lang.Object encryptionKeys)


unzip

Resource unzip(java.lang.Object file)


unzip

Resource unzip(java.lang.Object file, java.lang.Object toDir)


waitFor

boolean waitFor(java.lang.Object args, groovy.lang.Closure condition)
Waits for the condition to be true no longer than the timeout. true is returned if the condition was satisfied, false otherwise (if you specify noException)
Parameters:
args.timeout - how long max to wait
args.heartbeat - how long to wait between calling the condition
args.noException - to get false instead of an exception


waitFor

boolean waitFor(groovy.lang.Closure condition)
Waits for the condition to be true no longer than the timeout. true is returned if the condition was satisfied, false otherwise


withMBeanServerConnection

java.lang.Object withMBeanServerConnection(java.lang.Object pid, groovy.lang.Closure closure)
Invokes the closure with an MBeanServerConnection to the jmx control running on the vm started with the provided pid. The closure will be invoked with null if cannot determine the process.


withReader

java.lang.Object withReader(java.lang.Object file, groovy.lang.Closure closure)
Same as withInputStream but wraps in a reader using the charset
Parameters:
file - anything that can be provided to java.io.FileSystem#toResource(java.lang.Object)
Returns:
whatever the closure returns


withWriter

java.lang.Object withWriter(java.lang.Object file, groovy.lang.Closure closure)
Same as withOutputStream but wraps in a writer using the charset
Parameters:
file - anything that can be provided to java.io.FileSystem#toResource(java.lang.Object)
Returns:
whatever the closure returns


 

Groovy Documentation