Package org.jboss.byteman.agent.submit

Examples of org.jboss.byteman.agent.submit.Submit


        super(TestSubmit.class.getCanonicalName());
    }

    public void test()
    {
        Submit submit = new Submit();
        ScriptRepository repository = new ScriptRepository(false);
        List<ScriptText> scripts = new ArrayList<ScriptText>();
        scripts.add(new ScriptText("dynamic", getRuleText()));

        try {
            submit.addScripts(scripts);
        } catch (Exception e) {
            System.out.println("exception submitting script");
            fail();
        }

        try {
            log("calling TestSubmit.triggerMethod");
            triggerMethod();
            log("called TestSubmit.triggerMethod");
        } catch (Exception e) {
            log(e);
        } catch (Throwable th) {
            System.out.println("unexpected throwable " + th);
            fail();
        }

        try {
            submit.deleteScripts(scripts);
        } catch (Exception e) {
            System.out.println("exception deleting script");
            fail();
        }
View Full Code Here


            throw new FileNotFoundException("Rule file not found for Byteman test case " + key);
        }
        if (!file.canRead()) {
            throw new IOException("Cannot read Byteman rule file " + filename);
        }
        Submit submit = new Submit();
        List<String> files =  new ArrayList<String>();
        files.add(filename);
        if (verbose) {
            System.out.println("BMUNit : loading file script = " + filename);
        }
        submit.addRulesFromFiles(files);
        fileTable.put(key, filename);
    }
View Full Code Here

        String key = className + "#"  + testName;
        String filename = fileTable.remove(key);
        if (filename == null) {
            throw new FileNotFoundException("Rule file not found for Byteman test case " + key);
        }
        Submit submit = new Submit();
        List<String> files =  new ArrayList<String>();
        files.add(filename);
        if (verbose) {
            System.out.println("BMUNit : unloading fle script = " + filename);
        }
        submit.deleteRulesFromFiles(files);
    }
View Full Code Here

        if (testname ==  null) {
            testname = "";
        }
        String key = className + "+"  + testname;
        fileTable.put(key, scriptText);
        Submit submit = new Submit();
        if (verbose) {
            System.out.println("BMUNit : loading text script = " + key);
            // System.out.println(scriptText);
        }
        List<ScriptText> scripts = new ArrayList<ScriptText>();
        ScriptText script = new ScriptText(key, scriptText);
        scripts.add(script);
        submit.addScripts(scripts);
    }
View Full Code Here

        String key = className + "+"  + testName;
        String scriptText = fileTable.remove(key);
        if (scriptText == null) {
            throw new Exception("Rule script not found " + key);
        }
        Submit submit = new Submit();
        if (verbose) {
            System.out.println("BMUNit : unloading text script = " + key);
        }
        List<ScriptText> scripts = new ArrayList<ScriptText>();
        ScriptText script = new ScriptText(key, scriptText);
        scripts.add(script);
        submit.deleteScripts(scripts);
    }
View Full Code Here

        File helper = jdbcTracerUtil.getHelperJarFile(bytemanAgentResource, helperJarFileName);
        String helperAbsolutePath = helper.getAbsolutePath();

        // see if there are already jdbc trace rules installed in the byteman agent
        // note that we talk directly to the remote byteman agent to get the info; our parent resource might not have our script yet in its cache
        Submit client = bytemanAgentResource.getBytemanClient();
        Map<String, String> allKnownScripts = client.getAllRules();
        String existingRules = null;
        if (allKnownScripts != null) {
            existingRules = allKnownScripts.get(scriptAbsolutePath);
        }

        // add or remove the rules as appropriate
        if (isEnabled()) {
            // if we are to refresh the script, remove the current script that is loaded (if one is loaded)
            if (existingRules != null && refresh) {
                Map<String, String> doomed = new HashMap<String, String>(1);
                doomed.put(scriptAbsolutePath, existingRules);
                client.deleteRules(doomed);
                existingRules = null;
            }

            if (refresh || !helper.exists()) {
                // the helper was deleted previously, we need to write it back out again
                jdbcTracerUtil.extractHelperJarFile(bytemanAgentResource, helperJarFileName);
            }
            if (refresh || !client.getLoadedSystemClassloaderJars().contains(helperAbsolutePath)) {
                client.addJarsToSystemClassloader(Arrays.asList(helperAbsolutePath));
            }

            if (existingRules == null) {
                if (!script.exists()) {
                    // the script was deleted previously, we need to write it back out again
                    jdbcTracerUtil.extractJdbcTraceRulesScriptFile(bytemanAgentResource, scriptName);
                }
                client.addRulesFromFiles(Arrays.asList(scriptAbsolutePath));
            }
        } else {
            if (existingRules != null) {
                Map<String, String> doomed = new HashMap<String, String>(1);
                doomed.put(scriptAbsolutePath, existingRules);
                client.deleteRules(doomed);
            }
        }

        return;
    }
View Full Code Here

    public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<BytemanScriptComponent> context)
        throws Exception {

        Set<DiscoveredResourceDetails> details = new HashSet<DiscoveredResourceDetails>();

        Submit client = context.getParentResourceComponent().getBytemanClient();
        List<String> rules = context.getParentResourceComponent().getRules();
        if (rules != null && !rules.isEmpty()) {
            for (String rule : rules) {
                String ruleName = client.determineRuleName(rule);
                details.add(new DiscoveredResourceDetails(context.getResourceType(), ruleName, ruleName, "unversioned",
                    "A rule defined in a Byteman script", null, null));
            }
        }
View Full Code Here

     * The plugin container will call this method when metrics are to be collected.
     *
     * @see MeasurementFacet#getValues(MeasurementReport, Set)
     */
    public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests) {
        Submit client = getBytemanClient();

        // a cache so we don't ask the byteman agent more than once for this while we are in here
        // we don't rely on this.allKnownScripts because we want the latest-n-greatest value for our metrics
        Map<String, String> allScripts = null;

        for (MeasurementScheduleRequest request : requests) {
            String name = request.getName();

            try {
                if (name.equals("TRAIT-clientVersion")) {
                    String clientVersion = client.getClientVersion();
                    report.addData(new MeasurementDataTrait(request, clientVersion));
                } else if (name.equals("totalNumberOfScripts")) {
                    int total = 0;
                    if (allScripts == null) {
                        allScripts = client.getAllRules();
                    }
                    if (allScripts != null) {
                        total += allScripts.size();
                    }
                    report.addData(new MeasurementDataNumeric(request, Double.valueOf(total)));
                } else if (name.equals("totalNumberOfRules")) {
                    int total = 0;
                    if (allScripts == null) {
                        allScripts = client.getAllRules();
                    }
                    if (allScripts != null) {
                        for (String script : allScripts.values()) {
                            total += client.splitAllRulesFromScript(script).size();
                        }
                    }
                    report.addData(new MeasurementDataNumeric(request, Double.valueOf(total)));
                } else if (name.equals("totalNumberOfBootJars")) {
                    int total = 0;
                    List<String> loadedJars = client.getLoadedBootClassloaderJars();
                    if (loadedJars != null) {
                        total = loadedJars.size();
                    }
                    report.addData(new MeasurementDataNumeric(request, Double.valueOf(total)));
                } else if (name.equals("totalNumberOfSystemJars")) {
                    int total = 0;
                    List<String> loadedJars = client.getLoadedSystemClassloaderJars();
                    if (loadedJars != null) {
                        total = loadedJars.size();
                    }
                    report.addData(new MeasurementDataNumeric(request, Double.valueOf(total)));
                } else {
View Full Code Here

     * @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));
View Full Code Here

     * Deploys boot and system classpath jars to the Byteman agent.
     *
     * @see ContentFacet#deployPackages(Set, ContentServices)
     */
    public DeployPackagesResponse deployPackages(Set<ResourcePackageDetails> packages, ContentServices contentServices) {
        Submit client = getBytemanClient();
        DeployPackagesResponse response = new DeployPackagesResponse();
        DeployIndividualPackageResponse individualResponse;

        for (ResourcePackageDetails detail : packages) {
            PackageDetailsKey packageKey = detail.getKey();
            String packageType = detail.getPackageTypeName();

            individualResponse = new DeployIndividualPackageResponse(packageKey);
            response.addPackageResponse(individualResponse);

            try {
                Boolean isBootJar = null; // null if not a classpath jar (this is for the future; today, it will always get set)
                // if necessary, create the data directory where the file should be deployed
                if (PKG_TYPE_NAME_BOOT_JAR.equals(packageType)) {
                    this.bootJarsDataDir.mkdirs();
                    isBootJar = Boolean.TRUE;
                } else if (PKG_TYPE_NAME_SYSTEM_JAR.equals(packageType)) {
                    this.systemJarsDataDir.mkdirs();
                    isBootJar = Boolean.FALSE;
                } else {
                    throw new UnsupportedOperationException("Cannot deploy package of type [" + packageType + "]");
                }

                // download the package to our data directory
                File newFile = getPackageFile(detail);
                FileOutputStream fos = new FileOutputStream(newFile);
                try {
                    ContentContext contentContext = this.resourceContext.getContentContext();
                    contentServices.downloadPackageBits(contentContext, packageKey, fos, true);
                } finally {
                    fos.close();
                }

                // tell the byteman agent to add it to the proper classloader
                if (isBootJar != null) {
                    if (isBootJar.booleanValue()) {
                        client.addJarsToBootClassloader(Arrays.asList(newFile.getAbsolutePath()));
                    } else {
                        client.addJarsToSystemClassloader(Arrays.asList(newFile.getAbsolutePath()));
                    }
                }

                // everything is OK
                individualResponse.setResult(ContentResponseResult.SUCCESS);
View Full Code Here

TOP

Related Classes of org.jboss.byteman.agent.submit.Submit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.