Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iotamak-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMAC
AMAK
Python
IoTAMAK
iotamak-core
Commits
18f22866
Commit
18f22866
authored
3 years ago
by
shinedday
Browse files
Options
Downloads
Patches
Plain Diff
Add mode for scheduler
parent
8d679e3c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ihm.py
+20
-9
20 additions, 9 deletions
ihm.py
scheduler.py
+30
-5
30 additions, 5 deletions
scheduler.py
with
50 additions
and
14 deletions
ihm.py
+
20
−
9
View file @
18f22866
import
subprocess
import
sys
import
sys
from
subprocess
import
Popen
from
os
import
path
from
os
import
path
from
time
import
sleep
from
time
import
sleep
...
@@ -7,7 +7,6 @@ from mqtt_client import MqttClient
...
@@ -7,7 +7,6 @@ from mqtt_client import MqttClient
from
ssh_client
import
SSHClient
,
Cmd
,
RemoteClient
from
ssh_client
import
SSHClient
,
Cmd
,
RemoteClient
from
update
import
VersionManager
from
update
import
VersionManager
class
Ihm
(
MqttClient
,
SSHClient
):
class
Ihm
(
MqttClient
,
SSHClient
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -24,10 +23,12 @@ class Ihm(MqttClient, SSHClient):
...
@@ -24,10 +23,12 @@ class Ihm(MqttClient, SSHClient):
print
(
"
\n
"
)
print
(
"
\n
"
)
cmd
=
input
(
"
>
"
)
cmd
=
input
(
"
>
"
)
# Envoie un signal a tout le monde pour exit
if
cmd
.
lower
()
==
"
exit
"
:
if
cmd
.
lower
()
==
"
exit
"
:
self
.
client
.
publish
(
"
ihm/exit
"
)
self
.
client
.
publish
(
"
ihm/exit
"
)
exit_bool
=
True
exit_bool
=
True
# cherche tout les potentiel agents sur les raspberry et les tuent
if
cmd
.
lower
()
==
"
kill
"
:
if
cmd
.
lower
()
==
"
kill
"
:
commands
=
[
commands
=
[
...
@@ -49,6 +50,7 @@ class Ihm(MqttClient, SSHClient):
...
@@ -49,6 +50,7 @@ class Ihm(MqttClient, SSHClient):
print
(
"
Hostname :
"
,
self
.
clients
[
i_client
].
hostname
,
"
User :
"
,
self
.
clients
[
i_client
].
user
)
print
(
"
Hostname :
"
,
self
.
clients
[
i_client
].
hostname
,
"
User :
"
,
self
.
clients
[
i_client
].
user
)
self
.
run_cmd
(
i_client
,
commands
)
self
.
run_cmd
(
i_client
,
commands
)
# affiche tout les agents en vie
if
cmd
.
lower
()
==
"
agent
"
:
if
cmd
.
lower
()
==
"
agent
"
:
commands
=
[
commands
=
[
Cmd
(
Cmd
(
...
@@ -59,11 +61,13 @@ class Ihm(MqttClient, SSHClient):
...
@@ -59,11 +61,13 @@ class Ihm(MqttClient, SSHClient):
print
(
"
Hostname :
"
,
self
.
clients
[
i_client
].
hostname
,
"
User :
"
,
self
.
clients
[
i_client
].
user
)
print
(
"
Hostname :
"
,
self
.
clients
[
i_client
].
hostname
,
"
User :
"
,
self
.
clients
[
i_client
].
user
)
self
.
run_cmd
(
i_client
,
commands
)
self
.
run_cmd
(
i_client
,
commands
)
# automatise la mise a jour de l'exerience sur les raspberry
if
cmd
.
lower
()
==
"
update
"
:
if
cmd
.
lower
()
==
"
update
"
:
r
=
RemoteClient
(
"
192.168.105.18
"
,
"
pi
"
,
"
raspberry
"
)
r
=
RemoteClient
(
"
192.168.105.18
"
,
"
pi
"
,
"
raspberry
"
)
updater
=
VersionManager
(
r
)
updater
=
VersionManager
(
r
)
updater
.
update
()
updater
.
update
()
# charge une experience et verifie le format
if
cmd
.
lower
()
==
"
load
"
:
if
cmd
.
lower
()
==
"
load
"
:
print
(
"
Give Path to experiment folder(relavive)
"
)
print
(
"
Give Path to experiment folder(relavive)
"
)
cmd
=
input
(
"
>
"
)
cmd
=
input
(
"
>
"
)
...
@@ -78,29 +82,36 @@ class Ihm(MqttClient, SSHClient):
...
@@ -78,29 +82,36 @@ class Ihm(MqttClient, SSHClient):
experiment_folder
=
cmd
experiment_folder
=
cmd
print
(
"
Experiment loaded
"
)
print
(
"
Experiment loaded
"
)
# Crée les processus amas/env/scheduler de l'experience chargé
if
cmd
.
lower
()
==
"
start
"
:
if
cmd
.
lower
()
==
"
start
"
:
if
experiment_folder
!=
""
:
if
experiment_folder
!=
""
:
# choose exec
# choose exec
print
(
"
Choose execution mode for the scheduler
"
)
print
(
"
0 : step by step, 1 : auto
"
)
while
cmd
not
in
[
"
0
"
,
"
1
"
]:
cmd
=
input
(
"
>
"
)
# start subprocess scheduler
# start subprocess scheduler
subprocess
.
Popen
([
sys
.
executable
,
'
scheduler.py
'
])
p1
=
Popen
([
sys
.
executable
,
'
scheduler.py
'
,
cmd
])
# wait
(1)
sleep
(
1
)
# start subprocess amas
# start subprocess amas
subprocess
.
Popen
([
sys
.
executable
,
experiment_folder
+
'
/amas.py
'
])
p2
=
Popen
([
sys
.
executable
,
experiment_folder
+
'
/amas.py
'
])
# start subprocess env
# start subprocess env
subprocess
.
Popen
([
sys
.
executable
,
experiment_folder
+
'
/env.py
'
])
p3
=
Popen
([
sys
.
executable
,
experiment_folder
+
'
/env.py
'
])
if
cmd
.
lower
()
==
"
pause
"
:
if
cmd
.
lower
()
==
"
pause
"
:
pass
self
.
client
.
publish
(
"
ihm/pause
"
)
if
cmd
.
lower
()
==
"
unpause
"
:
if
cmd
.
lower
()
in
[
"
s
"
,
"
step
"
]
:
pass
self
.
client
.
publish
(
"
ihm/step
"
)
self
.
client
.
publish
(
"
ihm/step
"
)
sleep
(
2
)
sleep
(
2
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
a
=
Ihm
()
a
=
Ihm
()
a
.
run
()
a
.
run
()
This diff is collapsed.
Click to expand it.
scheduler.py
+
30
−
5
View file @
18f22866
import
sys
from
time
import
sleep
from
time
import
sleep
from
schedulable
import
Schedulable
from
schedulable
import
Schedulable
...
@@ -5,21 +6,35 @@ from schedulable import Schedulable
...
@@ -5,21 +6,35 @@ from schedulable import Schedulable
class
Scheduler
(
Schedulable
):
class
Scheduler
(
Schedulable
):
def
__init__
(
self
):
def
__init__
(
self
,
execution_policy
:
int
):
Schedulable
.
__init__
(
self
,
client_id
=
"
Scheduler
"
)
Schedulable
.
__init__
(
self
,
client_id
=
"
Scheduler
"
)
self
.
sleep_between_cycle
=
5
self
.
sleep_between_cycle
=
0
# 0: pas a pas, 1: auto
self
.
execution_policy
:
int
=
execution_policy
self
.
ihm_token
=
0
self
.
paused
=
True
self
.
nbr_agent
=
0
self
.
nbr_agent
=
0
self
.
subscribe
(
"
amas/agent/new
"
,
self
.
update_nbr_agent
)
self
.
subscribe
(
"
amas/agent/new
"
,
self
.
update_nbr_agent
)
self
.
subscribe
(
"
amas/action_done
"
,
self
.
update_schedulable
)
self
.
subscribe
(
"
amas/action_done
"
,
self
.
update_schedulable
)
self
.
subscribe
(
"
env/action_done
"
,
self
.
update_schedulable
)
self
.
subscribe
(
"
env/action_done
"
,
self
.
update_schedulable
)
self
.
subscribe
(
"
ihm/step
"
,
self
.
step
)
self
.
subscribe
(
"
ihm/pause
"
,
self
.
pause
)
self
.
agent_waiting
=
0
self
.
agent_waiting
=
0
self
.
schedulable_waiting
=
0
self
.
schedulable_waiting
=
0
print
(
"
Init done
"
)
print
(
"
Init done
"
)
def
pause
(
self
,
client
,
userdata
,
message
):
self
.
paused
=
not
self
.
paused
self
.
ihm_token
+=
1
def
step
(
self
,
client
,
userdata
,
message
):
self
.
ihm_token
+=
1
def
update_schedulable
(
self
,
client
,
userdata
,
message
):
def
update_schedulable
(
self
,
client
,
userdata
,
message
):
self
.
schedulable_waiting
+=
1
self
.
schedulable_waiting
+=
1
print
(
"
__Schedulable is waiting
"
)
print
(
"
__Schedulable is waiting
"
)
...
@@ -43,6 +58,11 @@ class Scheduler(Schedulable):
...
@@ -43,6 +58,11 @@ class Scheduler(Schedulable):
sleep
(
self
.
wait_delay
)
sleep
(
self
.
wait_delay
)
self
.
schedulable_waiting
=
0
self
.
schedulable_waiting
=
0
def
wait_ihm
(
self
):
while
self
.
ihm_token
==
0
:
sleep
(
self
.
wait_delay
)
self
.
ihm_token
-=
1
def
first_part
(
self
)
->
None
:
def
first_part
(
self
)
->
None
:
"""
"""
first part of a cycle
first part of a cycle
...
@@ -87,6 +107,11 @@ class Scheduler(Schedulable):
...
@@ -87,6 +107,11 @@ class Scheduler(Schedulable):
while
not
self
.
exit_bool
:
while
not
self
.
exit_bool
:
print
(
"
Cycle :
"
,
self
.
nbr_cycle
)
print
(
"
Cycle :
"
,
self
.
nbr_cycle
)
if
self
.
execution_policy
==
0
or
self
.
paused
:
self
.
wait_ihm
()
if
self
.
exit_bool
:
break
print
(
"
-First part
"
)
print
(
"
-First part
"
)
self
.
first_part
()
self
.
first_part
()
print
(
"
-Main part
"
)
print
(
"
-Main part
"
)
...
@@ -94,15 +119,15 @@ class Scheduler(Schedulable):
...
@@ -94,15 +119,15 @@ class Scheduler(Schedulable):
print
(
"
-Last part
"
)
print
(
"
-Last part
"
)
self
.
last_part
()
self
.
last_part
()
# sleep(self.sleep_between_cycle)
sleep
(
self
.
sleep_between_cycle
)
# input()
self
.
nbr_cycle
+=
1
self
.
nbr_cycle
+=
1
# exit
self
.
client
.
publish
(
"
scheduler/schedulable/wakeup
"
,
""
)
self
.
client
.
publish
(
"
scheduler/schedulable/wakeup
"
,
""
)
self
.
client
.
publish
(
"
scheduler/agent/wakeup
"
,
""
)
self
.
client
.
publish
(
"
scheduler/agent/wakeup
"
,
""
)
sleep
(
2
)
sleep
(
2
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
s
=
Scheduler
()
s
=
Scheduler
(
int
(
sys
.
argv
[
1
])
)
s
.
run
()
s
.
run
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment