From 4177e6815affc26531fa7defdb86e88bbd5447dd Mon Sep 17 00:00:00 2001 From: Vasilii_Komarov Date: Wed, 14 Feb 2018 10:16:32 +0400 Subject: [PATCH] [PDI-17019] PDI 8.0 server run configuration settings are ignored - The new fields for storing parameters have been added into AbstractMeta and JobMeta classes - The updating of executionConfiguration have been added into SpoonJobDelegate and SpoonTransformationDelegate classes - The schedule request generating has been fixed --- .../org/pentaho/di/base/AbstractMeta.java | 29 +++- .../main/java/org/pentaho/di/job/JobMeta.java | 20 +++ .../pentaho/scheduler/SchedulerRequest.java | 100 ++++++++++--- .../scheduler/SchedulerRequestTest.java | 138 ++++++++++++++++-- .../ui/spoon/delegates/SpoonJobDelegate.java | 61 +++++--- .../SpoonTransformationDelegate.java | 13 +- .../spoon/delegates/SpoonJobDelegateTest.java | 77 +++++++++- .../SpoonTransformationDelegateTest.java | 20 ++- 8 files changed, 395 insertions(+), 63 deletions(-) diff --git a/engine/src/main/java/org/pentaho/di/base/AbstractMeta.java b/engine/src/main/java/org/pentaho/di/base/AbstractMeta.java index 97d85cb148de..0baea4f48f97 100644 --- a/engine/src/main/java/org/pentaho/di/base/AbstractMeta.java +++ b/engine/src/main/java/org/pentaho/di/base/AbstractMeta.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -198,6 +198,8 @@ public abstract class AbstractMeta implements ChangedFlagInterface, UndoInterfac protected int undo_position; + protected RunOptions runOptions = new RunOptions(); + private boolean showDialog = true; private boolean alwaysShowRunOptions = true; @@ -2090,4 +2092,29 @@ public Boolean getVersioningEnabled() { return this.versioningEnabled; } + private class RunOptions { + boolean clearingLog; + boolean safeModeEnabled; + + RunOptions() { + clearingLog = true; + safeModeEnabled = false; + } + } + + public boolean isClearingLog() { + return runOptions.clearingLog; + } + + public void setClearingLog( boolean clearingLog ) { + this.runOptions.clearingLog = clearingLog; + } + + public boolean isSafeModeEnabled() { + return runOptions.safeModeEnabled; + } + + public void setSafeModeEnabled( boolean safeModeEnabled ) { + this.runOptions.safeModeEnabled = safeModeEnabled; + } } diff --git a/engine/src/main/java/org/pentaho/di/job/JobMeta.java b/engine/src/main/java/org/pentaho/di/job/JobMeta.java index 133da2eefcf7..e0d934a10ec1 100644 --- a/engine/src/main/java/org/pentaho/di/job/JobMeta.java +++ b/engine/src/main/java/org/pentaho/di/job/JobMeta.java @@ -147,6 +147,10 @@ public class JobMeta extends AbstractMeta protected List extraLogTables; + protected String startCopyName; + + protected boolean expandingRemoteJob; + /** The log channel interface. */ protected LogChannelInterface log; @@ -2821,4 +2825,20 @@ public NamedClusterEmbedManager getNamedClusterEmbedManager( ) { } return namedClusterEmbedManager; } + + public String getStartCopyName() { + return startCopyName; + } + + public void setStartCopyName( String startCopyName ) { + this.startCopyName = startCopyName; + } + + public boolean isExpandingRemoteJob() { + return expandingRemoteJob; + } + + public void setExpandingRemoteJob( boolean expandingRemoteJob ) { + this.expandingRemoteJob = expandingRemoteJob; + } } diff --git a/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequest.java b/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequest.java index 3cb7911500e1..7789e8dc33db 100644 --- a/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequest.java +++ b/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequest.java @@ -1,26 +1,24 @@ -/* - * ***************************************************************************** +/*! ****************************************************************************** * - * Pentaho Data Integration + * Pentaho Data Integration * - * Copyright (C) 2017 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com * - * ******************************************************************************* - * Licensed 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 + * Licensed 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 * - * 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. + * 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.pentaho.di.engine.configuration.impl.pentaho.scheduler; @@ -31,6 +29,7 @@ import org.pentaho.di.base.AbstractMeta; import org.pentaho.di.core.parameters.UnknownParamException; import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.job.JobMeta; import org.pentaho.di.repository.Repository; import java.io.UnsupportedEncodingException; @@ -135,14 +134,69 @@ StringEntity buildSchedulerRequestEntity( AbstractMeta meta ) StringBuilder sb = new StringBuilder(); sb.append( "\n" ); sb.append( "" ).append( filename ).append( "\n" ); - sb.append( "\n" ); - for ( String param : meta.listParameters() ) { - sb.append( "\n" ); - sb.append( "" ).append( param ).append( "\n" ); - sb.append( "" ).append( meta.getParameterValue( param ) ).append( "\n" ); - sb.append( "\n" ); + + // Set the log level + if ( meta.getLogLevel() != null ) { + sb.append( "\n" ); + sb.append( "" ).append( "logLevel" ).append( "\n" ); + sb.append( "" ).append( "string" ).append( "\n" ); + sb.append( "" ).append( meta.getLogLevel().getCode() ).append( "\n" ); + sb.append( "\n" ); + } + + // Set the clearing log param + sb.append( "\n" ); + sb.append( "" ).append( "clearLog" ).append( "\n" ); + sb.append( "" ).append( "string" ).append( "\n" ); + sb.append( "" ).append( meta.isClearingLog() ).append( "\n" ); + sb.append( "\n" ); + + // Set the safe mode enabled param + sb.append( "\n" ); + sb.append( "" ).append( "runSafeMode" ).append( "\n" ); + sb.append( "" ).append( "string" ).append( "\n" ); + sb.append( "" ).append( meta.isSafeModeEnabled() ).append( "\n" ); + sb.append( "\n" ); + + // Set the gathering metrics param + sb.append( "\n" ); + sb.append( "" ).append( "gatheringMetrics" ).append( "\n" ); + sb.append( "" ).append( "string" ).append( "\n" ); + sb.append( "" ).append( meta.isGatheringMetrics() ).append( "\n" ); + sb.append( "\n" ); + + if ( meta instanceof JobMeta ) { + JobMeta jobMeta = (JobMeta) meta; + + if ( jobMeta.getStartCopyName() != null ) { + // Set the start step name + sb.append( "\n" ); + sb.append( "" ).append( "startCopyName" ).append( "\n" ); + sb.append( "" ).append( "string" ).append( "\n" ); + sb.append( "" ).append( jobMeta.getStartCopyName() ).append( "\n" ); + sb.append( "\n" ); + } + + // Set the expanding remote job param + sb.append( "\n" ); + sb.append( "" ).append( "expandingRemoteJob" ).append( "\n" ); + sb.append( "" ).append( "string" ).append( "\n" ); + sb.append( "" ).append( jobMeta.isExpandingRemoteJob() ).append( "\n" ); + sb.append( "\n" ); } - sb.append( "\n" ); + + // Set the PDI parameters + if ( meta.listParameters() != null ) { + sb.append( "\n" ); + for ( String param : meta.listParameters() ) { + sb.append( "\n" ); + sb.append( "" ).append( param ).append( "\n" ); + sb.append( "" ).append( meta.getParameterValue( param ) ).append( "\n" ); + sb.append( "\n" ); + } + sb.append( "\n" ); + } + sb.append( "" ); return new StringEntity( sb.toString() ); diff --git a/plugins/engine-configuration/impl/src/test/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequestTest.java b/plugins/engine-configuration/impl/src/test/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequestTest.java index 5dd14fd2f976..592425733267 100644 --- a/plugins/engine-configuration/impl/src/test/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequestTest.java +++ b/plugins/engine-configuration/impl/src/test/java/org/pentaho/di/engine/configuration/impl/pentaho/scheduler/SchedulerRequestTest.java @@ -1,22 +1,104 @@ +/*! ****************************************************************************** + * + * Pentaho Data Integration + * + * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com + * + ******************************************************************************* + * + * Licensed 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.pentaho.di.engine.configuration.impl.pentaho.scheduler; +import org.apache.http.entity.StringEntity; import org.junit.Before; import org.junit.Test; import org.pentaho.di.base.AbstractMeta; +import org.pentaho.di.core.logging.LogLevel; import org.pentaho.di.core.parameters.UnknownParamException; +import org.pentaho.di.job.JobMeta; import org.pentaho.di.repository.RepositoryDirectoryInterface; +import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.doReturn; public class SchedulerRequestTest { - private static final String EMPTY_STRING = ""; - private static final String TEST_PARAM_NAME = "paramName"; - private static final String[] ARRAY_WITH_PARAM_NAME = new String[]{TEST_PARAM_NAME}; + // input file + private static final String TEST_REPOSITORY_DIRECTORY = "/home/admin"; + private static final String TEST_JOB_NAME = "jobName"; + private static final String JOB_EXTENSION = "kjb"; + + // job parameters + private static final String STRING_PARAM_TYPE = "string"; + private static final String LOG_LEVEL_PARAM_NAME = "logLevel"; + private static final String TEST_LOG_LEVEL_PARAM_VALUE = "Rowlevel"; + private static final String CLEAR_LOG_PARAM_NAME = "clearLog"; + private static final String TEST_CLEAR_LOG_PARAM_VALUE = "true"; + private static final String RUN_SAFE_MODE_PARAM_NAME = "runSafeMode"; + private static final String TEST_RUN_SAFE_MODE_PARAM_VALUE = "false"; + private static final String GATHERING_METRICS_PARAM_NAME = "gatheringMetrics"; + private static final String TEST_GATHERING_METRICS_PARAM_VALUE = "false"; + private static final String START_COPY_NAME_PARAM_NAME = "startCopyName"; + private static final String TEST_START_COPY_NAME_PARAM_VALUE = "stepName"; + private static final String EXPANDING_REMOTE_JOB_PARAM_NAME = "expandingRemoteJob"; + private static final String TEST_EXPANDING_REMOTE_JOB_PARAM_VALUE = "false"; + + // pdi parameters + private static final String TEST_PDI_PARAM_NAME = "paramName"; + private static final String TEST_PDI_PARAM_VALUE = "paramValue"; + private static final String[] ARRAY_WITH_TEST_PDI_PARAM_NAME = new String[]{TEST_PDI_PARAM_NAME}; + + private static final String REFERENCE_TEST_REQUEST = String.format( "\n" + + "%s/%s.%s\n" + + "\n" + + "%s\n" + "%s\n" + "%s\n" + + "\n" + + "\n" + + "%s\n" + "%s\n" + "%s\n" + + "\n" + + "\n" + + "%s\n" + "%s\n" + "%s\n" + + "\n" + + "\n" + + "%s\n" + "%s\n" + "%s\n" + + "\n" + + "\n" + + "%s\n" + "%s\n" + "%s\n" + + "\n" + + "\n" + + "%s\n" + "%s\n" + "%s\n" + + "\n" + + "\n" + + "\n" + + "%s\n" + "%s\n" + + "\n" + + "\n" + + "", TEST_REPOSITORY_DIRECTORY, TEST_JOB_NAME, JOB_EXTENSION, + LOG_LEVEL_PARAM_NAME, STRING_PARAM_TYPE, TEST_LOG_LEVEL_PARAM_VALUE, + CLEAR_LOG_PARAM_NAME, STRING_PARAM_TYPE, TEST_CLEAR_LOG_PARAM_VALUE, + RUN_SAFE_MODE_PARAM_NAME, STRING_PARAM_TYPE, TEST_RUN_SAFE_MODE_PARAM_VALUE, + GATHERING_METRICS_PARAM_NAME, STRING_PARAM_TYPE, TEST_GATHERING_METRICS_PARAM_VALUE, + START_COPY_NAME_PARAM_NAME, STRING_PARAM_TYPE, TEST_START_COPY_NAME_PARAM_VALUE, + EXPANDING_REMOTE_JOB_PARAM_NAME, STRING_PARAM_TYPE, TEST_EXPANDING_REMOTE_JOB_PARAM_VALUE, + TEST_PDI_PARAM_NAME, TEST_PDI_PARAM_VALUE ); private SchedulerRequest schedulerRequest; @@ -28,19 +110,45 @@ public void before() { @Test @SuppressWarnings( "ResultOfMethodCallIgnored" ) public void testBuildSchedulerRequestEntity() throws UnknownParamException, UnsupportedEncodingException { - AbstractMeta abstractMeta = mock( AbstractMeta.class ); - RepositoryDirectoryInterface repositoryDirectoryInterface = mock( RepositoryDirectoryInterface.class ); + AbstractMeta meta = mock( JobMeta.class ); + RepositoryDirectoryInterface repositoryDirectory = mock( RepositoryDirectoryInterface.class ); - doReturn( repositoryDirectoryInterface ).when( abstractMeta ).getRepositoryDirectory(); - doReturn( EMPTY_STRING ).when( repositoryDirectoryInterface ).getPath(); - doReturn( EMPTY_STRING ).when( abstractMeta ).getName(); - doReturn( EMPTY_STRING ).when( abstractMeta ).getDefaultExtension(); - doReturn( ARRAY_WITH_PARAM_NAME ).when( abstractMeta ).listParameters(); + doReturn( repositoryDirectory ).when( meta ).getRepositoryDirectory(); + doReturn( TEST_REPOSITORY_DIRECTORY ).when( repositoryDirectory ).getPath(); + doReturn( TEST_JOB_NAME ).when( meta ).getName(); + doReturn( JOB_EXTENSION ).when( meta ).getDefaultExtension(); - doCallRealMethod().when( schedulerRequest ).buildSchedulerRequestEntity( abstractMeta ); - schedulerRequest.buildSchedulerRequestEntity( abstractMeta ); + doReturn( LogLevel.getLogLevelForCode( TEST_LOG_LEVEL_PARAM_VALUE ) ).when( meta ).getLogLevel(); + doReturn( Boolean.valueOf( TEST_CLEAR_LOG_PARAM_VALUE ) ).when( meta ).isClearingLog(); + doReturn( Boolean.valueOf( TEST_RUN_SAFE_MODE_PARAM_VALUE ) ).when( meta ).isSafeModeEnabled(); + doReturn( Boolean.valueOf( TEST_GATHERING_METRICS_PARAM_VALUE ) ).when( meta ).isGatheringMetrics(); + doReturn( TEST_START_COPY_NAME_PARAM_VALUE ).when( (JobMeta) meta ).getStartCopyName(); + doReturn( Boolean.valueOf( TEST_EXPANDING_REMOTE_JOB_PARAM_VALUE ) ).when( (JobMeta) meta ).isExpandingRemoteJob(); + + doReturn( ARRAY_WITH_TEST_PDI_PARAM_NAME ).when( meta ).listParameters(); + doReturn( TEST_PDI_PARAM_VALUE ).when( meta ).getParameterValue( TEST_PDI_PARAM_NAME ); + + doCallRealMethod().when( schedulerRequest ).buildSchedulerRequestEntity( meta ); + + assertTrue( compareContentOfStringEntities( schedulerRequest.buildSchedulerRequestEntity( meta ), + new StringEntity( REFERENCE_TEST_REQUEST ) ) ); + } - verify( abstractMeta ).listParameters(); - verify( abstractMeta ).getParameterValue( TEST_PARAM_NAME ); + private boolean compareContentOfStringEntities( StringEntity entity1, StringEntity entity2 ) { + if ( entity1.getContentLength() == entity2.getContentLength() ) { + try ( InputStream stream1 = entity1.getContent(); + InputStream stream2 = entity2.getContent() ) { + while ( stream1.available() > 0 ) { + if ( stream1.read() != stream2.read() ) { + return false; + } + } + return true; + } catch ( IOException e ) { + return false; + } + } else { + return false; + } } } diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java index 305ba4a91af4..17db389cc91f 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -22,6 +22,7 @@ package org.pentaho.di.ui.spoon.delegates; +import com.google.common.annotations.VisibleForTesting; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -29,6 +30,7 @@ import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; import org.pentaho.di.core.Const; import org.pentaho.di.core.NotePadMeta; import org.pentaho.di.core.ObjectLocationSpecificationMethod; @@ -1336,14 +1338,47 @@ public void executeJob( JobMeta jobMeta, boolean local, boolean remote, Date rep executionConfiguration.getUsedArguments( jobMeta, spoon.getArguments(), spoon.getMetaStore() ); executionConfiguration.setLogLevel( DefaultLogLevel.getLogLevel() ); - JobExecutionConfigurationDialog dialog = - new JobExecutionConfigurationDialog( spoon.getShell(), executionConfiguration, jobMeta ); + JobExecutionConfigurationDialog dialog = newJobExecutionConfigurationDialog( spoon.getShell(), + executionConfiguration, jobMeta ); if ( !jobMeta.isShowDialog() || dialog.open() ) { JobGraph jobGraph = spoon.getActiveJobGraph(); jobGraph.jobLogDelegate.addJobLog(); + // Set the variables that where specified... + // + for ( String varName : executionConfiguration.getVariables().keySet() ) { + String varValue = executionConfiguration.getVariables().get( varName ); + jobMeta.setVariable( varName, varValue ); + } + + // Set and activate the parameters... + // + for ( String paramName : executionConfiguration.getParams().keySet() ) { + String paramValue = executionConfiguration.getParams().get( paramName ); + jobMeta.setParameterValue( paramName, paramValue ); + } + jobMeta.activateParameters(); + + // Set the log level + // + if ( executionConfiguration.getLogLevel() != null ) { + jobMeta.setLogLevel( executionConfiguration.getLogLevel() ); + } + + // Set the start step name + // + if ( executionConfiguration.getStartCopyName() != null ) { + jobMeta.setStartCopyName( executionConfiguration.getStartCopyName() ); + } + + // Set the run options + // + jobMeta.setClearingLog( executionConfiguration.isClearingLog() ); + jobMeta.setSafeModeEnabled( executionConfiguration.isSafeModeEnabled() ); + jobMeta.setExpandingRemoteJob( executionConfiguration.isExpandingRemoteJob() ); + ExtensionPointHandler.callExtensionPoint( log, KettleExtensionPoint.SpoonJobMetaExecutionStart.id, jobMeta ); ExtensionPointHandler.callExtensionPoint( log, KettleExtensionPoint.SpoonJobExecutionConfiguration.id, executionConfiguration ); @@ -1363,20 +1398,6 @@ public void executeJob( JobMeta jobMeta, boolean local, boolean remote, Date rep } } - // Set the variables that where specified... - // - for ( String varName : executionConfiguration.getVariables().keySet() ) { - String varValue = executionConfiguration.getVariables().get( varName ); - jobMeta.setVariable( varName, varValue ); - } - - // Set and activate the parameters... - // - for ( String paramName : executionConfiguration.getParams().keySet() ) { - String paramValue = executionConfiguration.getParams().get( paramName ); - jobMeta.setParameterValue( paramName, paramValue ); - } - // Is this a local execution? // if ( executionConfiguration.isExecutingLocally() ) { @@ -1402,4 +1423,10 @@ public void executeJob( JobMeta jobMeta, boolean local, boolean remote, Date rep } } } + + @VisibleForTesting + JobExecutionConfigurationDialog newJobExecutionConfigurationDialog( Shell shell, + JobExecutionConfiguration executionConfiguration, JobMeta jobMeta ) { + return new JobExecutionConfigurationDialog( spoon.getShell(), executionConfiguration, jobMeta ); + } } diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegate.java b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegate.java index 6981a4d15ca4..9348449fb19d 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegate.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegate.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -868,6 +868,17 @@ public void executeTransformation( final TransMeta transMeta, final boolean loca } transMeta.activateParameters(); + // Set the log level + // + if ( executionConfiguration.getLogLevel() != null ) { + transMeta.setLogLevel( executionConfiguration.getLogLevel() ); + } + + // Set the run options + transMeta.setClearingLog( executionConfiguration.isClearingLog() ); + transMeta.setSafeModeEnabled( executionConfiguration.isSafeModeEnabled() ); + transMeta.setGatheringMetrics( executionConfiguration.isGatheringMetrics() ); + ExtensionPointHandler.callExtensionPoint( log, KettleExtensionPoint.SpoonTransMetaExecutionStart.id, transMeta ); ExtensionPointHandler.callExtensionPoint( log, KettleExtensionPoint.SpoonTransExecutionConfiguration.id, executionConfiguration ); diff --git a/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegateTest.java b/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegateTest.java index c4e6c47a5534..df2389bc231a 100644 --- a/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegateTest.java +++ b/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegateTest.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2017 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2017-2018 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -22,13 +22,24 @@ package org.pentaho.di.ui.spoon.delegates; +import org.eclipse.swt.widgets.Shell; import org.junit.Before; import org.junit.Test; +import org.pentaho.di.core.RowMetaAndData; +import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.logging.JobLogTable; +import org.pentaho.di.core.logging.LogLevel; +import org.pentaho.di.core.row.RowMetaInterface; +import org.pentaho.di.job.JobExecutionConfiguration; import org.pentaho.di.job.JobMeta; +import org.pentaho.di.ui.job.dialog.JobExecutionConfigurationDialog; import org.pentaho.di.ui.spoon.Spoon; +import org.pentaho.di.ui.spoon.job.JobGraph; +import org.pentaho.di.ui.spoon.job.JobLogDelegate; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -36,8 +47,28 @@ import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; public class SpoonJobDelegateTest { + private static final String[] EMPTY_STRING_ARRAY = new String[]{}; + private static final String TEST_VARIABLE_KEY = "variableKey"; + private static final String TEST_VARIABLE_VALUE = "variableValue"; + private static final Map MAP_WITH_TEST_VARIABLE = new HashMap() { + { + put( TEST_VARIABLE_KEY, TEST_VARIABLE_VALUE ); + } + }; + private static final String TEST_PARAM_KEY = "paramKey"; + private static final String TEST_PARAM_VALUE = "paramValue"; + private static final Map MAP_WITH_TEST_PARAM = new HashMap() { + { + put( TEST_PARAM_KEY, TEST_PARAM_VALUE ); + } + }; + private static final LogLevel TEST_LOG_LEVEL = LogLevel.BASIC; + private static final String TEST_START_COPY_NAME = "startCopyName"; + private static final boolean TEST_BOOLEAN_PARAM = true; + private SpoonJobDelegate delegate; private Spoon spoon; private JobLogTable jobLogTable; @@ -53,6 +84,8 @@ public void before() { spoon = mock( Spoon.class ); spoon.delegates = mock( SpoonDelegates.class ); spoon.delegates.tabs = mock( SpoonTabsDelegate.class ); + spoon.variables = mock( RowMetaAndData.class ); + delegate.spoon = spoon; doReturn( jobMap ).when( delegate ).getJobList(); doReturn( spoon ).when( delegate ).getSpoon(); @@ -68,4 +101,46 @@ public void testAddAndCloseTransformation() { delegate.closeJob( jobMeta ); assertTrue( delegate.addJob( jobMeta ) ); } + + @Test + @SuppressWarnings( "ResultOfMethodCallIgnored" ) + public void testSetParamsIntoMetaInExecuteJob() throws KettleException { + doCallRealMethod().when( delegate ).executeJob( jobMeta, true, false, null, false, + null, 0 ); + + JobExecutionConfiguration jobExecutionConfiguration = mock( JobExecutionConfiguration.class ); + RowMetaInterface rowMeta = mock( RowMetaInterface.class ); + Shell shell = mock( Shell.class ); + JobExecutionConfigurationDialog jobExecutionConfigurationDialog = mock( JobExecutionConfigurationDialog.class ); + JobGraph activeJobGraph = mock( JobGraph.class ); + activeJobGraph.jobLogDelegate = mock( JobLogDelegate.class ); + + + doReturn( jobExecutionConfiguration ).when( spoon ).getJobExecutionConfiguration(); + doReturn( rowMeta ).when( spoon.variables ).getRowMeta(); + doReturn( EMPTY_STRING_ARRAY ).when( rowMeta ).getFieldNames(); + doReturn( shell ).when( spoon ).getShell(); + doReturn( jobExecutionConfigurationDialog ).when( delegate ).newJobExecutionConfigurationDialog( shell, + jobExecutionConfiguration, jobMeta ); + doReturn( activeJobGraph ).when( spoon ).getActiveJobGraph(); + doReturn( MAP_WITH_TEST_VARIABLE ).when( jobExecutionConfiguration ).getVariables(); + doReturn( MAP_WITH_TEST_PARAM ).when( jobExecutionConfiguration ).getParams(); + doReturn( TEST_LOG_LEVEL ).when( jobExecutionConfiguration ).getLogLevel(); + doReturn( TEST_START_COPY_NAME ).when( jobExecutionConfiguration ).getStartCopyName(); + doReturn( TEST_BOOLEAN_PARAM ).when( jobExecutionConfiguration ).isClearingLog(); + doReturn( TEST_BOOLEAN_PARAM ).when( jobExecutionConfiguration ).isSafeModeEnabled(); + doReturn( TEST_BOOLEAN_PARAM ).when( jobExecutionConfiguration ).isExpandingRemoteJob(); + + delegate.executeJob( jobMeta, true, false, null, false, + null, 0 ); + + verify( jobMeta ).setVariable( TEST_VARIABLE_KEY, TEST_VARIABLE_VALUE ); + verify( jobMeta ).setParameterValue( TEST_PARAM_KEY, TEST_PARAM_VALUE ); + verify( jobMeta ).activateParameters(); + verify( jobMeta ).setLogLevel( TEST_LOG_LEVEL ); + verify( jobMeta ).setStartCopyName( TEST_START_COPY_NAME ); + verify( jobMeta ).setClearingLog( TEST_BOOLEAN_PARAM ); + verify( jobMeta ).setSafeModeEnabled( TEST_BOOLEAN_PARAM ); + verify( jobMeta ).setExpandingRemoteJob( TEST_BOOLEAN_PARAM ); + } } diff --git a/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegateTest.java b/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegateTest.java index c7f329db032c..d1298429412b 100644 --- a/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegateTest.java +++ b/ui/src/test/java/org/pentaho/di/ui/spoon/delegates/SpoonTransformationDelegateTest.java @@ -2,7 +2,7 @@ * * Pentaho Data Integration * - * Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com + * Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com * ******************************************************************************* * @@ -59,6 +59,8 @@ public class SpoonTransformationDelegateTest { put( TEST_PARAM_KEY, TEST_PARAM_VALUE ); } }; + private static final LogLevel TEST_LOG_LEVEL = LogLevel.BASIC; + private static final boolean TEST_BOOLEAN_PARAM = true; private SpoonTransformationDelegate delegate; private Spoon spoon; @@ -114,25 +116,33 @@ public void testAddAndCloseTransformation() { @Test @SuppressWarnings( "ResultOfMethodCallIgnored" ) - public void testSetNamedParameters() throws KettleException { + public void testSetParamsIntoMetaInExecuteTransformation() throws KettleException { doCallRealMethod().when( delegate ).executeTransformation( transMeta, true, false, false, false, false, null, false, LogLevel.BASIC ); - RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class ); + RowMetaInterface rowMeta = mock( RowMetaInterface.class ); TransExecutionConfiguration transExecutionConfiguration = mock( TransExecutionConfiguration.class ); TransGraph activeTransGraph = mock( TransGraph.class ); activeTransGraph.transLogDelegate = mock( TransLogDelegate.class ); - doReturn( rowMetaInterface ).when( spoon.variables ).getRowMeta(); - doReturn( EMPTY_STRING_ARRAY ).when( rowMetaInterface ).getFieldNames(); + doReturn( rowMeta ).when( spoon.variables ).getRowMeta(); + doReturn( EMPTY_STRING_ARRAY ).when( rowMeta ).getFieldNames(); doReturn( transExecutionConfiguration ).when( spoon ).getTransExecutionConfiguration(); doReturn( MAP_WITH_TEST_PARAM ).when( transExecutionConfiguration ).getParams(); doReturn( activeTransGraph ).when( spoon ).getActiveTransGraph(); + doReturn( TEST_LOG_LEVEL ).when( transExecutionConfiguration ).getLogLevel(); + doReturn( TEST_BOOLEAN_PARAM ).when( transExecutionConfiguration ).isClearingLog(); + doReturn( TEST_BOOLEAN_PARAM ).when( transExecutionConfiguration ).isSafeModeEnabled(); + doReturn( TEST_BOOLEAN_PARAM ).when( transExecutionConfiguration ).isGatheringMetrics(); delegate.executeTransformation( transMeta, true, false, false, false, false, null, false, LogLevel.BASIC ); verify( transMeta ).setParameterValue( TEST_PARAM_KEY, TEST_PARAM_VALUE ); verify( transMeta ).activateParameters(); + verify( transMeta ).setLogLevel( TEST_LOG_LEVEL ); + verify( transMeta ).setClearingLog( TEST_BOOLEAN_PARAM ); + verify( transMeta ).setSafeModeEnabled( TEST_BOOLEAN_PARAM ); + verify( transMeta ).setGatheringMetrics( TEST_BOOLEAN_PARAM ); } }