Aufgrund einer Wartung wird GitLab am 25.01 zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 25.01 between 8:00 and 9:00 am.

Commit f1e0c0c3 authored by Marlene Käthe Gebhard's avatar Marlene Käthe Gebhard
Browse files

Extract methodes in base class

parent 8f40cfe4
import s3i
import sys, os
import json
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
import config
import importlib
configData = importlib.import_module("config."+"johnDeere_harvester")
from Machines.harvester import Harvester
import tools
class JohnDeere(Harvester):
def __init__(self, idp):
super().__init__(idp)
def send_komatsuForwarder(self, receiver_name, job):
iD = tools.dir_search_with_name(self.idp, receiver_name)
endpoint = tools.dir_id_to_defualtEndpoints(self.idp, iD)
tools.service_request(self.idp, "komatsu_forwarder", "fml40::ForwardingJob", endpoint,parameter=job)
\ No newline at end of file
......@@ -20,14 +20,12 @@
import config
import importlib
configData = importlib.import_module("config."+"johnDeere_harvester")
import digitalTwin
from aas import Aas
from johnDeere import JohnDeere
print("Hello I'm the John Deere Harvester of the FBZ. I can harvest if you send me a felling job.")
def callback(ch, method, properties, body):
#msgDis_ref.tell(body)
aas_ref.tell(body)
johnDeere_ref.tell(body)
if __name__ == "__main__":
idp = IdentityProvider(grant_type='client_credentials', identity_provider_url="https://idp.s3i.vswf.dev/",
......@@ -36,7 +34,6 @@ def callback(ch, method, properties, body):
s3i_broker = Broker(
auth_form='Username/Password', username=" ", password=access_token, host="rabbitmq.s3i.vswf.dev")
#msgDis_ref = HarvesterMessageDistributer.start(idp)
aas_ref = Aas.start(idp) #.proxy()
johnDeere_ref = JohnDeere.start(idp)
s3i_broker.receive("s3ibs://"+configData.DATA["thingId"], callback) #TODO get own Endpoint with Dir
\ No newline at end of file
import uuid
import sys, os
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from digitalTwin import Functionality
class AcceptsJobs(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def acceptJob(self, job):
pass
def queryJob(self, id):
self.aas.jobs[id]
def removeJob(self, id):
pass
class AcceptsForwardingJobs(AcceptsJobs):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def acceptJob(self, job):
# Check if job can be accepted
# Find the correct functionality which should execute the job
print("I check if I (the Komatsu Forwarder) can accept the job.")
proxyExecuter = self.aas.proxyFunctionalities.get()["forwards"]
proxyExecuter.executeJob(job)
class Forwards(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def executeJob(self, job):
#executeTheJob
print("I am forwarding right now. So much fun!")
\ No newline at end of file
import s3i
import sys, os
import json
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
#from digitalTwin import ManagingActor
import config
import importlib
configData = importlib.import_module("config."+"johnDeere_harvester")
from Machines.forwarder import Forwarder
import tools
import functionalities
class Komatsu(Forwarder):
def __init__(self, idp):
super().__init__(idp)
\ No newline at end of file
......@@ -16,14 +16,12 @@
import config
import importlib
configData = importlib.import_module("config."+"komatsu_forwarder")
import digitalTwin
from aas import Aas
from komatsu import Komatsu
print("Hello I'm the Komatsu Forwarder. I can forward if you send me a forwarding job.")
def callback(ch, method, properties, body):
#msgDis_ref.tell(body)
aas_ref.tell(body)
komatsu_ref.tell(body)
if __name__ == "__main__":
idp = IdentityProvider(grant_type='client_credentials', identity_provider_url="https://idp.s3i.vswf.dev/",
......@@ -32,7 +30,6 @@ def callback(ch, method, properties, body):
s3i_broker = Broker(
auth_form='Username/Password', username=" ", password=access_token, host="rabbitmq.s3i.vswf.dev")
#msgDis_ref = ForwarderMessageDistributer.start(idp)
aas_ref = Aas.start(idp)
komatsu_ref = Komatsu.start(idp)
s3i_broker.receive("s3ibs://"+configData.DATA["thingId"], callback) #TODO get own Endpoint with Dir
\ No newline at end of file
import s3i
import sys, os
import json
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from digitalTwin import AssetAdministrationShell
import config
import importlib
configData = importlib.import_module("config."+"johnDeere_harvester")
from digitalTwin import tools
import functionalities
PACKAGE_PARENT = '../..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
import json
from managingActor import ManagingActor
from functionalities import functionalities
class Aas(AssetAdministrationShell):
class Forwarder(ManagingActor):
def __init__(self, idp):
#idp = s3i.IdentityProvider(grant_type='client_credentials', identity_provider_url="https://idp.s3i.vswf.dev/",
# realm='KWH', client_id=configData.DATA["thingId"], client_secret=configData.CLIENT_SECRET)
super().__init__(idp)
self.jobs = dict()
functionalities.Forwards.start(self.idp, self.actor_ref, "forwards").proxy()
......@@ -31,8 +27,4 @@ def on_receive(self, body):
if body_json["messageType"] == "serviceRequest":
if body_json["serviceType"] == "fml40::ForwardingJob":
self.proxyFunctionalities["acceptsForwardingJobs"].acceptJob("This is a forwarding job")
return "I'm the asset administration shell and I distributed your message to one of my highly qualified services"
\ No newline at end of file
return "I'm the asset administration shell and I distributed your message to one of my highly qualified services"
\ No newline at end of file
import s3i
import sys, os
import json
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from digitalTwin import AssetAdministrationShell
import config
import importlib
configData = importlib.import_module("config."+"johnDeere_harvester")
from digitalTwin import tools
import functionalities
PACKAGE_PARENT = '../..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
import json
from managingActor import ManagingActor
from functionalities import functionalities
class Aas(AssetAdministrationShell):
class Harvester(ManagingActor):
def __init__(self, idp):
#idp = s3i.IdentityProvider(grant_type='client_credentials', identity_provider_url="https://idp.s3i.vswf.dev/",
# realm='KWH', client_id=configData.DATA["thingId"], client_secret=configData.CLIENT_SECRET)
......@@ -32,11 +30,4 @@ def on_receive(self, body):
if body_json["messageType"] == "serviceRequest":
if body_json["serviceType"] == "fml40::FellingJob":
self.proxyFunctionalities["acceptsFellingJobs"].acceptJob("This is a felling job")
return "I'm the Message Distribution Actor and I distributed your message to one of my highly qualified actors"
def send_komatsuForwarder(self, receiver_name, job):
iD = tools.dir_search_with_name(self.idp, receiver_name)
endpoint = tools.dir_id_to_defualtEndpoints(self.idp, iD)
tools.service_request(self.idp, "komatsu_forwarder", "fml40::ForwardingJob", endpoint,parameter=job)
\ No newline at end of file
return "I'm the Message Distribution Actor and I distributed your message to one of my highly qualified actors"
\ No newline at end of file
from Ponsse_Harvester.harvesterMessageDistributer import HarvesterMessageDistributer
from Ponsse_Harvester.harvesterServices import HarvesterServices
from Ponsse_Harvester.harvesterSecretary import HarvesterSecretary
import uuid
import sys, os
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from digitalTwin import Functionality
class AcceptsJobs(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def acceptJob(self, job):
pass
def queryJob(self, id):
self.aas.jobs[id]
def removeJob(self, id):
pass
class AcceptsFellingJobs(AcceptsJobs):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def acceptJob(self, job):
# Check if job can be accepted
# Find the correct functionality which should execute the job
print("I check if the I (the Ponsse Harvester) can accept the job.")
proxyExecuter = self.aas.proxyFunctionalities.get()["harvests"]
proxyExecuter.executeJob(job)
class Harvests(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def executeJob(self, job):
#executeTheJob
print("I am harvesting right now. So much fun!")
proxyManager = self.aas.proxyFunctionalities.get()["managesJobs"]
id = uuid.uuid4()
proxyManager.assignJob(job, id)
class ManageJobs(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def assignJob(self, job, id):
# Find assignee
print("I assign the job {} to the Komatsu forwarder".format(job))
self.aas.send_komatsuForwarder("Komatsu Forwarder", job)
......@@ -4,36 +4,17 @@
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from digitalTwin import AssetAdministrationShell
import config
import importlib
configData = importlib.import_module("config."+"ponsse_harvester")
from digitalTwin import tools
import functionalities
import tools
from Machines.harvester import Harvester
class Aas(AssetAdministrationShell):
class Ponsse(Harvester):
def __init__(self, idp):
#idp = s3i.IdentityProvider(grant_type='client_credentials', identity_provider_url="https://idp.s3i.vswf.dev/",
# realm='KWH', client_id=configData.DATA["thingId"], client_secret=configData.CLIENT_SECRET)
super().__init__(idp)
self.jobs = dict()
functionalities.Harvests.start(self.idp, self.actor_ref, "harvests").proxy()
functionalities.ManageJobs.start(self.idp, self.actor_ref, "managesJobs").proxy()
functionalities.AcceptsFellingJobs.start(self.idp, self.actor_ref, "acceptsFellingJobs").proxy()
def on_receive(self, body):
"""This function is called when the Asset Administration Shell gets something told. In this case, whenever the harvester receives a message.
"""
body_str = body.decode('utf8').replace("'", '"').replace(
"True", "true"). replace("False", "false") # convert bytes to str
body_json = json.loads(body_str)
print("Message received: ", body_json["messageType"], ":", body_json["serviceType"])
if body_json["messageType"] == "serviceRequest":
if body_json["serviceType"] == "fml40::FellingJob":
self.proxyFunctionalities["acceptsFellingJobs"].acceptJob("This is a felling job")
return "I'm the Asset Administration Shell and I distributed your message to one of the functionalities of this harvester"
super().__init__(idp)
def send_komatsuForwarder(self, receiver_name, job):
iD = tools.dir_search_with_name(self.idp, receiver_name)
endpoint = tools.dir_id_to_defualtEndpoints(self.idp, iD)
......
......@@ -16,14 +16,12 @@
import config
import importlib
configData = importlib.import_module("config."+"ponsse_harvester")
import digitalTwin
from aas import Aas
from ponsse import Ponsse
print("Hello I'm the Ponsse Harvester. I can harvest if you send me a felling job.")
def callback(ch, method, properties, body):
#msgDis_ref.tell(body)
aas_ref.tell(body)
ponsse_ref.tell(body)
if __name__ == "__main__":
idp = IdentityProvider(grant_type='client_credentials', identity_provider_url="https://idp.s3i.vswf.dev/",
......@@ -32,7 +30,6 @@ def callback(ch, method, properties, body):
s3i_broker = Broker(
auth_form='Username/Password', username=" ", password=access_token, host="rabbitmq.s3i.vswf.dev")
#msgDis_ref = HarvesterMessageDistributer.start(idp)
aas_ref = Aas.start(idp)
ponsse_ref = Ponsse.start(idp)
s3i_broker.receive("s3ibs://"+configData.DATA["thingId"], callback) #TODO get own Endpoint with Dir
\ No newline at end of file
#import sys, os
#sys.path.append(os.path.abspath(os.path.join("..", "config")))
#from config.config import *
from digitalTwin.tools import service_request, print_ts, input_ts, service_reply
from digitalTwin.assetAdministrationShell import AssetAdministrationShell
from digitalTwin.functionality import Functionality
\ No newline at end of file
......@@ -3,48 +3,73 @@
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from digitalTwin import Functionality
from managedActor import ManagedActor
class Functionality(ManagedActor):
def __init__(self, idp, refManagingActor, name):
super().__init__(idp, refManagingActor, name)
class AcceptsJobs(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def __init__(self, idp, refManagingActor, name):
super().__init__(idp, refManagingActor, name)
self.jobs = list()
def acceptJob(self, job):
pass
def queryJob(self, id):
self.aas.jobs[id]
pass
def removeJob(self, id):
pass
class AcceptsFellingJobs(AcceptsJobs):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
def __init__(self, idp, refManagingActor, name):
super().__init__(idp, refManagingActor, name)
def acceptJob(self, job):
# Check if job can be accepted
# Find the correct functionality which should execute the job
print("I check if the I (the John Deere Harvester) can accept the job.")
proxyExecuter = self.aas.proxyFunctionalities.get()["harvests"]
proxyExecuter = self.managingActor.proxyFunctionalities.get()["harvests"]
proxyExecuter.executeJob(job)
class Harvests(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
class Harvests(ManagedActor):
def __init__(self, idp, refManagingActor, name):
super().__init__(idp, refManagingActor, name)
def executeJob(self, job):
#executeTheJob
print("I am harvesting right now. So much fun!")
proxyManager = self.aas.proxyFunctionalities.get()["managesJobs"]
proxyManager = self.managingActor.proxyFunctionalities.get()["managesJobs"]
id = uuid.uuid4()
proxyManager.assignJob(job, id)
class ManageJobs(Functionality):
def __init__(self, idp, ref_aas, name):
super().__init__(idp, ref_aas, name)
class ManageJobs(ManagedActor):
def __init__(self, idp, refManagingActor, name):
super().__init__(idp, refManagingActor, name)
def assignJob(self, job, id):
# Find assignee
print("I assign the job {} to the Komatsu forwarder".format(job))
self.aas.send_komatsuForwarder("Komatsu Forwarder", job)
self.managingActor.send_komatsuForwarder("Komatsu Forwarder", job)
class AcceptsForwardingJobs(AcceptsJobs):
def __init__(self, idp, refManagingActor, name):
super().__init__(idp, refManagingActor, name)
def acceptJob(self, job):
# Check if job can be accepted
# Find the correct functionality which should execute the job
print("I check if I (the Komatsu Forwarder) can accept the job.")
proxyExecuter = self.managingActor.proxyFunctionalities.get()["forwards"]
proxyExecuter.executeJob(job)
class Forwards(ManagedActor):
def __init__(self, idp, refManagingActor, name):
super().__init__(idp, refManagingActor, name)
def executeJob(self, job):
#executeTheJob
print("I am forwarding right now. So much fun!")
import pykka
import logging
logging.basicConfig(level=logging.WARNING)
class Functionality(pykka.ThreadingActor):
def __init__(self, idp, ref_aas, name):
class ManagedActor(pykka.ThreadingActor):
def __init__(self, idp, refManagingActor, name):
super().__init__()
self.idp = idp
self.aas = ref_aas.proxy()
self.managingActor = refManagingActor.proxy()
self.name = name
self.aas.registerFunctionality(name, self.actor_ref.proxy())
self.managingActor.registerManagedActor(name, self.actor_ref.proxy())
def on_receive(self, msg):
print("Hello, I'm a functionality of a digital twin with the name {}.".format(self.name))
print("Hello, I'm a Managed Actor of a digital twin with the name {}.".format(self.name))
print("You send me a message: ", msg)
import pykka
import logging
logging.basicConfig(level=logging.WARNING)
class AssetAdministrationShell(pykka.ThreadingActor):
class ManagingActor(pykka.ThreadingActor):
"""This is the administration shell of the forwarder. It receives the service replys which are addressed to the forwarder and schedules the further forwarder actions when all necessary replys have arrived.
"""
def __init__(self, idp):
......@@ -13,12 +15,15 @@ def on_receive(self, msg):
print("Hello, I'm a secretary")
print("You send me a message: ", msg)
def registerFunctionality(self, name, proxy):
def registerManagedActor(self, name, proxy):
self.proxyFunctionalities[name] = proxy
def on_stop(self):
for i in self.proxyFunctionalities.keys():
pykka.ActorRegistry.get_by_class_name(i)[0].stop()
def accept(self, functionality, parameters):
self.proxyFunctionalities[functionality].visit(self, parameters)
\ No newline at end of file
......@@ -27,13 +27,10 @@
def sendRequest():
senderUUID = data["thingID"]
receiverUUID = ["s3i:5e83b933-331f-4278-b318-b7fdcb0e4872"]
receiver_endpoint = "s3ibs://s3i:3154edfa-5b04-4a28-b803-d6ec46135c19"
endpoint_ponsse = "s3ibs://s3i:5e83b933-331f-4278-b318-b7fdcb0e4872"
endpoint_john = "s3ibs://s3i:c5d5cd58-8786-40b2-8079-5f2de443de36"
receiver_endpoints = list()
receiver_endpoints.append(endpoint_john)
receiver_endpoints.append(endpoint_ponsse)
identifier_johnDeere = "s3i:c5d5cd58-8786-40b2-8079-5f2de443de36"
identifier_ponsse = "s3i:5e83b933-331f-4278-b318-b7fdcb0e4872"
receiverUUID = [identifier_johnDeere, identifier_ponsse]
receiver_endpoints = [("s3ibs://"+i) for i in receiverUUID]
serviceType = "fml40::FellingJob"
msgUUID = "s3i:" + str(uuid.uuid4())
req = ServiceRequest()
......
Markdown is supported
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