View Javadoc
1   package org.metricshub.winrm;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * WinRM Java Client
6    * ჻჻჻჻჻჻
7    * Copyright 2023 - 2024 Metricshub
8    * ჻჻჻჻჻჻
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   *
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
21   */
22  
23  import java.nio.charset.Charset;
24  import java.util.List;
25  import java.util.Map;
26  import java.util.concurrent.TimeoutException;
27  import org.metricshub.winrm.exceptions.WindowsRemoteException;
28  import org.metricshub.winrm.exceptions.WqlQuerySyntaxException;
29  
30  public interface WindowsRemoteExecutor extends AutoCloseable {
31  	/**
32  	 * <p>Execute a WQL query and process its result.</p>
33  	 *
34  	 * @param wqlQuery the WQL query (required)
35  	 * @param timeout Timeout in milliseconds (throws an IllegalArgumentException if negative or zero)
36  	 *
37  	 * @return a list of result rows. A result row is a Map(LinkedHashMap to preserve the query order) of
38  	 * properties/values.
39  	 *
40  	 * @throws TimeoutException to notify userName of timeout.
41  	 * @throws WqlQuerySyntaxException if WQL query syntax is invalid
42  	 * @throws WindowsRemoteException For any problem encountered
43  	 */
44  	public List<Map<String, Object>> executeWql(final String wqlQuery, final long timeout)
45  		throws TimeoutException, WqlQuerySyntaxException, WindowsRemoteException;
46  
47  	/**
48  	 * Execute the command on the remote
49  	 *
50  	 * @param command The command to execute
51  	 * @param workingDirectory Path of the directory for the spawned process on the remote system (can be null)
52  	 * @param charset The charset
53  	 * @param timeout Timeout in milliseconds
54  	 *
55  	 * @return The command result
56  	 *
57  	 * @throws WindowsRemoteException For any problem encountered
58  	 * @throws TimeoutException To notify userName of timeout.
59  	 */
60  	public WindowsRemoteCommandResult executeCommand(
61  		final String command,
62  		final String workingDirectory,
63  		final Charset charset,
64  		final long timeout
65  	) throws WindowsRemoteException, TimeoutException;
66  
67  	/**
68  	 * Get the hostname.
69  	 * @return
70  	 */
71  	public String getHostname();
72  
73  	/**
74  	 * Get the username.
75  	 * @return
76  	 */
77  	public String getUsername();
78  
79  	/**
80  	 * Get the password.
81  	 * @return
82  	 */
83  	public char[] getPassword();
84  }