/xservices/trunk/src/java/net/brutex/xservices/ws/impl/DateServiceImpl.java |
---|
44,7 → 44,7 |
private static String ERR_INVALIDFORMAT = "Invalid format pattern."; |
private static String ERR_INVALIDTIMEZONE = "Invalid timezone."; |
@Override |
public GregorianCalendar getDate(String timezone) throws XServicesFault { |
if (! isValidTimezone(timezone) ) { |
String valid_ids = ""; |
60,7 → 60,7 |
return c; |
} |
@Override |
public BigInteger getTimestamp() { |
Date d = new Date(); |
long l = d.getTime(); |
68,7 → 68,7 |
return timestamp; |
} |
@Override |
public GregorianCalendar getInTimezone(GregorianCalendar cal, |
String timezone) throws XServicesFault { |
if(! isValidTimezone(timezone)) throw new XServicesFault(ERR_INVALIDTIMEZONE); |
77,12 → 77,12 |
return c; |
} |
@Override |
public String formatDate(GregorianCalendar cal, DateFormatType format) throws XServicesFault { |
return formatDateAdvanced(cal, format.format()); |
} |
@Override |
public String formatDateAdvanced(GregorianCalendar cal, String format) |
throws XServicesFault { |
String result= null; |
95,12 → 95,12 |
return result; |
} |
@Override |
public GregorianCalendar parseDate(String s, DateFormatType format, String timezone) throws XServicesFault { |
return parseDateAdvanced(s, format.format(), timezone); |
} |
@Override |
public GregorianCalendar parseDateAdvanced(String s, String format, String timezone) throws XServicesFault { |
SimpleDateFormat f = null; |
Date date = null; |
121,7 → 121,7 |
return cal; |
} |
@Override |
public BigInteger dateTimeDiff(GregorianCalendar fromCal, |
GregorianCalendar toCal) throws XServicesFault { |
long diff = toCal.getTimeInMillis() - fromCal.getTimeInMillis(); |
129,7 → 129,7 |
return d; |
} |
@Override |
public BigInteger dateTimeDiff2(GregorianCalendar fromCal, |
GregorianCalendar toCal, DateTimeUnits unit) throws XServicesFault { |
BigInteger d = dateTimeDiff(fromCal, toCal); |
149,7 → 149,7 |
return d; |
} |
@Override |
public GregorianCalendar dateAdd(GregorianCalendar cal, BigInteger value, DateTimeUnits unit) |
throws XServicesFault { |
switch (unit) { |
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/FileServiceImpl.java |
---|
64,7 → 64,7 |
* @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String, |
* java.lang.String) |
*/ |
@Override |
public String basename(String filename, String suffix) { |
final String BASENAME_VALUE = "basename.value"; |
Basename basename = new Basename(); |
139,7 → 139,7 |
* net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices |
* .types.FileSetResource) |
*/ |
@Override |
public AttachmentType downloadFile(FileResource res) throws XServicesFault { |
InputStream is = null; |
try { |
163,7 → 163,7 |
* net.brutex.xservices.ws.impl.FileService#base64Decode(net.brutex.xservices |
* .types.AttachmentType) |
*/ |
@Override |
public String uploadFile(AttachmentType file) throws XServicesFault { |
DataHandler h = file.getContent(); |
File f = new File(file.getFilename()); |
188,7 → 188,7 |
* net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types |
* .FileSetResource, java.lang.String, boolean, boolean, java.lang.String) |
*/ |
@Override |
public ReturnCode copy(FileSetResource src, String todir, boolean plm, |
boolean overwrite, String encoding) throws XServicesFault { |
Copy copy = new Copy(); |
213,7 → 213,7 |
return runner.postTask(); |
} |
@Override |
public ReturnCode copyFile(String fromFile, String tofile, boolean overwrite) |
throws XServicesFault { |
Copy copy = new Copy(); |
235,7 → 235,7 |
* net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices |
* .types.FileResource, java.lang.String) |
*/ |
@Override |
public String loadRes(FileResource res, String encoding) |
throws XServicesFault { |
if (encoding == null || encoding.equals("")) { |
259,7 → 259,7 |
* net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex |
* .xservices.types.ArchiveResource, java.lang.String) |
*/ |
@Override |
public String loadResFromArchive(ArchiveResource res, String encoding) { |
if (encoding == null || encoding.equals("")) { |
encoding = System.getProperty("file.encoding"); |
282,7 → 282,7 |
* @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String, |
* java.lang.String, java.lang.String, boolean) |
*/ |
@Override |
public ReturnCode echo2file(String message, String file, String encoding, |
boolean append) throws XServicesFault { |
316,7 → 316,7 |
* net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices |
* .types.FileSetResource, java.lang.String) |
*/ |
@Override |
public ReturnCode changeOwner(FileSetResource res, String owner) { |
Chown chown = new Chown(); |
chown.setTaskName("Chown"); |
335,7 → 335,7 |
* net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices |
* .types.FileSetResource, java.lang.String) |
*/ |
@Override |
public ReturnCode changeGroup(FileSetResource res, String group) { |
Chgrp chgrp = new Chgrp(); |
chgrp.setTaskName("Chgrp"); |
354,7 → 354,7 |
* net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices |
* .types.FileSetResource, java.lang.String) |
*/ |
@Override |
public ReturnCode changeMode(FileSetResource res, String perm) { |
Chmod chmod = new Chmod(); |
chmod.setTaskName("Chmod"); |
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/ArchiveServiceImpl.java |
---|
22,9 → 22,7 |
import net.brutex.xservices.types.ArchiveResource; |
import net.brutex.xservices.types.CompressionType; |
import net.brutex.xservices.types.FileResource; |
import net.brutex.xservices.types.FileSetResource; |
import net.brutex.xservices.types.ResourceInterface; |
import net.brutex.xservices.types.ResourceSetInterface; |
import net.brutex.xservices.types.ReturnCode; |
import net.brutex.xservices.util.BrutexNamespaces; |
import net.brutex.xservices.util.RunTask; |
52,7 → 50,6 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#bzip2(net.brutex.xservices.types.FileResource, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2) |
public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
62,7 → 59,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#bzip2FromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE) |
public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
72,7 → 69,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#gzip(net.brutex.xservices.types.FileResource, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP) |
public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
82,7 → 79,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#gzipFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE) |
public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
92,7 → 89,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#gunzip(java.lang.String, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP) |
public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
106,7 → 103,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#bunzip2(java.lang.String, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = WS_OPERATION_BUNZIP2) |
public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
120,7 → 117,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#gunzipFromURL(java.lang.String, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = "gunzipFromURL") |
public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
134,7 → 131,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#bunzip2FromURL(java.lang.String, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = "bunzip2FromURL") |
public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
148,7 → 145,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#zip(net.brutex.xservices.types.FileResource, java.lang.String, boolean, java.lang.String, int) |
*/ |
@Override |
@WebMethod(operationName = "zip") |
public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file, |
167,7 → 164,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#zipFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String, boolean, java.lang.String, int) |
*/ |
@Override |
@WebMethod(operationName = "zipFromArchive") |
public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file, |
180,7 → 177,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#unzip(java.lang.String, java.lang.String, boolean, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = "unzip") |
public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest, |
192,7 → 189,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#unrar(java.lang.String, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = "unrar") |
public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
202,7 → 199,7 |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.ArchiveService#untar(java.lang.String, java.lang.String, boolean, net.brutex.xservices.types.CompressionType) |
*/ |
@Override |
@WebMethod(operationName = "untar") |
public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest, |
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/ExecuteServiceImpl.java |
---|
17,6 → 17,8 |
package net.brutex.xservices.ws.impl; |
import java.io.File; |
import java.util.UUID; |
import javax.jws.WebMethod; |
import javax.jws.WebParam; |
import javax.jws.WebService; |
23,8 → 25,10 |
import net.brutex.xservices.types.HostConnection; |
import net.brutex.xservices.types.ReturnCode; |
import net.brutex.xservices.util.BrutexNamespaces; |
import net.brutex.xservices.util.JobWrapper; |
import net.brutex.xservices.util.RunTask; |
import net.brutex.xservices.ws.ExecuteService; |
import net.brutex.xservices.ws.XServicesFault; |
import org.apache.tools.ant.taskdefs.ExecTask; |
import org.apache.tools.ant.taskdefs.optional.net.RExecTask; |
31,136 → 35,157 |
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask; |
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec; |
import org.apache.tools.ant.types.Commandline; |
import org.mozilla.javascript.Context; |
import org.mozilla.javascript.Scriptable; |
import org.quartz.JobBuilder; |
import org.quartz.JobDetail; |
import org.quartz.Scheduler; |
import org.quartz.SchedulerException; |
import org.quartz.Trigger; |
import static org.quartz.TriggerBuilder.*; |
import static org.quartz.SimpleScheduleBuilder.*; |
import org.quartz.TriggerUtils; |
import org.quartz.impl.StdSchedulerFactory; |
import org.quartz.impl.triggers.SimpleTriggerImpl; |
/** |
* |
* @author Brian Rosenberger, bru@brutex.de |
*/ |
@WebService( |
targetNamespace=BrutexNamespaces.WS_XSERVICES, |
endpointInterface="net.brutex.xservices.ws.ExecuteService", |
serviceName="ExecuteService" |
) |
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.ExecuteService", serviceName = "ExecuteService") |
public class ExecuteServiceImpl implements ExecuteService { |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String, java.lang.String, long) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String, |
* java.lang.String, long) |
*/ |
@Override |
@WebMethod(operationName = "runCommand") |
public ReturnCode runCommand(@WebParam(name = "executable") String cmd, |
@WebParam(name = "argline") String args, |
@WebParam(name = "timeout") long timeout) { |
return executeCommand(cmd, |
Commandline.translateCommandline(args), |
null, |
false, |
null, |
false, |
true, |
false, |
timeout); |
return executeCommand(cmd, Commandline.translateCommandline(args), |
null, false, null, false, true, false, timeout); |
} |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang.String, java.lang.String[], long) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang |
* .String, java.lang.String[], long) |
*/ |
@Override |
@WebMethod(operationName = "runCommandWithArgs") |
public ReturnCode runCommandWithArgs(@WebParam(name = "executable") String cmd, |
public ReturnCode runCommandWithArgs( |
@WebParam(name = "executable") String cmd, |
@WebParam(name = "arg") String[] args, |
@WebParam(name = "timeout") long timeout) { |
return executeCommand(cmd, |
args, |
null, |
false, |
null, |
false, |
true, |
false, |
return executeCommand(cmd, args, null, false, null, false, true, false, |
timeout); |
} |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang.String, java.lang.String) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang |
* .String, java.lang.String) |
*/ |
@Override |
@WebMethod(operationName = "runCommandAsync") |
public ReturnCode runCommandAsync(@WebParam(name = "executable") String cmd, |
public ReturnCode runCommandAsync( |
@WebParam(name = "executable") String cmd, |
@WebParam(name = "argline") String args) { |
return executeCommand(cmd, |
Commandline.translateCommandline(args), |
null, |
true, |
null, |
false, |
true, |
false, |
0); |
return executeCommand(cmd, Commandline.translateCommandline(args), |
null, true, null, false, true, false, 0); |
} |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java.lang.String, java.lang.String[]) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java |
* .lang.String, java.lang.String[]) |
*/ |
@Override |
@WebMethod(operationName = "runCommandAsyncWithArgs") |
public ReturnCode runCommandAsyncWithArgs(@WebParam(name = "executable") String cmd, |
public ReturnCode runCommandAsyncWithArgs( |
@WebParam(name = "executable") String cmd, |
@WebParam(name = "arg") String[] args) { |
return executeCommand(cmd, |
args, |
null, |
true, |
null, |
false, |
true, |
false, |
return executeCommand(cmd, args, null, true, null, false, true, false, |
0); |
} |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, long) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang |
* .String, int, java.lang.String, java.lang.String, java.lang.String, long) |
*/ |
@Override |
@WebMethod(operationName = "runCommandWithSSH") |
public ReturnCode runCommandWithSSH(@WebParam(name = "host") HostConnection host, |
public ReturnCode runCommandWithSSH( |
@WebParam(name = "host") HostConnection host, |
@WebParam(name = "command") String cmd, |
@WebParam(name = "timeout") long timeout) { |
return sshExec(host.hostname, host.user, host.password, host.port, cmd, timeout); |
return sshExec(host.hostname, host.user, host.password, host.port, cmd, |
timeout); |
} |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, java.lang.String, long) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth( |
* java.lang.String, int, java.lang.String, java.lang.String, |
* java.lang.String, java.lang.String, long) |
*/ |
@Override |
@WebMethod(operationName = "runCommandWithSSHKeyAuth") |
public ReturnCode runCommandWithSSHKeyAuth(@WebParam(name = "host") HostConnection host, |
public ReturnCode runCommandWithSSHKeyAuth( |
@WebParam(name = "host") HostConnection host, |
@WebParam(name = "keyfile") String keyfile, |
@WebParam(name = "command") String cmd, |
@WebParam(name = "timeout") long timeout) { |
return sshExecWithCert(host.hostname, host.user, host.password, keyfile, host.port, cmd, timeout); |
return sshExecWithCert(host.hostname, host.user, host.password, |
keyfile, host.port, cmd, timeout); |
} |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices.types.HostConnection, java.lang.String, long) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices |
* .types.HostConnection, java.lang.String, long) |
*/ |
@Override |
@WebMethod(operationName = "rExec") |
public ReturnCode rExec(@WebParam(name = "host") HostConnection host, |
@WebParam(name = "command") String cmd, |
@WebParam(name = "timeout") long timeout) { |
return rexec(host.hostname, host.port, host.user, host.password, cmd, timeout); |
return rexec(host.hostname, host.port, host.user, host.password, cmd, |
timeout); |
} |
/* (non-Javadoc) |
* @see net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices.types.HostConnection, java.lang.String, java.lang.String, java.lang.String, long) |
/* |
* (non-Javadoc) |
* |
* @see |
* net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices |
* .types.HostConnection, java.lang.String, java.lang.String, |
* java.lang.String, long) |
*/ |
@Override |
@WebMethod(operationName = "telnet") |
public ReturnCode runTelnet(@WebParam(name = "host") HostConnection host, |
@WebParam(name = "prompt") String prompt, |
167,27 → 192,73 |
@WebParam(name = "command") String cmd, |
@WebParam(name = "expect") String expect, |
@WebParam(name = "timeout") long timeout) { |
return telnet(host.hostname, host.port, host.user, host.password, cmd, timeout, prompt, expect); |
return telnet(host.hostname, host.port, host.user, host.password, cmd, |
timeout, prompt, expect); |
} |
public void runJScript(String script) throws XServicesFault { |
try { |
// Create and enter a Context. A Context stores information about |
// the execution environment of a script. |
Context cx = Context.enter(); |
cx.setOptimizationLevel(0); |
cx.setLanguageVersion(Context.VERSION_1_7); |
// cx is the Context instance you're using to run scripts |
/* |
* cx.setClassShutter(new ClassShutter() { public boolean |
* visibleToScripts(String className) { |
* if(className.startsWith("adapter")) return true; |
* if(className.startsWith("java.lang.System") || |
* className.startsWith |
* ("org.apache.tomcat.util.log.SystemLogHandler")) return true; |
* System.out.println(className + " is blocked."); return false; } |
* }); |
*/ |
// Initialise the standard objects (Object, Function, etc.). This |
// must be done before scripts can be |
// executed. The null parameter tells initStandardObjects |
// to create and return a scope object that we use |
// in later calls. |
Scriptable scope = cx.initStandardObjects(); |
// Object wrappedOut = Context.javaToJS(System.out, scope); |
// Object wrappedOut2 = Context.javaToJS(this, scope); |
// scope.put("out", scope, wrappedOut); |
// scope.put("exe", scope, wrappedOut2); |
// Execute the script |
// cx.evaluateString(scope, "importClass('java.lang.System');\n", |
// "head", 1, null); |
// cx.evaluateString(scope, "importPackage('java.util');\n", "head", |
// 2, null); |
Object obj = cx |
.evaluateString(scope, script, "TestScript", 1, null); |
} catch (Exception e) { |
System.out.println(e.getMessage()); |
} finally { |
// Exit the Context. This removes the association between the |
// Context and the current thread and is an |
// essential cleanup action. There should be a call to exit for |
// every call to enter. |
Context.exit(); |
} |
} |
@WebMethod(exclude = true) |
private ReturnCode executeCommand(String executable, |
String[] args, |
File dir, |
boolean spawn, |
String inputstring, |
boolean newenvironment, |
boolean vmlauncher, |
boolean searchpath, |
private ReturnCode executeCommand(String executable, String[] args, |
File dir, boolean spawn, String inputstring, |
boolean newenvironment, boolean vmlauncher, boolean searchpath, |
long timeout) { |
ExecTask exe = new ExecTask(); |
RunTask runner = new RunTask(exe); |
/* |
Commandline cmdl = new Commandline(); |
cmdl.setExecutable(executable); |
cmdl.addArguments(args); |
System.out.println(cmdl.describeCommand()); |
* Commandline cmdl = new Commandline(); cmdl.setExecutable(executable); |
* cmdl.addArguments(args); System.out.println(cmdl.describeCommand()); |
*/ |
exe.setExecutable(executable); |
214,12 → 285,8 |
} |
@WebMethod(exclude = true) |
private ReturnCode sshExec(String host, |
String username, |
String password, |
int port, |
String command, |
long timeout) { |
private ReturnCode sshExec(String host, String username, String password, |
int port, String command, long timeout) { |
SSHExec sshexec = new SSHExec(); |
RunTask runner = new RunTask(sshexec); |
sshexec.setHost(host); |
234,12 → 301,8 |
} |
@WebMethod(exclude = true) |
private ReturnCode sshExecWithCert(String host, |
String username, |
String passphrase, |
String keyfile, |
int port, |
String command, |
private ReturnCode sshExecWithCert(String host, String username, |
String passphrase, String keyfile, int port, String command, |
long timeout) { |
SSHExec sshexec = new SSHExec(); |
RunTask runner = new RunTask(sshexec); |
256,12 → 319,8 |
} |
@WebMethod(exclude = true) |
private ReturnCode rexec(String host, |
int port, |
String username, |
String password, |
String command, |
long timeout) { |
private ReturnCode rexec(String host, int port, String username, |
String password, String command, long timeout) { |
RExecTask rexec = new RExecTask(); |
RunTask runner = new RunTask(rexec); |
rexec.setServer(host); |
275,12 → 334,9 |
} |
@WebMethod(exclude = true) |
private ReturnCode telnet(String host, |
int port, |
String username, |
String password, |
String command, |
long timeout, String prompt, String expect) { |
private ReturnCode telnet(String host, int port, String username, |
String password, String command, long timeout, String prompt, |
String expect) { |
TelnetTask rexec = new TelnetTask(); |
RunTask runner = new RunTask(rexec); |
rexec.setServer(host); |
/xservices/trunk/src/java/net/brutex/xservices/ws/impl/JobServiceImpl.java |
---|
0,0 → 1,151 |
/* |
* Copyright 2011 Brian Rosenberger (Brutex Network) |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* See the License for the specific language governing permissions and |
* limitations under the License. |
*/ |
package net.brutex.xservices.ws.impl; |
import static org.quartz.TriggerBuilder.newTrigger; |
import java.util.ArrayList; |
import java.util.GregorianCalendar; |
import java.util.List; |
import java.util.Set; |
import java.util.TimeZone; |
import java.util.UUID; |
import javax.jws.WebService; |
import org.quartz.JobBuilder; |
import org.quartz.JobDataMap; |
import org.quartz.JobDetail; |
import org.quartz.JobKey; |
import org.quartz.Scheduler; |
import org.quartz.SchedulerException; |
import org.quartz.SimpleTrigger; |
import org.quartz.Trigger; |
import org.quartz.TriggerKey; |
import org.quartz.impl.StdSchedulerFactory; |
import org.quartz.impl.matchers.GroupMatcher; |
import net.brutex.xservices.types.ScheduledJob; |
import net.brutex.xservices.util.BrutexNamespaces; |
import net.brutex.xservices.util.JobWrapper; |
import net.brutex.xservices.ws.JobService; |
import net.brutex.xservices.ws.XServicesFault; |
/** |
* @author Brian Rosenberger |
* @since 0.5.0 |
* |
*/ |
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.JobService", serviceName = JobService.SERVICE_NAME) |
public class JobServiceImpl implements JobService { |
public List<ScheduledJob> getJobList() throws XServicesFault { |
List<ScheduledJob> joblist = new ArrayList<ScheduledJob>(); |
try { |
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); |
List<String> jobgroups = scheduler.getJobGroupNames(); |
for (String g : jobgroups) { |
GroupMatcher m = GroupMatcher.groupContains(g); |
Set<JobKey> keyset = scheduler.getJobKeys(m); |
for (JobKey key : keyset) { |
JobDataMap detail = scheduler.getJobDetail(key) |
.getJobDataMap(); |
ScheduledJob job = new ScheduledJob(key.getName(), |
(GregorianCalendar) detail.get("date"), |
detail.getString("script")); |
joblist.add(job); |
} |
} |
} catch (SchedulerException e) { |
throw new XServicesFault(e); |
} |
return joblist; |
} |
public ScheduledJob getJob(String uuid) throws XServicesFault { |
try { |
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); |
JobDetail job = scheduler.getJobDetail(new JobKey(uuid, "DEFAULT")); |
if (job == null) |
throw new XServicesFault("Job not found."); |
Trigger t = scheduler.getTrigger(new TriggerKey(uuid)); |
GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault()); |
cal.setTime(t.getStartTime()); |
return new ScheduledJob(uuid, cal, job.getJobDataMap().getString( |
"script"), job.getDescription()); |
} catch (SchedulerException e) { |
e.printStackTrace(); |
throw new XServicesFault(e); |
} |
} |
public void deleteJob(String uuid) throws XServicesFault { |
try { |
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); |
JobKey key = new JobKey(uuid, "DEFAULT"); |
JobDetail job = scheduler.getJobDetail(key); |
if (job == null) |
throw new XServicesFault("Job not found."); |
Trigger t = scheduler.getTrigger(new TriggerKey(uuid)); |
scheduler.deleteJob(key); |
} catch (SchedulerException e) { |
throw new XServicesFault(e); |
} |
} |
public String scheduleJob(ScheduledJob job) throws XServicesFault { |
try { |
// Grab the Scheduler instance from the Factory |
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); |
// and start it off |
if (!scheduler.isStarted()) |
scheduler.start(); |
if (scheduler.isInStandbyMode()) |
scheduler.resumeAll(); |
String identity = UUID.randomUUID().toString(); |
//String identity = "test"; |
JobDetail job2 = JobBuilder.newJob(JobWrapper.class) |
.withIdentity(identity).build(); |
job2.getJobDataMap().put("script", job.getScript()); |
job2.getJobDataMap().put("description", job.getDescription()); |
job2.getJobDataMap().put("date", job.getDate()); |
SimpleTrigger t = (SimpleTrigger) newTrigger() |
.withIdentity(identity).startAt(job.getDate().getTime()) |
.build(); |
; |
scheduler.scheduleJob(job2, t); |
return identity; |
} catch (SchedulerException e) { |
e.printStackTrace(); |
throw new XServicesFault(e); |
} |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |