private static void publishLogs(LogPublisherManager logPublisherManager) { // check if enabled if (DataPublisherConfiguration.getInstance().isEnabled()) { List<String> logFilePaths = CartridgeAgentConfiguration.getInstance().getLogFilePaths(); if (logFilePaths == null) { log.error("No valid log file paths found, no logs will be published"); } else { // initialize the log publishing try { logPublisherManager.init(DataPublisherConfiguration.getInstance()); } catch (DataPublisherException e) { log.error("Error occurred in log publisher initialization", e); return; } // start a log publisher for each file path for (String logFilePath : logFilePaths) { try { logPublisherManager.start(logFilePath); } catch (DataPublisherException e) { log.error("Error occurred in publishing logs ", e); } } } } }
@Override public void run() { if (log.isInfoEnabled()) { log.info("Cartridge agent started"); } eventListenerns = new CartridgeAgentEventListeners(); validateRequiredSystemProperties(); if (log.isInfoEnabled()) { log.info("Cartridge agent validated system properties done"); } // Start topology event receiver thread registerTopologyEventListeners(); if (log.isInfoEnabled()) { log.info("Cartridge agent registerTopologyEventListeners done"); } if (log.isInfoEnabled()) { log.info("Waiting for CompleteTopologyEvent.."); } ExtensionUtils.waitForCompleteTopology(); if (log.isInfoEnabled()) { log.info("CompleteTopologyEvent received."); } // wait till the member spawned event while (!CartridgeAgentConfiguration.getInstance().isInitialized()) { try { if (log.isDebugEnabled()) { log.info("Waiting for Cartridge Agent to be initialized..."); } Thread.sleep(1000); } catch (InterruptedException ignore) { } } if (log.isInfoEnabled()) { log.info("Cartridge agent initialized done"); } // Start instance notifier listener thread registerInstanceNotifierEventListeners(); if (log.isInfoEnabled()) { log.info("Cartridge agent registerInstanceNotifierEventListeners done"); } // Start tenant event receiver thread /* registerTenantEventListeners(); if (log.isInfoEnabled()) { log.info("Cartridge agent registerTenantEventListeners done"); } */ // Start application event receiver thread registerApplicationEventListeners(); if (log.isInfoEnabled()) { log.info("Cartridge agent registering all event listeners ... done"); } // Execute instance started shell script extensionHandler.onInstanceStartedEvent(); if (log.isInfoEnabled()) { log.info("Cartridge agent onInstanceStartedEvent done"); } // Publish instance started event CartridgeAgentEventPublisher.publishInstanceStartedEvent(); // Execute start servers extension try { extensionHandler.startServerExtension(); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Error processing start servers event", e); } } if (log.isInfoEnabled()) { log.info("Cartridge agent startServerExtension done"); } // Check repo url String repoUrl = CartridgeAgentConfiguration.getInstance().getRepoUrl(); if (log.isInfoEnabled()) { log.info("Cartridge agent getRepoUrl done"); } if ("null".equals(repoUrl) || StringUtils.isBlank(repoUrl)) { if (log.isInfoEnabled()) { log.info("No artifact repository found. Publishing InstanceActivatedEvent."); } // Publish instance activated event CartridgeAgentEventPublisher.publishInstanceActivatedEvent(); // Execute instance activated shell script extensionHandler.onInstanceActivatedEvent(); if (log.isInfoEnabled()) { log.info("Cartridge agent onInstanceActivatedEvent done"); } } else { if (log.isInfoEnabled()) { log.info( "Artifact repository found. Waiting for ArtifactUpdatedEvent to commence cloning."); } } String persistenceMappingsPayload = CartridgeAgentConfiguration.getInstance().getPersistenceMappings(); if (persistenceMappingsPayload != null) { extensionHandler.volumeMountExtension(persistenceMappingsPayload); } // start log publishing LogPublisherManager logPublisherManager = new LogPublisherManager(); publishLogs(logPublisherManager); // Keep the thread live until terminated while (!terminated) { try { Thread.sleep(1000); } catch (InterruptedException ignore) { } } logPublisherManager.stop(); }