diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java index f02b1d598b7eafc9833a25086cbd133b142b31ed..fd53f4aa55e95fd46e4e7fd0a476041c61abe4e5 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java @@ -47,9 +47,11 @@ public class PAGateway { public final PAConnectorIaasGateway connectorIaasGateway; - private final String NEW_LINE = System.getProperty("line.separator"); + private static final String NEW_LINE = System.getProperty("line.separator"); - private final String SCRIPTS_SEPARATION = NEW_LINE + NEW_LINE + "# Main script" + NEW_LINE; + private static final String SCRIPTS_SEPARATION_BASH = NEW_LINE + NEW_LINE + "# Main script" + NEW_LINE + NEW_LINE; + + private static final String SCRIPTS_SEPARATION_GROOVY = NEW_LINE + NEW_LINE + "// Separation script" + NEW_LINE + NEW_LINE; private static final Logger LOGGER = Logger.getLogger(PAGateway.class); @@ -691,7 +693,7 @@ public class PAGateway { task.getInstallation().getPostInstall().isEmpty())) { if (!task.getInstallation().getInstall().isEmpty()) { scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix, - Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION + + Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION_BASH + task.getInstallation().getInstall()); } else { scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix, @@ -700,13 +702,13 @@ public class PAGateway { if (!task.getInstallation().getPreInstall().isEmpty()) { scriptTaskInstall.setPreScript(PAFactory.createSimpleScript( - Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION + + Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION_BASH + task.getInstallation().getPreInstall(), "bash")); } if (!task.getInstallation().getPostInstall().isEmpty()) { scriptTaskInstall.setPostScript(PAFactory.createSimpleScript( - Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION + + Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION_BASH + task.getInstallation().getPostInstall(), "bash")); } @@ -722,7 +724,7 @@ public class PAGateway { task.getInstallation().getPostStart().isEmpty())) { if (!task.getInstallation().getStart().isEmpty()) { scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix, - Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION + + Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION_BASH + task.getInstallation().getStart()); } else { scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix, @@ -731,16 +733,19 @@ public class PAGateway { if (!task.getInstallation().getPreStart().isEmpty()) { scriptTaskStart.setPreScript(PAFactory.createSimpleScript( - Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION + + Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION_BASH + task.getInstallation().getPreStart(), "bash")); } if (!task.getInstallation().getPostStart().isEmpty()) { scriptTaskStart.setPostScript(PAFactory.createSimpleScript( - Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION + + Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION_BASH + task.getInstallation().getPostStart(), "bash")); } + if (!task.getParentTasks().isEmpty()) { + scriptTaskStart.setVariables(taskVariablesMap); + } if(scriptTaskInstall != null) { scriptTaskStart.addDependence(scriptTaskInstall); } @@ -989,7 +994,7 @@ public class PAGateway { if (!task.getInstallation().getUpdateCmd().isEmpty()) { scriptTaskUpdate = PAFactory.createBashScriptTask(task.getName() + "_update" + suffix, - Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION + + Utils.getContentWithFileName("export_env_var_script.sh") + SCRIPTS_SEPARATION_BASH + task.getInstallation().getUpdateCmd()); } else { scriptTaskUpdate = PAFactory.createBashScriptTask(task.getName() + "_install" + suffix, @@ -1248,7 +1253,9 @@ public class PAGateway { if (!task.getPortsToOpen().isEmpty()) { prepareInfraTask = PAFactory.createBashScriptTaskFromFile(taskName, "prepare_infra_script.sh"); - prepareInfraTask.setPostScript(PAFactory.createSimpleScriptFromFIle("post_prepare_infra_script.groovy", + prepareInfraTask.setPostScript(PAFactory.createSimpleScript( + Utils.getContentWithFileName("post_prepare_infra_script.groovy") + + SCRIPTS_SEPARATION_GROOVY + Utils.getContentWithFileName("collect_ip_addr_results.groovy"), "groovy")); //TODO: Taking into consideration multiple provided ports taskVariablesMap.put("providedPortName", new TaskVariable("providedPortName", diff --git a/scheduling-abstraction-layer/src/main/resources/collect_ip_addr_results.groovy b/scheduling-abstraction-layer/src/main/resources/collect_ip_addr_results.groovy index 7d4e51644532918dd100cca81f0dc67624234c6a..77f5ee6d28aa969aad0b7e0495d57cd2cc7cf721 100644 --- a/scheduling-abstraction-layer/src/main/resources/collect_ip_addr_results.groovy +++ b/scheduling-abstraction-layer/src/main/resources/collect_ip_addr_results.groovy @@ -1,18 +1,21 @@ +//Collect public IP addresses script def requestedPortName = variables.get("requestedPortName") -def publicRequestedPort -def count = 0 +if (requestedPortName != null) { + def publicRequestedPort + def count = 0 -variables.each { key, value -> - if (key.contains(requestedPortName)) { - if (count == 0) { - publicRequestedPort = value.toString() - count++ - } else { - publicRequestedPort += "," + value.toString() - count++ + variables.each { key, value -> + if (key.contains(requestedPortName)) { + if (count == 0) { + publicRequestedPort = value.toString() + count++ + } else { + publicRequestedPort += "," + value.toString() + count++ + } } } -} -println "publicRequestedPort: " + publicRequestedPort -variables.put(requestedPortName, publicRequestedPort) \ No newline at end of file + println "publicRequestedPort: " + publicRequestedPort + variables.put(requestedPortName, publicRequestedPort) +} \ No newline at end of file diff --git a/scheduling-abstraction-layer/src/main/resources/post_prepare_infra_script.groovy b/scheduling-abstraction-layer/src/main/resources/post_prepare_infra_script.groovy index b590df29efee2e83fe9ef746d5e13790cbfb9679..2d881a77a455cede3afabdfea798111dfb6a23d0 100644 --- a/scheduling-abstraction-layer/src/main/resources/post_prepare_infra_script.groovy +++ b/scheduling-abstraction-layer/src/main/resources/post_prepare_infra_script.groovy @@ -1,10 +1,10 @@ +//Post prepare infrastructure script def providedPortName = variables.get("providedPortName") def providedPortValue = variables.get("providedPortValue") if (providedPortName?.trim()){ def ipAddr = new File(providedPortName+"_ip").text.trim() def publicProvidedPort = ipAddr + ":" + providedPortValue - variables.put(providedPortName, publicProvidedPort) variables.put(providedPortName + variables.get("PA_TASK_ID"), publicProvidedPort) println("Provided variable " + providedPortName + "=" + publicProvidedPort) } \ No newline at end of file