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);
}
}
}
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"));
}
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"));
}
Aggregations