Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.hop.workflow.config.IWorkflowEngineRunConfiguration;
import org.apache.hop.workflow.config.WorkflowRunConfiguration;
import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
import org.apache.hop.workflow.engines.remote.RemoteWorkflowEngine;

public class WorkflowEngineFactory {

Expand Down Expand Up @@ -106,6 +107,8 @@ private static final <T extends WorkflowMeta> IWorkflowEngine<T> createWorkflowE

if (workflowEngine instanceof LocalWorkflowEngine localWorkflowEngine) {
localWorkflowEngine.setParentLoggingObject(parentLogging);
} else if (workflowEngine instanceof RemoteWorkflowEngine remoteWorkflowEngine) {
remoteWorkflowEngine.setParentLoggingObject(parentLogging);
}
workflowEngine.setWorkflowMeta(workflowMeta);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ protected IPipelineEngine<PipelineMeta> createPipeline(
variables, variables.resolve(runConfigurationName), metadataProvider, pipelineMeta);
pipeline.setParent(servletLoggingObject);
pipeline.setMetadataProvider(metadataProvider);
pipeline.setLogLevel(pipelineExecutionConfiguration.getLogLevel());

// Also copy the parameters over...
copyParameters(pipeline, pipelineExecutionConfiguration.getParametersMap());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hop.workflow.engine;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;

import org.apache.hop.core.HopEnvironment;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.logging.LogLevel;
import org.apache.hop.core.logging.LoggingObjectType;
import org.apache.hop.core.logging.SimpleLoggingObject;
import org.apache.hop.core.variables.Variables;
import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
import org.apache.hop.workflow.WorkflowMeta;
import org.apache.hop.workflow.config.IWorkflowEngineRunConfiguration;
import org.apache.hop.workflow.config.WorkflowRunConfiguration;
import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
import org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration;
import org.apache.hop.workflow.engines.remote.RemoteWorkflowEngine;
import org.apache.hop.workflow.engines.remote.RemoteWorkflowRunConfiguration;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

class WorkflowEngineFactoryTest {

@BeforeAll
static void setUpBeforeClass() throws HopException {
HopEnvironment.init();
}

/**
* The parent logging object is how the log level is pushed down into the engine. A workflow that
* runs on a server needs it as much as one that runs locally, or the server ends up logging at
* Basic whatever level was asked for. See issue #3173.
*/
@Test
void remoteEngineKeepsTheParentLoggingObject() throws Exception {
SimpleLoggingObject parent = createParent();

RemoteWorkflowEngine engine =
assertInstanceOf(
RemoteWorkflowEngine.class,
createEngine("Remote", new RemoteWorkflowRunConfiguration(), parent));

assertSame(parent, engine.getParent());
assertEquals(LogLevel.DEBUG, engine.getParent().getLogLevel());
}

/** The local engine has always been given the parent, this makes sure it keeps it. */
@Test
void localEngineKeepsTheParentLoggingObject() throws Exception {
SimpleLoggingObject parent = createParent();

LocalWorkflowEngine engine =
assertInstanceOf(
LocalWorkflowEngine.class,
createEngine("Local", new LocalWorkflowRunConfiguration(), parent));

assertSame(parent, engine.getParent());
}

private SimpleLoggingObject createParent() {
SimpleLoggingObject parent =
new SimpleLoggingObject("a-parent", LoggingObjectType.HOP_GUI, null);
parent.setLogLevel(LogLevel.DEBUG);
return parent;
}

/**
* @param enginePluginId the id of the workflow engine plugin to run with, normally filled in when
* the run configuration is read from its metadata
*/
private IWorkflowEngine<WorkflowMeta> createEngine(
String enginePluginId,
IWorkflowEngineRunConfiguration engineRunConfiguration,
SimpleLoggingObject parent)
throws HopException {
engineRunConfiguration.setEnginePluginId(enginePluginId);

String name = "a-" + enginePluginId + "-run-configuration";
MemoryMetadataProvider metadataProvider = new MemoryMetadataProvider();
metadataProvider
.getSerializer(WorkflowRunConfiguration.class)
.save(new WorkflowRunConfiguration(name, "", null, engineRunConfiguration, false));

return WorkflowEngineFactory.createWorkflowEngine(
new Variables(), name, metadataProvider, new WorkflowMeta(), parent);
}
}
101 changes: 101 additions & 0 deletions integration-tests/hop_server/0011-loglevel.hpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<pipeline>
<info>
<name>0011-loglevel</name>
<name_sync_with_filename>Y</name_sync_with_filename>
<description>Writes a message to the log at the Debug level. When this pipeline is executed on a
server with a Debug log level, the message shows up in the log of that server. When the log
level is not carried over to the server, the server runs at Basic and swallows the message.
See issue #3173.</description>
<extended_description/>
<pipeline_version/>
<pipeline_type>Normal</pipeline_type>
<parameters>
</parameters>
<capture_transform_performance>N</capture_transform_performance>
<transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
<transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
<created_user>-</created_user>
<created_date>2024/01/01 00:00:00.000</created_date>
<modified_user>-</modified_user>
<modified_date>2024/01/01 00:00:00.000</modified_date>
</info>
<notepads>
</notepads>
<order>
<hop>
<from>Generate a row</from>
<to>Write debug message</to>
<enabled>Y</enabled>
</hop>
</order>
<transform>
<name>Generate a row</name>
<type>RowGenerator</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<fields>
</fields>
<interval_in_ms>5000</interval_in_ms>
<last_time_field/>
<never_ending>N</never_ending>
<limit>1</limit>
<row_time_field/>
<attributes/>
<GUI>
<xloc>48</xloc>
<yloc>80</yloc>
</GUI>
</transform>
<transform>
<name>Write debug message</name>
<type>WriteToLog</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<displayHeader>N</displayHeader>
<fields>
</fields>
<limitRows>N</limitRows>
<limitRowsNumber>0</limitRowsNumber>
<loglevel>Debug</loglevel>
<logmessage>LOGLEVEL-MARKER-3173</logmessage>
<attributes/>
<GUI>
<xloc>224</xloc>
<yloc>80</yloc>
</GUI>
</transform>
<transform_error_handling>
</transform_error_handling>
<attributes/>
</pipeline>
80 changes: 80 additions & 0 deletions integration-tests/hop_server/0012-loglevel-workflow.hwf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<workflow>
<name>0012-loglevel-workflow</name>
<name_sync_with_filename>Y</name_sync_with_filename>
<description>Writes a message to the log at the Debug level. When this workflow is executed on a
server with a Debug log level, the message shows up in the log of that server. When the log
level is not carried over to the server, the server runs at Basic and swallows the message.
See issue #3173.</description>
<extended_description/>
<workflow_version/>
<created_user>-</created_user>
<created_date>2024/01/01 00:00:00.000</created_date>
<modified_user>-</modified_user>
<modified_date>2024/01/01 00:00:00.000</modified_date>
<parameters>
</parameters>
<actions>
<action>
<name>Start</name>
<description/>
<type>SPECIAL</type>
<attributes/>
<DayOfMonth>1</DayOfMonth>
<hour>12</hour>
<intervalMinutes>60</intervalMinutes>
<intervalSeconds>0</intervalSeconds>
<minutes>0</minutes>
<repeat>N</repeat>
<schedulerType>0</schedulerType>
<weekDay>1</weekDay>
<parallel>N</parallel>
<xloc>50</xloc>
<yloc>50</yloc>
<attributes_hac/>
</action>
<action>
<name>Write debug message</name>
<description/>
<type>WRITE_TO_LOG</type>
<attributes/>
<loglevel>Debug</loglevel>
<logmessage>LOGLEVEL-MARKER-3173-WORKFLOW</logmessage>
<logsubject/>
<parallel>N</parallel>
<xloc>250</xloc>
<yloc>50</yloc>
<attributes_hac/>
</action>
</actions>
<hops>
<hop>
<from>Start</from>
<to>Write debug message</to>
<enabled>Y</enabled>
<evaluation>Y</evaluation>
<unconditional>Y</unconditional>
</hop>
</hops>
<notepads>
</notepads>
<attributes/>
</workflow>
Loading
Loading