Wenjun Ruan
1 year ago
committed by
GitHub
38 changed files with 1081 additions and 516 deletions
@ -0,0 +1,171 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell; |
||||
|
||||
import org.apache.dolphinscheduler.common.utils.FileUtils; |
||||
import org.apache.dolphinscheduler.common.utils.PropertyUtils; |
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.AbstractCommandExecutorConstants; |
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils; |
||||
|
||||
import org.apache.commons.collections4.CollectionUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.nio.file.StandardOpenOption; |
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
@Slf4j |
||||
public abstract class BaseLinuxShellInterceptorBuilder<T extends BaseLinuxShellInterceptorBuilder<T, Y>, Y extends BaseShellInterceptor> |
||||
extends |
||||
BaseShellInterceptorBuilder<T, Y> { |
||||
|
||||
protected void generateShellScript() throws IOException { |
||||
List<String> finalScripts = new ArrayList<>(); |
||||
// add shell header
|
||||
finalScripts.add(shellHeader()); |
||||
finalScripts.add("BASEDIR=$(cd `dirname $0`; pwd)"); |
||||
finalScripts.add("cd $BASEDIR"); |
||||
// add system env
|
||||
finalScripts.addAll(systemEnvScript()); |
||||
// add custom env
|
||||
finalScripts.addAll(customEnvScript()); |
||||
// add k8s config
|
||||
finalScripts.addAll(k8sConfig()); |
||||
// add shell body
|
||||
finalScripts.add(shellBody()); |
||||
// create shell file
|
||||
String finalScript = finalScripts.stream().collect(Collectors.joining(System.lineSeparator())); |
||||
Path shellAbsolutePath = shellAbsolutePath(); |
||||
FileUtils.createFileWith755(shellAbsolutePath); |
||||
Files.write(shellAbsolutePath, finalScript.getBytes(), StandardOpenOption.APPEND); |
||||
log.info("Final Shell file is : \n{}", finalScript); |
||||
} |
||||
|
||||
protected List<String> generateBootstrapCommand() { |
||||
if (sudoEnable) { |
||||
return bootstrapCommandInSudoMode(); |
||||
} |
||||
return bootstrapCommandInNormalMode(); |
||||
} |
||||
|
||||
protected abstract String shellHeader(); |
||||
|
||||
protected abstract String shellInterpreter(); |
||||
|
||||
protected abstract String shellExtension(); |
||||
|
||||
private List<String> systemEnvScript() { |
||||
if (CollectionUtils.isEmpty(systemEnvs)) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return systemEnvs |
||||
.stream() |
||||
.map(systemEnv -> "source " + systemEnv).collect(Collectors.toList()); |
||||
} |
||||
|
||||
private List<String> customEnvScript() { |
||||
if (CollectionUtils.isEmpty(customEnvScripts)) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return customEnvScripts; |
||||
} |
||||
|
||||
private List<String> k8sConfig() throws IOException { |
||||
if (StringUtils.isEmpty(k8sConfigYaml)) { |
||||
return Collections.emptyList(); |
||||
} |
||||
Path kubeConfigPath = Paths.get(FileUtils.getKubeConfigPath(shellDirectory)); |
||||
FileUtils.createFileWith755(kubeConfigPath); |
||||
Files.write(kubeConfigPath, k8sConfigYaml.getBytes(), StandardOpenOption.APPEND); |
||||
log.info("Created kubernetes configuration file: {}.", kubeConfigPath); |
||||
return Collections.singletonList("export KUBECONFIG=" + kubeConfigPath); |
||||
} |
||||
|
||||
private String shellBody() { |
||||
if (CollectionUtils.isEmpty(scripts)) { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
String scriptBody = scripts |
||||
.stream() |
||||
.collect(Collectors.joining(System.lineSeparator())); |
||||
scriptBody = scriptBody.replaceAll("\\r\\n", System.lineSeparator()); |
||||
return ParameterUtils.convertParameterPlaceholders(scriptBody, propertyMap); |
||||
} |
||||
|
||||
private Path shellAbsolutePath() { |
||||
return Paths.get(shellDirectory, shellName + shellExtension()); |
||||
} |
||||
|
||||
private List<String> bootstrapCommandInSudoMode() { |
||||
if (PropertyUtils.getBoolean(AbstractCommandExecutorConstants.TASK_RESOURCE_LIMIT_STATE)) { |
||||
return bootstrapCommandInResourceLimitMode(); |
||||
} |
||||
List<String> bootstrapCommand = new ArrayList<>(); |
||||
bootstrapCommand.add("sudo"); |
||||
if (StringUtils.isNotBlank(runUser)) { |
||||
bootstrapCommand.add("-u"); |
||||
bootstrapCommand.add(runUser); |
||||
} |
||||
bootstrapCommand.add("-E"); |
||||
bootstrapCommand.add(shellAbsolutePath().toString()); |
||||
return bootstrapCommand; |
||||
} |
||||
|
||||
private List<String> bootstrapCommandInNormalMode() { |
||||
List<String> bootstrapCommand = new ArrayList<>(); |
||||
bootstrapCommand.add(shellInterpreter()); |
||||
bootstrapCommand.add(shellAbsolutePath().toString()); |
||||
return bootstrapCommand; |
||||
} |
||||
|
||||
private List<String> bootstrapCommandInResourceLimitMode() { |
||||
List<String> bootstrapCommand = new ArrayList<>(); |
||||
bootstrapCommand.add("sudo"); |
||||
bootstrapCommand.add("systemd-run"); |
||||
bootstrapCommand.add("-q"); |
||||
bootstrapCommand.add("--scope"); |
||||
|
||||
if (cpuQuota == -1) { |
||||
bootstrapCommand.add("-p"); |
||||
bootstrapCommand.add("CPUQuota="); |
||||
} else { |
||||
bootstrapCommand.add("-p"); |
||||
bootstrapCommand.add(String.format("CPUQuota=%s%%", cpuQuota)); |
||||
} |
||||
|
||||
// use `man systemd.resource-control` to find available parameter
|
||||
if (memoryQuota == -1) { |
||||
bootstrapCommand.add("-p"); |
||||
bootstrapCommand.add(String.format("MemoryLimit=%s", "infinity")); |
||||
} else { |
||||
bootstrapCommand.add("-p"); |
||||
bootstrapCommand.add(String.format("MemoryLimit=%sM", memoryQuota)); |
||||
} |
||||
|
||||
bootstrapCommand.add(String.format("--uid=%s", runUser)); |
||||
return bootstrapCommand; |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
@Slf4j |
||||
public abstract class BaseShellInterceptor implements IShellInterceptor { |
||||
|
||||
protected final String workingDirectory; |
||||
protected final List<String> executeCommands; |
||||
|
||||
protected BaseShellInterceptor(List<String> executeCommands, String workingDirectory) { |
||||
this.executeCommands = executeCommands; |
||||
this.workingDirectory = workingDirectory; |
||||
} |
||||
|
||||
@Override |
||||
public Process execute() throws IOException { |
||||
// init process builder
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(); |
||||
// setting up a working directory
|
||||
processBuilder.directory(new File(workingDirectory)); |
||||
// merge error information to standard output stream
|
||||
processBuilder.redirectErrorStream(true); |
||||
processBuilder.command(executeCommands); |
||||
log.info("Executing shell command : {}", String.join(" ", executeCommands)); |
||||
return processBuilder.start(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,141 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell; |
||||
|
||||
import org.apache.commons.collections4.MapUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public abstract class BaseShellInterceptorBuilder<T extends BaseShellInterceptorBuilder<T, Y>, Y extends BaseShellInterceptor> |
||||
implements |
||||
IShellInterceptorBuilder<T, Y> { |
||||
|
||||
protected String shellDirectory; |
||||
|
||||
protected String shellName; |
||||
|
||||
protected String runUser; |
||||
|
||||
protected Integer cpuQuota; |
||||
|
||||
protected Integer memoryQuota; |
||||
|
||||
protected List<String> systemEnvs = new ArrayList<>(); |
||||
|
||||
protected List<String> customEnvScripts = new ArrayList<>(); |
||||
|
||||
protected String k8sConfigYaml; |
||||
|
||||
protected Map<String, String> propertyMap = new HashMap<>(); |
||||
|
||||
protected boolean sudoEnable; |
||||
|
||||
protected List<String> scripts = new ArrayList<>(); |
||||
|
||||
protected BaseShellInterceptorBuilder() { |
||||
} |
||||
|
||||
@Override |
||||
public T newBuilder(T builder) { |
||||
T newBuilder = newBuilder(); |
||||
newBuilder.shellDirectory = builder.shellDirectory; |
||||
newBuilder.shellName = builder.shellName; |
||||
newBuilder.runUser = builder.runUser; |
||||
newBuilder.cpuQuota = builder.cpuQuota; |
||||
newBuilder.memoryQuota = builder.memoryQuota; |
||||
newBuilder.systemEnvs = builder.systemEnvs; |
||||
newBuilder.customEnvScripts = builder.customEnvScripts; |
||||
newBuilder.k8sConfigYaml = builder.k8sConfigYaml; |
||||
newBuilder.propertyMap = builder.propertyMap; |
||||
newBuilder.sudoEnable = builder.sudoEnable; |
||||
newBuilder.scripts = builder.scripts; |
||||
return newBuilder; |
||||
} |
||||
|
||||
@Override |
||||
public T shellDirectory(String shellDirectory) { |
||||
this.shellDirectory = shellDirectory; |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T shellName(String shellFilename) { |
||||
this.shellName = shellFilename; |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T runUser(String systemUser) { |
||||
this.runUser = systemUser; |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T cpuQuota(Integer cpuQuota) { |
||||
this.cpuQuota = cpuQuota; |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T memoryQuota(Integer memoryQuota) { |
||||
this.memoryQuota = memoryQuota; |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T appendSystemEnv(String envFiles) { |
||||
systemEnvs.add(envFiles); |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T appendCustomEnvScript(String customEnvScript) { |
||||
customEnvScripts.add(customEnvScript); |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T k8sConfigYaml(String k8sConfigYaml) { |
||||
this.k8sConfigYaml = k8sConfigYaml; |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T properties(Map<String, String> propertyMap) { |
||||
if (MapUtils.isNotEmpty(propertyMap)) { |
||||
this.propertyMap.putAll(propertyMap); |
||||
} |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T sudoMode(boolean sudoEnable) { |
||||
this.sudoEnable = sudoEnable; |
||||
return (T) this; |
||||
} |
||||
|
||||
@Override |
||||
public T appendScript(String script) { |
||||
scripts.add(script); |
||||
return (T) this; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,116 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell; |
||||
|
||||
import org.apache.dolphinscheduler.common.utils.FileUtils; |
||||
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils; |
||||
|
||||
import org.apache.commons.collections4.CollectionUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.nio.file.StandardOpenOption; |
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
@Slf4j |
||||
public abstract class BaseWindowsShellInterceptorBuilder<T extends BaseWindowsShellInterceptorBuilder<T, Y>, Y extends BaseShellInterceptor> |
||||
extends |
||||
BaseShellInterceptorBuilder<T, Y> { |
||||
|
||||
protected void generateShellScript() throws IOException { |
||||
List<String> finalScripts = new ArrayList<>(); |
||||
// add shell header
|
||||
finalScripts.add(shellHeader()); |
||||
finalScripts.add("cd /d %~dp0"); |
||||
// add system env
|
||||
finalScripts.addAll(systemEnvScript()); |
||||
// add custom env
|
||||
finalScripts.addAll(customEnvScript()); |
||||
// add k8s config
|
||||
finalScripts.addAll(k8sConfig()); |
||||
// add shell body
|
||||
finalScripts.add(shellBody()); |
||||
// create shell file
|
||||
String finalScript = finalScripts.stream().collect(Collectors.joining(System.lineSeparator())); |
||||
Path shellAbsolutePath = shellAbsolutePath(); |
||||
FileUtils.createFileWith755(shellAbsolutePath); |
||||
Files.write(shellAbsolutePath, finalScript.getBytes(), StandardOpenOption.APPEND); |
||||
log.info("Final Shell file is : \n{}", finalScript); |
||||
} |
||||
|
||||
private String shellBody() { |
||||
if (CollectionUtils.isEmpty(scripts)) { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
String scriptBody = scripts |
||||
.stream() |
||||
.collect(Collectors.joining(System.lineSeparator())); |
||||
return ParameterUtils.convertParameterPlaceholders(scriptBody, propertyMap); |
||||
} |
||||
|
||||
private Collection<String> k8sConfig() { |
||||
log.warn("k8s config is not supported in windows"); |
||||
return Collections.emptyList(); |
||||
} |
||||
|
||||
protected List<String> generateBootstrapCommand() { |
||||
if (sudoEnable) { |
||||
log.warn("sudo is not supported in windows"); |
||||
} |
||||
// todo: support tenant in widnows
|
||||
List<String> bootstrapCommand = new ArrayList<>(); |
||||
bootstrapCommand.add(shellInterpreter()); |
||||
bootstrapCommand.add(shellAbsolutePath().toString()); |
||||
return bootstrapCommand; |
||||
} |
||||
|
||||
protected abstract String shellHeader(); |
||||
|
||||
protected abstract String shellInterpreter(); |
||||
|
||||
protected abstract String shellExtension(); |
||||
|
||||
private List<String> systemEnvScript() { |
||||
if (CollectionUtils.isEmpty(systemEnvs)) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return systemEnvs.stream() |
||||
.map(systemEnv -> "call " + systemEnv) |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
private List<String> customEnvScript() { |
||||
if (CollectionUtils.isEmpty(customEnvScripts)) { |
||||
return Collections.emptyList(); |
||||
} |
||||
return customEnvScripts; |
||||
} |
||||
|
||||
private Path shellAbsolutePath() { |
||||
return Paths.get(shellDirectory, shellName + shellExtension()); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* This interface is used to execute shell commands. |
||||
* It should be created by @{@link IShellInterceptorBuilder}. |
||||
*/ |
||||
public interface IShellInterceptor { |
||||
|
||||
Process execute() throws IOException; |
||||
|
||||
} |
@ -0,0 +1,52 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.Map; |
||||
|
||||
public interface IShellInterceptorBuilder<T extends IShellInterceptorBuilder<T, Y>, Y extends IShellInterceptor> { |
||||
|
||||
T newBuilder(); |
||||
|
||||
T newBuilder(T builder); |
||||
|
||||
T shellDirectory(String directory); |
||||
|
||||
T shellName(String shellFilename); |
||||
|
||||
T runUser(String systemUser); |
||||
|
||||
T cpuQuota(Integer cpuQuota); |
||||
|
||||
T memoryQuota(Integer memoryQuota); |
||||
|
||||
T appendSystemEnv(String envFiles); |
||||
|
||||
T appendCustomEnvScript(String customEnvScript); |
||||
|
||||
T k8sConfigYaml(String k8sConfigYaml); |
||||
|
||||
T properties(Map<String, String> propertyMap); |
||||
|
||||
T sudoMode(boolean sudoEnable); |
||||
|
||||
T appendScript(String script); |
||||
|
||||
Y build() throws IOException; |
||||
} |
@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell; |
||||
|
||||
import org.apache.dolphinscheduler.common.utils.PropertyUtils; |
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.bash.BashShellInterceptorBuilder; |
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.cmd.CmdShellInterceptorBuilder; |
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.sh.ShShellInterceptorBuilder; |
||||
|
||||
public class ShellInterceptorBuilderFactory { |
||||
|
||||
private final static String INTERCEPTOR_TYPE = PropertyUtils.getString("shell.interceptor.type", "bash"); |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
public static IShellInterceptorBuilder newBuilder() { |
||||
if (INTERCEPTOR_TYPE.equalsIgnoreCase("bash")) { |
||||
return new BashShellInterceptorBuilder(); |
||||
} |
||||
if (INTERCEPTOR_TYPE.equalsIgnoreCase("sh")) { |
||||
return new ShShellInterceptorBuilder(); |
||||
} |
||||
if (INTERCEPTOR_TYPE.equalsIgnoreCase("cmd")) { |
||||
return new CmdShellInterceptorBuilder(); |
||||
} |
||||
throw new IllegalArgumentException("not support shell type: " + INTERCEPTOR_TYPE); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell.bash; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.BaseShellInterceptor; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class BashShellInterceptor extends BaseShellInterceptor { |
||||
|
||||
public BashShellInterceptor(List<String> executeCommands, String workingDirectory) { |
||||
super(executeCommands, workingDirectory); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,56 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell.bash; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.BaseLinuxShellInterceptorBuilder; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
public class BashShellInterceptorBuilder |
||||
extends |
||||
BaseLinuxShellInterceptorBuilder<BashShellInterceptorBuilder, BashShellInterceptor> { |
||||
|
||||
@Override |
||||
public BashShellInterceptorBuilder newBuilder() { |
||||
return new BashShellInterceptorBuilder(); |
||||
} |
||||
|
||||
@Override |
||||
public BashShellInterceptor build() throws IOException { |
||||
generateShellScript(); |
||||
List<String> bootstrapCommand = generateBootstrapCommand(); |
||||
return new BashShellInterceptor(bootstrapCommand, shellDirectory); |
||||
} |
||||
|
||||
@Override |
||||
protected String shellInterpreter() { |
||||
return "bash"; |
||||
} |
||||
|
||||
@Override |
||||
protected String shellExtension() { |
||||
return ".sh"; |
||||
} |
||||
|
||||
@Override |
||||
protected String shellHeader() { |
||||
return "#!/bin/bash"; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell.cmd; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.BaseShellInterceptor; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class CmdShellInterceptor extends BaseShellInterceptor { |
||||
|
||||
protected CmdShellInterceptor(List<String> executeCommands, String workingDirectory) { |
||||
super(executeCommands, workingDirectory); |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell.cmd; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.BaseWindowsShellInterceptorBuilder; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
public class CmdShellInterceptorBuilder |
||||
extends |
||||
BaseWindowsShellInterceptorBuilder<CmdShellInterceptorBuilder, CmdShellInterceptor> { |
||||
|
||||
@Override |
||||
protected String shellHeader() { |
||||
return "@echo off"; |
||||
} |
||||
|
||||
@Override |
||||
protected String shellInterpreter() { |
||||
return "cmd.exe"; |
||||
} |
||||
|
||||
@Override |
||||
protected String shellExtension() { |
||||
return ".bat"; |
||||
} |
||||
|
||||
@Override |
||||
public CmdShellInterceptorBuilder newBuilder() { |
||||
return new CmdShellInterceptorBuilder(); |
||||
} |
||||
|
||||
@Override |
||||
public CmdShellInterceptor build() throws IOException { |
||||
generateShellScript(); |
||||
List<String> bootstrapCommand = generateBootstrapCommand(); |
||||
return new CmdShellInterceptor(bootstrapCommand, shellDirectory); |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell.sh; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.BaseShellInterceptor; |
||||
|
||||
import java.util.List; |
||||
|
||||
public class ShShellInterceptor extends BaseShellInterceptor { |
||||
|
||||
protected ShShellInterceptor(List<String> executeCommands, String shellDirectory) { |
||||
super(executeCommands, shellDirectory); |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
/* |
||||
* 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.dolphinscheduler.plugin.task.api.shell.sh; |
||||
|
||||
import org.apache.dolphinscheduler.plugin.task.api.shell.BaseLinuxShellInterceptorBuilder; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
public class ShShellInterceptorBuilder |
||||
extends |
||||
BaseLinuxShellInterceptorBuilder<ShShellInterceptorBuilder, ShShellInterceptor> { |
||||
|
||||
@Override |
||||
public ShShellInterceptorBuilder newBuilder() { |
||||
return new ShShellInterceptorBuilder(); |
||||
} |
||||
|
||||
@Override |
||||
public ShShellInterceptorBuilder k8sConfigYaml(String k8sConfigYaml) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public ShShellInterceptor build() throws IOException { |
||||
generateShellScript(); |
||||
List<String> bootstrapCommand = generateBootstrapCommand(); |
||||
return new ShShellInterceptor(bootstrapCommand, shellDirectory); |
||||
} |
||||
|
||||
@Override |
||||
protected String shellHeader() { |
||||
return "#!/bin/sh"; |
||||
} |
||||
|
||||
@Override |
||||
protected String shellInterpreter() { |
||||
return "sh"; |
||||
} |
||||
|
||||
@Override |
||||
protected String shellExtension() { |
||||
return ".sh"; |
||||
} |
||||
} |
Loading…
Reference in new issue