diff --git a/dist/iotAmak-0.0.3-py3-none-any.whl b/dist/iotAmak-0.0.3-py3-none-any.whl index 284ab4a3bfeb7d001be3cea0645a66430eb7cdc6..1cc743c6130b0688eb4dafe5ad4324cf30c2936b 100644 Binary files a/dist/iotAmak-0.0.3-py3-none-any.whl and b/dist/iotAmak-0.0.3-py3-none-any.whl differ diff --git a/dist/iotAmak-0.0.4-py3-none-any.whl b/dist/iotAmak-0.0.4-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..42769f4e5d488201bd5a91be52ffdac1598420de Binary files /dev/null and b/dist/iotAmak-0.0.4-py3-none-any.whl differ diff --git a/iotAmak/agent.py b/iotAmak/agent.py index f749a10d66939e8e24eab2e05e12599e0ede0e2f..bbaaf26524fd083c4c2855de6e3c837f3e5dfc4f 100644 --- a/iotAmak/agent.py +++ b/iotAmak/agent.py @@ -1,6 +1,8 @@ """ Agent class file """ +import json +import random from ast import literal_eval from typing import Dict, List @@ -17,9 +19,20 @@ class Agent(Schedulable): base class for agent """ - def __init__(self, identifier: int, broker_ip: str) -> None: + def __init__(self, arguments: str) -> None: + + arguments = json.loads(arguments) + + broker_ip: str = arguments.get("broker_ip") + identifier: int = int(arguments.get("identifier")) + seed: int = int(arguments.get("seed")) + self.id: int = identifier + random.seed(seed + 10 + self.id) + + print(random.random()) + Schedulable.__init__(self, broker_ip, "Agent" + str(self.id)) self.subscribe("scheduler/agent/wakeup", self.wake_up) diff --git a/iotAmak/amas.py b/iotAmak/amas.py index eda32ccc7e19868f343d5f7e3e6fae6377a711d6..f0e82f48497627d26c120fb9167dbfc303410d51 100644 --- a/iotAmak/amas.py +++ b/iotAmak/amas.py @@ -1,11 +1,13 @@ """ Amas class """ +import json from ast import literal_eval from typing import List, Dict import sys import pathlib +import random sys.path.insert(0, str(pathlib.Path(__file__).parent)) @@ -19,13 +21,24 @@ class Amas(Schedulable, SSHClient): Amas class """ - def __init__(self, broker_ip: str, clients: str) -> None: + def __init__(self, arguments: str) -> None: + + arguments = json.loads(arguments) + + broker_ip: str = arguments.get("broker_ip") + clients: str = arguments.get("clients") + seed: int = int(arguments.get("seed")) + + random.seed(seed) + Schedulable.__init__(self, broker_ip, "Amas") true_client = [RemoteClient(i.get("hostname"), i.get("user"), i.get("password")) for i in literal_eval(clients)] SSHClient.__init__(self, true_client) + self.seed = seed + self.broker_ip: str = broker_ip self.subscribe("scheduler/schedulable/wakeup", self.wake_up) @@ -54,10 +67,12 @@ class Amas(Schedulable, SSHClient): """ if args is None: args = [] + + arg_dict = {"broker_ip": str(self.broker_ip), "seed": self.seed, "identifier": self.next_id} + command = "nohup python " - command += "\"Desktop/mqtt_goyon/example/" + experience_name + "/agent.py\" " - command += str(self.next_id) + " \"" - command += str(self.broker_ip) + "\" " + command += "\'Desktop/mqtt_goyon/example/" + experience_name + "/agent.py\' \'" + command += json.dumps(arg_dict) + "\' " for arg in args: command += str(arg) + " " command += "&" diff --git a/iotAmak/environment.py b/iotAmak/environment.py index 9adb3989458c17e086609cb70a2a081da0f48686..16910585724dcee7335f0be98abbc537dcacfd25 100644 --- a/iotAmak/environment.py +++ b/iotAmak/environment.py @@ -1,6 +1,8 @@ """ Environment class """ +import json +import random import sys import pathlib @@ -14,7 +16,15 @@ class Environment(Schedulable): Environment class """ - def __init__(self, broker_ip: str) -> None: + def __init__(self, arguments: str) -> None: + + arguments = json.loads(arguments) + + broker_ip: str = arguments.get("broker_ip") + seed: int = int(arguments.get("seed")) + + random.seed(seed + 1) + Schedulable.__init__(self, broker_ip, "Env") self.subscribe("scheduler/schedulable/wakeup", self.wake_up) diff --git a/iotAmak/scheduler.py b/iotAmak/scheduler.py index 4af27f46c53fbe7c64031d12b9caeb8eb41c66a7..3f6a54f5d6f7bf394b7c828ac270fc2058eeb211 100644 --- a/iotAmak/scheduler.py +++ b/iotAmak/scheduler.py @@ -2,7 +2,7 @@ Scheduler class file """ from threading import Semaphore -from time import sleep +from time import sleep, time import sys import pathlib @@ -144,19 +144,28 @@ class Scheduler(Schedulable): self.wait_ihm() if self.exit_bool: + print("Exit") break print("-First part") + start_time = time() self.first_part() + print("--- %s seconds ---" % (time() - start_time)) print("-Main part") + start_time = time() self.main_part() + print("--- %s seconds ---" % (time() - start_time)) print("-Last part") + start_time = time() self.last_part() + print("--- %s seconds ---" % (time() - start_time)) self.nbr_cycle += 1 self.publish("scheduler/cycledone", "") - # exit + print("Exit loop") self.client.publish("scheduler/schedulable/wakeup", "") self.client.publish("scheduler/agent/wakeup", "") + sleep(5) + print("Done") diff --git a/requirements.txt b/requirements.txt index a48456a278a658364cf08eab0f626369f23a0622..b0194c6c2b2e023cc225181f62cd3912160ced2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -paho-mqtt -paramiko -pexpect \ No newline at end of file +paho-mqtt >= 1.6.1 +paramiko >= 2.10.4 +pexpect >= 4.8.0 \ No newline at end of file diff --git a/setup.py b/setup.py index a2f08fdd27dc9c103798da426afe89e883c9f42b..c62ced9133e0d4fe4c46d8f4dc0ac72cfc5c4566 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,12 @@ from setuptools import setup, find_packages setup( name='iotAmak', packages=find_packages(), - version='0.0.3', + version='0.0.4', description='AmakFramework in python', author='SMAC - GOYON Sebastien', - install_requires=[], + install_requires=[ + "paho-mqtt >= 1.6.1", + "paramiko >= 2.10.4", + "pexpect >= 4.8.0" + ], )