Search in sources :

Example 1 with TaskQueueFactory

use of com.wavefront.agent.queueing.TaskQueueFactory in project java by wavefrontHQ.

the class ReportSourceTagHandlerTest method setup.

@Before
public void setup() {
    mockAgentAPI = EasyMock.createMock(SourceTagAPI.class);
    taskQueueFactory = new TaskQueueFactory() {

        @Override
        public <T extends DataSubmissionTask<T>> TaskQueue<T> getTaskQueue(@Nonnull HandlerKey handlerKey, int threadNum) {
            return null;
        }
    };
    newAgentId = UUID.randomUUID();
    senderTaskFactory = new SenderTaskFactoryImpl(new APIContainer(null, mockAgentAPI, null), newAgentId, taskQueueFactory, null, new DefaultEntityPropertiesFactoryForTesting());
    handlerKey = HandlerKey.of(ReportableEntityType.SOURCE_TAG, "4878");
    sourceTagHandler = new ReportSourceTagHandlerImpl(handlerKey, 10, senderTaskFactory.createSenderTasks(handlerKey), null, blockedLogger);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) TaskQueueFactory(com.wavefront.agent.queueing.TaskQueueFactory) SourceTagAPI(com.wavefront.api.SourceTagAPI) TaskQueue(com.wavefront.agent.queueing.TaskQueue) DefaultEntityPropertiesFactoryForTesting(com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting) Before(org.junit.Before)

Example 2 with TaskQueueFactory

use of com.wavefront.agent.queueing.TaskQueueFactory 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)2 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 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 SSLException (javax.net.ssl.SSLException)1 Before (org.junit.Before)1