Commit f4eb8006 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Improve and fix communications canals creation

parent b7ae5cb0
...@@ -569,10 +569,10 @@ public class PAGateway { ...@@ -569,10 +569,10 @@ public class PAGateway {
return 0; return 0;
} }
private List<ScriptTask> createAppTasks(Task task, String taskNameSuffix, String taskToken) { private List<ScriptTask> createAppTasks(Task task, String taskNameSuffix, String taskToken, Job job) {
switch (task.getType()) { switch (task.getType()) {
case "commands": case "commands":
return createCommandsTask(task, taskNameSuffix, taskToken); return createCommandsTask(task, taskNameSuffix, taskToken, job);
case "docker": case "docker":
return createDockerTask(task, taskNameSuffix, taskToken); return createDockerTask(task, taskNameSuffix, taskToken);
} }
...@@ -594,27 +594,46 @@ public class PAGateway { ...@@ -594,27 +594,46 @@ public class PAGateway {
return scriptTasks; return scriptTasks;
} }
private List<ScriptTask> createCommandsTask(Task task, String taskNameSuffix, String taskToken) { private List<ScriptTask> createCommandsTask(Task task, String taskNameSuffix, String taskToken, Job job) {
final String newLine = System.getProperty("line.separator");
final String scriptsSeparation = newLine + newLine + "# Main script" + newLine;
List<ScriptTask> scriptTasks = new LinkedList<>(); List<ScriptTask> scriptTasks = new LinkedList<>();
ScriptTask scriptTaskStart = null; ScriptTask scriptTaskStart = null;
ScriptTask scriptTaskInstall = null; ScriptTask scriptTaskInstall = null;
Map<String, TaskVariable> taskVariablesMap = new HashMap<>();
if (!task.getParentTasks().isEmpty()) {
//TODO: Taking into consideration multiple parent tasks with multiple communications
taskVariablesMap.put("requestedPortName", new TaskVariable("requestedPortName",
job.findTask(task.getParentTasks().get(0)).getPortsToOpen().get(0).getRequestedName()));
}
if (!(task.getInstallation().getInstall().isEmpty() && if (!(task.getInstallation().getInstall().isEmpty() &&
task.getInstallation().getPreInstall().isEmpty() && task.getInstallation().getPreInstall().isEmpty() &&
task.getInstallation().getPostInstall().isEmpty())) { task.getInstallation().getPostInstall().isEmpty())) {
if (!task.getInstallation().getInstall().isEmpty()) { if (!task.getInstallation().getInstall().isEmpty()) {
scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix, scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix,
task.getInstallation().getInstall()); Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getInstall());
} else { } else {
scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix, scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix,
"echo \"Installation script is empty. Nothing to be executed.\""); "echo \"Installation script is empty. Nothing to be executed.\"");
} }
if (!task.getInstallation().getPreInstall().isEmpty()) { if (!task.getInstallation().getPreInstall().isEmpty()) {
scriptTaskInstall.setPreScript(PAFactory.createSimpleScript(task.getInstallation().getPreInstall(), "bash")); scriptTaskInstall.setPreScript(PAFactory.createSimpleScript(
Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getPreInstall(),
"bash"));
} }
if (!task.getInstallation().getPostInstall().isEmpty()) { if (!task.getInstallation().getPostInstall().isEmpty()) {
scriptTaskInstall.setPostScript(PAFactory.createSimpleScript(task.getInstallation().getPostInstall(), "bash")); scriptTaskInstall.setPostScript(PAFactory.createSimpleScript(
Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getPostInstall(),
"bash"));
}
if (!task.getParentTasks().isEmpty()) {
scriptTaskInstall.setVariables(taskVariablesMap);
} }
scriptTaskInstall.addGenericInformation("NODE_ACCESS_TOKEN", taskToken); scriptTaskInstall.addGenericInformation("NODE_ACCESS_TOKEN", taskToken);
scriptTasks.add(scriptTaskInstall); scriptTasks.add(scriptTaskInstall);
...@@ -625,17 +644,24 @@ public class PAGateway { ...@@ -625,17 +644,24 @@ public class PAGateway {
task.getInstallation().getPostStart().isEmpty())) { task.getInstallation().getPostStart().isEmpty())) {
if (!task.getInstallation().getStart().isEmpty()) { if (!task.getInstallation().getStart().isEmpty()) {
scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix, scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix,
task.getInstallation().getStart()); Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getStart());
} else { } else {
scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix, scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix,
"echo \"Installation script is empty. Nothing to be executed.\""); "echo \"Installation script is empty. Nothing to be executed.\"");
} }
if (!task.getInstallation().getPreStart().isEmpty()) { if (!task.getInstallation().getPreStart().isEmpty()) {
scriptTaskStart.setPreScript(PAFactory.createSimpleScript(task.getInstallation().getPreStart(), "bash")); scriptTaskStart.setPreScript(PAFactory.createSimpleScript(
Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getPreStart(),
"bash"));
} }
if (!task.getInstallation().getPostStart().isEmpty()) { if (!task.getInstallation().getPostStart().isEmpty()) {
scriptTaskStart.setPostScript(PAFactory.createSimpleScript(task.getInstallation().getPostStart(), "bash")); scriptTaskStart.setPostScript(PAFactory.createSimpleScript(
Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getPostStart(),
"bash"));
} }
if(scriptTaskInstall != null) { if(scriptTaskInstall != null) {
scriptTaskStart.addDependence(scriptTaskInstall); scriptTaskStart.addDependence(scriptTaskInstall);
...@@ -808,7 +834,7 @@ public class PAGateway { ...@@ -808,7 +834,7 @@ public class PAGateway {
if (task.getDeployments() == null || task.getDeployments().isEmpty()) { if (task.getDeployments() == null || task.getDeployments().isEmpty()) {
LOGGER.warn("The task " + task.getName() + " does not have a deployment. It will be scheduled on any free node."); LOGGER.warn("The task " + task.getName() + " does not have a deployment. It will be scheduled on any free node.");
scriptTasks.addAll(createAppTasks(task, "", "")); scriptTasks.addAll(createAppTasks(task, "", "", job));
task.setDeploymentFirstSubmittedTaskName(scriptTasks.get(0).getName()); task.setDeploymentFirstSubmittedTaskName(scriptTasks.get(0).getName());
task.setDeploymentLastSubmittedTaskName(scriptTasks.get(scriptTasks.size()-1).getName()); task.setDeploymentLastSubmittedTaskName(scriptTasks.get(scriptTasks.size()-1).getName());
} }
...@@ -825,7 +851,7 @@ public class PAGateway { ...@@ -825,7 +851,7 @@ public class PAGateway {
deployment.setIsDeployed(true); deployment.setIsDeployed(true);
// Creating application deployment tasks // Creating application deployment tasks
List<ScriptTask> appTasks = createAppTasks(task, suffix, token); List<ScriptTask> appTasks = createAppTasks(task, suffix, token, job);
task.setDeploymentLastSubmittedTaskName(appTasks.get(appTasks.size()-1).getName().substring(0, appTasks.get(appTasks.size()-1).getName().lastIndexOf(suffix))); task.setDeploymentLastSubmittedTaskName(appTasks.get(appTasks.size()-1).getName().substring(0, appTasks.get(appTasks.size()-1).getName().lastIndexOf(suffix)));
// Creating infra preparation task // Creating infra preparation task
......
package org.activeeon.morphemic.application.deployment; package org.activeeon.morphemic.application.deployment;
import org.activeeon.morphemic.service.TemporaryFilesHelper; import org.activeeon.morphemic.service.TemporaryFilesHelper;
import org.activeeon.morphemic.service.Utils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.ow2.proactive.scheduler.common.job.JobVariable; import org.ow2.proactive.scheduler.common.job.JobVariable;
import org.ow2.proactive.scheduler.common.task.ScriptTask; import org.ow2.proactive.scheduler.common.task.ScriptTask;
...@@ -10,14 +11,10 @@ import org.ow2.proactive.scripting.SelectionScript; ...@@ -10,14 +11,10 @@ import org.ow2.proactive.scripting.SelectionScript;
import org.ow2.proactive.scripting.SimpleScript; import org.ow2.proactive.scripting.SimpleScript;
import org.ow2.proactive.scripting.TaskScript; import org.ow2.proactive.scripting.TaskScript;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class PAFactory { public class PAFactory {
...@@ -52,15 +49,7 @@ public class PAFactory { ...@@ -52,15 +49,7 @@ public class PAFactory {
*/ */
public static SimpleScript createSimpleScriptFromFIle(String scriptFileName, String scriptLanguage) { public static SimpleScript createSimpleScriptFromFIle(String scriptFileName, String scriptLanguage) {
SimpleScript mySQLSimpleScript = null; SimpleScript mySQLSimpleScript = null;
String script; String script = Utils.getContentWithFileName(scriptFileName);
String newLine = System.getProperty("line.separator");
String scriptFileNameWithSeparator = (scriptFileName.startsWith(File.separator)) ?
scriptFileName : File.separator + scriptFileName;
LOGGER.debug("Creating a simple script from the file : " + scriptFileNameWithSeparator);
try (Stream<String> lines = new BufferedReader(new InputStreamReader(
PAFactory.class.getResourceAsStream(scriptFileNameWithSeparator))).lines()) {
script = lines.collect(Collectors.joining(newLine));
}
mySQLSimpleScript = createSimpleScript(script, scriptLanguage); mySQLSimpleScript = createSimpleScript(script, scriptLanguage);
LOGGER.debug("Simple script created."); LOGGER.debug("Simple script created.");
return mySQLSimpleScript; return mySQLSimpleScript;
......
package org.activeeon.morphemic.service;
import org.activeeon.morphemic.application.deployment.PAFactory;
import org.apache.log4j.Logger;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Utils {
private static final Logger LOGGER = Logger.getLogger(Utils.class);
private Utils() { }
public static String getContentWithFileName(String fileName) {
String script;
String newLine = System.getProperty("line.separator");
String scriptFileNameWithSeparator = (fileName.startsWith(File.separator)) ?
fileName : File.separator + fileName;
LOGGER.debug("Creating a simple script from the file : " + scriptFileNameWithSeparator);
try (Stream<String> lines = new BufferedReader(new InputStreamReader(
PAFactory.class.getResourceAsStream(scriptFileNameWithSeparator))).lines()) {
script = lines.collect(Collectors.joining(newLine));
}
return script;
}
}
# Environment variables preparation
if [ -z "$variables_requestedPortName" ]; then
echo "[Env_var] No requested ports for this task. Nothing to be set."
else
REQUESTED_PORT_NAME="PUBLIC_$variables_requestedPortName"
if [[ ! -z $variables_requestedPortName ]]; then
REQ="variables_$variables_requestedPortName"
REQUESTED_PORT_VALUE=${!REQ}
if [[ -z ${!REQUESTED_PORT_NAME} ]]; then
echo "[Env_var] Variable $REQUESTED_PORT_NAME does not exist. Exporting ..."
export PUBLIC_$REQUESTED_PORT_NAME=$REQUESTED_PORT_VALUE
fi
echo "[Env_var] $REQUESTED_PORT_NAME variable set to $REQUESTED_PORT_VALUE"
fi
fi
REQUESTED_PORT_NAME="PUBLIC_$variables_requestedPortName"
if [[ ! -z $variables_requestedPortName ]]; then
REQ="variables_$variables_requestedPortName"
REQUESTED_PORT_VALUE=${!REQ}
if [[ -z ${!REQUESTED_PORT_NAME} ]]; then
echo "Variable $REQUESTED_PORT_NAME does not exist. Exporting ..."
export PUBLIC_$REQUESTED_PORT_NAME=$REQUESTED_PORT_VALUE
echo "export PUBLIC_$REQUESTED_PORT_NAME=$REQUESTED_PORT_VALUE" >> ~/.bashrc
source ~/.bashrc
fi
echo "$REQUESTED_PORT_NAME variable set to $REQUESTED_PORT_VALUE"
fi
PROVIDED_PORT_NAME=$variables_providedPortName PROVIDED_PORT_NAME=$variables_providedPortName
if [[ ! -z $PROVIDED_PORT_NAME ]]; then if [[ ! -z $PROVIDED_PORT_NAME ]]; then
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment