Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andreas Tsagkaropoulos
morphemic-preprocessor
Commits
f4eb8006
Commit
f4eb8006
authored
Mar 30, 2021
by
Mohamed Khalil Labidi
Browse files
Improve and fix communications canals creation
parent
b7ae5cb0
Changes
5
Hide whitespace changes
Inline
Side-by-side
scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/PAGateway.java
View file @
f4eb8006
...
...
@@ -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
...
...
scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/application/deployment/PAFactory.java
View file @
f4eb8006
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
;
...
...
scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/service/Utils.java
0 → 100644
View file @
f4eb8006
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
;
}
}
scheduling-abstraction-layer/src/main/resources/export_env_var_script.sh
0 → 100644
View file @
f4eb8006
# 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
scheduling-abstraction-layer/src/main/resources/prepare_infra_script.sh
View file @
f4eb8006
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment