Search in sources :

Example 1 with ReinstrumentResult

use of com.newrelic.agent.reinstrument.ReinstrumentResult in project newrelic-java-agent by newrelic.

the class ExtensionService method reloadCustomExtensionsIfModified.

private void reloadCustomExtensionsIfModified() {
    File[] xmlFiles = getExtensionFiles(ExtensionFileTypes.XML.getFilter());
    File[] ymlFiles = getExtensionFiles(ExtensionFileTypes.YML.getFilter());
    // element count start at -1 to ensure fileModified is true the first time
    boolean fileModified = (xmlFiles.length + ymlFiles.length) != elementCount;
    if (!fileModified) {
        for (File file : xmlFiles) {
            fileModified |= (file.lastModified() <= System.currentTimeMillis() && lastReloaded < file.lastModified());
        }
        for (File file : ymlFiles) {
            fileModified |= (file.lastModified() <= System.currentTimeMillis() && lastReloaded < file.lastModified());
        }
    }
    // if you are changing be sure to test without an extensions directory
    if (fileModified) {
        lastReloaded = System.currentTimeMillis();
        elementCount = xmlFiles.length + ymlFiles.length;
        pointCuts.clear();
        HashMap<String, Extension> allExtensions = new HashMap<>(internalExtensions);
        loadValidExtensions(xmlFiles, extensionParsers.getXmlParser(), allExtensions);
        loadValidExtensions(ymlFiles, extensionParsers.getYamlParser(), allExtensions);
        Set<Extension> externalExtensions = new HashSet<>(allExtensions.values());
        externalExtensions.removeAll(internalExtensions.values());
        Set<Extension> oldExtensions = extensions;
        extensions = Collections.unmodifiableSet(externalExtensions);
        JmxService jmxService = ServiceFactory.getJmxService();
        if (jmxService != null) {
            jmxService.reloadExtensions(oldExtensions, extensions);
        }
        for (Extension extension : allExtensions.values()) {
            pointCuts.addAll(extension.getInstrumentationMatchers());
        }
        ClassRetransformer retransformer = ServiceFactory.getClassTransformerService().getLocalRetransformer();
        if (retransformer != null) {
            Class<?>[] allLoadedClasses = ServiceFactory.getCoreService().getInstrumentation().getAllLoadedClasses();
            retransformer.setClassMethodMatchers(pointCuts);
            InstrumentationContextClassMatcherHelper matcherHelper = new InstrumentationContextClassMatcherHelper();
            Set<Class<?>> classesToRetransform = ClassesMatcher.getMatchingClasses(retransformer.getMatchers(), matcherHelper, allLoadedClasses);
            ReinstrumentUtils.checkClassExistsAndRetransformClasses(new ReinstrumentResult(), Collections.<ExtensionClassAndMethodMatcher>emptyList(), null, classesToRetransform);
        }
    }
}
Also used : ClassRetransformer(com.newrelic.agent.instrumentation.custom.ClassRetransformer) InstrumentationContextClassMatcherHelper(com.newrelic.agent.instrumentation.context.InstrumentationContextClassMatcherHelper) HashMap(java.util.HashMap) JmxService(com.newrelic.agent.jmx.JmxService) File(java.io.File) HashSet(java.util.HashSet) ReinstrumentResult(com.newrelic.agent.reinstrument.ReinstrumentResult)

Example 2 with ReinstrumentResult

use of com.newrelic.agent.reinstrument.ReinstrumentResult in project newrelic-java-agent by newrelic.

the class HighSecurityRemoteInstTest method testHighSecurityRemoteInstTest.

@Test
public void testHighSecurityRemoteInstTest() {
    ReinstrumentResult result = runTest(true);
    Assert.assertNotNull(result.getStatusMap().get("errors"));
    String errors = (String) result.getStatusMap().get("errors");
    Assert.assertTrue("Error does not contain high security. Error: " + errors, errors.contains("not supported in high security"));
    Assert.assertEquals(0, result.getStatusMap().get("pointcuts_specified"));
}
Also used : ReinstrumentResult(com.newrelic.agent.reinstrument.ReinstrumentResult) Test(org.junit.Test)

Example 3 with ReinstrumentResult

use of com.newrelic.agent.reinstrument.ReinstrumentResult in project newrelic-java-agent by newrelic.

the class HighSecurityRemoteInstTest method testNoHighSecurityRemoteInstTest.

@Test
public void testNoHighSecurityRemoteInstTest() throws Exception {
    ReinstrumentResult result = runTest(false);
    // this is going to have an error, but the point cut count will get set which should not happen in high security
    Assert.assertEquals(1, result.getStatusMap().get("pointcuts_specified"));
}
Also used : ReinstrumentResult(com.newrelic.agent.reinstrument.ReinstrumentResult) Test(org.junit.Test)

Aggregations

ReinstrumentResult (com.newrelic.agent.reinstrument.ReinstrumentResult)3 Test (org.junit.Test)2 InstrumentationContextClassMatcherHelper (com.newrelic.agent.instrumentation.context.InstrumentationContextClassMatcherHelper)1 ClassRetransformer (com.newrelic.agent.instrumentation.custom.ClassRetransformer)1 JmxService (com.newrelic.agent.jmx.JmxService)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1