Search in sources :

Example 1 with LoggingHierarchy

use of org.apache.hop.core.logging.LoggingHierarchy in project hop by apache.

the class PipelineLoggingExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, IPipelineEngine<PipelineMeta> pipeline) throws HopException {
    // 
    if (!LoggingCore.isEnabled(pipeline)) {
        return;
    }
    // Keep the start date
    // 
    pipeline.getExtensionDataMap().put(PIPELINE_START_DATE, new Date());
    String connectionName = pipeline.getVariable(Defaults.VARIABLE_NEO4J_LOGGING_CONNECTION);
    try {
        final NeoConnection connection = LoggingCore.getConnection(pipeline.getMetadataProvider(), pipeline);
        if (connection == null) {
            log.logBasic("Warning! Unable to find Neo4j connection to log to : " + connectionName);
            return;
        }
        log.logDetailed("Logging pipeline information to Neo4j connection : " + connection.getName());
        final Driver driver = connection.getDriver(log, variables);
        final Session session = connection.getSession(log, driver, variables);
        logPipelineMetadata(log, session, connection, pipeline);
        logStartOfPipeline(log, session, connection, pipeline);
        pipeline.addExecutionFinishedListener(pipelineEngine -> {
            logEndOfPipeline(log, session, connection, pipelineEngine);
            // 
            if (pipelineEngine.getParentWorkflow() == null && pipelineEngine.getParentPipeline() == null) {
                String logChannelId = pipelineEngine.getLogChannelId();
                List<LoggingHierarchy> loggingHierarchy = LoggingCore.getLoggingHierarchy(logChannelId);
                logHierarchy(log, session, connection, loggingHierarchy, logChannelId);
            }
            // 
            if (session != null) {
                session.close();
            }
            if (driver != null) {
                driver.close();
            }
        });
    } catch (Exception e) {
        // Let's not kill the pipeline just yet, just log the error
        // otherwise: throw new HopException(...)
        // 
        log.logError("Error logging to Neo4j:", e);
    }
}
Also used : LoggingHierarchy(org.apache.hop.core.logging.LoggingHierarchy) NeoConnection(org.apache.hop.neo4j.shared.NeoConnection) Driver(org.neo4j.driver.Driver) HopException(org.apache.hop.core.exception.HopException) Session(org.neo4j.driver.Session)

Aggregations

HopException (org.apache.hop.core.exception.HopException)1 LoggingHierarchy (org.apache.hop.core.logging.LoggingHierarchy)1 NeoConnection (org.apache.hop.neo4j.shared.NeoConnection)1 Driver (org.neo4j.driver.Driver)1 Session (org.neo4j.driver.Session)1