Search in sources :

Example 11 with APIContainer

use of com.wavefront.agent.api.APIContainer in project java by wavefrontHQ.

the class AbstractAgent method start.

/**
 * Entry-point for the application.
 *
 * @param args Command-line parameters passed on to JCommander to configure the daemon.
 */
public void start(String[] args) {
    try {
        /* ------------------------------------------------------------------------------------
       * Configuration Setup.
       * ------------------------------------------------------------------------------------ */
        // Parse commandline arguments and load configuration file
        parseArguments(args);
        postProcessConfig();
        initSslContext();
        initPreprocessors();
        if (proxyConfig.isTestLogs() || proxyConfig.getTestPreprocessorForPort() != null || proxyConfig.getTestSpanPreprocessorForPort() != null) {
            InteractiveTester interactiveTester;
            if (proxyConfig.isTestLogs()) {
                logger.info("Reading line-by-line sample log messages from STDIN");
                interactiveTester = new InteractiveLogsTester(this::loadLogsIngestionConfig, proxyConfig.getPrefix());
            } else if (proxyConfig.getTestPreprocessorForPort() != null) {
                logger.info("Reading line-by-line points from STDIN");
                interactiveTester = new InteractivePreprocessorTester(preprocessors.get(proxyConfig.getTestPreprocessorForPort()), ReportableEntityType.POINT, proxyConfig.getTestPreprocessorForPort(), proxyConfig.getCustomSourceTags());
            } else if (proxyConfig.getTestSpanPreprocessorForPort() != null) {
                logger.info("Reading line-by-line spans from STDIN");
                interactiveTester = new InteractivePreprocessorTester(preprocessors.get(String.valueOf(proxyConfig.getTestPreprocessorForPort())), ReportableEntityType.TRACE, proxyConfig.getTestPreprocessorForPort(), proxyConfig.getCustomSourceTags());
            } else {
                throw new IllegalStateException();
            }
            // noinspection StatementWithEmptyBody
            while (interactiveTester.interactiveTest()) {
            // empty
            }
            System.exit(0);
        }
        // If we are exporting data from the queue, run export and exit
        if (proxyConfig.getExportQueueOutputFile() != null && proxyConfig.getExportQueuePorts() != null) {
            TaskQueueFactory tqFactory = new TaskQueueFactoryImpl(proxyConfig.getBufferFile(), false, false, proxyConfig.getBufferShardSize());
            EntityPropertiesFactory epFactory = new EntityPropertiesFactoryImpl(proxyConfig);
            QueueExporter queueExporter = new QueueExporter(proxyConfig.getBufferFile(), proxyConfig.getExportQueuePorts(), proxyConfig.getExportQueueOutputFile(), proxyConfig.isExportQueueRetainData(), tqFactory, epFactory);
            logger.info("Starting queue export for ports: " + proxyConfig.getExportQueuePorts());
            queueExporter.export();
            logger.info("Done");
            System.exit(0);
        }
        // 2. Read or create the unique Id for the daemon running on this machine.
        agentId = getOrCreateProxyId(proxyConfig);
        apiContainer = new APIContainer(proxyConfig, proxyConfig.isUseNoopSender());
        // Perform initial proxy check-in and schedule regular check-ins (once a minute)
        proxyCheckinScheduler = new ProxyCheckInScheduler(agentId, proxyConfig, apiContainer, this::processConfiguration, () -> System.exit(1), this::truncateBacklog);
        proxyCheckinScheduler.scheduleCheckins();
        // Start the listening endpoints
        startListeners();
        Timer startupTimer = new Timer("Timer-startup");
        shutdownTasks.add(startupTimer::cancel);
        startupTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                // exit if no active listeners
                if (activeListeners.count() == 0) {
                    logger.severe("**** All listener threads failed to start - there is already a " + "running instance listening on configured ports, or no listening ports " + "configured!");
                    logger.severe("Aborting start-up");
                    System.exit(1);
                }
                Runtime.getRuntime().addShutdownHook(new Thread("proxy-shutdown-hook") {

                    @Override
                    public void run() {
                        shutdown();
                    }
                });
                logger.info("setup complete");
            }
        }, 5000);
    } catch (Exception e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        // logger.severe(e.getMessage());
        System.exit(1);
    }
}
Also used : TaskQueueFactoryImpl(com.wavefront.agent.queueing.TaskQueueFactoryImpl) TaskQueueFactory(com.wavefront.agent.queueing.TaskQueueFactory) QueueExporter(com.wavefront.agent.queueing.QueueExporter) EntityPropertiesFactory(com.wavefront.agent.data.EntityPropertiesFactory) UnrecognizedPropertyException(com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) ParameterException(com.beust.jcommander.ParameterException) FileNotFoundException(java.io.FileNotFoundException) SSLException(javax.net.ssl.SSLException) APIContainer(com.wavefront.agent.api.APIContainer) InteractiveLogsTester(com.wavefront.agent.logsharvesting.InteractiveLogsTester) Timer(java.util.Timer) TimerTask(java.util.TimerTask) EntityPropertiesFactoryImpl(com.wavefront.agent.data.EntityPropertiesFactoryImpl) InteractivePreprocessorTester(com.wavefront.agent.preprocessor.InteractivePreprocessorTester)

Aggregations

APIContainer (com.wavefront.agent.api.APIContainer)11 ProxyV2API (com.wavefront.api.ProxyV2API)9 AgentConfiguration (com.wavefront.api.agent.AgentConfiguration)9 UUID (java.util.UUID)9 Test (org.junit.Test)9 ClientErrorException (javax.ws.rs.ClientErrorException)5 TaskQueueFactory (com.wavefront.agent.queueing.TaskQueueFactory)2 ParameterException (com.beust.jcommander.ParameterException)1 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 DefaultEntityPropertiesFactoryForTesting (com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting)1 EntityPropertiesFactory (com.wavefront.agent.data.EntityPropertiesFactory)1 EntityPropertiesFactoryImpl (com.wavefront.agent.data.EntityPropertiesFactoryImpl)1 InteractiveLogsTester (com.wavefront.agent.logsharvesting.InteractiveLogsTester)1 InteractivePreprocessorTester (com.wavefront.agent.preprocessor.InteractivePreprocessorTester)1 QueueExporter (com.wavefront.agent.queueing.QueueExporter)1 TaskQueue (com.wavefront.agent.queueing.TaskQueue)1 TaskQueueFactoryImpl (com.wavefront.agent.queueing.TaskQueueFactoryImpl)1 SourceTagAPI (com.wavefront.api.SourceTagAPI)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1