Search in sources :

Example 1 with CoreService

use of com.newrelic.agent.core.CoreService in project newrelic-java-agent by newrelic.

the class ServiceManagerTest method dynamicServices.

@Test
public void dynamicServices() throws Exception {
    AgentHelper.initializeConfig();
    CoreService agent = new MockCoreService();
    ConfigService configService = ConfigServiceFactory.createConfigService(mock(Logger.class), false);
    ServiceManager serviceManager = new ServiceManagerImpl(agent, configService);
    Service testService = new TestService("My Service");
    serviceManager.addService(testService);
    Assert.assertEquals(testService, serviceManager.getService(testService.getName()));
    Assert.assertFalse(testService.isStarted());
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) MockCoreService(com.newrelic.agent.MockCoreService) CoreService(com.newrelic.agent.core.CoreService) MockCoreService(com.newrelic.agent.MockCoreService) CoreService(com.newrelic.agent.core.CoreService) MockCoreService(com.newrelic.agent.MockCoreService) ConfigService(com.newrelic.agent.config.ConfigService) Logger(com.newrelic.api.agent.Logger) Test(org.junit.Test)

Example 2 with CoreService

use of com.newrelic.agent.core.CoreService in project newrelic-java-agent by newrelic.

the class Agent method tryToInitializeServiceManager.

private static boolean tryToInitializeServiceManager(Instrumentation inst) {
    try {
        CoreService coreService = new CoreServiceImpl(inst);
        ConfigService configService = ConfigServiceFactory.createConfigService(Agent.LOG, System.getProperty("newrelic.checkconfig") != null);
        ServiceManager serviceManager = new ServiceManagerImpl(coreService, configService);
        ServiceFactory.setServiceManager(serviceManager);
        if (isLicenseKeyEmpty(serviceManager.getConfigService().getDefaultAgentConfig().getLicenseKey())) {
            LOG.error("license_key is empty in the config. Not starting New Relic Agent.");
            return false;
        }
        if (!serviceManager.getConfigService().getDefaultAgentConfig().isAgentEnabled()) {
            LOG.warning("agent_enabled is false in the config. Not starting New Relic Agent.");
            return false;
        }
        // Now that we know the agent is enabled, add the ApiClassTransformer
        BootstrapLoader.forceCorrectNewRelicApi(inst);
        // init problem classes before class transformer service is active
        InitProblemClasses.loadInitialClasses();
    } catch (ForceDisconnectException e) {
        /* Note: Our use of ForceDisconnectException is a bit misleading here as we haven't even tried to connect
             * to RPM at this point (that happens a few lines down when we call serviceManager.start()). This exception
             * comes from ConfigServiceFactory when it attempts to validate the local yml and finds that both HSM and
             * LASP are enabled. The LASP spec says in this scenario that "Shutdown will follow the behavior of the
             * ForceDisconnectException response from "New Relic." Not specifically that we should throw ForceDisconnectException.
             * Perhaps we should throw a different, more accurately named exception, that simply has the same behavior
             * as ForceDisconnectException as it will be replaced by a 410 response code in Protocol 17.
             */
        LOG.log(Level.SEVERE, e.getMessage());
        return false;
    } catch (Throwable t) {
        // this is the last point where we can stop the agent gracefully if something has gone wrong.
        LOG.log(Level.SEVERE, t, "Unable to start the New Relic Agent. Your application will continue to run but it will not be monitored.");
        return false;
    }
    return true;
}
Also used : ServiceManager(com.newrelic.agent.service.ServiceManager) ServiceManagerImpl(com.newrelic.agent.service.ServiceManagerImpl) CoreService(com.newrelic.agent.core.CoreService) CoreServiceImpl(com.newrelic.agent.core.CoreServiceImpl)

Example 3 with CoreService

use of com.newrelic.agent.core.CoreService in project newrelic-java-agent by newrelic.

the class CommandParser method doStart.

@Override
protected void doStart() {
    AgentConfig config = ServiceFactory.getConfigService().getDefaultAgentConfig();
    CoreService coreService = ServiceFactory.getCoreService();
    addCommands(new ShutdownCommand(coreService), new RestartCommand());
    updateCommandParserConfig(config);
    if (isEnabled()) {
        ServiceFactory.getHarvestService().addHarvestListener(this);
    } else {
        getLogger().log(Level.CONFIG, "The command parser is disabled");
    }
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) CoreService(com.newrelic.agent.core.CoreService)

Example 4 with CoreService

use of com.newrelic.agent.core.CoreService in project newrelic-java-agent by newrelic.

the class W3CTraceContextCrossAgentTest method setup.

@Before
public void setup() throws Exception {
    savedInstrumentation = AgentBridge.instrumentation;
    savedAgent = AgentBridge.agent;
    serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    Map<String, Object> config = Maps.newHashMap();
    config.put(AgentConfigImpl.APP_NAME, APP_NAME);
    Map<String, Object> dtConfig = Maps.newHashMap();
    dtConfig.put("enabled", true);
    dtConfig.put("exclude_newrelic_header", true);
    config.put("distributed_tracing", dtConfig);
    Map<String, Object> spanConfig = Maps.newHashMap();
    spanConfig.put("collect_span_events", true);
    config.put("span_events", spanConfig);
    ConfigService configService = setupConfig(config);
    serviceManager.setTransactionTraceService(new TransactionTraceService());
    serviceManager.setTransactionService(new TransactionService());
    distributedTraceService = new DistributedTraceServiceImpl();
    transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
    serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
    serviceManager.setHarvestService(new HarvestServiceImpl());
    statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    serviceManager.setEnvironmentService(new EnvironmentServiceImpl());
    serviceManager.setAttributesService(new AttributesService());
    AgentBridge.instrumentation = new InstrumentationImpl(Agent.LOG);
    AgentBridge.agent = new AgentImpl(Agent.LOG);
    CoreService coreService = Mockito.mock(CoreService.class);
    when(coreService.isEnabled()).thenReturn(true);
    serviceManager.setCoreService(coreService);
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    ServiceFactory.getServiceManager().start();
    ServiceFactory.getTransactionService().addTransactionListener(distributedTraceService);
    spanEventService = createSpanEventService(configService, transactionDataToDistributedTraceIntrinsics);
    serviceManager.setDistributedTraceService(distributedTraceService);
    serviceManager.setSpansEventService(spanEventService);
}
Also used : InstrumentationImpl(com.newrelic.agent.instrumentation.InstrumentationImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) CoreService(com.newrelic.agent.core.CoreService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) JSONObject(org.json.simple.JSONObject) Before(org.junit.Before)

Aggregations

CoreService (com.newrelic.agent.core.CoreService)4 MockCoreService (com.newrelic.agent.MockCoreService)1 AttributesService (com.newrelic.agent.attributes.AttributesService)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 ConfigService (com.newrelic.agent.config.ConfigService)1 CoreServiceImpl (com.newrelic.agent.core.CoreServiceImpl)1 EnvironmentServiceImpl (com.newrelic.agent.environment.EnvironmentServiceImpl)1 InstrumentationImpl (com.newrelic.agent.instrumentation.InstrumentationImpl)1 ServiceManager (com.newrelic.agent.service.ServiceManager)1 ServiceManagerImpl (com.newrelic.agent.service.ServiceManagerImpl)1 TransactionDataToDistributedTraceIntrinsics (com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics)1 TransactionEventsService (com.newrelic.agent.service.analytics.TransactionEventsService)1 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)1 Logger (com.newrelic.api.agent.Logger)1 JSONObject (org.json.simple.JSONObject)1 Before (org.junit.Before)1 Test (org.junit.Test)1