@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License .
* /
package org.apache.dolphinscheduler.server.worker.task.shell ;
package org.apache.dolphinscheduler.server.worker.task.shell ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.enums.CommandType ;
@ -23,7 +23,7 @@ import org.apache.dolphinscheduler.common.process.Property;
import org.apache.dolphinscheduler.common.task.AbstractParameters ;
import org.apache.dolphinscheduler.common.task.shell.ShellParameters ;
import org.apache.dolphinscheduler.common.utils.DateUtils ;
import org.apache.dolphinscheduler.common.utils.* ;
import org.apache.dolphinscheduler.common.utils.JSONUtils ;
import org.apache.dolphinscheduler.common.utils.OSUtils ;
import org.apache.dolphinscheduler.common.utils.ParameterUtils ;
import org.apache.dolphinscheduler.server.entity.TaskExecutionContext ;
@ -31,7 +31,6 @@ import org.apache.dolphinscheduler.server.utils.ParamUtils;
import org.apache.dolphinscheduler.server.worker.task.AbstractTask ;
import org.apache.dolphinscheduler.server.worker.task.CommandExecuteResult ;
import org.apache.dolphinscheduler.server.worker.task.ShellCommandExecutor ;
import org.slf4j.Logger ;
import java.io.File ;
import java.nio.file.Files ;
@ -43,6 +42,8 @@ import java.nio.file.attribute.PosixFilePermissions;
import java.util.Map ;
import java.util.Set ;
import org.slf4j.Logger ;
/ * *
* shell task
* /
@ -65,6 +66,7 @@ public class ShellTask extends AbstractTask {
/ * *
* constructor
*
* @param taskExecutionContext taskExecutionContext
* @param logger logger
* /
@ -111,6 +113,7 @@ public class ShellTask extends AbstractTask {
/ * *
* create command
*
* @return file name
* @throws Exception exception
* /
@ -127,18 +130,13 @@ public class ShellTask extends AbstractTask {
}
String script = shellParameters . getRawScript ( ) . replaceAll ( "\\r\\n" , "\n" ) ;
/ * *
* combining local and global parameters
* /
// combining local and global parameters
Map < String , Property > paramsMap = ParamUtils . convert ( ParamUtils . getUserDefParamsMap ( taskExecutionContext . getDefinedParams ( ) ) ,
taskExecutionContext . getDefinedParams ( ) ,
shellParameters . getLocalParametersMap ( ) ,
CommandType . of ( taskExecutionContext . getCmdTypeIfComplement ( ) ) ,
taskExecutionContext . getScheduleTime ( ) ) ;
if ( paramsMap ! = null ) {
script = ParameterUtils . convertParameterPlaceholders ( script , ParamUtils . convert ( paramsMap ) ) ;
}
// new
// replace variable TIME with $[YYYYmmddd...] in shell file when history run job and batch complement job
if ( paramsMap ! = null ) {
if ( taskExecutionContext . getScheduleTime ( ) ! = null ) {
@ -148,9 +146,10 @@ public class ShellTask extends AbstractTask {
p . setProp ( Constants . PARAMETER_SHECDULE_TIME ) ;
paramsMap . put ( Constants . PARAMETER_SHECDULE_TIME , p ) ;
}
script = ParameterUtils . convertParameterPlaceholders2 ( script , ParamUtils . convert ( paramsMap ) ) ;
}
script = ParameterUtils . convertParameterPlaceholders2 ( script , ParamUtils . convert ( paramsMap ) ) ;
shellParameters . setRawScript ( script ) ;
logger . info ( "raw script : {}" , shellParameters . getRawScript ( ) ) ;