/** * Tells the Byteman agent to list all deployed rules. * * @return all the rules deployed in the Byteman agent * * @throws Exception * if the request failed */ public String listAllRules() throws Exception { return submitRequest("LIST\n"); }
public Instrumentor(String address, int port) throws RemoteException { this(new Submit(address, port), BytemanTestHelper.DEFAULT_RMI_PORT); }
/** * Deploys rules into Byteman, where the rule definitions are found in the * given streams. Rule definitions are read from the streams and the rule * text uploaded directly to the Byteman agent. * * This method is useful for using rules files from the classpath. * * @param resourceStreams * input streams containing the rule definitions to be deployed * to Byteman * * @return the results of the deployment * * @throws Exception * if the request failed */ public String addRulesFromResources(List<InputStream> resourceStreams) throws Exception { List<ScriptText> scripts = getRulesFromRuleStreams(resourceStreams); return addScripts(scripts); }
private static void uploadAgentProperties() throws Exception { // if any Byteman config changes have been requested and // are allowed upload all reconfigured system property // settings to the agent. BMUnitConfigState previousConfigState = currentConfigState.previous; if (needPropertyReset(currentConfigState, previousConfigState)) { Submit submit = new Submit(currentConfigState.getHost(), currentConfigState.getPort()); Properties properties = new Properties(); if (configurePropertyReset(currentConfigState, previousConfigState, properties)) { submit.setSystemProperties(properties); } } }
/** * Deletes rules from Byteman. * * @param scripts * rule scripts to be deleted from Byteman * * @return the results of the deletion * * @throws Exception * if the request failed */ public String deleteScripts(List<ScriptText> scripts) throws Exception { if (scripts == null || scripts.size() == 0) { return ""; } StringBuilder str = new StringBuilder("DELETE\n"); for (ScriptText scriptText : scripts) { str.append("SCRIPT " + scriptText.getFileName() + '\n'); str.append(scriptText.getText()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDDELETE\n"); return submitRequest(str.toString()); }
/** * Deletes rules from Byteman, where the rule definitions are found in the * given streams. Rule definitions are read from the streams so that details * of which rules to unload can be uploaded directly to the Byteman agent. * * This method is useful for using rules files from the classpath. * * @param resourceStreams * the URLS to files containing the rule definitions to be deleted * from Byteman * * @return the results of the deletion * * @throws Exception * if the request failed */ public String deleteRulesFromResources(List<InputStream> resourceStreams) throws Exception { List<ScriptText> scripts = getRulesFromRuleStreams(resourceStreams); return deleteScripts(scripts); }
/** * Submits the generic request string to the Byteman agent for processing. * * @param request * the request to submit * * @return the response that the Byteman agent replied with * * @throws Exception * if the request failed */ public String submitRequest(String request) throws Exception { Comm comm = new Comm(this.address, this.port); try { comm.print(request); String results = comm.readResponse(); return results; } finally { comm.close(); } }
/** * Deploys rules into Byteman, where the rule definitions are found in the * local files found at the given paths. The rule definitions found in the * files are actually passed down directly to Byteman, not the file paths * themselves. Therefore, these files must exist on the machine where this * client is running (i.e. the files are not loaded directly by the Byteman * agent). * * @param filePaths * the local files containing the rule definitions to be deployed * to Byteman * * @return the results of the deployment * * @throws Exception * if the request failed */ public String addRulesFromFiles(List<String> filePaths) throws Exception { List<ScriptText> scripts = getRulesFromRuleFiles(filePaths); return addScripts(scripts); }
/** * Deletes rules from Byteman, where the rule definitions are found in the * local files found at the given paths. After this method is done, the * given rules will no longer be processed by Byteman. The rule definitions * found in the files are actually passed down directly to Byteman, not the * file paths themselves. Therefore, these files must exist on the machine * where this client is running (i.e. the files are not read directly by the * Byteman agent). * * @param filePaths * the local files containing the rule definitions to be deleted * from Byteman * * @return the results of the deletion * * @throws Exception * if the request failed */ public String deleteRulesFromFiles(List<String> filePaths) throws Exception { List<ScriptText> scripts = getRulesFromRuleFiles(filePaths); return deleteScripts(scripts); }
/** * Flush any instrumentation for the given class in the remote system and clean up the local cache. * * @throws Exception in case of failure. */ public void removeAllInstrumentation() throws Exception { submit.deleteScripts(installedScripts); removeLocalState(); }
public static void remove(String scriptResourcePath) { try { List<InputStream> streams = getScriptFromResource(scriptResourcePath); submit.deleteRulesFromResources(streams); } catch (Exception e) { throw new RuntimeException("Failed to remove Byteman script", e); } }
public static void submit(String scriptResourcePath) { try { List<InputStream> streams = getScriptFromResource(scriptResourcePath); submit.addRulesFromResources(streams); } catch (Exception e) { throw new RuntimeException("Failed to submit Byteman script", e); } }
/** * Looping through installed scripts and checking if scriptName * is there. If so returns it otherwise returns null. */ private ScriptText findInstalledScript(String scriptName) { for(ScriptText installedScript: installedScripts) { if(installedScript.getFileName().equals(scriptName)) return installedScript; } return null; } }
/** * Deploys rule scripts into Byteman * * @param scripts * scripts to be deployed to Byteman * * @return the results of the deployment * * @throws Exception * if the request failed */ public String addScripts(List<ScriptText> scripts) throws Exception { if (scripts == null || scripts.size() == 0) { return ""; } StringBuilder str = new StringBuilder("LOAD\n"); for (ScriptText scriptText : scripts) { str.append("SCRIPT " + scriptText.getFileName() + '\n'); str.append(scriptText.getText()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDLOAD\n"); return submitRequest(str.toString()); }
public Instrumentor(String address, int port, int rmiPort) throws RemoteException { this(new Submit(address, port), rmiPort); }
public static void remove(String scriptResourcePath) { try { List<InputStream> streams = getScriptFromResource(scriptResourcePath); submit.deleteRulesFromResources(streams); } catch (Exception e) { throw new RuntimeException("Failed to remove Byteman script", e); } }
public static void submit(String scriptResourcePath) { try { List<InputStream> streams = getScriptFromResource(scriptResourcePath); submit.addRulesFromResources(streams); } catch (Exception e) { throw new RuntimeException("Failed to submit Byteman script", e); } }
/** * Tells the Byteman agent to delete all rules. This will effectively revert * the Byteman's VM to its original state; that is, no Byteman injected * byte-code will be invoked. * * @return the results of the delete-all request to the Byteman agent * * @throws Exception * if the request failed */ public String deleteAllRules() throws Exception { return submitRequest("DELETEALL\n"); }
public Instrumentor() throws RemoteException { this(new Submit(), BytemanTestHelper.DEFAULT_RMI_PORT); }
/** * Returns the version of the remote Byteman agent. * * @return the version of the remote Byteman agent * * @throws Exception * if the request failed */ public String getAgentVersion() throws Exception { String version = submitRequest("VERSION\n"); return (version != null) ? version.trim() : "0"; }