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 {
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()) {
case "commands":
return createCommandsTask(task, taskNameSuffix, taskToken);
return createCommandsTask(task, taskNameSuffix, taskToken, job);
case "docker":
return createDockerTask(task, taskNameSuffix, taskToken);
}
......@@ -594,27 +594,46 @@ public class PAGateway {
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<>();
ScriptTask scriptTaskStart = 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() &&
task.getInstallation().getPreInstall().isEmpty() &&
task.getInstallation().getPostInstall().isEmpty())) {
if (!task.getInstallation().getInstall().isEmpty()) {
scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix,
task.getInstallation().getInstall());
Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getInstall());
} else {
scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix,
"echo \"Installation script is empty. Nothing to be executed.\"");
}
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()) {
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);
scriptTasks.add(scriptTaskInstall);
......@@ -625,17 +644,24 @@ public class PAGateway {
task.getInstallation().getPostStart().isEmpty())) {
if (!task.getInstallation().getStart().isEmpty()) {
scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix,
task.getInstallation().getStart());
Utils.getContentWithFileName("export_env_var_script.sh") + scriptsSeparation +
task.getInstallation().getStart());
} else {
scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix,
"echo \"Installation script is empty. Nothing to be executed.\"");
}
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()) {
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) {
scriptTaskStart.addDependence(scriptTaskInstall);
......@@ -808,7 +834,7 @@ public class PAGateway {
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.");
scriptTasks.addAll(createAppTasks(task, "", ""));
scriptTasks.addAll(createAppTasks(task, "", "", job));
task.setDeploymentFirstSubmittedTaskName(scriptTasks.get(0).getName());
task.setDeploymentLastSubmittedTaskName(scriptTasks.get(scriptTasks.size()-1).getName());
}
......@@ -825,7 +851,7 @@ public class PAGateway {
deployment.setIsDeployed(true);
// 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)));
// Creating infra preparation task
......
package org.activeeon.morphemic.application.deployment;
import org.activeeon.morphemic.service.TemporaryFilesHelper;
import org.activeeon.morphemic.service.Utils;
import org.apache.log4j.Logger;
import org.ow2.proactive.scheduler.common.job.JobVariable;
import org.ow2.proactive.scheduler.common.task.ScriptTask;
......@@ -10,14 +11,10 @@ import org.ow2.proactive.scripting.SelectionScript;
import org.ow2.proactive.scripting.SimpleScript;
import org.ow2.proactive.scripting.TaskScript;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class PAFactory {
......@@ -52,15 +49,7 @@ public class PAFactory {
*/
public static SimpleScript createSimpleScriptFromFIle(String scriptFileName, String scriptLanguage) {
SimpleScript mySQLSimpleScript = null;
String script;
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));
}
String script = Utils.getContentWithFileName(scriptFileName);
mySQLSimpleScript = createSimpleScript(script, scriptLanguage);
LOGGER.debug("Simple script created.");
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
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