public JmxInstance(Instance instance) { try { String[] itemNames = AdminServiceMBean.INSTANCE; Object[] itemValues = new Object[itemNames.length]; itemValues[0] = instance.getPid(); itemValues[1] = instance.getName(); itemValues[2] = instance.isRoot(); itemValues[3] = instance.getSshPort(); itemValues[4] = instance.getRmiRegistryPort(); itemValues[5] = instance.getRmiServerPort(); try { itemValues[6] = instance.getState(); } catch (Exception e) { itemValues[6] = "Error"; } itemValues[7] = instance.getLocation(); itemValues[8] = instance.getJavaOpts(); data = new CompositeDataSupport(INSTANCE, itemNames, itemValues); } catch (OpenDataException e) { throw new IllegalStateException("Cannot create instance open data", e); } }
private boolean destroyInstance(String name) { try { Instance instance = adminService.getInstance(name); if (instance != null) { instance.destroy(); return true; } } catch (Exception ex) { Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex); } return false; }
public void startInstance(String name, String opts, boolean wait) throws Exception { Instance child = getExistingInstance(name); if (wait) { String state = child.getState(); if (Instance.STOPPED.equals(state)) { child.start(opts); } if (!Instance.STARTED.equals(state)) { do { Thread.sleep(500); state = child.getState(); } while (Instance.STARTING.equals(state)); } } else { child.start(opts); } }
protected boolean acceptsInstance(Instance instance) { try { if (instance.getState().equals(Instance.STARTED)) { return true; } else { return false; } } catch (Exception e) { return false; } } }
private boolean startInstance(String name, String javaOpts) { try { Instance instance = adminService.getInstance(name); if (instance != null) { instance.start(javaOpts); return true; } } catch (Exception ex) { Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex); } return false; }
public int createInstance(String name, InstanceSettings settings) throws Exception { Instance inst = adminService.createInstance(name, settings); if (inst != null) { return inst.getPid(); } else { return -1; } }
protected Object doExecute() throws Exception { String cmdStr = ""; if (command != null) { StringBuilder sb = new StringBuilder(); for (String cmd : command) { if (sb.length() > 0) { sb.append(' '); } sb.append(cmd); } cmdStr = "'" + sb.toString().replaceAll("'", "\\'") + "'"; } int port = getExistingInstance(instance).getSshPort(); if (username != null) { if (password == null) { session.execute("ssh -l " + username + " -p " + port + " localhost " + cmdStr); } else { session.execute("ssh -l " + username + " -P " + password + " -p " + port + " localhost " + cmdStr); } } else { session.execute("ssh -p " + port + " localhost " + cmdStr); } return null; } }
public int complete(String buffer, int cursor, List candidates) { StringsCompleter delegate = new StringsCompleter(); for (Instance instance : adminService.getInstances()) { if (acceptsInstance(instance)) { delegate.getStrings().add(instance.getName()); } } return delegate.complete(buffer, cursor, candidates); }
protected boolean acceptsInstance(Instance instance) { try { if (instance.getState().equals(Instance.STOPPED)) { return true; } else { return false; } } catch (Exception e) { return false; } }
public void startInstance(String name) throws Exception { getExistingInstance(name).start(null); }
public int createInstance(String name, int sshPort, int rmiRegistryPort, int rmiServerPort, String location, String javaOpts, String features, String featureURLs, String address) throws Exception { if ("".equals(location)) { location = null; } if ("".equals(javaOpts)) { javaOpts = null; } InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts, parseStringList(featureURLs), parseStringList(features), new HashMap<String, URL>(), new HashMap<String, URL>(), address); Instance inst = adminService.createInstance(name, settings); if (inst != null) { return inst.getPid(); } else { return -1; } }
StringBuilder sb = new StringBuilder(); sb.append('['); String s = Integer.toString(instance.getSshPort()); for (int i = s.length(); i < 8; i++) { sb.append(' '); String rmiRegistryPort = Integer.toString(instance.getRmiRegistryPort()); String rmiServerPort = Integer.toString(instance.getRmiServerPort()); sb.append(rmiRegistryPort).append("/").append(rmiServerPort); for (int i = rmiRegistryPort.length() + rmiServerPort.length() + 1; i < 15; i++) { String state = instance.getState(); while (state.length() < "starting".length()) { state += " "; s = Integer.toString(instance.getPid()); for (int i = s.length(); i < 5; i++) { sb.append(' '); sb.append("] "); if (javaOpts) { sb.append(instance.getJavaOpts()); } else if (location) { sb.append(instance.getLocation()); } else { sb.append(instance.getName());
private boolean instanceStarted() { try { String state = adminService.getInstance(name).getState(); return Instance.STARTED.equals(state); } catch (Exception ex) { return false; } } }
protected Object doExecute() throws Exception { Instance child = getExistingInstance(instance); if (wait) { String state = child.getState(); if (Instance.STOPPED.equals(state)) { child.start(javaOpts); } if (!Instance.STARTED.equals(state)) { do { Thread.sleep(500); state = child.getState(); } while (Instance.STARTING.equals(state)); } } else { child.start(javaOpts); } return null; } }
public void startInstance(String name, String opts) throws Exception { getExistingInstance(name).start(opts); }
protected Object doExecute() throws Exception { getExistingInstance(instance).destroy(); return null; }
private void instanceInfo(JSONWriter jw, Instance instance) throws JSONException, Exception { jw.object(); jw.key("pid"); jw.value(instance.getPid()); jw.key("name"); jw.value(instance.getName()); jw.key("sshPort"); jw.value(instance.getSshPort()); jw.key("rmiRegistryPort"); jw.value(instance.getRmiRegistryPort()); jw.key("rmiServerPort"); jw.value(instance.getRmiServerPort()); jw.key("state"); jw.value(instance.getState()); jw.key("location"); jw.value(instance.getJavaOpts() != null ? instance.getJavaOpts() : ""); jw.key("javaopts"); jw.value(instance.getLocation()); jw.key("actions"); jw.array(); action(jw, "destroy", "Destroy", "delete"); if (instance.getState().equals(Instance.STARTED)) { action(jw, "stop", "Stop", "stop"); } else if (instance.getState().equals(Instance.STARTING)) { action(jw, "stop", "Stop", "stop"); } else if (instance.getState().equals(Instance.STOPPED)) { action(jw, "start", "Start", "start");
private boolean instanceStarted() { try { String state = adminService.getInstance(name).getState(); return Instance.STARTED.equals(state); } catch (Exception ex) { return false; } } }
public void destroyInstance(String name) throws Exception { getExistingInstance(name).destroy(); }
protected Object doExecute() throws Exception { System.out.println(getExistingInstance(name).getState()); return null; }