Subversion Repositories XServices

Rev

Rev 58 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 58 Rev 70
Line 15... Line 15...
15
 */
15
 */
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
package net.brutex.xservices.ws.impl;
17
package net.brutex.xservices.ws.impl;
-
 
18
 
-
 
19
import java.io.File;
18
 
20
import java.util.UUID;
19
import java.io.File;
21
 
20
import javax.jws.WebMethod;
22
import javax.jws.WebMethod;
21
import javax.jws.WebParam;
23
import javax.jws.WebParam;
22
import javax.jws.WebService;
24
import javax.jws.WebService;
23
import net.brutex.xservices.types.HostConnection;
25
import net.brutex.xservices.types.HostConnection;
-
 
26
import net.brutex.xservices.types.ReturnCode;
24
import net.brutex.xservices.types.ReturnCode;
27
import net.brutex.xservices.util.BrutexNamespaces;
25
import net.brutex.xservices.util.BrutexNamespaces;
28
import net.brutex.xservices.util.JobWrapper;
-
 
29
import net.brutex.xservices.util.RunTask;
Line 26... Line 30...
26
import net.brutex.xservices.util.RunTask;
30
import net.brutex.xservices.ws.ExecuteService;
27
import net.brutex.xservices.ws.ExecuteService;
31
import net.brutex.xservices.ws.XServicesFault;
28
 
32
 
29
import org.apache.tools.ant.taskdefs.ExecTask;
33
import org.apache.tools.ant.taskdefs.ExecTask;
30
import org.apache.tools.ant.taskdefs.optional.net.RExecTask;
34
import org.apache.tools.ant.taskdefs.optional.net.RExecTask;
-
 
35
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
-
 
36
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
-
 
37
import org.apache.tools.ant.types.Commandline;
-
 
38
import org.mozilla.javascript.Context;
-
 
39
import org.mozilla.javascript.Scriptable;
-
 
40
import org.quartz.JobBuilder;
-
 
41
import org.quartz.JobDetail;
-
 
42
import org.quartz.Scheduler;
-
 
43
import org.quartz.SchedulerException;
-
 
44
import org.quartz.Trigger;
-
 
45
import static org.quartz.TriggerBuilder.*;
-
 
46
import static org.quartz.SimpleScheduleBuilder.*;
Line 31... Line 47...
31
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
47
import org.quartz.TriggerUtils;
32
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
48
import org.quartz.impl.StdSchedulerFactory;
33
import org.apache.tools.ant.types.Commandline;
49
import org.quartz.impl.triggers.SimpleTriggerImpl;
34
 
50
 
35
/**
-
 
36
 *
-
 
37
 * @author Brian Rosenberger, bru@brutex.de
51
/**
38
 */
-
 
39
@WebService(
-
 
40
		targetNamespace=BrutexNamespaces.WS_XSERVICES, 
52
 * 
Line -... Line 53...
-
 
53
 * @author Brian Rosenberger, bru@brutex.de
41
		endpointInterface="net.brutex.xservices.ws.ExecuteService",
54
 */
-
 
55
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.ExecuteService", serviceName = "ExecuteService")
-
 
56
public class ExecuteServiceImpl implements ExecuteService {
42
		serviceName="ExecuteService"
57
 
-
 
58
	/*
43
			)
59
	 * (non-Javadoc)
44
public class ExecuteServiceImpl implements ExecuteService {
-
 
45
 
60
	 * 
46
    /* (non-Javadoc)
61
	 * @see
47
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String, java.lang.String, long)
62
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String,
48
	 */
63
	 * java.lang.String, long)
49
    @Override
64
	 */
50
	@WebMethod(operationName = "runCommand")
-
 
51
    public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
65
	@WebMethod(operationName = "runCommand")
52
            @WebParam(name = "argline") String args,
-
 
53
            @WebParam(name = "timeout") long timeout) {
-
 
54
 
-
 
55
        return executeCommand(cmd,
-
 
56
                Commandline.translateCommandline(args),
-
 
57
                null,
-
 
58
                false,
66
	public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
59
                null,
67
			@WebParam(name = "argline") String args,
60
                false,
68
			@WebParam(name = "timeout") long timeout) {
-
 
69
 
61
                true,
70
		return executeCommand(cmd, Commandline.translateCommandline(args),
-
 
71
				null, false, null, false, true, false, timeout);
-
 
72
	}
62
                false,
73
 
-
 
74
	/*
63
                timeout);
75
	 * (non-Javadoc)
64
    }
76
	 * 
65
 
77
	 * @see
-
 
78
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang
66
    /* (non-Javadoc)
79
	 * .String, java.lang.String[], long)
67
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang.String, java.lang.String[], long)
80
	 */
68
	 */
81
	
69
    @Override
82
	@WebMethod(operationName = "runCommandWithArgs")
70
	@WebMethod(operationName = "runCommandWithArgs")
83
	public ReturnCode runCommandWithArgs(
71
    public ReturnCode runCommandWithArgs(@WebParam(name = "executable") String cmd,
-
 
72
            @WebParam(name = "arg") String[] args,
-
 
73
            @WebParam(name = "timeout") long timeout) {
-
 
74
 
-
 
75
        return executeCommand(cmd,
-
 
76
                args,
-
 
77
                null,
-
 
78
                false,
84
			@WebParam(name = "executable") String cmd,
79
                null,
85
			@WebParam(name = "arg") String[] args,
80
                false,
86
			@WebParam(name = "timeout") long timeout) {
-
 
87
 
81
                true,
88
		return executeCommand(cmd, args, null, false, null, false, true, false,
-
 
89
				timeout);
-
 
90
	}
82
                false,
91
 
-
 
92
	/*
83
                timeout);
93
	 * (non-Javadoc)
84
    }
94
	 * 
85
 
95
	 * @see
-
 
96
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang
86
    /* (non-Javadoc)
97
	 * .String, java.lang.String)
87
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang.String, java.lang.String)
98
	 */
88
	 */
99
	
89
    @Override
-
 
90
	@WebMethod(operationName = "runCommandAsync")
100
	@WebMethod(operationName = "runCommandAsync")
91
    public ReturnCode runCommandAsync(@WebParam(name = "executable") String cmd,
-
 
92
            @WebParam(name = "argline") String args) {
-
 
93
 
-
 
94
        return executeCommand(cmd,
-
 
95
                Commandline.translateCommandline(args),
-
 
96
                null,
101
	public ReturnCode runCommandAsync(
97
                true,
-
 
98
                null,
102
			@WebParam(name = "executable") String cmd,
99
                false,
103
			@WebParam(name = "argline") String args) {
-
 
104
 
100
                true,
105
		return executeCommand(cmd, Commandline.translateCommandline(args),
-
 
106
				null, true, null, false, true, false, 0);
-
 
107
	}
101
                false,
108
 
-
 
109
	/*
102
                0);
110
	 * (non-Javadoc)
103
    }
111
	 * 
104
 
112
	 * @see
-
 
113
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java
105
    /* (non-Javadoc)
114
	 * .lang.String, java.lang.String[])
106
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java.lang.String, java.lang.String[])
115
	 */
107
	 */
116
	
108
    @Override
117
	@WebMethod(operationName = "runCommandAsyncWithArgs")
109
	@WebMethod(operationName = "runCommandAsyncWithArgs")
-
 
110
    public ReturnCode runCommandAsyncWithArgs(@WebParam(name = "executable") String cmd,
-
 
111
            @WebParam(name = "arg") String[] args) {
-
 
112
 
-
 
113
        return executeCommand(cmd,
-
 
114
                args,
-
 
115
                null,
-
 
116
                true,
118
	public ReturnCode runCommandAsyncWithArgs(
117
                null,
119
			@WebParam(name = "executable") String cmd,
118
                false,
120
			@WebParam(name = "arg") String[] args) {
-
 
121
 
119
                true,
122
		return executeCommand(cmd, args, null, true, null, false, true, false,
-
 
123
				0);
-
 
124
	}
-
 
125
 
120
                false,
126
	/*
121
                0);
127
	 * (non-Javadoc)
122
    }
128
	 * 
123
 
129
	 * @see
-
 
130
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang
124
    /* (non-Javadoc)
131
	 * .String, int, java.lang.String, java.lang.String, java.lang.String, long)
125
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, long)
132
	 */
126
	 */
133
	
127
    @Override
134
	@WebMethod(operationName = "runCommandWithSSH")
128
	@WebMethod(operationName = "runCommandWithSSH")
135
	public ReturnCode runCommandWithSSH(
-
 
136
			@WebParam(name = "host") HostConnection host,
129
    public ReturnCode runCommandWithSSH(@WebParam(name = "host") HostConnection host,
137
			@WebParam(name = "command") String cmd,
130
            @WebParam(name = "command") String cmd,
138
			@WebParam(name = "timeout") long timeout) {
-
 
139
 
131
            @WebParam(name = "timeout") long timeout) {
140
		return sshExec(host.hostname, host.user, host.password, host.port, cmd,
-
 
141
				timeout);
-
 
142
	}
132
 
143
 
-
 
144
	/*
-
 
145
	 * (non-Javadoc)
133
        return sshExec(host.hostname, host.user, host.password, host.port, cmd, timeout);
146
	 * 
134
    }
147
	 * @see
135
 
148
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth(
-
 
149
	 * java.lang.String, int, java.lang.String, java.lang.String,
136
    /* (non-Javadoc)
150
	 * java.lang.String, java.lang.String, long)
137
	 * @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)
151
	 */
138
	 */
152
	
139
    @Override
153
	@WebMethod(operationName = "runCommandWithSSHKeyAuth")
140
	@WebMethod(operationName = "runCommandWithSSHKeyAuth")
154
	public ReturnCode runCommandWithSSHKeyAuth(
141
    public ReturnCode runCommandWithSSHKeyAuth(@WebParam(name = "host") HostConnection host,
155
			@WebParam(name = "host") HostConnection host,
-
 
156
			@WebParam(name = "keyfile") String keyfile,
142
            @WebParam(name = "keyfile") String keyfile,
157
			@WebParam(name = "command") String cmd,
143
            @WebParam(name = "command") String cmd,
158
			@WebParam(name = "timeout") long timeout) {
-
 
159
 
144
            @WebParam(name = "timeout") long timeout) {
160
		return sshExecWithCert(host.hostname, host.user, host.password,
-
 
161
				keyfile, host.port, cmd, timeout);
-
 
162
	}
145
 
163
 
-
 
164
	/*
146
        return sshExecWithCert(host.hostname, host.user, host.password, keyfile, host.port, cmd, timeout);
165
	 * (non-Javadoc)
147
    }
166
	 * 
148
 
167
	 * @see
149
    /* (non-Javadoc)
168
	 * net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices
150
	 * @see net.brutex.xservices.ws.impl.ExecuteService#rExec(net.brutex.xservices.types.HostConnection, java.lang.String, long)
169
	 * .types.HostConnection, java.lang.String, long)
151
	 */
170
	 */
152
    @Override
171
	
-
 
172
	@WebMethod(operationName = "rExec")
153
	@WebMethod(operationName = "rExec")
173
	public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
154
    public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
174
			@WebParam(name = "command") String cmd,
-
 
175
			@WebParam(name = "timeout") long timeout) {
155
            @WebParam(name = "command") String cmd,
176
		return rexec(host.hostname, host.port, host.user, host.password, cmd,
-
 
177
				timeout);
-
 
178
	}
156
            @WebParam(name = "timeout") long timeout) {
179
 
-
 
180
	/*
-
 
181
	 * (non-Javadoc)
157
        return rexec(host.hostname, host.port, host.user, host.password, cmd, timeout);
182
	 * 
158
    }
183
	 * @see
159
 
184
	 * net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices
Line 290... Line 346...
290
        rexec.setTimeout((int) Math.round(timeout));
346
		rexec.setTimeout((int) Math.round(timeout));
291
        
347
 
292
        rexec.createRead().addText(prompt);
348
		rexec.createRead().addText(prompt);