Changeset 2295
- Timestamp:
- Mar 17, 2014, 2:09:53 PM (9 years ago)
- Location:
- extensions/net.sf.basedb.reggie/trunk
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/trunk/META-INF/servlets.xml
r2267 r2295 101 101 <servlet-class>net.sf.basedb.reggie.servlet.SessionServlet</servlet-class> 102 102 </servlet> 103 <servlet> 104 <servlet-name>Ogs</servlet-name> 105 <servlet-class>net.sf.basedb.reggie.servlet.OgsServlet</servlet-class> 106 </servlet> 103 107 </servlets> -
extensions/net.sf.basedb.reggie/trunk/resources/index.jsp
r2267 r2295 65 65 <script language="JavaScript"> 66 66 67 var debug = false;67 var debug = 1; 68 68 var myPermissions = {}; 69 69 … … 769 769 </ul> 770 770 </dd> 771 <dt> 772 <base:icon image="<%=home + "/images/ogs-cluster.png"%>" /> 773 <span class="require-permission" data-role="Administrator" data-link="admin/ogs-clusters.jsp?ID=<%=ID%>">Open Grid Scheduler cluster</span> 771 774 </dl> 772 775 <% -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/ssh/SshHost.java
r2293 r2295 1 1 package net.sf.basedb.reggie.ssh; 2 2 3 import java.io.ByteArrayOutputStream; 3 4 import java.io.IOException; 4 import java.io.InputStream;5 import java.io.InputStreamReader;6 import java.io.StringWriter;7 5 import java.security.PublicKey; 8 6 import java.util.HashMap; 9 7 import java.util.Map; 8 import java.util.concurrent.TimeUnit; 10 9 11 10 import org.json.simple.JSONObject; … … 18 17 import net.schmizz.sshj.connection.channel.direct.Session.Command; 19 18 import net.schmizz.sshj.transport.verification.PromiscuousVerifier; 20 import net.sf.basedb.util.File Util;19 import net.sf.basedb.util.FileCopyRunnable; 21 20 22 21 /** … … 43 42 44 43 private String hostInfoCommand = "uname -a"; 44 // private String hostInfoCommand = "./demux.sh"; 45 45 46 46 /** … … 171 171 response is cached. 172 172 */ 173 public StringgetHostInfo()174 { 175 String systemInfo = (String)infoCache.get("host-info");173 public CmdResult getHostInfo() 174 { 175 CmdResult systemInfo = (CmdResult)infoCache.get("host-info"); 176 176 if (systemInfo == null) 177 177 { 178 try 179 { 180 systemInfo = executeCmd(getHostInfoCommand()); 181 } 182 catch (Exception ex) 183 { 184 systemInfo = ex.getMessage(); 185 } 178 systemInfo = executeCmd(getHostInfoCommand(), 2); 186 179 infoCache.put("host-info", systemInfo); 187 180 } … … 193 186 be used to send commands or transfer files to/from 194 187 the host. 195 */ 196 public SSHClient connect() 188 @param timeout Timeout in seconds for the connection to be established 189 */ 190 public SSHClient connect(int timeout) 197 191 { 198 192 SSHClient ssh = new SSHClient(); … … 207 201 try 208 202 { 203 ssh.setConnectTimeout(timeout * 1000); 209 204 ssh.connect(getAddress(), getPort()); 210 205 ssh.authPassword(getUser(), getPassword()); … … 221 216 Execute a single command on the host and return the 222 217 output as a string. 223 */ 224 public String executeCmd(String cmd) 225 { 226 227 SSHClient ssh = connect(); 218 @param cmd The command to execute 219 @param timeout Timeout in seconds to wait for the command to 220 finish 221 */ 222 public CmdResult executeCmd(String cmd, int timeout) 223 { 224 SSHClient ssh = null; 228 225 Session s = null; 229 StringWriter out = new StringWriter();226 CmdResult result = new CmdResult(); 230 227 try 231 228 { 229 ssh = connect(timeout); 230 ByteArrayOutputStream stdout = new ByteArrayOutputStream(); 231 ByteArrayOutputStream stderr = new ByteArrayOutputStream(); 232 232 233 s = ssh.startSession(); 233 234 Command c = s.exec(cmd); 234 InputStream result = c.getInputStream(); 235 FileUtil.copy(new InputStreamReader(result), out); 235 236 new Thread(new FileCopyRunnable(c.getInputStream(), stdout)).start(); 237 new Thread(new FileCopyRunnable(c.getErrorStream(), stderr)).start(); 238 s.join(timeout, TimeUnit.SECONDS); 239 240 result.setStdout(stdout.toString("UTF-8")); 241 result.setStderr(stderr.toString("UTF-8")); 242 result.setExitStatus(c.getExitStatus()); 236 243 } 237 244 catch (Exception ex) 238 245 { 239 throw new RuntimeException(ex);246 result.setException(ex); 240 247 } 241 248 finally … … 244 251 SshUtil.close(ssh); 245 252 } 246 return out.toString();253 return result; 247 254 } 248 255 … … 265 272 JSONObject jsonHostInfo = new JSONObject(); 266 273 jsonHostInfo.put("cmd", getHostInfoCommand()); 267 jsonHostInfo.put("info", getHostInfo() );274 jsonHostInfo.put("info", getHostInfo().asJSONObject()); 268 275 json.put("hostInfo", jsonHostInfo); 269 276
Note: See TracChangeset
for help on using the changeset viewer.