* @see OperationFacet#invokeOperation(String, Configuration)
*/
public OperationResult invokeOperation(String name, Configuration configuration) {
OperationResult result = new OperationResult();
Submit client = getBytemanClient();
try {
if ("getRule".equals(name)) {
//
// getRule == retrieves the rule definition for a given rule
String ruleName = configuration.getSimpleValue("ruleName", null);
if (ruleName == null || ruleName.length() == 0) {
throw new Exception("Did not specify the name of the rule to get");
}
Map<String, String> allScripts = client.getAllRules();
for (String script : allScripts.values()) {
List<String> rules = client.splitAllRulesFromScript(script);
for (String rule : rules) {
if (ruleName.equals(client.determineRuleName(rule))) {
Configuration resultConfig = result.getComplexResults();
resultConfig.put(new PropertySimple("ruleDefinition", rule));
return result;
}
}
}
throw new Exception("No rule was found with the name [" + ruleName + "]");
} else if ("getClientVersion".equals(name)) {
//
// getClientVersion == return the version string of the client this plugin is using
String clientVersion = client.getClientVersion();
Configuration resultConfig = result.getComplexResults();
resultConfig.put(new PropertySimple("version", (clientVersion == null) ? "<unknown>" : clientVersion));
return result;
} else if ("addJarsToSystemClasspath".equals(name)) {
//
// addJarsToSystemClasspath == adds a jar to the remote byteman agent's system classpath
String jarPaths = configuration.getSimpleValue("jarPathnames", null);
if (jarPaths == null || jarPaths.length() == 0) {
throw new Exception("Did not specify any jars to add");
}
String[] jarPathsArr = jarPaths.split(",");
List<String> jarPathList = new ArrayList<String>();
for (String jarPathString : jarPathsArr) {
jarPathList.add(jarPathString);
}
String response = client.addJarsToSystemClassloader(jarPathList);
result.setSimpleResult(response);
return result;
} else if ("addJarsToBootClasspath".equals(name)) {
//
// addJarsToBootClasspath == adds a jar to the remote byteman agent's boot classpath
String jarPaths = configuration.getSimpleValue("jarPathnames", null);
if (jarPaths == null || jarPaths.length() == 0) {
throw new Exception("Did not specify any jars to add");
}
String[] jarPathsArr = jarPaths.split(",");
List<String> jarPathList = new ArrayList<String>();
for (String jarPathString : jarPathsArr) {
jarPathList.add(jarPathString);
}
String response = client.addJarsToBootClassloader(jarPathList);
result.setSimpleResult(response);
return result;
} else if ("getAddedClasspathJars".equals(name)) {
//
// getAddedClasspathJars == gets all jars that were added to the byteman agent's boot and system classpaths
Configuration resultConfig = result.getComplexResults();
List<String> jars;
jars = client.getLoadedBootClassloaderJars();
if (jars != null && !jars.isEmpty()) {
PropertyList list = new PropertyList("additionalBootClasspathJars");
for (String jar : jars) {
PropertyMap map = new PropertyMap("additionalBootClasspathJar");
map.put(new PropertySimple("jarPathname", jar));
list.add(map);
}
resultConfig.put(list);
}
jars = client.getLoadedSystemClassloaderJars();
if (jars != null && !jars.isEmpty()) {
PropertyList list = new PropertyList("additionalSystemClasspathJars");
for (String jar : jars) {
PropertyMap map = new PropertyMap("additionalSystemClasspathJar");
map.put(new PropertySimple("jarPathname", jar));