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

Fix empty communication and script tasks building

parent b7d200ad
...@@ -85,13 +85,15 @@ public class PAGateway { ...@@ -85,13 +85,15 @@ public class PAGateway {
private List<Port> extractListOfPortsToOpen(JSONArray ports) { private List<Port> extractListOfPortsToOpen(JSONArray ports) {
List<Port> portsToOpen = new LinkedList<>(); List<Port> portsToOpen = new LinkedList<>();
ports.forEach(object -> { if (ports != null) {
JSONObject portEntry = (JSONObject) object; ports.forEach(object -> {
if (Objects.equals("PortProvided", portEntry.optString("type"))) { JSONObject portEntry = (JSONObject) object;
Port portToOpen = new Port(portEntry.optInt("port")); if (Objects.equals("PortProvided", portEntry.optString("type"))) {
portsToOpen.add(portToOpen); Port portToOpen = new Port(portEntry.optInt("port"));
} portsToOpen.add(portToOpen);
}); }
});
}
return portsToOpen; return portsToOpen;
} }
...@@ -125,15 +127,18 @@ public class PAGateway { ...@@ -125,15 +127,18 @@ public class PAGateway {
private List<String> extractParentTasks(JSONObject job, JSONObject task) { private List<String> extractParentTasks(JSONObject job, JSONObject task) {
List<String> parentTasks = new LinkedList<>(); List<String> parentTasks = new LinkedList<>();
task.optJSONArray("ports").forEach(portObject -> { JSONArray ports = task.optJSONArray("ports");
JSONObject portEntry = (JSONObject) portObject; if (ports != null) {
if (Objects.equals("PortRequired", portEntry.optString("type")) ports.forEach(portObject -> {
&& portEntry.optBoolean("isMandatory")) { JSONObject portEntry = (JSONObject) portObject;
LOGGER.debug("Mandatory required port detected"); if (Objects.equals("PortRequired", portEntry.optString("type"))
String providedPortName = findProvidedPort(job, portEntry.optString("name")); && portEntry.optBoolean("isMandatory")) {
parentTasks.add(findTaskByProvidedPort(job.optJSONArray("tasks"), providedPortName)); LOGGER.debug("Mandatory required port detected");
} String providedPortName = findProvidedPort(job, portEntry.optString("name"));
}); parentTasks.add(findTaskByProvidedPort(job.optJSONArray("tasks"), providedPortName));
}
});
}
return parentTasks; return parentTasks;
} }
...@@ -586,7 +591,14 @@ public class PAGateway { ...@@ -586,7 +591,14 @@ public class PAGateway {
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())) {
scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix, task.getInstallation().getInstall()); if (!task.getInstallation().getInstall().isEmpty()) {
scriptTaskInstall = PAFactory.createBashScriptTask(task.getName() + "_install" + taskNameSuffix,
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()) { if (!task.getInstallation().getPreInstall().isEmpty()) {
scriptTaskInstall.setPreScript(PAFactory.createSimpleScript(task.getInstallation().getPreInstall(), "bash")); scriptTaskInstall.setPreScript(PAFactory.createSimpleScript(task.getInstallation().getPreInstall(), "bash"));
} }
...@@ -600,7 +612,14 @@ public class PAGateway { ...@@ -600,7 +612,14 @@ public class PAGateway {
if (!(task.getInstallation().getStart().isEmpty() && if (!(task.getInstallation().getStart().isEmpty() &&
task.getInstallation().getPreStart().isEmpty() && task.getInstallation().getPreStart().isEmpty() &&
task.getInstallation().getPostStart().isEmpty())) { task.getInstallation().getPostStart().isEmpty())) {
scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix, task.getInstallation().getStart()); if (!task.getInstallation().getStart().isEmpty()) {
scriptTaskStart = PAFactory.createBashScriptTask(task.getName() + "_start" + taskNameSuffix,
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()) { if (!task.getInstallation().getPreStart().isEmpty()) {
scriptTaskStart.setPreScript(PAFactory.createSimpleScript(task.getInstallation().getPreStart(), "bash")); scriptTaskStart.setPreScript(PAFactory.createSimpleScript(task.getInstallation().getPreStart(), "bash"));
} }
......
...@@ -6,4 +6,6 @@ while [ `ps aux | grep [l]ock_is_held | wc -l` != 0 ]; do ...@@ -6,4 +6,6 @@ while [ `ps aux | grep [l]ock_is_held | wc -l` != 0 ]; do
((i=i+10)); ((i=i+10));
done done
echo "Exited the while loop, time spent: $i" echo "Exited the while loop, time spent: $i"
ps aux | grep [a]pt echo "ps aux | grep apt"
\ No newline at end of file ps aux | grep apt
echo "Waiting for lock task ended properly."
\ No newline at end of file
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