Subversion Repositories XServices

Rev

Rev 58 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 58 Rev 70
1
/*
1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.ws.impl;
17
package net.brutex.xservices.ws.impl;
18
 
18
 
19
import java.io.File;
19
import java.io.File;
-
 
20
import java.util.UUID;
-
 
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;
24
import net.brutex.xservices.types.ReturnCode;
26
import net.brutex.xservices.types.ReturnCode;
25
import net.brutex.xservices.util.BrutexNamespaces;
27
import net.brutex.xservices.util.BrutexNamespaces;
-
 
28
import net.brutex.xservices.util.JobWrapper;
26
import net.brutex.xservices.util.RunTask;
29
import net.brutex.xservices.util.RunTask;
27
import net.brutex.xservices.ws.ExecuteService;
30
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;
31
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
35
import org.apache.tools.ant.taskdefs.optional.net.TelnetTask;
32
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
36
import org.apache.tools.ant.taskdefs.optional.ssh.SSHExec;
33
import org.apache.tools.ant.types.Commandline;
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.*;
-
 
47
import org.quartz.TriggerUtils;
-
 
48
import org.quartz.impl.StdSchedulerFactory;
-
 
49
import org.quartz.impl.triggers.SimpleTriggerImpl;
34
 
50
 
35
/**
51
/**
36
 *
52
 * 
37
 * @author Brian Rosenberger, bru@brutex.de
53
 * @author Brian Rosenberger, bru@brutex.de
38
 */
-
 
39
@WebService(
-
 
40
		targetNamespace=BrutexNamespaces.WS_XSERVICES, 
54
 */
41
		endpointInterface="net.brutex.xservices.ws.ExecuteService",
-
 
42
		serviceName="ExecuteService"
-
 
43
			)
55
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.ExecuteService", serviceName = "ExecuteService")
-
 
56
public class ExecuteServiceImpl implements ExecuteService {
44
public class ExecuteServiceImpl implements ExecuteService {
57
 
-
 
58
	/*
-
 
59
	 * (non-Javadoc)
45
 
60
	 * 
-
 
61
	 * @see
46
    /* (non-Javadoc)
62
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String,
47
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommand(java.lang.String, java.lang.String, long)
-
 
48
	 */
63
	 * java.lang.String, long)
49
    @Override
64
	 */
50
	@WebMethod(operationName = "runCommand")
65
	@WebMethod(operationName = "runCommand")
51
    public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
66
	public ReturnCode runCommand(@WebParam(name = "executable") String cmd,
52
            @WebParam(name = "argline") String args,
67
			@WebParam(name = "argline") String args,
53
            @WebParam(name = "timeout") long timeout) {
-
 
54
 
68
			@WebParam(name = "timeout") long timeout) {
55
        return executeCommand(cmd,
-
 
56
                Commandline.translateCommandline(args),
-
 
57
                null,
-
 
58
                false,
-
 
59
                null,
-
 
60
                false,
-
 
61
                true,
69
 
62
                false,
70
		return executeCommand(cmd, Commandline.translateCommandline(args),
63
                timeout);
71
				null, false, null, false, true, false, timeout);
-
 
72
	}
64
    }
73
 
-
 
74
	/*
-
 
75
	 * (non-Javadoc)
65
 
76
	 * 
-
 
77
	 * @see
66
    /* (non-Javadoc)
78
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang
67
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithArgs(java.lang.String, java.lang.String[], long)
79
	 * .String, java.lang.String[], long)
68
	 */
80
	 */
-
 
81
	
69
    @Override
82
	@WebMethod(operationName = "runCommandWithArgs")
70
	@WebMethod(operationName = "runCommandWithArgs")
83
	public ReturnCode runCommandWithArgs(
71
    public ReturnCode runCommandWithArgs(@WebParam(name = "executable") String cmd,
84
			@WebParam(name = "executable") String cmd,
72
            @WebParam(name = "arg") String[] args,
85
			@WebParam(name = "arg") String[] args,
73
            @WebParam(name = "timeout") long timeout) {
86
			@WebParam(name = "timeout") long timeout) {
74
 
-
 
75
        return executeCommand(cmd,
-
 
76
                args,
-
 
77
                null,
-
 
78
                false,
-
 
79
                null,
-
 
80
                false,
-
 
81
                true,
87
 
82
                false,
88
		return executeCommand(cmd, args, null, false, null, false, true, false,
83
                timeout);
89
				timeout);
-
 
90
	}
84
    }
91
 
-
 
92
	/*
-
 
93
	 * (non-Javadoc)
85
 
94
	 * 
-
 
95
	 * @see
86
    /* (non-Javadoc)
96
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang
87
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsync(java.lang.String, java.lang.String)
97
	 * .String, java.lang.String)
88
	 */
98
	 */
-
 
99
	
89
    @Override
100
	@WebMethod(operationName = "runCommandAsync")
90
	@WebMethod(operationName = "runCommandAsync")
101
	public ReturnCode runCommandAsync(
91
    public ReturnCode runCommandAsync(@WebParam(name = "executable") String cmd,
102
			@WebParam(name = "executable") String cmd,
92
            @WebParam(name = "argline") String args) {
-
 
93
 
103
			@WebParam(name = "argline") String args) {
94
        return executeCommand(cmd,
-
 
95
                Commandline.translateCommandline(args),
-
 
96
                null,
-
 
97
                true,
-
 
98
                null,
-
 
99
                false,
104
 
100
                true,
-
 
101
                false,
105
		return executeCommand(cmd, Commandline.translateCommandline(args),
102
                0);
106
				null, true, null, false, true, false, 0);
-
 
107
	}
103
    }
108
 
-
 
109
	/*
-
 
110
	 * (non-Javadoc)
104
 
111
	 * 
-
 
112
	 * @see
105
    /* (non-Javadoc)
113
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java
106
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandAsyncWithArgs(java.lang.String, java.lang.String[])
114
	 * .lang.String, java.lang.String[])
107
	 */
115
	 */
-
 
116
	
108
    @Override
117
	@WebMethod(operationName = "runCommandAsyncWithArgs")
109
	@WebMethod(operationName = "runCommandAsyncWithArgs")
118
	public ReturnCode runCommandAsyncWithArgs(
110
    public ReturnCode runCommandAsyncWithArgs(@WebParam(name = "executable") String cmd,
119
			@WebParam(name = "executable") String cmd,
111
            @WebParam(name = "arg") String[] args) {
120
			@WebParam(name = "arg") String[] args) {
112
 
-
 
113
        return executeCommand(cmd,
-
 
114
                args,
-
 
115
                null,
-
 
116
                true,
-
 
117
                null,
-
 
118
                false,
-
 
119
                true,
121
 
120
                false,
122
		return executeCommand(cmd, args, null, true, null, false, true, false,
121
                0);
123
				0);
-
 
124
	}
122
    }
125
 
-
 
126
	/*
-
 
127
	 * (non-Javadoc)
-
 
128
	 * 
123
 
129
	 * @see
124
    /* (non-Javadoc)
130
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang
125
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSH(java.lang.String, int, java.lang.String, java.lang.String, java.lang.String, long)
131
	 * .String, int, java.lang.String, java.lang.String, java.lang.String, long)
126
	 */
132
	 */
-
 
133
	
127
    @Override
134
	@WebMethod(operationName = "runCommandWithSSH")
128
	@WebMethod(operationName = "runCommandWithSSH")
135
	public ReturnCode runCommandWithSSH(
129
    public ReturnCode runCommandWithSSH(@WebParam(name = "host") HostConnection host,
136
			@WebParam(name = "host") HostConnection host,
130
            @WebParam(name = "command") String cmd,
137
			@WebParam(name = "command") String cmd,
131
            @WebParam(name = "timeout") long timeout) {
138
			@WebParam(name = "timeout") long timeout) {
-
 
139
 
132
 
140
		return sshExec(host.hostname, host.user, host.password, host.port, cmd,
133
        return sshExec(host.hostname, host.user, host.password, host.port, cmd, timeout);
141
				timeout);
-
 
142
	}
134
    }
143
 
-
 
144
	/*
-
 
145
	 * (non-Javadoc)
135
 
146
	 * 
-
 
147
	 * @see
-
 
148
	 * net.brutex.xservices.ws.impl.ExecuteService#runCommandWithSSHKeyAuth(
136
    /* (non-Javadoc)
149
	 * java.lang.String, int, java.lang.String, java.lang.String,
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)
150
	 * java.lang.String, java.lang.String, long)
138
	 */
151
	 */
-
 
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,
142
            @WebParam(name = "keyfile") String keyfile,
156
			@WebParam(name = "keyfile") String keyfile,
143
            @WebParam(name = "command") String cmd,
157
			@WebParam(name = "command") String cmd,
144
            @WebParam(name = "timeout") long timeout) {
158
			@WebParam(name = "timeout") long timeout) {
-
 
159
 
145
 
160
		return sshExecWithCert(host.hostname, host.user, host.password,
146
        return sshExecWithCert(host.hostname, host.user, host.password, keyfile, host.port, cmd, timeout);
161
				keyfile, host.port, cmd, timeout);
-
 
162
	}
147
    }
163
 
-
 
164
	/*
-
 
165
	 * (non-Javadoc)
148
 
166
	 * 
-
 
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
	
153
	@WebMethod(operationName = "rExec")
172
	@WebMethod(operationName = "rExec")
154
    public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
173
	public ReturnCode rExec(@WebParam(name = "host") HostConnection host,
155
            @WebParam(name = "command") String cmd,
174
			@WebParam(name = "command") String cmd,
-
 
175
			@WebParam(name = "timeout") long timeout) {
156
            @WebParam(name = "timeout") long timeout) {
176
		return rexec(host.hostname, host.port, host.user, host.password, cmd,
157
        return rexec(host.hostname, host.port, host.user, host.password, cmd, timeout);
177
				timeout);
-
 
178
	}
158
    }
179
 
-
 
180
	/*
-
 
181
	 * (non-Javadoc)
159
 
182
	 * 
-
 
183
	 * @see
-
 
184
	 * net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices
160
    /* (non-Javadoc)
185
	 * .types.HostConnection, java.lang.String, java.lang.String,
161
	 * @see net.brutex.xservices.ws.impl.ExecuteService#runTelnet(net.brutex.xservices.types.HostConnection, java.lang.String, java.lang.String, java.lang.String, long)
186
	 * java.lang.String, long)
162
	 */
187
	 */
293
        rexec.createWrite().addText(command);
349
		rexec.createWrite().addText(command);
294
        rexec.createRead().addText(expect);
350
		rexec.createRead().addText(expect);
295
 
351
 
296
        return runner.postTask();
352
		return runner.postTask();
297
    }
353
	}
298
}
354
}